Since: 3.8.0 Initial implementation

class Thirdparties extends DolibarrApi (View source)

API class for thirdparties

Properties

protected DoliDB $db from  DolibarrApi
Restler $r from  DolibarrApi
static string[] $FIELDS
Societe $company

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 a third party

array|mixed
getByEmail(string $email)

Get properties of a third party by email.

array|mixed
getByBarcode(string $barcode)

Get a third party by barcode.

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

List third parties

int
post(array $request_data = null)

Create a third party

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

Update third party

object
merge(int $id, int $idtodelete)

Merge a third party into another third party

array
delete(int $id)

Delete a third party

object
setThirdpartyPriceLevel(int $id, int $priceLevel)

Set a new price level for the given third party

int
addRepresentative(int $id, int $representative_id)

Add a customer representative to a third party

int
deleteRepresentative(int $id, int $representative_id)

Remove the link between a customer representative and a third party

array
getCategories(int $id, string $sortfield = "s.rowid", string $sortorder = 'ASC', int $limit = 0, int $page = 0)

Get customer categories for a third party

object
addCategory(int $id, int $category_id)

Add a customer category to a third party

object
deleteCategory(int $id, int $category_id)

Remove the link between a customer category and the third party

array
getSupplierCategories(int $id, string $sortfield = "s.rowid", string $sortorder = 'ASC', int $limit = 0, int $page = 0)

Get supplier categories for a third party

mixed
addSupplierCategory(int $id, int $category_id)

Add a supplier category to a third party

mixed
deleteSupplierCategory(int $id, int $category_id)

Remove the link between a category and the third party

array
getOutStandingProposals(int $id, string $mode = 'customer')

Get outstanding proposals for a third party

array
getOutStandingOrder(int $id, string $mode = 'customer')

Get outstanding orders for a third party

array
getOutStandingInvoices(int $id, string $mode = 'customer')

Get outstanding invoices for a third party

array
getSalesRepresentatives(int $id, int $mode = 0)

Get representatives of a third party

array
getFixedAmountDiscounts(int $id, string $mode = 'customer', string $filter = "none", string $sortfield = "f.type", string $sortorder = 'ASC')

Get fixed amount discount of a third party

array
splitdiscount(int $id, int $discountid, float $amount_ttc_1, float $amount_ttc_2)

Split a discount in 2 smaller discount

array
getInvoicesQualifiedForReplacement(int $id)

Return invoices qualified to be replaced by another invoice

array
getInvoicesQualifiedForCreditNote(int $id)

Return invoices qualified to be corrected by a credit note

array
getCompanyNotification(int $id)

Get company notifications for a third party

array|mixed
createCompanyNotification(int $id, array $request_data = null)

Create a company notification for a third party

array|mixed
createCompanyNotificationByCode(int $id, string $code, array $request_data = null)

Create a company notification for a third party using action trigger code

int
deleteCompanyNotification(int $id, int $notification_id)

Delete a company notification attached to a third party

array|mixed
updateCompanyNotification(int $id, int $notification_id, array $request_data = null)

Update a company notification for a third party

array
getCompanyBankAccount(int $id)

Get company bank accounts of a third party

array|mixed
createCompanyBankAccount(int $id, array $request_data = null)

Create a company bank account for a third party

array|mixed
updateCompanyBankAccount(int $id, int $bankaccount_id, array $request_data = null)

Update a company bank account of a third party

int
deleteCompanyBankAccount(int $id, int $bankaccount_id)

Delete a bank account attached to a third party

array
generateBankAccountDocument(int $id, int $companybankid = null, string $model = 'sepamandate')

Generate a document from a bank account record

array|mixed
getSocieteAccounts(int $id, string $site = null)

Get a specific account attached to a third party

array|mixed
getSocieteByAccounts(string $site, string $key_account)

Get a specific third party by account

array|mixed
createSocieteAccount(int $id, array $request_data = null)

Create and attach a new account to an existing third party

array|mixed
postSocieteAccount(int $id, string $site, array $request_data = null)

Create and attach a new (or replace an existing) specific site account for a third party

array|mixed
putSocieteAccount(int $id, string $site, array $request_data = null)

Update specified values of a specific account attached to a third party

void
deleteSocieteAccount(int $id, string $site)

Delete a specific site account attached to a third party

void
deleteSocieteAccounts(int $id)

Delete all accounts attached to a third party

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)

Since: 3.8.0 Initial implementation

Get a third party

Return the third party object

Parameters

int $id

ID of the third party to load

Return Value

object

Object with cleaned properties

