コード例 #1
0
        private void InitialiseBudgetList(ABudgetTable ABdgTable)
        {
            string CheckedMember = "CHECKED";
            string AccountDBN    = ABudgetTable.GetAccountCodeDBName();
            string CostCentreDBN = ABudgetTable.GetCostCentreCodeDBName();
            string BudgetSeqDBN  = ABudgetTable.GetBudgetSequenceDBName();
            string CCAccDesc     = "CostCentreAccountDescription";
            string BudgetSeqKey  = "BudgetSequenceKey";

            //Calculate the longest Cost Centre to calculate padding amount
            ABudgetRow BudgetRow;
            int        CostCentreCodeLength = 0;

            if (ABdgTable != null)
            {
                if (ABdgTable.Count > 0)
                {
                    FBudgetsExist = true;

                    for (int i = 0; i < ABdgTable.Count; i++)
                    {
                        BudgetRow            = (ABudgetRow)ABdgTable.Rows[i];
                        CostCentreCodeLength = BudgetRow.CostCentreCode.Length;

                        if (CostCentreCodeLength > CostCentrePadding)
                        {
                            CostCentrePadding = CostCentreCodeLength;
                        }
                    }

                    BudgetRow = null;

                    // add empty row so that SetSelectedString for invalid string will not result in undefined behaviour (selecting the first cost centre etc)
                    //ABudgetRow emptyRow = (ABudgetRow)ABdgTable.NewRow();

                    DataView view = new DataView(ABdgTable);
                    view.RowFilter = String.Format("{0}={1}",
                                                   ABudgetTable.GetLedgerNumberDBName(),
                                                   FLedgerNumber);
                    DataTable ABdgTable2 = view.ToTable(true, new string[] { BudgetSeqDBN, AccountDBN, CostCentreDBN });

                    ABdgTable2.Columns.Add(new DataColumn(CheckedMember, typeof(bool)));
                    ABdgTable2.Columns.Add(new DataColumn(BudgetSeqKey, typeof(string), BudgetSeqDBN));
                    ABdgTable2.Columns.Add(new DataColumn(CCAccDesc, typeof(string),
                                                          CostCentreDBN.PadRight(CostCentrePadding + 2, ' ') + " + '-' + " + AccountDBN));

                    clbCostCentreAccountCodes.Columns.Clear();
                    clbCostCentreAccountCodes.AddCheckBoxColumn("", ABdgTable2.Columns[CheckedMember], 17, false);
                    clbCostCentreAccountCodes.AddTextColumn("Key", ABdgTable2.Columns[BudgetSeqKey], 0);
                    clbCostCentreAccountCodes.AddTextColumn("Cost Centre-Account", ABdgTable2.Columns[CCAccDesc], 200);
                    clbCostCentreAccountCodes.DataBindGrid(ABdgTable2, BudgetSeqKey, CheckedMember, BudgetSeqKey, false, true, false);

                    clbCostCentreAccountCodes.SetCheckedStringList("");
                }
            }

            btnOK.Enabled = FBudgetsExist;
            btnSelectAllBudgets.Enabled   = FBudgetsExist;
            btnUnselectAllBudgets.Enabled = FBudgetsExist;
        }
コード例 #2
0
        private void SelectAll()
        {
            ABudgetTable BudgetTable = FMainDS.ABudget;
            ABudgetRow   BudgetRow;
            string       CheckedList = string.Empty;

            try
            {
                this.Cursor = Cursors.WaitCursor;

                for (int i = 0; i < BudgetTable.Count; i++)
                {
                    BudgetRow    = (ABudgetRow)BudgetTable.Rows[i];
                    CheckedList += BudgetRow.BudgetSequence.ToString() + ",";
                }

                if (CheckedList.Length > 0)
                {
                    CheckedList = CheckedList.Substring(0, CheckedList.Length - 1);
                    clbCostCentreAccountCodes.SetCheckedStringList(CheckedList);
                    clbCostCentreAccountCodes.SelectRowInGrid(1);
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
コード例 #3
0
        private void InitialiseBudgetList(ABudgetTable ABdgTable)
        {
            string CheckedMember = "CHECKED";
            string AccountDBN    = ABudgetTable.GetAccountCodeDBName();
            string CostCentreDBN = ABudgetTable.GetCostCentreCodeDBName();
            string BudgetSeqDBN  = ABudgetTable.GetBudgetSequenceDBName();
            string CCAccDesc     = "CostCentreAccountDescription";
            string BudgetSeqKey  = "BudgetSequenceKey";

            //Calculate the longest Cost Centre to calculate padding amount
            ABudgetRow BudgetRow;
            int        CostCentreCodeLength = 0;

            if (ABdgTable != null)
            {
                if (ABdgTable.Count > 0)
                {
                    FBudgetsExist = true;

                    for (int i = 0; i < ABdgTable.Count; i++)
                    {
                        BudgetRow            = (ABudgetRow)ABdgTable.Rows[i];
                        CostCentreCodeLength = BudgetRow.CostCentreCode.Length;

                        if (CostCentreCodeLength > CostCentrePadding)
                        {
                            CostCentrePadding = CostCentreCodeLength;
                        }
                    }

                    BudgetRow = null;

                    // add empty row so that SetSelectedString for invalid string will not result in undefined behaviour (selecting the first cost centre etc)
                    //ABudgetRow emptyRow = (ABudgetRow)ABdgTable.NewRow();

                    // We create a copy of the ABudget table but this time only with three columns and ensuring we get didtinct rows.
                    // This caters for having multiple budget revisions by 'filtering' them out.
                    // We already have a specific ledger and year from the server in ABdgTable.
                    DataTable ABdgTable2 = ABdgTable.DefaultView.ToTable(true, new string[] { BudgetSeqDBN, AccountDBN, CostCentreDBN });

                    ABdgTable2.Columns.Add(new DataColumn(CheckedMember, typeof(bool)));
                    ABdgTable2.Columns.Add(new DataColumn(BudgetSeqKey, typeof(string), BudgetSeqDBN));
                    ABdgTable2.Columns.Add(new DataColumn(CCAccDesc, typeof(string),
                                                          CostCentreDBN.PadRight(CostCentrePadding + 2, ' ') + " + '-' + " + AccountDBN));

                    clbCostCentreAccountCodes.Columns.Clear();
                    clbCostCentreAccountCodes.AddCheckBoxColumn("", ABdgTable2.Columns[CheckedMember], 17, false);
                    clbCostCentreAccountCodes.AddTextColumn("Key", ABdgTable2.Columns[BudgetSeqKey], 0);
                    clbCostCentreAccountCodes.AddTextColumn("Cost Centre-Account", ABdgTable2.Columns[CCAccDesc]);
                    clbCostCentreAccountCodes.DataBindGrid(ABdgTable2, CCAccDesc, CheckedMember, BudgetSeqKey, false, true, false);

                    clbCostCentreAccountCodes.SetCheckedStringList("");
                }
            }

            btnOK.Enabled = FBudgetsExist;
            btnSelectAllBudgets.Enabled   = FBudgetsExist;
            btnUnselectAllBudgets.Enabled = FBudgetsExist;
        }
コード例 #4
0
        public static BudgetTDS LoadBudgetForAutoGenerate(Int32 ALedgerNumber)
        {
            BudgetTDS FMainDS = new BudgetTDS();

            TDBTransaction Transaction = new TDBTransaction();
            TDataBase      db          = DBAccess.Connect("LoadBudgetForAutoGenerate");

            db.ReadTransaction(
                ref Transaction,
                delegate
            {
                ALedgerAccess.LoadByPrimaryKey(FMainDS, ALedgerNumber, Transaction);

                #region Validate Data

                if ((FMainDS.ALedger == null) || (FMainDS.ALedger.Count == 0))
                {
                    throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                                                                               "Function:{0} - Ledger data for Ledger number {1} does not exist or could not be accessed!"),
                                                                                           Utilities.GetMethodName(true),
                                                                                           ALedgerNumber));
                }

                #endregion Validate Data

                int CurrentFinancialYear = FMainDS.ALedger[0].CurrentFinancialYear;

                //Load all by Ledger/Year but none may exist
                ABudgetTable BudgetTable = new ABudgetTable();
                ABudgetRow TemplateRow   = (ABudgetRow)BudgetTable.NewRow();

                TemplateRow.LedgerNumber = ALedgerNumber;
                TemplateRow.Year         = CurrentFinancialYear;

                StringCollection Operators = StringHelper.InitStrArr(new string[] { "=", "=" });
                StringCollection OrderList = new StringCollection();

                OrderList.Add("ORDER BY");
                OrderList.Add(ABudgetTable.GetCostCentreCodeDBName() + " ASC");
                OrderList.Add(ABudgetTable.GetAccountCodeDBName() + " ASC");

                ABudgetAccess.LoadUsingTemplate(FMainDS, TemplateRow, Operators, null, Transaction, OrderList, 0, 0);
                ABudgetPeriodAccess.LoadViaABudgetTemplate(FMainDS, TemplateRow, Operators, null, Transaction, OrderList, 0, 0);

                ABudgetRevisionAccess.LoadByPrimaryKey(FMainDS, ALedgerNumber, CurrentFinancialYear, 0, Transaction);

                ABudgetTypeAccess.LoadAll(FMainDS, Transaction);
            });

            // Accept row changes here so that the Client gets 'unmodified' rows
            FMainDS.AcceptChanges();

            // Remove all Tables that were not filled with data before remoting them.
            FMainDS.RemoveEmptyTables();

            return(FMainDS);
        }
