示例#1
0
        public ActionResult CreateAdjustmentVoucher(string voucherId)
        {
            List <AdjustmentVoucherDetailsDTO> detailsList = new List <AdjustmentVoucherDetailsDTO>();

            if (voucherId != null)
            {
                AdjustmentVoucherEF voucher = stockService.FindAdjustmentVoucherById(voucherId);
                var baseDetailsList         = stockService.FindAdjustmentDetailsById(voucherId);
                foreach (var d in baseDetailsList)
                {
                    AdjustmentVoucherDetailsDTO toAdd = new AdjustmentVoucherDetailsDTO();
                    toAdd.ItemCode    = d.ItemCode;
                    toAdd.Quantity    = d.Quantity;
                    toAdd.Reason      = d.Reason;
                    toAdd.Description = d.Stock.Description;
                    toAdd.Remove      = false;

                    detailsList.Add(toAdd);
                }

                detailsList         = stockService.GetPricesForVoucherDetails(detailsList);
                ViewData["voucher"] = voucher;
            }
            List <StockEF> itemList = stockService.FindAllStocks().OrderBy(x => x.ItemCode).ToList();

            ViewData["itemList"] = itemList;

            return(View(detailsList));
        }
示例#2
0
        public List <AdjustmentVoucherDetailsDTO> ConvertAdjVoucherDetailsToDTO(List <AdjustmentVoucherDetailsEF> detailsList)
        {
            List <AdjustmentVoucherDetailsDTO> dtoList = new List <AdjustmentVoucherDetailsDTO>();

            foreach (var d in detailsList)
            {
                AdjustmentVoucherDetailsDTO newItem = new AdjustmentVoucherDetailsDTO();
                List <SupplierDetailsEF>    items   = purchaseEFF.FindSupplierDetailsByItemCode(d.ItemCode);
                newItem.Price       = items.Average(x => x.UnitPrice);
                newItem.ItemCode    = d.ItemCode;
                newItem.Quantity    = d.Quantity;
                newItem.Reason      = d.Reason;
                newItem.Description = d.Stock.Description;

                dtoList.Add(newItem);
            }
            return(dtoList);
        }
示例#3
0
        public ActionResult CreateAdjustmentVoucher(string itemToAdd, string removalItem, string choice, string voucherId, List <AdjustmentVoucherDetailsDTO> detailsList)
        {
            List <StockEF> itemList = stockService.FindAllStocks().OrderBy(x => x.ItemCode).ToList();

            ViewData["itemList"] = itemList;

            AdjustmentVoucherEF voucher = new AdjustmentVoucherEF();

            if (voucherId == null)
            {
                voucher = new AdjustmentVoucherEF();
            }
            else
            {
                voucher = stockService.FindAdjustmentVoucherById(voucherId);
            }
            ViewData["voucher"] = voucher;

            if (detailsList == null)
            {
                detailsList = new List <AdjustmentVoucherDetailsDTO>();
            }
            if (choice == "Add Item")
            {
                StockEF item        = new StockEF();
                bool    isValid     = false;
                string  description = "";
                //check if in the existing stock
                foreach (var v in itemList)
                {
                    if (v.ItemCode == itemToAdd)
                    {
                        description = v.Description;
                        isValid     = true;
                    }
                }
                if (isValid)
                {
                    AdjustmentVoucherDetailsDTO newVoucherDetails = new AdjustmentVoucherDetailsDTO();
                    newVoucherDetails.ItemCode    = itemToAdd;
                    newVoucherDetails.Description = description;
                    newVoucherDetails.Quantity    = 1;
                    newVoucherDetails.Remove      = false;
                    detailsList.Add(newVoucherDetails);
                }
            }
            if (choice == "Remove" && detailsList.Count > 0)
            {
                for (int i = 0; i < detailsList.Count; i++)
                {
                    if (detailsList[i].Remove == true)
                    {
                        detailsList.RemoveAt(i);
                        i--;
                    }
                }
            }
            if (choice == "Submit")
            {
                StaffEF requester = staffService.GetStaff();
                string  newId     = "";
                List <AdjustmentVoucherDetailsDTO> QOHValid = stockService.checkQuantityOnHand(detailsList);

                if (QOHValid.Count == 0)
                {
                    if (stockService.VoucherExceedsSetValue(detailsList))
                    {
                        newId = stockService.SaveAdjustmentVoucherAndDetails(requester, voucher, detailsList, "Manager");
                        Debug.Print("Pending appr sent to manager email");
                        SendEmailToAuthorityOnRequest(voucher.VoucherId, "Manager");
                    }
                    else if (!stockService.VoucherExceedsSetValue(detailsList))
                    {
                        newId = stockService.SaveAdjustmentVoucherAndDetails(requester, voucher, detailsList, "Supervisor");
                        Debug.Print("Pending appr sent to supervisor email");
                        SendEmailToAuthorityOnRequest(voucher.VoucherId, "Supervisor");
                    }
                    return(RedirectToAction("ViewAdjustmentDetails", "ManageAdjustmentVoucher", new { voucherId = newId }));
                }
                else
                {
                    ViewData["invalidItems"] = QOHValid;
                }
            }
            if (choice == "Cancel")
            {
                return(RedirectToAction("Index", "ManageAdjustmentVoucher", new { page = 1 }));
            }

            //get prices for each item
            detailsList = stockService.GetPricesForVoucherDetails(detailsList);

            ModelState.Clear();
            return(View(detailsList));
        }