public async Task <IActionResult> PutItemGroup(int id, ItemGroup itemGroup)
        {
            if (id != itemGroup.Id)
            {
                return(BadRequest());
            }

            _context.Entry(itemGroup).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ItemGroupExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
        public async Task <IActionResult> PutCustomer(int id, Customer customer)
        {
            if (id != customer.Id)
            {
                return(BadRequest());
            }

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutStoreType(int id, StoreType storeType)
        {
            if (id != storeType.Id)
            {
                return(BadRequest());
            }

            _context.Entry(storeType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StoreTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostTransaction([FromBody] InventoryTransactionLines transactionApi)
        {
            APIResponse response = new APIResponse();

            try
            {
                Models.InventoryTransactionLines transactionLines = new Models.InventoryTransactionLines();
                transactionLines.InventoryTransactionId = transactionApi.InventoryTransactionId;
                transactionLines.ArticleId   = transactionApi.ArticleId;
                transactionLines.ArticleName = transactionApi.ArticleName;
                transactionLines.Qty         = transactionApi.Qty;
                _context.InventoryTransactionLines.Add(transactionLines);
                await _context.SaveChangesAsync();

                response.code    = "1";
                response.message = "Sucess Add Data";
            }
            catch (Exception ex)
            {
                response.code    = "0";
                response.message = ex.ToString();
            }
            return(Ok(response));
        }
Example #5
0
        public async Task <UserLogin> Login(string username, string password)
        {
            var employeecode = await _context.Employee.Where(c => c.EmployeeCode == username).Select(c => c.Id).FirstOrDefaultAsync();

            // var login = await _context.UserLogin.FirstOrDefaultAsync(x => x.UserId == Int32.Parse(username));
            var login = await _context.UserLogin.FirstOrDefaultAsync(x => x.UserId == employeecode);

            if (login == null)
            {
                return(null);
            }

            if (!VerifyPasswordHash(password, login.PasswordHash, login.PasswordSalt))
            {
                return(null);
            }

            login.LastLogin = DateTime.UtcNow;
            _context.Update(login);
            await _context.SaveChangesAsync();

            //auth sukses
            return(login);
        }
        public async Task <IActionResult> PostTransaction([FromBody] HOTransaction transactionApi)
        {
            APIResponse response = new APIResponse();

            try
            {
                Store store = _context.Store.Where(c => c.Code == transactionApi.storeCode).First();
                Models.InventoryTransaction transaction = new Models.InventoryTransaction();
                transaction.TransactionId       = transactionApi.transactionId;
                transaction.StoreCode           = transactionApi.storeCode;
                transaction.Remarks             = "";
                transaction.StoreName           = store.Name;
                transaction.TransactionTypeId   = RetailEnum.HOTransaction;
                transaction.TransactionTypeName = "HOTransaction";
                transaction.WarehouseOriginal   = store.WarehouseId;
                transaction.RequestDeliveryDate = DateTime.Now;
                transaction.TransactionDate     = DateTime.Now;

                transaction.Status   = "Pending";
                transaction.StatusId = RetailEnum.doStatusPending;

                try
                {
                    transaction.EmployeeCode = transactionApi.employeeId;
                    transaction.EmployeeName = transactionApi.employeeName;
                }
                catch { }


                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                //log record
                LogRecord log = new LogRecord();
                log.TimeStamp = DateTime.Now;
                log.Tag       = "HO Transaction";
                log.Message   = JsonConvert.SerializeObject(transactionApi);
                _context.LogRecord.Add(log);
                _context.InventoryTransaction.Add(transaction);
                await _context.SaveChangesAsync();

                /*
                 * //save Lines
                 * for (int i = 0; i < transactionApi.hoTransactionLines.Count; i++)
                 * {
                 *  Models.InventoryTransactionLines transactionLines = new Models.InventoryTransactionLines();
                 *  transactionLines.InventoryTransactionId = transaction.Id;
                 *  transactionLines.ArticleId = transactionApi.hoTransactionLines[i].article.articleId;
                 *  transactionLines.ArticleName = transactionApi.hoTransactionLines[i].article.articleName;
                 *  transactionLines.Qty = transactionApi.hoTransactionLines[i].quantity;
                 *  _context.InventoryTransactionLines.Add(transactionLines);
                 *  await _context.SaveChangesAsync();
                 * }
                 */
                response.code    = "1";
                response.message = "Sucess Add Data";

                //   WebAPIInforController.InforAPIController inforAPIController = new WebAPIInforController.InforAPIController(_context);
                //  inforAPIController.postRequestOrder(transactionApi, transaction.Id).Wait();
                this.sequenceNumber(transactionApi);
            }

            catch (Exception ex)
            {
                response.code    = "0";
                response.message = ex.ToString();
            }
            return(Ok(response));
        }
Example #7
0
        public async Task <IActionResult> PostTransaction([FromBody] MutasiOrder transactionApi)
        {
            APIResponse response = new APIResponse();

            try
            {
                if (transactionApi.mutasiFromWarehouse == "" || transactionApi.mutasiFromWarehouse == null || transactionApi.mutasiToWarehouse == "" || transactionApi.mutasiFromWarehouse == null)
                {
                    response.code    = "0";
                    response.message = "No Warehouse Origin / Destination, Make sure to fill it.";
                    return(BadRequest(response));
                }
                bool exist = _context.InventoryTransaction.Any(c => c.TransactionId == transactionApi.mutasiOrderId);
                if (exist == false)
                {
                    LogRecord log = new LogRecord();
                    log.TimeStamp     = DateTime.Now;
                    log.Tag           = "Mutasi Order";
                    log.Message       = JsonConvert.SerializeObject(transactionApi);
                    log.TransactionId = transactionApi.mutasiOrderId;
                    await _context.LogRecord.AddAsync(log);

                    await _context.SaveChangesAsync();

                    DateTime asd;// = DateTime.Now;
                    try
                    {
                        // transaction.RequestDeliveryDate = DateTime.ParseExact(transactionApi.timeStamp, "MMM dd, yyyy h:mm:ss tt", CultureInfo.InvariantCulture);
                        asd = DateTime.ParseExact(transactionApi.date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                        asd = DateTime.ParseExact(transactionApi.date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    }
                    DateTime maret10 = DateTime.ParseExact("2019-03-10", "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    if (maret10 >= asd)
                    {
                        response.code    = "1";
                        response.message = "Sucess Add Data";
                        return(Ok(response));
                    }

                    Store store = _context.Store.Where(c => c.Code == transactionApi.storeCode).First();
                    Models.InventoryTransaction transaction = new Models.InventoryTransaction();
                    transaction.TransactionId       = transactionApi.mutasiOrderId;
                    transaction.StoreCode           = transactionApi.storeCode;
                    transaction.Remarks             = transactionApi.remarks;
                    transaction.StoreName           = store.Name;
                    transaction.TransactionTypeId   = RetailEnum.mutasiTransaction;
                    transaction.TransactionTypeName = "Mutasi";
                    transaction.Status               = null;
                    transaction.StatusId             = null;
                    transaction.WarehouseOriginal    = transactionApi.mutasiFromWarehouse;
                    transaction.WarehouseDestination = transactionApi.mutasiToWarehouse;
                    transaction.RequestDeliveryDate  = DateTime.Now;
                    transaction.Sjlama               = transactionApi.oldSJ;
                    transaction.TransactionDate      = DateTime.Now;//DateTime.ParseExact(transactionApi.date, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                    try
                    {
                        transaction.TransactionDate = DateTime.Parse(transactionApi.date);
                    }
                    catch
                    {
                    }
                    try
                    {
                        transaction.RequestDeliveryDate = DateTime.Parse(transactionApi.requestDeliveryDate);
                    }
                    catch
                    {
                    }
                    transaction.TotalQty = transactionApi.totalQty;
                    transaction.Remarks  = "";
                    try
                    {
                        transaction.EmployeeCode = transactionApi.employeeId;
                        transaction.EmployeeName = transactionApi.employeeName;
                    }
                    catch
                    {
                    }
                    //add by frank for mutasi matrix
                    try
                    {
                        Store storeMaster = _context.Store.Where(c => c.Code == transactionApi.mutasiFromWarehouse).First();
                        List <MutasiApproverMatrix> mutasiApproverMatrixs = _context.MutasiApproverMatrix.Where(c => c.StoreMatrix == storeMaster.Id).ToList();
                        MutasiApproverMatrix        ms = mutasiApproverMatrixs.Where(c => c.StoreMatrix == storeMaster.Id).First();
                        if (transactionApi.mutasiType == 1)
                        {
                            transaction.EmployeeToApprove = ms.ApproverCity;
                        }
                        else if (transactionApi.mutasiType == 2)
                        {
                            transaction.EmployeeToApprove = ms.ApproverRegional;
                        }
                        else
                        {
                            transaction.EmployeeToApprove = ms.ApproverNational;
                        }
                    }
                    catch
                    {
                        transaction.EmployeeToApprove = "admin123";
                    }

                    if (!ModelState.IsValid)
                    {
                        return(BadRequest(ModelState));
                    }
                    //log record

                    _context.InventoryTransaction.Add(transaction);
                    _context.SaveChanges();

                    //save Lines
                    for (int i = 0; i < transactionApi.mutasiOrderLines.Count; i++)
                    {
                        Models.InventoryTransactionLines transactionLines = new Models.InventoryTransactionLines();
                        transactionLines.InventoryTransactionId = transaction.Id;
                        transactionLines.ArticleId   = transactionApi.mutasiOrderLines[i].article.articleIdAlias;
                        transactionLines.ArticleName = transactionApi.mutasiOrderLines[i].article.articleName;
                        transactionLines.Qty         = transactionApi.mutasiOrderLines[i].quantity;
                        try
                        {
                            transactionLines.ValueSalesPrice = transactionLines.Qty * _context.PriceList.Where(c => c.ItemId == transactionLines.ArticleId).First().SalesPrice;
                        }
                        catch
                        {
                            transactionLines.ValueSalesPrice = 0;
                        }
                        _context.InventoryTransactionLines.Add(transactionLines);
                        _context.SaveChanges();
                    }

                    response.code    = "1";
                    response.message = "Sucess Add Data";
                    //Duplace karena di POS sudah kurang, jika rect qty akan bertambah, jika approve tidak perlu kalkulaso
                    this.insertAndCalculateDO(transactionApi);
                    this.sequenceNumber(transactionApi);
                }
                else
                {
                    response.code    = "1";
                    response.message = "Transaction Already Exist";
                    LogRecord log = new LogRecord();
                    log.TimeStamp = DateTime.Now;
                    log.Tag       = "Mutasi Order";
                    log.Message   = transactionApi.mutasiOrderId + "Aleader Exist";
                    _context.LogRecord.Add(log);
                    _context.SaveChanges();
                }
            }

            catch (Exception ex)
            {
                response.code    = "1";
                response.message = ex.ToString();
            }


            // await _context.SaveChangesAsync();
            return(Ok(response));
            //     return CreatedAtAction("GetTransaction", new { id = transaction.Id }, transaction);
        }
Example #8
0
        public async Task <IActionResult> PostTransaction([FromBody] ReturnOrder transactionApi)
        {
            APIResponse response = new APIResponse();
            bool        exist    = _context.InventoryTransaction.Any(c => c.TransactionId == transactionApi.returnOrderId);

            if (exist == false)
            {
                LogRecord log = new LogRecord();
                log.TimeStamp     = DateTime.Now;
                log.Tag           = "Return Order";
                log.Message       = JsonConvert.SerializeObject(transactionApi);
                log.TransactionId = transactionApi.returnOrderId;
                _context.LogRecord.Add(log);
                _context.SaveChanges();


                DateTime asd;
                try
                {
                    // transaction.RequestDeliveryDate = DateTime.ParseExact(transactionApi.timeStamp, "MMM dd, yyyy h:mm:ss tt", CultureInfo.InvariantCulture);
                    asd = DateTime.ParseExact(transactionApi.date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                }
                catch
                {
                    asd = DateTime.ParseExact(transactionApi.date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                }
                DateTime maret10 = DateTime.ParseExact("2019-03-10", "yyyy-MM-dd", CultureInfo.InvariantCulture);
                if (maret10 >= asd)
                {
                    response.code    = "1";
                    response.message = "Sucess Add Data";
                    return(Ok(response));
                }


                Store store = _context.Store.Where(c => c.Code == transactionApi.storeCode).First();
                Models.InventoryTransaction transaction = new Models.InventoryTransaction();

                transaction.TransactionId        = transactionApi.returnOrderId;
                transaction.StoreCode            = transactionApi.storeCode;
                transaction.Remarks              = "-";
                transaction.StoreName            = store.Name;
                transaction.TransactionTypeId    = RetailEnum.returnTransaction;
                transaction.TransactionTypeName  = "Return";
                transaction.WarehouseOriginal    = store.WarehouseId;
                transaction.WarehouseDestination = "210";
                transaction.RequestDeliveryDate  = DateTime.Now;
                // transaction.SJlama = transactionApi.oldSJ;
                try
                {
                    transaction.TransactionDate = DateTime.Parse(transactionApi.date);
                }
                catch
                {
                }

                //DateTime.ParseExact(transactionApi.date, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                transaction.TotalQty = transactionApi.totalQty;
                transaction.Remarks  = transactionApi.remark;

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                _context.InventoryTransaction.Add(transaction);
                await _context.SaveChangesAsync();

                // this.insertInventoryReturnOrder(transactionApi).Wait();
                //save Lines
                for (int i = 0; i < transactionApi.returnOrderLines.Count; i++)
                {
                    Models.InventoryTransactionLines transactionLines = new Models.InventoryTransactionLines();
                    transactionLines.InventoryTransactionId = transaction.Id;
                    transactionLines.ArticleId   = transactionApi.returnOrderLines[i].article.articleIdAlias;
                    transactionLines.ArticleName = transactionApi.returnOrderLines[i].article.articleName;
                    transactionLines.Qty         = transactionApi.returnOrderLines[i].quantity;
                    // transactionLines.Amount = transactionApi.transactionLines[i].subtotal;
                    _context.InventoryTransactionLines.Add(transactionLines);
                    await _context.SaveChangesAsync();
                }

                response.code    = "1";
                response.message = "Sucess Add Data";
                this.sequenceNumber(transactionApi);
            }
            else
            {
                response.code    = "0";
                response.message = "Transacion Number Already Exist";
                LogRecord log = new LogRecord();
                log.TimeStamp = DateTime.Now;
                log.Tag       = "Return Order";
                log.Message   = transactionApi.returnOrderId + "Aleader Exist";
                _context.LogRecord.Add(log);
                _context.SaveChanges();
            }
            return(Ok(response));
            //     return CreatedAtAction("GetTransaction", new { id = transaction.Id }, transaction);
        }
        public async Task <IActionResult> PostTransaction([FromBody] RequestOrder transactionApi)
        {
            APIResponse response = new APIResponse();

            try
            {
                Store store = _context.Store.Where(c => c.Code == transactionApi.storeCode).First();
                Models.InventoryTransaction transaction = new Models.InventoryTransaction();
                transaction.TransactionId       = transactionApi.requestOrderId;
                transaction.StoreCode           = transactionApi.storeCode;
                transaction.Remarks             = "";
                transaction.StoreName           = store.Name;
                transaction.TransactionTypeId   = RetailEnum.requestTransaction;
                transaction.TransactionTypeName = "Request";
                transaction.WarehouseOriginal   = store.WarehouseId;
                transaction.RequestDeliveryDate = DateTime.Now;
                transaction.TransactionDate     = DateTime.Now;//DateTime.ParseExact(transactionApi.date, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                transaction.TotalQty            = transactionApi.totalQty;
                transaction.Remarks             = "";
                transaction.Sjlama = transactionApi.oldSJ;
                try
                {
                    transaction.EmployeeCode = transactionApi.employeeId;
                    transaction.EmployeeName = transactionApi.employeeName;
                }
                catch { }


                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                //log record
                LogRecord log = new LogRecord();
                log.TimeStamp = DateTime.Now;
                log.Tag       = "Request Order";
                log.Message   = JsonConvert.SerializeObject(transactionApi);
                _context.LogRecord.Add(log);
                _context.InventoryTransaction.Add(transaction);
                await _context.SaveChangesAsync();

                //save Lines
                for (int i = 0; i < transactionApi.requestOrderLines.Count; i++)
                {
                    Models.InventoryTransactionLines transactionLines = new Models.InventoryTransactionLines();
                    transactionLines.InventoryTransactionId = transaction.Id;
                    transactionLines.ArticleId   = transactionApi.requestOrderLines[i].article.articleId;
                    transactionLines.ArticleName = transactionApi.requestOrderLines[i].article.articleName;
                    // transactionLines.price = transactionApi.transactionLines[i].price;
                    transactionLines.Qty = transactionApi.requestOrderLines[i].quantity;
                    // transactionLines.Amount = transactionApi.transactionLines[i].subtotal;
                    _context.InventoryTransactionLines.Add(transactionLines);
                    await _context.SaveChangesAsync();
                }
                response.code    = "1";
                response.message = "Sucess Add Data";
                // this.insertAndCalculateRO(transactionApi).Wait();

                WebAPIInforController.InforAPIController inforAPIController = new WebAPIInforController.InforAPIController(_context);
                inforAPIController.postRequestOrder(transactionApi, transaction.Id).Wait();
                this.sequenceNumber(transactionApi);
            }

            catch (Exception ex)
            {
                response.code    = "0";
                response.message = ex.ToString();
            }
            return(Ok(response));
            //     return CreatedAtAction("GetTransaction", new { id = transaction.Id }, transaction);
        }