dolibarr  19.0.0-dev
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
Invoices Class Reference
Inheritance diagram for Invoices:
Inheritance graph
[legend]
Collaboration diagram for Invoices:
Collaboration graph
[legend]

Public Member Functions

 __construct ()
 Constructor.
 
 get ($id, $contact_list=1)
 Get properties of a invoice object. More...
 
 getByRef ($ref, $contact_list=1)
 Get properties of an invoice object by ref. More...
 
 getByRefExt ($ref_ext, $contact_list=1)
 Get properties of an invoice object by ref_ext. More...
 
 index ($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $status='', $sqlfilters='')
 List invoices. More...
 
 post ($request_data=null)
 Create invoice object. More...
 
 createInvoiceFromOrder ($orderid)
 Create an invoice using an existing order. More...
 
 getLines ($id)
 Get lines of an invoice. More...
 
 putLine ($id, $lineid, $request_data=null)
 Update a line to a given invoice. More...
 
 postContact ($id, $contactid, $type)
 Add a contact type of given invoice. More...
 
 deleteContact ($id, $contactid, $type)
 Delete a contact type of given invoice. More...
 
 deleteLine ($id, $lineid)
 Deletes a line of a given invoice. More...
 
 put ($id, $request_data=null)
 Update invoice. More...
 
 delete ($id)
 Delete invoice. More...
 
 postLine ($id, $request_data=null)
 Add a line to a given invoice. More...
 
 addContact ($id, $fk_socpeople, $type_contact, $source, $notrigger=0)
 Adds a contact to an invoice. More...
 
 settodraft ($id, $idwarehouse=-1)
 Sets an invoice as draft. More...
 
 validate ($id, $idwarehouse=0, $notrigger=0)
 Validate an invoice. More...
 
 settopaid ($id, $close_code='', $close_note='')
 Sets an invoice as paid. More...
 
 settounpaid ($id)
 Sets an invoice as unpaid. More...
 
 getDiscount ($id)
 Get discount from invoice. More...
 
 markAsCreditAvailable ($id)
 Create a discount (credit available) for a credit note or a deposit. More...
 
 useDiscount ($id, $discountid)
 Add a discount line into an invoice (as an invoice line) using an existing absolute discount. More...
 
 useCreditNote ($id, $discountid)
 Add an available credit note discount to payments of an existing invoice. More...
 
 getPayments ($id)
 Get list of payments of a given invoice. More...
 
 addPayment ($id, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment='', $comment='', $chqemetteur='', $chqbank='')
 Add payment line to a specific invoice with the remain to pay as amount. More...
 
 addPaymentDistributed ($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment='', $comment='', $chqemetteur='', $chqbank='', $ref_ext='', $accepthigherpayment=false)
 Add a payment to pay partially or completely one or several invoices. More...
 
 putPayment ($id, $num_payment='')
 Update a payment. More...
 
 getTemplateInvoice ($id, $contact_list=1)
 Get properties of a template invoice object. More...
 
- Public Member Functions inherited from DolibarrApi
 __construct ($db, $cachedir='', $refreshCache=false)
 Constructor. More...
 

Protected Member Functions

 _cleanObjectDatas ($object)
 Clean sensible object datas. More...
 
 _cleanTemplateObjectDatas ($object)
 Clean sensible object datas. More...
 
- Protected Member Functions inherited from DolibarrApi
 _checkValForAPI ($field, $value, $object)
 Check and convert a string depending on its type/name. More...
 
 _checkFilters ($sqlfilters, &$error='')
 Return if a $sqlfilters parameter is valid Function no more used. More...
 

Private Member Functions

 _fetch ($id, $ref='', $ref_ext='', $contact_list=1)
 Get properties of an invoice object. More...
 
 _validate ($data)
 Validate fields before create or update object. More...
 
 _fetchTemplateInvoice ($id, $ref='', $ref_ext='', $contact_list=1)
 Get properties of an invoice object. More...
 

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. More...
 
static _forge_criteria_callback ($matches)
 Function to forge a SQL criteria from a Generic filter string. More...
 

Detailed Description

Definition at line 31 of file api_invoices.class.php.

Member Function Documentation

◆ _cleanObjectDatas()

Invoices::_cleanObjectDatas (   $object)
protected

Clean sensible object datas.

Parameters
Object$objectObject to clean
Returns
Object Object with cleaned properties

Reimplemented from DolibarrApi.

Definition at line 1674 of file api_invoices.class.php.

◆ _cleanTemplateObjectDatas()

Invoices::_cleanTemplateObjectDatas (   $object)
protected

Clean sensible object datas.

Parameters
Object$objectObject to clean
Returns
Object Object with cleaned properties

Definition at line 1777 of file api_invoices.class.php.

◆ _fetch()

Invoices::_fetch (   $id,
  $ref = '',
  $ref_ext = '',
  $contact_list = 1 
)
private

