pixiManualCreditCreate
Creates a manual credit note (negative invoice) for an existing invoice with a single amount and VAT rate.
Creates a credit note that references an existing invoice. The credit has no item lines; it consists of one amount and one VAT rate.
- Validation
Amountmust be greater than 0.VATRatemust beH,LorN.- At least one of
InvoiceKeyorInvoiceNrmust be given. If onlyInvoiceNris given, the key is looked up inInvoices. The invoice must exist. If both are given, they must belong to the same invoice.
- Invoice data: order type, invoice location, customer, billing and shipping address and currency are taken from the original invoice. The country comes from the billing address.
- Position text: if
PositionTextis empty, a default text is built. WithLanguageId= 1 it isManual Credit: Created From: {InvoiceNr}. Otherwise it isManuell Gutschrift: Erstellt von: {InvoiceNr}.LanguageIddefaults to 2. - VAT calculation: the VAT rates for the country and order type are read with
Pixi_CA_GetVATList. The row with the requestedVATRateis used.- For order type
B2B,Amountis treated as net: net = −Amount, gross = −Amount× (1 + VAT), rounded to 2 decimals. - For all other order types,
Amountis treated as gross: gross = −Amount, net = −Amount/ (1 + VAT), rounded to 2 decimals.
- For order type
- Limit check: the absolute gross amount of the new credit is added to the absolute sum of the totals of all invoices that already reference the original invoice (
RefToInvoiceKey). If the result is greater than the original invoice total, the call is rejected. - Creation:
Pixi_CA_InsertManualInvoicecreates the credit. It does the following:- assigns the next invoice number;
- inserts the record into
InvoiceswithRefToInvoiceKey/RefToInvoiceNrpointing to the original invoice; - adds SEPA data and an
InvoicePackagerecord; - books the credit to the customer account;
- publishes the MQ event
InvoiceCreated.
The call returns one status row with Status and Message.
Notes
- The call runs in its own transaction. If a transaction is already open, it uses a savepoint instead. Validation errors roll back and return return code 2. Unexpected errors are logged via
log.InsertErrorand return return code 3. Success returns 0. Return codes are not part of the SOAP rows. - Always pass
AmountandVATRate. ANULLvalue does not trigger the validation checks, because comparisons withNULLare not true. The calculated totals then stayNULL, and the limit check is skipped as well. - The same applies when the VAT list contains no row for the requested
VATRate, for exampleLfor a country without a reduced rate. Totals stayNULL. Pixi_CA_GetVATListcan return both the current rate and a rate valid 12 months ago for the sameVATRate. Which row is used for the calculation is then not determined by the code.- The limit check adds the absolute value of the sum of existing referencing invoices, not the sum of absolute values.
- Invoice lookups use
NOLOCK, so concurrent credits for the same invoice are not strictly prevented from exceeding the invoice total. Pixi_CA_InsertManualInvoicecatches its own errors, logs them and does not re-raise them. If it fails, the caller may still receive theOKrow. This can be followed by anErrorrow if the final commit fails because the transaction was already rolled back.- The text of the generic error (
...getting the report values...) is misleading; it covers any unexpected error of this call. - The inner procedures
Pixi_GetNextInvNr,Pixi_CA_AddPixiInvoice,Pixi_AddDataForSEPAExportToInvoiceandPixi_MQ_EventPublishare not attached. Their exact effects, such as customer account bookings and the MQ event, are not documented here.
Tables used
| Parameter | Type | Default | Description |
|---|---|---|---|
InvoiceKey
|
int | NULL |
Key of the original invoice. Either this or Example: |
InvoiceNr
|
varchar(20) string |
NULL |
Number of the original invoice. Used to look up the key if Example: |
PositionText
|
varchar(120) string |
NULL |
Text of the credit note, stored as the invoice text without lines. If empty, a default text with the original invoice number is used. Example: |
LanguageId
|
tinyint int |
NULL |
Language for the default position text. Allowed values
Example: |
VATRate
|
varchar(1) string |
NULL |
VAT rate class of the credit amount. Allowed values
Example: |
Amount
|
money decimal |
NULL |
Positive credit amount. It is net for order type Example: |
UserName
|
varchar(50) string |
NULL |
User name stored as creator of the credit note. Example: |
Result set 1 · Always; one status row (in rare inner-failure cases an OK row may be followed by an Error row)
Status of the operation.
| Column | Type | Description |
|---|---|---|
Status
|
varchar(5) string |
|
Message
|
varchar(max) string |
|
Response example
<SqlRowSet1>
<row>
<Status>OK</Status>
<Message>Credit created</Message>
</row>
</SqlRowSet1>
| Status | Message | Cause |
|---|---|---|
| Error | Amount should be positive | `Amount` is 0 or negative. Pass a positive amount. |
| Error | Missing VAT data | `VATRate` is not `H`, `L` or `N`. |
| Error | Missing Invoice data | Neither `InvoiceKey` nor `InvoiceNr` was given. |
| Error | Invoice does not exist | No invoice was found for the given `InvoiceNr` or `InvoiceKey`. |
| Error | InvoiceNr and InvoiceKey do not match | Both identifiers were given but belong to different invoices. Pass only one or consistent values. |
| Error | Credit total is too high | The new credit plus existing credits referencing the invoice would exceed the invoice total. Reduce the amount. |
| Error | Unexpected error while getting the report values. ({ERROR_MESSAGE}) | An unexpected SQL error occurred; the transaction is rolled back and the error is logged. |
POST https://apigateway.descartes.com/tms/pixi/
Content-Type: text/xml; charset=utf-8
Authorization: Basic BASE64(USERNAME:PASSWORD)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://apigateway.descartes.com/tms/pixi/">
<SOAP-ENV:Body>
<ns1:pixiManualCreditCreate>
<!-- <InvoiceKey>104523</InvoiceKey> -->
<!-- <InvoiceNr>RE2024001234</InvoiceNr> -->
<!-- <PositionText>Goodwill credit for late delivery</PositionText> -->
<!-- <LanguageId>2</LanguageId> -->
<!-- <VATRate>H</VATRate> -->
<!-- <Amount>25.00</Amount> -->
<!-- <UserName>api_user</UserName> -->
</ns1:pixiManualCreditCreate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
curl -X POST 'https://apigateway.descartes.com/tms/pixi/' \
--user 'USERNAME:PASSWORD' \
--header 'Content-Type: text/xml; charset=utf-8' \
--data-binary @- <<'XML'
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://apigateway.descartes.com/tms/pixi/">
<SOAP-ENV:Body>
<ns1:pixiManualCreditCreate>
<!-- <InvoiceKey>104523</InvoiceKey> -->
<!-- <InvoiceNr>RE2024001234</InvoiceNr> -->
<!-- <PositionText>Goodwill credit for late delivery</PositionText> -->
<!-- <LanguageId>2</LanguageId> -->
<!-- <VATRate>H</VATRate> -->
<!-- <Amount>25.00</Amount> -->
<!-- <UserName>api_user</UserName> -->
</ns1:pixiManualCreditCreate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XML
<?php
$soapClient = new SoapClient(null, [
'login' => 'USERNAME',
'password' => 'PASSWORD',
'location' => 'https://apigateway.descartes.com/tms/pixi/',
'uri' => 'https://apigateway.descartes.com/tms/pixi/',
]);
$arguments = [
// 'InvoiceKey' => '104523',
// 'InvoiceNr' => 'RE2024001234',
// 'PositionText' => 'Goodwill credit for late delivery',
// 'LanguageId' => '2',
// 'VATRate' => 'H',
// 'Amount' => '25.00',
// 'UserName' => 'api_user',
];
$soapArguments = [];
foreach ($arguments as $name => $value) {
$soapArguments[] = new SoapVar($value, XSD_STRING, '', '', $name);
}
$response = $soapClient->__soapCall('pixiManualCreditCreate', $soapArguments);
- SQL object:
- dbo.pipiManualCreditCreate