コード例 #5
0
        /// <summary>
        /// Update Budget Period Amounts for each record that was created or modified during an import
        /// </summary>
        private void UpdateABudgetPeriodAmounts(BudgetTDS AMainDS, int ACurrentBudgetYear)
        {
            DataView BudgetDV = new DataView(AMainDS.ABudget);

            BudgetDV.RowFilter = String.Format("Isnull({0},'') <> '' And ({0}='Added' Or {0}='Updated')",
                                               ABudgetTable.GetCommentDBName());

            BudgetDV.Sort = String.Format("{0} ASC",
                                          ABudgetTable.GetYearDBName());

            foreach (DataRowView drv in BudgetDV)
            {
                BudgetTDSABudgetRow budgetRow = (BudgetTDSABudgetRow)drv.Row;

                int budgetSeq = budgetRow.BudgetSequence;

                DataView budgetPeriodsDV = new DataView(AMainDS.ABudgetPeriod);

                budgetPeriodsDV.RowFilter = String.Format("{0}={1}",
                                                          ABudgetPeriodTable.GetBudgetSequenceDBName(),
                                                          budgetRow.BudgetSequence);
                budgetPeriodsDV.Sort = String.Format("{0} ASC",
                                                     ABudgetPeriodTable.GetPeriodNumberDBName());

                foreach (DataRowView drv2 in budgetPeriodsDV)
                {
                    ABudgetPeriodRow budgetPeriodRow = (ABudgetPeriodRow)drv2.Row;

                    int    period             = budgetPeriodRow.PeriodNumber;
                    string periodAmountColumn = string.Empty;

                    if (period <= FNumberOfPeriods)
                    {
                        periodAmountColumn            = "Period" + period.ToString("00") + "Amount";
                        budgetRow[periodAmountColumn] = budgetPeriodRow.BudgetBase;
                    }
                    else
                    {
                        //TODO After data migration, this should not happen so add an error message.
                        // In old Petra, budget periods always go up to 20, but are only populated
                        //   up to number of financial periods
                    }
                }
            }

            //Remove import related comment
            // - done separately to loop above to avoid confusion as DataView filtering is on Comment field
            foreach (DataRowView drv in BudgetDV)
            {
                BudgetTDSABudgetRow budgetRow = (BudgetTDSABudgetRow)drv.Row;
                budgetRow.Comment = string.Empty;
            }
        }
