public bool ProcessStockAdjustmentEntry(Staff staff) { UnitOfWork uow = new UnitOfWork(); if (HttpContext.Current.Session["AdjustmentCart"] == null) { return(false); } AdjustmentVoucherVM Voucher = (AdjustmentVoucherVM)HttpContext.Current.Session["AdjustmentCart"]; AdjustmentVoucher adjustmentVoucher = new AdjustmentVoucher(Voucher, uow, staff); if (uow.StockCardEntryRepository.ProcessAdjustmentVoucher(adjustmentVoucher)) { uow.AdjustmentVoucherRepository.Insert(adjustmentVoucher); uow.Save(); Debug.WriteLine("Adjustment Voucher inserted successfully into DB"); //Update the respective inventory item foreach (AdjustmentItemVM adjustment in Voucher.AdjustmentItems) { if (!UpdateInStoreQty(adjustment.ItemID)) { Debug.WriteLine("Update In Store Qty failed for" + adjustment.ItemID); } } return(true); } return(false); }
public ActionResult SaveAdjustments([Bind(Include = "AdjustmentID,ReportedByStaffName,ReportedByStaffID,Status,AdjustmentItems")] AdjustmentVoucherVM AdjustmentVM, string change) { Debug.WriteLine("Saving adjustments cart via ajax..."); Debug.WriteLine(Server.UrlDecode(change)); for (int i = 0; i < change.Split('&').Count(); i++) { string changestr = change.Split('&')[i]; if (i % 2 == 0) { string qty = Server.UrlDecode(changestr.Split('=')[1]); if (int.TryParse(qty, out int output)) { AdjustmentVM.AdjustmentItems[i / 2].QtyAdjusted = output; Debug.WriteLine(AdjustmentVM.AdjustmentItems[i / 2].QtyAdjusted); } } else { string remarks = Server.UrlDecode(changestr.Split('=')[1]); AdjustmentVM.AdjustmentItems[i / 2].Remarks = remarks; Debug.WriteLine(AdjustmentVM.AdjustmentItems[i / 2].Remarks); } } Session["AdjustmentCart"] = AdjustmentVM; return(Content("")); }
public static void addItemToAdjustmentCart(AdjustmentItemVM ItemToAdd) { if (HttpContext.Current.Session["AdjustmentCart"] == null) { HttpContext.Current.Session["AdjustmentCart"] = new AdjustmentVoucherVM(); } AdjustmentVoucherVM Voucher = (AdjustmentVoucherVM)HttpContext.Current.Session["AdjustmentCart"]; Voucher.AdjustmentItems.Add(ItemToAdd); }
public AdjustmentVoucherVM GetAdjustmentVoucherVMSingle(int id) { AdjustmentVoucher voucher = uow.AdjustmentVoucherRepository.Get(filter: x => x.ID == id, includeProperties: "CreatedByStaff,DocumentItems.Item").FirstOrDefault(); if (voucher == null) { return(null); } AdjustmentVoucherVM vM = new AdjustmentVoucherVM(voucher); return(vM); }
public List <AdjustmentVoucherVM> GetAdjVoucherByClerk(int clerkId) { List <AdjustmentVoucherVM> voucherList = new List <AdjustmentVoucherVM>(); SqlDataReader reader = null; try { connection.Open(); string sql = " SELECT av.Date,av.Status,av.VoucherID,SUM(ABS(iav.Qty)) TotalQuantity " + " FROM AdjustmentVoucher av, ItemAdjVoucher iav " + " WHERE av.VoucherID = iav.VoucherID " + " AND av.EmployeeID = @clerkId " + " GROUP BY av.VoucherID,av.Date,av.Status "; SqlCommand cmd = new SqlCommand(sql, connection); cmd.Parameters.AddWithValue("@clerkId", clerkId); AdjustmentVoucherVM adjVM = null; reader = cmd.ExecuteReader(); while (reader.Read()) { adjVM = new AdjustmentVoucherVM() { Id = (int)reader["VoucherID"], Date = (DateTime)reader["Date"], Status = reader["Status"].ToString(), TotalQuantity = (int)reader["TotalQuantity"] }; voucherList.Add(adjVM); } } catch (Exception e) { return(null); } finally { if (reader != null) { reader.Close(); } connection.Close(); } voucherList = voucherList.OrderByDescending(x => x.Id).ToList(); return(voucherList); }
public ActionResult RemoveAdjustment(int?index) { AdjustmentVoucherVM adjustmentCart = (AdjustmentVoucherVM)Session["AdjustmentCart"]; if (adjustmentCart != null && index.HasValue) { Debug.WriteLine("Removing item " + index.Value + "from adjustment cart"); adjustmentCart.AdjustmentItems.RemoveAt(index.Value); if (adjustmentCart.AdjustmentItems.Count == 0) { Session.Remove("AdjustmentCart"); } } return(RedirectToAction("Adjustment", new { command = "view" })); }
public static bool VerifyAdjustmentCart() { if (HttpContext.Current.Session["AdjustmentCart"] == null) { return(false); } AdjustmentVoucherVM Voucher = (AdjustmentVoucherVM)HttpContext.Current.Session["AdjustmentCart"]; foreach (AdjustmentItemVM item in Voucher.AdjustmentItems) { if (item.QtyAdjusted.Equals(0)) { return(false); } } return(true); }
public AdjustmentVoucher(AdjustmentVoucherVM AVM, UnitOfWork uow, Staff staff) : base() { if (AVM == null) { return; } CreatedByStaff = staff; List <DocumentItem> documentItems = new List <DocumentItem>(); foreach (AdjustmentItemVM AItemVm in AVM.AdjustmentItems) { Item item = uow.ItemRepository.GetByID(AItemVm.ItemID); DocumentItem documentItem = new DocumentItem(item, AItemVm.QtyAdjusted); documentItem.Remarks = AItemVm.Remarks; documentItems.Add(documentItem); } DocumentItems = documentItems; }
public ActionResult Adjustment(int?id, string item = "", string command = "") { if (!LoginService.IsAuthorizedRoles("manager", "supervisor", "clerk")) { return(RedirectToAction("Index", "Home")); } if (command == "add" && item != "") { Debug.WriteLine("adding adjusted item to adjustment cart = " + item); InventoryService.addItemToAdjustmentCart(new AdjustmentItemVM(item)); return(RedirectToAction("Adjustment", new { command = "view" })); } else if (command == "view" && item == "") { Debug.WriteLine("viewing adjustment cart"); if (Session["AdjustmentCart"] == null) { ViewBag.Empty = "true"; return(View("AdjustmentVoucherNew")); } else { ViewBag.ErrorMsg = TempData["ErrorMsg"]; AdjustmentVoucherVM adjustmentCart = (AdjustmentVoucherVM)Session["AdjustmentCart"]; return(View("AdjustmentVoucherNew", adjustmentCart)); } } else if (id.HasValue) { AdjustmentVoucherVM VM = InventoryService.GetAdjustmentVoucherVMSingle(id.Value); if (VM != null) { if (LoginService.IsAuthorizedRoles("manager", "supervisor")) { ViewBag.IsSuper = true; } return(View("AdjustmentVoucher", VM)); } } //redirect to AV list return(View("AdjustmentList", InventoryService.GetAdjustmentVoucherVMList())); }
public List <AdjustmentVoucherVM> GetByStatus(string status) { List <AdjustmentVoucher> voucherList = new List <AdjustmentVoucher>(); AdjustmentVoucher av = null; List <ItemAdjVoucher> itemVoucherList = new List <ItemAdjVoucher>(); ItemAdjVoucher iav = null; List <Item> itemList = new List <Item>(); Item i = null; List <Employee> employeeList = new List <Employee>(); Employee employee = null; string sql = "SELECT av.*, iav.ID AS [ItemAdjID], iav.ItemID, iav.VoucherID AS [ItemAdjVoucherID], iav.Qty, iav.Reason, i.*, e.ID AS [EmpId], e.Name AS [EmpName] " + "FROM AdjustmentVoucher av, Item i, ItemAdjVoucher iav, Employee e " + "WHERE av.VoucherID = iav.VoucherID " + "AND av.Status=@value " + "AND e.ID = av.EmployeeID " + "AND iav.ItemID = i.ID"; SqlCommand cmd = new SqlCommand(sql, connection); cmd.Parameters.Add("@value", SqlDbType.VarChar); cmd.Parameters["@value"].Value = status; connection.Open(); SqlDataReader data = cmd.ExecuteReader(); while (data.Read()) { av = new AdjustmentVoucher() { Id = Convert.ToInt32(data["VoucherID"]), EmployeeId = Convert.ToInt32(data["EmployeeID"]), Date = Convert.ToDateTime(data["Date"]), Status = data["Status"].ToString() }; iav = new ItemAdjVoucher() { Id = Convert.ToInt32(data["ItemAdjVoucherID"]), ItemId = data["ItemID"].ToString(), VoucherId = Convert.ToInt32(data["ItemAdjVoucherID"]), Quantity = Convert.ToInt32(data["Qty"]), Reason = data["Reason"].ToString() }; i = new Item() { Id = data["ID"].ToString(), CategoryId = Convert.ToInt32(data["CategoryID"]), Description = data["Description"].ToString(), ThresholdValue = Convert.ToInt32(data["ThresholdValue"]), ReorderQty = Convert.ToInt32(data["ReorderQty"]), Uom = data["UOM"].ToString(), BinNo = data["BinNo"].ToString(), FirstSupplier = data["FirstSupplier"].ToString(), FirstPrice = Convert.ToDouble(data["FirstPrice"]), SecondSupplier = data["SecondSupplier"].ToString(), SecondPrice = Convert.ToDouble(data["SecondPrice"]), ThirdSupplier = data["ThirdSupplier"].ToString(), ThirdPrice = Convert.ToDouble(data["ThirdPrice"]), }; employee = new Employee() { Id = Convert.ToInt32(data["EmpId"]), Name = data["EmpName"].ToString() }; voucherList.Add(av); itemVoucherList.Add(iav); itemList.Add(i); employeeList.Add(employee); } data.Close(); connection.Close(); List <Item> itemsAbove250 = new List <Item>(); itemsAbove250 = itemList.Where(x => (x.FirstPrice + x.SecondPrice + x.ThirdPrice) / 3 >= 250).ToList(); List <AdjustmentVoucherVM> vouchersVMList = new List <AdjustmentVoucherVM>(); AdjustmentVoucherVM voucherVM = null; List <int> voucherIdsForManager = (from voucherDetail in itemVoucherList join items in itemsAbove250 on voucherDetail.ItemId equals items.Id select voucherDetail.VoucherId).Distinct().ToList(); foreach (int id in voucherIdsForManager) { voucherList.RemoveAll(x => x.Id == id); } voucherList = voucherList.GroupBy(x => x.Id) .Select(y => y.First()) .ToList(); foreach (AdjustmentVoucher voucher in voucherList) { employee = employeeList.Find(x => x.Id == voucher.EmployeeId); voucherVM = new AdjustmentVoucherVM() { Name = employee.Name, Id = voucher.Id, Date = voucher.Date, Status = voucher.Status, TotalQuantity = itemVoucherList.Where(x => x.VoucherId == voucher.Id) .Sum(y => y.Quantity) }; vouchersVMList.Add(voucherVM); } return(vouchersVMList); }