Ejemplo n.º 1
0
        /// <summary>
        /// create a new batch with a consecutive batch number in the ledger
        /// for call inside a server function
        /// for performance reasons submitting (save the data in the database) is done later (not here)
        /// </summary>
        /// <param name="MainDS"></param>
        /// <param name="Transaction"></param>
        /// <param name="LedgerTable"></param>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ADateEffective"></param>
        /// <param name="AForceEffectiveDateToFit"></param>
        /// <returns>the new gift batch row</returns>
        public static AGiftBatchRow CreateANewGiftBatchRow(ref GiftBatchTDS MainDS,
                                                           ref TDBTransaction Transaction,
                                                           ref ALedgerTable LedgerTable,
                                                           Int32 ALedgerNumber,
                                                           DateTime ADateEffective,
                                                           bool AForceEffectiveDateToFit = true)
        {
            AGiftBatchRow NewRow = MainDS.AGiftBatch.NewRowTyped(true);

            NewRow.LedgerNumber = ALedgerNumber;
            LedgerTable[0].LastGiftBatchNumber++;
            NewRow.BatchNumber = LedgerTable[0].LastGiftBatchNumber;
            Int32 BatchYear, BatchPeriod;

            // if DateEffective is outside the range of open periods, use the most fitting date
            TFinancialYear.GetLedgerDatePostingPeriod(ALedgerNumber,
                                                      ref ADateEffective,
                                                      out BatchYear,
                                                      out BatchPeriod,
                                                      Transaction,
                                                      AForceEffectiveDateToFit);
            NewRow.BatchYear          = BatchYear;
            NewRow.BatchPeriod        = BatchPeriod;
            NewRow.GlEffectiveDate    = ADateEffective;
            NewRow.ExchangeRateToBase = 1.0M;
            NewRow.BatchDescription   = "PLEASE ENTER A DESCRIPTION";
            NewRow.BankAccountCode    = TLedgerInfo.GetDefaultBankAccount(ALedgerNumber);
            NewRow.BankCostCentre     = TLedgerInfo.GetStandardCostCentre(ALedgerNumber);
            NewRow.CurrencyCode       = LedgerTable[0].BaseCurrency;
            MainDS.AGiftBatch.Rows.Add(NewRow);
            return(NewRow);
        }
