예제 #1
0
        private TVerificationResultCollection ReversePayment(int APaymentNumber, DateTime APeriodEndDate,
                                                             List <int> ADocumentIds, AccountsPayableTDS AApDS)
        {
            string AssertFailMessage = "Failed to reverse AP payment: ";
            TVerificationResultCollection VerificationResult;

            List <Int32> glBatchNumbers;

            // "Un-pay" the specified invoice
            if (!TAPTransactionWebConnector.ReversePayment(FLedgerNumber,
                                                           APaymentNumber,
                                                           APeriodEndDate,
                                                           out glBatchNumbers,
                                                           out VerificationResult))
            {
                Assert.Fail(AssertFailMessage +
                            VerificationResult.BuildVerificationResultString());
            }

            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult, AssertFailMessage);   // Guard Assert

            // "Un-post" the specified invoice - returning it to "Approved" status!
            ADocumentIds[0] += 2; // The invoice I posted was reversed, and a duplicate now exists with an Id 2 greater than the original.

            return(PostAPDocument(AApDS, APeriodEndDate, ref ADocumentIds, true));
        }
예제 #2
0
        private TVerificationResultCollection PostAPDocument(AccountsPayableTDS AMainDS, DateTime APostingDate,
                                                             ref List <int> ADocumentIds, bool AReversal = false)
        {
            string AssertFailMessage = AReversal ? "Failed to post AP document reversal: " : "Problems posting AP document: ";
            TVerificationResultCollection VerificationResult;

            if (!AReversal)
            {
                ADocumentIds.Add(AMainDS.AApDocument[0].ApDocumentId);
            }

            Int32 glBatchNumber;

            if (!TAPTransactionWebConnector.PostAPDocuments(FLedgerNumber,
                                                            ADocumentIds,
                                                            APostingDate,
                                                            AReversal,
                                                            out glBatchNumber,
                                                            out VerificationResult))
            {
                Assert.Fail(AssertFailMessage +
                            VerificationResult.BuildVerificationResultString());
            }

            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult, AssertFailMessage);   // Guard Assert

            return(VerificationResult);
        }
예제 #3
0
        private AAPInfos PostSimpleAPDocument(decimal AAmount, string ADocumentCode, string ANarrative,
                                              out decimal AAPAccountBalanceBefore, out decimal ABankAccountBefore, out decimal AExpAccountBefore,
                                              out List <int> ADocumentIds)
        {
            TVerificationResultCollection VerificationResult;

            ADocumentIds = new List <int>();

            AAPInfos APInfos = APTestsArrangement(SUPPLIER_PARTNER_KEY, AAmount, null, ADocumentCode, ANarrative);

            // Save the current amount on the AP account
            AAPAccountBalanceBefore = new TGet_GLM_Info(FLedgerNumber,
                                                        APInfos.ApAccountCode, APInfos.CostCentreCode).YtdActual;
            ABankAccountBefore = new TGet_GLM_Info(FLedgerNumber,
                                                   APInfos.BankAccount, APInfos.CostCentreCode).YtdActual;

            AExpAccountBefore = new TGet_GLM_Info(FLedgerNumber,
                                                  APInfos.ApDS.AApSupplier[0].DefaultExpAccount,
                                                  APInfos.CostCentreCode).YtdActual;

            VerificationResult = PostAPDocument(APInfos.ApDS, APInfos.PeriodStartDate, ref ADocumentIds);
            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult);   // Guard Assert

            //
            // Guard Assert: Posting OK?
            //
            decimal ExpAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                                                        APInfos.ApDS.AApSupplier[0].DefaultExpAccount,
                                                        APInfos.ApDS.AApSupplier[0].DefaultCostCentre).YtdActual;

            Assert.AreEqual(AAmount, ExpAccountAfter - AExpAccountBefore, "after posting the invoice, the expense account should be debited");

            return(APInfos);
        }
