Ejemplo n.º 1
0
        private void BuildStoreInventoryList(int year, int storeId, DataTable dtItm)
        {
            string[] str = { "Item Name", "Batch No.", "Remark", "Unit Price" };
            foreach (string co in str)
            {
                dtBB.Columns.Add(co);
            }
            str = new string[] { "ItemId", "No.", "Beginning Balance", "Ending Balance(SOH)", "Physical Inventory", "ID", "RecID" };//, "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;
            DateTime dtCurent = new DateTime();

            dtDate.CustomFormat = "MM/dd/yyyy";
            dtCurent            = ConvertDate.DateConverter(dtDate.Text);

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

            var yEnd = new YearEnd();


            foreach (DataRow dr in dtItm.Rows)//For each item
            {
                string itemName      = dr["ItemName"].ToString() + " - " + dr["DosageForm"].ToString() + " - " + dr["Strength"].ToString();
                int    itemID        = Convert.ToInt32(dr["ID"]);
                bool   BalanceExists = (yProcess.DoesBalanceExist(year, storeId, itemID, false));

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

                //bereket
                //Int64 soh = bal.GetSOH(Convert.ToInt32(dr["ID"]), storeId, 10, year);
                var soh  = bal.GetSOHOptimized(Convert.ToInt32(dr["ID"]), storeId, month, year);
                var bbal = yEnd.GetBBalance(year, storeId, Convert.ToInt32(dr["ID"]), month);

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

                Int64 BB;
                BB = yProcess.RowCount > 0 ? yProcess.BBalance : bbal;
                Int64 EB;
                EB = yProcess.RowCount > 0 && yProcess.EBalance != 0 ? yProcess.EBalance : soh;
                //Now if the physical inventory is chosen to be default value, we set it to the ending balance of last year.
                string Phy = (yProcess.RowCount > 0) ? yProcess.PhysicalInventory.ToString() : (_defaultValueToPhysicalInventory ? EB.ToString() : "");
                //int id = (yProcess.RowCount > 0) ? yProcess.ID : 0;
                string remark = (yProcess.RowCount > 0) ? yProcess.Remark : "";
                //object[] obj = { Convert.ToInt32(dr["ID"]), count, itemName, "", BB, ((EB != 0) ? EB.ToString("#,###") : "0"), Phy, remark, id, -1 };
                //dtBB.Rows.Add(obj);
                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;

                if (Phy != "")
                {
                    drv["Physical Inventory"] = Phy;
                }
                drv["RecID"]      = -1;
                drv["Unit Price"] = "_";
                drv["Remark"]     = remark;
                //drv["Change Since Sene 30"] = BLL.Balance.GetChangeAfterDate(itemID, storeId, ethioDate.EndOfFiscalYear.ToGregorianDate());
                count++;
                //if (!BalanceExists)
                //{
                int       theLastBalance = 0;
                DataTable dtBatchs       = recDoc.GetBatchWithValue(storeId, Convert.ToInt32(dr["ID"]), dtCurent);
                foreach (DataRow drBatch in dtBatchs.Rows.Cast <DataRow>().Where(drBatch => drBatch["QuantityLeft"] != DBNull.Value && Convert.ToInt64(drBatch["QuantityLeft"]) != 0))
                {
                    drv = dtBB.DefaultView.AddNew();
                    drv["Item Name"]           = ">>";
                    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"];
                    drv["Unit Price"] = drBatch["Cost"];
                }
                //}
            }

            grdYearEnd.DataSource = dtBB;
            dtDate.CustomFormat   = "MMMM dd, yyyy";
        }
