AP Payment v2
Rules in AP Payment
- Payment Knockoff Date must be equal or greater than the Payment Date.
- Payment net total must be greater than 0.
- Payment net total must be the sum of Payment Amount in Payment Detail
- Total of knockoff Amount must not exceed the sum of Payment Amount.
- Payment Method is created in General Maintenance | Payment Method Maintenance.
References of AutoCount Accounting version 2.0
AutoCount.Accounting.dll AutoCount.Accounting.UI.dll AutoCount.dll AutoCount.MainEntry.dll AutoCount.UI.dll AutoCount.ARAP.dll
AP Payment API Usage
New
public void NewAPPayment(AutoCount.Authentication.UserSession userSession)
{
AutoCount.ARAP.APPayment.APPaymentDataAccess cmd =
AutoCount.ARAP.APPayment.APPaymentDataAccess.Create(userSession, userSession.DBSetting);
AutoCount.ARAP.APPayment.APPaymentEntity doc = cmd.NewAPPayment();
//If you want to set your own Payment Voucher number, uncomment doc.DocNo to assign document no.
//System auto assign running number, when DocNo is not defined.
//doc.DocNo = “PV-0001″;
doc.CreditorCode = "400-X001";
// Add one payment detail
AutoCount.ARAP.APPayment.APPaymentDTLEntity paymentDetail = doc.NewDetail();
paymentDetail.PaymentMethod = "CASH";
paymentDetail.PaymentAmt = 100;
paymentDetail.ChequeNo = "PBB123456";
//Knockoff Invoice
doc.KnockOff(AutoCount.Document.DocumentType.APInvoice, "IV-0001", 100);
try
{
cmd.SaveAPPayment(doc, userSession.LoginUserID);
AutoCount.AppMessage.ShowMessage($"Success: {doc.DocNo}");
}
catch (AutoCount.AppException ex)
{
AutoCount.AppMessage.ShowMessage(ex.Message);
}
}
Edit
public void EditAPPayment(AutoCount.Authentication.UserSession userSession)
{
AutoCount.ARAP.APPayment.APPaymentDataAccess cmd =
AutoCount.ARAP.APPayment.APPaymentDataAccess.Create(userSession, userSession.DBSetting);
AutoCount.ARAP.APPayment.APPaymentEntity doc = cmd.GetAPPayment("PV-0001");
//If doc (APPayment) is null, doc (APPayment) does not exist in AP Payment;
//Then exit this function
if (doc == null)
return;
//Detail is the Payment with Payment Method & Amount
doc.ClearDetails();
AutoCount.ARAP.APPayment.APPaymentDTLEntity paymentDetail = doc.NewDetail();
paymentDetail.PaymentMethod = "CARD";
paymentDetail.PaymentAmt = 600;
try
{
cmd.SaveAPPayment(doc, userSession.LoginUserID);
AutoCount.AppMessage.ShowMessage($"{doc.DocNo} is updated successfully.");
}
catch (AutoCount.AppException ex)
{
AutoCount.AppMessage.ShowMessage($"Failed to update {doc.DocNo}.");
}
}
Cancel (Void)
private void CancelAPPayment(AutoCount.Authentication.UserSession userSession)
{
AutoCount.ARAP.APPayment.APPaymentDataAccess cmd =
AutoCount.ARAP.APPayment.APPaymentDataAccess.Create(userSession, userSession.DBSetting);
try
{
cmd.CancelAPPayment("PV-0001", userSession.LoginUserID);
AutoCount.AppMessage.ShowMessage("Payment is Cancelled.");
}
catch (AutoCount.AppException ex)
{
AutoCount.AppMessage.ShowMessage("Failed to Cancel Payment.");
}
}
Delete
private void DeleteAPPayment(AutoCount.Authentication.UserSession userSession)
{
AutoCount.ARAP.APPayment.APPaymentDataAccess cmd =
AutoCount.ARAP.APPayment.APPaymentDataAccess.Create(userSession, userSession.DBSetting);
try
{
cmd.DeleteAPPayment("PV-0001", userSession.LoginUserID);
AutoCount.AppMessage.ShowMessage("Pay is deleted.");
}
catch (AutoCount.AppException ex)
{
AutoCount.AppMessage.ShowMessage("Failed to Delete Payment.\n" + ex.Message);
}
}
Sample Code with Data Model
This sample code provides the example of creating new AP Payment with tested data.
Source Data (Example for reference Only)
Source Data is implemented to hold data that is to be updated into AutoCount Accounting. The Source Data designed here is for reference only. You may either create your own data model, or read from your database and assign value to transaction/document of AutoCount Accounting.
public class APPaymentSource
{
public string CreditorCode { get; set; }
public string DocumentNo { get; set; }
public string ReceiptNo2 { get; set; }
public DateTime DocumentDate { get; set; } = DateTime.Today.Date;
public string Description { get; set; }
public string DepositMethod { get; set; }
//PaymentCurrencyCode will be the currency code of Creditor's Account.
//Need to define only when PaymentCurrencyCode is different from Creditor's Account Currency
public string PaymentCurrencyCode { get; set; }
//Require PaymentToHomeCurrencyRate,
//when PaymentCurrencyCode is in Foreign Currency
public decimal? PaymentToHomeCurrencyRate { get; set; }
//Require PaymentToCreditorCurrencyRate,
//when PaymentCurrencyCode is different from Creditor CurrencyCode
public decimal? PaymentToCreditorCurrencyRate { get; set; }
public string Project { get; set; }
public string Department { get; set; }
public List<APPaymentDetailSource> PaymentDetail = new List<APPaymentDetailSource>();
public List<PaymentKnockoffSource> PaymentKnockoff = new List<PaymentKnockoffSource>();
}
public class APPaymentDetailSource
{
public string PaymentMethod { get; set; }
public string ChequeNo { get; set; }
public decimal PaymentAmount { get; set; }
public decimal? BankCharge { get; set; }
public string BankChargeTaxCode { get; set; }
public string BankChargeBillNoForGst { get; set; }
public string PaymentBy { get; set; }
//If this cheque is returned/bounced cheque
//Set the returned/bounced date. Otherwise it is null
public DateTime? ReturnChequeDate { get; set; }
}
public class PaymentKnockoffSource
{
//Document Type of APPayment knockoff
public const string APInvoiceDocType = AutoCount.Document.DocumentType.APInvoice;
public const string APDebitNoteDocType = AutoCount.Document.DocumentType.APDN;
//Must assign with valid document type
//in this class, you may find both possible document type for APPayment Knockoff
//(1) APInvoiceDocType, and (2) APDebitNoteDocType
public string DocType { get; set; }
//The DocNo must already exist in the respective document type
public string DocNo { get; set; }
//The amount to be used to knockoff invoice,
//the total must not be more than sum of Payment Amount
public decimal Amount { get; set; }
//When knockoff date is null,
//system will use Payment Date as knockoff date
public DateTime? Date { get; set; }
}
Create New AP Payment
public void NewAPPayment(APPaymentSource source, AutoCount.Authentication.UserSession userSession)
{
//Create command object of APPayment
AutoCount.ARAP.APPayment.APPaymentDataAccess cmd =
AutoCount.ARAP.APPayment.APPaymentDataAccess.Create(userSession, userSession.DBSetting);
//Create a new APPayment transaction
AutoCount.ARAP.APPayment.APPaymentEntity doc = cmd.NewAPPayment();
//Assign value to master table
doc.CreditorCode = source.CreditorCode;
doc.DocNo = source.DocumentNo ?? doc.DocNo;
doc.DocNo2 = source.ReceiptNo2 ?? doc.DocNo2;
doc.DocDate = source.DocumentDate;
doc.CurrencyCode = source.PaymentCurrencyCode ?? doc.CurrencyCode;
doc.ToHomeRate = source.PaymentToHomeCurrencyRate ?? doc.ToHomeRate;
doc.ToCreditorRate = source.PaymentToCreditorCurrencyRate ?? doc.ToCreditorRate;
doc.ProjNo = source.Project;
doc.DeptNo = source.Department;
//Loop and assign value to payment detail
source.PaymentDetail.ForEach(s => AddAPPaymentDetail(s, doc.NewDetail));
//Knockoff document
foreach (PaymentKnockoffSource knockoff in source.PaymentKnockoff)
{
if (knockoff.Date.HasValue)
{
doc.KnockOff(knockoff.DocType, knockoff.DocNo, knockoff.Amount, knockoff.Date.Value);
}
else
{
//If Knockoff date is not defined, system will assign Payment Date to Knockoff Date
doc.KnockOff(knockoff.DocType, knockoff.DocNo, knockoff.Amount);
}
}
try
{
cmd.SaveAPPayment(doc, userSession.LoginUserID);
//AutoCount.AppMessage.ShowMessage(string.Format("{0} is created.", doc.DocNo));
}
catch (AutoCount.AppException ex)
{
//log error
//AutoCount.AppMessage.ShowMessage(ex.Message);
}
}
Add New AP Payment Detail
private void AddAPPaymentDetail(APPaymentDetailSource source,
Func<AutoCount.ARAP.APPayment.APPaymentDTLEntity> addPaymentDetail)
{
AutoCount.ARAP.APPayment.APPaymentDTLEntity dtl = addPaymentDetail();
dtl.PaymentMethod = source.PaymentMethod;
dtl.ChequeNo = source.ChequeNo ?? dtl.ChequeNo;
dtl.PaymentAmt = source.PaymentAmount;
dtl.BankCharge = source.BankCharge ?? dtl.BankCharge;
dtl.BankChargeTaxType = source.BankChargeTaxCode ?? dtl.BankChargeTaxType;
dtl.BankChargeTaxRefNo = source.BankChargeBillNoForGst ?? dtl.BankChargeTaxRefNo;
dtl.PaymentBy = source.PaymentBy ?? source.PaymentBy;
if (source.ReturnChequeDate.HasValue)
{
dtl.IsRCHQ = true;
dtl.RCHQDate = source.ReturnChequeDate.Value;
}
}
Example of AP Payment in Home currency only
Test Data 1
public void TestSampleData1(AutoCount.Authentication.UserSession userSession)
{
APPaymentSource source = new APPaymentSource()
{
//Home Currency Debtor, payment with home currency
CreditorCode = "400-X001",
Description = "Generated Test Payment 1",
DocumentDate = new DateTime(2017, 12, 20),
};
source.PaymentDetail.Add(new APPaymentDetailSource()
{
PaymentMethod = "BANK",
ChequeNo = "CHQ00012",
PaymentAmount = 100,
BankCharge = 0.50M
});
//Document type is required for document knockoff
source.PaymentKnockoff.Add(new PaymentKnockoffSource()
{
DocType = PaymentKnockoffSource.APInvoiceDocType,
DocNo = "B-000002",
Amount = 70
});
source.PaymentKnockoff.Add(new PaymentKnockoffSource()
{
DocType = PaymentKnockoffSource.APInvoiceDocType,
DocNo = "B-000003",
Amount = 30
});
//Create New APPayment in AutoCount Accounting
NewAPPayment(source, userSession);
}
Example of Foreign Customer and payment in customer currency
A payment of SGD100.00 knockoff 2 outstanding invoices, which both invoices currency rate is 3.2.
AutoCount Accounting auto generate Loss in foreign currency transaction.
This is because the currency rate was issued is 3.2 in invoice, and the payment currency rate is 3.1.
Test Data 2
public void TestSampleData2(AutoCount.Authentication.UserSession userSession)
{
APPaymentSource source = new APPaymentSource()
{
//Singapore customer, payment in Singapore Dollar
CreditorCode = "400-S001",
Description = "Generated Payment - Test Data",
DocumentDate = new DateTime(2017, 12, 21),
//If Payment Currency is same as Debtor Currency,
//"PaymentCurrencyCode" can be excluded
PaymentCurrencyCode = "SGD",
PaymentToHomeCurrencyRate = 3.1M,
};
source.PaymentDetail.Add(new APPaymentDetailSource()
{
PaymentMethod = "BANK",
ChequeNo = "SGB0009",
PaymentAmount = 100, //Currency in SGD
});
//Document type is required for document knockoff
source.PaymentKnockoff.Add(new PaymentKnockoffSource()
{
DocType = PaymentKnockoffSource.APInvoiceDocType,
DocNo = "B-000017",
Amount = 70
});
source.PaymentKnockoff.Add(new PaymentKnockoffSource()
{
DocType = PaymentKnockoffSource.APInvoiceDocType,
DocNo = "B-000018",
Amount = 30
});
NewAPPayment(source, userSession);
}
See Also
AutoCount Accounting Account API | |||
---|---|---|---|
AR | AP | ||
Transactions | Version | Transactions | Version |
AR Debtor (Customer) | 1.8, 1.9 2.0 |
AP Creditor (Supplier) | 1.8, 1.9 2.0 |
AR Invoice | 1.8, 1.9 2.0 |
AP Invoice | 1.8, 1.9 2.0 |
AR Received Payment | 1.8, 1.9 2.0 |
AP Payment | 1.8, 1.9 2.0 |
AR Debit Note | 1.8, 1.9 2.0 |
AP Debit Note | 1.8, 1.9 2.0 |
AR Credit Note | 1.8, 1.9 2.0 |
AP Credit Note | 1.8, 1.9 2.0 |
AR Refund | 1.8, 1.9 2.0 |
AP Refund | 1.8, 1.9 2.0 |
AR Deposit | 1.8, 1.9 2.0 |
AP Deposit | 1.8, 1.9 2.0 |
AR Deposit - Create New or Update with Refund & Forfeit |
1.8, 1.9 2.0 | ||
A/R and A/P Contra Entry | 1.8, 1.9 2.0 |
Go to top
|
Resources For AutoCount Software Developers
|