예제 #4
0
        public void ForeignCurrencySupplier_ExpectDocumentPostingPayingAndReversingWorking()
        {
            //
            // Arrange
            //
            decimal APAccountBalanceBefore;
            decimal BankAccountBefore;
            decimal RevalAccountBefore;
            TVerificationResultCollection VerificationResult;
            int PaymentNumber;

            List <int> DocumentIDs;
            AAPInfos   APInfos;

            CommonNUnitFunctions.ResetDatabase();
            TPetraServerConnector.Connect();

            TDataBase      db          = DBAccess.Connect("ForeignCurrencySupplier_ExpectDocumentPostingPayingAndReversingWorking");
            TDBTransaction transaction = db.BeginTransaction(IsolationLevel.Serializable);

            // Post and pay a document with a foreign currency supplier
            APInfos = PostAndPayForeignSupplierAPDocument("Test Reverse", out PaymentNumber, out DocumentIDs,
                                                          out APAccountBalanceBefore, out BankAccountBefore, out RevalAccountBefore, db);

            transaction.Commit();
            transaction = db.BeginTransaction(IsolationLevel.Serializable);

            //
            // Act: Immediately "un-pay" and "un-post" this invoice!
            //
            VerificationResult = ReversePayment(PaymentNumber, APInfos.PeriodEndDate, DocumentIDs, APInfos.ApDS, db);
            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult);   // Guard Assert

            transaction.Commit();
            transaction = db.BeginTransaction(IsolationLevel.Serializable);

            // Save the current amount on the AP account
            decimal APAccountBalanceAfter = new TGet_GLM_Info(FLedgerNumber,
                                                              APInfos.ApAccountCode, APInfos.CostCentreCode, db).YtdActual;
            decimal BankAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                                                         APInfos.BankAccount, APInfos.CostCentreCode, db).YtdForeign;
            decimal RevalAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                                                          APInfos.ForexGainsLossesAccount, APInfos.CostCentreCode, db).YtdActual;

            //
            // Primary Assert: Reversal OK?
            //
            // Now I can see whether anything is left over by all these
            // various transactions, that should have added up to 0.
            // Check the amount on the AP account
            Assert.AreEqual(APAccountBalanceBefore, APAccountBalanceAfter, "After paying then reversing, the AP account should be as before.");
            Assert.AreEqual(BankAccountBefore, BankAccountAfter, "After paying then reversing, the Bank account should be as before.");
            Assert.AreEqual(
                Math.Round(RevalAccountAfter, 2),
                Math.Round(RevalAccountBefore, 2),
                "After paying then reversing, the Forex Gains/Losses Account account should be as before.");

            transaction.Commit();
        }
