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

Public Member Functions

 __construct ()
 Constructor.
 
 get ($id)
 Get properties of a shipment object.
 
 index ($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $sqlfilters='', $properties='', $pagination_data=false)
 List shipments.
 
 post ($request_data=null)
 Create shipment object.
 
 getLines ($id)
 Get lines of a shipment.
 
 postLine ($id, $fk_origin_line=0, $qty=0, $warehouse_id=0, $fk_product=0)
 Add a line to a given shipment.
 
 putLine ($id, $lineid, $qty=0, $warehouse_id=0)
 Update a line of a given shipment.
 
 deleteLine ($id, $lineid)
 Delete a line of a given shipment.
 
 put ($id, $request_data=null)
 Update shipment general fields (won't touch lines of shipment)
 
 delete ($id)
 Delete shipment.
 
 validate ($id, $notrigger=0)
 Validate a shipment.
 
 close ($id, $notrigger=0)
 Classify the shipment as invoiced.
 
 setToDraft ($id)
 Set a shipment back to draft status.
 
- Public Member Functions inherited from DolibarrApi
 __construct ($db, $cachedir='', $refreshCache=false)
 Constructor.
 

Protected Member Functions

 _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 34 of file api_shipments.class.php.

Member Function Documentation

◆ _cleanObjectDatas()

Shipments::_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 843 of file api_shipments.class.php.

References $object.

Referenced by close(), get(), getLines(), index(), setToDraft(), and validate().

◆ _validate()

Shipments::_validate ( $data)
private

Validate fields before create or update object.

Parameters
?array<string,string>$data Array with data to verify
Returns
array<string,string>
Exceptions
RestException

Definition at line 889 of file api_shipments.class.php.

References getDolGlobalString().

Referenced by post().

◆ close()

Shipments::close ( $id,
$notrigger = 0 )

Classify the shipment as invoiced.

Parameters
int$idId of the shipment

@url POST {id}/setinvoiced

Returns
int
Exceptions
RestException400
RestException401
RestException404
RestException405 Create a shipment using an existing order.
Parameters
int$orderidId of the order

@url POST /createfromorder/{orderid}

Returns
int
Exceptions
RestException400
RestException401
RestException404
RestException405 Close a shipment (Classify it as "Delivered")
Parameters
int$idExpedition ID
int$notriggerDisabled triggers

@url POST {id}/close

Returns
object

Definition at line 754 of file api_shipments.class.php.

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

◆ delete()

Shipments::delete ( $id)

Delete shipment.

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

Definition at line 587 of file api_shipments.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ deleteLine()

Shipments::deleteLine ( $id,
$lineid )

Delete a line of a given shipment.

A line can only be deleted while the shipment is still a draft: once validated the stock has already been moved, so removing the line would desync the stock.

Parameters
int$idId of shipment to update
int$lineidId of line to delete

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

Returns
Object Updated shipment
Exceptions
RestException403
RestException404
RestException405
RestException500

Definition at line 492 of file api_shipments.class.php.

References $id, DolibarrApi\_checkAccessToResource(), and Expedition\STATUS_DRAFT.

◆ get()

Shipments::get ( $id)

Get properties of a shipment object.

Return an array with shipment information

Parameters
int$idID of shipment
Returns
Object Object with cleaned properties
Exceptions
RestException

Definition at line 70 of file api_shipments.class.php.

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

◆ getLines()

Shipments::getLines ( $id)

Get lines of a shipment.

Parameters
int$idId of shipment

@url GET {id}/lines

Returns
array @phan-return ExpeditionLigne[] @phpstan-return ExpeditionLigne[]

Definition at line 284 of file api_shipments.class.php.

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

◆ index()

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

List shipments.

Get a list of shipments

Parameters
string$sortfieldSort field
string$sortorderSort order
int$limitLimit for list
int$pagePage number
string$thirdparty_idsThirdparty ids to filter shipments of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i}
string$sqlfiltersOther criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:>:'20160101')"
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 shipment objects @phan-return Expedition[] @phpstan-return Expedition[]
Exceptions
RestException

