private void LoadTestTata_GetBatchInfo()
        {
            TDBTransaction transaction = DBAccess.GDBAccessObj.BeginTransaction();
            ABatchRow      template    = new ABatchTable().NewRowTyped(false);

            template.BatchDescription = strTestDataBatchDescription;
            ABatchTable batches = ABatchAccess.LoadUsingTemplate(template, transaction);

            DBAccess.GDBAccessObj.CommitTransaction();

            if (batches.Rows.Count == 0)
            {
                CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\GL\\" +
                                                      "test-sql\\gl-test-batch-data.sql", intLedgerNumber);
            }
        }
Example #2
0
        private void LoadTestData_GetBatchInfo()
        {
            ABatchRow template = new ABatchTable().NewRowTyped(false);

            template.LedgerNumber     = FLedgerNumber;
            template.BatchDescription = strTestDataBatchDescription;

            TDBTransaction transaction = null;
            ABatchTable    batches     = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(ref transaction,
                                                           delegate
            {
                batches = ABatchAccess.LoadUsingTemplate(template, transaction);
            });

            if (batches.Rows.Count == 0)
            {
                CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\GL\\" +
                                                      "test-sql\\gl-test-batch-data.sql", FLedgerNumber);
            }
        }
Example #3
0
        /// <summary>
        /// Export all the Data of the batches array list to a String
        /// </summary>
        /// <param name="Abatches"></param>
        /// <param name="ArequestParams"></param>
        /// <param name="AexportString"></param>
        /// <returns>false if batch does not exist at all</returns>
        public bool ExportAllGLBatchData(ArrayList Abatches, Hashtable ArequestParams, out String AexportString)
        {
            FStringWriter     = new StringWriter();
            FMainDS           = new GLBatchTDS();
            FDelimiter        = (String)ArequestParams["Delimiter"];
            FLedgerNumber     = (Int32)ArequestParams["ALedgerNumber"];
            FDateFormatString = (String)ArequestParams["DateFormatString"];
            FSummary          = (bool)ArequestParams["Summary"];
            FUseBaseCurrency  = (bool)ArequestParams["bUseBaseCurrency"];
            FBaseCurrency     = (String)ArequestParams["BaseCurrency"];
            FDateForSummary   = (DateTime)ArequestParams["DateForSummary"];
            String NumberFormat = (String)ArequestParams["NumberFormat"];

            FCultureInfo          = new CultureInfo(NumberFormat.Equals("American") ? "en-US" : "de-DE");
            FTransactionsOnly     = (bool)ArequestParams["TransactionsOnly"];
            FDontSummarize        = (bool)ArequestParams["bDontSummarize"];
            FDontSummarizeAccount = (String)ArequestParams["DontSummarizeAccount"];

            SortedDictionary <String, AJournalSummaryRow> sdSummary = new SortedDictionary <String, AJournalSummaryRow>();

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

            db.ReadTransaction(ref Transaction,
                               delegate
            {
                UInt32 progressCounter        = 0;
                UInt32 progressJournalCounter = 0;

                TProgressTracker.InitProgressTracker(DomainManager.GClientID.ToString(),
                                                     Catalog.GetString("Exporting GL Batches"),
                                                     100);

                TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                                                 Catalog.GetString("Retrieving records"),
                                                 10);

                while (Abatches.Count > 0)
                {
                    Int32 ABatchNumber = (Int32)Abatches[0];
                    ABatchAccess.LoadByPrimaryKey(FMainDS, FLedgerNumber, ABatchNumber, Transaction);
                    AJournalAccess.LoadViaABatch(FMainDS, FLedgerNumber, ABatchNumber, Transaction);

                    foreach (AJournalRow journal in FMainDS.AJournal.Rows)
                    {
                        if (journal.BatchNumber.Equals(ABatchNumber) && journal.LedgerNumber.Equals(FLedgerNumber))
                        {
                            ATransactionAccess.LoadViaAJournal(FMainDS, journal.LedgerNumber,
                                                               journal.BatchNumber,
                                                               journal.JournalNumber,
                                                               Transaction);
                        }
                    }

                    foreach (ATransactionRow trans in FMainDS.ATransaction.Rows)
                    {
                        if (trans.BatchNumber.Equals(ABatchNumber) && trans.LedgerNumber.Equals(FLedgerNumber))
                        {
                            ATransAnalAttribAccess.LoadViaATransaction(FMainDS, trans.LedgerNumber,
                                                                       trans.BatchNumber,
                                                                       trans.JournalNumber,
                                                                       trans.TransactionNumber,
                                                                       Transaction);
                        }
                    }

                    Abatches.RemoveAt(0);
                }

                UInt32 counter = 0;
                AJournalSummaryRow journalSummary = null;

                foreach (ABatchRow batch in FMainDS.ABatch.Rows)
                {
                    progressCounter = 0;

                    TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                                                     String.Format(Catalog.GetString("Batch {0}"), batch.BatchNumber),
                                                     20);

                    if (!FTransactionsOnly & !FSummary)
                    {
                        WriteBatchLine(batch);
                    }

                    //foreach (AJournalRow journal in journalDS.AJournal.Rows)
                    foreach (AJournalRow journal in FMainDS.AJournal.Rows)
                    {
                        if (journal.BatchNumber.Equals(batch.BatchNumber) && journal.LedgerNumber.Equals(batch.LedgerNumber))
                        {
                            progressJournalCounter = 0;

                            TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                                                             String.Format(Catalog.GetString("Batch {0}, Journal {1}"), batch.BatchNumber, journal.JournalNumber),
                                                             (progressCounter / 25 + 4) * 5 > 90 ? 90 : (progressCounter / 25 + 4) * 5);

                            if (FSummary)
                            {
                                String mapCurrency            = FUseBaseCurrency ? FBaseCurrency : journal.TransactionCurrency;
                                decimal mapExchangeRateToBase = FUseBaseCurrency ? 1 : journal.ExchangeRateToBase;

                                if (!sdSummary.TryGetValue(mapCurrency, out journalSummary))
                                {
                                    journalSummary = new AJournalSummaryRow();
                                    sdSummary.Add(mapCurrency, journalSummary);
                                }

                                //overwrite always because we want to have the last
                                journalSummary.ExchangeRateToBase  = mapExchangeRateToBase;
                                journalSummary.TransactionCurrency = mapCurrency;
                            }
                            else
                            {
                                if (!FTransactionsOnly)
                                {
                                    WriteJournalLine(journal);
                                }
                            }

                            FMainDS.ATransaction.DefaultView.Sort      = ATransactionTable.GetTransactionNumberDBName();
                            FMainDS.ATransaction.DefaultView.RowFilter =
                                String.Format("{0}={1} and {2}={3} and {4}={5}",
                                              ATransactionTable.GetLedgerNumberDBName(),
                                              journal.LedgerNumber,
                                              ATransactionTable.GetBatchNumberDBName(),
                                              journal.BatchNumber,
                                              ATransactionTable.GetJournalNumberDBName(),
                                              journal.JournalNumber);

                            foreach (DataRowView dv in FMainDS.ATransaction.DefaultView)
                            {
                                progressJournalCounter++;

                                if (++progressCounter % 25 == 0)
                                {
                                    TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                                                                     String.Format(Catalog.GetString(
                                                                                       "Batch {0}, Journal {1} - {2}"), batch.BatchNumber, journal.JournalNumber,
                                                                                   progressJournalCounter),
                                                                     (progressCounter / 25 + 4) * 5 > 90 ? 90 : (progressCounter / 25 + 4) * 5);
                                }

                                ATransactionRow transactionRow = (ATransactionRow)dv.Row;

                                if (FSummary)
                                {
                                    ATransactionSummaryRow transactionSummary;
                                    counter++;
                                    String DictionaryKey       = transactionRow.CostCentreCode + ";" + transactionRow.AccountCode;
                                    int signum                 = transactionRow.DebitCreditIndicator ? 1 : -1;
                                    bool bDontSummarizeAccount = FDontSummarize && FDontSummarizeAccount != null &&
                                                                 FDontSummarizeAccount.Length > 0 &&
                                                                 transactionRow.AccountCode.Equals(FDontSummarizeAccount);

                                    if (bDontSummarizeAccount)
                                    {
                                        DictionaryKey += ";" + counter.ToString("X");
                                    }

                                    if (journalSummary.TransactionSummaries.TryGetValue(DictionaryKey, out transactionSummary))
                                    {
                                        transactionSummary.TransactionAmount    += signum * transactionRow.TransactionAmount;
                                        transactionSummary.AmountInBaseCurrency += signum * transactionRow.AmountInBaseCurrency;
                                    }
                                    else
                                    {
                                        transactionSummary = new ATransactionSummaryRow();
                                        transactionSummary.CostCentreCode       = transactionRow.CostCentreCode;
                                        transactionSummary.AccountCode          = transactionRow.AccountCode;
                                        transactionSummary.TransactionAmount    = signum * transactionRow.TransactionAmount;
                                        transactionSummary.AmountInBaseCurrency = signum * transactionRow.AmountInBaseCurrency;

                                        if (bDontSummarizeAccount)
                                        {
                                            transactionSummary.Narrative = transactionRow.Narrative;
                                            transactionSummary.Reference = transactionRow.Reference;
                                        }
                                        else
                                        {
                                            transactionSummary.Narrative = summarizedData;
                                            transactionSummary.Reference = "";
                                        }

                                        journalSummary.TransactionSummaries.Add(DictionaryKey, transactionSummary);
                                    }
                                }
                                else
                                {
                                    WriteTransactionLine(transactionRow);
                                }
                            }
                        }
                    }
                }

                if (FSummary)
                {
                    TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                                                     Catalog.GetString("Summarising"),
                                                     95);

                    //To simplify matters this is always written even if there are no batches
                    if (!FTransactionsOnly)
                    {
                        // no batch summary line if only transactions are to be exported
                        WriteBatchSummaryLine();
                    }

                    foreach (KeyValuePair <string, AJournalSummaryRow> kvp in sdSummary)
                    {
                        if (!FTransactionsOnly)
                        {
                            // no journal summary line if only transactions are to be exported
                            WriteJournalSummaryLine(kvp.Value);
                        }

                        foreach (KeyValuePair <string, ATransactionSummaryRow> kvpt in kvp.Value.TransactionSummaries)
                        {
                            WriteTransactionSummaryLine(kvpt.Value);
                        }
                    }
                }

                TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                                                 Catalog.GetString("GL batch export successful"),
                                                 100);

                TProgressTracker.FinishJob(DomainManager.GClientID.ToString());
            });
            AexportString = FStringWriter.ToString();
            return(true);
        } // Export All GLBatch Data
        /// <summary>
        /// ResetForwardPeriodBatches.RunOperation
        ///
        /// Reset period columns on batch, journal and gift batch tables for periods beyond end of the old year
        /// </summary>
        public override Int32 RunOperation()
        {
            Int32 JobSize = 0;
            bool NewTransaction;
            Boolean ShouldCommit = false;
            TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                out NewTransaction);

            try
            {
                String Query =
                    "SELECT * FROM PUB_a_batch WHERE " +
                    "a_ledger_number_i=" + FLedgerInfo.LedgerNumber +
                    " AND a_batch_year_i=" + FOldYearNum +
                    " AND a_batch_period_i>" + FLedgerInfo.NumberOfAccountingPeriods;
                ABatchTable BatchTbl = new ABatchTable();
                DBAccess.GDBAccessObj.SelectDT(BatchTbl, Query, Transaction);

                if (BatchTbl.Rows.Count > 0)
                {
                    JobSize = BatchTbl.Rows.Count;

                    if (!FInfoMode)
                    {
                        foreach (ABatchRow BatchRow in BatchTbl.Rows)
                        {
                            BatchRow.BatchPeriod -= FLedgerInfo.NumberOfAccountingPeriods;
                            BatchRow.BatchYear += 1;
                        }

                        ABatchAccess.SubmitChanges(BatchTbl, Transaction);
                        ShouldCommit = true;
                    }
                }

                Query =
                    "SELECT PUB_a_journal.* FROM PUB_a_batch, PUB_a_journal WHERE " +
                    " PUB_a_journal.a_ledger_number_i=" + FLedgerInfo.LedgerNumber +
                    " AND PUB_a_batch.a_batch_number_i= PUB_a_journal.a_batch_number_i" +
                    " AND PUB_a_batch.a_batch_year_i=" + FOldYearNum +
                    " AND a_journal_period_i>" + FLedgerInfo.NumberOfAccountingPeriods;
                AJournalTable JournalTbl = new AJournalTable();
                DBAccess.GDBAccessObj.SelectDT(JournalTbl, Query, Transaction);

                if (JournalTbl.Rows.Count > 0)
                {
                    if (!FInfoMode)
                    {
                        foreach (AJournalRow JournalRow in JournalTbl.Rows)
                        {
                            JournalRow.JournalPeriod -= FLedgerInfo.NumberOfAccountingPeriods;
                        }

                        AJournalAccess.SubmitChanges(JournalTbl, Transaction);
                        ShouldCommit = true;
                    }
                }

                Query =
                    "SELECT * FROM PUB_a_gift_batch WHERE " +
                    " a_ledger_number_i=" + FLedgerInfo.LedgerNumber +
                    " AND a_batch_year_i=" + FOldYearNum +
                    " AND a_batch_period_i>" + FLedgerInfo.NumberOfAccountingPeriods;
                AGiftBatchTable GiftBatchTbl = new AGiftBatchTable();
                DBAccess.GDBAccessObj.SelectDT(GiftBatchTbl, Query, Transaction);

                if (GiftBatchTbl.Rows.Count > 0)
                {
                    JobSize += GiftBatchTbl.Rows.Count;

                    if (!FInfoMode)
                    {
                        foreach (AGiftBatchRow GiftBatchRow in GiftBatchTbl.Rows)
                        {
                            GiftBatchRow.BatchPeriod -= FLedgerInfo.NumberOfAccountingPeriods;
                            GiftBatchRow.BatchYear += 1;
                        }

                        AGiftBatchAccess.SubmitChanges(GiftBatchTbl, Transaction);
                        ShouldCommit = true;
                    }
                }
            }     // try
            finally
            {
                if (NewTransaction)
                {
                    if (ShouldCommit)
                    {
                        DBAccess.GDBAccessObj.CommitTransaction();
                    }
                    else
                    {
                        DBAccess.GDBAccessObj.RollbackTransaction();
                    }
                }
            }
            return JobSize;
        }