예제 #5
0
        /// <summary>
        /// Creates a AP document for the supplier specified with APartnerKey.
        /// </summary>
        /// <param name="APartnerKey"></param>
        /// <param name="AAmount"></param>
        /// <param name="AExchangeRatePosting"></param>
        /// <param name="ADocumentCode"></param>
        /// <param name="ANarrative"></param>
        /// <param name="AMainDS"></param>
        /// <param name="ADataBase"></param>
        /// <returns></returns>
        private TVerificationResultCollection CreateAPDocument(Int64 APartnerKey, decimal AAmount, decimal?AExchangeRatePosting,
                                                               string ADocumentCode, string ANarrative, out AccountsPayableTDS AMainDS, TDataBase ADataBase)
        {
            string AssertFailMessage = "Problems saving AP document: ";
            TSubmitChangesResult          SubmRes;
            TVerificationResultCollection VerificationResult;

            TDataBase db = DBAccess.Connect("CreateAPDocument", ADataBase);

            AMainDS = TAPTransactionWebConnector.CreateAApDocument(FLedgerNumber, APartnerKey, false, db);
            AccountsPayableTDS MainDS = AMainDS;

            TDBTransaction Transaction = new TDBTransaction();

            db.ReadTransaction(
                ref Transaction,
                delegate
            {
                AApSupplierAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
            });

            AMainDS.AApDocument[0].DocumentCode = ADocumentCode + DateTime.Now.Ticks.ToString();

            AMainDS.Merge(TAPTransactionWebConnector.CreateAApDocumentDetail(
                              FLedgerNumber,
                              AMainDS.AApDocument[0].ApDocumentId,
                              AMainDS.AApSupplier[0].DefaultExpAccount,
                              AMainDS.AApSupplier[0].DefaultCostCentre,
                              AAmount,
                              AMainDS.AApDocument[0].LastDetailNumber + 1));

            AMainDS.AApDocument[0].LastDetailNumber++;
            AMainDS.AApDocument[0].TotalAmount     = AAmount;
            AMainDS.AApDocument[0].DocumentStatus  = MFinanceConstants.AP_DOCUMENT_APPROVED;
            AMainDS.AApDocumentDetail[0].Narrative = ANarrative;

            if (AExchangeRatePosting.HasValue)
            {
                AMainDS.AApDocument[0].ExchangeRateToBase = AExchangeRatePosting.Value;
            }

            SubmRes = TAPTransactionWebConnector.SaveAApDocument(ref AMainDS, out VerificationResult, db);

            if (SubmRes != TSubmitChangesResult.scrOK)
            {
                Assert.Fail(AssertFailMessage + String.Format(" - (SaveAApDocument return value: {0}) - ", SubmRes) +
                            VerificationResult.BuildVerificationResultString());
            }

            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult, AssertFailMessage);   // Guard Assert

            return(VerificationResult);
        }
예제 #6
0
        public void SimpleDocument_ExpectPostingAndPayingWorking()
        {
            //
            // Arrange
            //
            decimal Amount = 399.0m;
            decimal APAccountBalanceBefore;
            decimal ABankAccountBefore;
            decimal AExpAccountBefore;
            TVerificationResultCollection VerificationResult;

            List <int> DocumentIDs;
            int        PaymentNumber;
            AAPInfos   APInfos;

            CommonNUnitFunctions.ResetDatabase();
            TPetraServerConnector.Connect();

            TDataBase      db          = DBAccess.Connect("SimpleDocument_ExpectPostingAndPayingWorking");
            TDBTransaction transaction = db.BeginTransaction(IsolationLevel.Serializable);

            APInfos = PostSimpleAPDocument(Amount, "Test", "Detail Item", out APAccountBalanceBefore, out ABankAccountBefore,
                                           out AExpAccountBefore, out DocumentIDs, db);

            transaction.Commit();
            transaction = db.BeginTransaction(IsolationLevel.Serializable);

            //
            // Act: Pay the AP document
            //
            VerificationResult = PayAPDocument(APInfos.ApDS.AApDocument[0].ApDocumentId, Amount,
                                               APInfos.BankAccount, APInfos.CurrencyCode, APInfos.PeriodEndDate, out PaymentNumber, null, db);
            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult);   // Guard Assert

            transaction.Commit();

            // Save the current amount on the AP account
            decimal APAccountBalanceAfter = new TGet_GLM_Info(FLedgerNumber,
                                                              APInfos.ApAccountCode, APInfos.CostCentreCode, db).YtdActual;
            decimal BankAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                                                         APInfos.BankAccount, APInfos.CostCentreCode, db).YtdActual;

            //
            // Primary Assert: Paying OK?
            //
            // Check the amount on the AP account
            Assert.AreEqual(0.0m, APAccountBalanceAfter - APAccountBalanceBefore, "after paying the invoice, the AP account should be cleared");
            Assert.AreEqual((-1.0m) * Amount, BankAccountAfter - ABankAccountBefore, "after paying the invoice, the bank account should be credited");
        }