Get properties of an invoice object.

Return an array with invoice informations

Parameters
int$idID of order
string$refRef of object
string$ref_extExternal reference of object
int$contact_list0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id, -1: Do not return contacts/adddesses
Returns
Object Object with cleaned properties
Exceptions
RestException

Definition at line 128 of file api_invoices.class.php.

Referenced by getByRefExt().

◆ _fetchTemplateInvoice()

Invoices::_fetchTemplateInvoice (   $id,
  $ref = '',
  $ref_ext = '',
  $contact_list = 1 
)
private

Get properties of an invoice object.

Return an array with invoice informations

Parameters
int$idID of order
string$refRef of object
string$ref_extExternal reference of object
int$contact_list0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id, -1: Do not return contacts/adddesses
Returns
Object Object with cleaned properties
Exceptions
RestException

Definition at line 1742 of file api_invoices.class.php.

◆ _validate()

Invoices::_validate (   $data)
private

Validate fields before create or update object.

Parameters
array | null$dataDatas to validate
Returns
array
Exceptions
RestException

Definition at line 1698 of file api_invoices.class.php.

◆ addContact()

Invoices::addContact (   $id,
  $fk_socpeople,
  $type_contact,
  $source,
  $notrigger = 0 
)

Adds a contact to an invoice.

Parameters
int$idOrder ID
int$fk_socpeopleId of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link
string$type_contactType of contact (code). Must a code found into table llx_c_type_contact. For example: BILLING
string$sourceexternal=Contact extern (llx_socpeople), internal=Contact intern (llx_user)
int$notriggerDisable all triggers

@url POST {id}/contacts

Returns
object
Exceptions
RestException304
RestException401
RestException404
RestException500 System error

Definition at line 788 of file api_invoices.class.php.

◆ addPayment()

Invoices::addPayment (   $id,
  $datepaye,
  $paymentid,
  $closepaidinvoices,
  $accountid,
  $num_payment = '',
  $comment = '',
  $chqemetteur = '',
  $chqbank = '' 
)

Add payment line to a specific invoice with the remain to pay as amount.

Parameters
int$idId of invoice
string$datepaye{@from body} Payment date {@type timestamp}
int$paymentid{@from body} Payment mode Id {@min 1}
string$closepaidinvoices{@from body} Close paid invoices {@choice yes,no}
int$accountid{@from body} Account Id {@min 1}
string$num_payment{@from body} Payment number (optional)
string$comment{@from body} Note private (optional)
string$chqemetteur{@from body} Payment issuer (mandatory if paymentcode = 'CHQ')
string$chqbank{@from body} Issuer bank name (optional)

@url POST {id}/payments

Returns
int Payment ID
Exceptions
RestException400
RestException401
RestException404

Definition at line 1380 of file api_invoices.class.php.

◆ addPaymentDistributed()

Invoices::addPaymentDistributed (   $arrayofamounts,
  $datepaye,
  $paymentid,
  $closepaidinvoices,
  $accountid,
  $num_payment = '',
  $comment = '',
  $chqemetteur = '',
  $chqbank = '',
  $ref_ext = '',
  $accepthigherpayment = false 
)

Add a payment to pay partially or completely one or several invoices.

Warning: Take care that all invoices are owned by the same customer. Example of value for parameter arrayofamounts: {"1": {"amount": "99.99", "multicurrency_amount": ""}, "2": {"amount": "", "multicurrency_amount": "10"}}

Parameters
array$arrayofamounts{@from body} Array with id of invoices with amount to pay for each invoice
string$datepaye{@from body} Payment date {@type timestamp}
int$paymentid{@from body} Payment mode Id {@min 1}
string$closepaidinvoices{@from body} Close paid invoices {@choice yes,no}
int$accountid{@from body} Account Id {@min 1}
string$num_payment{@from body} Payment number (optional)
string$comment{@from body} Note private (optional)
string$chqemetteur{@from body} Payment issuer (mandatory if paiementcode = 'CHQ')
string$chqbank{@from body} Issuer bank name (optional)
string$ref_ext{@from body} External reference (optional)
bool$accepthigherpayment{@from body} Accept higher payments that it remains to be paid (optional)

@url POST /paymentsdistributed

Returns
int Payment ID
Exceptions
RestException400
RestException401
RestException403
RestException404

Definition at line 1500 of file api_invoices.class.php.

◆ createInvoiceFromOrder()

Invoices::createInvoiceFromOrder (   $orderid)

Create an invoice using an existing order.

Parameters
int$orderidId of the order
Returns
Object Object with cleaned properties

@url POST /createfromorder/{orderid}

Exceptions
RestException400
RestException401
RestException404
RestException405

Definition at line 337 of file api_invoices.class.php.

◆ delete()

Invoices::delete (   $id)

