コード例 #1
0
ファイル: YearEnd.cs プロジェクト: tomanye/facility
        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();
            }
        }
コード例 #2
0
        private void BuildStoreInventoryListForHandleUnit(int year, int storeId, DataTable dtItm)
        {
            string[] str = { "Item Name", "Batch No.", "Remark" };
            foreach (string co in str)
            {
                dtBB.Columns.Add(co);
            }
            str = new string[] { "ItemId", "No.", "Beginning Balance", "Ending Balance(SOH)", "Physical Inventory", "ID", "RecID", "UnitID" };//, "Change Since Sene 30" };

            foreach (string co in str)
            {
                dtBB.Columns.Add(co, typeof(int));
            }
            int count = 1;
            var yProcess = new YearEnd();
            var bal = new Balance();

            dtDate.Value = DateTime.Now;
            var dtCurent = new DateTime();
            dtDate.CustomFormat = "MM/dd/yyyy";
            dtCurent = ConvertDate.DateConverter(dtDate.Text);

            var recDoc = new ReceiveDoc();
            int month = dtCurent.Month;

            if ((dtCurent.Month == 10 && dtCurent.Day == 30) || dtCurent.Month == 11)
            {
                btnSave.Enabled = ((!yProcess.IsInventoryComplete(year, storeId)));
               //btnSave.Enabled = true;
                month = 10;
            }
            else
                btnSave.Enabled = false;

            var yEnd = new YearEnd();
            foreach (DataRow dr in dtItm.Rows)//For each item
            {
                var itemName = dr["ItemName"].ToString() + " - " + dr["DosageForm"].ToString() + " - " + dr["Strength"].ToString();
                int itemId= Convert.ToInt32(dr["ID"]);
                var unitid = Convert.ToInt32(dr["UnitID"]);
                var BalanceExists = (yProcess.DoesBalanceExistByUnit(year, itemId,storeId, false,unitid));

                //We don't want to display those items whose inventory has already been done.
                if (BalanceExists)
                    continue;

               // Int64 soh = bal.GetSOHByUnit(Convert.ToInt32(dr["ID"]), storeId, month, year,unitid);
                Int64 soh = bal.GetSOHByUnitOptimized(Convert.ToInt32(dr["ID"]), storeId, month, year, unitid);
                Int64 bbal = yEnd.GetBBalanceByUnit(year, storeId, Convert.ToInt32(dr["ID"]), month,unitid);

                yProcess.GetBalanceByItemIdByUnitID(year, storeId, Convert.ToInt32(dr["ID"]),unitid);

                Int64 BB = (yProcess.RowCount > 0) ? yProcess.BBalance : bbal;
                Int64 EB = ((yProcess.RowCount > 0 && yProcess.EBalance != 0) ? yProcess.EBalance : soh);
                string Phy = (yProcess.RowCount > 0) ? yProcess.PhysicalInventory.ToString() : (_defaultValueToPhysicalInventory ? EB.ToString() : "");
                string remark = (yProcess.RowCount > 0) ? yProcess.Remark : "";

                DataRowView drv = dtBB.DefaultView.AddNew();
                if (yProcess.RowCount > 0)
                {
                    drv["ID"] = yProcess.ID;
                }
                drv["ItemId"] = dr["ID"];
                drv["No."] = count;
                drv["Item Name"] = itemName;
                drv["Beginning Balance"] = BB;
                drv["Ending Balance(SOH)"] = EB;
                drv["UnitID"] = unitid;

                if (Phy != "")
                {
                    drv["Physical Inventory"] = Phy;
                }
                drv["RecID"] = -1;
                drv["Remark"] = remark;
                count++;

                int theLastBalance = 0;
                DataTable dtBatchs = recDoc.GetBatchWithValueByUnit(storeId, Convert.ToInt32(dr["ID"]), dtCurent ,unitid);
                foreach (DataRow drBatch in dtBatchs.Rows) //For each batch
                {
                    if (drBatch["QuantityLeft"] != DBNull.Value && Convert.ToInt64(drBatch["QuantityLeft"]) != 0)
                    {
                       drv = dtBB.DefaultView.AddNew();

                        drv["Item Name"] = ">>";
                        drv["UnitID"] =drBatch["UnitID"];
                        drv["Batch No."] = drBatch["BatchNo"];
                        drv["Ending Balance(SOH)"] = Convert.ToInt64(drBatch["QuantityLeft"]);
                        //Now if the physical inventory is chosen to be default value, we set it to the ending balance of last year.
                        if (_defaultValueToPhysicalInventory)
                            drv["Physical Inventory"] = drBatch["QuantityLeft"].ToString();

                        theLastBalance += Convert.ToInt32(drBatch["QuantityLeft"]);
                        drv["RecID"] = drBatch["ID"];
                    }
                }
                //}
            }

            grdYearEnd.DataSource = dtBB;
            dtDate.CustomFormat = "MMMM dd, yyyy"; //throw new NotImplementedException();
        }
コード例 #3
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();
            }
        }