예제 #7
0
        private TVerificationResultCollection PayAPDocument(int AApDocumentId, decimal AAmount, string ABankAccount,
                                                            string ACurrencyCode, DateTime APeriodEndDate, out int APaymentNumber, decimal?AExchangeRatePayment = null, TDataBase ADataBase = null)
        {
            string AssertFailMessage = "Problems paying AP document: ";
            TVerificationResultCollection VerificationResult;
            AccountsPayableTDS            MainDS = new AccountsPayableTDS();

            AApPaymentRow Payment = MainDS.AApPayment.NewRowTyped();

            Payment.LedgerNumber  = FLedgerNumber;
            Payment.PaymentNumber = -1;
            Payment.Amount        = AAmount;
            Payment.BankAccount   = ABankAccount;
            Payment.CurrencyCode  = ACurrencyCode;

            if (AExchangeRatePayment.HasValue)
            {
                Payment.ExchangeRateToBase = AExchangeRatePayment.Value;
            }

            MainDS.AApPayment.Rows.Add(Payment);

            AApDocumentPaymentRow DocPayment = MainDS.AApDocumentPayment.NewRowTyped();

            DocPayment.LedgerNumber  = FLedgerNumber;
            DocPayment.ApDocumentId  = AApDocumentId;
            DocPayment.Amount        = AAmount;
            DocPayment.PaymentNumber = Payment.PaymentNumber;
            MainDS.AApDocumentPayment.Rows.Add(DocPayment);
            Int32 glBatchNumber;
            AccountsPayableTDSAApPaymentTable newPayments;

            if (!TAPTransactionWebConnector.PostAPPayments(ref MainDS, APeriodEndDate,
                                                           out glBatchNumber,
                                                           out newPayments,
                                                           out VerificationResult,
                                                           ADataBase))
            {
                Assert.Fail(AssertFailMessage +
                            VerificationResult.BuildVerificationResultString());
            }

            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult, AssertFailMessage);   // Guard Assert

            APaymentNumber = DocPayment.PaymentNumber;

            return(VerificationResult);
        }
예제 #8
0
        private AAPInfos PostAndPayForeignSupplierAPDocument(string ADocumentCode, out int APaymentNumber, out List <int> ADocumentIDs,
                                                             out decimal AAPAccountBalanceBefore, out decimal ABankAccountBefore, out decimal ARevalAccountBefore)
        {
            decimal Amount = 100.0m;
            decimal ExchangeRatePosting = 1.2m;
            decimal ExchangeRatePayment = 1.1m;
            decimal ExpAccountBefore;
            TVerificationResultCollection VerificationResult;
            AAPInfos APInfos;

            APInfos = PostForeignSupplierAPDocument(Amount, ExchangeRatePosting, ADocumentCode, "Detail Item",
                                                    out AAPAccountBalanceBefore, out ABankAccountBefore, out ExpAccountBefore, out ARevalAccountBefore, out ADocumentIDs);

            //
            // Pay the AP document
            //
            VerificationResult = PayAPDocument(APInfos.ApDS.AApDocument[0].ApDocumentId, Amount,
                                               APInfos.BankAccount, APInfos.CurrencyCode, APInfos.PeriodEndDate, out APaymentNumber, ExchangeRatePayment);
            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult);   // Guard Assert

            // Save the current amount on the AP account and Bank Account
            decimal APAccountBalanceAfter = new TGet_GLM_Info(FLedgerNumber,
                                                              APInfos.ApAccountCode, APInfos.CostCentreCode).YtdActual;
            decimal BankAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                                                         APInfos.BankAccount, APInfos.CostCentreCode).YtdForeign;

            //
            // Guard Assert: Paying OK?
            //
            // Check the amount on the AP account
            Assert.AreEqual(0.0m, APAccountBalanceAfter - AAPAccountBalanceBefore, "after paying the invoice, the AP account should be cleared");
            Assert.AreEqual((-1.0m) * Amount, BankAccountAfter - ABankAccountBefore, "after paying the invoice, the bank account should be credited");

            decimal RevalAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                                                          APInfos.ForexGainsLossesAccount, APInfos.CostCentreCode).YtdActual;

            Assert.AreEqual(
                Math.Round((Amount / ExchangeRatePayment) - (Amount / ExchangeRatePosting), 2),
                Math.Round((RevalAccountAfter - ARevalAccountBefore), 2),
                "after paying the invoice, the revaluation account should be credited with the forex gain");

            return(APInfos);
        }
