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); }
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)); }
/// create new AP info public static AApDocumentRow CreateNewAPInfo(Int64 APartnerKey, ref AccountsPayableTDS AMainDS) { ALedgerTable LedgerTable = ALedgerAccess.LoadAll(DBAccess.GDBAccessObj.Transaction); AMainDS = TAPTransactionWebConnector.CreateAApDocument(((ALedgerRow)LedgerTable.Rows[0]).LedgerNumber, APartnerKey, true); // Create a new RecurringGiftBatch AApDocumentRow Document = AMainDS.AApDocument[0]; Document.DocumentCode = "TEST"; Document.CreditNoteFlag = false; Document.DateIssued = DateTime.Today; Document.DateEntered = DateTime.Today; Document.TotalAmount = 0; Document.CurrencyCode = "EUR"; Document.LastDetailNumber = 0; // Create a new RecurringGift record AApSupplierRow ApSupplierRow = AMainDS.AApSupplier.NewRowTyped(); ApSupplierRow.PartnerKey = APartnerKey; ApSupplierRow.CurrencyCode = "EUR"; AMainDS.AApSupplier.Rows.Add(ApSupplierRow); return(Document); }
/// create new AP info public static AApDocumentRow CreateNewAPInfo(Int64 APartnerKey, ref AccountsPayableTDS AMainDS, TDataBase ADataBase = null) { TDataBase db = DBAccess.Connect("CreateNewAPInfo", ADataBase); TDBTransaction Transaction = db.BeginTransaction(IsolationLevel.Serializable); ALedgerTable LedgerTable = ALedgerAccess.LoadAll(Transaction); AMainDS = TAPTransactionWebConnector.CreateAApDocument(((ALedgerRow)LedgerTable.Rows[0]).LedgerNumber, APartnerKey, true, db); // Create a new RecurringGiftBatch AApDocumentRow Document = AMainDS.AApDocument[0]; Document.DocumentCode = "TEST"; Document.CreditNoteFlag = false; Document.DateIssued = DateTime.Today; Document.DateEntered = DateTime.Today; Document.TotalAmount = 0; Document.CurrencyCode = "EUR"; Document.LastDetailNumber = 0; // Create a new RecurringGift record AApSupplierRow ApSupplierRow = AMainDS.AApSupplier.NewRowTyped(); ApSupplierRow.PartnerKey = APartnerKey; ApSupplierRow.CurrencyCode = "EUR"; AMainDS.AApSupplier.Rows.Add(ApSupplierRow); Transaction.Commit(); return(Document); }
/// <summary> /// post and pay all invoices in the given period, but leave some (or none) unposted /// </summary> public static bool PostAndPayInvoices(int AYear, int APeriod, int ALeaveInvoicesUnposted = 0) { TLogging.LogAtLevel(1, "PostAndPayInvoices for year " + AYear.ToString() + " / period " + APeriod.ToString()); AccountsPayableTDS MainDS = new AccountsPayableTDS(); string sqlLoadDocuments = "SELECT * FROM PUB_a_ap_document WHERE a_ledger_number_i = ? AND a_date_issued_d >= ? AND a_date_issued_d <= ? AND a_document_status_c='APPROVED'"; DateTime PeriodStartDate, PeriodEndDate; TFinancialYear.GetStartAndEndDateOfPeriod(FLedgerNumber, APeriod, out PeriodStartDate, out PeriodEndDate, null); List <OdbcParameter> parameters = new List <OdbcParameter>(); OdbcParameter parameter; parameter = new OdbcParameter("ledgernumber", OdbcType.Int); parameter.Value = FLedgerNumber; parameters.Add(parameter); parameter = new OdbcParameter("startDate", OdbcType.DateTime); parameter.Value = PeriodStartDate; parameters.Add(parameter); parameter = new OdbcParameter("endDate", OdbcType.DateTime); parameter.Value = PeriodEndDate; parameters.Add(parameter); DBAccess.GDBAccessObj.SelectDT(MainDS.AApDocument, sqlLoadDocuments, null, parameters.ToArray(), -1, -1); int countUnPosted = MainDS.AApDocument.Count; List <int> DocumentIdsToPost = new List <int>(); foreach (AApDocumentRow invoice in MainDS.AApDocument.Rows) { if (countUnPosted <= ALeaveInvoicesUnposted) { break; } DocumentIdsToPost.Add(invoice.ApDocumentId); countUnPosted--; } TVerificationResultCollection VerificationResult; if ((DocumentIdsToPost.Count > 0) && !TAPTransactionWebConnector.PostAPDocuments(FLedgerNumber, DocumentIdsToPost, PeriodEndDate, false, out VerificationResult)) { TLogging.Log(VerificationResult.BuildVerificationResultString()); return(false); } // TODO pay the invoices as well return(true); }
/// <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); }
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); }