Purchase Payment POST

URI

https://{DATACENTER}.brightpearlconnect.com/public-api/{ACCOUNT}
/accounting-service/invoice/purchase-payment/

Refer to our documentation on URI syntax for more information on how to construct URIs.

Description

Transforms the Payment resource sent into the corresponding journal lines. This endpoint uses specific logic to validate the payment representation, but then delegates to the journal entry logic to validate and create the lines in the database.
Using the adjustment field in a payment you can specify a certain amount to be taken from or redirected to a difference nominal code.

Purchase Payment POST Validation

Mandatory elements are the header, and at least one payment line

The fields that are mandatory in the header component are:

  • contactId
  • bankAccountNominalCode - unless the payments balance is zero
  • taxDate
  • exchangeRate (if currencyId is not the base currency)

The fields that are mandatory in each payment line are:

  • value

Other validations are:

  • The order id must be in the system
  • The contact id must be in the system
  • The contact must be of type "supplier"
  • The contact must be the primary contact for the order
  • The nominal code must be a bank account or an adjustment account
  • For each invoice reference given we check that the currency specified is compatible with the previous entries (if any):
    • If previous currency is not a base currency then the specified currency must be the same of the previous entries
    For further info see paragraph "Currency conversion" below.
  • If an adjustment is added to a payment it must have both value and nominal code
  • The sum of the payment and adjustment cannot be greater than the invoice amount

The journal-entry POST is then validating additional accounting rules, if applicable.

Default values are:

  • If currency id is not sent, it defaults to the base currency (unless exchange rate sent it not 1)
  • If no invoice reference is specified for a line then a temporary reference is created with this form accnt-JOURNAL_ID (where JOURNAL_ID is the number of the journal id being created)

Calculations and currency conversions:

  • If all journals for all invoices in the PP are in the same currency or there are no previous journal entries, no conversion happens.
  • If PP is in foreign currency and previous journals are in base currency, or multi currency feature toggle is off, we convert the values to base currency using the specified exchange rate and create the PP in base currency.
  • If the payment that is being specified exceeds the amount of the invoice, an overpayment is created.
  • The overpayment can be produced also as a consequence of one of the base currency conversions described in the previous point. The invoice reference for the overpayment will be: prefix "ovr_" followed by the invoice that it is referring, i. e. ovr_PI-1029.
  • When a PP only contains positive and negative lines balancing each other, only lines for figures are created, and no line for the bank account.

Invoice clearing:

  • If the posted PP (summed with eventual previous ones) has a value to clear an invoice, all the journals that are relative to the same invoice reference will be marked as cleared.
  • When an invoice is cleared, the calculation of the exchange rate variance is triggered: If the invoice is in a foreign currency and there was an exchange rate variance, a special extra PP journal is created to compensate for the fluctuations in currency value.

Example

Creating a purchase payment for the purchase invoice PI-126 of order 2 (having made a payment) and purchase credit PC 345 of order 3501 (having received a refund), both invoices belonging to supplier 203. The second payment has an adjustment that will move 1 from the bank account to the specified 7804 nominal code. Returns the journal id if successful.

Request URI

/invoice/purchase-payment/

Request body

{
	"header": {
		"checkNumber": "1234566",
		"contactId": 203,
		"bankAccountNominalCode": "1200",
		"description": "a description for PP",
		"taxDate": "2016-04-13",
		"currencyId": 1,
		"exchangeRate": 1
	},
	"payments": [
		{
			"invoiceRef": "126",
			"orderId": 2,
			"value": 33.00
		},
		{
			"invoiceRef": "345",
			"orderId": 3501,
			"value": -12.00,
			"adjustment": {
				"value": 1.00,
				"nominalCode": "7804"
			}
		}
	]
}

Response

{
	"response": 30
}