Exceptions

RestException

array|mixed getByEmail(string $email)

Since: 11.0.0 Initial implementation

Get properties of a third party by email.

Return an array with third party information

Parameters

string $email

Email of the third party to load

Return Value

array|mixed

Cleaned Societe object

Exceptions

RestException

array|mixed getByBarcode(string $barcode)

Since: 13.0.0 Initial implementation

Get a third party by barcode.

Return an array with third party information

Parameters

string $barcode

Barcode of the third party

Return Value

array|mixed

Cleaned Societe object

Exceptions

RestException

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

Since: 3.8.0 Initial implementation

List third parties

Get a list of third parties

Parameters

string $sortfield

S ort field

string $sortorder

Sort order

int $limit

List limit

int $page

Page number

int $mode

Set to 0 to show all third parties, Set to 1 to show only customers, 2 for prospects, 3 for neither customer or prospect, 4 for suppliers

int $category

Use this param to filter the list by category

string $sqlfilters

Other criteria to filter answers separated by a comma. Syntax example "((t.nom:like:'TheCompany%') or (t.name_alias:like:'TheCompany%')) 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 thirdparty objects

Exceptions

RestException

int post(array $request_data = null)

Since: 3.8.0 Initial implementation

Create a third party

Parameters

array $request_data

Request data

Return Value

int

ID of third party

Exceptions

RestException

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

Since: 3.8.0 Initial implementation

Update third party

Parameters

int $id

ID of thirdparty to update

array $request_data Data

Return Value

object

Updated object

Exceptions

RestException
RestException
RestException

object merge(int $id, int $idtodelete)

Since: 7.0.0 Initial implementation

Merge a third party into another third party

Merge content (properties, notes) and objects (like invoices, events, orders, proposals, ...) of a third party into a target third party, then delete the merged third party. If a property has a defined value both in the third party to delete and the third party to keep, the value of the third party to delete will be ignored, the value of the target third party will remain, except for notes (content is concatenated).

Parameters

int $id

ID of thirdparty to keep (the target third party)

int $idtodelete

ID of thirdparty to remove (the third party to delete), once data has been merged into the target third party.

Return Value

object

Return the resulted third party.

Exceptions

RestException

array delete(int $id)

Since: 3.8.0 Initial implementation

Delete a third party

Parameters

int $id

ID of the third party

Return Value

array

Exceptions

RestException

object setThirdpartyPriceLevel(int $id, int $priceLevel)

Since: 13.0.0 Initial implementation

Set a new price level for the given third party

Parameters

int $id

ID of thirdparty

int $priceLevel

Price level to apply to thirdparty

Return Value

object

Thirdparty data without useless information

Exceptions

RestException
RestException
RestException
RestException
RestException

int addRepresentative(int $id, int $representative_id)

Since: 20.0.0 Initial implementation

Add a customer representative to a third party

Parameters

int $id

ID of the third party

int $representative_id

ID of representative

Return Value

int

Return integer <=0 if KO, >0 if OK

Exceptions

RestException
RestException

int deleteRepresentative(int $id, int $representative_id)

Since: 20.0.0 Initial implementation

Remove the link between a customer representative and a third party

Parameters

int $id

ID of the third party

int $representative_id

ID of representative

Return Value

int

Return integer <=0 if KO, >0 if OK

Exceptions

RestException
RestException

array getCategories(int $id, string $sortfield = "s.rowid", string $sortorder = 'ASC', int $limit = 0, int $page = 0)

Since: 5.0.0 Initial implementation

Get customer categories for a third party

Parameters

int $id

ID of the third party

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

List limit

int $page

Page number

Return Value

array

Exceptions

RestException

object addCategory(int $id, int $category_id)

Since: 5.0.0 Initial implementation

Add a customer category to a third party

Parameters

int $id

ID of the third party

int $category_id

ID of category

Return Value

object

Exceptions

RestException

object deleteCategory(int $id, int $category_id)

Since: 7.0.0 Initial implementation

Remove the link between a customer category and the third party

Parameters

int $id

ID of the third party

int $category_id

ID of category

Return Value

object

Exceptions

RestException

array getSupplierCategories(int $id, string $sortfield = "s.rowid", string $sortorder = 'ASC', int $limit = 0, int $page = 0)

Since: 7.0.0 Initial implementation

Get supplier categories for a third party

Parameters

int $id

ID of the third party

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

List limit

int $page

Page number

Return Value

array

Exceptions

RestException

mixed addSupplierCategory(int $id, int $category_id)

Since: 7.0.0 Initial implementation