コード例 #6
0
ファイル: Test.Budget.cs プロジェクト: Kingefosa/openpetra
        public void T0_Consolidation()
        {
            // reset the database, so that there is no consolidated budget
            CommonNUnitFunctions.ResetDatabase();

            string budgetTestFile = TAppSettingsManager.GetValue("GiftBatch.file",
                                                                 CommonNUnitFunctions.rootPath + "/csharp/ICT/Testing/lib/MFinance/SampleData/BudgetImport-All.csv");

            int NumBudgetsUpdated;
            int NumFailedRows;
            TVerificationResultCollection VerificationResult;

            BudgetTDS ImportDS = new BudgetTDS();

            string ImportString = File.ReadAllText(budgetTestFile);

            // import budget from CSV
            decimal RowsImported = TBudgetMaintainWebConnector.ImportBudgets(
                FLedgerNumber,
                0,
                ImportString,
                budgetTestFile,
                new string[] { ",", "dmy", "American" },
                ref ImportDS,
                out NumBudgetsUpdated,
                out NumFailedRows,
                out VerificationResult);

            Assert.AreNotEqual(0, RowsImported, "expect to import several rows");

            CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult,
                                                                                "ImportBudgets has critical errors:");

            BudgetTDSAccess.SubmitChanges(ImportDS);

            // check for value in budget table
            string sqlQueryBudget =
                String.Format(
                    "SELECT {0} FROM PUB_{1}, PUB_{2} WHERE {1}.a_budget_sequence_i = {2}.a_budget_sequence_i AND a_period_number_i = 1 AND " +
                    "a_ledger_number_i = {3} AND a_revision_i = 0 AND a_year_i = 0 AND a_account_code_c = '0300' AND a_cost_centre_code_c = '4300'",
                    ABudgetPeriodTable.GetBudgetBaseDBName(),
                    ABudgetTable.GetTableDBName(),
                    ABudgetPeriodTable.GetTableDBName(),
                    FLedgerNumber);

            decimal budgetValue = Convert.ToDecimal(DBAccess.GDBAccessObj.ExecuteScalar(sqlQueryBudget, IsolationLevel.ReadCommitted));

            Assert.AreEqual(250m, budgetValue, "problem with importing budget from CSV");

            // check for zero in glmperiod budget: that row does not even exist yet, so check that it does not exist
            string sqlQueryCheckEmptyConsolidatedBudget =
                String.Format(
                    "SELECT COUNT(*) FROM PUB_{0}, PUB_{1} WHERE {0}.a_glm_sequence_i = {1}.a_glm_sequence_i AND a_period_number_i = 1 AND " +
                    "a_ledger_number_i = {2} AND a_year_i = 0 AND a_account_code_c = '0300' AND a_cost_centre_code_c = '4300'",
                    AGeneralLedgerMasterPeriodTable.GetTableDBName(),
                    AGeneralLedgerMasterTable.GetTableDBName(),
                    FLedgerNumber);

            Assert.AreEqual(0, DBAccess.GDBAccessObj.ExecuteScalar(sqlQueryCheckEmptyConsolidatedBudget,
                                                                   IsolationLevel.ReadCommitted), "budget should not be consolidated yet");

            // consolidate the budget
            TBudgetConsolidateWebConnector.LoadBudgetForConsolidate(FLedgerNumber);
            TBudgetConsolidateWebConnector.ConsolidateBudgets(FLedgerNumber, true);

            // check for correct value in glmperiod budget
            string sqlQueryConsolidatedBudget =
                String.Format(
                    "SELECT {0} FROM PUB_{1}, PUB_{2} WHERE {1}.a_glm_sequence_i = {2}.a_glm_sequence_i AND a_period_number_i = 1 AND " +
                    "a_ledger_number_i = {3} AND a_year_i = 0 AND a_account_code_c = '0300' AND a_cost_centre_code_c = '4300'",
                    AGeneralLedgerMasterPeriodTable.GetBudgetBaseDBName(),
                    AGeneralLedgerMasterPeriodTable.GetTableDBName(),
                    AGeneralLedgerMasterTable.GetTableDBName(),
                    FLedgerNumber);

            decimal consolidatedBudgetValue =
                Convert.ToDecimal(DBAccess.GDBAccessObj.ExecuteScalar(sqlQueryConsolidatedBudget, IsolationLevel.ReadCommitted));

            Assert.AreEqual(250m, consolidatedBudgetValue, "budget should now be consolidated");

            // TODO: also check some summary account and cost centre for summed up budget values

            // check how reposting a budget works
            string sqlChangeBudget = String.Format("UPDATE PUB_{0} SET {1} = 44 WHERE a_period_number_i = 1 AND " +
                                                   "EXISTS (SELECT * FROM PUB_{2} WHERE {0}.a_budget_sequence_i = {2}.a_budget_sequence_i AND a_ledger_number_i = {3} " +
                                                   "AND a_year_i = 0 AND a_revision_i = 0 AND a_account_code_c = '0300' AND a_cost_centre_code_c = '4300')",
                                                   ABudgetPeriodTable.GetTableDBName(),
                                                   ABudgetPeriodTable.GetBudgetBaseDBName(),
                                                   ABudgetTable.GetTableDBName(),
                                                   FLedgerNumber);

            bool           SubmissionOK = true;
            TDBTransaction Transaction  = null;

            DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK,
                                                       delegate
            {
                DBAccess.GDBAccessObj.ExecuteNonQuery(sqlChangeBudget, Transaction);
            });

            // post all budgets again
            TBudgetConsolidateWebConnector.LoadBudgetForConsolidate(FLedgerNumber);
            TBudgetConsolidateWebConnector.ConsolidateBudgets(FLedgerNumber, true);

            consolidatedBudgetValue =
                Convert.ToDecimal(DBAccess.GDBAccessObj.ExecuteScalar(sqlQueryConsolidatedBudget, IsolationLevel.ReadCommitted));
            Assert.AreEqual(44.0m, consolidatedBudgetValue, "budget should be consolidated with the new value");

            // post only a modified budget (testing UnPostBudget)
            sqlChangeBudget = String.Format("UPDATE PUB_{0} SET {1} = 65 WHERE a_period_number_i = 1 AND " +
                                            "EXISTS (SELECT * FROM PUB_{2} WHERE {0}.a_budget_sequence_i = {2}.a_budget_sequence_i AND a_ledger_number_i = {3} " +
                                            "AND a_year_i = 0 AND a_revision_i = 0 AND a_account_code_c = '0300' AND a_cost_centre_code_c = '4300')",
                                            ABudgetPeriodTable.GetTableDBName(),
                                            ABudgetPeriodTable.GetBudgetBaseDBName(),
                                            ABudgetTable.GetTableDBName(),
                                            FLedgerNumber);

            string sqlMarkBudgetForConsolidation = String.Format("UPDATE PUB_{0} SET {1} = false WHERE " +
                                                                 "a_ledger_number_i = {2} " +
                                                                 "AND a_year_i = 0 AND a_revision_i = 0 AND a_account_code_c = '0300' AND a_cost_centre_code_c = '4300'",
                                                                 ABudgetTable.GetTableDBName(),
                                                                 ABudgetTable.GetBudgetStatusDBName(),
                                                                 FLedgerNumber);

            SubmissionOK = true;
            Transaction  = null;
            DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK,
                                                       delegate
            {
                DBAccess.GDBAccessObj.ExecuteNonQuery(sqlChangeBudget, Transaction);
                DBAccess.GDBAccessObj.ExecuteNonQuery(sqlMarkBudgetForConsolidation, Transaction);
            });

            // post only modified budget again
            TBudgetConsolidateWebConnector.LoadBudgetForConsolidate(FLedgerNumber);
            TBudgetConsolidateWebConnector.ConsolidateBudgets(FLedgerNumber, false);

            consolidatedBudgetValue =
                Convert.ToDecimal(DBAccess.GDBAccessObj.ExecuteScalar(sqlQueryConsolidatedBudget, IsolationLevel.ReadCommitted));
            Assert.AreEqual(65.0m, consolidatedBudgetValue, "budget should be consolidated with the new value, after UnPostBudget");

            // TODO: test forwarding periods. what happens to next year values, when there is no next year glm record yet?
        }