Definition at line 110 of file api_shipments.class.php.

References $object, _cleanObjectDatas(), DolibarrApi\_filterObjectProperties(), dol_syslog(), and forgeSQLFromUniversalSearchCriteria().

◆ post()

Shipments::post ( $request_data = null)

Create shipment object.

Parameters
array$request_dataRequest data @phan-param ?array<string,string|array<string,string|array<string,string>>> $request_data @phpstan-param ?array<string,string|array<string,string|array<string,string>>> $request_data
Returns
int ID of shipment created

Definition at line 223 of file api_shipments.class.php.

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

◆ postLine()

Shipments::postLine ( $id,
$fk_origin_line = 0,
$qty = 0,
$warehouse_id = 0,
$fk_product = 0 )

Add a line to a given shipment.

A shipment line always references the order line it ships (fk_origin_line): the shipped quantity relates to that order line. A line can only be added while the shipment is still a draft, before any stock movement. Lines managed by lot/serial (batch) are not supported here (the quantity is split by lot in expeditiondet_batch) - use the dedicated dispatch flow instead.

Parameters
int$idId of shipment to update
int$fk_origin_lineId of the order line shipped by this line {@from body}{@required true}
float$qtyQuantity to ship for this line {@from body}{@required true}{@min 1}
int$warehouse_idSource warehouse id (may be optional depending on STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS) {@from body}{@required false}
int$fk_productProduct id (optional, defaults to the order line product) {@from body}{@required false}

@url POST {id}/lines

Returns
int Id of the created shipment line
Exceptions
RestException400
RestException403
RestException404
RestException405
RestException500

Definition at line 331 of file api_shipments.class.php.

References $id, DolibarrApi\_checkAccessToResource(), isModEnabled(), and Expedition\STATUS_DRAFT.

◆ put()

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

Update shipment general fields (won't touch lines of shipment)

Parameters
int$idId of shipment to update
array$request_dataData @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
Object Updated object

Definition at line 538 of file api_shipments.class.php.

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

◆ putLine()

Shipments::putLine ( $id,
$lineid,
$qty = 0,
$warehouse_id = 0 )

Update a line of a given shipment.

Only the quantity (and optionally the source warehouse) of the line can be changed, and only while the shipment is still a draft: once validated the stock has already been moved, so editing the line would desync the stock. Lines managed by lot/serial (batch) are not supported here (the quantity is split by lot in expeditiondet_batch) - delete the line and create it again.

Parameters
int$idId of shipment to update
int$lineidId of line to update
float$qtyNew quantity to ship for this line {@from body}{@required true}{@min 1}
int$warehouse_idSource warehouse id for this line (optional, 0 to keep the current one) {@from body}{@required false}

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

Returns
Object Updated shipment
Exceptions
RestException400
RestException403
RestException404
RestException405
RestException500

Definition at line 419 of file api_shipments.class.php.

References $id, DolibarrApi\_checkAccessToResource(), and Expedition\STATUS_DRAFT.

◆ setToDraft()

Shipments::setToDraft ( $id)

Set a shipment back to draft status.

This reverts a validated shipment to draft. If stock movements were recorded at validation, they are cancelled back accordingly by the native method.

Parameters
int$idShipment ID

@url POST {id}/settodraft

Returns
object
Exceptions
RestException304
RestException403
RestException404
RestException500

Definition at line 802 of file api_shipments.class.php.

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

◆ validate()

Shipments::validate ( $id,
$notrigger = 0 )

Validate a shipment.

This may record stock movements if module stock is enabled and option to decrease stock on shipment is on.

Parameters
int$idShipment ID
int$notrigger1=Does not execute triggers, 0= execute triggers

@url POST {id}/validate

Returns
object

Definition at line 632 of file api_shipments.class.php.

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


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