public async Task <IActionResult> Index(string itemNumber, int quantityRetrieved, int quantityForVoucher, string remark, int quantityRetrievedModalName, int addToVoucherModalName)
        {
            ADTeam5User user = await _userManager.GetUserAsync(HttpContext.User);

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

            if (itemNumber == null)
            {
                return(NotFound());
            }

            if (addToVoucherModalName == 1)
            {
                if (quantityForVoucher == 0)
                {
                    TempData["QuantityError"] = "Please select a quantity to add to voucher. Quantity cannot be 0.";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    b.CreateNewVoucherItem(userID, itemNumber, quantityForVoucher, remark);
                }
            }
            else if (quantityRetrievedModalName == 1)
            {
                var stockCheck = _context.Catalogue.Where(x => x.ItemNumber == itemNumber).FirstOrDefault();
                int stockAmt   = stockCheck.Stock + stockCheck.Out;

                if (quantityRetrieved > stockAmt)
                {
                    TempData["InsufficientStock"] = "Stock level: " + stockAmt + ". There is insufficient stock. Please select a quantity less than or equals to stock level.";
                }
                else
                {
                    b.UpdateCatalogueOutAndStockAfterRetrieval(itemNumber, quantityRetrieved);
                }
            }

            List <StationeryRetrievalList> result = b.GetStationeryRetrievalLists();

            return(View(result));
        }
        public async Task <IActionResult> Details(string id, string itemNumber, int quantity, int rowID, string remark, int createNewVoucherItemModalName, int voucherItemModalName, string itemSubmitted, string itemSavedToDraft, string rejectVoucher, string approveBySup, string approveByMan)
        {
            ADTeam5User user = await _userManager.GetUserAsync(HttpContext.User);

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

            if (id == null)
            {
                return(NotFound());
            }

            //ViewBag for voucher price
            decimal?amount = b.GetTotalAmountForVoucher(id);
            decimal?GST    = Math.Round((decimal)(amount * (decimal?)0.07), 2);

            ViewBag.Amount      = amount;
            ViewBag.GST         = GST;
            ViewBag.TotalAmount = amount + GST;

            //ViewData for voucherNo
            ViewData["VoucherNo"] = id;

            //handle post action
            List <AdjustmentRecordDetails> adjustmentRecordDetailsList = b.GetAdjustmentRecordDetails(id);

            if (createNewVoucherItemModalName == 1)
            {
                b.CreateNewVoucherItem(userID, id, itemNumber, quantity, remark);
                return(RedirectToAction(nameof(Details)));
            }
            else if (voucherItemModalName == 1)
            {
                b.UpdateVoucherItem(rowID, quantity, remark, adjustmentRecordDetailsList);
            }

            if (itemSubmitted == "1")
            {
                //changestatus to pending approval
                b.UpdateRecordStatus("Pending Approval", "AdjustmentRecord", id);
                return(RedirectToAction(nameof(Index)));
            }
            else if (itemSavedToDraft == "1")
            {
                //change status to draft
                b.UpdateRecordStatus("Draft", "AdjustmentRecord", id);
                return(RedirectToAction(nameof(Index)));
            }

            if (rejectVoucher == "1")
            {
                var ar = _context.AdjustmentRecord.FirstOrDefault(x => x.VoucherNo == id);
                if (ar != null)
                {
                    //changestatus to reject
                    b.RejectVoucher(userID, userRole, id);
                }
                return(RedirectToAction(nameof(Index)));
            }
            else if (approveBySup == "1")
            {
                //change status to draft
                b.ApproveVoucher(userID, userRole, id);
                return(RedirectToAction(nameof(Index)));
            }
            else if (approveByMan == "1")
            {
                //change status to draft
                b.ApproveVoucher(userID, userRole, id);
                return(RedirectToAction(nameof(Index)));
            }

            //Viewbag for category dropdown list, need to post back
            List <Catalogue> categoryList = new List <Catalogue>();
            var q = _context.Catalogue.GroupBy(x => new { x.Category }).Select(x => x.FirstOrDefault());

            foreach (var item in q)
            {
                categoryList.Add(item);
            }
            categoryList.Insert(0, new Catalogue {
                ItemNumber = "0", Category = "---Select Category---"
            });
            ViewBag.ListofCategory = categoryList;

            //ViewBag for record status
            ViewBag.AdjustmentRecordStatus = _context.AdjustmentRecord.FirstOrDefault(x => x.VoucherNo == id).Status;

            List <AdjustmentRecordDetails> result = b.GetAdjustmentRecordDetails(id);

            return(View(result));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Index(string itemNumber, int quantity, int rowID, string remark, int createNewVoucherItemModalName, int voucherItemModalName, string[] itemSubmitted, string[] itemSavedToDraft)
        {
            ADTeam5User user = await _userManager.GetUserAsync(HttpContext.User);

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

            voucherNo = "";


            //handle post action
            List <TempVoucherDetails> tempVoucherDetailsList = b.GetTempVoucherDetailsList(userID);

            if (createNewVoucherItemModalName == 1)
            {
                if (quantity == 0)
                {
                    TempData["QuantityError"] = "Please select a quantity to add to voucher. Quantity cannot be 0.";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    b.CreateNewVoucherItem(userID, itemNumber, quantity, remark);
                    return(RedirectToAction(nameof(Index)));
                }
            }
            else if (voucherItemModalName == 1)
            {
                b.UpdateVoucherItem(rowID, quantity, remark, tempVoucherDetailsList);
            }

            if (itemSubmitted.Length != 0)
            {
                voucherNo = b.IDGenerator("V");
                foreach (var item in tempVoucherDetailsList)
                {
                    if (Array.Exists(itemSubmitted, i => i == item.RowID.ToString()))
                    {
                        b.AddItemsToVoucher(item.RowID, voucherNo, tempVoucherDetailsList);
                    }
                }
                b.CreateAdjustmentRecord(userID, voucherNo, "Pending Approval");

                //send notification email to Head of stationery department

                var boss = (from x in _context.User
                            join y in _context.Department
                            on x.UserId equals y.RepId
                            where y.DepartmentCode == "STAS"
                            select new
                {
                    email = x.EmailAddress,
                    name = x.Name
                }).First();

                string email = boss.email;
                await _emailSender.SendEmailAsync(email, "New Adjustment Voucher Pending Approval", "Dear " + boss.name + ",<br>There is a new adjustment voucher that needs your approval.<br><br>-- (Automated email, no reply required) --");

                return(Json(new { redirecturl = "AdjustmentRecords/Details/" + voucherNo }));
            }
            else if (itemSavedToDraft.Length != 0)
            {
                voucherNo = b.IDGenerator("V");
                foreach (var item in tempVoucherDetailsList)
                {
                    if (Array.Exists(itemSavedToDraft, i => i == item.RowID.ToString()))
                    {
                        b.AddItemsToVoucher(item.RowID, voucherNo, tempVoucherDetailsList);
                    }
                }
                b.CreateAdjustmentRecord(userID, voucherNo, "Draft");
                //return RedirectToAction(nameof(Index));
                return(Json(new { redirecturl = "AdjustmentRecords/Details/" + voucherNo }));
            }

            List <TempVoucherDetails> result = b.GetTempVoucherDetailsList(userID);

            //Viewbag for category dropdown list, need to post back
            List <Catalogue> categoryList = new List <Catalogue>();
            var q = _context.Catalogue.GroupBy(x => new { x.Category }).Select(x => x.FirstOrDefault());

            foreach (var item in q)
            {
                categoryList.Add(item);
            }
            categoryList.Insert(0, new Catalogue {
                ItemNumber = "0", Category = "---Select Category---"
            });
            ViewBag.ListofCategory = categoryList;
            return(View(result));
        }