Ejemplo n.º 2
0
        private void ReallocationLoop(TGlmpInfo AGlmpInfo, TCommonAccountingTool YearEndBatch, String AAccountFrom, String ACostCentreFrom)
        {
            string strCostCentreTo = TLedgerInfo.GetStandardCostCentre(FledgerInfo.LedgerNumber);
            string strAccountTo;

            FaccountInfo.AccountCode = AAccountFrom;
            Boolean blnDebitCredit = FaccountInfo.DebitCreditIndicator;
            String narrativeMessage = FstrNarrativeToMessage;

            string strCCAccoutCode = FaccountInfo.SetCarryForwardAccount(); // Move FaccountInfo to the Carry Forward Account - if there is one.

            if (FaccountInfo.IsValid) // The CarryForward account exists..
            {
                strAccountTo = FaccountInfo.AccountCode;

                if (strCCAccoutCode == "SAMECC")
                {
                    strCostCentreTo = ACostCentreFrom;
                    narrativeMessage = FstrNarrativeFromToMessage;
                }
            }
            else // If there's no Carry Forward account, use EARNINGS_BF_ACCT
            {
                FaccountInfo.SetSpecialAccountCode(TAccountPropertyEnum.EARNINGS_BF_ACCT);
                strAccountTo = FaccountInfo.AccountCode;
            }

            if (FledgerInfo.IltAccountFlag) // In either case, change that if ICH_ACCT is set
            {
                FaccountInfo.SetSpecialAccountCode(TAccountPropertyEnum.ICH_ACCT);
                strAccountTo = FaccountInfo.AccountCode;
            }

            if (FledgerInfo.BranchProcessing) // Keep the original Cost Centres - don't roll up
            {
                strCostCentreTo = ACostCentreFrom;
                narrativeMessage = FstrNarrativeFromToMessage;
            }

            if (FglmInfo.YtdActualBase < 0)
            {
                blnDebitCredit = !blnDebitCredit;
            }

            Decimal TransactionAmount = Math.Abs(AGlmpInfo.ActualBase);

            YearEndBatch.AddBaseCurrencyTransaction(
                AAccountFrom, ACostCentreFrom,
                String.Format(narrativeMessage, ACostCentreFrom, AAccountFrom, strCostCentreTo, strAccountTo),
                FstrYearEnd, !blnDebitCredit, TransactionAmount);

            YearEndBatch.AddBaseCurrencyTransaction(
                strAccountTo, strCostCentreTo,
                String.Format(narrativeMessage, ACostCentreFrom, AAccountFrom, strCostCentreTo, strAccountTo),
                FstrYearEnd, blnDebitCredit, TransactionAmount);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// create a new batch with a consecutive batch number in the ledger
        /// for call inside a server function
        /// for performance reasons submitting (save the data in the database) is done later (not here)
        /// </summary>
        /// <param name="AMainDS"></param>
        /// <param name="ATransaction"></param>
        /// <param name="ALedgerNumber"></param>
        /// <returns>the new gift batch row</returns>
        public static ARecurringGiftBatchRow CreateANewRecurringGiftBatchRow(ref GiftBatchTDS AMainDS,
                                                                             ref TDBTransaction ATransaction,
                                                                             Int32 ALedgerNumber)
        {
            #region Validate Arguments

            if (AMainDS == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString(
                                                                                         "Function:{0} - The Gift Batch dataset is NULL!"),
                                                                                     Utilities.GetMethodName(true)));
            }
            else if (ATransaction == null)
            {
                throw new EFinanceSystemDBTransactionNullException(String.Format(Catalog.GetString(
                                                                                     "Function:{0} - Database Transaction must not be NULL!"),
                                                                                 Utilities.GetMethodName(true)));
            }
            else if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                                                                                       "Function:{0} - The Ledger number must be greater than 0!"),
                                                                                   Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            TLedgerInfo info = new TLedgerInfo(ALedgerNumber, ATransaction.DataBaseObj);
            ALedgerAccess.LoadByPrimaryKey(AMainDS, ALedgerNumber, ATransaction);

            if ((AMainDS.ALedger == null) || (AMainDS.ALedger.Count == 0))
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString(
                                                                                         "Function:{0} - The Ledger table is NULL or is empty!"),
                                                                                     Utilities.GetMethodName(true)));
            }

            ARecurringGiftBatchRow NewRow = AMainDS.ARecurringGiftBatch.NewRowTyped(true);

            NewRow.LedgerNumber     = ALedgerNumber;
            NewRow.BatchNumber      = ++AMainDS.ALedger[0].LastRecGiftBatchNumber;
            NewRow.BatchDescription = Catalog.GetString("Please enter recurring batch description");
            NewRow.BankAccountCode  = info.GetDefaultBankAccount();
            NewRow.BankCostCentre   = info.GetStandardCostCentre();
            NewRow.CurrencyCode     = AMainDS.ALedger[0].BaseCurrency;
            AMainDS.ARecurringGiftBatch.Rows.Add(NewRow);
            return(NewRow);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// create a new batch with a consecutive batch number in the ledger
        /// for call inside a server function
        /// for performance reasons submitting (save the data in the database) is done later (not here)
        /// </summary>
        /// <param name="MainDS"></param>
        /// <param name="Transaction"></param>
        /// <param name="LedgerTable"></param>
        /// <param name="ALedgerNumber"></param>
        /// <returns>the new gift batch row</returns>
        public static ARecurringGiftBatchRow CreateANewRecurringGiftBatchRow(ref GiftBatchTDS MainDS,
                                                                             ref TDBTransaction Transaction,
                                                                             ref ALedgerTable LedgerTable,
                                                                             Int32 ALedgerNumber)
        {
            GiftBatchTDS Temp = new GiftBatchTDS();

            ARecurringGiftBatchAccess.LoadViaALedger(Temp, LedgerTable[0].LedgerNumber, Transaction);

            DataView RecurringGiftBatchDV = new DataView(Temp.ARecurringGiftBatch);

            RecurringGiftBatchDV.RowFilter = string.Empty;
            RecurringGiftBatchDV.Sort      = string.Format("{0} DESC",
                                                           ARecurringGiftBatchTable.GetBatchNumberDBName());

            //Recurring batch numbers can be reused so check each time for current highest number
            if (RecurringGiftBatchDV.Count > 0)
            {
                LedgerTable[0].LastRecGiftBatchNumber = (int)(RecurringGiftBatchDV[0][ARecurringGiftBatchTable.GetBatchNumberDBName()]);
            }
            else
            {
                LedgerTable[0].LastRecGiftBatchNumber = 0;
            }

            ARecurringGiftBatchRow NewRow = MainDS.ARecurringGiftBatch.NewRowTyped(true);

            NewRow.LedgerNumber     = ALedgerNumber;
            NewRow.BatchNumber      = ++LedgerTable[0].LastRecGiftBatchNumber;
            NewRow.BatchDescription = Catalog.GetString("Please enter recurring batch description");
            NewRow.BankAccountCode  = TLedgerInfo.GetDefaultBankAccount(ALedgerNumber);
            NewRow.BankCostCentre   = TLedgerInfo.GetStandardCostCentre(ALedgerNumber);
            NewRow.CurrencyCode     = LedgerTable[0].BaseCurrency;
            MainDS.ARecurringGiftBatch.Rows.Add(NewRow);
            return(NewRow);
        }