Delete invoice.

Parameters
int$idInvoice ID
Returns
array

Definition at line 648 of file api_invoices.class.php.

◆ deleteContact()

Invoices::deleteContact (   $id,
  $contactid,
  $type 
)

Delete a contact type of given invoice.

Parameters
int$idId of invoice to update
int$contactidRow key of the contact in the array contact_ids.
string$typeType of the contact (BILLING, SHIPPING, CUSTOMER).
Returns
Object Object with cleaned properties

@url DELETE {id}/contact/{contactid}/{type}

Exceptions
RestException401
RestException404
RestException500 System error

Definition at line 528 of file api_invoices.class.php.

◆ deleteLine()

Invoices::deleteLine (   $id,
  $lineid 
)

Deletes a line of a given invoice.

Parameters
int$idId of invoice
int$lineidId of the line to delete
Returns
Object Object with cleaned properties

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

Exceptions
RestException400
RestException401
RestException404
RestException405

Definition at line 573 of file api_invoices.class.php.

◆ get()

Invoices::get (   $id,
  $contact_list = 1 
)

Get properties of a invoice object.

Return an array with invoice informations

Parameters
int$idID of invoice
int$contact_list0:Return array contains all properties, 1:Return array contains just id, -1: Do not return contacts/adddesses
Returns
Object Object with cleaned properties
Exceptions
RestException

Definition at line 74 of file api_invoices.class.php.

◆ getByRef()

Invoices::getByRef (   $ref,
  $contact_list = 1 
)

Get properties of an invoice object by ref.

Return an array with invoice informations

Parameters
string$refRef of object
int$contact_list0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id, -1: Do not return contacts/adddesses
Returns
Object Object with cleaned properties

@url GET ref/{ref}

Exceptions
RestException

Definition at line 92 of file api_invoices.class.php.

◆ getByRefExt()

Invoices::getByRefExt (   $ref_ext,
  $contact_list = 1 
)

Get properties of an invoice object by ref_ext.

Return an array with invoice informations

Parameters
string$ref_extExternal reference of object
int$contact_list0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id, -1: Do not return contacts/adddesses
Returns
Object Object with cleaned properties

@url GET ref_ext/{ref_ext}

Exceptions
RestException

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

References _fetch().

◆ getDiscount()

Invoices::getDiscount (   $id)

Get discount from invoice.

Parameters
int$idId of invoice
Returns
Object Object with cleaned properties

@url GET {id}/discount

Definition at line 1028 of file api_invoices.class.php.

◆ getLines()

Invoices::getLines (   $id)

Get lines of an invoice.

Parameters
int$idId of invoice
Returns
array Array of lines

@url GET {id}/lines

Definition at line 373 of file api_invoices.class.php.

◆ getPayments()

Invoices::getPayments (   $id)

Get list of payments of a given invoice.

Parameters
int$idId of invoice
Returns
array

@url GET {id}/payments

Exceptions
RestException400
RestException401
RestException404
RestException405

Definition at line 1331 of file api_invoices.class.php.

◆ getTemplateInvoice()

Invoices::getTemplateInvoice (   $id,
  $contact_list = 1 
)

Get properties of a template invoice object.

Return an array with invoice informations

Parameters
int$idID of template invoice
int$contact_list0:Return array contains all properties, 1:Return array contains just id, -1: Do not return contacts/adddesses
Returns
Object Object with cleaned properties

@url GET templates/{id}

Exceptions
RestException

Definition at line 1724 of file api_invoices.class.php.

◆ index()

Invoices::index (   $sortfield = "t.rowid",
  $sortorder = 'ASC',
  $limit = 100,
  $page = 0,
  $thirdparty_ids = '',
  $status = '',
  $sqlfilters = '' 
)

List invoices.

Get a list of invoices

Parameters
string$sortfieldSort field
string$sortorderSort order
int$limitLimit for list
int$pagePage number
string$thirdparty_idsThirdparty ids to filter orders of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i}
string$statusFilter by invoice status : draft | unpaid | paid | cancelled
string$sqlfiltersOther criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
Returns
array Array of invoice objects
Exceptions
RestException404 Not found
RestException503 Error

Definition at line 179 of file api_invoices.class.php.

◆ markAsCreditAvailable()

Invoices::markAsCreditAvailable (   $id)

Create a discount (credit available) for a credit note or a deposit.

Parameters
int$idInvoice ID
Returns
Object Object with cleaned properties

@url POST {id}/markAsCreditAvailable

Exceptions
RestException304
RestException401
RestException404
RestException500 System error

Definition at line 1071 of file api_invoices.class.php.

◆ post()

Invoices::post (   $request_data = null)

Create invoice object.

Parameters
array$request_dataRequest datas
Returns
int ID of invoice

Definition at line 295 of file api_invoices.class.php.

◆ postContact()

