public async Task <IActionResult> Index(string[] itemSubmitted)
        {
            ADTeam5User user = await _userManager.GetUserAsync(HttpContext.User);

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

            dept = identity[0];
            role = identity[1];

            if (itemSubmitted.Length != 0)
            {
                rrid = b.IDGenerator(dept);
                foreach (var item in tempNewRequests)
                {
                    if (Array.Exists(itemSubmitted, i => i == item.ItemNumber.ToString()))
                    {
                        //add items to request
                        RecordDetails r = new RecordDetails();
                        r.Rrid              = rrid;
                        r.ItemNumber        = item.ItemNumber;
                        r.Quantity          = item.Quantity;
                        r.QuantityDelivered = 0;
                        _context.RecordDetails.Add(r);
                        _context.SaveChanges();
                    }
                }

                //check if item exists in record details
                var record = _context.RecordDetails.FirstOrDefault(x => x.Rrid == rrid);
                if (record != null)
                {
                    // Make new EmployeeRequestRecord
                    EmployeeRequestRecord e = new EmployeeRequestRecord();
                    DateTime requestDate    = DateTime.Now.Date;
                    int      empId          = userid;
                    var      findHeadId     = _context.Department.Where(x => x.DepartmentCode == dept).First();
                    int      headId         = findHeadId.HeadId;
                    string   deptCode       = dept;
                    string   status         = "Pending Approval";
                    e.Rrid        = rrid;
                    e.RequestDate = requestDate;
                    e.DepEmpId    = empId;
                    e.DepHeadId   = headId;
                    e.DepCode     = deptCode;
                    e.Status      = status;
                    _context.EmployeeRequestRecord.Add(e);
                    _context.SaveChanges();

                    TempData["Submitted"] = "New request has been created successfully!";
                }
            }

            tempNewRequests = new List <TempNewRequest>();
            List <RecordDetails> rdList = _context.RecordDetails.Where(x => x.Rrid == rrid).ToList();

            //return RedirectToAction("Details", new { id = rrid });
            return(Json(new { redirecturl = "NewRequest/Details/" + rrid }));
        }
Beispiel #2
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;
        }
        public async Task <IActionResult> Index(string itemNumber, int quantity, int rowID, string supplierCode, int createNewPOItemModalName, int POItemModalName, string[] itemSubmitted, string[] itemSavedToDraft)
        {
            ADTeam5User user = await _userManager.GetUserAsync(HttpContext.User);

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

            poNo = "";

            //handle post action
            List <TempPurchaseOrderDetails> tempPurchaseOrderDetailsList = b.GetTempPurchaseOrderDetailsList();

            if (createNewPOItemModalName == 1)
            {
                if (supplierCode == null || supplierCode == "")
                {
                    TempData["SupplierNameError"]      = "Purchase order was not successfully raised. Please try again.";
                    TempData["SupplierSelectionError"] = "Please select supplier.";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    b.CreateNewPOItem(userID, itemNumber, quantity, supplierCode);
                    return(RedirectToAction(nameof(Index)));
                }
            }
            else if (POItemModalName == 1)
            {
                if (supplierCode == null || supplierCode == "")
                {
                    TempData["SupplierNameError"]      = "Purchase order was not successfully raised. Please try again.";
                    TempData["SupplierSelectionError"] = "Please select supplier.";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    b.UpdatePOItem(userID, rowID, quantity, supplierCode, tempPurchaseOrderDetailsList);
                }
            }

            if (itemSubmitted.Length != 0)
            {
                //split supplier
                var supplier = tempPurchaseOrderDetailsList.GroupBy(x => x.SupplierCode).Select(y => y.Key);
                foreach (var s in supplier)
                {
                    poNo = b.IDGenerator("PO");
                    foreach (var item in tempPurchaseOrderDetailsList)
                    {
                        if (Array.Exists(itemSubmitted, i => i == item.RowID.ToString()) && item.SupplierCode == s)
                        {
                            b.AddItemsToPO(item.RowID, poNo, tempPurchaseOrderDetailsList);
                            b.CreatePurchaseOrderRecord(userID, poNo, s, "Pending Delivery");
                        }
                    }
                }

                //return through ajax
                return(Json(new { redirecturl = "PurchaseOrderRecords" }));
            }
            else if (itemSavedToDraft.Length != 0)
            {
                var supplier = tempPurchaseOrderDetailsList.GroupBy(x => x.SupplierCode).Select(y => y.Key);
                foreach (var s in supplier)
                {
                    poNo = b.IDGenerator("PO");
                    foreach (var item in tempPurchaseOrderDetailsList)
                    {
                        if (Array.Exists(itemSavedToDraft, i => i == item.RowID.ToString()))
                        {
                            b.AddItemsToPO(item.RowID, poNo, tempPurchaseOrderDetailsList);
                            b.CreatePurchaseOrderRecord(userID, poNo, s, "Draft");
                        }
                    }
                }
                //return RedirectToAction(nameof(Index));
                return(Json(new { redirecturl = "PurchaseOrderRecords" }));
            }

            List <TempPurchaseOrderDetails> result = b.GetTempPurchaseOrderDetailsList();

            //calculate order total amount by supplier


            //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));
        }
Beispiel #4
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));
        }
        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));
        }