dolibarr 23.0.3
Contracts Class Reference
Inheritance diagram for Contracts:
Collaboration diagram for Contracts:

Public Member Functions

 __construct ()
 Constructor.
 
 get ($id, $properties='', $withLines=true)
 Get properties of a contract object.
 
 index ($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $sqlfilters='', $properties='', $pagination_data=false, $withLines=true)
 List contracts.
 
 post ($request_data=null)
 Create contract object.
 
 getLines ($id, $sortfield="d.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='', $pagination_data=false)
 Get lines of a contract.
 
 postLine ($id, $request_data=null)
 Add a line to given contract.
 
 putLine ($id, $lineid, $request_data=null)
 Update a line to given contract.
 
 activateLine ($id, $lineid, $datestart, $dateend=null, $comment=null)
 Activate a service line of a given contract.
 
 unactivateLine ($id, $lineid, $datestart, $comment=null)
 Unactivate a service line of a given contract.
 
 deleteLine ($id, $lineid)
 Delete a line to given contract.
 
 put ($id, $request_data=null)
 Update contract general fields (won't touch lines of contract)
 
 delete ($id)
 Delete contract.
 
 validate ($id, $notrigger=0)
 Validate a contract.
 
 close ($id, $notrigger=0)
 Close all services of a contract.
 
- 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.
 
 _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')
 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 32 of file api_contracts.class.php.

Member Function Documentation

◆ _cleanObjectDatas()

Contracts::_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 976 of file api_contracts.class.php.

References $object.

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

◆ _validate()

Contracts::_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
RestException400 Bad Request

Definition at line 995 of file api_contracts.class.php.

Referenced by post().

◆ activateLine()

Contracts::activateLine ( $id,
$lineid,
$datestart,
$dateend = null,
$comment = null )

Activate a service line of a given contract.

Parameters
int$idId of contract to activate
int$lineidId of line to activate
string$datestart{@from body} Date start {@type timestamp}
string$dateend{@from body} Date end {@type timestamp}
string$comment{@from body} Comment

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

Returns
Object|bool
Exceptions
RestException403 Access denied
RestException404 Not found

Definition at line 610 of file api_contracts.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ close()

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

Close all services of a contract.

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

@url POST {id}/close

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 { "notrigger": 0 }

Exceptions
RestException304 Not Modified
RestException403 Access denied
RestException404 Not found
RestException500 Error

Definition at line 931 of file api_contracts.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ delete()

Contracts::delete ( $id)

Delete contract.

Parameters
int$idContract ID
Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}
Exceptions
RestException400 Bad Request
RestException403 Access denied
RestException404 Not found
RestException500 Error

Definition at line 821 of file api_contracts.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ deleteLine()

Contracts::deleteLine ( $id,
$lineid )

Delete a line to given contract.

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

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

Returns
array|mixed
Exceptions
RestException401
RestException404

Definition at line 691 of file api_contracts.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ get()

Contracts::get ( $id,
$properties = '',
$withLines = true )

Get properties of a contract object.

Return an array with contract information

Parameters
int$idID of contract
string$propertiesRestrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
bool$withLinestrue or false to display or hide lines
Returns
Object Object with cleaned properties
Exceptions
RestException403 Access denied
RestException404 Not found
RestException503 Error

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

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

◆ getLines()

Contracts::getLines ( $id,
$sortfield = "d.rowid",
$sortorder = 'ASC',
$limit = 100,
$page = 0,
$sqlfilters = '',
$properties = '',
$pagination_data = false )

Get lines of a contract.

Parameters
int$idId of contract
string$sortfieldSort field
string$sortorderSort order
int$limitLimit for list
int$pagePage number
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 contrat det objects @phan-return ContratLigne[] @phpstan-return ContratLigne[]

@url GET {id}/lines

Exceptions
RestException404 Not Found
RestException503 Error

Definition at line 308 of file api_contracts.class.php.

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

◆ index()

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

List contracts.

Get a list of contracts

Parameters
string$sortfieldSort field
string$sortorderSort order
int$limitLimit for list
int$pagePage number
string$thirdparty_idsThirdparty ids to filter contracts 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*
bool$withLinestrue or false to display or hide lines
Returns
array Array of order objects @phan-return Contrat[]|array{data:Contrat[],pagination:array{total:int,page:int,page_count:int,limit:int}} @phpstan-return Contrat[]|array{data:Contrat[],pagination:array{total:int,page:int,page_count:int,limit:int}}
Exceptions
RestException400 Bad Request
RestException403 Access denied
RestException503 Error

Definition at line 119 of file api_contracts.class.php.

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

◆ post()

Contracts::post ( $request_data = null)

Create contract object.

Parameters
array$request_dataRequest data @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
int ID of contrat
Exceptions
RestException400 Bad Request
RestException403 Access denied
RestException404 Not found
RestException500 Error

Definition at line 230 of file api_contracts.class.php.

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

◆ postLine()

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

Add a line to given contract.

Parameters
int$idId of contrat to update
array$request_dataContractline data @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data

@url POST {id}/lines

Returns
int|bool

Definition at line 399 of file api_contracts.class.php.

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

◆ put()

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

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

Parameters
int$idId of contract to update
array$request_dataData @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
Object Updated object
Exceptions
RestException400 Bad Request
RestException403 Access denied
RestException404 Not found
RestException500 Error

Definition at line 730 of file api_contracts.class.php.

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

◆ putLine()

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

Update a line to given contract.

Parameters
int$idId of contrat to update
int$lineidId of line to update
array$request_dataContractline data @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data

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

Returns
Object|bool

Definition at line 459 of file api_contracts.class.php.

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

◆ unactivateLine()

Contracts::unactivateLine ( $id,
$lineid,
$datestart,
$comment = null )

Unactivate a service line of a given contract.

Parameters
int$idId of contract to activate
int$lineidId of line to activate
string$datestart{@from body} Date start {@type timestamp}
string$comment{@from body} Comment

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

Returns
Object|bool
Exceptions
RestException403 Access denied
RestException404 Not found

Definition at line 651 of file api_contracts.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ validate()

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

Validate a contract.

Parameters
int$idContract 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 { "notrigger": 0 }

Exceptions
RestException304 Not Modified
RestException403 Access denied
RestException404 Not found
RestException500 Error

Definition at line 874 of file api_contracts.class.php.

References $id, and DolibarrApi\_checkAccessToResource().


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