Esempio n. 1
0
        public Int64 GetBBalanceByUnit(int year, int storeId, int itemId, int month, int unitId)
        {
            //CALENDAR:
            this.FlushData();
            Int64 bb = 0;

            //int bYear = ((month > 10) ? year : year - 1);
            EthiopianDate.EthiopianDate ethioDate = new EthiopianDate.EthiopianDate(year, month, 30);
            int    bYear = ethioDate.FiscalYear;
            string query =
                String.Format(
                    "Select * from YearEnd where StoreID = {0} AND ItemID = {1} AND Year = {2}  and UnitID={3} and (AutomaticallyEntered = 0 or AutomaticallyEntered is null) order by PhysicalInventory desc",
                    storeId, itemId, bYear, unitId);

            this.LoadFromRawSql(query);
            if (this.DataTable.Rows.Count > 0 && this.DataTable.Rows[0]["PhysicalInventory"] != DBNull.Value)
            {
                bb = Convert.ToInt64(this.DataTable.Rows[0]["PhysicalInventory"]);
            }
            else
            {
                this.LoadFromRawSql(
                    String.Format(
                        "Select * from YearEnd where StoreID = {0} AND ItemID = {1} AND Year = {2} and UnitID={3} and (AutomaticallyEntered = 0  or AutomaticallyEntered is null)",
                        storeId, itemId, year - 1, unitId));
                if (this.DataTable.Rows.Count > 0)
                {
                    bb = Convert.ToInt64(this.DataTable.Rows[0]["PhysicalInventory"]);
                }
                else if (((year + 8) > DateTime.Now.Year) || (month > 10 && (year + 8) == DateTime.Now.Year))
                // to check if it is different year from current
                {
                    Int64      cons = 0;
                    IssueDoc   iss  = new IssueDoc();
                    ReceiveDoc rec  = new ReceiveDoc();
                    Disposal   dis  = new Disposal();
                    if ((year + 8) > DateTime.Now.Year) // to check if it is hamle and Nehase
                    {
                        year = year - 1;
                    }
                    month = 10;
                    //}

                    long RecievedQuantity = rec.GetReceivedQuantityTillMonthByUnit(itemId, storeId, month, year,
                                                                                   unitId);
                    long AdjustedQuantity = dis.GetAdjustedQuantityTillMonthByUnit(itemId, storeId, month, year,
                                                                                   unitId);
                    long IssuedQuantity = iss.GetIssuedQuantityTillMonthByUnit(itemId, storeId, month, year, unitId);
                    long LossQuantity   = dis.GetLossesQuantityTillMonthByUnit(itemId, storeId, month, year, unitId);
                    // long BalanceQuantity = yEnd.GetBBalance(year, storeId, itemId, month);
                    cons = (RecievedQuantity + AdjustedQuantity - IssuedQuantity - LossQuantity);

                    //cons = (rec.GetReceivedQuantityTillMonth(itemId, storeId, month, year) + dis.GetAdjustedQuantityTillMonth(itemId, storeId, month, year) - iss.GetIssuedQuantityTillMonth(itemId, storeId, month, year) - dis.GetLossesQuantityTillMonth(itemId, storeId, month, year));
                    bb = cons;
                }
            }

            return(bb);
        }
        public Int64 GetBBalanceByUnit(int year, int storeId, int itemId, int month, int unitId)
        {
            //CALENDAR:
            this.FlushData();
            Int64 bb = 0;
            //int bYear = ((month > 10) ? year : year - 1);
            EthiopianDate.EthiopianDate ethioDate = new EthiopianDate.EthiopianDate(year, month, 30);
            int bYear = ethioDate.FiscalYear;
            string query =
                String.Format(
                    "Select * from YearEnd where StoreID = {0} AND ItemID = {1} AND Year = {2}  and UnitID={3} and (AutomaticallyEntered = 0 or AutomaticallyEntered is null) order by PhysicalInventory desc",
                    storeId, itemId, bYear, unitId);
            this.LoadFromRawSql(query);
            if (this.DataTable.Rows.Count > 0 && this.DataTable.Rows[0]["PhysicalInventory"] != DBNull.Value)
            {
                bb = Convert.ToInt64(this.DataTable.Rows[0]["PhysicalInventory"]);
            }
            else
            {
                this.LoadFromRawSql(
                    String.Format(
                        "Select * from YearEnd where StoreID = {0} AND ItemID = {1} AND Year = {2} and UnitID={3} and (AutomaticallyEntered = 0  or AutomaticallyEntered is null)",
                        storeId, itemId, year - 1, unitId));
                if (this.DataTable.Rows.Count > 0)
                {
                    bb = Convert.ToInt64(this.DataTable.Rows[0]["PhysicalInventory"]);
                }
                else if (((year + 8) > DateTime.Now.Year) || (month > 10 && (year + 8) == DateTime.Now.Year))
                    // to check if it is different year from current
                {
                    Int64 cons = 0;
                    IssueDoc iss = new IssueDoc();
                    ReceiveDoc rec = new ReceiveDoc();
                    Disposal dis = new Disposal();
                    if ((year + 8) > DateTime.Now.Year) // to check if it is hamle and Nehase
                        year = year - 1;
                    month = 10;
                    //}

                    long RecievedQuantity = rec.GetReceivedQuantityTillMonthByUnit(itemId, storeId, month, year,
                                                                                   unitId);
                    long AdjustedQuantity = dis.GetAdjustedQuantityTillMonthByUnit(itemId, storeId, month, year,
                                                                                   unitId);
                    long IssuedQuantity = iss.GetIssuedQuantityTillMonthByUnit(itemId, storeId, month, year, unitId);
                    long LossQuantity = dis.GetLossesQuantityTillMonthByUnit(itemId, storeId, month, year, unitId);
                    // long BalanceQuantity = yEnd.GetBBalance(year, storeId, itemId, month);
                    cons = (RecievedQuantity + AdjustedQuantity - IssuedQuantity - LossQuantity);

                    //cons = (rec.GetReceivedQuantityTillMonth(itemId, storeId, month, year) + dis.GetAdjustedQuantityTillMonth(itemId, storeId, month, year) - iss.GetIssuedQuantityTillMonth(itemId, storeId, month, year) - dis.GetLossesQuantityTillMonth(itemId, storeId, month, year));
                    bb = cons;
                }
            }

            return bb;
        }