Ejemplo n.º 2
0
        private void btnUpdateOnlyOnce_Click(object sender, EventArgs e)
        {
            DataTable dtBB = new DataTable();
            Items     itms = new Items();

            int storeId = 1;// (cboStores.EditValue != null) ? Convert.ToInt32(cboStores.EditValue) : 1;

            DataTable dtItm = itms.ExcludeNeverReceivedItems(storeId, Convert.ToInt32(lkCommodityTypes.EditValue));

            string[] str = { "Item Name", "Batch No.", "Remark" };
            foreach (string co in str)
            {
                dtBB.Columns.Add(co);
            }
            str = new string[] { "ItemId", "No.", "Begining Balance", "Ending Balance(SOH)", "Physical Inventory", "ID", "RecID" };

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

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

            ReceiveDoc recDoc = new ReceiveDoc();
            int        month  = 2;

            int year = 2003;

            YearEnd yEnd          = new YearEnd();
            bool    BalanceExists = (yProcess.DoesBalanceExist(year, storeId, false));

            //int mon = (year == dtCurent.Year) ? dtCurent.Month : 10;
            foreach (DataRow dr in dtItm.Rows)
            {
                string itemName = dr["ItemName"].ToString() + " - " + dr["DosageForm"].ToString() + " - " + dr["Strength"].ToString();
                int    itemID   = Convert.ToInt32(dr["ID"]);
                Int64  soh      = bal.GetSOH(Convert.ToInt32(dr["ID"]), storeId, month, year);
                Int64  bbal     = yEnd.GetBBalance(year, storeId, Convert.ToInt32(dr["ID"]), month);
                yProcess.GetBalanceByItemId(year, storeId, Convert.ToInt32(dr["ID"]));

                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() : "";
                int    id     = (yProcess.RowCount > 0) ? yProcess.ID : 0;
                string remark = (yProcess.RowCount > 0) ? yProcess.Remark : "";
                //object[] obj = {Convert.ToInt32(dr["ID"]),count,itemName,"",BB,((EB != 0)?EB.ToString("#,###"):"0"),Phy,remark,id,-1};
                //dtBB.Rows.Add(obj);
                DataRowView drv = dtBB.DefaultView.AddNew();
                drv["ItemId"]              = dr["ID"];
                drv["No."]                 = count;
                drv["Item Name"]           = itemName;
                drv["Begining Balance"]    = BB;
                drv["Ending Balance(SOH)"] = EB;
                if (Phy != "")
                {
                    drv["Physical Inventory"] = Phy;
                }
                drv["RecID"]  = -1;
                drv["Remark"] = remark;
                count++;
                if (!BalanceExists)
                {
                    // this is the wierdest fixer ever

                    int theLastBalance = 0;
                    //DataTable dtBatchs = recDoc.GetBatchWithValue(storeId, Convert.ToInt32(dr["ID"]), dtCurent);
                    //foreach (DataRow drBatch in dtBatchs.Rows)
                    //{

                    //    if (drBatch["QuantityLeft"] != DBNull.Value && Convert.ToInt64(drBatch["QuantityLeft"]) != 0)
                    //    {

                    //        drv = dtBB.DefaultView.AddNew();

                    //        drv["Item Name"] = ">>";
                    //        drv["Batch No."] = drBatch["BatchNo"];
                    //        drv["Ending Balance(SOH)"] = Convert.ToInt64(drBatch["QuantityLeft"]);
                    //        theLastBalance += Convert.ToInt32(drBatch["QuantityLeft"]);
                    //        drv["RecID"] = drBatch["ID"];
                    //    }
                    //}
                    //try
                    //{
                    //    if ((theLastBalance - EB) != 0)
                    //    {
                    //        int ID = Convert.ToInt32(dtBatchs.Rows[dtBatchs.Rows.Count - 1]);
                    //        ReceiveDoc rd = new ReceiveDoc();
                    //        rd.LoadByPrimaryKey(ID);
                    //        rd.QuantityLeft -= (theLastBalance - EB);
                    //        rd.Quantity -= theLastBalance;

                    //        if (rd.QuantityLeft < 0)
                    //        {
                    //            rd.QuantityLeft = 0;
                    //            rd.Out = true;
                    //            if (rd.Quantity < 0)
                    //            {
                    //                rd.Quantity = 0;
                    //            }
                    //        }
                    //        else
                    //        {
                    //            rd.Out = false;
                    //        }

                    //        rd.Save();
                    //    }
                    //}
                    //catch
                    //{
                    //    ReceiveDoc rd = new ReceiveDoc();
                    //    rd.GetLastReceivedBatchAfterIssue(storeId, itemID);
                    //    rd.Quantity -= (theLastBalance - EB);
                    //    rd.QuantityLeft -= (theLastBalance - EB);
                    //    rd.Save();
                    //};
                }
            }
        }