-
Notifications
You must be signed in to change notification settings - Fork 2
PostPayAndAllocateSalesInvoices
The PostPayAndAllocateSalesInvoice function supports common scenarios that many third party applications require when integrating sales data with AccountsIQ. For example, an online e-shop or EPOS will often want to record a customer invoice and receipt simultaneously and allocate the two together at the same time from an accounting point of view.
This method is the bulk form of PostPayAndAllocateSalesInvoice, which means you can send a set of invoices and receipts to be created and allocated in a single API call.
Each request is atomic, but the whole is not. That is, if an invoice/receipt/allocation group is atomic, it is possible that the first 10 of the batch will succeed while the rest will fail.
Each query can be tagged with its unique client reference and is returned in each response, this useful to match the query to the request in case there was any shuffling during the serialization/de-serialization cycles.
public WSResult2<WSResult2<WSPostPayAndAllocateSalesInvoiceResult>[]> PostPayAndAllocateSalesInvoices(String token, WSPostPayAndAllocateSalesInvoiceQuery[] queries)
Parameter | Type | Description |
---|---|---|
token | String | The session token retrieved during authentication. |
queries | WSPostPayAndAllocateSalesInvoiceQuery[] | Queries describing the request made of the system |
Please see PostPayAndAllocateSalesInvoice for the details of the request and response format. Each element of the response carries its own Status
, ErrorCode
and ErrorMessage
. The overall response also has its own, and the overall result will have the status Success
only and only if every single query has a status of Success
. Otherwise it will be Failure
. In this case, looking at the ErrorCode
and ErrorMessage
fields of each response element will provide more information on the failure.
NOTE while within each query the customer code used for the invoice and the receipt must be the same, they do not have to be the same for the whole batch.
The following example creates an invoice, a receipt and perform an allocation:
Integration ws = new Integration();
String auth = ws.Login(entityID, partnerKey, userKey);
if( auth != null )
{
var queries = Enumerable.Range(0, 1000)
.Select(i => {
BatchSalesInvoice invoice = new BatchSalesInvoice();
invoice.CustomerCode = cust.Code;
invoice.ExchangeRate = 1M;
invoice.InvoiceDate = DateTime.Now;
invoice.ExternalReference = "REF000" + i;
inv.Lines = new BatchSalesInvoiceLine[1]
{
new BatchSalesInvoiceLine()
{
Description = "Line 1",
GLAccountCode = "1000",
NetAmount = 100M,
TaxAmount = 0M,
TaxCode = "V01",
TaxRate = 0
}
};
SalesReceipt receipt = new SalesReceipt()
{
BankAccountCode = "6010",
BankExchangeRate = 1M,
CheckReference = "REF01",
CustomerCode = "CUST012",
Description = "Receipt",
ExchangeRate = 1M,
PaymentAmount = 199M,
PaymentDate = DateTime.Now.AddDays(2)
};
receipt.CheckReference = "CHQ-" + invoice.ExternalReference;
return new WSPostPayAndAllocateSalesInvoiceQuery()
{
BatchInvoice = invoice,
Receipt = receipt,
PerformAllocation = true,
PerformExternalReferenceDuplicateCheckOnInvoice = true,
PerformExternalReferenceDuplicateCheckOnReceipt = true,
AllocationReference = invoice.ExternalReference
};
})
.ToArray();
var result = ws.PostPayAndAllocateSalesInvoices(auth, queries);
result.Status.Should().Be(OperationStatus.Success);
}