Add a supplier category to a third party

Parameters

int $id

ID of the third party

int $category_id

ID of category

Return Value

mixed

Exceptions

RestException

mixed deleteSupplierCategory(int $id, int $category_id)

Since: 7.0.0 Initial implementation

Remove the link between a category and the third party

Parameters

int $id

ID of the third party

int $category_id

ID of category

Return Value

mixed

Exceptions

RestException

array getOutStandingProposals(int $id, string $mode = 'customer')

Since: 7.0.0 Initial implementation

Get outstanding proposals for a third party

Parameters

int $id

ID of the third party

string $mode

'customer' or 'supplier'

Return Value

array

List of outstandings proposals of thirdparty

Exceptions

RestException
RestException
RestException

array getOutStandingOrder(int $id, string $mode = 'customer')

Since: 7.0.0 Initial implementation

Get outstanding orders for a third party

Parameters

int $id

ID of the third party

string $mode

'customer' or 'supplier'

Return Value

array

List of outstandings orders of the third party

Exceptions

RestException
RestException
RestException

array getOutStandingInvoices(int $id, string $mode = 'customer')

Since: 7.0.0 Initial implementation

Get outstanding invoices for a third party

Parameters

int $id

ID of the third party

string $mode

'customer' or 'supplier'

Return Value

array

List of outstanding invoices of the third party

Exceptions

RestException
RestException
RestException

array getSalesRepresentatives(int $id, int $mode = 0)

Since: 11.0.0 Initial implementation

Get representatives of a third party

Parameters

int $id

ID of the third party

int $mode

0=Array with properties, 1=Array of id.

Return Value

array

List of representatives of the third party

Exceptions

RestException
RestException
RestException

array getFixedAmountDiscounts(int $id, string $mode = 'customer', string $filter = "none", string $sortfield = "f.type", string $sortorder = 'ASC')

Since: 7.0.0 Initial implementation

Get fixed amount discount of a third party

all sources: deposit, credit note, commercial offers, etc.

Parameters

int $id

ID of the third party

string $mode

'customer' or 'supplier'

string $filter

Filter exceptional discount. "none" will return every discount, "available" returns unapplied discounts, "used" returns applied discounts {@choice none,available,used}

string $sortfield

Sort field

string $sortorder

Sort order

Return Value

array

List of fixed discount of the third party

Exceptions

RestException
RestException
RestException
RestException

array splitdiscount(int $id, int $discountid, float $amount_ttc_1, float $amount_ttc_2)

Split a discount in 2 smaller discount

Parameters

int $id

ID of the thirdparty

int $discountid

ID of a discount coming from a credit note

float $amount_ttc_1

Amount 1 (inc. tax)

float $amount_ttc_2

Amount 2 (inc. tax)

Return Value

array

List of fixed discount of the third party

Exceptions

RestException
RestException
RestException
RestException
RestException
RestException
RestException

array getInvoicesQualifiedForReplacement(int $id)

Since: 7.0.0 Initial implementation

Return invoices qualified to be replaced by another invoice

Parameters

int $id

ID of a third party

Return Value

array

Exceptions

RestException
RestException
RestException
RestException

array getInvoicesQualifiedForCreditNote(int $id)

Since: 7.0.0 Initial implementation

Return invoices qualified to be corrected by a credit note

Invoices matching the following rules are returned (validated + payment on process) or classified (paid completely or paid partially) + not already replaced + not already a credit note

Parameters

int $id

ID of a third party

Return Value

array

Exceptions

RestException
RestException
RestException
RestException

array getCompanyNotification(int $id)

Since: 20.0.0 Initial implementation

Get company notifications for a third party

Parameters

int $id

ID of the third party

Return Value

array

Exceptions

RestException

array|mixed createCompanyNotification(int $id, array $request_data = null)

Since: 20.0.0 Initial implementation

Create a company notification for a third party

Parameters

int $id

ID of the third party

array $request_data

Request data

Return Value

array|mixed

Notification of the third party

Exceptions

RestException

array|mixed createCompanyNotificationByCode(int $id, string $code, array $request_data = null)

Since: 21.0.0 Initial implementation

Create a company notification for a third party using action trigger code

Parameters

int $id

ID of the third party

string $code

Action Trigger code

array $request_data

Request data

Return Value

array|mixed

Notification for the third party

Exceptions

RestException

int deleteCompanyNotification(int $id, int $notification_id)

Since: 20.0.0 Initial implementation

Delete a company notification attached to a third party

Parameters

int $id

ID of the third party

int $notification_id

ID of CompanyNotification

