class SupplierOrders extends DolibarrApi (View source)

API class for supplier orders

Properties

protected DoliDB $db from  DolibarrApi
Restler $r from  DolibarrApi
static string[] $FIELDS
CommandeFournisseur $order

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.

array|mixed
get(int $id)

Get properties of a supplier order object

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

List orders

int
post(array $request_data = null)

Create supplier order object

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

Update supplier order

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

Add a line to a given supplier order

array<int, mixed>
getContacts(int $id, string $source, string $type = '')

Get contacts of given supplier order

array
postContact(int $id, int $contactid, string $type, string $source)

Add a contact type of given supplier order

array
deleteContact(int $id, int $contactid, string $type, string $source)

Unlink a contact type of given supplier order

array
delete(int $id)

Delete supplier order

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

Validate an order

array
approve(int $id, int $idwarehouse = 0, int $secondlevel = 0)

Approve an order

array
makeOrder(int $id, int $date, int $method, string $comment = '')

Sends an order to the vendor

array
receiveOrder(int $id, int $closeopenorder, string $comment, array $lines)

Receives the order, dispatches products.

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%'"

array|mixed get(int $id)

Get properties of a supplier order object

Return an array with supplier order information

Parameters

int $id

ID of supplier order

Return Value

array|mixed

data without useless information

Exceptions

RestException

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

List orders

Get a list of supplier orders

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 orders of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i}

string $product_ids

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

string $status

Filter by order status : draft | validated | approved | running | received_start | received_end | cancelled | refused

string $sqlfilters

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

string $sqlfilterlines

Other criteria to filter answers separated by a comma. Syntax example "(tl.fk_product:=:'17') and (tl.price:<:'250')"

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 order objects

Exceptions

RestException

int post(array $request_data = null)

Create supplier order object

Example: {"ref": "auto", "ref_supplier": "1234", "socid": "1", "multicurrency_code": "SEK", "multicurrency_tx": 1, "tva_tx": 25, "note": "Imported via the REST API"}

Parameters

array $request_data

Request data

Return Value

int

ID of supplier order

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

Update supplier order

Parameters

int $id

Id of supplier order to update

array $request_data Data

Return Value

object|false

Updated object

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

Add a line to a given supplier order

Parameters

int $id

Id of order to update

array $request_data

OrderLine data

Return Value

int

array<int, mixed> getContacts(int $id, string $source, string $type = '')

Get contacts of given supplier order

Return an array with contact information

Parameters

int $id

ID of supplier order

string $source

Source of the contact (internal, external, all).

string $type

Type of the contact (BILLING, SHIPPING, CUSTOMER, SALESREPFOLL, ...)

Return Value

array<int, mixed>

Array of contacts

Exceptions

RestException

array postContact(int $id, int $contactid, string $type, string $source)

Add a contact type of given supplier order

Parameters

int $id

Id of supplier order to update

int $contactid

Id of contact/user to add

string $type

Type of the contact (BILLING, SHIPPING, CUSTOMER, SALESREPFOLL, ...)

string $source

Source of the contact (external, internal)

Return Value

array

Exceptions

RestException
RestException

array deleteContact(int $id, int $contactid, string $type, string $source)

Unlink a contact type of given supplier order

Parameters

int $id

Id of supplier order to update

int $contactid

Id of contact/user to add

string $type

Type of the contact (BILLING, SHIPPING, CUSTOMER, SALESREPFOLL, ...).

string $source

Source of the contact (internal, external).

Return Value

array

Exceptions

RestException
RestException
RestException

array delete(int $id)

Delete supplier order

Parameters

int $id

Supplier order ID

Return Value

array

Array of result

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

Validate an order

Parameters

int $id

Order ID

int $idwarehouse

Warehouse ID

int $notrigger

1=Does not execute triggers, 0= execute triggers

Return Value

array

array approve(int $id, int $idwarehouse = 0, int $secondlevel = 0)

Approve an order

Parameters

int $id

Order ID

int $idwarehouse

Warehouse ID

int $secondlevel

1=Does not execute triggers, 0= execute triggers

Return Value

array

array makeOrder(int $id, int $date, int $method, string $comment = '')

Sends an order to the vendor

Parameters

int $id

Order ID

int $date

Date (unix timestamp in sec)

int $method Method
string $comment Comment

Return Value

array

array receiveOrder(int $id, int $closeopenorder, string $comment, array $lines)

Receives the order, dispatches products.

Example:


  "closeopenorder": 1,
  "comment": "",
  "lines": [{
     "id": 14,
     "fk_product": 112,
     "qty": 18,
     "warehouse": 1,
     "price": 114,
     "comment": "",
     "eatby": 0,
     "sellby": 0,
     "batch": 0,
     "notrigger": 0
  }]
}```

Parameters

int $id

Order ID

int $closeopenorder

Close order if everything is received {@required false}

string $comment

Comment {@required false}

array $lines

Array of product dispatches

Return Value

array