dolibarr 25.0.0-alpha
SupplierOrders Class Reference
Inheritance diagram for SupplierOrders:
Collaboration diagram for SupplierOrders:

Public Member Functions

 __construct ()
 Constructor.
 
 get ($id)
 Get properties of a supplier order object.
 
 index ($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $product_ids='', $status='', $sqlfilters='', $sqlfilterlines='', $properties='', $pagination_data=false)
 List orders.
 
 post ($request_data=null)
 Create supplier order object.
 
 put ($id, $request_data=null)
 Update supplier order.
 
 postLine ($id, $request_data=null)
 Add a line to a given supplier order.
 
 getLine ($id, $lineid)
 Get one supplier order line after checking access to its parent.
 
 putLine ($id, $lineid, $request_data=null)
 Update selected fields of a draft supplier order line.
 
 deleteLine ($id, $lineid)
 Deletes a line of a given draft supplier order.
 
 getContacts ($id, $source, $type='')
 Get contacts of given supplier order.
 
 postContact ($id, $contactid, $type, $source)
 Add a contact type of given supplier order.
 
 deleteContact ($id, $contactid, $type, $source)
 Unlink a contact type of given supplier order.
 
 delete ($id)
 Delete supplier order.
 
 validate ($id, $idwarehouse=0, $notrigger=0)
 Validate an order.
 
 settodraft ($id)
 Set a validated or approved order back to draft.
 
 approve ($id, $idwarehouse=0, $secondlevel=0)
 Approve an order.
 
 refuse ($id, $comment='')
 Refuse a validated order that is waiting for approval.
 
 makeOrder ($id, $date, $method, $comment='')
 Sends an order to the vendor.
 
 cancel ($id, $comment='')
 Cancel an approved order that has not been sent to the vendor yet.
 
 receiveOrder ($id, $closeopenorder, $comment, $lines)
 Receives the order, dispatches products.
 
- Public Member Functions inherited from DolibarrApi
 __construct ($db, $cachedir='', $refreshCache=false)
 Constructor.
 

Protected Member Functions

 prepareLineUpdate ($line, $request_data)
 Prepare a partial update without changing the original line or writing data.
 
 loadOrderForOperation ($id)
 Load an authorised order without sanitising its live database handle.
 
 loadLineForOperation ($id, $lineid)
 Load the complete line after checking its parent and ownership.
 
 _cleanObjectDatas ($object)
 Clean sensible object datas @phpstan-template T.
 
- Protected Member Functions inherited from DolibarrApi
 _checkValForAPI ($field, $value, $object)
 Check and convert a string depending on its type/name.
 
 _checkValExtrafieldsForAPI ($field, $value, $object)
 Check and convert a string depending on its type/name.
 
 _filterObjectProperties ($object, $properties)
 Filter properties that will be returned on object.
 
 _checkFilters ($sqlfilters, &$error='')
 Return if a $sqlfilters parameter is valid Function no more used.
 

Private Member Functions

 _validate ($data)
 Validate fields before create or update object.
 

Additional Inherited Members

- Static Protected Member Functions inherited from DolibarrApi
static _checkAccessToResource ($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $parenttableforentity='')
 Check access by user to a given resource.
 
static _forge_criteria_callback ($matches)
 Function to forge a SQL criteria from a Generic filter string.
 

Detailed Description

Definition at line 35 of file api_supplier_orders.class.php.

Member Function Documentation

◆ _cleanObjectDatas()

SupplierOrders::_cleanObjectDatas ( $object)
protected

Clean sensible object datas @phpstan-template T.

Parameters
Object$objectObject to clean
Returns
Object Object with cleaned properties @phpstan-param T $object @phpstan-return T

Reimplemented from DolibarrApi.

Definition at line 1292 of file api_supplier_orders.class.php.

References $object.

Referenced by get(), getLine(), index(), and putLine().

◆ _validate()

SupplierOrders::_validate ( $data)
private

Validate fields before create or update object.

Parameters
?array<string,string>$data Data to validate
Returns
array<string,string>
Exceptions
RestException

Definition at line 1314 of file api_supplier_orders.class.php.

Referenced by post().

◆ approve()

SupplierOrders::approve ( $id,
$idwarehouse = 0,
$secondlevel = 0 )

Approve an order.

