class SupplierInvoices extends DolibarrApi (View source)

API class for supplier invoices

Properties

DoliDB $db
Restler $r from  DolibarrApi
static string[] $FIELDS
FactureFournisseur $invoice

Methods

__construct()

Constructor

string|array<string, mixed>
_checkValForAPI(string $field, string|string[] $value, object $object)

Check and convert a string depending on its type/name.

object
_filterObjectProperties(object $object, string $properties)

Filter properties that will be returned on object

object
_cleanObjectDatas(object $object)

Clean sensible object datas

static bool
_checkAccessToResource(string $resource, int $resource_id = 0, string $dbtablename = '', string $feature2 = '', string $dbt_keyfield = 'fk_soc', string $dbt_select = 'rowid')

Check access by user to a given resource

bool|string
_checkFilters(string $sqlfilters, string $error = '')

Return if a $sqlfilters parameter is valid Function no more used. Kept for backward compatibility with old APIs of modules

static string
_forge_criteria_callback(string[] $matches)

Function to forge a SQL criteria from a Generic filter string.

object
get(int $id)

Get properties of a supplier invoice object

array
index(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $thirdparty_ids = '', string $status = '', string $sqlfilters = '', string $properties = '', bool $pagination_data = false)

List invoices

int
post(array $request_data = null)

Create supplier invoice object

object|false
put(int $id, array $request_data = null)

Update supplier invoice

array
delete(int $id)

Delete supplier invoice

array
validate(int $id, int $idwarehouse = 0, int $notrigger = 0)

Validate an invoice

object
settodraft(int $id, int $idwarehouse = -1, int $notrigger = 0)

Sets an invoice as draft

array
getPayments(int $id)

Get list of payments of a given supplier invoice

int
addPayment(int $id, int $datepaye, int $payment_mode_id, string $closepaidinvoices, int $accountid, string $num_payment = '', string $comment = '', string $chqemetteur = '', string $chqbank = '', float $amount = null)

Add payment line to a specific supplier invoice with the remain to pay as amount.

object
settopaid(int $id, string $close_code = '', string $close_note = '')

Sets a supplier invoice as paid

object
settounpaid(int $id)

Sets a supplier invoice as unpaid

array
getLines(int $id)

Get lines of a supplier invoice

int|bool
postLine(int $id, array $request_data = null)

Add a line to given supplier invoice

object
putLine(int $id, int $lineid, array $request_data = null)

Update a line to a given supplier invoice

array
deleteLine(int $id, int $lineid)

Deletes a line of a given supplier invoice

Details

__construct()

Constructor

protected string|array<string, mixed> _checkValForAPI(string $field, string|string[] $value, object $object)

Check and convert a string depending on its type/name.

Parameters

string $field

Field name

string|string[] $value

Value to check/clean

object $object Object

Return Value

string|array<string, mixed>

Value cleaned

protected object _filterObjectProperties(object $object, string $properties)

Filter properties that will be returned on object

Parameters

object $object

Object to clean

string $properties

Comma separated list of properties names

Return Value

object

Object with cleaned properties

protected object _cleanObjectDatas(object $object)

Clean sensible object datas

Parameters

object $object

Object to clean

Return Value

object

Object with cleaned properties

static protected bool _checkAccessToResource(string $resource, int $resource_id = 0, string $dbtablename = '', string $feature2 = '', string $dbt_keyfield = 'fk_soc', string $dbt_select = 'rowid')

Check access by user to a given resource

Parameters

string $resource

element to check

int $resource_id

Object ID if we want to check a particular record (optional) is linked to a owned thirdparty (optional).

string $dbtablename

'TableName&SharedElement' with Tablename is table where object is stored. SharedElement is an optional key to define where to check entity. Not used if objectid is null (optional)

string $feature2

Feature to check, second level of permission (optional). Can be or check with 'level1|level2'.

string $dbt_keyfield

Field name for socid foreign key if not fk_soc. Not used if objectid is null (optional)

string $dbt_select

Field name for select if not rowid. Not used if objectid is null (optional)

Return Value

bool

protected bool|string _checkFilters(string $sqlfilters, string $error = '')

Return if a $sqlfilters parameter is valid Function no more used. Kept for backward compatibility with old APIs of modules

Parameters

string $sqlfilters

sqlfilter string

string $error

Error message

Return Value

bool|string

True if valid, False if not valid

static protected string _forge_criteria_callback(string[] $matches)

Function to forge a SQL criteria from a Generic filter string.

Function no more used. Kept for backward compatibility with old APIs of modules

Parameters

string[] $matches

Array of found string by regex search. Each entry is 1 and only 1 criteria. Example: "t.ref:like:'SO-%'", "t.date_creation:<:'20160101'", "t.date_creation:<:'2016-01-01 12:30:00'", "t.nature:is:NULL", "t.field2:isnot:NULL"

Return Value

string

Forged criteria. Example: "t.field like 'abc%'"

object get(int $id)

Get properties of a supplier invoice object

Return an array with supplier invoice information

Parameters

int $id

ID of supplier invoice

Return Value

object

Object with cleaned properties

Exceptions

RestException
RestException

