/// <summary> /// Returns the specified find results page. /// /// @comment Pages can be requested in any order! /// /// </summary> /// <param name="APage">Page to return</param> /// <param name="APageSize">Number of records to return per page</param> /// <param name="ATotalRecords">The amount of rows found by the SELECT statement</param> /// <param name="ATotalPages">The number of pages that will be needed on client-side to /// hold all rows found by the SELECT statement</param> /// <returns>DataTable containing the find result records for the specified page /// </returns> public DataTable GetDataPagedResult(System.Int16 APage, System.Int16 APageSize, out System.Int32 ATotalRecords, out System.Int16 ATotalPages) { if (TLogging.DL >= 7) { Console.WriteLine(this.GetType().FullName + ".GetDataPagedResult called."); } DataTable ReturnValue = FPagedDataSetObject.GetData(APage, APageSize); if (FSearchTransactions) { foreach (DataRow Row in ReturnValue.Rows) { SetOutstandingAmount(Row); } } else { // searching for outstanding invoices on the main screen if (!FSearchSupplierOrInvoice) { foreach (DataRow Row in ReturnValue.Rows) { // calculate DateDue and DateDiscountUntil // add creditTerms to dateIssued to get DateDue if (Row["CreditTerms"].GetType() != typeof(DBNull)) { Row["DateDue"] = Convert.ToDateTime(Row["DateIssued"]).AddDays(Convert.ToInt16(Row["CreditTerms"])); } if (Row["DiscountDays"].GetType() != typeof(DBNull)) { Row["DateDiscountUntil"] = Convert.ToDateTime(Row["DateIssued"]).AddDays(Convert.ToInt16(Row["DiscountDays"])); } SetOutstandingAmount(Row); Row["DiscountMsg"] = "None"; Row["Selected"] = false; if (Row["DiscountPercentage"].GetType() == typeof(DBNull)) { Row["DiscountPercentage"] = 0; } if (Convert.ToDateTime(Row["DateDiscountUntil"]) > DateTime.Now) { Row["DiscountMsg"] = String.Format("{0:n0}% until {1}", Row["DiscountPercentage"], TDate.DateTimeToLongDateString2(Convert.ToDateTime(Row["DateDiscountUntil"]))); } else { Row["DiscountMsg"] = "Expired"; } } } } ATotalPages = FPagedDataSetObject.TotalPages; ATotalRecords = FPagedDataSetObject.TotalRecords; // TODO TAccountsPayableAggregate.ApplySecurity(ref ReturnValue); return(ReturnValue); }
/// <summary> /// A payment made to a supplier needs to be reversed. /// It's done by creating and posting a set of matching "negatives" - /// In the simplest case this is a single credit note matching an invoice /// but it could be more complex. These negative documents are payed using /// a standard call to PostAPPayments. /// /// After the reversal, I'll also create and post new copies of all /// the invoices / credit notes that made up the original payment. /// </summary> /// <param name="ALedgerNumber"></param> /// <param name="APaymentNumber"></param> public void ReversePayment(Int32 ALedgerNumber, Int32 APaymentNumber) { AccountsPayableTDS TempDS = TRemote.MFinance.AP.WebConnectors.LoadAPPayment(ALedgerNumber, APaymentNumber); if (TempDS.AApPayment.Rows.Count == 0) // Invalid Payment number? { MessageBox.Show(Catalog.GetString("The referenced payment Connot be loaded."), Catalog.GetString("Error")); return; } TempDS.AApDocument.DefaultView.Sort = AApDocumentTable.GetApDocumentIdDBName(); // // First I'll check that the amounts add up: // Decimal PaidDocumentsTotal = 0.0m; foreach (AApDocumentPaymentRow PaymentRow in TempDS.AApDocumentPayment.Rows) { Int32 DocIdx = TempDS.AApDocument.DefaultView.Find(PaymentRow.ApDocumentId); AApDocumentRow DocumentRow = TempDS.AApDocument[DocIdx]; if (DocumentRow.CreditNoteFlag) { PaidDocumentsTotal -= DocumentRow.TotalAmount; } else { PaidDocumentsTotal += DocumentRow.TotalAmount; } } // // If this is a partial payment, I can't deal with that here... // if (PaidDocumentsTotal != TempDS.AApPayment[0].Amount) { String ErrorMsg = String.Format(Catalog.GetString( "This Payment cannot be reversed automatically because the total amount of the referenced documents ({0:n2} {1}) differs from the amount in the payment ({2:n2} {3})."), PaidDocumentsTotal, TempDS.AApSupplier[0].CurrencyCode, TempDS.AApPayment[0].Amount, TempDS.AApSupplier[0].CurrencyCode); MessageBox.Show(ErrorMsg, Catalog.GetString("Reverse Payment"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Find out if this payment was already reversed, // because if it was, perhaps the user doesn't really want to // reverse it again? this.Cursor = Cursors.WaitCursor; if (TRemote.MFinance.AP.WebConnectors.WasThisPaymentReversed(ALedgerNumber, APaymentNumber)) { this.Cursor = Cursors.Default; MessageBox.Show(Catalog.GetString("Cannot reverse Payment - there is already a matching reverse transaction."), Catalog.GetString("Reverse Payment"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.Cursor = Cursors.Default; // // Ask the user to confirm reversal of this payment // String PaymentMsg = Catalog.GetString("Do you want to reverse this payment?"); PaymentMsg += ("\r\n" + String.Format("Payment made {0} to {1}\r\n\r\nRelated invoices:", TDate.DateTimeToLongDateString2(TempDS.AApPayment[0].PaymentDate.Value), TempDS.PPartner[0].PartnerShortName)); foreach (AApDocumentPaymentRow PaymentRow in TempDS.AApDocumentPayment.Rows) { Int32 DocIdx = TempDS.AApDocument.DefaultView.Find(PaymentRow.ApDocumentId); AApDocumentRow DocumentRow = TempDS.AApDocument[DocIdx]; PaymentMsg += ("\r\n" + String.Format(" {2} ({3}) {0:n2} {1}", DocumentRow.TotalAmount, TempDS.AApSupplier[0].CurrencyCode, DocumentRow.DocumentCode, DocumentRow.Reference)); } PaymentMsg += ("\r\n\r\n" + String.Format("Total payment {0:n2} {1}", TempDS.AApPayment[0].Amount, TempDS.AApSupplier[0].CurrencyCode)); DialogResult YesNo = MessageBox.Show(PaymentMsg, Catalog.GetString("Reverse Payment"), MessageBoxButtons.YesNo); if (YesNo == DialogResult.No) { return; } TDlgGLEnterDateEffective dateEffectiveDialog = new TDlgGLEnterDateEffective( ALedgerNumber, Catalog.GetString("Select posting date"), Catalog.GetString("The date effective for the reversal") + ":"); if (dateEffectiveDialog.ShowDialog() != DialogResult.OK) { MessageBox.Show(Catalog.GetString("Reversal was cancelled."), Catalog.GetString("Reverse Payment"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DateTime PostingDate = dateEffectiveDialog.SelectedDate; TVerificationResultCollection Verifications; this.Cursor = Cursors.WaitCursor; if (TRemote.MFinance.AP.WebConnectors.ReversePayment(ALedgerNumber, APaymentNumber, PostingDate, out Verifications)) { this.Cursor = Cursors.Default; // TODO: print reports on successfully posted batch MessageBox.Show(Catalog.GetString("The AP payment has been reversed."), Catalog.GetString("Reverse Payment")); TFormsMessage broadcastMessage = new TFormsMessage(TFormsMessageClassEnum.mcAPTransactionChanged); broadcastMessage.SetMessageDataAPTransaction(String.Empty); TFormsList.GFormsList.BroadcastFormMessage(broadcastMessage); } else { this.Cursor = Cursors.Default; string ErrorMessages = String.Empty; foreach (TVerificationResult verif in Verifications) { ErrorMessages += "[" + verif.ResultContext + "] " + verif.ResultTextCaption + ": " + verif.ResultText + Environment.NewLine; } System.Windows.Forms.MessageBox.Show(ErrorMessages, Catalog.GetString("Reverse Payment Failed")); } }