Since
15.0.0 Initial implementation
Parameters
int$idOrder ID
int$idwarehouseWarehouse ID
int$secondlevel1=Does not execute triggers, 0= execute triggers

@url POST {id}/approve

Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}

FIXME An error 403 is returned if the request has an empty body. Error message: "Forbidden: Content type `text/plain` is not supported." Workaround: send this in the body { "idwarehouse": 0, "secondlevel": 0 }

Definition at line 979 of file api_supplier_orders.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ cancel()

SupplierOrders::cancel ( $id,
$comment = '' )

Cancel an approved order that has not been sent to the vendor yet.

Since
25.0.0 Initial implementation
Parameters
int$idOrder ID
string$commentReason of the cancellation, added to the agenda event {@required false}

@url POST {id}/cancel

Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}
Exceptions
RestException403 Not allowed
RestException404 Not found
RestException405 Order is not approved
RestException500 Error

FIXME An error 403 is returned if the request has an empty body. Error message: "Forbidden: Content type `text/plain` is not supported." Workaround: send this in the body { "comment": "" }

Definition at line 1153 of file api_supplier_orders.class.php.

References $id, DolibarrApi\_checkAccessToResource(), and CommandeFournisseur\STATUS_ACCEPTED.

◆ delete()

SupplierOrders::delete ( $id)

Delete supplier order.

Since
6.0.0 Initial implementation
Parameters
int$idSupplier order ID
Returns
array Array of result @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}

Definition at line 811 of file api_supplier_orders.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ deleteContact()

SupplierOrders::deleteContact ( $id,
$contactid,
$type,
$source )

Unlink a contact type of given supplier order.

Since
18.0.0 Initial implementation
Parameters
int$idId of supplier order to update
int$contactidId of contact/user to add
string$typeType of the contact (BILLING, SHIPPING, CUSTOMER, SALESREPFOLL, ...).
string$sourceSource of the contact (internal, external).

@url DELETE {id}/contact/{contactid}/{type}/{source}

Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}
Exceptions
RestException401
RestException404
RestException500 System error

Definition at line 758 of file api_supplier_orders.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ deleteLine()

SupplierOrders::deleteLine ( $id,
$lineid )

Deletes a line of a given draft supplier order.

A line that has already been received cannot be deleted.

Since
25.0.0 Initial implementation
Parameters
int$idId of supplier order
int$lineidId of the line to delete

@url DELETE {id}/lines/{lineid}

Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}
Exceptions
RestException400 Bad parameters
RestException403 Not allowed
RestException404 Not found
RestException405 Error

Definition at line 521 of file api_supplier_orders.class.php.

References $id, loadLineForOperation(), and CommandeFournisseur\STATUS_DRAFT.

◆ get()

SupplierOrders::get ( $id)

Get properties of a supplier order object.

Return an array with supplier order information

Since
6.0.0 Initial implementation
Parameters
int$idID of supplier order
Returns
array|mixed data without useless information
Exceptions
RestException

Definition at line 71 of file api_supplier_orders.class.php.

References $id, DolibarrApi\_checkAccessToResource(), and _cleanObjectDatas().

◆ getContacts()

SupplierOrders::getContacts ( $id,
$source,
$type = '' )

Get contacts of given supplier order.

Return an array with contact information

Since
18.0.0 Initial implementation
Parameters
int$idID of supplier order
string$sourceSource of the contact (internal, external, all).
string$typeType of the contact (BILLING, SHIPPING, CUSTOMER, SALESREPFOLL, ...)
Returns
array<int,mixed> Array of contacts

@url GET {id}/contacts

Exceptions
RestException

Definition at line 658 of file api_supplier_orders.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ getLine()

SupplierOrders::getLine ( $id,
$lineid )

Get one supplier order line after checking access to its parent.

Since
25.0.0 Initial implementation
Parameters
int$idSupplier order ID
int$lineidLine ID
Returns
CommandeFournisseurLigne Order line @url GET {id}/lines/{lineid}

Definition at line 434 of file api_supplier_orders.class.php.

References $id, _cleanObjectDatas(), and loadLineForOperation().

◆ index()

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

List orders.

Get a list of supplier orders