Ejemplo n.º 5
0
        public static bool GenerateHOSAFiles(int ALedgerNumber,
                                             int APeriodNumber,
                                             int AIchNumber,
                                             string ACostCentre,
                                             String ACurrencySelect,
                                             string AFileName,
                                             out TVerificationResultCollection AVerificationResult
                                             )
        {
            bool Successful = false;

            GLBatchTDS MainDS = new GLBatchTDS();

            TVerificationResultCollection VerificationResult = new TVerificationResultCollection();

            AVerificationResult = VerificationResult;

            TDBTransaction DBTransaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                      TEnforceIsolationLevel.eilMinimum,
                                                                      ref DBTransaction,
                                                                      delegate
            {
                //Load tables needed: AccountingPeriod, Ledger, Account, Cost Centre, Transaction, Gift Batch, ICHStewardship
                ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, DBTransaction);

                /* Retrieve info on the ledger. */
                ALedgerRow LedgerRow = (ALedgerRow)MainDS.ALedger.Rows[0];
                String Currency      = (ACurrencySelect == MFinanceConstants.CURRENCY_BASE) ? LedgerRow.BaseCurrency : LedgerRow.IntlCurrency;

                /*              String StoreNumericFormat = "#" + CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator + "##0";
                 *
                 *              if (CultureInfo.CurrentCulture.NumberFormat.NumberDecimalDigits > 0)
                 *              {
                 *                  string DecPls = new String('0', CultureInfo.CurrentCulture.NumberFormat.NumberDecimalDigits);
                 *                  StoreNumericFormat += CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + DecPls;
                 *              }
                 */
                AAccountingPeriodTable AccountingPeriodTable =
                    AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, APeriodNumber, DBTransaction);
                AAccountingPeriodRow AccountingPeriodRow = (AAccountingPeriodRow)AccountingPeriodTable.Rows[0];
                String MonthName = AccountingPeriodRow.AccountingPeriodDesc;

                //Create table definitions
                DataTable TableForExport = new DataTable();
                TableForExport.Columns.Add("CostCentre", typeof(string));
                TableForExport.Columns.Add("Account", typeof(string));
                TableForExport.Columns.Add("LedgerMonth", typeof(string));
                TableForExport.Columns.Add("ICHPeriod", typeof(string));
                TableForExport.Columns.Add("Date", typeof(DateTime));
                TableForExport.Columns.Add("IndividualDebitTotal", typeof(decimal));
                TableForExport.Columns.Add("IndividualCreditTotal", typeof(decimal));

                string TableForExportHeader = "/** Header **" + "," +
                                              APeriodNumber.ToString() + "," +
                                              TLedgerInfo.GetStandardCostCentre(ALedgerNumber) + "," +
                                              ACostCentre + "," +
                                              DateTime.Today.ToShortDateString() + "," +
                                              Currency;

                //See gi3200.p ln: 170
                //Select any gift transactions to export
                string strSql = TDataBase.ReadSqlFile("ICH.HOSAExportGifts.sql");

                OdbcParameter parameter;

                List <OdbcParameter> parameters = new List <OdbcParameter>();
                parameter       = new OdbcParameter("LedgerNumber", OdbcType.Int);
                parameter.Value = ALedgerNumber;
                parameters.Add(parameter);
                parameter       = new OdbcParameter("Year", OdbcType.Int);
                parameter.Value = LedgerRow.CurrentFinancialYear;
                parameters.Add(parameter);
                parameter       = new OdbcParameter("CostCentre", OdbcType.VarChar);
                parameter.Value = ACostCentre;
                parameters.Add(parameter);

                DataTable TmpTable = DBAccess.GDBAccessObj.SelectDT(strSql, "table", DBTransaction, parameters.ToArray());

                foreach (DataRow untypedTransRow in TmpTable.Rows)
                {
                    string gLMAcctCode  = untypedTransRow[3].ToString();
                    string gLMCostCCode = untypedTransRow[4].ToString();
                    string gLMAcctType  = untypedTransRow[5].ToString();

                    if (gLMAcctType == MFinanceConstants.ACCOUNT_TYPE_INCOME)         //a_account.a_account_type_c
                    {
                        DateTime PeriodStartDate = AccountingPeriodRow.PeriodStartDate;
                        DateTime PeriodEndDate   = AccountingPeriodRow.PeriodEndDate;

                        /*RUN Export_gifts(INPUT pv_ledger_number_i...*/

                        //gi3200-1.i
                        ExportGifts(ALedgerNumber,
                                    ACostCentre,
                                    gLMAcctCode,
                                    MonthName,
                                    APeriodNumber,
                                    PeriodStartDate,
                                    PeriodEndDate,
                                    ACurrencySelect,
                                    AIchNumber,
                                    TableForExport,
                                    VerificationResult);
                    }

                    /* Then see if there are any GL transactions to export */
                    //gi3200.i ln:33

                    /*
                     * This scheme with ODBC parameters consistently causes an "input string is the wrong type" eror:
                     *
                     * strSql = TDataBase.ReadSqlFile("ICH.HOSAExportGLTrans.sql");
                     * OdbcParameter[] SqlParams = new OdbcParameter[] {
                     *      new OdbcParameter("LedgerNumber", (Int32)ALedgerNumber),
                     *      new OdbcParameter("Account", (String)gLMAcctCode),
                     *      new OdbcParameter("CostCentre", (String)gLMCostCCode),
                     *      new OdbcParameter("Narrative", (String)MFinanceConstants.NARRATIVE_YEAR_END_REALLOCATION),
                     *      new OdbcParameter("ICHNumber", (Int32)AIchNumber),
                     *      new OdbcParameter("ICHNumber2", (Int32)AIchNumber),
                     *      new OdbcParameter("PeriodNumber", (Int32)APeriodNumber)
                     *  };
                     * DataTable TmpTransTable = DBAccess.GDBAccessObj.SelectDT(strSql, "Transactions", DBTransaction, SqlParams);
                     */

                    strSql = "SELECT Trans.a_ledger_number_i, Trans.a_batch_number_i, Trans.a_journal_number_i, Trans.a_transaction_number_i, " +
                             "Trans.a_account_code_c, Trans.a_cost_centre_code_c, Trans.a_transaction_date_d, Trans.a_transaction_amount_n, " +
                             "Trans.a_amount_in_base_currency_n, Trans.a_amount_in_intl_currency_n, Trans.a_ich_number_i, Trans.a_system_generated_l, "
                             +
                             "Trans.a_narrative_c, Trans.a_debit_credit_indicator_l  FROM public.a_transaction AS Trans, public.a_journal AS Journal "
                             +
                             "WHERE Trans.a_ledger_number_i = Journal.a_ledger_number_i AND Trans.a_batch_number_i = Journal.a_batch_number_i " +
                             "AND Trans.a_journal_number_i = Journal.a_journal_number_i " +
                             String.Format(
                        "AND Trans.a_ledger_number_i = {0} AND Trans.a_account_code_c = '{1}' AND Trans.a_cost_centre_code_c = '{2}' " +
                        "AND Trans.a_transaction_status_l = true AND NOT (Trans.a_narrative_c LIKE '{3}%' AND Trans.a_system_generated_l = true) "
                        +
                        "AND ((Trans.a_ich_number_i + {4}) = Trans.a_ich_number_i OR Trans.a_ich_number_i = {4}) " +
                        "AND Journal.a_journal_period_i = {5};",
                        ALedgerNumber,
                        gLMAcctCode,
                        gLMCostCCode,
                        MFinanceConstants.NARRATIVE_YEAR_END_REALLOCATION,
                        AIchNumber,
                        APeriodNumber
                        );

                    DataTable TmpTransTable = DBAccess.GDBAccessObj.SelectDT(strSql, "Transactions", DBTransaction);

                    foreach (DataRow untypedTransactRow in TmpTransTable.Rows)
                    {
                        Decimal DebitTotal  = 0;
                        Decimal CreditTotal = 0;

                        bool Debit           = Convert.ToBoolean(untypedTransactRow[13]);       //a_transaction.a_debit_credit_indicator_l
                        bool SystemGenerated = Convert.ToBoolean(untypedTransactRow[11]);       //a_transaction.a_system_generated_l
                        //TODO: Calendar vs Financial Date Handling - Check if number of ledger periods needs to be used here and not 12 assumed
                        string Narrative         = untypedTransactRow[12].ToString();           //a_transaction.a_narrative_c
                        DateTime TransactionDate = Convert.ToDateTime(untypedTransactRow[6]);   //a_transaction.a_transaction_date_d

                        if (ACurrencySelect == MFinanceConstants.CURRENCY_BASE)
                        {
                            decimal AmountInBaseCurrency = Convert.ToDecimal(untypedTransactRow[8]);      //a_transaction.a_amount_in_base_currency_n

                            /* find transaction amount and store as debit or credit */
                            if (Debit)
                            {
                                DebitTotal += AmountInBaseCurrency;
                            }
                            else
                            {
                                CreditTotal += AmountInBaseCurrency;
                            }
                        }
                        else
                        {
                            decimal AmountInIntlCurrency = Convert.ToDecimal(untypedTransactRow[9]);       //a_transaction.a_amount_in_intl_currency_n

                            if (Debit)
                            {
                                DebitTotal += AmountInIntlCurrency;
                            }
                            else
                            {
                                CreditTotal += AmountInIntlCurrency;
                            }
                        }

                        TLogging.LogAtLevel(4, "HOSA-Narrative: " + Narrative);

                        //Check for specific narrative strings
                        bool IsNarrativeGBGiftBatch            = false;
                        int LenNarrativeGBGiftBatch            = MFinanceConstants.NARRATIVE_GB_GIFT_BATCH.Length;
                        bool IsNarrativeGiftsReceivedGiftBatch = false;
                        int LenNarrativeGiftsReceivedGiftBatch = MFinanceConstants.NARRATIVE_GIFTS_RECEIVED_GIFT_BATCH.Length;

                        if (Narrative.Length >= LenNarrativeGiftsReceivedGiftBatch)
                        {
                            IsNarrativeGiftsReceivedGiftBatch =
                                (Narrative.Substring(0,
                                                     LenNarrativeGiftsReceivedGiftBatch) == MFinanceConstants.NARRATIVE_GIFTS_RECEIVED_GIFT_BATCH);
                        }

                        if (Narrative.Length >= LenNarrativeGBGiftBatch)
                        {
                            IsNarrativeGBGiftBatch =
                                (Narrative.Substring(0, LenNarrativeGBGiftBatch) == MFinanceConstants.NARRATIVE_GB_GIFT_BATCH);
                        }

                        if ((gLMAcctType.ToUpper() != MFinanceConstants.ACCOUNT_TYPE_INCOME.ToUpper()) ||
                            !(SystemGenerated && (IsNarrativeGBGiftBatch || IsNarrativeGiftsReceivedGiftBatch)))
                        {
                            // Put transaction information
                            DataRow DR = (DataRow)TableForExport.NewRow();

                            DR[0] = gLMCostCCode;
                            DR[1] = ConvertAccount(gLMAcctCode);
                            DR[2] = ALedgerNumber.ToString() + MonthName + ":" + Narrative;
                            DR[3] = "ICH-" + APeriodNumber.ToString("00");
                            DR[4] = TransactionDate;
                            DR[5] = DebitTotal;
                            DR[6] = CreditTotal;

                            TableForExport.Rows.Add(DR);
                        }
                    }
                }

                TableForExport.AcceptChanges();

                TLogging.LogAtLevel(4, "HOSA-TableForExport: " + TableForExport.Rows.Count.ToString());

                //DataTables to XML to CSV
                XmlDocument doc = TDataBase.DataTableToXml(TableForExport);

                TCsv2Xml.Xml2Csv(doc, AFileName);

                //Replace the default CSV header row with OM specific
                ReplaceHeaderInFile(AFileName, TableForExportHeader, ref VerificationResult);
                Successful = true;
            });     // Get NewOrExisting AutoReadTransaction

            return(Successful);
        } // Generate HOSA Files
        public static Int32 CreateGLBatch(BankImportTDS AMainDS,
                                          Int32 ALedgerNumber,
                                          Int32 AStatementKey,
                                          Int32 AGLBatchNumber,
                                          out TVerificationResultCollection AVerificationResult)
        {
            AMainDS.AEpTransaction.DefaultView.RowFilter =
                String.Format("{0}={1}",
                              AEpTransactionTable.GetStatementKeyDBName(),
                              AStatementKey);
            AMainDS.AEpStatement.DefaultView.RowFilter =
                String.Format("{0}={1}",
                              AEpStatementTable.GetStatementKeyDBName(),
                              AStatementKey);
            AEpStatementRow stmt = (AEpStatementRow)AMainDS.AEpStatement.DefaultView[0].Row;

            AVerificationResult = null;

            Int32          DateEffectivePeriodNumber, DateEffectiveYearNumber;
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            if (!TFinancialYear.IsValidPostingPeriod(ALedgerNumber, stmt.Date, out DateEffectivePeriodNumber, out DateEffectiveYearNumber,
                                                     Transaction))
            {
                string msg = String.Format(Catalog.GetString("Cannot create a GL batch for date {0} since it is not in an open period of the ledger."),
                                           stmt.Date.ToShortDateString());
                TLogging.Log(msg);
                AVerificationResult = new TVerificationResultCollection();
                AVerificationResult.Add(new TVerificationResult(Catalog.GetString("Creating GL Batch"), msg, TResultSeverity.Resv_Critical));

                DBAccess.GDBAccessObj.RollbackTransaction();
                return(-1);
            }

            Int32 BatchYear, BatchPeriod;

            // if DateEffective is outside the range of open periods, use the most fitting date
            DateTime DateEffective = stmt.Date;

            TFinancialYear.GetLedgerDatePostingPeriod(ALedgerNumber, ref DateEffective, out BatchYear, out BatchPeriod, Transaction, true);

            ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction);

            DBAccess.GDBAccessObj.RollbackTransaction();

            GLBatchTDS GLDS = TGLTransactionWebConnector.CreateABatch(ALedgerNumber);

            ABatchRow glbatchRow = GLDS.ABatch[0];

            glbatchRow.BatchPeriod      = BatchPeriod;
            glbatchRow.DateEffective    = DateEffective;
            glbatchRow.BatchDescription = String.Format(Catalog.GetString("bank import for date {0}"), stmt.Date.ToShortDateString());

            decimal HashTotal   = 0.0M;
            decimal DebitTotal  = 0.0M;
            decimal CreditTotal = 0.0M;

            // TODO: support several journals
            // TODO: support several currencies, support other currencies than the base currency
            AJournalRow gljournalRow = GLDS.AJournal.NewRowTyped();

            gljournalRow.LedgerNumber        = glbatchRow.LedgerNumber;
            gljournalRow.BatchNumber         = glbatchRow.BatchNumber;
            gljournalRow.JournalNumber       = glbatchRow.LastJournal + 1;
            gljournalRow.TransactionCurrency = LedgerTable[0].BaseCurrency;
            glbatchRow.LastJournal++;
            gljournalRow.JournalPeriod       = glbatchRow.BatchPeriod;
            gljournalRow.DateEffective       = glbatchRow.DateEffective;
            gljournalRow.JournalDescription  = glbatchRow.BatchDescription;
            gljournalRow.SubSystemCode       = CommonAccountingSubSystemsEnum.GL.ToString();
            gljournalRow.TransactionTypeCode = CommonAccountingTransactionTypesEnum.STD.ToString();
            gljournalRow.ExchangeRateToBase  = 1.0m;
            GLDS.AJournal.Rows.Add(gljournalRow);

            foreach (DataRowView dv in AMainDS.AEpTransaction.DefaultView)
            {
                AEpTransactionRow transactionRow = (AEpTransactionRow)dv.Row;

                DataView v = AMainDS.AEpMatch.DefaultView;
                v.RowFilter = AEpMatchTable.GetActionDBName() + " = '" + MFinanceConstants.BANK_STMT_STATUS_MATCHED_GL + "' and " +
                              AEpMatchTable.GetMatchTextDBName() + " = '" + transactionRow.MatchText + "'";

                if (v.Count > 0)
                {
                    AEpMatchRow     match = (AEpMatchRow)v[0].Row;
                    ATransactionRow trans = GLDS.ATransaction.NewRowTyped();
                    trans.LedgerNumber      = glbatchRow.LedgerNumber;
                    trans.BatchNumber       = glbatchRow.BatchNumber;
                    trans.JournalNumber     = gljournalRow.JournalNumber;
                    trans.TransactionNumber = gljournalRow.LastTransactionNumber + 1;
                    trans.AccountCode       = match.AccountCode;
                    trans.CostCentreCode    = match.CostCentreCode;
                    trans.Reference         = match.Reference;
                    trans.Narrative         = match.Narrative;
                    trans.TransactionDate   = transactionRow.DateEffective;

                    if (transactionRow.TransactionAmount < 0)
                    {
                        trans.AmountInBaseCurrency = -1 * transactionRow.TransactionAmount;
                        trans.TransactionAmount    = -1 * transactionRow.TransactionAmount;
                        trans.DebitCreditIndicator = true;
                        DebitTotal += trans.AmountInBaseCurrency;
                    }
                    else
                    {
                        trans.AmountInBaseCurrency = transactionRow.TransactionAmount;
                        trans.TransactionAmount    = transactionRow.TransactionAmount;
                        trans.DebitCreditIndicator = false;
                        CreditTotal += trans.AmountInBaseCurrency;
                    }

                    GLDS.ATransaction.Rows.Add(trans);
                    gljournalRow.LastTransactionNumber++;

                    // add one transaction for the bank as well
                    trans = GLDS.ATransaction.NewRowTyped();
                    trans.LedgerNumber      = glbatchRow.LedgerNumber;
                    trans.BatchNumber       = glbatchRow.BatchNumber;
                    trans.JournalNumber     = gljournalRow.JournalNumber;
                    trans.TransactionNumber = gljournalRow.LastTransactionNumber + 1;
                    trans.AccountCode       = stmt.BankAccountCode;
                    trans.CostCentreCode    = TLedgerInfo.GetStandardCostCentre(ALedgerNumber);
                    trans.Reference         = match.Reference;
                    trans.Narrative         = match.Narrative;
                    trans.TransactionDate   = transactionRow.DateEffective;

                    if (transactionRow.TransactionAmount < 0)
                    {
                        trans.AmountInBaseCurrency = -1 * transactionRow.TransactionAmount;
                        trans.TransactionAmount    = -1 * transactionRow.TransactionAmount;
                        trans.DebitCreditIndicator = false;
                        CreditTotal += trans.AmountInBaseCurrency;
                    }
                    else
                    {
                        trans.AmountInBaseCurrency = transactionRow.TransactionAmount;
                        trans.TransactionAmount    = transactionRow.TransactionAmount;
                        trans.DebitCreditIndicator = true;
                        DebitTotal += trans.AmountInBaseCurrency;
                    }

                    GLDS.ATransaction.Rows.Add(trans);
                    gljournalRow.LastTransactionNumber++;
                }
            }

            gljournalRow.JournalDebitTotal  = DebitTotal;
            gljournalRow.JournalCreditTotal = CreditTotal;
            glbatchRow.BatchDebitTotal      = DebitTotal;
            glbatchRow.BatchCreditTotal     = CreditTotal;
            glbatchRow.BatchControlTotal    = HashTotal;

            TVerificationResultCollection VerificationResult;

            TSubmitChangesResult result = TGLTransactionWebConnector.SaveGLBatchTDS(ref GLDS,
                                                                                    out VerificationResult);

            if (result == TSubmitChangesResult.scrOK)
            {
                return(glbatchRow.BatchNumber);
            }

            TLogging.Log("Problems storing GL Batch");
            return(-1);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// create a new batch with a consecutive batch number in the ledger
        /// for call inside a server function
        /// for performance reasons submitting (save the data in the database) is done later (not here)
        /// </summary>
        /// <param name="AMainDS"></param>
        /// <param name="ATransaction"></param>
        /// <param name="ALedgerTbl"></param>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ADateEffective"></param>
        /// <param name="AForceEffectiveDateToFit"></param>
        /// <returns>the new gift batch row</returns>
        public static AGiftBatchRow CreateANewGiftBatchRow(ref GiftBatchTDS AMainDS,
                                                           ref TDBTransaction ATransaction,
                                                           ref ALedgerTable ALedgerTbl,
                                                           Int32 ALedgerNumber,
                                                           DateTime ADateEffective,
                                                           bool AForceEffectiveDateToFit = true)
        {
            #region Validate Arguments

            if (AMainDS == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString(
                                                                                         "Function:{0} - The Gift Batch dataset is NULL!"),
                                                                                     Utilities.GetMethodName(true)));
            }
            else if (ATransaction == null)
            {
                throw new EFinanceSystemDBTransactionNullException(String.Format(Catalog.GetString(
                                                                                     "Function:{0} - Database Transaction must not be NULL!"),
                                                                                 Utilities.GetMethodName(true)));
            }
            else if ((ALedgerTbl == null) || (ALedgerTbl.Count == 0))
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString(
                                                                                         "Function:{0} - The Ledger table is NULL or is empty!"),
                                                                                     Utilities.GetMethodName(true)));
            }
            else if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                                                                                       "Function:{0} - The Ledger number must be greater than 0!"),
                                                                                   Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            AGiftBatchRow NewRow = null;

            try
            {
                NewRow = AMainDS.AGiftBatch.NewRowTyped(true);

                NewRow.LedgerNumber = ALedgerNumber;
                NewRow.BatchNumber  = ++ALedgerTbl[0].LastGiftBatchNumber;
                Int32 BatchYear, BatchPeriod;
                // if DateEffective is outside the range of open periods, use the most fitting date
                TFinancialYear.GetLedgerDatePostingPeriod(ALedgerNumber,
                                                          ref ADateEffective,
                                                          out BatchYear,
                                                          out BatchPeriod,
                                                          ATransaction,
                                                          AForceEffectiveDateToFit);

                NewRow.BatchYear          = BatchYear;
                NewRow.BatchPeriod        = BatchPeriod;
                NewRow.GlEffectiveDate    = ADateEffective;
                NewRow.ExchangeRateToBase = 1.0M;
                NewRow.BatchDescription   = "PLEASE ENTER A DESCRIPTION";
                NewRow.BankAccountCode    = TLedgerInfo.GetDefaultBankAccount(ALedgerNumber);
                NewRow.BankCostCentre     = TLedgerInfo.GetStandardCostCentre(ALedgerNumber);
                NewRow.CurrencyCode       = ALedgerTbl[0].BaseCurrency;
                AMainDS.AGiftBatch.Rows.Add(NewRow);
            }
            catch (Exception ex)
            {
                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw;
            }

            return(NewRow);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// create a new batch with a consecutive batch number in the ledger
        /// for call inside a server function
        /// for performance reasons submitting (save the data in the database) is done later (not here)
        /// </summary>
        /// <param name="AMainDS"></param>
        /// <param name="ATransaction"></param>
        /// <param name="ALedgerTbl"></param>
        /// <param name="ALedgerNumber"></param>
        /// <returns>the new gift batch row</returns>
        public static ARecurringGiftBatchRow CreateANewRecurringGiftBatchRow(ref GiftBatchTDS AMainDS,
                                                                             ref TDBTransaction ATransaction,
                                                                             ref ALedgerTable ALedgerTbl,
                                                                             Int32 ALedgerNumber)
        {
            #region Validate Arguments

            if (AMainDS == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString(
                                                                                         "Function:{0} - The Gift Batch dataset is NULL!"),
                                                                                     Utilities.GetMethodName(true)));
            }
            else if (ATransaction == null)
            {
                throw new EFinanceSystemDBTransactionNullException(String.Format(Catalog.GetString(
                                                                                     "Function:{0} - Database Transaction must not be NULL!"),
                                                                                 Utilities.GetMethodName(true)));
            }
            else if ((ALedgerTbl == null) || (ALedgerTbl.Count == 0))
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString(
                                                                                         "Function:{0} - The Ledger table is NULL or is empty!"),
                                                                                     Utilities.GetMethodName(true)));
            }
            else if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                                                                                       "Function:{0} - The Ledger number must be greater than 0!"),
                                                                                   Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            GiftBatchTDS Temp = new GiftBatchTDS();

            ARecurringGiftBatchAccess.LoadViaALedger(Temp, ALedgerNumber, ATransaction);

            DataView RecurringGiftBatchDV = new DataView(Temp.ARecurringGiftBatch);
            RecurringGiftBatchDV.RowFilter = string.Empty;
            RecurringGiftBatchDV.Sort      = string.Format("{0} DESC",
                                                           ARecurringGiftBatchTable.GetBatchNumberDBName());

            //Recurring batch numbers can be reused so check each time for current highest number
            if (RecurringGiftBatchDV.Count > 0)
            {
                ALedgerTbl[0].LastRecGiftBatchNumber = (int)(RecurringGiftBatchDV[0][ARecurringGiftBatchTable.GetBatchNumberDBName()]);
            }
            else
            {
                ALedgerTbl[0].LastRecGiftBatchNumber = 0;
            }

            ARecurringGiftBatchRow NewRow = AMainDS.ARecurringGiftBatch.NewRowTyped(true);

            NewRow.LedgerNumber     = ALedgerNumber;
            NewRow.BatchNumber      = ++ALedgerTbl[0].LastRecGiftBatchNumber;
            NewRow.BatchDescription = Catalog.GetString("Please enter recurring batch description");
            NewRow.BankAccountCode  = TLedgerInfo.GetDefaultBankAccount(ALedgerNumber);
            NewRow.BankCostCentre   = TLedgerInfo.GetStandardCostCentre(ALedgerNumber);
            NewRow.CurrencyCode     = ALedgerTbl[0].BaseCurrency;
            AMainDS.ARecurringGiftBatch.Rows.Add(NewRow);
            return(NewRow);
        }
