Beispiel #1
0
 void WriteJournalSummaryLine(AJournalSummaryRow journalSummary)
 {
     WriteStringQuoted("J");
     WriteStringQuoted(summarizedData);
     WriteStringQuoted("GL");
     WriteStringQuoted("STD");
     WriteStringQuoted(journalSummary.TransactionCurrency);
     WriteGeneralNumber(journalSummary.ExchangeRateToBase);             // format ok ???
     WriteDate(FDateForSummary, true);
 }
Beispiel #2
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 = null;
            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, 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
Beispiel #3
0
 void WriteJournalSummaryLine(AJournalSummaryRow journalSummary)
 {
     WriteStringQuoted("J");
     WriteStringQuoted(summarizedData);
     WriteStringQuoted("GL");
     WriteStringQuoted("STD");
     WriteStringQuoted(journalSummary.TransactionCurrency);
     WriteGeneralNumber(journalSummary.ExchangeRateToBase);             // format ok ???
     WriteDate(FDateForSummary, true);
 }
Beispiel #4
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