Esempio n. 1
0
        /// <summary>
        /// Loads only GLM Data selected by Ledger Number, Year and Account Code ...
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ACurrentFinancialYear"></param>
        /// <param name="AAccountCode"></param>
        public TGlmInfo(int ALedgerNumber, int ACurrentFinancialYear, string AAccountCode)
        {
            bool NewTransaction = false;

            try
            {
                TDBTransaction transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                               TEnforceIsolationLevel.eilMinimum,
                                                                                               out NewTransaction);
                FGLMTbl = new AGeneralLedgerMasterTable();
                AGeneralLedgerMasterRow GLMTemplateRow = FGLMTbl.NewRowTyped(false);
                GLMTemplateRow.LedgerNumber = ALedgerNumber;
                GLMTemplateRow.AccountCode  = AAccountCode;
                GLMTemplateRow.Year         = ACurrentFinancialYear;
                FGLMTbl = AGeneralLedgerMasterAccess.LoadUsingTemplate(GLMTemplateRow, transaction);
                TLogging.LogAtLevel(1,
                                    "TGlmInfo(" + ALedgerNumber + ", " + ACurrentFinancialYear + ", " + AAccountCode + ") has loaded " + FGLMTbl.Rows.Count +
                                    " Rows.");
                iPtr = -1;
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }
            }
        }
Esempio n. 2
0
        private Boolean RunRevaluationIntern()
        {
            TDBTransaction Transaction = null;

            AGeneralLedgerMasterTable GlmTable    = new AGeneralLedgerMasterTable();
            AGeneralLedgerMasterRow   glmTemplate = (AGeneralLedgerMasterRow)GlmTable.NewRowTyped(false);

            glmTemplate.LedgerNumber = F_LedgerNum;
            glmTemplate.Year         = F_FinancialYear;

            for (Int32 i = 0; i < F_ForeignAccount.Length; i++)
            {
                glmTemplate.AccountCode = F_ForeignAccount[i];
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                          ref Transaction,
                                                                          delegate
                {
                    GlmTable = AGeneralLedgerMasterAccess.LoadUsingTemplate(glmTemplate, Transaction);
                });

                if (GlmTable.Rows.Count > 0)
                {
                    RevaluateAccount(GlmTable, F_ExchangeRate[i], F_ForeignAccount[i]);
                }
            }

            return(CloseRevaluationAccountingBatch());
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="AAccountCode"></param>
        /// <param name="ACurrentFinancialYear">Number of the year after the the installation of the software</param>
        public TGet_GLM_Info(int ALedgerNumber, string AAccountCode, int ACurrentFinancialYear)
        {
            bool NewTransaction = false;

            try
            {
                TDBTransaction transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                               TEnforceIsolationLevel.eilMinimum,
                                                                                               out NewTransaction);

                FGLMTbl = new AGeneralLedgerMasterTable();
                AGeneralLedgerMasterRow GLMTemplateRow = FGLMTbl.NewRowTyped(false);
                GLMTemplateRow.LedgerNumber = ALedgerNumber;
                GLMTemplateRow.AccountCode  = AAccountCode;
                GLMTemplateRow.Year         = ACurrentFinancialYear;
                FGLMTbl = AGeneralLedgerMasterAccess.LoadUsingTemplate(GLMTemplateRow, transaction);
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// THIS METHOD DOES NOT RETURN USEFUL VALUES because the Year is not specified.
        /// It is only called from tests, and those tests pass,
        /// because there's no previous financial year in the database,
        /// because the data returned by this method is from the earliest year in the ledger.
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="AAccountCode"></param>
        /// <param name="ACostCentreCode"></param>
        public TGet_GLM_Info(int ALedgerNumber, string AAccountCode, string ACostCentreCode)
        {
            bool NewTransaction = false;

            try
            {
                TDBTransaction transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                               TEnforceIsolationLevel.eilMinimum,
                                                                                               out NewTransaction);

                FGLMTbl = new AGeneralLedgerMasterTable();
                AGeneralLedgerMasterRow GLMTemplateRow = FGLMTbl.NewRowTyped(false);
                GLMTemplateRow.LedgerNumber   = ALedgerNumber;
                GLMTemplateRow.AccountCode    = AAccountCode;
                GLMTemplateRow.CostCentreCode = ACostCentreCode;
                FGLMTbl = AGeneralLedgerMasterAccess.LoadUsingTemplate(GLMTemplateRow, transaction);

                if (FGLMTbl.Rows.Count == 0)
                {
//                    String msg = TLogging.StackTraceToText(new StackTrace(true));
                    String msg = "";

                    TLogging.Log(String.Format("ERROR: No TGet_GLM_Info row found for ({0}, {1}).",
                                               ACostCentreCode, AAccountCode, msg));
                }
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Loads <b>all</b> GLMP data for the selected year
        /// </summary>
        public void LoadByYear(Int32 AYear)
        {
            bool NewTransaction = false;

            try
            {
                TDBTransaction transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                               TEnforceIsolationLevel.eilMinimum,
                                                                                               out NewTransaction);

                AGeneralLedgerMasterTable GLMTemplateTbl = new AGeneralLedgerMasterTable();
                AGeneralLedgerMasterRow   GLMTemplateRow = GLMTemplateTbl.NewRowTyped(false);
                GLMTemplateRow.LedgerNumber = FLedgerNumber;
                GLMTemplateRow.Year         = AYear;

                FGLMpTable = AGeneralLedgerMasterPeriodAccess.LoadViaAGeneralLedgerMasterTemplate(GLMTemplateRow, transaction);
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Loads only GLM Data selected by Ledger Number, Year and Account Code ...
        /// </summary>
        public TGlmInfo(int ALedgerNumber, int ACurrentFinancialYear, string AAccountCode, TDataBase ADataBase = null)
        {
            TDBTransaction transaction = new TDBTransaction();
            TDataBase      db          = DBAccess.Connect("TGlmInfo", ADataBase);

            db.ReadTransaction(
                ref transaction,
                delegate
            {
                FGLMTbl = new AGeneralLedgerMasterTable();
                AGeneralLedgerMasterRow GLMTemplateRow = FGLMTbl.NewRowTyped(false);
                GLMTemplateRow.LedgerNumber            = ALedgerNumber;
                GLMTemplateRow.AccountCode             = AAccountCode;
                GLMTemplateRow.Year = ACurrentFinancialYear;
                FGLMTbl             = AGeneralLedgerMasterAccess.LoadUsingTemplate(GLMTemplateRow, transaction);
                TLogging.LogAtLevel(1,
                                    "TGlmInfo(" + ALedgerNumber + ", " + ACurrentFinancialYear + ", " + AAccountCode + ") has loaded " + FGLMTbl.Rows.Count +
                                    " Rows.");
                iPtr = -1;
            });

            if (ADataBase == null)
            {
                db.CloseDBConnection();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// THIS METHOD DOES NOT RETURN USEFUL VALUES because the Year is not specified.
        /// It is only called from tests, and those tests pass,
        /// because there's no previous financial year in the database,
        /// because the data returned by this method is from the earliest year in the ledger.
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="AAccountCode"></param>
        /// <param name="ACostCentreCode"></param>
        /// <param name="ADataBase"></param>
        public TGet_GLM_Info(int ALedgerNumber, string AAccountCode, string ACostCentreCode, TDataBase ADataBase = null)
        {
            TDBTransaction transaction = new TDBTransaction();
            TDataBase      db          = DBAccess.Connect("TGet_GLM_Info", ADataBase);

            db.ReadTransaction(ref transaction,
                               delegate
            {
                FGLMTbl = new AGeneralLedgerMasterTable();
                AGeneralLedgerMasterRow GLMTemplateRow = FGLMTbl.NewRowTyped(false);
                GLMTemplateRow.LedgerNumber            = ALedgerNumber;
                GLMTemplateRow.AccountCode             = AAccountCode;
                GLMTemplateRow.CostCentreCode          = ACostCentreCode;
                FGLMTbl = AGeneralLedgerMasterAccess.LoadUsingTemplate(GLMTemplateRow, transaction);

                if (FGLMTbl.Rows.Count == 0)
                {
                    // String msg = TLogging.StackTraceToText(new StackTrace(true));
                    String msg = "";

                    TLogging.Log(String.Format("ERROR: No TGet_GLM_Info row found for ({0}, {1}).",
                                               ACostCentreCode, AAccountCode, msg));
                }
            });

            if (ADataBase == null)
            {
                db.CloseDBConnection();
            }
        }
Esempio n. 8
0
        /// Returns true if it seems to be OK.
        private Boolean RunRevaluationIntern()
        {
            TDBTransaction Transaction = null;

            AGeneralLedgerMasterTable GlmTable    = new AGeneralLedgerMasterTable();
            AGeneralLedgerMasterRow   glmTemplate = (AGeneralLedgerMasterRow)GlmTable.NewRowTyped(false);
            Boolean transactionsWereCreated       = false;

            glmTemplate.LedgerNumber = F_LedgerNum;
            glmTemplate.Year         = F_FinancialYear;

            for (Int32 i = 0; i < F_ForeignAccount.Length; i++)
            {
                glmTemplate.AccountCode = F_ForeignAccount[i];
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                          ref Transaction,
                                                                          delegate
                {
                    GlmTable = AGeneralLedgerMasterAccess.LoadUsingTemplate(glmTemplate, Transaction);
                });

                if (GlmTable.Rows.Count > 0)
                {
                    transactionsWereCreated |= RevaluateAccount(GlmTable, F_ExchangeRate[i], F_ForeignAccount[i]);
                }
            }

            Boolean batchPostedOK = true;

            if (transactionsWereCreated)
            {
                batchPostedOK = CloseRevaluationAccountingBatch();
            }

            if (batchPostedOK)
            {
                if (!transactionsWereCreated) // If no transactions were needed, I'll just advise the user:
                {
                    FVerificationCollection.Add(new TVerificationResult(
                                                    "Post Forex Batch",
                                                    "Exchange rates are unchanged - no revaluation was required.",
                                                    TResultSeverity.Resv_Status));
                }

                for (Int32 i = 0; i < F_ForeignAccount.Length; i++)
                {
                    TLedgerInitFlag.RemoveFlagComponent(F_LedgerNum, MFinanceConstants.LEDGER_INIT_FLAG_REVAL, F_ForeignAccount[i]);
                }
            }
            else
            {
                FVerificationCollection.Add(new TVerificationResult(
                                                "Post Forex Batch",
                                                "The Revaluation Batch could not be posted.",
                                                TResultSeverity.Resv_Critical));
            }

            return(batchPostedOK);
        }
Esempio n. 9
0
        /// <summary>
        /// Next Element of the Row list ...
        /// </summary>
        /// <returns></returns>
        public bool MoveNext()
        {
            if (++iPtr >= FGLMTbl.Rows.Count)
            {
                return(false);
            }

            FglmRow = (AGeneralLedgerMasterRow)FGLMTbl.Rows[iPtr];
            return(true);
        }
Esempio n. 10
0
        private void RunRevaluationIntern()
        {
            Boolean        NewTransaction;
            TDBTransaction DBTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, out NewTransaction);
            AAccountTable  accountTable  = new AAccountTable();

            AAccountRow accountTemplate = (AAccountRow)accountTable.NewRowTyped(false);

            accountTemplate.LedgerNumber        = F_LedgerNum;
            accountTemplate.AccountActiveFlag   = true;
            accountTemplate.ForeignCurrencyFlag = true;
            accountTable = AAccountAccess.LoadUsingTemplate(accountTemplate, DBTransaction);

            AGeneralLedgerMasterTable glmTable    = new AGeneralLedgerMasterTable();
            AGeneralLedgerMasterRow   glmTemplate = (AGeneralLedgerMasterRow)glmTable.NewRowTyped(false);

            glmTemplate.LedgerNumber = F_LedgerNum;
            glmTemplate.Year         = F_FinancialYear;
            glmTable = AGeneralLedgerMasterAccess.LoadUsingTemplate(glmTemplate, DBTransaction);

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }

            if (accountTable.Rows.Count == 0) // not using any foreign accounts?
            {
                return;
            }

            for (int iCnt = 0; iCnt < accountTable.Rows.Count; ++iCnt)
            {
                AAccountRow accountRow = (AAccountRow)accountTable[iCnt];

                for (int kCnt = 0; kCnt < F_CurrencyCode.Length; ++kCnt)
                {
                    // AForeignCurrency[] and ANewExchangeRate[] shall support a value
                    // for this account resp. for the currency of the account
                    if (accountRow.ForeignCurrencyCode.Equals(F_CurrencyCode[kCnt]))
                    {
                        glmTable.DefaultView.RowFilter = "a_account_code_c = '" + accountRow.AccountCode + "'";

                        if (glmTable.DefaultView.Count > 0)
                        {
                            RevaluateAccount(glmTable.DefaultView, F_ExchangeRate[kCnt]);
                        }
                    }
                }
            }

            CloseRevaluationAccountingBatch();
        }
        /// <summary>
        /// Unpost a budget
        /// </summary>
        /// <param name="ABudgetRow"></param>
        /// <param name="ALedgerNumber"></param>
        /// <returns>true if it seemed to go OK</returns>
        private static bool UnPostBudget(ABudgetRow ABudgetRow, int ALedgerNumber)
        {
            /* post the negative budget, which will result in an empty a_glm_period.budget */

            // get the current budget value for each GLM Period, and unpost that budget

            GLPostingDS.AGeneralLedgerMaster.DefaultView.Sort = String.Format("{0},{1},{2},{3}",
                                                                              AGeneralLedgerMasterTable.GetLedgerNumberDBName(),
                                                                              AGeneralLedgerMasterTable.GetYearDBName(),
                                                                              AGeneralLedgerMasterTable.GetAccountCodeDBName(),
                                                                              AGeneralLedgerMasterTable.GetCostCentreCodeDBName());

            int glmIndex = GLPostingDS.AGeneralLedgerMaster.DefaultView.Find(
                new object[] { ALedgerNumber, ABudgetRow.Year, ABudgetRow.AccountCode, ABudgetRow.CostCentreCode });

            if (glmIndex != -1)
            {
                AGeneralLedgerMasterRow glmRow = (AGeneralLedgerMasterRow)GLPostingDS.AGeneralLedgerMaster.DefaultView[glmIndex].Row;

                List <ABudgetPeriodRow> budgetPeriods = new List <ABudgetPeriodRow>();

                for (int Period = 1; Period <= GLPostingDS.ALedger[0].NumberOfAccountingPeriods; Period++)
                {
                    AGeneralLedgerMasterPeriodRow GeneralLedgerMasterPeriodRow =
                        (AGeneralLedgerMasterPeriodRow)GLPostingDS.AGeneralLedgerMasterPeriod.Rows.Find(
                            new object[] { glmRow.GlmSequence, Period });

                    ABudgetPeriodRow budgetPeriodRow = FBudgetTDS.ABudgetPeriod.NewRowTyped(true);
                    budgetPeriodRow.PeriodNumber   = Period;
                    budgetPeriodRow.BudgetSequence = ABudgetRow.BudgetSequence;

                    // use negative amount for unposting
                    budgetPeriodRow.BudgetBase = -1 * GeneralLedgerMasterPeriodRow.BudgetBase;

                    // do not add to the budgetperiod table, but to our local list
                    budgetPeriods.Add(budgetPeriodRow);
                }

                PostBudget(ALedgerNumber, ABudgetRow, budgetPeriods);
            }

            ABudgetRow.BudgetStatus = false;                 //i.e. unposted

            return(true);
        }
Esempio n. 12
0
        public static void GetForeignCurrencyAccountActuals(ref DataTable AForeignCurrencyAccounts, Int32 ALedgerNumber, Int32 AYear)
        {
            DataTable ForeignCurrencyAccounts = AForeignCurrencyAccounts;

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

            db.ReadTransaction(ref Transaction,
                               delegate
            {
                AGeneralLedgerMasterTable glmTbl       = new AGeneralLedgerMasterTable();
                AGeneralLedgerMasterRow GLMTemplateRow = glmTbl.NewRowTyped(false);

                foreach (DataRow ForeignCurrencyAccountRow in ForeignCurrencyAccounts.Rows)
                {
                    GLMTemplateRow.LedgerNumber = ALedgerNumber;
                    GLMTemplateRow.Year         = AYear;
                    GLMTemplateRow.AccountCode  = ForeignCurrencyAccountRow[AAccountTable.GetAccountCodeDBName()].ToString();

                    glmTbl                   = AGeneralLedgerMasterAccess.LoadUsingTemplate(GLMTemplateRow, Transaction);
                    Decimal YtdActual        = 0;
                    Decimal YtdActualForeign = 0;

                    if (glmTbl != null)
                    {
                        //
                        // I need to sum up all the GLM entries for this account:
                        foreach (AGeneralLedgerMasterRow glmRow in glmTbl.Rows)
                        {
                            if (!glmRow.IsYtdActualForeignNull())
                            {
                                YtdActualForeign += glmRow.YtdActualForeign;
                            }

                            YtdActual += glmRow.YtdActualBase;
                        }
                    }

                    ForeignCurrencyAccountRow[AGeneralLedgerMasterTable.GetYtdActualBaseDBName()]    = YtdActual;
                    ForeignCurrencyAccountRow[AGeneralLedgerMasterTable.GetYtdActualForeignDBName()] = YtdActualForeign;
                }
            });

            db.CloseDBConnection();
        }
Esempio n. 13
0
        public static void GetForeignCurrencyAccountActuals(ref DataTable AForeignCurrencyAccounts, Int32 ALedgerNumber, Int32 AYear)
        {
            //string ReturnValue = "";
            DataTable ForeignCurrencyAccounts = AForeignCurrencyAccounts.Clone();

            ForeignCurrencyAccounts.Merge(AForeignCurrencyAccounts);
            string         CostCentreCode = "[" + ALedgerNumber + "]";
            TDBTransaction Transaction    = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(ref Transaction,
                                                           delegate
            {
                foreach (DataRow ForeignCurrencyAccountRow in ForeignCurrencyAccounts.Rows)
                {
                    AGeneralLedgerMasterTable Table = AGeneralLedgerMasterAccess.LoadByUniqueKey(
                        ALedgerNumber, AYear, ForeignCurrencyAccountRow[AAccountTable.GetAccountCodeDBName()].ToString(), CostCentreCode,
                        Transaction);

                    if ((Table != null) && (Table.Rows.Count > 0))
                    {
                        AGeneralLedgerMasterRow Row = Table[0];

                        if (Row.IsYtdActualForeignNull())
                        {
                            ForeignCurrencyAccountRow[AGeneralLedgerMasterTable.GetYtdActualForeignDBName()] = 0;
                        }
                        else
                        {
                            ForeignCurrencyAccountRow[AGeneralLedgerMasterTable.GetYtdActualForeignDBName()] = Row.YtdActualForeign;
                        }

                        ForeignCurrencyAccountRow[AGeneralLedgerMasterTable.GetYtdActualBaseDBName()] = Row.YtdActualBase;
                    }
                    else
                    {
                        ForeignCurrencyAccountRow[AGeneralLedgerMasterTable.GetYtdActualForeignDBName()] = 0;
                        ForeignCurrencyAccountRow[AGeneralLedgerMasterTable.GetYtdActualBaseDBName()]    = 0;
                    }
                }
            });

            AForeignCurrencyAccounts = ForeignCurrencyAccounts;
        }
Esempio n. 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="AAccountCode"></param>
        /// <param name="ACurrentFinancialYear">Number of the year after the the installation of the software</param>
        /// <param name="ADataBase"></param>
        public TGet_GLM_Info(int ALedgerNumber, string AAccountCode, int ACurrentFinancialYear, TDataBase ADataBase = null)
        {
            TDBTransaction transaction = new TDBTransaction();
            TDataBase      db          = DBAccess.Connect("TGet_GLM_Info", ADataBase);

            db.ReadTransaction(ref transaction,
                               delegate
            {
                FGLMTbl = new AGeneralLedgerMasterTable();
                AGeneralLedgerMasterRow GLMTemplateRow = FGLMTbl.NewRowTyped(false);
                GLMTemplateRow.LedgerNumber            = ALedgerNumber;
                GLMTemplateRow.AccountCode             = AAccountCode;
                GLMTemplateRow.Year = ACurrentFinancialYear;
                FGLMTbl             = AGeneralLedgerMasterAccess.LoadUsingTemplate(GLMTemplateRow, transaction);
            });

            if (ADataBase == null)
            {
                db.CloseDBConnection();
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Loads <b>all</b> GLMP data for the selected year
        /// </summary>
        public void LoadByYear(Int32 AYear)
        {
            TDBTransaction transaction = new TDBTransaction();
            TDataBase      db          = DBAccess.Connect("LoadByYear", FDataBase);

            db.ReadTransaction(ref transaction,
                               delegate
            {
                AGeneralLedgerMasterTable GLMTemplateTbl = new AGeneralLedgerMasterTable();
                AGeneralLedgerMasterRow GLMTemplateRow   = GLMTemplateTbl.NewRowTyped(false);
                GLMTemplateRow.LedgerNumber = FLedgerNumber;
                GLMTemplateRow.Year         = AYear;

                FGLMpTable = AGeneralLedgerMasterPeriodAccess.LoadViaAGeneralLedgerMasterTemplate(GLMTemplateRow, transaction);
            });

            if (FDataBase == null)
            {
                db.CloseDBConnection();
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Get the actual amount
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="AGLMSeqThisYear"></param>
        /// <param name="AGLMSeqNextYear"></param>
        /// <param name="APeriodNumber"></param>
        /// <param name="ANumberAccountingPeriods"></param>
        /// <param name="ACurrentFinancialYear"></param>
        /// <param name="AThisYear"></param>
        /// <param name="AYTD"></param>
        /// <param name="ABalSheetForwardPeriods"></param>
        /// <param name="ACurrencySelect"></param>
        /// <returns></returns>
        private static decimal GetActualInternal(int ALedgerNumber,
                                                 int AGLMSeqThisYear,
                                                 int AGLMSeqNextYear,
                                                 int APeriodNumber,
                                                 int ANumberAccountingPeriods,
                                                 int ACurrentFinancialYear,
                                                 int AThisYear,
                                                 bool AYTD,
                                                 bool ABalSheetForwardPeriods,
                                                 string ACurrencySelect)
        {
            decimal retVal = 0;

            decimal currencyAmount         = 0;
            bool    incExpAccountFwdPeriod = false;

            //DEFINE BUFFER a_glm_period FOR a_general_ledger_master_period.
            //DEFINE BUFFER a_glm FOR a_general_ledger_master.
            //DEFINE BUFFER buf_account FOR a_account.

            if (AGLMSeqThisYear == -1)
            {
                return(retVal);
            }

            bool           newTransaction = false;
            TDataBase      db             = DBAccess.Connect("GetActualInternal");
            TDBTransaction dBTransaction  = db.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, out newTransaction);

            AGeneralLedgerMasterTable generalLedgerMasterTable = null;
            AGeneralLedgerMasterRow   generalLedgerMasterRow   = null;

            AGeneralLedgerMasterPeriodTable generalLedgerMasterPeriodTable = null;
            AGeneralLedgerMasterPeriodRow   generalLedgerMasterPeriodRow   = null;

            AAccountTable AccountTable = null;
            AAccountRow   AccountRow   = null;

            try
            {
                if (APeriodNumber == 0)             /* start balance */
                {
                    generalLedgerMasterTable = AGeneralLedgerMasterAccess.LoadByPrimaryKey(AGLMSeqThisYear, dBTransaction);
                    generalLedgerMasterRow   = (AGeneralLedgerMasterRow)generalLedgerMasterTable.Rows[0];

                    switch (ACurrencySelect)
                    {
                    case MFinanceConstants.CURRENCY_BASE:
                        currencyAmount = generalLedgerMasterRow.StartBalanceBase;
                        break;

                    case MFinanceConstants.CURRENCY_INTERNATIONAL:
                        currencyAmount = generalLedgerMasterRow.StartBalanceIntl;
                        break;

                    default:
                        currencyAmount = generalLedgerMasterRow.StartBalanceForeign;
                        break;
                    }
                }
                else if (APeriodNumber > ANumberAccountingPeriods)             /* forwarding periods only exist for the current financial year */
                {
                    if (ACurrentFinancialYear == AThisYear)
                    {
                        generalLedgerMasterPeriodTable = AGeneralLedgerMasterPeriodAccess.LoadByPrimaryKey(AGLMSeqThisYear,
                                                                                                           APeriodNumber,
                                                                                                           dBTransaction);
                        generalLedgerMasterPeriodRow = (AGeneralLedgerMasterPeriodRow)generalLedgerMasterPeriodTable.Rows[0];
                    }
                    else
                    {
                        generalLedgerMasterPeriodTable =
                            AGeneralLedgerMasterPeriodAccess.LoadByPrimaryKey(AGLMSeqNextYear,
                                                                              (APeriodNumber - ANumberAccountingPeriods),
                                                                              dBTransaction);
                        generalLedgerMasterPeriodRow = (AGeneralLedgerMasterPeriodRow)generalLedgerMasterPeriodTable.Rows[0];
                    }
                }
                else             /* normal period */
                {
                    generalLedgerMasterPeriodTable = AGeneralLedgerMasterPeriodAccess.LoadByPrimaryKey(AGLMSeqThisYear, APeriodNumber, dBTransaction);
                    generalLedgerMasterPeriodRow   = (AGeneralLedgerMasterPeriodRow)generalLedgerMasterPeriodTable.Rows[0];
                }

                if (generalLedgerMasterPeriodRow != null)
                {
                    switch (ACurrencySelect)
                    {
                    case MFinanceConstants.CURRENCY_BASE:
                        currencyAmount = generalLedgerMasterPeriodRow.ActualBase;
                        break;

                    case MFinanceConstants.CURRENCY_INTERNATIONAL:
                        currencyAmount = generalLedgerMasterPeriodRow.ActualIntl;
                        break;

                    default:
                        currencyAmount = generalLedgerMasterPeriodRow.ActualForeign;
                        break;
                    }
                }

                if ((APeriodNumber > ANumberAccountingPeriods) && (ACurrentFinancialYear == AThisYear))
                {
                    generalLedgerMasterTable = AGeneralLedgerMasterAccess.LoadByPrimaryKey(AGLMSeqThisYear, dBTransaction);
                    generalLedgerMasterRow   = (AGeneralLedgerMasterRow)generalLedgerMasterTable.Rows[0];

                    AccountTable = AAccountAccess.LoadByPrimaryKey(ALedgerNumber, generalLedgerMasterRow.AccountCode, dBTransaction);
                    AccountRow   = (AAccountRow)AccountTable.Rows[0];

                    if ((AccountRow.AccountCode.ToUpper() == MFinanceConstants.ACCOUNT_TYPE_INCOME.ToUpper()) ||
                        (AccountRow.AccountCode.ToUpper() == MFinanceConstants.ACCOUNT_TYPE_EXPENSE.ToUpper()) &&
                        !ABalSheetForwardPeriods)
                    {
                        incExpAccountFwdPeriod = true;
                        currencyAmount        -= GetActualInternal(ALedgerNumber,
                                                                   AGLMSeqThisYear,
                                                                   AGLMSeqNextYear,
                                                                   ANumberAccountingPeriods,
                                                                   ANumberAccountingPeriods,
                                                                   ACurrentFinancialYear,
                                                                   AThisYear,
                                                                   true,
                                                                   ABalSheetForwardPeriods,
                                                                   ACurrencySelect);
                    }
                }

                if (!AYTD)
                {
                    if (!((APeriodNumber == (ANumberAccountingPeriods + 1)) && incExpAccountFwdPeriod) &&
                        !((APeriodNumber == (ANumberAccountingPeriods + 1)) && (ACurrentFinancialYear > AThisYear)))
                    {
                        /* if it is an income expense acount, and we are in period 13, nothing needs to be subtracted,
                         * because that was done in correcting the amount in the block above;
                         * if we are in a previous year, in period 13, don't worry about subtracting.
                         *
                         * THIS IS CLEARLY INCORRECT - THE CONDITION ABOVE APPLIES *ONLY* IN THE FIRST FORWARDING PERIOD, NOT IN EVERY FORWARDING PERIOD.
                         * IF THE METHOD IS ONLY CALLED FROM AUTOGENERATE BUDGETS, THIS IS PROBABLY INCONSEQUENTIAL.
                         */
                        currencyAmount -= GetActualInternal(ALedgerNumber,
                                                            AGLMSeqThisYear,
                                                            AGLMSeqNextYear,
                                                            (APeriodNumber - 1),
                                                            ANumberAccountingPeriods,
                                                            ACurrentFinancialYear,
                                                            AThisYear,
                                                            true,
                                                            ABalSheetForwardPeriods,
                                                            ACurrencySelect);
                    }
                }

                retVal = currencyAmount;
            }
            finally
            {
                if (newTransaction)
                {
                    dBTransaction.Rollback();
                }
            }

            return(retVal);
        }
Esempio n. 17
0
        /// <summary>
        /// Next Element of the Row list ...
        /// </summary>
        /// <returns></returns>
        public bool MoveNext()
        {
            if (++iPtr >= FGLMTbl.Rows.Count)
            {
                return false;
            }

            FglmRow = (AGeneralLedgerMasterRow)FGLMTbl.Rows[iPtr];
            return true;
        }
Esempio n. 18
0
        /// <summary>
        /// Run the revaluation and set the flag for the ledger
        /// Returns true if a Reval batch was posted.
        /// </summary>
        public Boolean RunRevaluation(out Int32 glBatchNumber)
        {
            glBatchNumber = -1;
            try
            {
                TLedgerInfo ledger = new TLedgerInfo(F_LedgerNum, FDataBase);
                F_BaseCurrency       = ledger.BaseCurrency;
                F_BaseCurrencyDigits = new TCurrencyInfo(F_BaseCurrency).digits;
                F_RevaluationAccCode = ledger.RevaluationAccount;
                F_FinancialYear      = ledger.CurrentFinancialYear;
                F_AccountingPeriod   = ledger.CurrentPeriod;

                TDBTransaction Transaction = new TDBTransaction();
                FDataBase = DBAccess.Connect("RunRevaluation", FDataBase);

                AGeneralLedgerMasterTable GlmTable    = new AGeneralLedgerMasterTable();
                AGeneralLedgerMasterRow   glmTemplate = (AGeneralLedgerMasterRow)GlmTable.NewRowTyped(false);
                Boolean transactionsWereCreated       = false;

                glmTemplate.LedgerNumber = F_LedgerNum;
                glmTemplate.Year         = F_FinancialYear;

                for (Int32 i = 0; i < F_ForeignAccount.Length; i++)
                {
                    glmTemplate.AccountCode = F_ForeignAccount[i];
                    FDataBase.ReadTransaction(
                        ref Transaction,
                        delegate
                    {
                        GlmTable = AGeneralLedgerMasterAccess.LoadUsingTemplate(glmTemplate, Transaction);
                    });

                    if (GlmTable.Rows.Count > 0)
                    {
                        transactionsWereCreated |= RevaluateAccount(GlmTable, F_ExchangeRate[i], F_ForeignCurrency[i]);
                    }
                }

                Boolean batchPostedOK = true;

                if (transactionsWereCreated)
                {
                    batchPostedOK = CloseRevaluationAccountingBatch(out glBatchNumber);
                }

                if (batchPostedOK)
                {
                    if (!transactionsWereCreated) // If no transactions were needed, I'll just advise the user:
                    {
                        FVerificationCollection.Add(new TVerificationResult(
                                                        "Post Forex Batch",
                                                        "Exchange rates are unchanged - no revaluation was required.",
                                                        TResultSeverity.Resv_Status));
                    }

                    TLedgerInitFlag flag = new TLedgerInitFlag(F_LedgerNum, "", FDataBase);
                    for (Int32 i = 0; i < F_ForeignAccount.Length; i++)
                    {
                        flag.RemoveFlagComponent(MFinanceConstants.LEDGER_INIT_FLAG_REVAL, F_ForeignAccount[i]);
                    }
                }
                else
                {
                    FVerificationCollection.Add(new TVerificationResult(
                                                    "Post Forex Batch",
                                                    "The Revaluation Batch could not be posted.",
                                                    TResultSeverity.Resv_Critical));
                }

                return(batchPostedOK);
            }
            catch (EVerificationException terminate)
            {
                FVerificationCollection = terminate.ResultCollection();
                return(false);
            }
        } // Run Revaluation
        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);
        }
Esempio n. 20
0
        private void RevaluateAccount(DataView GLMView, decimal AExchangeRate)
        {
            foreach (DataRowView RowView in GLMView)
            {
                AGeneralLedgerMasterRow         glmRow  = (AGeneralLedgerMasterRow)RowView.Row;
                ACostCentreTable                tempTbl = null;
                AGeneralLedgerMasterPeriodTable glmpTbl = null;

                TDBTransaction transaction = null;
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                          TEnforceIsolationLevel.eilMinimum,
                                                                          ref transaction,
                                                                          delegate
                {
                    tempTbl = ACostCentreAccess.LoadByPrimaryKey(F_LedgerNum, glmRow.CostCentreCode, transaction);
                    glmpTbl = AGeneralLedgerMasterPeriodAccess.LoadByPrimaryKey(glmRow.GlmSequence, F_AccountingPeriod, transaction);
                });

                if (tempTbl.Rows.Count == 0)
                {
                    continue; // I really don't expect this, but if it does happen, this will prevent a crash!
                }

                ACostCentreRow tempRow = tempTbl[0];

                if (!tempRow.PostingCostCentreFlag)
                {
                    continue; // I do expect this - many rows are not "posting" cost centres.
                }

                try
                {
                    if (glmpTbl.Rows.Count == 0)
                    {
                        continue; // I really don't expect this, but if it does happen, this will prevent a crash!
                    }

                    AGeneralLedgerMasterPeriodRow glmpRow = glmpTbl[0];

                    //
                    // If ActualForeign has not been set, I can't allow the ORM to even attempt to access them:
                    // (If ActualForeign is NULL, that's probably a fault, but this has occured in historical data.)

                    if (glmpRow.IsActualBaseNull() || glmpRow.IsActualForeignNull())
                    {
                        continue;
                    }

                    decimal delta = AccountDelta(glmpRow.ActualBase,
                                                 glmpRow.ActualForeign,
                                                 AExchangeRate,
                                                 F_BaseCurrencyDigits);

                    if (delta != 0)
                    {
                        // Now we have the relevant Cost Centre ...
                        RevaluateCostCentre(glmRow.AccountCode, glmRow.CostCentreCode, delta);
                    }
                    else
                    {
                        string strMessage = String.Format(
                            Catalog.GetString("The account {1}:{0} does not require revaluation."),
                            glmRow.AccountCode,
                            glmRow.CostCentreCode,
                            AExchangeRate);
                        FVerificationCollection.Add(new TVerificationResult(
                                                        strStatusContent, strMessage, TResultSeverity.Resv_Noncritical));
                    }
                }
                catch (EVerificationException terminate)
                {
                    FVerificationCollection = terminate.ResultCollection();
                }
                catch (DivideByZeroException)
                {
                    FVerificationCollection.Add(new TVerificationResult(
                                                    strStatusContent, Catalog.GetString("DivideByZeroException"), TResultSeverity.Resv_Noncritical));
                }
                catch (OverflowException)
                {
                    FVerificationCollection.Add(new TVerificationResult(
                                                    strStatusContent, Catalog.GetString("OverflowException"), TResultSeverity.Resv_Noncritical));
                }
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Next-Year records will be created, and the Ledger will be moved to the new year.
        /// </summary>
        public override Int32 RunOperation()
        {
            Int32 TempGLMSequence = -1;
            Int32 EntryCount = 0;

            if (!FInfoMode)
            {
                FYearEndOperator.SetNextPeriod();
            }

            try
            {
                foreach (AGeneralLedgerMasterRow GlmRowFrom in FGlmPostingFrom.Rows)
                {
                    ++EntryCount;

                    if (FInfoMode)
                    {
                        continue;
                    }

                    FGlmpFrom.DefaultView.RowFilter = "a_glm_sequence_i=" + GlmRowFrom.GlmSequence;

                    AGeneralLedgerMasterRow GlmRowTo = null;
                    //
                    // If there's not already a GLM row for this Account / Cost Centre,
                    // I need to create one now.
                    //
                    Int32 GlmToRowIdx = GlmTDS.AGeneralLedgerMaster.DefaultView.Find(
                        new Object[] { GlmRowFrom.AccountCode, GlmRowFrom.CostCentreCode }
                        );

                    if (GlmToRowIdx >= 0)
                    {
                        GlmRowTo = (AGeneralLedgerMasterRow)GlmTDS.AGeneralLedgerMaster.DefaultView[GlmToRowIdx].Row;
                    }
                    else        // GLM record Not present - I'll make one now...
                    {
                        GlmRowTo = GlmTDS.AGeneralLedgerMaster.NewRowTyped(true);
                        GlmRowTo.GlmSequence = TempGLMSequence;
                        TempGLMSequence--;
                        GlmRowTo.LedgerNumber = FLedgerInfo.LedgerNumber;
                        GlmRowTo.AccountCode = GlmRowFrom.AccountCode;
                        GlmRowTo.CostCentreCode = GlmRowFrom.CostCentreCode;
                        GlmRowTo.Year = FNewYearNum;

                        GlmTDS.AGeneralLedgerMaster.Rows.Add(GlmRowTo);

                        GlmRowTo.YtdActualBase = GlmRowFrom.YtdActualBase;

                        if (!GlmRowFrom.IsYtdActualForeignNull())
                        {
                            GlmRowTo.YtdActualForeign = GlmRowFrom.YtdActualForeign;
                        }
                    }

                    // If the GlmRowTo row already existed, its GLMP records will also exist,
                    // but I need to update them with data from last year's forward periods.
                    // Otherwise I need to create a clutch of matching GLMP records.

                    // The first (FwdPostingPeriods) rows are copies of last year's Fwd records,
                    // and the remainder have the balances carried forward.


                    Int32 LastPeriodFromLastYear = FGlmpFrom.DefaultView.Count;
                    Decimal ActualBase = GlmRowTo.YtdActualBase;
                    Decimal ActualForeign = 0;
                    Boolean UsingForeign = false;

                    if (!GlmRowTo.IsYtdActualForeignNull())
                    {
                        ActualForeign = GlmRowTo.YtdActualForeign;
                        UsingForeign = true;
                    }

                    for (int PeriodCount = 1;
                         PeriodCount <= FLedgerAccountingPeriods + FLedgerFwdPeriods;
                         PeriodCount++)
                    {
                        AGeneralLedgerMasterPeriodRow glmPeriodRow;

                        if (GlmToRowIdx >= 0) // If there's already a GLM entry, I need to use the existing GLMP row for this period
                        {
                            glmPeriodRow = (AGeneralLedgerMasterPeriodRow)GlmTDS.AGeneralLedgerMasterPeriod.DefaultView[PeriodCount - 1].Row;
                        }
                        else // otherwise I need to create one now.
                        {
                            glmPeriodRow = GlmTDS.AGeneralLedgerMasterPeriod.NewRowTyped(true);
                            glmPeriodRow.GlmSequence = GlmRowTo.GlmSequence;
                            glmPeriodRow.PeriodNumber = PeriodCount;
                            GlmTDS.AGeneralLedgerMasterPeriod.Rows.Add(glmPeriodRow);
                        }

                        if (PeriodCount <= LastPeriodFromLastYear) // For any forward periods, I've already got data...
                        {
                            AGeneralLedgerMasterPeriodRow GlmFromRow =
                                (AGeneralLedgerMasterPeriodRow)FGlmpFrom.DefaultView[PeriodCount - 1].Row;
                            ActualBase = GlmFromRow.ActualBase;

                            if (!GlmFromRow.IsActualForeignNull())
                            {
                                ActualForeign = GlmFromRow.ActualForeign;
                                UsingForeign = true;
                            }
                        }

                        glmPeriodRow.ActualBase = ActualBase;

                        if (UsingForeign)
                        {
                            glmPeriodRow.ActualForeign = ActualForeign;
                        }
                    }
                }
            }
            finally
            {
                // Nothing special to do
            }

            if (DoExecuteableCode)
            {
                GlmTDS.ThrowAwayAfterSubmitChanges = true;
                GLPostingTDSAccess.SubmitChanges(GlmTDS);
            }

            return EntryCount;
        } // RunOperation