public ActionResult StockCard(long itemId, string sessionId)
 {
     ViewData["catalogue"]  = CatalogueService.GetCatalogueById(itemId);
     ViewData["priceList"]  = PriceListService.GetPriceListByItemId(itemId);
     ViewData["stockCards"] = StockCardService.GetStockCardById(itemId);
     ViewData["sessionId"]  = sessionId;
     return(View());
 }
Пример #2
0
        public ActionResult ConfirmClose(PurchaseOrder orderToClose, FormCollection formCollection, string sessionId)
        {
            PurchaseOrder order = PurchaseOrderService.GetOrderDetails(orderToClose.OrderNumber);

            List <int>  itemsQuantities = new List <int>();
            List <long> itemIds         = new List <long>();

            for (int i = 0; i < order.ItemDetails.Count; i++)
            {
                itemsQuantities.Add(int.Parse(formCollection["quantity_" + i]));
                itemIds.Add(long.Parse(formCollection["item_" + i]));
            }

            /*The following code is for StockCard table*/
            //By the time close order, update StockCard table with itemId, deptId and date, souceType = 3
            StockCardService.CreateStockCardFromOrder(order, itemIds, itemsQuantities);

            //SET status to close and update quantities (if any) accordingly
            //Stock level is also updated accordingly
            PurchaseOrderService.ClosePurchaseOrder(order, itemIds, itemsQuantities);

            //Inform Purchasing Dept
            if (order.SupplierId != long.Parse(formCollection["itemSupplierId"]))
            {
                EmailNotification notice    = new EmailNotification();
                long       purchasingDeptId = DepartmentService.GetDeptIdByName("Purchasing Department");
                Department dept             = DepartmentService.GetDepartmentById(purchasingDeptId);
                notice.Dept = dept;

                long repId = DepartmentService.GetCurrentRep(purchasingDeptId);
                notice.ReceiverMailAddress = EmployeeService.GetUserEmail(repId);

                notice.Order = PurchaseOrderService.GetOrderDetails(order.OrderNumber);;
                EmailService emailService = new EmailService();
                Task.Run(() => emailService.SendMail(notice, EmailTrigger.ON_ALTERNATIVE_SUPPLIER));
            }

            return(RedirectToAction("All", new { sessionid = sessionId }));
        }
        /*
         * public ActionResult Generate(List<Inventory> inventories, string sessionId)
         * {
         *  long adjId = (long)AdjVoucherService.GetLastId() + 1;
         *  int flag = 0;
         *  foreach (Inventory inventory in inventories)
         *  {
         *      int qty = inventory.ActualStock - inventory.StockLevel;
         *      if (qty != 0)
         *      {
         *          flag = 1;
         *          AdjVoucherService.CreateAdjVoucher(adjId, inventory.ItemId, qty);
         *          StockService.UpdateInventoryStockById(inventory.ItemId, inventory.ActualStock);
         *      }
         *  }
         *  if(flag == 0)
         *  {
         *      TempData["errorMsg"] = "<script>alert('There are no discrepancies in stock.');</script>";
         *      ViewData["userName"] = EmployeeService.GetUserBySessionId(sessionId).EmpName;
         *      ViewData["sessionId"] = sessionId;
         *      return View("~/Views/StoreLandingPage/Home.cshtml");
         *  }
         *
         *
         *  return RedirectToAction("PutReason", new { sessionId});
         * }*/


        public ActionResult Generate(Inventory item, FormCollection formCollection, string sessionId)
        {
            List <int>  itemsQuantities = new List <int>();
            List <long> itemIds         = new List <long>();
            long        adjId           = (long)AdjVoucherService.GetLastId() + 1;
            int         flag            = 0;

            string counter = formCollection["counter"];

            for (int i = 0; i < int.Parse(counter); i++)
            {
                int actualStock = int.Parse(formCollection["actualStock_" + i]);
                int lastStock   = int.Parse(formCollection["lastStock_" + i]);
                int qty         = actualStock - lastStock;
                if (qty != 0)
                {
                    flag = 1;
                    long itemId = long.Parse(formCollection["itemId_" + i]);
                    AdjVoucherService.CreateAdjVoucher(adjId, itemId, qty);

                    //Update Inventory with new stock level
                    StockService.UpdateInventoryStockById(itemId, actualStock);
                    //The function below is for update stock card
                    //By the time authorise adjustment voucher, update StockCard table with itemId and date, souceType = 1
                    StockCardService.CreateStockCardFromAdj(adjId, itemId, qty);
                }
            }
            if (flag == 0)
            {
                TempData["errorMsg"]  = "<script>alert('There are no discrepancies in stock.');</script>";
                ViewData["userName"]  = EmployeeService.GetUserBySessionId(sessionId).EmpName;
                ViewData["sessionId"] = sessionId;
                return(View("~/Views/StoreLandingPage/Home.cshtml"));
            }
            return(RedirectToAction("PutReason", new { sessionId }));
        }