public void GenerateAutomaticInventory() { var ethDate = new EthiopianDate.EthiopianDate(); if (InventoryRequired(false)) { Stores stores = new Stores(); stores.GetActiveStores(); while (!stores.EOF) //This needs to be done for each store { if (!DoesBalanceExist(ethDate.Year, stores.ID, true)) //If Inventory information hasn't already been filled for this store { var itm = new Items(); //bereket //itm.ExcludeNeverReceivedItemsNoCategory(stores.ID); itm.ExcludeNeverReceivedItemsNoCategoryOptimized(stores.ID, ethDate.Year); while (!itm.EOF) //For each time { var yearEnd = new YearEnd(); var balance = new Balance(); yearEnd.LoadByItemIDStoreAndYear(itm.ID, stores.ID, ethDate.Year, true); if (yearEnd.RowCount > 0) { return; } //YearEnd.PurgeAutomaticallyEnteredInventory(itm.ID, stores.ID, ethDate.Year); yearEnd.AddNew(); yearEnd.ItemID = itm.ID; yearEnd.StoreID = stores.ID; yearEnd.Year = ethDate.Year; //bereket //yearEnd.EBalance = balance.GetSOH(itm.ID, stores.ID, 10, ethDate.Year); yearEnd.EBalance = balance.GetSOHOptimized(itm.ID, stores.ID, 10, ethDate.Year); yearEnd.PhysicalInventory = yearEnd.EBalance; yearEnd.AutomaticallyEntered = true; yearEnd.UnitID = 0; yearEnd.Save(); itm.MoveNext(); } } stores.MoveNext(); } } }
public long GetBeginningBalance(int year, int item, int storeID) { YearEnd yearEnd = new YearEnd(); yearEnd.LoadByItemIDStoreAndYear(item, storeID, year - 1, false); if (yearEnd.RowCount > 0) { return yearEnd.PhysicalInventory; } return 0; }
private bool SaveInventoryWithOutUnit() { var yEnd = new YearEnd(); var rec = new ReceiveDoc(); if (IsValid()) { dtDate.Value = DateTime.Now; DateTime dtCurent = new DateTime(); dtDate.CustomFormat = "MM/dd/yyyy"; dtCurent = ConvertDate.DateConverter(dtDate.Text); int year = dtCurent.Year; if (XtraMessageBox.Show("Are You Sure, You want to save this Transaction?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DataTable yearEndTable = (DataTable)grdYearEnd.DataSource; for (int i = 0; i < dtBB.Rows.Count; i++) { int id = 0; int storeID = Convert.ToInt32(cboStores.EditValue); if (dtBB.Rows[i]["ItemID"] != DBNull.Value) { var itemID = Convert.ToInt32(dtBB.Rows[i]["ItemID"]); //var unitID = Convert.ToInt32(dtBB.Rows[i]["UnitID"]); id = yEnd.LoadByItemIDStoreAndYear(itemID, storeID, year, false); } if (id != 0 && !ReferenceEquals(yearEndTable.Rows[i]["Physical Inventory"], string.Empty))//There is already a manual entry in the yearend table. { //yEnd.LoadByPrimaryKey(id); yEnd.BBalance = Convert.ToInt64(FilterNumbers(yearEndTable.Rows[i]["Beginning Balance"].ToString())); yEnd.EBalance = Int64.Parse(FilterNumbers(yearEndTable.Rows[i]["Ending Balance(SOH)"].ToString()), NumberStyles.AllowThousands); yEnd.PhysicalInventory = Convert.ToInt64(FilterNumbers(yearEndTable.Rows[i]["Physical Inventory"].ToString())); //yEnd.BatchNo = yearEndTable.Rows[i]["Batch No."].ToString(); yEnd.UnitID = 0; yEnd.Remark = yearEndTable.Rows[i]["Remark"].ToString(); yEnd.AutomaticallyEntered = false; yEnd.Save(); } else//There is no entry in the yearend table under this item name that has been entered manually. { DataRow cRow = dtBB.Rows[i]; if (!ReferenceEquals(cRow["Physical Inventory"], string.Empty) && cRow["ItemID"] != DBNull.Value) { var itemID = Convert.ToInt32(cRow["ItemID"]); var unitID = 0; YearEnd.PurgeAutomaticallyEnteredInventoryForUnit(itemID, storeID, year, unitID); //if (areAllBatchesPhyInventoryNullValue == false) //We want to add an inventory record if at least one of the batches has a non empty value. //{ yEnd.AddNew(); yEnd.ItemID = itemID; yEnd.StoreID = storeID; yEnd.Year = year; yEnd.BBalance = Convert.ToInt64(cRow["Beginning Balance"]); Int64 endBal = Convert.ToInt64(cRow["Ending Balance(SOH)"]); //yEnd.BatchNo = cRow["Batch No."].ToString(); yEnd.EBalance = endBal;// Convert.ToInt64(yearEndTable.Rows[i].Cells[5].Value); if (cRow["Physical Inventory"] != DBNull.Value) yEnd.PhysicalInventory = Convert.ToInt64(cRow["Physical Inventory"]); //yEnd.PhysicalInventory = physicalInventoryTotal; yEnd.UnitID = 0; yEnd.Remark = cRow["Remark"].ToString(); yEnd.AutomaticallyEntered = cRow["Physical Inventory"] == DBNull.Value; yEnd.Save(); //} //long physicalInventoryTotal = 0; //bool areAllBatchesPhyInventoryNullValue = true; //if (endBal != yEnd.PhysicalInventory) if (true) { int k = i + 1; if (k < dtBB.Rows.Count) { while (Convert.ToInt32(dtBB.Rows[k]["RecID"]) != -1) { if (dtBB.Rows[k]["Physical Inventory"] != DBNull.Value) { //areAllBatchesPhyInventoryNullValue = false; long batchPhysicalInventory = Convert.ToInt64(dtBB.Rows[k]["Physical Inventory"]); //physicalInventoryTotal += batchPhysicalInventory; rec.LoadByPrimaryKey(Convert.ToInt32(dtBB.Rows[k]["RecID"])); rec.QuantityLeft = Convert.ToInt64(batchPhysicalInventory); rec.Remark = "Physical Inventory"; rec.UnitID = 0; rec.Out = rec.QuantityLeft == 0; rec.Save(); } k++; if (k >= yearEndTable.Rows.Count) break; } } } } } } XtraMessageBox.Show("Transaction Succsfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); return true; } else { return false; } } else { return false; } }