Since
6.0.0 Initial implementation
12.0.0 Added product_ids parameter
19.0.0 Added sqlfilterlines and properties parameters
21.0.0 Added pagination_data parameter
Parameters
string$sortfieldSort field
string$sortorderSort order
int$limitLimit for list
int$pagePage number
string$thirdparty_idsThirdparty ids to filter orders of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i}
string$product_idsProduct ids to filter orders of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i}
string$statusFilter by order status : draft | validated | approved | running | received_start | received_end | cancelled | refused
string$sqlfiltersOther criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'20160101')"
string$sqlfilterlinesOther criteria to filter answers separated by a comma. Syntax example "(tl.fk_product:=:'17') and (tl.price:<:'250')"
string$propertiesRestrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
bool$pagination_dataIf this parameter is set to true the response will include pagination data. Default value is false. Page starts from 0*
Returns
array Array of order objects @phan-return CommandeFournisseur[]|array{data:CommandeFournisseur[],pagination:array{total:int,page:int,page_count:int,limit:int}} @phpstan-return CommandeFournisseur[]|array{data:CommandeFournisseur[],pagination:array{total:int,page:int,page_count:int,limit:int}}
Exceptions
RestException

Definition at line 117 of file api_supplier_orders.class.php.

References _cleanObjectDatas(), DolibarrApi\_filterObjectProperties(), and forgeSQLFromUniversalSearchCriteria().

◆ loadLineForOperation()

SupplierOrders::loadLineForOperation ( $id,
$lineid )
protected

Load the complete line after checking its parent and ownership.

Parameters
int$idSupplier order ID
int$lineidLine ID
Returns
CommandeFournisseurLigne Order line

Definition at line 631 of file api_supplier_orders.class.php.

References $id, and loadOrderForOperation().

Referenced by deleteLine(), getLine(), and putLine().

◆ loadOrderForOperation()

SupplierOrders::loadOrderForOperation ( $id)
protected

Load an authorised order without sanitising its live database handle.

Parameters
int$idSupplier order ID
Returns
void

Definition at line 611 of file api_supplier_orders.class.php.

References $id.

Referenced by loadLineForOperation().

◆ makeOrder()

SupplierOrders::makeOrder ( $id,
$date,
$method,
$comment = '' )

Sends an order to the vendor.

Since
15.0.0 Initial implementation
Parameters
int$idOrder ID
integer$dateDate (unix timestamp in sec)
int$methodMethod
string$commentComment

@url POST {id}/makeorder

Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}

FIXME An error 403 is returned if the request has an empty body. Error message: "Forbidden: Content type `text/plain` is not supported." Workaround: send this in the body { "date": 0, "method": 0, "comment": "" }

Definition at line 1097 of file api_supplier_orders.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ post()

SupplierOrders::post ( $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"}

Since
6.0.0 Initial implementation
Parameters
array$request_dataRequest data @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
int ID of supplier order

Definition at line 265 of file api_supplier_orders.class.php.

References DolibarrApi\_checkValForAPI(), _validate(), dol_now(), and sanitizeVal().

◆ postContact()

SupplierOrders::postContact ( $id,
$contactid,
$type,
$source )

Add a contact type of given supplier order.

Since
18.0.0 Initial implementation
Parameters
int$idId of supplier order to update
int$contactidId of contact/user to add
string$typeType of the contact (BILLING, SHIPPING, CUSTOMER, SALESREPFOLL, ...)
string$sourceSource of the contact (external, internal)
Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}

@url POST {id}/contact/{contactid}/{type}/{source}

Exceptions
RestException401
RestException404

Definition at line 705 of file api_supplier_orders.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ postLine()

SupplierOrders::postLine ( $id,
$request_data = null )

Add a line to a given supplier order.

Since
23.0.0 Initial implementation
Parameters
int$idId of order to update
array$request_dataOrderLine data @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data

@url POST {id}/lines

Returns
int

Definition at line 371 of file api_supplier_orders.class.php.

References $id, DolibarrApi\_checkAccessToResource(), and sanitizeVal().

◆ prepareLineUpdate()

SupplierOrders::prepareLineUpdate ( $line,
$request_data )
protected

Prepare a partial update without changing the original line or writing data.

Parameters
CommandeFournisseurLigne$lineCurrent line
array<string,mixed>|null$request_data Fields to change
Returns
CommandeFournisseurLigne Prepared line

Definition at line 558 of file api_supplier_orders.class.php.

References DolibarrApi\_checkValExtrafieldsForAPI(), and DolibarrApi\_checkValForAPI().

