protected void BtnProcess_Click(object sender, EventArgs e) { try { foreach (GridViewRow row in gvActionSummary.Rows) { int discID = Int32.Parse((row.FindControl("lblDiscID") as Label).Text); string action = (row.FindControl("lblAction") as Label).Text; Discrepency d = EFBroker_Discrepancy.GetDiscrepancyById(discID); if (d.Status == "Monthly") { if (action == "Approved") { List <Discrepency> dList = EFBroker_Discrepancy.GetPendingDiscrepanciesByItemCode(d.ItemCode); foreach (Discrepency d2 in dList) { if (d2.DiscrepencyID < d.DiscrepencyID) { //Negating discrepancies reported before the monthly discrepancy after it is approved EFBroker_Discrepancy.ProcessDiscrepancy(d2.DiscrepencyID, "Resolved"); } } } } EFBroker_Discrepancy.ProcessDiscrepancy(discID, action); if (action == "Approved") { //only update stock card and item tables if discrepancy is approved StockCard sc = new StockCard(); StockCard lastEntry = EFBroker_StockCard.GetStockCardsByItemCode(d.ItemCode).Last(); sc.ItemCode = d.ItemCode; sc.TransactionType = "Adjustment"; sc.Qty = d.AdjustmentQty; sc.Balance = lastEntry.Balance + d.AdjustmentQty; sc.TransactionDetailID = d.DiscrepencyID; EFBroker_StockCard.ResolveDiscrepancy(sc, sc.ItemCode, (int)sc.Balance); } } Session["discrepancySummary"] = null; Utility.AlertMessageThenRedirect("Adjustments processed", "StockAdjustment.aspx"); } catch (Exception ex) { Session["discrepancySummary"] = null; Utility.AlertMessageThenRedirect("Failed to process adjustments, please try again", "StockAdjustment.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { string itemCode = Request.QueryString["itemCode"]; string adjustment = "Adjustment"; //strings for stock card transaction type string disbursement = "Disbursement"; string purchase = "Purchase"; if (!ValidatorUtil.isEmpty(itemCode)) { Item item = EFBroker_Item.GetItembyItemCode(itemCode); string currentYear = DateTime.Now.Year.ToString(); List <PriceList> plList = EFBroker_PriceList.GetPriceListByItemCode(itemCode).Where(c => c.TenderYear == currentYear).ToList(); if (item != null && plList.Count > 0) { lblItemCode.Text = item.ItemCode; lblItemName.Text = item.Description; lblBin.Text = item.Bin; lblUom.Text = item.UnitOfMeasure; foreach (PriceList pl in plList) { switch (pl.SupplierRank) { case 1: lblSupp1.Text = pl.SupplierCode; break; case 2: lblSupp2.Text = pl.SupplierCode; break; case 3: lblSupp3.Text = pl.SupplierCode; break; } } if (plList.Count < 3) // N/A on supplier labels if there are less than 3 suppliers { lblSupp3.Text = "N/A"; if (plList.Count < 2) { lblSupp2.Text = "N/A"; } } List <StockCard> scList = EFBroker_StockCard.GetStockCardsByItemCode(itemCode); List <StockCardDisplayRow> scDisplayList = new List <StockCardDisplayRow>(); foreach (StockCard sc in scList) { if (sc.TransactionType == adjustment || sc.TransactionType == disbursement || sc.TransactionType == purchase) { //Possible to display 3 types of stock card entries (each accessing different tables) StockCardDisplayRow scdr = new StockCardDisplayRow(); if (sc.TransactionType == adjustment) { Discrepency d = EFBroker_Discrepancy.GetDiscrepancyById((int)sc.TransactionDetailID); scdr.TransDate = ((DateTime)d.Date).ToShortDateString(); scdr.TransDetails = "Adjustment ID. " + sc.TransactionDetailID; scdr.Quantity = "ADJ " + GetQuantityString((int)sc.Qty); } else if (sc.TransactionType == purchase) { PurchaseOrder po = EFBroker_PurchaseOrder.GetPurchaseOrderById((int)sc.TransactionDetailID); scdr.TransDate = ((DateTime)po.ExpectedDate).ToShortDateString(); scdr.TransDetails = "Supplier - " + po.SupplierCode; Item_PurchaseOrder ipo = EFBroker_PurchaseOrder.GetPurchaseOrderItem(po.PurchaseOrderID, itemCode); scdr.Quantity = GetQuantityString((int)sc.Qty); } else if (sc.TransactionType == disbursement) { Disbursement db = EFBroker_Disbursement.GetDisbursmentbyDisbID((int)sc.TransactionDetailID); scdr.TransDate = ((DateTime)db.CollectionDate).ToShortDateString(); scdr.TransDetails = EFBroker_DeptEmployee.GetDepartByDepCode(db.DeptCode).DeptName; scdr.Quantity = GetQuantityString((int)sc.Qty); } scdr.Balance = (int)sc.Balance; scDisplayList.Add(scdr); } } gvTransactions.DataSource = scDisplayList; gvTransactions.DataBind(); } else //if item is not found or no entries found in price list table { Response.Redirect(LoginController.StationeryCatalogueURI); } } else //if there is no itemCode in querystring { Response.Redirect(LoginController.StationeryCatalogueURI); } }