Exemple #1
0
        public void TestBatchPostingRecalculations()
        {
            TVerificationResultCollection VerificationResult;

            Int64        RecipientKey;
            Int64        RealRecipientLedgerNumber;
            Int64        FalseRecipientLedgerNumber;
            const string REALCOSTCENTRECODE  = "4300";
            const string FALSECOSTCENTRECODE = "3500";
            const string ACCOUNTCODE         = "0100";

            Int32 GiftBatchNumber;

            //
            // Arrange: Create all data needed for this test (Gift Details have 'fake' RecipientLedgerNumber and CostCentreCode)
            //
            TestBatchPostingRecalculations_Arrange(out RecipientKey, out RealRecipientLedgerNumber,
                                                   out FalseRecipientLedgerNumber, REALCOSTCENTRECODE, FALSECOSTCENTRECODE, out GiftBatchNumber);

            //
            // Act: Post the batch
            //
            bool result = TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, GiftBatchNumber, out VerificationResult);

            //
            // Assert
            //

            // Initial Assert: Tests that the post returns positive
            Assert.AreEqual(true,
                            result,
                            "TestBatchPostingRecalculations fail: Posting GiftBatch failed: " + VerificationResult.BuildVerificationResultString());

            // Primary Assert: Chaeck that the gifts have the correct RecipientLedgerNumber, CostCentreCode and Account
            TDBTransaction  Transaction           = null;
            AGiftDetailRow  PositiveGiftDetailRow = null;
            AGiftDetailRow  NegativeGiftDetailRow = null;
            ATransactionRow TransactionRow        = null;
            Int32           GLBatchNumber         = -1;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                      TEnforceIsolationLevel.eilMinimum,
                                                                      ref Transaction,
                                                                      delegate
            {
                PositiveGiftDetailRow = AGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, GiftBatchNumber, 1, 1, Transaction)[0];
                NegativeGiftDetailRow = AGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, GiftBatchNumber, 2, 1, Transaction)[0];

                GLBatchNumber  = ALedgerAccess.LoadByPrimaryKey(FLedgerNumber, Transaction)[0].LastBatchNumber;
                TransactionRow = ATransactionAccess.LoadByPrimaryKey(FLedgerNumber, GLBatchNumber, 1, 1, Transaction)[0];
            });

            Assert.IsNotNull(PositiveGiftDetailRow, "TestBatchPostingRecalculations fail: Obtaining PositiveGiftDetailRow from database failed");
            Assert.IsNotNull(NegativeGiftDetailRow, "TestBatchPostingRecalculations fail: Obtaining NegativeGiftDetailRow from database failed");
            Assert.IsNotNull(TransactionRow, "TestBatchPostingRecalculations fail: Obtaining Transaction from database failed");

            Assert.AreEqual(RealRecipientLedgerNumber, PositiveGiftDetailRow.RecipientLedgerNumber,
                            "TestBatchPostingRecalculations fail: RecipientLedgerNumber for PositiveGiftDetailRow is incorrect");
            Assert.AreEqual(FalseRecipientLedgerNumber, NegativeGiftDetailRow.RecipientLedgerNumber,
                            "TestBatchPostingRecalculations fail: RecipientLedgerNumber for NegativeGiftDetailRow is incorrect");
            Assert.AreEqual(REALCOSTCENTRECODE, PositiveGiftDetailRow.CostCentreCode,
                            "TestBatchPostingRecalculations fail: CostCentreCode for PositiveGiftDetailRow is incorrect");
            Assert.AreEqual(FALSECOSTCENTRECODE, NegativeGiftDetailRow.CostCentreCode,
                            "TestBatchPostingRecalculations fail: CostCentreCode for NegativeGiftDetailRow is incorrect");
            Assert.AreEqual(ACCOUNTCODE, TransactionRow.AccountCode,
                            "TestBatchPostingRecalculations fail: AccountCode for PositiveGiftDetailRow is incorrect");

            // Cleanup: Delete test records

            bool SubmissionOK = true;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable,
                                                                  TEnforceIsolationLevel.eilMinimum,
                                                                  ref Transaction,
                                                                  ref SubmissionOK,
                                                                  delegate
            {
                AProcessedFeeAccess.DeleteUsingTemplate(
                    new TSearchCriteria[] { new TSearchCriteria("a_ledger_number_i", FLedgerNumber),
                                            new TSearchCriteria("a_batch_number_i", GiftBatchNumber) },
                    Transaction);

                AGiftDetailAccess.DeleteRow(AGiftDetailTable.TableId, PositiveGiftDetailRow, Transaction);
                AGiftDetailAccess.DeleteRow(AGiftDetailTable.TableId, NegativeGiftDetailRow, Transaction);
            });

            TPartnerWebConnector.DeletePartner(RecipientKey, out VerificationResult);
            TPartnerWebConnector.DeletePartner(RealRecipientLedgerNumber, out VerificationResult);
            TPartnerWebConnector.DeletePartner(FalseRecipientLedgerNumber, out VerificationResult);
        }
Exemple #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 = 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