Exemplo n.º 1
0
        /// <summary>
        /// Any foreign account that has a non-zero opening balance should be marked
        /// for revaluation.
        /// </summary>
        private void NoteForexRevalRequired(Int32 ALedgerNumber, Int32 AYear, Int32 ABatchPeriod)
        {
            TDBTransaction transaction  = null;
            Boolean        submissionOK = true;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable,
                                                                  ref transaction,
                                                                  ref submissionOK,
                                                                  delegate
            {
                string strSQL = "SELECT Account.a_account_code_c," +
                                "SUM (GLMP.a_actual_foreign_n) AS Balance" +
                                " FROM PUB_a_account Account, PUB_a_general_ledger_master GLM, PUB_a_general_ledger_master_period GLMP" +
                                " WHERE Account.a_ledger_number_i=" + ALedgerNumber +
                                " AND Account.a_foreign_currency_flag_l=true" +
                                " AND GLM.a_ledger_number_i=" + ALedgerNumber +
                                " AND GLM.a_account_code_c=Account.a_account_code_c" +
                                " AND GLM.a_year_i= " + AYear +
                                " AND GLMP.a_glm_sequence_i=GLM.a_glm_sequence_i" +
                                " AND GLMP.a_period_number_i=" + ABatchPeriod +
                                " GROUP BY Account.a_account_code_c, GLMP.a_actual_foreign_n";
                DataTable Balance = DBAccess.GDBAccessObj.SelectDT(strSQL, "Balance", transaction);

                foreach (DataRow Row in Balance.Rows)
                {
                    if (Convert.ToDecimal(Row["Balance"]) != 0)
                    {
                        TLedgerInitFlag.SetFlagComponent(ALedgerNumber, MFinanceConstants.LEDGER_INIT_FLAG_REVAL,
                                                         Row["a_account_code_c"].ToString());
                    }
                }
            });
        }
