Exemple #1
0
        private void btnDoEndOfYear_Click(object sender, EventArgs e)
        {
            var result = XtraMessageBox.Show("Are you sure you want to perform the year End activity automatically?",
                                             "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            var confirm =
                XtraMessageBox.Show(
                    "Performing the year end automatically will make HCMIS take the present stock as the beginning balance of the next fiscal year.  You will not be able to use the Inventory page to input inventory data.  Do you want to proceed?",
                    "Confirmation", MessageBoxButtons.YesNo);

            if (confirm == DialogResult.No)
            {
                return;
            }

            btnDoEndOfYear.Enabled = false;
            int      year   = ConvertDate.GetEthiopianYear(DateTimeHelper.ServerDateTime);
            Activity stores = new Activity();

            stores.LoadAll();

            BLL.CommodityType commodityType = new BLL.CommodityType();
            commodityType.LoadAll();

            while (!commodityType.EOF)
            {
                while (!stores.EOF)
                {
                    DataTable dtbl = Balance.GetSohForAllItems(stores.ID, commodityType.ID, year, 10);
                    YearEnd   ye   = new YearEnd();
                    foreach (DataRow dr in dtbl.Rows)
                    {
                        if (dr["ID"] == DBNull.Value || dr["UnitID"] == DBNull.Value)
                        {
                            continue;
                        }

                        ye.AddNew();

                        ye.ItemID  = Convert.ToInt32(dr["ID"]);
                        ye.UnitID  = Convert.ToInt32(dr["UnitID"]);
                        ye.StoreID = stores.ID;
                        ye.Year    = year;

                        ye.PhysicalInventory      = ye.EBalance = Convert.ToInt32(dr["SOH"]);
                        ye.PhysicalInventoryPrice = ye.EndingPrice = Convert.ToDecimal(Convert.ToDouble(dr["Price"]));
                        ye.Save();
                    }
                    stores.MoveNext();
                }
                commodityType.MoveNext();
            }
            XtraMessageBox.Show("Year End has been populated");
            btnDoEndOfYear.Enabled = !BLL.YearEnd.IsPerformedForYear(EthiopianDate.EthiopianDate.Now.Year);
        }