コード例 #7
0
        public static bool LoadBudgetForConsolidate(Int32 ALedgerNumber)
        {
            FBudgetTDS = new BudgetTDS();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                      TEnforceIsolationLevel.eilMinimum,
                                                                      ref Transaction,
                                                                      delegate
            {
                ALedgerAccess.LoadByPrimaryKey(FBudgetTDS, ALedgerNumber, Transaction);

                string sqlLoadBudgetForThisAndNextYear =
                    string.Format("SELECT * FROM PUB_{0} WHERE {1}=? AND ({2} = ? OR {2} = ?)",
                                  ABudgetTable.GetTableDBName(),
                                  ABudgetTable.GetLedgerNumberDBName(),
                                  ABudgetTable.GetYearDBName());

                List <OdbcParameter> parameters = new List <OdbcParameter>();
                OdbcParameter param             = new OdbcParameter("ledgernumber", OdbcType.Int);
                param.Value = ALedgerNumber;
                parameters.Add(param);
                param       = new OdbcParameter("thisyear", OdbcType.Int);
                param.Value = FBudgetTDS.ALedger[0].CurrentFinancialYear;
                parameters.Add(param);
                param       = new OdbcParameter("nextyear", OdbcType.Int);
                param.Value = FBudgetTDS.ALedger[0].CurrentFinancialYear + 1;
                parameters.Add(param);

                DBAccess.GDBAccessObj.Select(FBudgetTDS, sqlLoadBudgetForThisAndNextYear, FBudgetTDS.ABudget.TableName, Transaction,
                                             parameters.ToArray());

                string sqlLoadBudgetPeriodForThisAndNextYear =
                    string.Format("SELECT {0}.* FROM PUB_{0}, PUB_{1} WHERE {0}.a_budget_sequence_i = {1}.a_budget_sequence_i AND " +
                                  "{2}=? AND ({3} = ? OR {3} = ?)",
                                  ABudgetPeriodTable.GetTableDBName(),
                                  ABudgetTable.GetTableDBName(),
                                  ABudgetTable.GetLedgerNumberDBName(),
                                  ABudgetTable.GetYearDBName());

                DBAccess.GDBAccessObj.Select(FBudgetTDS,
                                             sqlLoadBudgetPeriodForThisAndNextYear,
                                             FBudgetTDS.ABudgetPeriod.TableName,
                                             Transaction,
                                             parameters.ToArray());

                // Accept row changes here so that the Client gets 'unmodified' rows
                FBudgetTDS.AcceptChanges();

                GLPostingDS = new GLPostingTDS();
                AAccountAccess.LoadViaALedger(GLPostingDS, ALedgerNumber, Transaction);
                AAccountHierarchyDetailAccess.LoadViaALedger(GLPostingDS, ALedgerNumber, Transaction);
                ACostCentreAccess.LoadViaALedger(GLPostingDS, ALedgerNumber, Transaction);
                ALedgerAccess.LoadByPrimaryKey(GLPostingDS, ALedgerNumber, Transaction);

                // get the glm sequences for this year and next year
                for (int i = 0; i <= 1; i++)
                {
                    int Year = GLPostingDS.ALedger[0].CurrentFinancialYear + i;

                    AGeneralLedgerMasterRow TemplateRow = (AGeneralLedgerMasterRow)GLPostingDS.AGeneralLedgerMaster.NewRowTyped(false);

                    TemplateRow.LedgerNumber = ALedgerNumber;
                    TemplateRow.Year         = Year;

                    GLPostingDS.AGeneralLedgerMaster.Merge(AGeneralLedgerMasterAccess.LoadUsingTemplate(TemplateRow, Transaction));
                }

                string sqlLoadGlmperiodForThisAndNextYear =
                    string.Format("SELECT {0}.* FROM PUB_{0}, PUB_{1} WHERE {0}.a_glm_sequence_i = {1}.a_glm_sequence_i AND " +
                                  "{2}=? AND ({3} = ? OR {3} = ?)",
                                  AGeneralLedgerMasterPeriodTable.GetTableDBName(),
                                  AGeneralLedgerMasterTable.GetTableDBName(),
                                  AGeneralLedgerMasterTable.GetLedgerNumberDBName(),
                                  AGeneralLedgerMasterTable.GetYearDBName());

                DBAccess.GDBAccessObj.Select(GLPostingDS,
                                             sqlLoadGlmperiodForThisAndNextYear,
                                             GLPostingDS.AGeneralLedgerMasterPeriod.TableName,
                                             Transaction,
                                             parameters.ToArray());
            });

            GLPostingDS.AcceptChanges();

            return(true);
        }