array index(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $thirdparty_ids = '', string $status = '', string $sqlfilters = '', string $properties = '', bool $pagination_data = false)

List invoices

Get a list of supplier invoices

Parameters

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

Limit for list

int $page

Page number

string $thirdparty_ids

Thirdparty ids to filter invoices of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i}

string $status

Filter by invoice status : draft | unpaid | paid | cancelled

string $sqlfilters

Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'20160101')"

string $properties

Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names

bool $pagination_data

If this parameter is set to true the response will include pagination data. Default value is false. Page starts from 0*

Return Value

array

Array of invoice objects

Exceptions

RestException

int post(array $request_data = null)

Create supplier invoice object

Note: soc_id = dolibarr_order_id

Example: {'ref': 'auto', 'ref_supplier': '7985630', 'socid': 1, 'note': 'Inserted with Python', 'order_supplier': 1, 'date': '2021-07-28'}

Parameters

array $request_data

Request data

Return Value

int

ID of supplier invoice

Exceptions

RestException
RestException

object|false put(int $id, array $request_data = null)

Update supplier invoice

Parameters

int $id

Id of supplier invoice to update

array $request_data Data

Return Value

object|false

Updated object

Exceptions

RestException
RestException

array delete(int $id)

Delete supplier invoice

Parameters

int $id

Supplier invoice ID

Return Value

array

Exceptions

RestException
RestException
RestException

array validate(int $id, int $idwarehouse = 0, int $notrigger = 0)

Validate an invoice

Parameters

int $id

Invoice ID

int $idwarehouse

Warehouse ID

int $notrigger

1=Does not execute triggers, 0= execute triggers

Return Value

array

Exceptions

RestException
RestException
RestException
RestException
RestException

object settodraft(int $id, int $idwarehouse = -1, int $notrigger = 0)

Sets an invoice as draft

Parameters

int $id

Id of supplier invoice

int $idwarehouse

Warehouse ID

int $notrigger

1=Does not execute triggers, 0= execute triggers

Return Value

object

Object with cleaned properties

Exceptions

RestException
RestException
RestException
RestException

array getPayments(int $id)

Get list of payments of a given supplier invoice

Parameters

int $id

Id of SupplierInvoice

Return Value

array

Exceptions

RestException
RestException
RestException
RestException

int addPayment(int $id, int $datepaye, int $payment_mode_id, string $closepaidinvoices, int $accountid, string $num_payment = '', string $comment = '', string $chqemetteur = '', string $chqbank = '', float $amount = null)

Add payment line to a specific supplier invoice with the remain to pay as amount.

Parameters

int $id

Id of invoice

int $datepaye

{@from body} Payment date {@type timestamp}

int $payment_mode_id

{@from body} Payment mode ID (look it up via REST GET to /setup/dictionary/payment_types) {@min 1}

string $closepaidinvoices

{@from body} Close paid invoices {@choice yes,no}

int $accountid

{@from body} Bank account ID (look it up via REST GET to /bankaccounts) {@min 1}

string $num_payment

{@from body} Payment number (optional)

string $comment

{@from body} Note (optional)

string $chqemetteur

{@from body} Payment issuer (mandatory if payment_mode_id corresponds to 'CHQ'-payment type)

string $chqbank

{@from body} Issuer bank name (optional)

float $amount

{@from body} Amount of payment if we don't want to use the remain to pay

Return Value

int

Payment ID

Exceptions

RestException
RestException
RestException

object settopaid(int $id, string $close_code = '', string $close_note = '')

Sets a supplier invoice as paid

Parameters

int $id

Supplier invoice ID

string $close_code

Optional close code (e.g. discount/escompte case)

string $close_note

Optional close note/comment

Return Value

object

Object with cleaned properties

Exceptions

RestException
RestException
RestException
RestException

object settounpaid(int $id)

Sets a supplier invoice as unpaid

Parameters

int $id

Supplier invoice ID

Return Value

object

Object with cleaned properties

Exceptions

RestException
RestException
RestException
RestException

array getLines(int $id)

Get lines of a supplier invoice

Parameters

int $id

Id of supplier invoice

Return Value

array

Exceptions

RestException
RestException

int|bool postLine(int $id, array $request_data = null)

Add a line to given supplier invoice

Note: socid = dolibarr_order_id, pu_ht = net price, remise = discount

Example: {'socid': 1, 'qty': 1, 'pu_ht': 21.0, 'tva_tx': 25.0, 'fk_product': '1189', 'product_type': 0, 'remise_percent': 1.0, 'vat_src_code': None}

Parameters

int $id

Id of supplier invoice to update

array $request_data

supplier invoice line data

Return Value

int|bool

Exceptions

RestException
RestException

object putLine(int $id, int $lineid, array $request_data = null)

Update a line to a given supplier invoice

Parameters

int $id

Id of supplier invoice to update

int $lineid

Id of line to update

array $request_data

InvoiceLine data

Return Value

object

Exceptions

RestException
RestException
RestException

array deleteLine(int $id, int $lineid)

Deletes a line of a given supplier invoice

Parameters

int $id

Id of supplier invoice

int $lineid

Id of the line to delete

Return Value

array

Exceptions

RestException
RestException
RestException
RestException