Exemplo n.º 2
0
        public void Test_01_TLedgerInitFlagHandler()
        {
            bool blnOld = new TLedgerInitFlag(43, "RevalTest").IsSet;

            new TLedgerInitFlag(FLedgerNumber, "RevalTest").IsSet = true;
            Assert.IsTrue(new TLedgerInitFlag(
                              FLedgerNumber, "RevalTest").IsSet, "Flag was set a line before");
            TLedgerInitFlag.SetOrRemoveFlag(FLedgerNumber, "RevalTest", true);
            Assert.IsTrue(new TLedgerInitFlag(
                              FLedgerNumber, "RevalTest").IsSet, "Flag was set a line before");
            new TLedgerInitFlag(FLedgerNumber, "RevalTest").IsSet = false;
            Assert.IsFalse(new TLedgerInitFlag(
                               FLedgerNumber, "RevalTest").IsSet, "Flag was reset a line before");
            TLedgerInitFlag.SetOrRemoveFlag(FLedgerNumber, "RevalTest", false);
            Assert.IsFalse(new TLedgerInitFlag(
                               FLedgerNumber, "RevalTest").IsSet, "Flag was reset a line before");

            TLedgerInitFlag.SetFlagComponent(FLedgerNumber, "RevalTest", "A");
            TLedgerInitFlag.SetFlagComponent(FLedgerNumber, "RevalTest", "B");
            TLedgerInitFlag.SetFlagComponent(FLedgerNumber, "RevalTest", "C");
            TLedgerInitFlag.RemoveFlagComponent(FLedgerNumber, "RevalTest", "B");
            String NewVal = TLedgerInitFlag.GetFlagValue(FLedgerNumber, "RevalTest");

            Assert.IsTrue(NewVal == "A,C", "Flag Value of 'RevalTest' should be 'A,C' but is '" + NewVal + "'");
            new TLedgerInitFlag(FLedgerNumber, "RevalTest").IsSet = blnOld;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Any foreign account that has a non-zero opening balance should be marked
        /// for revaluation.
        /// </summary>
        private void NoteForexRevalRequired(Int32 ALedgerNumber, Int32 AYear, Int32 ABatchPeriod)
        {
            TDBTransaction transaction  = new TDBTransaction();
            TDataBase      db           = DBAccess.Connect("NoteForexRevalRequired", FDataBase);
            Boolean        submissionOK = true;

            if (ABatchPeriod == FledgerInfo.NumberOfAccountingPeriods)
            {
                if (FledgerInfo.NumberFwdPostingPeriods == 0)
                {
                    return;
                }
                else
                {
                    // If we're closing the final period, SetNextPeriod() doesn't update FledgerInfo.CurrentPeriod. But we still want to
                    // check the next period for foreign forward-posted amounts, so we have to increment the period locally here.
                    ABatchPeriod++;
                }
            }

            db.WriteTransaction(
                ref transaction,
                ref submissionOK,
                delegate
            {
                string strSQL = "SELECT Account.a_account_code_c," +
                                "SUM (GLMP.a_actual_foreign_n) AS Balance" +
                                " FROM PUB_a_account Account, PUB_a_general_ledger_master GLM, PUB_a_general_ledger_master_period GLMP" +
                                " WHERE Account.a_ledger_number_i=" + ALedgerNumber +
                                " AND Account.a_foreign_currency_flag_l=true" +
                                " AND GLM.a_ledger_number_i=" + ALedgerNumber +
                                " AND GLM.a_account_code_c=Account.a_account_code_c" +
                                " AND GLM.a_year_i= " + AYear +
                                " AND GLMP.a_glm_sequence_i=GLM.a_glm_sequence_i" +
                                " AND GLMP.a_period_number_i=" + ABatchPeriod +
                                " GROUP BY Account.a_account_code_c";
                DataTable Balance = db.SelectDT(strSQL, "Balance", transaction);

                foreach (DataRow Row in Balance.Rows)
                {
                    if (Convert.ToDecimal(Row["Balance"]) != 0)
                    {
                        TLedgerInitFlag flag = new TLedgerInitFlag(ALedgerNumber, "", transaction.DataBaseObj);
                        flag.SetFlagComponent(MFinanceConstants.LEDGER_INIT_FLAG_REVAL,
                                              Row["a_account_code_c"].ToString());
                    }
                }
            });

            if (FDataBase == null)
            {
                db.CloseDBConnection();
            }
        }
Exemplo n.º 5
0
        private void CheckIfRevaluationIsDone()
        {
            if (!FInfoMode)
            {
                return;
            }

            TLedgerInitFlag flag          = new TLedgerInitFlag(FledgerInfo.LedgerNumber, "", null);
            String          RevalAccounts = flag.GetFlagValue(MFinanceConstants.LEDGER_INIT_FLAG_REVAL);

            if (RevalAccounts == "")
            {
                return; // Revaluation has been performed.
            }

            TVerificationResult tvr;

            if (FledgerInfo.CurrentPeriod < FledgerInfo.NumberOfAccountingPeriods)
            {
                tvr = new TVerificationResult(
                    Catalog.GetString("Currency revaluation"),
                    String.Format(
                        Catalog.GetString("Before proceeding you may want to revalue foreign currency accounts {0}."),
                        RevalAccounts),
                    "",
                    TPeriodEndErrorAndStatusCodes.PEEC_05.ToString(), TResultSeverity.Resv_Status);
                // Error is non-critical - the user can choose to continue.
            }
            else
            {
                tvr = new TVerificationResult(
                    Catalog.GetString("Currency revaluation"),
                    String.Format(
                        Catalog.GetString("The foreign currency accounts {0} need to be revalued."),
                        RevalAccounts),
                    "",
                    TPeriodEndErrorAndStatusCodes.PEEC_05.ToString(), TResultSeverity.Resv_Critical);
                // Error is critical - the user nust do a reval.
            }

            FverificationResults.Add(tvr);
        }
Exemplo n.º 6
0
        } // Run Revaluation

        private Boolean RevaluateAccount(AGeneralLedgerMasterTable AGlmTbl, decimal AExchangeRate, string ACurrencyCode)
        {
            Boolean transactionsWereCreated = false;

            foreach (AGeneralLedgerMasterRow glmRow in AGlmTbl.Rows)
            {
                AGeneralLedgerMasterPeriodTable glmpTbl = null;

                TDBTransaction transaction = null;

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

                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, AExchangeRate, ACurrencyCode);
                        transactionsWereCreated = true;
                    }
                    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_Status));
                        TLedgerInitFlag.RemoveFlagComponent(F_LedgerNum, MFinanceConstants.LEDGER_INIT_FLAG_REVAL, glmRow.AccountCode);
                    }
                }
                catch (EVerificationException terminate)
                {
                    FVerificationCollection = terminate.ResultCollection();
                }
            } // foreach

            return(transactionsWereCreated);
        }
Exemplo n.º 7
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