Exemple #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 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();
            }
        }