/// <summary> /// Saves the receiving unit related information /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnIssueSave_Click(object sender, EventArgs e) { if(txtReceivingUnit.Text=="") { XtraMessageBox.Show("Please enter the name of the receiving unit", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ReceivingUnits recUnit = new ReceivingUnits(); if (_receivingUnitId != 0) { recUnit.LoadByPrimaryKey(_receivingUnitId); recUnit.Name = txtReceivingUnit.Text; recUnit.Phone = txtPhone.Text; recUnit.Description = memoEdit1.Text; recUnit.IsActive = chkIsDispensaryActive.Checked; recUnit.Min = Convert.ToDouble(cboDUMin.SelectedValue); recUnit.Max = Convert.ToDouble(cboDUMax.SelectedValue); recUnit.Woreda = txtWoreda.Text; recUnit.Region = txtRegion.Text; recUnit.Zone = txtZone.Text; recUnit.FacilityType = txtType.Text; recUnit.Save(); //recUnit.Save(); XtraMessageBox.Show("Issue Location Record Updated.", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { recUnit.AddNew(); recUnit.Name = txtReceivingUnit.Text; recUnit.Phone = txtPhone.Text; recUnit.Description = memoEdit1.Text; recUnit.IsActive = chkIsDispensaryActive.Checked; recUnit.Min = Convert.ToDouble(cboDUMin.SelectedValue); recUnit.Max = Convert.ToDouble(cboDUMax.SelectedValue); recUnit.Woreda = txtWoreda.Text; recUnit.Region = txtRegion.Text; recUnit.Zone = txtZone.Text; recUnit.FacilityType = txtType.Text; recUnit.Save(); recUnit.LoadAll(); PopulateReceivingUnit(recUnit); ResetIssuesLocation(); XtraMessageBox.Show("Issue Location Record Saved.", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Handles the Index Changed event of the receiving unit list box /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lstReceivingUnit_SelectedIndexChanged(object sender, EventArgs e) { if (lstReceivingUnit.SelectedItems.Count > 0) { int selected = Convert.ToInt32(lstReceivingUnit.SelectedItems[0].Tag); ReceivingUnits recUnit = new ReceivingUnits(); recUnit.LoadByPrimaryKey(selected); txtReceivingUnit.Text = recUnit.Name; memoEdit1.Text = recUnit.Description; txtPhone.Text = recUnit.Phone; txtWoreda.Text = recUnit.Woreda; txtRegion.Text = recUnit.Region; txtZone.Text = recUnit.Zone; txtType.Text = recUnit.FacilityType; chkIsDispensaryActive.Checked = recUnit.IsColumnNull("IsActive") ? true : recUnit.IsActive; _receivingUnitId = recUnit.ID; try { cboDUMax.SelectedValue = recUnit.Max.ToString(); cboDUMin.SelectedValue = recUnit.Min.ToString(); } catch { } btnIssueSave.Text = "Update"; } }
/// <summary> /// Populates the picklist based on the selected issue configuration /// </summary> private void PopulatePickList() { var valid = ValidateFields(); if (valid == "true") { var iss = new IssueDoc(); var rec = new ReceiveDoc(); var bal = new Balance(); var itmB = new Items(); var DUs = new ReceivingUnits(); var dtIssueConf = new DataTable(); string[] strr = { "No", "Stock Code", "Item Name", "Quantity", "BatchNo", "Expiry Date", "Pack Price", "Total Price", "ItemId", "RecId", "Unit Price", "No of Pack", "Qty per pack", "DUSOH", "DUAMC", "Near Expiry", "DURecomended","SOH Left","UnitID" }; foreach (string col in strr) { dtIssueConf.Columns.Add(col); } DUs.LoadByPrimaryKey(Convert.ToInt32(cboReceivingUnits.EditValue)); double duMax = 0.5; try { duMax = DUs.Max; } catch { } double duMaxDays = duMax * 30; lblNearExpiryComment.Text = "*Near Expiry means items that has expiry in the next " + duMaxDays.ToString() + " Days."; DateTime xx = dtIssueDate.Value; dtIssueDate.CustomFormat = "MM/dd/yyyy"; DateTime dtIss = ConvertDate.DateConverter(dtIssueDate.Text); dtIssueDate.Value = DateTime.Now; DateTime dtCurrent = new DateTime();// Convert.ToDateTime(dtIssueDate.Text); dtCurrent = ConvertDate.DateConverter(dtIssueDate.Text); dtIssueDate.Value = xx; dtIssueDate.CustomFormat = "MMM dd,yyyy"; var dtIssueGrid = (DataTable)issueGrid.DataSource; for (int i = 0; i < dtIssueGrid.Rows.Count; i++) { var unitid = Convert.ToInt32(dtIssueGrid.Rows[i]["UnitID"]); Int64 expAmount = itmB.GetExpiredQtyItemsByID(Convert.ToInt32(dtIssueGrid.Rows[i]["ID"]), Convert.ToInt32(cboStores.EditValue)); Int64 sohQty = 0; try { switch (VisibilitySetting.HandleUnits) { case 1: sohQty = bal.GetSOH(Convert.ToInt32(dtIssueGrid.Rows[i]["ID"]), Convert.ToInt32(cboStores.EditValue), dtIss.Month, dtIss.Year) - expAmount; break; case 2: sohQty = bal.GetSOHByUnit(Convert.ToInt32(dtIssueGrid.Rows[i]["ID"]), Convert.ToInt32(cboStores.EditValue), dtIss.Month, dtIss.Year, unitid) - expAmount; break; case 3: sohQty = bal.GetSOHByUnit(Convert.ToInt32(dtIssueGrid.Rows[i]["ID"]), Convert.ToInt32(cboStores.EditValue), dtIss.Month, dtIss.Year, unitid) - expAmount; break; } } catch { XtraMessageBox.Show("Please check all the information you have input into the form including the issue date.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (sohQty >= Convert.ToInt64(dtIssueGrid.Rows[i]["Requested Qty"])) { var itm = new Items(); itm.LoadByPrimaryKey(Convert.ToInt32(dtIssueGrid.Rows[i]["ID"])); if (itm.IsColumnNull("NeedExpiryBatch")) { itm.NeedExpiryBatch = true; itm.Save(); } if (itm.NeedExpiryBatch && VisibilitySetting.HandleUnits == 1) { _dtRec = rec.GetBatchToIssue(Convert.ToInt32(cboStores.EditValue), Convert.ToInt32(dtIssueGrid.Rows[i]["ID"]), dtIss); } else if (itm.NeedExpiryBatch && VisibilitySetting.HandleUnits == 2) { _dtRec = rec.GetBatchToIssueByUnit(Convert.ToInt32(cboStores.EditValue), Convert.ToInt32(dtIssueGrid.Rows[i]["ID"]), dtIss ,unitid); } else if (itm.NeedExpiryBatch && VisibilitySetting.HandleUnits == 3) { _dtRec = rec.GetBatchToIssueByUnit(Convert.ToInt32(cboStores.EditValue), Convert.ToInt32(dtIssueGrid.Rows[i]["ID"]), dtIss, unitid); } else _dtRec = rec.GetSupplyToIssueWithOutBatch(Convert.ToInt32(cboStores.EditValue), Convert.ToInt32(dtIssueGrid.Rows[i]["ID"]), dtIssueDate.Value); // Extream measures: // This has tobe properly mitigated // if there is the balance an there is no batch to be issued, just select the last batch and add the balance to it. if (rec.RowCount > 0) { int j = 0; Int64 quantity = 0; double sohbalance = 0; switch (VisibilitySetting.HandleUnits) { case 1: quantity = Convert.ToInt64(dtIssueGrid.Rows[i]["Requested Qty"]); sohbalance = sohQty - quantity; break; case 2: quantity = Convert.ToInt64(dtIssueGrid.Rows[i]["Pack Qty"]); sohbalance = sohQty - quantity; break; default: quantity = Convert.ToInt64(dtIssueGrid.Rows[i]["Pack Qty"]); sohbalance = sohQty - quantity; break; } while (quantity >=0 && rec.RowCount > j) { var batch = itm.NeedExpiryBatch ? _dtRec.Rows[j]["BatchNo"].ToString() : ""; Int64 qu = ((quantity > Convert.ToInt32(_dtRec.Rows[j]["QuantityLeft"])) ? Convert.ToInt64(_dtRec.Rows[j]["QuantityLeft"]) : quantity); double qtyPerPack = Convert.ToDouble(_dtRec.Rows[j]["QtyPerPack"]); double unitPrice = Convert.ToDouble(_dtRec.Rows[j]["Cost"]); double packPrice = unitPrice * qtyPerPack; //Convert.ToDouble(dtIssueGrid.Rows[i]["Qty Per Pack"]); double reqPackQty = Convert.ToDouble(dtIssueGrid.Rows[i]["Pack Qty"]); double totPrice = unitPrice * qu; bool nearExp = false; DateTime? dtx = new DateTime(); switch (VisibilitySetting.HandleUnits) { case 1: rec.UnitID = 0; rec.QtyPerPack = Convert.ToInt32(dtIssueGrid.Rows[i]["Qty Per Pack"]); break; case 2: rec.UnitID = Convert.ToInt32(dtIssueGrid.Rows[i]["UnitID"]); rec.QtyPerPack = 1; break; case 3: rec.UnitID = Convert.ToInt32(dtIssueGrid.Rows[i]["UnitID"]); rec.QtyPerPack = 1; break; } if (itm.NeedExpiryBatch) { dtx = Convert.ToDateTime(_dtRec.Rows[j]["ExpDate"]); if (dtx <= DateTime.Now.AddDays(duMaxDays)) nearExp = true; } else if (!itm.NeedExpiryBatch) { dtx = null; // nearExp = false; } int rowNo = j + 1; object[] obj = { rowNo, dtIssueGrid.Rows[i]["Stock Code"], dtIssueGrid.Rows[i]["Item Name"], qu, batch,dtx, packPrice.ToString("#,##0.#0"), ((totPrice != double.NaN) ? totPrice.ToString("#,##0.#0") : "0"), Convert.ToInt32(dtIssueGrid.Rows[i]["ID"]), Convert.ToInt32(_dtRec.Rows[j]["ID"]), unitPrice.ToString("#,##0.00"), dtIssueGrid.Rows[i]["Pack Qty"], dtIssueGrid.Rows[i]["Qty Per Pack"], dtIssueGrid.Rows[i]["DU Remaining SOH"], dtIssueGrid.Rows[i]["DU AMC"], ((nearExp) ? "Yes" : "No"), dtIssueGrid.Rows[i]["Recommended Qty"], sohbalance,dtIssueGrid.Rows[i]["UnitID"]}; dtIssueConf.Rows.Add(obj); quantity = quantity - Convert.ToInt64(_dtRec.Rows[j]["QuantityLeft"]); j++; } } else { XtraMessageBox.Show("There is no enough Quantity in the store OR It has expired. Please check the issue date, quantity and try again!"); } } else { XtraMessageBox.Show("There is not enough Quantity in the store OR It has expired. Please check the issue date, quantity and try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (dtIssueConf.Rows.Count > 0) { _tabPage = 2; tabControl1.SelectedTabPageIndex = 2; txtConfRef.Text = txtRefNo.Text; txtIssuedDate.Value = dtIssueDate.Value; txtIssuedTo.Text = cboReceivingUnits.Text; txtStore.Text = cboStores.Text; txtConIssuedBy.Text = txtIssuedBy.Text; txtConRemark.Text = txtRemark.Text; txtConRecipientName.Text = txtRecipientName.Text; gridConfirmation.DataSource = dtIssueConf; } } else { tabControl1.SelectedTabPageIndex = 1; XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { var view = sender as GridView; if (view == null) return; var iu = new ItemUnit(); if ((view.FocusedColumn.FieldName == "Pack Qty") || (view.FocusedColumn.FieldName == "Qty Per Pack") || (view.FocusedColumn.FieldName == "DU Remaining SOH")) { DataRow dr = issueGridView.GetDataRow(issueGridView.GetSelectedRows()[0]); int qty = Convert.ToInt32(dr["Pack Qty"]); int qtyPerpack = Convert.ToInt32(dr["Qty Per Pack"]); switch (VisibilitySetting.HandleUnits) { case 2: { iu.LoadByPrimaryKey(Convert.ToInt32(dr["UnitID"])); var qtyperunit = iu.QtyPerUnit; dr["Qty Per Pack"] = qtyperunit; dr["Requested Qty"] = qty; } break; case 3: { iu.LoadByPrimaryKey(Convert.ToInt32(dr["UnitID"])); var qtyperunit = iu.QtyPerUnit; dr["Qty Per Pack"] = qtyperunit; dr["Requested Qty"] = qty; } break; case 1: dr["Qty Per Pack"] = qtyPerpack; dr["Requested Qty"] = (qtyPerpack * qty); break; } DateTime xx = dtIssueDate.Value; dtIssueDate.Value = DateTime.Now; dtIssueDate.CustomFormat = "MM/dd/yyyy"; DateTime dtCurrent = ConvertDate.DateConverter(dtIssueDate.Text); dtIssueDate.Value = xx; var bal = new Balance(); var receivingUnit = Convert.ToInt32(cboReceivingUnits.EditValue); Int64 duAmc = 0; int itmId = Convert.ToInt32(dr["ID"]); int lstSOH = ((dr["DU Remaining SOH"] != null && dr["DU Remaining SOH"] != DBNull.Value) ? Convert.ToInt32(dr["DU Remaining SOH"]) : 0); duAmc = bal.CalculateDUAMC(itmId, receivingUnit, dtCurrent.Month, dtCurrent.Year, lstSOH); dr["DU AMC"] = duAmc; //recommend qty to du var DUs = new ReceivingUnits(); DUs.LoadByPrimaryKey(receivingUnit); double dumax = 0.5; try { dumax = DUs.Max; } catch { } double recQty = (Convert.ToInt32(dr["DU AMC"]) * dumax) - lstSOH; dr["Recommended Qty"] = ((recQty > 0) ? Convert.ToInt64(recQty) : 0); } }
private void cboReceivingUnits_SelectedValueChanged(object sender, EventArgs e) { DataTable issGrid = (DataTable)issueGrid.DataSource; if (issGrid != null) { if (cboReceivingUnits.EditValue != null && issGrid.Rows.Count > 0) { DateTime xx = dtIssueDate.Value; dtIssueDate.Value = DateTime.Now; dtIssueDate.CustomFormat = "MM/dd/yyyy"; DateTime dtCurrent = ConvertDate.DateConverter(dtIssueDate.Text); dtIssueDate.Value = xx; var iss = new IssueDoc(); var bal = new Balance(); int receivingUnit = Convert.ToInt32(cboReceivingUnits.EditValue); var DUs = new ReceivingUnits(); DUs.LoadByPrimaryKey(receivingUnit); double dumax = 0.5; try { dumax = DUs.Max; } catch(Exception EX) { } for (int i = 0; i < issGrid.Rows.Count; i++) { int itmId = Convert.ToInt32(issGrid.Rows[i]["ID"]); int lastIssueQty = iss.GetDULastIssueQty(itmId, receivingUnit); int lastDUSOH = iss.GetDULastSOH(itmId, receivingUnit); issGrid.Rows[i]["MR Issue Qty"] = lastIssueQty; issGrid.Rows[i]["MR DU SOH"] = lastDUSOH; const int lstSOH = 0; issGrid.Rows[i]["DU Remaining SOH"] = 0; int yer = (dtCurrent.Month < 11) ? dtCurrent.Year : dtCurrent.Year - 1; Int64 duAmc = bal.CalculateDUAMC(itmId, receivingUnit, dtCurrent.Month, dtCurrent.Year, lstSOH); issGrid.Rows[i]["DU AMC"] = duAmc; double recQty = (duAmc * dumax) - Convert.ToInt32(issGrid.Rows[i]["DU Remaining SOH"]); issGrid.Rows[i]["Recommended Qty"] = ((recQty > 0) ? Convert.ToInt64(recQty) : 0); } } } }
/* private void GenerateBinCard() { ReceiveDoc rec = new ReceiveDoc(); IssueDoc iss = new IssueDoc(); Disposal dis = new Disposal(); DisposalReasons res = new DisposalReasons(); Balance bal = new Balance(); GeneralInfo info = new GeneralInfo(); YearEnd yEnd = new YearEnd(); Items itm = new Items(); info.LoadAll(); year = Convert.ToInt32(cboYear.SelectedItem); DataTable dtRec = rec.GetAllTransaction(itemId,storeId,dtCurrent.Month,year); DataTable dtIss = iss.GetTransactionByItemId(storeId, itemId, year); DataTable dtDis = dis.GetTransactionByItemId(storeId, itemId, year); Int64[] cStockout = { 0, 0, 0 }; Int64[] cOverStock = { 0, 0, 0 }; Int64[] cNearStockOut = { 0, 0, 0 }; Int64[] cBelowMin = { 0, 0, 0 }; //DateTime dtThree = dtCurrent.AddMonths(3); DataTable dtbin = new DataTable(); string[] col = { "Date", "Ref. No", "Receive", "Issue", "Unit Price", "Balance", "Batch No", "Expiry Date","To / From"}; foreach (string str in col) { dtbin.Columns.Add(str); } int i = 0; Int64 bBalance = 0; dtDate.Value = DateTime.Now; dtDate.CustomFormat = "MM/dd/yyyy"; dtCurrent = ConvertDate.DateConverter(dtDate.Text); bBalance = yEnd.GetBBalance(year, storeId, itemId,dtCurrent.Month); Int64 balanceAmount = bBalance; Int64 mincon = 0; Int64 maxcon = 0; double eopcon = 0; DateTime dtT = new DateTime(); string balanceAm = ""; txtBBalance.Text = bBalance.ToString(); string ddDate = ""; string batNo = ""; foreach (DataRow dvRec in dtRec.Rows) { i++; if (Convert.ToInt32(dvRec["Transact"]) == 1) { rec.LoadByPrimaryKey(Convert.ToInt32(dvRec["ID"])); balanceAmount = balanceAmount + Convert.ToInt64(dvRec["Quantity"]); balanceAm = (balanceAmount > 0) ? balanceAmount.ToString("#,###") : "0"; itm.LoadByPrimaryKey(rec.ItemID); if (itm.NeedExpiryBatch) { ddDate = rec.ExpDate.ToString("MMM dd,yyyy"); batNo = rec.BatchNo; } Supplier sup = new Supplier(); sup.LoadByPrimaryKey(rec.SupplierID); object[] obj = { Convert.ToDateTime(dvRec["Date"]).ToString("MM dd,yyyy"), dvRec["RefNo"], Convert.ToInt64(dvRec["Quantity"]).ToString("#,###"), "", Convert.ToDouble(dvRec["Cost"]).ToString("C"), balanceAm, batNo, ddDate, sup.CompanyName}; dtbin.Rows.Add(obj); //For stock Out dtT = Convert.ToDateTime(dvRec["Date"]); //int monb = (dtT.Month < 11) ? dtT.Month + 2 : ((dtT.Month == 11) ? 1 : 2); //int yer = (dtT.Month < 11) ? dtT.Year : dtT.Year - 1; Int64 bBal = bal.GetSOH(itemId, storeId, dtT.Month, dtT.Year); Int64 bAmc = bal.CalculateAMC(itemId, storeId, dtT.Month, dtT.Year); mincon = bAmc * info.Min; maxcon = bAmc * info.Max; eopcon = bAmc * info.EOP; if (balanceAmount == 0) { if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(90))) { cStockout[0]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(180))) { cStockout[1]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(360))) { cStockout[2]++; } } else if (balanceAmount > maxcon) { //For Over stock if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(90))) { cOverStock[0]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(180))) { cOverStock[1]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(360))) { cOverStock[2]++; } }//For Below min else if (balanceAmount > eopcon && balanceAmount <= mincon) { if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(90))) { cBelowMin[0]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(180))) { cBelowMin[1]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(360))) { cBelowMin[2]++; } } else if (balanceAmount > 0 && balanceAmount < eopcon) { if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(90))) { cNearStockOut[0]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(180))) { cNearStockOut[1]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(360))) { cNearStockOut[2]++; } } }else if(Convert.ToInt32(dvRec["Transact"]) == 0) { //DateTime dteIss = Convert.ToDateTime(drIss["Date"]); //DateTime dteRec = Convert.ToDateTime(dvRec["Date"]); //DateTime dTomorow = new DateTime(dtCurrent.Year, dtCurrent.Month, dtCurrent.Day + 1); //DateTime dteNextRec = (i <= dtRec.Rows.Count - 1) ? Convert.ToDateTime(dtRec.Rows[i]["Date"]) : dTomorow; iss.LoadByPrimaryKey(Convert.ToInt32(dvRec["ID"])); try { rec.LoadByPrimaryKey(iss.RecievDocID); } catch { rec.GetTransactionByBatch(itemId, dvRec["BatchNo"].ToString(), storeId); } ReceivingUnits recUnit = new ReceivingUnits(); recUnit.LoadByPrimaryKey(iss.ReceivingUnitID); string issuedTo = recUnit.Name; balanceAmount = balanceAmount - Convert.ToInt64(dvRec["Quantity"]); balanceAm = (balanceAmount > 0) ? balanceAmount.ToString("#,###") : "0"; itm.LoadByPrimaryKey(iss.ItemID); if (itm.NeedExpiryBatch) { ddDate = ((rec.RowCount > 0) ? rec.ExpDate.ToString("MMM dd,yyyy") : ""); ; batNo = dvRec["BatchNo"].ToString(); //rec.BatchNo; } else { ddDate = ""; batNo = ""; } object[] obj = { Convert.ToDateTime(dvRec["Date"]).ToString("MM dd,yyyy"), dvRec["RefNo"], "", Convert.ToInt64(dvRec["Quantity"]).ToString("#,###"), Convert.ToDouble(dvRec["Cost"]).ToString("C"), balanceAm,batNo, ddDate,issuedTo}; dtbin.Rows.Add(obj); //For stock Out dtT = Convert.ToDateTime(dvRec["Date"]); //int monb1 = (dtT.Month < 11) ? dtT.Month + 2 : ((dtT.Month == 11) ? 1 : 2); //int yer1 = (dtT.Month < 11) ? dtT.Year : dtT.Year - 1; Int64 bBal = bal.GetSOH(itemId, storeId, dtT.Month, dtT.Year); Int64 bAmc = bal.CalculateAMC(itemId, storeId, dtT.Month, dtT.Year); mincon = bAmc * info.Min; maxcon = bAmc * info.Max; eopcon = bAmc * info.EOP; if (balanceAmount == 0) { if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(90))) { cStockout[0]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(180))) { cStockout[1]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(360))) { cStockout[2]++; } } else if (balanceAmount > maxcon) { //For Over stock if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(90))) { cOverStock[0]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(180))) { cOverStock[1]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(360))) { cOverStock[2]++; } }//For Below min else if (balanceAmount > eopcon && balanceAmount <= mincon) { if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(90))) { cBelowMin[0]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(180))) { cBelowMin[1]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(360))) { cBelowMin[2]++; } } else if (balanceAmount > 0 && balanceAmount < eopcon) { if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(90))) { cNearStockOut[0]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(180))) { cNearStockOut[1]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(360))) { cNearStockOut[2]++; } } } foreach (DataRow drDis in dtDis.Rows) { DateTime dteDis = Convert.ToDateTime(drDis["Date"]); DateTime dteRec = Convert.ToDateTime(dvRec["Date"]); res.LoadByPrimaryKey(Convert.ToInt32(drDis["ReasonId"])); rec.GetTransactionByBatch(itemId,drDis["BatchNo"].ToString(),storeId); DateTime dteNextRec = (i <= dtRec.Rows.Count - 1) ? Convert.ToDateTime(dtRec.Rows[i]["Date"]) : dtCurrent; if ((dteRec <= dteDis) && (dteDis < dteNextRec)) { if (Convert.ToBoolean(drDis["Losses"])) { balanceAmount = balanceAmount - Convert.ToInt64(drDis["Quantity"]); balanceAm = (balanceAmount > 0) ? balanceAmount.ToString("#,###") : "0"; object[] objIss = { Convert.ToDateTime(drDis["Date"]).ToString("MM dd,yyyy"), drDis["RefNo"], "", Convert.ToInt64(drDis["Quantity"]).ToString("#,###"), Convert.ToDouble(drDis["Cost"]).ToString("C"), balanceAm, drDis["BatchNo"], rec.ExpDate.ToString("MMM dd,yyyy"), res.Reason}; dtbin.Rows.Add(objIss); } else { balanceAmount = balanceAmount + Convert.ToInt64(drDis["Quantity"]); balanceAm = (balanceAmount > 0) ? balanceAmount.ToString("#,###") : "0"; object[] objIss2 = { Convert.ToDateTime(drDis["Date"]).ToString("MM dd,yyyy"), drDis["RefNo"], Convert.ToInt64(drDis["Quantity"]).ToString("#,###"), "", Convert.ToDouble(drDis["Cost"]).ToString("C"), balanceAm, drDis["BatchNo"], rec.ExpDate.ToString("MMM dd,yyyy"), res.Reason}; dtbin.Rows.Add(objIss2); } dtT = Convert.ToDateTime(dvRec["Date"]); Int64 bAmc = bal.CalculateAMC(itemId, storeId, dtT.Month, dtT.Year); mincon = bAmc * info.Min; maxcon = bAmc * info.Max; eopcon = bAmc * info.EOP; if (balanceAmount == 0) { if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(90))) { cStockout[0]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(180))) { cStockout[1]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(360))) { cStockout[2]++; } } else if (balanceAmount > maxcon) { //For Over stock if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(90))) { cOverStock[0]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(180))) { cOverStock[1]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(360))) { cOverStock[2]++; } }//For Below min else if (balanceAmount > eopcon && balanceAmount <= mincon) { if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(90))) { cBelowMin[0]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(180))) { cBelowMin[1]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(360))) { cBelowMin[2]++; } } else if (balanceAmount > 0 && balanceAmount < eopcon) { if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(90))) { cNearStockOut[0]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(180))) { cNearStockOut[1]++; } else if (Convert.ToDateTime(dvRec["Date"]) <= dtCurrent && Convert.ToDateTime(dvRec["Date"]) >= dtCurrent.Subtract(TimeSpan.FromDays(360))) { cNearStockOut[2]++; } } } } } transactionGrid.DataSource = dtbin; //Stock Out lblThreeStockout.Text = cStockout[0].ToString(); lblSixStockOut.Text = (cStockout[0] + cStockout[1]).ToString(); lblTwelveStockOut.Text = (cStockout[0] + cStockout[1] + cStockout[2]).ToString(); //Over Stock lblThreeOverStock.Text = cOverStock[0].ToString(); lblSixOverStock.Text = (cOverStock[0] + cOverStock[1]).ToString(); lblTwelveOverStock.Text = (cOverStock[0] + cOverStock[1] + cOverStock[2]).ToString(); //Near eop lblThreeNearStock.Text = cNearStockOut[0].ToString(); lblSixNearStock.Text = (cNearStockOut[0] + cNearStockOut[1]).ToString(); lblTwelveNear.Text = (cNearStockOut[0] + cNearStockOut[1] + cNearStockOut[2]).ToString(); //Below Min lblThreeBelowMin.Text = cBelowMin[0].ToString(); lblSixBelowMin.Text = (cBelowMin[0] + cBelowMin[1]).ToString(); lblTwelveBelowMin.Text = (cBelowMin[0] + cBelowMin[1] + cBelowMin[2]).ToString(); } */ /// <summary> /// Generates the bin card transaction /// </summary> private void GenerateBinCard() { #region NewCode ////Get the beginning balance. //Int64 begBalance = 0; //YearEnd yearEnd = new YearEnd(); //begBalance = yearEnd.GetBeginningBalance(_storeId, _itemId); //txtBBalance.Text = begBalance.ToString(); ////Get the bin card. //Balance balance = new Balance(); //gridItemsList.DataSource = balance.GetBinCard(_storeId, _itemId); //return; #endregion #region Old Code ReceiveDoc rec = new ReceiveDoc(); IssueDoc iss = new IssueDoc(); Disposal dis = new Disposal(); DisposalReasons res = new DisposalReasons(); Balance bal = new Balance(); GeneralInfo info = new GeneralInfo(); YearEnd yEnd = new YearEnd(); Items itm = new Items(); info.LoadAll(); if (cboFiscalYear.SelectedItem == null) PopulateBinCardYearCombo(); //_year = Convert.ToInt32(cboFiscalYear.SelectedItem); _year = Convert.ToInt32(cboYear.SelectedItem); int yer = _year; //int mth = (_year > _dtCurrent.Year) ? _dtCurrent.Month : 10; int mth = _dtCurrent.Month; EthiopianDate.EthiopianDate ethioDate = new EthiopianDate.EthiopianDate(_year, 1, 1); //if (_dtCurrent.Month < 11) //{ // yer = _year; //} //else //{ // yer = _year - 1; //} //DataTable dtRec = rec.GetAllTransaction(_itemId, _storeId, ethioDate.Month,ethioDate.Year); DataTable dtRec = rec.GetAllTransaction(_itemId, _storeId, ethioDate.FiscalYear); DataTable dtIss = iss.GetTransactionByItemId(_storeId, _itemId, ethioDate.FiscalYear); DataTable dtDis = dis.GetTransactionByItemId(_storeId, _itemId, ethioDate.FiscalYear); Int64[] cStockout = { 0, 0, 0 }; Int64[] cOverStock = { 0, 0, 0 }; Int64[] cNearStockOut = { 0, 0, 0 }; Int64[] cBelowMin = { 0, 0, 0 }; //DateTime dtThree = dtCurrent.AddMonths(3); DataTable dtbin = new DataTable(); string[] col = { "Date", "RefNo", "Receive", "Issue", "Unit Price", "Balance", "Batch No", "Expiry Date", "ToFrom" }; foreach (string str in col) { dtbin.Columns.Add(str); } int i = 0; Int64 bBalance = 0; dtDate.Value = DateTime.Now; dtDate.CustomFormat = "MM/dd/yyyy"; _dtCurrent = ConvertDate.DateConverter(dtDate.Text); //bBalance = yEnd.GetBBalance(_year, _storeId, _itemId, _dtCurrent.Month); bBalance = yEnd.GetBBalance(_year, _storeId, _itemId); Int64 balanceAmount = bBalance; DateTime dtT = new DateTime(); string balanceAm = ""; string ddDate = ""; string batNo = ""; foreach (DataRow dvRec in dtRec.Rows) { i++; if (Convert.ToInt32(dvRec["Transact"]) == 1) { rec.LoadByPrimaryKey(Convert.ToInt32(dvRec["ID"])); if (dvRec["Quantity"] == DBNull.Value) { dvRec["Quantity"] = 0; } balanceAmount = balanceAmount + Convert.ToInt64(dvRec["Quantity"]); balanceAm = (balanceAmount > 0) ? balanceAmount.ToString("#,###") : "0"; itm.LoadByPrimaryKey(rec.ItemID); if (itm.NeedExpiryBatch) { if (!rec.IsColumnNull("ExpDate")) { ddDate = rec.ExpDate.ToString("MMM dd,yyyy"); batNo = rec.BatchNo; } } Supplier sup = new Supplier(); sup.LoadByPrimaryKey(rec.SupplierID); object[] obj = { Convert.ToDateTime(dvRec["Date"]).ToString("MM dd,yyyy"), dvRec["RefNo"], Convert.ToInt64(dvRec["Quantity"]).ToString("#,###"), "", Convert.ToDouble(dvRec["Cost"]).ToString("C"), balanceAm, batNo, ddDate, sup.CompanyName }; dtbin.Rows.Add(obj); //For stock Out dtT = Convert.ToDateTime(dvRec["Date"]); } else if (Convert.ToInt32(dvRec["Transact"]) == 0) { iss.LoadByPrimaryKey(Convert.ToInt32(dvRec["ID"])); try { rec.LoadByPrimaryKey(iss.RecievDocID); } catch { rec.GetTransactionByBatch(_itemId, dvRec["BatchNo"].ToString(), _storeId); } ReceivingUnits recUnit = new ReceivingUnits(); recUnit.LoadByPrimaryKey(iss.ReceivingUnitID); string issuedTo = recUnit.Name; balanceAmount = balanceAmount - Convert.ToInt64(dvRec["Quantity"]); balanceAm = (balanceAmount > 0) ? balanceAmount.ToString("#,###") : "0"; itm.LoadByPrimaryKey(iss.ItemID); if (itm.NeedExpiryBatch) { ddDate = ((rec.RowCount > 0) ? rec.ExpDate.ToString("MMM dd,yyyy") : ""); ; batNo = dvRec["BatchNo"].ToString(); //rec.BatchNo; } else { ddDate = ""; batNo = ""; } object[] obj = { Convert.ToDateTime(dvRec["Date"]).ToString("MM dd,yyyy"), dvRec["RefNo"], "", Convert.ToInt64(dvRec["Quantity"]).ToString("#,###"), Convert.ToDouble(dvRec["Cost"]).ToString("C"), balanceAm, batNo, ddDate, issuedTo }; dtbin.Rows.Add(obj); //For stock Out dtT = Convert.ToDateTime(dvRec["Date"]); } foreach (DataRow drDis in dtDis.Rows) { DateTime dteDis = Convert.ToDateTime(drDis["Date"]); DateTime dteRec = Convert.ToDateTime(dvRec["Date"]); res.LoadByPrimaryKey(Convert.ToInt32(drDis["ReasonId"])); rec.GetTransactionByBatch(_itemId, drDis["BatchNo"].ToString(), _storeId); DateTime dteNextRec = (i <= dtRec.Rows.Count - 1) ? Convert.ToDateTime(dtRec.Rows[i]["Date"]) : _dtCurrent; if ((dteRec <= dteDis) && (dteDis < dteNextRec)) { if (Convert.ToBoolean(drDis["Losses"])) { balanceAmount = balanceAmount - Convert.ToInt64(drDis["Quantity"]); balanceAm = (balanceAmount > 0) ? balanceAmount.ToString("#,###") : "0"; if (rec.RowCount > 0) { object[] objIss = { Convert.ToDateTime(drDis["Date"]).ToString("MM dd,yyyy"), drDis["RefNo"], "", Convert.ToInt64(drDis["Quantity"]).ToString("#,###"), Convert.ToDouble(drDis["Cost"]).ToString("C"), balanceAm, drDis["BatchNo"], rec.ExpDate.ToString("MMM dd,yyyy"), res.Reason }; dtbin.Rows.Add(objIss); } } else { balanceAmount = balanceAmount + Convert.ToInt64(drDis["Quantity"]); balanceAm = (balanceAmount > 0) ? balanceAmount.ToString("#,###") : "0"; object[] objIss2 = { Convert.ToDateTime(drDis["Date"]).ToString("MM dd,yyyy"), drDis["RefNo"], Convert.ToInt64(drDis["Quantity"]).ToString("#,###"), "", Convert.ToDouble(drDis["Cost"]).ToString("C"), balanceAm, drDis["BatchNo"], rec.ExpDate.ToString("MMM dd,yyyy"), res.Reason }; dtbin.Rows.Add(objIss2); } dtT = Convert.ToDateTime(dvRec["Date"]); } } } gridItemsList.DataSource = dtbin; #endregion }