コード例 #8
0
        public static BudgetTDS LoadAllBudgets(Int32 ALedgerNumber)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            BudgetTDS MainDS = new BudgetTDS();
            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);

                        #region Validate Data

                        if ((MainDS.ALedger == null) || (MainDS.ALedger.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Ledger data for Ledger number {1} does not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true),
                                    ALedgerNumber));
                        }

                        #endregion Validate Data

                        //Load all by Ledger but none may exist
                        ABudgetAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                        ABudgetRevisionAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);

                        ABudgetTable BudgetTable = new ABudgetTable();
                        ABudgetRow TemplateRow = (ABudgetRow)BudgetTable.NewRow();
                        TemplateRow.LedgerNumber = ALedgerNumber;

                        ABudgetPeriodAccess.LoadViaABudgetTemplate(MainDS, TemplateRow, Transaction);
                    });

                // Accept row changes here so that the Client gets 'unmodified' rows
                MainDS.AcceptChanges();

                // Remove all Tables that were not filled with data before remoting them.
                MainDS.RemoveEmptyTables();
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }
コード例 #9
0
        /// <summary>
        /// Import the budget from a CSV file
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ACurrentBudgetYear"></param>
        /// <param name="AImportString"></param>
        /// <param name="ACSVFileName"></param>
        /// <param name="AFdlgSeparator"></param>
        /// <param name="AImportDS"></param>
        /// <param name="ARecordsUpdated"></param>
        /// <param name="AFailedRows"></param>
        /// <param name="AVerificationResult"></param>
        /// <returns>Total number of records imported and number of which updated as the fractional part</returns>
        private static Int32 ImportBudgetFromCSV(Int32 ALedgerNumber,
            Int32 ACurrentBudgetYear,
            string AImportString,
            string ACSVFileName,
            string[] AFdlgSeparator,
            ref BudgetTDS AImportDS,
            ref Int32 ARecordsUpdated,
            ref Int32 AFailedRows,
            ref TVerificationResultCollection AVerificationResult)
        {
            StringReader sr = new StringReader(AImportString);

            string Separator = AFdlgSeparator[0];
            string DateFormat = AFdlgSeparator[1];
            string NumberFormat = AFdlgSeparator[2];

            FCultureInfoNumberFormat = new CultureInfo(NumberFormat.Equals("American") ? "en-US" : "de-DE");
            CultureInfo MyCultureInfoDate = new CultureInfo("en-GB");
            MyCultureInfoDate.DateTimeFormat.ShortDatePattern = DateFormat;

            // To store the From and To currencies
            // Use an array to store these to make for easy
            //   inverting of the two currencies when calculating
            //   the inverse value.

            //string currentBudgetVal = string.Empty;
            //string mess = string.Empty;
            ACostCentreTable CostCentreTable = null;
            AAccountTable AccountTable = null;

            string CostCentre = string.Empty;
            string Account = string.Empty;
            string BudgetTypeUpper = string.Empty;
            string BudgetYearStringUpper = string.Empty;
            int BudgetYearNumber = 0;
            int BdgRevision = 0;  //not currently implementing versioning so always zero

            int NumPeriods = TAccountingPeriodsWebConnector.GetNumberOfPeriods(ALedgerNumber);
            decimal[] BudgetPeriods = new decimal[NumPeriods];

            int RowNumber = 0;
            AFailedRows = 0;

            ABudgetTable BudgetTableExistingAndImported = new ABudgetTable();

            // Go round a loop reading the file line by line
            string ImportLine = sr.ReadLine();

            while (ImportLine != null)
            {
                decimal totalBudgetRowAmount = 0;

                try
                {
                    CostCentre = StringHelper.GetNextCSV(ref ImportLine, Separator, false).ToString();

                    //Check if header row exists
                    if ((CostCentre == "Cost Centre") || string.IsNullOrEmpty(ImportLine))
                    {
                        continue;
                    }

                    //Increment row number
                    RowNumber++;

                    //Read the values for the current line
                    //Account
                    Account = StringHelper.GetNextCSV(ref ImportLine, Separator, false).ToString();
                    //BudgetType
                    BudgetTypeUpper = StringHelper.GetNextCSV(ref ImportLine, Separator, false).ToString().ToUpper();
                    BudgetTypeUpper = BudgetTypeUpper.Replace(" ", ""); //Ad hoc will become ADHOC

                    //Allow for variations on Inf.Base and Inf.N
                    if (BudgetTypeUpper.Contains("INF"))
                    {
                        if (BudgetTypeUpper.Contains("BASE"))
                        {
                            if (BudgetTypeUpper != MFinanceConstants.BUDGET_INFLATE_BASE)
                            {
                                BudgetTypeUpper = MFinanceConstants.BUDGET_INFLATE_BASE;
                            }
                        }
                        else if (BudgetTypeUpper != MFinanceConstants.BUDGET_INFLATE_N)
                        {
                            BudgetTypeUpper = MFinanceConstants.BUDGET_INFLATE_N;
                        }
                    }

                    //BudgetYear
                    BudgetYearStringUpper = (StringHelper.GetNextCSV(ref ImportLine, Separator, false)).ToUpper();

                    //Check validity of CSV file line values
                    if (!ValidateKeyBudgetFields(ALedgerNumber,
                            RowNumber,
                            ref CostCentreTable,
                            ref AccountTable,
                            CostCentre,
                            Account,
                            BudgetTypeUpper,
                            BudgetYearStringUpper,
                            ref AVerificationResult))
                    {
                        AFailedRows++;
                        continue;
                    }

                    //Read the budgetperiod values to check if valid according to type
                    Array.Clear(BudgetPeriods, 0, NumPeriods);

                    if (!ProcessBudgetTypeImportDetails(RowNumber,
                            ref ImportLine,
                            Separator,
                            BudgetTypeUpper,
                            ref BudgetPeriods,
                            BudgetYearStringUpper,
                            CostCentre,
                            Account,
                            ref AVerificationResult))
                    {
                        continue;
                    }

                    //Calculate the budget Year
                    BudgetYearNumber = GetBudgetYearNumber(ALedgerNumber, BudgetYearStringUpper);

                    //Add budget revision record if there's not one already.
                    if (AImportDS.ABudgetRevision.Rows.Find(new object[] { ALedgerNumber, BudgetYearNumber, BdgRevision }) == null)
                    {
                        ABudgetRevisionRow BudgetRevisionRow = (ABudgetRevisionRow)AImportDS.ABudgetRevision.NewRowTyped();
                        BudgetRevisionRow.LedgerNumber = ALedgerNumber;
                        BudgetRevisionRow.Year = BudgetYearNumber;
                        BudgetRevisionRow.Revision = BdgRevision;
                        BudgetRevisionRow.Description = "Budget Import from: " + ACSVFileName;
                        AImportDS.ABudgetRevision.Rows.Add(BudgetRevisionRow);
                    }

                    for (int i = 0; i < NumPeriods; i++)
                    {
                        totalBudgetRowAmount += BudgetPeriods[i];
                    }

                    BudgetTDS mainDS = new BudgetTDS();
                    TDBTransaction transaction = null;

                    DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                        TEnforceIsolationLevel.eilMinimum,
                        ref transaction,
                        delegate
                        {
                            //TODO: need to filter on ABudgetPeriod using LoadViaBudget or LoadViaUniqueKey
                            ABudgetAccess.LoadByUniqueKey(mainDS, ALedgerNumber, BudgetYearNumber, BdgRevision, CostCentre, Account, transaction);

                            #region Validate Data

                            if ((mainDS.ABudget != null) && (mainDS.ABudget.Count > 1))
                            {
                                //TODO: update when budget revisioning is added
                                throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                            "Function:{0} - Duplicates unique keys exist in the Budget table for Ledger: {1} Year: '{2}' ({3}), Cost Centre: '{4}' & Account: '{5}'!"),
                                        Utilities.GetMethodName(true),
                                        ALedgerNumber,
                                        BudgetYearStringUpper,
                                        BudgetYearNumber,
                                        CostCentre,
                                        Account));
                            }

                            #endregion Validate Data
                        });

                    //Check to see if the budget combination already exists:
                    if (mainDS.ABudget.Count > 0)
                    {
                        //Will only be one row
                        ABudgetRow br2 = (ABudgetRow)mainDS.ABudget.Rows[0];

                        //Check if exists in AImportDS
                        int bdgSeq = br2.BudgetSequence;

                        //Add to duplicates-checking table
                        //If not in saved budget table, check if already been imported earlier in the file
                        DataRow duplicateBudgetRow = BudgetTableExistingAndImported.Rows.Find(new object[] { bdgSeq });

                        if (duplicateBudgetRow != null)
                        {
                            //TODO: update when budget revisioning is added
                            AVerificationResult.Add(new TVerificationResult(Catalog.GetString("Row: " + RowNumber.ToString("0000")),
                                    String.Format(Catalog.GetString(
                                            " This budget import row (Year: '{0}', Cost Centre: '{1}', Account: '{2}') is repeated in the import file!"),
                                        BudgetYearStringUpper,
                                        CostCentre,
                                        Account),
                                    TResultSeverity.Resv_Noncritical));

                            AFailedRows++;
                            continue;
                        }

                        BudgetTableExistingAndImported.ImportRow(br2);

                        ABudgetRow bdgRow = (ABudgetRow)AImportDS.ABudget.Rows.Find(new object[] { bdgSeq });

                        if (bdgRow != null)
                        {
                            bool rowUpdated = false;

                            if (bdgRow.BudgetTypeCode != BudgetTypeUpper)
                            {
                                rowUpdated = true;
                                bdgRow.BudgetTypeCode = BudgetTypeUpper;
                            }

                            ABudgetPeriodRow BPRow = null;

                            for (int i = 0; i < NumPeriods; i++)
                            {
                                BPRow = (ABudgetPeriodRow)AImportDS.ABudgetPeriod.Rows.Find(new object[] { bdgSeq, i + 1 });

                                if ((BPRow != null) && (BPRow.BudgetBase != BudgetPeriods[i]))
                                {
                                    rowUpdated = true;
                                    BPRow.BudgetBase = BudgetPeriods[i];
                                }

                                BPRow = null;
                            }

                            if (rowUpdated)
                            {
                                ARecordsUpdated++;
                            }
                        }
                    }
                    else
                    {
                        //If not in saved budget table, check if already been imported earlier in the file
                        DataRow[] duplicateBudgetRows =
                            BudgetTableExistingAndImported.Select(String.Format("{0}={1} And {2}={3} And {4}={5} And {6}='{7}' And {8}='{9}'",
                                    ABudgetTable.GetLedgerNumberDBName(),
                                    ALedgerNumber,
                                    ABudgetTable.GetYearDBName(),
                                    BudgetYearNumber,
                                    ABudgetTable.GetRevisionDBName(),
                                    BdgRevision,
                                    ABudgetTable.GetCostCentreCodeDBName(),
                                    CostCentre,
                                    ABudgetTable.GetAccountCodeDBName(),
                                    Account));

                        if ((duplicateBudgetRows != null) && (duplicateBudgetRows.Length > 0))
                        {
                            //TODO: update when budget revisioning is added
                            AVerificationResult.Add(new TVerificationResult(Catalog.GetString("Row: " + RowNumber.ToString("0000")),
                                    String.Format(Catalog.GetString(
                                            "This budget import row (Year: '{0}', Cost Centre: '{1}', Account: '{2}') is repeated in the import file!"),
                                        BudgetYearStringUpper,
                                        CostCentre,
                                        Account),
                                    TResultSeverity.Resv_Noncritical));

                            AFailedRows++;
                            continue;
                        }

                        //Add the new budget row
                        ABudgetRow BudgetRow = (ABudgetRow)AImportDS.ABudget.NewRowTyped();
                        int newSequence = Convert.ToInt32(TSequenceWebConnector.GetNextSequence(TSequenceNames.seq_budget)); // -1 * (AImportDS.ABudget.Rows.Count + 1);

                        BudgetRow.BudgetSequence = newSequence;
                        BudgetRow.LedgerNumber = ALedgerNumber;
                        BudgetRow.Year = BudgetYearNumber;
                        BudgetRow.Revision = BdgRevision;
                        BudgetRow.CostCentreCode = CostCentre;
                        BudgetRow.AccountCode = Account;
                        BudgetRow.BudgetTypeCode = BudgetTypeUpper;
                        AImportDS.ABudget.Rows.Add(BudgetRow);

                        //Add to import table to check for later duplicates
                        BudgetTableExistingAndImported.ImportRow(BudgetRow);

                        //Add the budget periods
                        for (int i = 0; i < NumPeriods; i++)
                        {
                            ABudgetPeriodRow BudgetPeriodRow = (ABudgetPeriodRow)AImportDS.ABudgetPeriod.NewRowTyped();
                            BudgetPeriodRow.BudgetSequence = newSequence;
                            BudgetPeriodRow.PeriodNumber = i + 1;
                            BudgetPeriodRow.BudgetBase = BudgetPeriods[i];
                            AImportDS.ABudgetPeriod.Rows.Add(BudgetPeriodRow);
                        }
                    }
                }
                catch (Exception ex)
                {
                    TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                            Utilities.GetMethodSignature(),
                            Environment.NewLine,
                            ex.Message));
                    throw ex;
                }
                finally
                {
                    // Read the next line
                    ImportLine = sr.ReadLine();
                }
            }

            //DataFile.Close();

            return RowNumber;
        }