Referenced by putLine().

◆ put()

SupplierOrders::put ( $id,
$request_data = null )

Update supplier order.

Since
6.0.0 Initial implementation
Parameters
int$idId of supplier order to update
array$request_dataData @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
Object|false Updated object

Definition at line 316 of file api_supplier_orders.class.php.

References $id, DolibarrApi\_checkAccessToResource(), DolibarrApi\_checkValExtrafieldsForAPI(), DolibarrApi\_checkValForAPI(), and sanitizeVal().

◆ putLine()

SupplierOrders::putLine ( $id,
$lineid,
$request_data = null )

Update selected fields of a draft supplier order line.

Omitted fields keep their current value. Dates are Unix timestamps or null. Give only one price, in company currency (HT or TTC) or order currency (HT).

Since
25.0.0 Initial implementation
Parameters
int$idSupplier order ID
int$lineidLine ID
array$request_dataFields to change @phan-param ?array<string,mixed> $request_data @phpstan-param ?array<string,mixed> $request_data
Returns
CommandeFournisseurLigne Updated line @url PUT {id}/lines/{lineid}

Definition at line 457 of file api_supplier_orders.class.php.

References $id, _cleanObjectDatas(), loadLineForOperation(), prepareLineUpdate(), and CommandeFournisseur\STATUS_DRAFT.

◆ receiveOrder()

SupplierOrders::receiveOrder ( $id,
$closeopenorder,
$comment,
$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 }] }

Since
15.0.0 Initial implementation
Parameters
int$idOrder ID
integer$closeopenorderClose order if everything is received {@required false}
string$commentComment {@required false}
array$linesArray of product dispatches @phan-param array<array{fk_product:string,qty:string,warehouse:string,price:string,comment:string,eatby:string,sellby:string,batch:string,id:string,notrigger:string}> $lines @phpstan-param array<array{fk_product:string,qty:string,warehouse:string,price:string,comment:string,eatby:string,sellby:string,batch:string,id:string,notrigger:string}> $lines

@url POST {id}/receive

Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}

FIXME An error 403 is returned if the request has an empty body. Error message: "Forbidden: Content type `text/plain` is not supported."

Definition at line 1229 of file api_supplier_orders.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ refuse()

SupplierOrders::refuse ( $id,
$comment = '' )

Refuse a validated order that is waiting for approval.

Since
25.0.0 Initial implementation
Parameters
int$idOrder ID
string$commentReason of the refusal, added to the agenda event {@required false}

@url POST {id}/refuse

Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}
Exceptions
RestException403 Not allowed
RestException404 Not found
RestException405 Order is not waiting for approval
RestException500 Error

FIXME An error 403 is returned if the request has an empty body. Error message: "Forbidden: Content type `text/plain` is not supported." Workaround: send this in the body { "comment": "" }

Definition at line 1035 of file api_supplier_orders.class.php.

References $id, DolibarrApi\_checkAccessToResource(), and CommandeFournisseur\STATUS_VALIDATED.

◆ settodraft()

SupplierOrders::settodraft ( $id)

Set a validated or approved order back to draft.

Since
25.0.0 Initial implementation
Parameters
int$idOrder ID

@url POST {id}/settodraft

Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}
Exceptions
RestException403 Not allowed
RestException404 Not found
RestException405 Order is not validated or approved
RestException500 Error

Definition at line 909 of file api_supplier_orders.class.php.

References $id, DolibarrApi\_checkAccessToResource(), getDolGlobalString(), CommandeFournisseur\STATUS_ACCEPTED, and CommandeFournisseur\STATUS_VALIDATED.

◆ validate()

SupplierOrders::validate ( $id,
$idwarehouse = 0,
$notrigger = 0 )

Validate an order.

Since
6.0.0 Initial implementation
Parameters
int$idOrder ID
int$idwarehouseWarehouse ID
int$notrigger1=Does not execute triggers, 0= execute triggers

@url POST {id}/validate

Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}

FIXME An error 403 is returned if the request has an empty body. Error message: "Forbidden: Content type `text/plain` is not supported." Workaround: send this in the body { "idwarehouse": 0, "notrigger": 0 }

Definition at line 861 of file api_supplier_orders.class.php.

References $id, and DolibarrApi\_checkAccessToResource().


The documentation for this class was generated from the following file: