Пример #1
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();
                }
            }
        }
Пример #2
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();
                }
            }
        }
Пример #3
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();
                }
            }
        }
Пример #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>
        /// <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();
            }
        }
Пример #5
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();
            }
        }
Пример #6
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();
                }
            }
        }
Пример #7
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());
        }
Пример #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);
        }
Пример #9
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();
        }
Пример #10
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();
        }
Пример #11
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();
            }
        }
Пример #12
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();
            }
        }
Пример #13
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();
        }
Пример #14
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);
                iPtr = -1;
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }
            }
        }
Пример #15
0
        private void LoadAll(Int32 ALedgerNumber, 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 = ALedgerNumber;
                GLMTemplateRow.Year = AYear;

                FGLMpTable = AGeneralLedgerMasterPeriodAccess.LoadViaAGeneralLedgerMasterTemplate(GLMTemplateRow, transaction);
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }
            }
        }
Пример #16
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
Пример #17
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)
                {
                    TLogging.Log(String.Format("\nERROR: No TGet_GLM_Info row found for ({0}, {1}).\n",
                            AAccountCode, ACostCentreCode));
                }
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }
            }
        }
Пример #18
0
        public static TSubmitChangesResult SaveLedgerSettings(
            Int32 ALedgerNumber,
            DateTime ACalendarStartDate,
            ref GLSetupTDS AInspectDS)
        {
            #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 (AInspectDS == null)
            {
                return TSubmitChangesResult.scrNothingToBeSaved;
            }

            #endregion Validate Arguments

            ALedgerTable LedgerTable;
            ALedgerRow LedgerRow;
            AAccountingPeriodTable AccountingPeriodTable;
            AAccountingPeriodRow AccountingPeriodRow;
            AAccountingPeriodTable NewAccountingPeriodTable;
            AAccountingPeriodRow NewAccountingPeriodRow;
            AGeneralLedgerMasterTable GLMTable;
            AGeneralLedgerMasterRow GLMRow;
            AGeneralLedgerMasterPeriodTable GLMPeriodTable;
            AGeneralLedgerMasterPeriodTable TempGLMPeriodTable;
            AGeneralLedgerMasterPeriodTable NewGLMPeriodTable;
            AGeneralLedgerMasterPeriodRow GLMPeriodRow;
            AGeneralLedgerMasterPeriodRow TempGLMPeriodRow;
            AGeneralLedgerMasterPeriodRow NewGLMPeriodRow;

            int CurrentNumberPeriods;
            int NewNumberPeriods;
            int CurrentNumberFwdPostingPeriods;
            int NewNumberFwdPostingPeriods;
            int CurrentLastFwdPeriod;
            int NewLastFwdPeriod;
            int Period;
            Boolean ExtendFwdPeriods = false;
            DateTime PeriodStartDate;
            DateTime CurrentCalendarStartDate;
            Boolean CreateCalendar = false;

            TDBTransaction Transaction = null;
            bool SubmissionOK = false;

            GLSetupTDS InspectDS = AInspectDS;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable,
                    TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    ref SubmissionOK,
                    delegate
                    {
                        // load ledger row currently saved in database so it can be used for comparison with modified data
                        LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction);

                        #region Validate Data

                        if ((LedgerTable == null) || (LedgerTable.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

                        LedgerRow = (ALedgerRow)LedgerTable.Rows[0];

                        if (InspectDS.ALedger != null)
                        {
                            // initialize variables for accounting periods and forward periods
                            CurrentNumberPeriods = LedgerRow.NumberOfAccountingPeriods;
                            NewNumberPeriods = ((ALedgerRow)(InspectDS.ALedger.Rows[0])).NumberOfAccountingPeriods;

                            CurrentNumberFwdPostingPeriods = LedgerRow.NumberFwdPostingPeriods;
                            NewNumberFwdPostingPeriods = ((ALedgerRow)(InspectDS.ALedger.Rows[0])).NumberFwdPostingPeriods;

                            // retrieve currently saved calendar start date (start date of financial year)
                            AAccountingPeriodTable CalendarTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, 1, Transaction);
                            CurrentCalendarStartDate = DateTime.MinValue;

                            if (CalendarTable.Count > 0)
                            {
                                CurrentCalendarStartDate = ((AAccountingPeriodRow)CalendarTable.Rows[0]).PeriodStartDate;
                            }

                            // update accounting periods (calendar):
                            // this only needs to be done if the calendar mode is changed
                            // or if calendar mode is monthly and the start date has changed
                            // or if not monthly and number of periods has changed
                            if (((ALedgerRow)(InspectDS.ALedger.Rows[0])).CalendarMode != LedgerRow.CalendarMode)
                            {
                                CreateCalendar = true;
                            }
                            else if (((ALedgerRow)(InspectDS.ALedger.Rows[0])).CalendarMode
                                     && (ACalendarStartDate != CurrentCalendarStartDate))
                            {
                                CreateCalendar = true;
                            }
                            else if (!((ALedgerRow)(InspectDS.ALedger.Rows[0])).CalendarMode
                                     && (NewNumberPeriods != CurrentNumberPeriods))
                            {
                                CreateCalendar = true;
                            }

                            if (!CreateCalendar
                                && (NewNumberFwdPostingPeriods < CurrentNumberFwdPostingPeriods))
                            {
                                CreateCalendar = true;
                            }

                            if (!CreateCalendar
                                && (NewNumberFwdPostingPeriods > CurrentNumberFwdPostingPeriods))
                            {
                                // in this case only extend the periods (as there may already be existing transactions)
                                ExtendFwdPeriods = true;
                            }

                            // now perform the actual update of accounting periods (calendar)
                            if (CreateCalendar)
                            {
                                // first make sure all accounting period records are deleted
                                if (AAccountingPeriodAccess.CountViaALedger(ALedgerNumber, Transaction) > 0)
                                {
                                    AAccountingPeriodTable TemplateTable = new AAccountingPeriodTable();
                                    AAccountingPeriodRow TemplateRow = TemplateTable.NewRowTyped(false);
                                    TemplateRow.LedgerNumber = ALedgerNumber;
                                    AAccountingPeriodAccess.DeleteUsingTemplate(TemplateRow, null, Transaction);
                                }

                                // now create all accounting period records according to monthly calendar mode
                                // (at the same time create forwarding periods. If number of forwarding periods also
                                // changes with this saving method then this will be dealt with further down in the code)
                                NewAccountingPeriodTable = new AAccountingPeriodTable();

                                PeriodStartDate = ACalendarStartDate;

                                for (Period = 1; Period <= NewNumberPeriods; Period++)
                                {
                                    NewAccountingPeriodRow = NewAccountingPeriodTable.NewRowTyped();
                                    NewAccountingPeriodRow.LedgerNumber = ALedgerNumber;
                                    NewAccountingPeriodRow.AccountingPeriodNumber = Period;
                                    NewAccountingPeriodRow.PeriodStartDate = PeriodStartDate;

                                    //TODO: Calendar vs Financial Date Handling - Check for current ledger number of periods
                                    if ((((ALedgerRow)(InspectDS.ALedger.Rows[0])).NumberOfAccountingPeriods == 13)
                                        && (Period == 12))
                                    {
                                        // in case of 12 periods the second last period represents the last month except for the very last day
                                        NewAccountingPeriodRow.PeriodEndDate = PeriodStartDate.AddMonths(1).AddDays(-2);
                                    }
                                    else if ((((ALedgerRow)(InspectDS.ALedger.Rows[0])).NumberOfAccountingPeriods == 13)
                                             && (Period == 13))
                                    {
                                        // in case of 13 periods the last period just represents the very last day of the financial year
                                        NewAccountingPeriodRow.PeriodEndDate = PeriodStartDate;
                                    }
                                    else
                                    {
                                        NewAccountingPeriodRow.PeriodEndDate = PeriodStartDate.AddMonths(1).AddDays(-1);
                                    }

                                    NewAccountingPeriodRow.AccountingPeriodDesc = PeriodStartDate.ToString("MMMM");
                                    NewAccountingPeriodTable.Rows.Add(NewAccountingPeriodRow);
                                    PeriodStartDate = NewAccountingPeriodRow.PeriodEndDate.AddDays(1);
                                }

                                AAccountingPeriodAccess.SubmitChanges(NewAccountingPeriodTable, Transaction);

                                TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing(
                                    TCacheableFinanceTablesEnum.AccountingPeriodList.ToString());

                                CurrentNumberPeriods = NewNumberPeriods;
                            }

                            // check if any new forwarding periods need to be created
                            if (CreateCalendar || ExtendFwdPeriods)
                            {
                                // now create new forwarding posting periods (if at all needed)
                                NewAccountingPeriodTable = new AAccountingPeriodTable();

                                // if calendar was created then there are no forward periods yet
                                if (CreateCalendar)
                                {
                                    Period = CurrentNumberPeriods + 1;
                                }
                                else
                                {
                                    Period = CurrentNumberPeriods + CurrentNumberFwdPostingPeriods + 1;
                                }

                                while (Period <= NewNumberPeriods + NewNumberFwdPostingPeriods)
                                {
                                    AccountingPeriodTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber,
                                        Period - CurrentNumberPeriods,
                                        Transaction);
                                    AccountingPeriodRow = (AAccountingPeriodRow)AccountingPeriodTable.Rows[0];

                                    NewAccountingPeriodRow = NewAccountingPeriodTable.NewRowTyped();
                                    NewAccountingPeriodRow.LedgerNumber = ALedgerNumber;
                                    NewAccountingPeriodRow.AccountingPeriodNumber = Period;
                                    NewAccountingPeriodRow.AccountingPeriodDesc = AccountingPeriodRow.AccountingPeriodDesc;
                                    NewAccountingPeriodRow.PeriodStartDate = AccountingPeriodRow.PeriodStartDate.AddYears(1);
                                    NewAccountingPeriodRow.PeriodEndDate = AccountingPeriodRow.PeriodEndDate.AddYears(1);

                                    NewAccountingPeriodTable.Rows.Add(NewAccountingPeriodRow);

                                    Period++;
                                }

                                AAccountingPeriodAccess.SubmitChanges(NewAccountingPeriodTable, Transaction);

                                TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing(
                                    TCacheableFinanceTablesEnum.AccountingPeriodList.ToString());

                                // also create new general ledger master periods with balances
                                CurrentLastFwdPeriod = LedgerRow.NumberOfAccountingPeriods + CurrentNumberFwdPostingPeriods;
                                NewLastFwdPeriod = LedgerRow.NumberOfAccountingPeriods + NewNumberFwdPostingPeriods;
                                // TODO: the following 2 lines would need to replace the 2 lines above if not all possible forward periods are created initially
                                //CurrentLastFwdPeriod = LedgerRow.CurrentPeriod + CurrentNumberFwdPostingPeriods;
                                //NewLastFwdPeriod = LedgerRow.CurrentPeriod + NewNumberFwdPostingPeriods;

                                GLMTable = new AGeneralLedgerMasterTable();
                                AGeneralLedgerMasterRow template = GLMTable.NewRowTyped(false);

                                template.LedgerNumber = ALedgerNumber;
                                template.Year = LedgerRow.CurrentFinancialYear;

                                // find all general ledger master records of the current financial year for given ledger
                                GLMTable = AGeneralLedgerMasterAccess.LoadUsingTemplate(template, Transaction);

                                NewGLMPeriodTable = new AGeneralLedgerMasterPeriodTable();

                                foreach (DataRow Row in GLMTable.Rows)
                                {
                                    // for each of the general ledger master records of the current financial year set the
                                    // new, extended forwarding glm period records (most likely they will not exist yet
                                    // but if they do then update values)
                                    GLMRow = (AGeneralLedgerMasterRow)Row;
                                    GLMPeriodTable =
                                        AGeneralLedgerMasterPeriodAccess.LoadByPrimaryKey(GLMRow.GlmSequence, CurrentLastFwdPeriod, Transaction);

                                    if (GLMPeriodTable.Count > 0)
                                    {
                                        GLMPeriodRow = (AGeneralLedgerMasterPeriodRow)GLMPeriodTable.Rows[0];

                                        for (Period = CurrentLastFwdPeriod + 1; Period <= NewLastFwdPeriod; Period++)
                                        {
                                            if (AGeneralLedgerMasterPeriodAccess.Exists(GLMPeriodRow.GlmSequence, Period, Transaction))
                                            {
                                                // if the record already exists then just change values
                                                TempGLMPeriodTable = AGeneralLedgerMasterPeriodAccess.LoadByPrimaryKey(GLMPeriodRow.GlmSequence,
                                                    Period,
                                                    Transaction);
                                                TempGLMPeriodRow = (AGeneralLedgerMasterPeriodRow)TempGLMPeriodTable.Rows[0];
                                                TempGLMPeriodRow.ActualBase = GLMPeriodRow.ActualBase;
                                                TempGLMPeriodRow.ActualIntl = GLMPeriodRow.ActualIntl;

                                                if (!GLMPeriodRow.IsActualForeignNull())
                                                {
                                                    TempGLMPeriodRow.ActualForeign = GLMPeriodRow.ActualForeign;
                                                }
                                                else
                                                {
                                                    TempGLMPeriodRow.SetActualForeignNull();
                                                }

                                                NewGLMPeriodTable.Merge(TempGLMPeriodTable, true);
                                            }
                                            else
                                            {
                                                // add new row since it does not exist yet
                                                NewGLMPeriodRow = NewGLMPeriodTable.NewRowTyped();
                                                NewGLMPeriodRow.GlmSequence = GLMPeriodRow.GlmSequence;
                                                NewGLMPeriodRow.PeriodNumber = Period;
                                                NewGLMPeriodRow.ActualBase = GLMPeriodRow.ActualBase;
                                                NewGLMPeriodRow.ActualIntl = GLMPeriodRow.ActualIntl;

                                                if (!GLMPeriodRow.IsActualForeignNull())
                                                {
                                                    NewGLMPeriodRow.ActualForeign = GLMPeriodRow.ActualForeign;
                                                }
                                                else
                                                {
                                                    NewGLMPeriodRow.SetActualForeignNull();
                                                }

                                                NewGLMPeriodTable.Rows.Add(NewGLMPeriodRow);
                                            }
                                        }

                                        // remove periods if the number of periods + forwarding periods has been reduced
                                        int NumberOfExistingPeriods = LedgerRow.NumberOfAccountingPeriods + LedgerRow.NumberFwdPostingPeriods;

                                        while ((NewNumberPeriods + NewNumberFwdPostingPeriods) < NumberOfExistingPeriods)
                                        {
                                            AGeneralLedgerMasterPeriodAccess.DeleteByPrimaryKey(GLMPeriodRow.GlmSequence,
                                                NumberOfExistingPeriods,
                                                Transaction);

                                            NumberOfExistingPeriods--;
                                        }
                                    }
                                }

                                // just one SubmitChanges for all records needed
                                AGeneralLedgerMasterPeriodAccess.SubmitChanges(NewGLMPeriodTable, Transaction);
                            }
                        }

                        // update a_ledger_init_flag records for:
                        // suspense account flag: "SUSP-ACCT"
                        // budget flag: "BUDGET"
                        // base currency: "CURRENCY"
                        // international currency: "INTL-CURRENCY" (this is a new flag for OpenPetra)
                        // current period (start of ledger date): CURRENT-PERIOD
                        // calendar settings: CAL
                        AddOrRemoveLedgerInitFlag(ALedgerNumber, MFinanceConstants.LEDGER_INIT_FLAG_SUSP_ACC, LedgerRow.SuspenseAccountFlag,
                            Transaction);
                        AddOrRemoveLedgerInitFlag(ALedgerNumber, MFinanceConstants.LEDGER_INIT_FLAG_BUDGET, LedgerRow.BudgetControlFlag, Transaction);
                        AddOrRemoveLedgerInitFlag(ALedgerNumber, MFinanceConstants.LEDGER_INIT_FLAG_CURRENCY, !LedgerRow.IsBaseCurrencyNull(),
                            Transaction);
                        AddOrRemoveLedgerInitFlag(ALedgerNumber, MFinanceConstants.LEDGER_INIT_FLAG_INTL_CURRENCY, !LedgerRow.IsIntlCurrencyNull(),
                            Transaction);
                        AddOrRemoveLedgerInitFlag(ALedgerNumber, MFinanceConstants.LEDGER_INIT_FLAG_CURRENT_PERIOD, !LedgerRow.IsCurrentPeriodNull(),
                            Transaction);
                        AddOrRemoveLedgerInitFlag(ALedgerNumber, MFinanceConstants.LEDGER_INIT_FLAG_CAL, !LedgerRow.IsNumberOfAccountingPeriodsNull(),
                            Transaction);

                        GLSetupTDSAccess.SubmitChanges(InspectDS);

                        SubmissionOK = true;
                    });
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return TSubmitChangesResult.scrOK;
        }