class BankAccounts extends DolibarrApi (View source)

API class for accounts

Properties

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

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
index(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, int $category = 0, string $sqlfilters = '', string $properties = '')

Get the list of accounts.

object
get(int $id)

Get account by ID.

int
post(array $request_data = null)

Create account object

array
transfer(int $bankaccount_from_id = 0, int $bankaccount_to_id = 0, string $date = null, string $description = "", float $amount = 0.0, float $amount_to = 0.0, string $cheque_number = "")

Create an internal wire transfer between two bank accounts

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

Update account

array
delete(int $id)

Delete account

array
getLines(int $id, string $sqlfilters = '')

Get the list of lines of the account.

int
addLine(int $id, string $date, string $type, string $label, float $amount, int $category = 0, string $cheque_number = '', string $cheque_writer = '', string $cheque_bank = '', string $accountancycode = '', string $datev = null, string $num_releve = '')

Add a line to an account

int
addLink(int $id, int $line_id, int $url_id, string $url, string $label, string $type)

Add a link to an account line

array
getLinks(int $id, int $line_id)

Get the list of links for a line of the account.

array|mixed
getDetailAccountLine(int $line_id)

Get the detail of a given line of the bank account.

int
updateLine(int $id, int $line_id, string $label)

Update an account line

array
deleteLine(int $id, int $line_id)

Delete an account line

float
getBalance(int $id)

Get the current account balance

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 index(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, int $category = 0, string $sqlfilters = '', string $properties = '')

Get the list of accounts.

Parameters

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

Limit for list

int $page

Page number

int $category

Use this param to filter list by category

string $sqlfilters

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

string $properties

Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names

Return Value

array

List of account objects

Exceptions

RestException

object get(int $id)

Get account by ID.

Parameters

int $id

ID of account

Return Value

object

Object with cleaned properties

Exceptions

RestException

int post(array $request_data = null)

Create account object

Parameters

array $request_data

Request data

Return Value

int

ID of account

array transfer(int $bankaccount_from_id = 0, int $bankaccount_to_id = 0, string $date = null, string $description = "", float $amount = 0.0, float $amount_to = 0.0, string $cheque_number = "")

Create an internal wire transfer between two bank accounts

Parameters

int $bankaccount_from_id

BankAccount ID to use as the source of the internal wire transfer {@from body}{@required true}

int $bankaccount_to_id

BankAccount ID to use as the destination of the internal wire transfer {@from body}{@required true}

string $date

Date of the internal wire transfer (UNIX timestamp) {@from body}{@required true}{@type timestamp}

string $description

Description of the internal wire transfer {@from body}{@required true}

float $amount

Amount to transfer from the source to the destination BankAccount {@from body}{@required true}

float $amount_to

Amount to transfer to the destination BankAccount (only when accounts does not share the same currency) {@from body}{@required false}

string $cheque_number

Cheque numero {@from body}{@required false}

Return Value

array

Exceptions

RestException
RestException
RestException
RestException

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

Update account

Parameters

int $id

ID of account

array $request_data data

Return Value

object

Object with cleaned properties

array delete(int $id)

Delete account

Parameters

int $id

ID of account

Return Value

array

array getLines(int $id, string $sqlfilters = '')

Get the list of lines of the account.

Parameters

int $id

ID of account

string $sqlfilters

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

Return Value

array

Array of AccountLine objects

Exceptions

RestException

int addLine(int $id, string $date, string $type, string $label, float $amount, int $category = 0, string $cheque_number = '', string $cheque_writer = '', string $cheque_bank = '', string $accountancycode = '', string $datev = null, string $num_releve = '')

Add a line to an account

Parameters

int $id

ID of account

string $date

Payment date (timestamp) {@from body} {@type timestamp}

string $type

Payment mode (TYP,VIR,PRE,LIQ,VAD,CB,CHQ...) {@from body}

string $label

Label {@from body}

float $amount

Amount (may be 0) {@from body}

int $category Category
string $cheque_number

Cheque numero {@from body}

string $cheque_writer

Name of cheque writer {@from body}

string $cheque_bank

Bank of cheque writer {@from body}

string $accountancycode

Accountancy code {@from body}

string $datev

Payment date value (timestamp) {@from body} {@type timestamp}

string $num_releve

Bank statement numero {@from body}

Return Value

int

ID of line

Add a link to an account line

Parameters

int $id

ID of account

int $line_id

ID of account line

int $url_id

ID to set in the URL {@from body}

string $url

URL of the link {@from body}

string $label

Label {@from body}

string $type

Type of link ('payment', 'company', 'member', ...) {@from body}

Return Value

int

ID of link

Get the list of links for a line of the account.

Parameters

int $id

ID of account

int $line_id

ID of account line

Return Value

array

Array of links

Exceptions

RestException

array|mixed getDetailAccountLine(int $line_id)

Get the detail of a given line of the bank account.

Parameters

int $line_id

ID of the account line

Return Value

array|mixed

Data without useless information. Note: If we use here AccountLine as return type, we got error if xdebug is on, due to infinite loop parsing of doc by Restler, we can disable this we commenting line 228 to 323 in CommonObject)

Exceptions

RestException

int updateLine(int $id, int $line_id, string $label)

Update an account line

Parameters

int $id

ID of account

int $line_id

ID of account line

string $label

Label {@from body}

Return Value

int

ID of link

array deleteLine(int $id, int $line_id)

Delete an account line

Parameters

int $id

ID of account

int $line_id

ID of account line

Return Value

array

float getBalance(int $id)

Get the current account balance

Parameters

int $id

ID of account

Return Value

float

$balance balance

Exceptions

RestException