Ejemplo n.º 9
0
        public void Test_PEMM_05_Revaluation()
        {
            FLedgerNumber = CommonNUnitFunctions.CreateNewLedger();
            // load foreign currency account 6001
            CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\GL\\" +
                                                  "test-sql\\gl-test-account-data.sql", FLedgerNumber);

            // post a batch for foreign currency account 6001
            TCommonAccountingTool commonAccountingTool =
                new TCommonAccountingTool(FLedgerNumber, "NUNIT");

            commonAccountingTool.AddForeignCurrencyJournal("GBP", 1.1m);
            commonAccountingTool.JournalDescription = "Test foreign currency account";
            string strAccountGift = "0200";
            string strAccountBank = "6001";

            // Accounting of some gifts ...
            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountBank, (FLedgerNumber * 100).ToString(), "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100);

            commonAccountingTool.AddBaseCurrencyTransaction(
                strAccountGift, (FLedgerNumber * 100).ToString(), "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100);

            Boolean PostedOk = commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work

            Assert.IsTrue(PostedOk, "Post foreign gift batch");


            TVerificationResultCollection verificationResult;

/*
 * This error is no longer critical - it's OK to run month end even if a reval is required. (Mantis# 03905)
 *
 *          bool blnHasErrors = TPeriodIntervalConnector.TPeriodMonthEnd(
 *              FLedgerNumber, true, out verificationResult);
 *
 *          for (int i = 0; i < verificationResult.Count; ++i)
 *          {
 *              if (verificationResult[i].ResultCode.Equals(
 *                      TPeriodEndErrorAndStatusCodes.PEEC_05.ToString()))
 *              {
 *                  blnStatusArrived = true;
 *                  Assert.IsTrue(verificationResult[i].ResultSeverity == TResultSeverity.Resv_Critical,
 *                      "A critical error is required: need to run revaluation first ...");
 *              }
 *          }
 */

            // run revaluation
            Boolean blnHasErrors = TRevaluationWebConnector.Revaluate(FLedgerNumber, new string[] { "GBP" }, new decimal[] { 1.2m },
                                                                      TLedgerInfo.GetStandardCostCentre(FLedgerNumber),
                                                                      out verificationResult);

            if (blnHasErrors)
            {
                TLogging.Log("\n\n\nTRevaluationWebConnector.Revaluate returned false, VerificationResult follows:");
                TLogging.Log(verificationResult.BuildVerificationResultString());
            }

            Assert.IsFalse(blnHasErrors, "Problem running the revaluation");

            blnHasErrors = TPeriodIntervalConnector.PeriodMonthEnd(
                FLedgerNumber, true, out verificationResult);

            if (blnHasErrors)
            {
                TLogging.Log("\n\n\nTPeriodMonthEnd returned true, VerificationResult follows:");
                TLogging.Log(verificationResult.BuildVerificationResultString());
            }

            Assert.IsFalse(blnHasErrors, "should now be able to close the month now that the revaluation has been run");
        }