Since: 5.0.0 Initial implementation

class ExpenseReports extends DolibarrApi (View source)

API class for Expense Reports

Properties

protected DoliDB $db from  DolibarrApi
Restler $r from  DolibarrApi
static string[] $FIELDS
static string[] $FIELDSLINE
static string[] $FIELDSPAYMENT
ExpenseReport $expensereport

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 an expense report

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

List expense reports

int
post(array $request_data = null)

Create an expense report

array
getLines(int $id)

Get lines of an expense report

int
postLine(int $id, array $request_data = null)

Add a line to an expense report

object|false
putLine(int $id, int $lineid, array $request_data = null)

Update a line of an expense report

object
deleteLine(int $id, int $lineid)

Delete a line from an expense report

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

Update expense report general fields

array
delete(int $id)

Delete expense report

object
setToDraft(int $id)

Set an expense report to draft

object
validate(int $id, int $notrigger = 0)

Validate an expense report

object
approve(int $id, int $notrigger = 0)

Approve an expense report

object
deny(int $id, string $details, int $notrigger = 0)

Deny an expense report

object
cancel(int $id, string $detail, int $notrigger = 0)

Cancel an expense report

array
getAllPayments(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0)

Get the list of payments of an expense report

object
getPayments(int $pid)

Get an expense report payment

int
addPayment(int $id, array $request_data = null)

Create a payment for an expense report

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

Update a payment of an expense report

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: 5.0.0 Initial implementation

Get an expense report

Return an array with Expense Report information

Parameters

int $id

ID of Expense Report

Return Value

object

Object with cleaned properties

Exceptions

RestException

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

Since: 5.0.0 Initial implementation

List expense reports

Get a list of Expense Reports

Parameters

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

List limit

int $page

Page number

string $user_ids

User ids filter field. Example: '1' or '1,2,3' {@pattern /^[0-9,]*$/i}

string $sqlfilters

Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'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 order objects

Exceptions

RestException

int post(array $request_data = null)

Since: 5.0.0 Initial implementation

Create an expense report

Parameters

array $request_data

Request data

Return Value

int

ID of Expense Report

Exceptions

RestException

array getLines(int $id)

Since: 23.0.0 Initial implementation

Get lines of an expense report

Parameters

int $id

ID of the expense report

Return Value

array

Exceptions

RestException
RestException

int postLine(int $id, array $request_data = null)

Since: 23.0.0 Initial implementation

Add a line to an expense report

Parameters

int $id

ID of the expense report to update

array $request_data

Expense Report line data

Return Value

int

Exceptions

RestException

object|false putLine(int $id, int $lineid, array $request_data = null)

Since: 23.0.0 Initial implementation

Update a line of an expense report

Parameters

int $id

ID of the expense report

int $lineid

ID of the line to update

array $request_data

Expense Report data

Return Value

object|false

Object with cleaned properties

Exceptions

RestException
RestException
RestException

object deleteLine(int $id, int $lineid)

Since: 23.0.0 Initial implementation

Delete a line from an expense report

Parameters

int $id

ID of the expense report to update

int $lineid

ID of line to delete

Return Value

object

Exceptions

RestException
RestException
RestException

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

Since: 5.0.0 Initial implementation

Update expense report general fields

Does not touch lines of the expense report

Parameters

int $id

ID of Expense Report to update

array $request_data

Expense report data

Return Value

object

Updated object

Exceptions

RestException
RestException
RestException

array delete(int $id)

Since: 5.0.0 Initial implementation

Delete expense report

Parameters

int $id

Expense Report ID

Return Value

array

Exceptions

RestException

object setToDraft(int $id)

Since: 23.0.0 Initial implementation

Set an expense report to draft

Parameters

int $id

Expense report ID

Return Value

object

Exceptions

RestException
RestException
RestException

object validate(int $id, int $notrigger = 0)

Since: 22.0.0 Initial implementation

Validate an expense report

If you get a bad value for param notrigger check, provide this in body { "notrigger": 0 }

Parameters

int $id

Expense report ID

int $notrigger

1=Does not execute triggers, 0= execute triggers

Return Value

object

Exceptions

RestException

object approve(int $id, int $notrigger = 0)

Since: 22.0.0 Initial implementation

Approve an expense report

If you get a bad value for param notrigger check, provide this in body { "notrigger": 0 }

Parameters

int $id

Expense report ID

int $notrigger

1=Does not execute triggers, 0= execute triggers

Return Value

object

Exceptions

RestException

object deny(int $id, string $details, int $notrigger = 0)

Since: 22.0.0 Initial implementation

Deny an expense report

If you get a bad value for param notrigger check, provide this in body { "notrigger": 0 }

Parameters

int $id

Expense report ID

string $details

Comments for denial

int $notrigger

1=Does not execute triggers, 0= execute triggers

Return Value

object

Exceptions

RestException

object cancel(int $id, string $detail, int $notrigger = 0)

Since: 23.0.0 Initial implementation

Cancel an expense report

Parameters

int $id

ID of the expense report

string $detail

Comments for cancellation

int $notrigger

1=Does not execute triggers, 0= execute triggers

Return Value

object

Exceptions

RestException
RestException
RestException

array getAllPayments(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0)

Since: 20.0.0 Initial implementation

Get the list of payments of an expense report

Parameters

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

List limit

int $page

Page number

Return Value

array

List of paymentExpenseReport objects

Exceptions

RestException

object getPayments(int $pid)

Since: 20.0.0 Initial implementation

Get an expense report payment

Parameters

int $pid

Payment ID

Return Value

object

PaymentExpenseReport object

Exceptions

RestException

int addPayment(int $id, array $request_data = null)

Since: 20.0.0 Initial implementation

Create a payment for an expense report

Parameters

int $id

ID of an expense report

array $request_data

{@from body} Request data

Return Value

int

ID of paymentExpenseReport

Exceptions

RestException

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

Since: 20.0.0 Initial implementation

Update a payment of an expense report

Parameters

int $id

ID of paymentExpenseReport

array $request_data data

Return Value

object

Exceptions

RestException