Return Value

int

-1 if error, 1 if correct deletion

Exceptions

RestException

array|mixed updateCompanyNotification(int $id, int $notification_id, array $request_data = null)

Since: 20.0.0 Initial implementation

Update a company notification for a third party

Parameters

int $id

ID of the third party

int $notification_id

ID of CompanyNotification

array $request_data

Request data

Return Value

array|mixed

Notification for the third party

Exceptions

RestException

array getCompanyBankAccount(int $id)

Since: 9.0.0 Initial implementation

Get company bank accounts of a third party

Parameters

int $id

ID of the third party

Return Value

array

Exceptions

RestException

array|mixed createCompanyBankAccount(int $id, array $request_data = null)

Since: 9.0.0 Initial implementation

Create a company bank account for a third party

Parameters

int $id

ID of the third party

array $request_data

Request data

Return Value

array|mixed

BankAccount of the third party

Exceptions

RestException

array|mixed updateCompanyBankAccount(int $id, int $bankaccount_id, array $request_data = null)

Since: 9.0.0 Initial implementation

Update a company bank account of a third party

Parameters

int $id

ID of the third party

int $bankaccount_id

ID of CompanyBankAccount

array $request_data

Request data

Return Value

array|mixed

BankAccount of the third party

Exceptions

RestException

int deleteCompanyBankAccount(int $id, int $bankaccount_id)

Since: 9.0.0 Initial implementation

Delete a bank account attached to a third party

Parameters

int $id

ID of the third party

int $bankaccount_id

ID of CompanyBankAccount

Return Value

int

-1 if error, 1 if correct deletion

Exceptions

RestException

array generateBankAccountDocument(int $id, int $companybankid = null, string $model = 'sepamandate')

Since: 9.0.0 Initial implementation

Generate a document from a bank account record

Like SEPA mandate

Parameters

int $id

ID of the third party

int $companybankid

ID of company bank

string $model

Model of document to generate

Return Value

array

Exceptions

RestException

array|mixed getSocieteAccounts(int $id, string $site = null)

Since: 9.0.0 Initial implementation

Get a specific account attached to a third party

Specify the site key

Parameters

int $id

ID of the third party

string $site

Site key

Return Value

array|mixed

Exceptions

RestException
RestException

array|mixed getSocieteByAccounts(string $site, string $key_account)

Since: 21.0.0 Initial implementation

Get a specific third party by account

Parameters

string $site

Site key

string $key_account

Key of the account

Return Value

array|mixed

Exceptions

RestException
RestException
RestException

array|mixed createSocieteAccount(int $id, array $request_data = null)

Since: 9.0.0 Initial implementation

Create and attach a new account to an existing third party

Possible fields for request_data (request body) are specified in llx_societe_account table.
See Table llx_societe_account wiki page for more information

Example body payload :

{"key_account": "cus_DAVkLSs1LYyYI", "site": "stripe"}

Parameters

int $id

ID of the third party

array $request_data

Request data

Return Value

array|mixed

Exceptions

RestException
RestException
RestException
RestException

array|mixed postSocieteAccount(int $id, string $site, array $request_data = null)

Since: 9.0.0 Initial implementation

Create and attach a new (or replace an existing) specific site account for a third party

You MUST pass all values to keep (otherwise, they will be deleted) !
If you just need to update specific fields prefer PUT /thirdparties/{id}/accounts/{site} endpoint.

When a SocieteAccount entity does not exist for the id and site supplied, a new one will be created. In that case fk_soc and site members form request body payload will be ignored and id and site query strings parameters will be used instead.

Parameters

int $id

ID of the third party

string $site

Site key

array $request_data

Request data

Return Value

array|mixed

Exceptions

RestException
RestException
RestException

array|mixed putSocieteAccount(int $id, string $site, array $request_data = null)

Since: 9.0.0 Initial implementation

Update specified values of a specific account attached to a third party

Parameters

int $id

ID of the third party

string $site

Site key

array $request_data

Request data

Return Value

array|mixed

Exceptions

RestException
RestException
RestException
RestException

void deleteSocieteAccount(int $id, string $site)

Since: 9.0.0 Initial implementation

Delete a specific site account attached to a third party

by account id

Parameters

int $id

ID of the third party

string $site

Site key

Return Value

void

Exceptions

RestException
RestException
RestException

void deleteSocieteAccounts(int $id)

Since: 9.0.0 Initial implementation

Delete all accounts attached to a third party

Parameters

int $id

ID of the third party

Return Value

void

Exceptions

RestException
RestException
RestException