Exemplo n.º 1
0
        public void delivered(string id)
        {
            string depCode = _context.DisbursementList.Find(id).DepartmentCode;
            List <RecordDetails> tempDisbursementListDetails = _context.RecordDetails.Where(s => s.Rrid == id).ToList();
            string dlID = b.IDGenerator("DL");

            foreach (var item in tempDisbursementListDetails)
            {
                string itemNo       = item.ItemNumber;
                int    qtyDelivered = item.QuantityDelivered;
                int    rdid         = item.Rdid;
                string remark       = item.Remark;
                if (qtyDelivered == 0)
                {
                    qtyDelivered = item.Quantity;
                }
                //generate a disbursement list if partial fulfilled
                if (qtyDelivered != item.Quantity)
                {
                    int qty = item.Quantity - qtyDelivered;
                    b.GenerateDisbursementListForPartialFulfillment(itemNo, qty, remark, depCode, dlID);
                }

                b.UpdateCatalogueOutAfterDelivery(itemNo, qtyDelivered);
                b.UpdateQuantityDeliveredAfterDelivery(qtyDelivered, rdid);

                int balance = _context.Catalogue.Find(itemNo).Stock;
                b.UpdateInventoryTransRecord(itemNo, id, -qtyDelivered, balance);
            }

            //update disbursement list status
            var disbursementList = _context.DisbursementList.Find(id);

            disbursementList.Status       = "Completed";
            disbursementList.CompleteDate = DateTime.Now;
            _context.DisbursementList.Update(disbursementList);
            _context.SaveChanges();

            //TempData["CorrectPassword"] = "******";

            return;
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Details(string id, int rowID, string itemNumber, int quantityDelivered, int quantityForVoucher, string remarkForDelivery, string remarkForVoucher, string confirmationPassword, int quantityDeliveredModalName, int addToVoucherModalName, int confirmDeliveryModalName, int noShowModalName, int backToListModalName)
        {
            ADTeam5User user = await _userManager.GetUserAsync(HttpContext.User);

            List <string> identity = userCheck.checkUserIdentityAsync(user);
            int           userID   = user.WorkID;

            //viewbag for status check
            ViewBag.DisbursementListStatus = _context.DisbursementList.FirstOrDefault(x => x.Dlid == id).Status;

            if (addToVoucherModalName == 1)
            {
                if (quantityForVoucher == 0)
                {
                    TempData["QuantityError"] = "Please select a quantity to add to voucher. Quantity cannot be 0.";
                    return(RedirectToAction("Details", new { id }));
                }
                else
                {
                    b.CreateNewVoucherItem(userID, itemNumber, quantityForVoucher, remarkForVoucher);
                }
            }
            else if (quantityDeliveredModalName == 1)
            {
                var q = _context.RecordDetails.Where(x => x.Rrid == id && x.ItemNumber == itemNumber).FirstOrDefault();
                int quantityNeeded = q.Quantity;
                if (quantityDelivered > quantityNeeded)
                {
                    TempData["ExcessError"] = "Quantity delivered cannot be greater than quantity requested. Please try again.";
                    return(RedirectToAction("Details", new { id }));
                }
                if (quantityDelivered < quantityNeeded && (remarkForDelivery == null || remarkForDelivery == ""))
                {
                    ViewData["InsufficientCheck"] = "true";
                    TempData["InsufficientError"] = "As quantity delivered is lesser than quantity requested, please key in remarks. Please try again.";
                    return(RedirectToAction("Details", new { id }));
                }
                foreach (DisbursementListDetails dlDetails in tempDisbursementListDetails)
                {
                    if (dlDetails.RowID == rowID)
                    {
                        dlDetails.QuantityDelivered = quantityDelivered;
                        dlDetails.Remark            = remarkForDelivery;
                    }
                }
            }
            else if (confirmDeliveryModalName == 1)
            {
                string depCode            = _context.DisbursementList.Find(id).DepartmentCode;
                string collectionPassword = _context.Department.Find(depCode).CollectionPassword;

                //check if password is correct
                if (confirmationPassword == collectionPassword)
                {
                    //update out quantity
                    string dlID = b.IDGenerator("DL");
                    foreach (var item in tempDisbursementListDetails)
                    {
                        string itemNo       = item.ItemNumber;
                        int    qtyDelivered = item.QuantityDelivered;
                        int    rdid         = item.RDID;
                        string remark       = item.Remark;

                        //generate a disbursement list if partial fulfilled
                        if (qtyDelivered != item.Quantity)
                        {
                            int qty = item.Quantity - qtyDelivered;
                            b.GenerateDisbursementListForPartialFulfillment(itemNo, qty, remark, depCode, dlID);
                        }

                        b.UpdateCatalogueOutAfterDelivery(itemNo, qtyDelivered);
                        b.UpdateQuantityDeliveredAfterDelivery(qtyDelivered, rdid);

                        int balance = _context.Catalogue.Find(itemNo).Stock;
                        b.UpdateInventoryTransRecord(itemNo, id, -qtyDelivered, balance);
                    }

                    //update disbursement list status
                    var disbursementList = _context.DisbursementList.Find(id);
                    disbursementList.Status       = "Completed";
                    disbursementList.CompleteDate = DateTime.Now;
                    _context.DisbursementList.Update(disbursementList);
                    _context.SaveChanges();

                    TempData["CorrectPassword"] = "******";

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    //check
                    //show incorrect password
                    TempData["IncorrectPassword"] = "******";
                }
            }
            else if (noShowModalName == 1)
            {
                //update disbursement list status
                var disbursementList = _context.DisbursementList.Find(id);
                disbursementList.Status       = "No Show";
                disbursementList.CompleteDate = DateTime.Now;
                _context.DisbursementList.Update(disbursementList);
                _context.SaveChanges();

                //update out and stock
                var itemToReturn = _context.RecordDetails.Where(x => x.Rrid == id);
                if (itemToReturn != null)
                {
                    foreach (var item in itemToReturn.ToList())
                    {
                        int quantityRequested = item.Quantity;
                        var q = _context.Catalogue.FirstOrDefault(x => x.ItemNumber == item.ItemNumber);
                        if (q != null)
                        {
                            int outQty   = q.Out;
                            int preStock = q.Stock;
                            //out number cannot be negative
                            if (outQty >= quantityRequested)
                            {
                                q.Stock = preStock + quantityRequested;
                                q.Out   = outQty - quantityRequested;
                            }
                            else
                            {
                                q.Stock = preStock + outQty;
                                q.Out   = 0;
                            }

                            _context.Catalogue.Update(q);
                            _context.SaveChanges();
                        }
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            else if (backToListModalName == 1)
            {
                return(RedirectToAction(nameof(Index)));
            }

            return(View(tempDisbursementListDetails));
        }