Beispiel #1
0
        public void GenerateAutomaticInventoryByUnit()
        {
            var ethDate = new EthiopianDate.EthiopianDate();
            var stores  = new Stores();

            stores.GetActiveStores();
            var rec     = new ReceiveDoc();
            var itm     = new Items();
            var yearEnd = new YearEnd();
            var balance = new Balance();

            if (!InventoryRequiredForHandlingUnit(false))
            {
                return;
            }
            while (!stores.EOF) //This needs to be done for each store and for each item
            {
                //bereket
                //itm.ExcludeNeverReceivedItemsNoCategoryForHandlingUnit(stores.ID);
                itm.ExcludeNeverReceivedItemsNoCategoryForHandlingUnitOptimized(stores.ID, ethDate.Year);
                while (!itm.EOF) //For each item
                {
                    var receivedoc = rec.GetDistinctUnitIDFromReceivedDoc(itm.ID);
                    foreach (var dr in receivedoc.Rows.Cast <DataRow>().Where(dr => !DoesBalanceExistByUnit(ethDate.Year, itm.ID, stores.ID, true, Convert.ToInt32(dr["UnitID"]))))
                    {
                        //need optimization
                        //we can exclude the already calculated items when we exclude never recieved items
                        yearEnd.LoadByItemIDStoreAndYearAndUnit(itm.ID, stores.ID, ethDate.Year, true, Convert.ToInt32(dr["UnitID"]));

                        if (yearEnd.RowCount > 0)
                        {
                            continue;
                        }

                        yearEnd.AddNew();
                        yearEnd.ItemID  = itm.ID;
                        yearEnd.StoreID = stores.ID;
                        yearEnd.Year    = ethDate.Year;

                        //need optimization
                        //atleast we can get the value directly by filtering using storeid and itemid rather than
                        //selecting all items in all stores and filter it by code
                        //yearEnd.EBalance = balance.GetSOHByUnit(itm.ID, stores.ID, ethDate.Month, ethDate.Year, Convert.ToInt32(dr["UnitID"]));
                        yearEnd.EBalance             = balance.GetSOHByUnitOptimized(itm.ID, stores.ID, ethDate.Month, ethDate.Year, Convert.ToInt32(dr["UnitID"]));
                        yearEnd.PhysicalInventory    = yearEnd.EBalance;
                        yearEnd.AutomaticallyEntered = true;
                        yearEnd.UnitID = Convert.ToInt32(dr["UnitID"]);
                        yearEnd.Save();
                    }
                    itm.MoveNext();
                }
                stores.MoveNext();
            }
        }
 public long GetBeginningBalanceByUnit(int year, int item, int storeID,int unitID)
 {
     var yearEnd = new YearEnd();
     yearEnd.LoadByItemIDStoreAndYearAndUnit(item, storeID, year - 1, false,unitID);
     if (yearEnd.RowCount > 0)
     {
         return yearEnd.PhysicalInventory;
     }
     return 0;
 }
        private bool SaveInventory()
        {
            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.LoadByItemIDStoreAndYearAndUnit(itemID, storeID, year, false,unitID);
                        }
                        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 =  Convert.ToInt32(yearEndTable.Rows[i]["UnitID"]);
                            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 = Convert.ToInt32(cRow["UnitID"]);
                                YearEnd.PurgeAutomaticallyEnteredInventoryForUnit(itemID, storeID, year,unitID);

                                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.EBalance = endBal;// Convert.ToInt64(yearEndTable.Rows[i].Cells[5].Value);

                                if (cRow["Physical Inventory"] !=DBNull.Value)
                                    yEnd.PhysicalInventory = Convert.ToInt64(cRow["Physical Inventory"]);

                                yEnd.UnitID = Convert.ToInt32(cRow["UnitID"]);
                                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 = Convert.ToInt32(dtBB.Rows[k]["UnitID"]);
                                                rec.Out = rec.QuantityLeft == 0;
                                                rec.Save();
                                            }
                                            k++;
                                            if (k >= yearEndTable.Rows.Count)
                                                break;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    XtraMessageBox.Show("Transaction Successfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        public void GenerateAutomaticInventoryByUnit()
        {
            var ethDate = new EthiopianDate.EthiopianDate();
            var stores = new Stores();
            stores.GetActiveStores();
            var rec = new ReceiveDoc();
            var itm = new Items();
            var yearEnd = new YearEnd();
            var balance = new Balance();

            if (!InventoryRequiredForHandlingUnit(false)) return;
            while (!stores.EOF) //This needs to be done for each store and for each item
            {
                //bereket
                //itm.ExcludeNeverReceivedItemsNoCategoryForHandlingUnit(stores.ID);
                itm.ExcludeNeverReceivedItemsNoCategoryForHandlingUnitOptimized(stores.ID, ethDate.Year);
                while (!itm.EOF) //For each item
                {
                    var receivedoc = rec.GetDistinctUnitIDFromReceivedDoc(itm.ID);
                    foreach (var dr in receivedoc.Rows.Cast<DataRow>().Where(dr =>!DoesBalanceExistByUnit(ethDate.Year, itm.ID, stores.ID, true,Convert.ToInt32(dr["UnitID"]))))
                    {
                        //need optimization
                        //we can exclude the already calculated items when we exclude never recieved items
                        yearEnd.LoadByItemIDStoreAndYearAndUnit(itm.ID, stores.ID, ethDate.Year, true, Convert.ToInt32(dr["UnitID"]));

                        if (yearEnd.RowCount > 0) continue;

                        yearEnd.AddNew();
                        yearEnd.ItemID = itm.ID;
                        yearEnd.StoreID = stores.ID;
                        yearEnd.Year = ethDate.Year;

                        //need optimization
                        //atleast we can get the value directly by filtering using storeid and itemid rather than
                        //selecting all items in all stores and filter it by code
                        //yearEnd.EBalance = balance.GetSOHByUnit(itm.ID, stores.ID, ethDate.Month, ethDate.Year, Convert.ToInt32(dr["UnitID"]));
                        yearEnd.EBalance = balance.GetSOHByUnitOptimized(itm.ID, stores.ID, ethDate.Month, ethDate.Year, Convert.ToInt32(dr["UnitID"]));
                        yearEnd.PhysicalInventory = yearEnd.EBalance;
                        yearEnd.AutomaticallyEntered = true;
                        yearEnd.UnitID = Convert.ToInt32(dr["UnitID"]);
                        yearEnd.Save();

                    }
                    itm.MoveNext();
                }
                stores.MoveNext();
            }
        }