コード例 #10
0
        public static BudgetTDS LoadBudgetsForYear(Int32 ALedgerNumber, Int32 ABudgetYear)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }
            else if (ABudgetYear < 0)
            {
                throw new ArgumentException(String.Format(Catalog.GetString("Function:{0} - The Budget Year number cannot be negative!"),
                        Utilities.GetMethodName(true)));
            }

            #endregion Validate Arguments

            BudgetTDS MainDS = new BudgetTDS();
            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);

                        #region Validate Data

                        if ((MainDS.ALedger == null) || (MainDS.ALedger.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Ledger data for Ledger number {1} does not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true),
                                    ALedgerNumber));
                        }

                        #endregion Validate Data

                        int numPeriods = MainDS.ALedger[0].NumberOfAccountingPeriods;

                        //Load all by Year
                        LoadABudgetByYearWithCustomColumns(ref MainDS, ALedgerNumber, ABudgetYear, numPeriods, Transaction);

                        //Load budget period data
                        ABudgetTable BudgetTable = new ABudgetTable();
                        ABudgetRow TemplateRow = (ABudgetRow)BudgetTable.NewRow();
                        TemplateRow.Year = ABudgetYear;

                        ABudgetPeriodAccess.LoadViaABudgetTemplate(MainDS, TemplateRow, Transaction);
                        //TODO: add Budget Revision capability when decision made to add it to OP.
                        //  Assume Revision=0 for now until implemented
                        ABudgetRevisionAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABudgetYear, 0, Transaction);
                    });

                // Accept row changes here so that the Client gets 'unmodified' rows
                MainDS.AcceptChanges();

                // Remove all Tables that were not filled with data before remoting them.
                MainDS.RemoveEmptyTables();
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }
コード例 #11
0
        public static bool GenBudgetForNextYear(int ALedgerNumber, int ABudgetSeq, string AForecastType)
        {
            bool retVal = false;

            decimal budgetSum;
            decimal priorAmount         = 0;
            decimal afterAmount         = 0;
            int     periodOfChange      = 0;
            int     gLMSequenceThisYear = 0;
            int     gLMSequenceLastYear = 0;

            ALedgerTable ledgerTable          = FMainDS.ALedger;
            ALedgerRow   ledgerRow            = (ALedgerRow)ledgerTable.Rows[0];
            int          currentFinancialYear = ledgerRow.CurrentFinancialYear;
            int          currentPeriod        = ledgerRow.CurrentPeriod;
            int          numAccPeriods        = ledgerRow.NumberOfAccountingPeriods;

            ABudgetTable budgetTable = FMainDS.ABudget;
            ABudgetRow   budgetRow   = (ABudgetRow)budgetTable.Rows.Find(new object[] { ABudgetSeq });

            #region  Validate Method Parameters

            if ((budgetRow == null) || (budgetRow.LedgerNumber != ledgerRow.LedgerNumber) || (budgetRow.Year != currentFinancialYear))
            {
                TLogging.Log("GenBudgetForNextYear: either could not find budget sequence " + ABudgetSeq.ToString() +
                             "or the sequence does not apply to ledger " + ledgerRow.LedgerNumber.ToString() +
                             "or to ledger current year " + currentFinancialYear.ToString());
                return(retVal);
            }

            if (ALedgerNumber != ledgerRow.LedgerNumber)
            {
                TLogging.Log("GenBudgetForNextYear: method parameter ALedgerNumber is " + ALedgerNumber.ToString() +
                             " but the data set expected the ledger to be " + ledgerRow.LedgerNumber.ToString());
            }

            #endregion

            string accountCode    = budgetRow.AccountCode;
            string costCentreCode = budgetRow.CostCentreCode;

            gLMSequenceThisYear = TCommonBudgetMaintain.GetGLMSequenceForBudget(ALedgerNumber,
                                                                                accountCode,
                                                                                costCentreCode,
                                                                                currentFinancialYear);

            gLMSequenceLastYear = TCommonBudgetMaintain.GetGLMSequenceForBudget(ALedgerNumber,
                                                                                accountCode,
                                                                                costCentreCode,
                                                                                (currentFinancialYear - 1));
            try
            {
                //Update the budget status
                budgetRow.BeginEdit();
                budgetRow.BudgetStatus = false;
                budgetRow.EndEdit();

                string budgetType = budgetRow.BudgetTypeCode;

                decimal budgetAmount    = 0;
                decimal actualAmount    = 0;
                bool    validBudgetType = true;

                switch (budgetType)
                {
                case MFinanceConstants.BUDGET_ADHOC:
                case MFinanceConstants.BUDGET_INFLATE_BASE:

                    for (int i = 1; i < currentPeriod; i++)
                    {
                        //Set budget period
                        actualAmount = TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                       gLMSequenceLastYear,
                                                                       gLMSequenceThisYear,
                                                                       i,
                                                                       numAccPeriods,
                                                                       currentFinancialYear,
                                                                       (currentFinancialYear - 1),
                                                                       false,
                                                                       MFinanceConstants.CURRENCY_BASE);
                        SetBudgetPeriodBaseAmount(ABudgetSeq, i, actualAmount);
                    }

                    for (int j = currentPeriod; j <= MFinanceConstants.MAX_PERIODS; j++)
                    {
                        if (AForecastType == MFinanceConstants.FORECAST_TYPE_BUDGET)
                        {
                            budgetAmount =
                                Math.Round(TCommonBudgetMaintain.GetBudget(gLMSequenceThisYear, -1, j, numAccPeriods,
                                                                           false,
                                                                           MFinanceConstants.CURRENCY_BASE));
                            SetBudgetPeriodBaseAmount(ABudgetSeq, j, budgetAmount);
                        }
                        else
                        {
                            actualAmount = TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                           gLMSequenceLastYear,
                                                                           gLMSequenceThisYear,
                                                                           j,
                                                                           numAccPeriods,
                                                                           currentFinancialYear,
                                                                           (currentFinancialYear - 1),
                                                                           false,
                                                                           MFinanceConstants.CURRENCY_BASE);
                            SetBudgetPeriodBaseAmount(ABudgetSeq, j, actualAmount);
                        }
                    }

                    break;

                case MFinanceConstants.BUDGET_SAME:                          //because this case has no code it will fall through to the next case until it finds code.
                case MFinanceConstants.BUDGET_SPLIT:

                    if ((currentPeriod - 1) != 0)
                    {
                        budgetSum =
                            TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                            gLMSequenceThisYear,
                                                            -1,
                                                            (currentPeriod - 1),
                                                            numAccPeriods,
                                                            currentFinancialYear,
                                                            currentFinancialYear,
                                                            true,
                                                            MFinanceConstants.CURRENCY_BASE);
                    }
                    else
                    {
                        budgetSum = 0;
                    }

                    if (AForecastType == MFinanceConstants.FORECAST_TYPE_BUDGET)
                    {
                        for (int i = currentPeriod; i <= numAccPeriods; i++)
                        {
                            budgetSum += TCommonBudgetMaintain.GetBudget(gLMSequenceThisYear,
                                                                         -1,
                                                                         i,
                                                                         numAccPeriods,
                                                                         false,
                                                                         MFinanceConstants.CURRENCY_BASE);
                        }
                    }
                    else
                    {
                        if (currentPeriod > 1)
                        {
                            budgetSum += TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                         gLMSequenceLastYear,
                                                                         gLMSequenceThisYear,
                                                                         numAccPeriods,
                                                                         numAccPeriods,
                                                                         currentFinancialYear,
                                                                         (currentFinancialYear - 1),
                                                                         true,
                                                                         MFinanceConstants.CURRENCY_BASE) -
                                         TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                         gLMSequenceLastYear,
                                                                         gLMSequenceThisYear,
                                                                         (currentPeriod - 1),
                                                                         numAccPeriods,
                                                                         currentFinancialYear,
                                                                         (currentFinancialYear - 1),
                                                                         true,
                                                                         MFinanceConstants.CURRENCY_BASE);
                        }
                        else
                        {
                            budgetSum += TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                         gLMSequenceLastYear,
                                                                         gLMSequenceThisYear,
                                                                         numAccPeriods,
                                                                         numAccPeriods,
                                                                         currentFinancialYear,
                                                                         (currentFinancialYear - 1),
                                                                         true,
                                                                         MFinanceConstants.CURRENCY_BASE);
                        }
                    }

                    budgetSum = budgetSum / numAccPeriods;

                    for (int i = 1; i <= numAccPeriods; i++)
                    {
                        SetBudgetPeriodBaseAmount(ABudgetSeq, i, Math.Round(budgetSum));
                    }

                    break;

                case MFinanceConstants.BUDGET_INFLATE_N:

                    for (int i = 1; i <= numAccPeriods; i++)
                    {
                        if (GetBudgetPeriodAmount(ABudgetSeq, i) != GetBudgetPeriodAmount(ABudgetSeq, 1))
                        {
                            periodOfChange = i - 1;
                            break;
                        }
                    }

                    /* Calculate average prior to change and after change. */
                    if (periodOfChange < (currentPeriod - 1))
                    {
                        priorAmount = TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                      gLMSequenceThisYear,
                                                                      -1,
                                                                      periodOfChange,
                                                                      numAccPeriods,
                                                                      currentFinancialYear,
                                                                      currentFinancialYear,
                                                                      true,
                                                                      MFinanceConstants.CURRENCY_BASE);

                        afterAmount =
                            TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                            gLMSequenceThisYear,
                                                            -1,
                                                            (currentPeriod - 1),
                                                            numAccPeriods,
                                                            currentFinancialYear,
                                                            currentFinancialYear,
                                                            true,
                                                            MFinanceConstants.CURRENCY_BASE) -
                            TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                            gLMSequenceThisYear,
                                                            -1,
                                                            periodOfChange + 1,
                                                            numAccPeriods,
                                                            currentFinancialYear,
                                                            currentFinancialYear,
                                                            true,
                                                            MFinanceConstants.CURRENCY_BASE);

                        if (AForecastType == MFinanceConstants.FORECAST_TYPE_BUDGET)
                        {
                            for (int i = currentPeriod; i <= numAccPeriods; i++)
                            {
                                afterAmount += TCommonBudgetMaintain.GetBudget(gLMSequenceThisYear,
                                                                               -1,
                                                                               i,
                                                                               numAccPeriods,
                                                                               false,
                                                                               MFinanceConstants.CURRENCY_BASE);
                            }
                        }
                        else
                        {
                            afterAmount += TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                           gLMSequenceLastYear,
                                                                           gLMSequenceThisYear,
                                                                           numAccPeriods,
                                                                           numAccPeriods,
                                                                           currentFinancialYear,
                                                                           (currentFinancialYear - 1),
                                                                           true,
                                                                           MFinanceConstants.CURRENCY_BASE) -
                                           TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                           gLMSequenceLastYear,
                                                                           gLMSequenceThisYear,
                                                                           currentPeriod,
                                                                           numAccPeriods,
                                                                           currentFinancialYear,
                                                                           (currentFinancialYear - 1),
                                                                           true,
                                                                           MFinanceConstants.CURRENCY_BASE);
                        }
                    }
                    else                              /* Period of change HAS NOT taken place. */
                    {
                        if ((currentPeriod - 1) != 0)
                        {
                            priorAmount =
                                TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                gLMSequenceThisYear,
                                                                -1,
                                                                (currentPeriod - 1),
                                                                numAccPeriods,
                                                                currentFinancialYear,
                                                                currentFinancialYear,
                                                                true,
                                                                MFinanceConstants.CURRENCY_BASE);
                        }
                        else
                        {
                            priorAmount = 0;
                        }

                        if (AForecastType == MFinanceConstants.FORECAST_TYPE_BUDGET)
                        {
                            for (int i = currentPeriod; i <= periodOfChange; i++)
                            {
                                priorAmount += TCommonBudgetMaintain.GetBudget(gLMSequenceThisYear,
                                                                               -1,
                                                                               i,
                                                                               numAccPeriods,
                                                                               false,
                                                                               MFinanceConstants.CURRENCY_BASE);
                            }
                        }
                        else
                        {
                            priorAmount = TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                          gLMSequenceLastYear,
                                                                          gLMSequenceThisYear,
                                                                          periodOfChange,
                                                                          numAccPeriods,
                                                                          currentFinancialYear,
                                                                          (currentFinancialYear - 1),
                                                                          true,
                                                                          MFinanceConstants.CURRENCY_BASE) -
                                          TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                          gLMSequenceLastYear,
                                                                          gLMSequenceThisYear,
                                                                          currentPeriod,
                                                                          numAccPeriods,
                                                                          currentFinancialYear,
                                                                          (currentFinancialYear - 1),
                                                                          true,
                                                                          MFinanceConstants.CURRENCY_BASE);
                        }

                        if (AForecastType == MFinanceConstants.FORECAST_TYPE_BUDGET)
                        {
                            for (int i = (periodOfChange + 1); i <= numAccPeriods; i++)
                            {
                                afterAmount += TCommonBudgetMaintain.GetBudget(gLMSequenceThisYear,
                                                                               -1,
                                                                               i,
                                                                               numAccPeriods,
                                                                               false,
                                                                               MFinanceConstants.CURRENCY_BASE);
                            }
                        }
                        else
                        {
                            afterAmount = TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                          gLMSequenceLastYear,
                                                                          gLMSequenceThisYear,
                                                                          numAccPeriods,
                                                                          numAccPeriods,
                                                                          currentFinancialYear,
                                                                          (currentFinancialYear - 1),
                                                                          true,
                                                                          MFinanceConstants.CURRENCY_BASE) -
                                          TCommonBudgetMaintain.GetActual(ALedgerNumber,
                                                                          gLMSequenceLastYear,
                                                                          gLMSequenceThisYear,
                                                                          (periodOfChange + 1),
                                                                          numAccPeriods,
                                                                          currentFinancialYear,
                                                                          (currentFinancialYear - 1),
                                                                          true,
                                                                          MFinanceConstants.CURRENCY_BASE);
                        }

                        /* Dividing after sum by prior sum gives rate of inflation. */
                        priorAmount = priorAmount / periodOfChange;
                        afterAmount = afterAmount / (numAccPeriods - periodOfChange);

                        for (int i = 1; i <= periodOfChange; i++)
                        {
                            SetBudgetPeriodBaseAmount(ABudgetSeq, i, Math.Round(priorAmount, 0));
                        }

                        for (int i = (periodOfChange + 1); i <= numAccPeriods; i++)
                        {
                            SetBudgetPeriodBaseAmount(ABudgetSeq, i, Math.Round(afterAmount, 0));
                        }
                    }

                    break;

                default:
                    validBudgetType = false;
                    break;
                }

                if (!validBudgetType)
                {
                    throw new InvalidOperationException(String.Format("Invalid budget type of: {0} for Budget Seq.: {1}",
                                                                      budgetType,
                                                                      budgetRow.BudgetSequence));
                }

                retVal = true;
            }
            catch (Exception)
            {
                throw;
            }

            return(retVal);
        }