Invoices::postContact (   $id,
  $contactid,
  $type 
)

Add a contact type of given invoice.

Parameters
int$idId of invoice to update
int$contactidId of contact to add
string$typeType of the contact (BILLING, SHIPPING, CUSTOMER)
Returns
array

@url POST {id}/contact/{contactid}/{type}

Exceptions
RestException401
RestException404

Definition at line 480 of file api_invoices.class.php.

◆ postLine()

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

Add a line to a given invoice.

Exemple of POST query : { "desc": "Desc", "subprice": "1.00000000", "qty": "1", "tva_tx": "20.000", "localtax1_tx": "0.000", "localtax2_tx": "0.000", "fk_product": "1", "remise_percent": "0", "date_start": "", "date_end": "", "fk_code_ventilation": 0, "info_bits": "0", "fk_remise_except": null, "product_type": "1", "rang": "-1", "special_code": "0", "fk_parent_line": null, "fk_fournprice": null, "pa_ht": "0.00000000", "label": "", "array_options": [], "situation_percent": "100", "fk_prev_id": null, "fk_unit": null }

Parameters
int$idId of invoice
array$request_dataInvoiceLine data

@url POST {id}/lines

Returns
int
Exceptions
RestException304
RestException401
RestException404
RestException400

Definition at line 700 of file api_invoices.class.php.

◆ put()

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

Update invoice.

Parameters
int$idId of invoice to update
array$request_dataDatas
Returns
Object|false Object with cleaned properties

Definition at line 606 of file api_invoices.class.php.

◆ putLine()

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

Update a line to a given invoice.

Parameters
int$idId of invoice to update
int$lineidId of line to update
array$request_dataInvoiceLine data
Returns
Object Object with cleaned properties

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

Exceptions
RestException304
RestException401
RestException404 Invoice not found

Definition at line 409 of file api_invoices.class.php.

◆ putPayment()

Invoices::putPayment (   $id,
  $num_payment = '' 
)

Update a payment.

Parameters
int$idId of payment
string$num_paymentPayment number

@url PUT payments/{id}

Returns
array
Exceptions
RestException400 Bad parameters
RestException401 Not allowed
RestException404 Not found

Definition at line 1634 of file api_invoices.class.php.

◆ settodraft()

Invoices::settodraft (   $id,
  $idwarehouse = -1 
)

Sets an invoice as draft.

Parameters
int$idOrder ID
int$idwarehouseWarehouse ID
Returns
Object Object with cleaned properties

@url POST {id}/settodraft

Exceptions
RestException304
RestException401
RestException404
RestException500 System error

Definition at line 836 of file api_invoices.class.php.

◆ settopaid()

Invoices::settopaid (   $id,
  $close_code = '',
  $close_note = '' 
)

Sets an invoice as paid.

Parameters
int$idOrder ID
string$close_codeCode filled if we classify to 'Paid completely' when payment is not complete (for escompte for example)
string$close_noteComment defined if we classify to 'Paid' when payment is not complete (for escompte for example)
Returns
Object Object with cleaned properties

@url POST {id}/settopaid

Exceptions
RestException304
RestException401
RestException404
RestException500 System error

Definition at line 936 of file api_invoices.class.php.

◆ settounpaid()

Invoices::settounpaid (   $id)

Sets an invoice as unpaid.

Parameters
int$idOrder ID
Returns
Object Object with cleaned properties

@url POST {id}/settounpaid

Exceptions
RestException304
RestException401
RestException404
RestException500 System error

Definition at line 985 of file api_invoices.class.php.

◆ useCreditNote()

Invoices::useCreditNote (   $id,
  $discountid 
)

Add an available credit note discount to payments of an existing invoice.

Note that this consume the credit note.

Parameters
int$idId of invoice
int$discountidId of a discount coming from a credit note
Returns
int

@url POST {id}/usecreditnote/{discountid}

Exceptions
RestException400
RestException401
RestException404
RestException405

Definition at line 1287 of file api_invoices.class.php.

◆ useDiscount()

Invoices::useDiscount (   $id,
  $discountid 
)

Add a discount line into an invoice (as an invoice line) using an existing absolute discount.

Note that this consume the discount.

Parameters
int$idId of invoice
int$discountidId of discount
Returns
int

@url POST {id}/usediscount/{discountid}

Exceptions
RestException400
RestException401
RestException404
RestException405

Definition at line 1242 of file api_invoices.class.php.

◆ validate()

Invoices::validate (   $id,
  $idwarehouse = 0,
  $notrigger = 0 
)

Validate an invoice.

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

Parameters
int$idInvoice ID
int$idwarehouseWarehouse ID
int$notrigger1=Does not execute triggers, 0= execute triggers
Returns
Object|false Object with cleaned properties

@url POST {id}/validate

Definition at line 887 of file api_invoices.class.php.


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