예제 #9
0
        private AAPInfos PostForeignSupplierAPDocument(decimal AAmount, decimal AExchangeRatePosting, string ADocumentCode, string ANarrative,
                                                       out decimal AAPAccountBalanceBefore, out decimal ABankAccountBefore, out decimal AExpAccountBefore,
                                                       out decimal ARevalAccountBefore, out List <int> ADocumentIds)
        {
            TVerificationResultCollection VerificationResult;

            ADocumentIds = new List <int>();

            AAPInfos APInfos = APTestsArrangement(SUPPLIER_FOREIGN_PARTNER_KEY, AAmount, AExchangeRatePosting, ADocumentCode, ANarrative);

            // Save the current amount on the AP account
            AAPAccountBalanceBefore = new TGet_GLM_Info(FLedgerNumber,
                                                        APInfos.ApAccountCode, APInfos.CostCentreCode).YtdActual;
            ABankAccountBefore = new TGet_GLM_Info(FLedgerNumber,
                                                   APInfos.BankAccount, APInfos.CostCentreCode).YtdForeign;

            AExpAccountBefore = new TGet_GLM_Info(FLedgerNumber,
                                                  APInfos.ApDS.AApSupplier[0].DefaultExpAccount,
                                                  APInfos.CostCentreCode).YtdActual;
            ARevalAccountBefore = new TGet_GLM_Info(FLedgerNumber,
                                                    APInfos.ForexGainsLossesAccount,
                                                    APInfos.CostCentreCode).YtdActual;

            VerificationResult = PostAPDocument(APInfos.ApDS, APInfos.PeriodStartDate, ref ADocumentIds);
            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult);   // Guard Assert

            //
            // Guard Assert: Posting OK?
            //
            decimal ExpAccountAfter = new TGet_GLM_Info(FLedgerNumber,
                                                        APInfos.ApDS.AApSupplier[0].DefaultExpAccount,
                                                        APInfos.ApDS.AApSupplier[0].DefaultCostCentre).YtdActual;

            Assert.AreEqual(Math.Round(AAmount / AExchangeRatePosting, 2), Math.Round(ExpAccountAfter - AExpAccountBefore,
                                                                                      2), "after posting the invoice, the expense account should be debited the amount in base currency (Exchange Rate is " +
                            AExchangeRatePosting + ")");

            return(APInfos);
        }
예제 #10
0
        private AAPInfos APTestsArrangement(Int64 APartnerKey, decimal AAmount, decimal?AExchangeRatePosting,
                                            string ADocumentCode, string ANarrative)
        {
            AAPInfos APInfos = new AAPInfos();

            TVerificationResultCollection VerificationResult = CreateAPDocument(APartnerKey,
                                                                                AAmount,
                                                                                AExchangeRatePosting,
                                                                                ADocumentCode,
                                                                                ANarrative,
                                                                                out APInfos.ApDS);

            CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult);   // Guard Assert

            GetLedgerInfo(out APInfos.PeriodStartDate, out APInfos.PeriodEndDate, out APInfos.ForexGainsLossesAccount);

            SetupSupplierAndDocumentInfo(APInfos.ApDS,
                                         out APInfos.BankAccount,
                                         out APInfos.CurrencyCode,
                                         out APInfos.ApAccountCode,
                                         out APInfos.CostCentreCode);

            return(APInfos);
        }