コード例 #12
0
        private void InitialiseBudgetList(ABudgetTable ABdgTable)
        {
            string CheckedMember = "CHECKED";
            string AccountDBN = ABudgetTable.GetAccountCodeDBName();
            string CostCentreDBN = ABudgetTable.GetCostCentreCodeDBName();
            string BudgetSeqDBN = ABudgetTable.GetBudgetSequenceDBName();
            string CCAccDesc = "CostCentreAccountDescription";
            string BudgetSeqKey = "BudgetSequenceKey";

            //Calculate the longest Cost Centre to calculate padding amount
            ABudgetRow BudgetRow;
            int CostCentreCodeLength = 0;

            if (ABdgTable != null)
            {
                if (ABdgTable.Count > 0)
                {
                    FBudgetsExist = true;

                    for (int i = 0; i < ABdgTable.Count; i++)
                    {
                        BudgetRow = (ABudgetRow)ABdgTable.Rows[i];
                        CostCentreCodeLength = BudgetRow.CostCentreCode.Length;

                        if (CostCentreCodeLength > CostCentrePadding)
                        {
                            CostCentrePadding = CostCentreCodeLength;
                        }
                    }

                    BudgetRow = null;

                    // add empty row so that SetSelectedString for invalid string will not result in undefined behaviour (selecting the first cost centre etc)
                    //ABudgetRow emptyRow = (ABudgetRow)ABdgTable.NewRow();

                    DataView view = new DataView(ABdgTable);
                    view.RowFilter = String.Format("{0}={1}",
                        ABudgetTable.GetLedgerNumberDBName(),
                        FLedgerNumber);
                    DataTable ABdgTable2 = view.ToTable(true, new string[] { BudgetSeqDBN, AccountDBN, CostCentreDBN });

                    ABdgTable2.Columns.Add(new DataColumn(CheckedMember, typeof(bool)));
                    ABdgTable2.Columns.Add(new DataColumn(BudgetSeqKey, typeof(string), BudgetSeqDBN));
                    ABdgTable2.Columns.Add(new DataColumn(CCAccDesc, typeof(string),
                            CostCentreDBN.PadRight(CostCentrePadding + 2, ' ') + " + '-' + " + AccountDBN));

                    clbCostCentreAccountCodes.Columns.Clear();
                    clbCostCentreAccountCodes.AddCheckBoxColumn("", ABdgTable2.Columns[CheckedMember], 17, false);
                    clbCostCentreAccountCodes.AddTextColumn("Key", ABdgTable2.Columns[BudgetSeqKey], 0);
                    clbCostCentreAccountCodes.AddTextColumn("Cost Centre-Account", ABdgTable2.Columns[CCAccDesc], 200);
                    clbCostCentreAccountCodes.DataBindGrid(ABdgTable2, BudgetSeqKey, CheckedMember, BudgetSeqKey, false, true, false);

                    clbCostCentreAccountCodes.SetCheckedStringList("");
                }
            }

            btnOK.Enabled = FBudgetsExist;
            btnSelectAllBudgets.Enabled = FBudgetsExist;
            btnUnselectAllBudgets.Enabled = FBudgetsExist;
        }