NEW: api invoice get by ref

This commit is contained in:
ptibogxiv 2020-03-01 18:33:13 +01:00 committed by GitHub
parent 06e428064f
commit 6ee8fa4e8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr> /* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
/* Copyright (C) 2020 Thibault FOUCART <support@ptibogxiv.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -63,11 +64,66 @@ class Invoices extends DolibarrApi
*/ */
public function get($id, $contact_list = 1) public function get($id, $contact_list = 1)
{ {
return $this->_fetch($id, '', '', '', $contact_list);
}
/**
* Get properties of an invoice object by ref
*
* Return an array with invoice informations
*
* @param string $ref Ref of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
*
* @url GET ref/{ref}
*
* @throws RestException
*/
public function getByRef($ref, $contact_list = 1)
{
return $this->_fetch('', $ref, '', '', $contact_list);
}
/**
* Get properties of an invoice object by ref_ext
*
* Return an array with invoice informations
*
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
*
* @url GET ref_ext/{ref_ext}
*
* @throws RestException
*/
public function getByRefExt($ref_ext, $contact_list = 1)
{
return $this->_fetch('', '', $ref_ext, '', $contact_list);
}
/**
* Get properties of an order object
*
* Return an array with order informations
*
* @param int $id ID of order
* @param string $ref Ref of object
* @param string $ref_ext External reference of object
* @param string $ref_int Internal reference of other objec
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
*
* @throws RestException
*/
private function _fetch($id, $ref = '', $ref_ext = '', $ref_int = '', $contact_list = 1)
{
if (!DolibarrApiAccess::$user->rights->facture->lire) { if (!DolibarrApiAccess::$user->rights->facture->lire) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->invoice->fetch($id); $result = $this->invoice->fetch($id, $ref, $ref_ext, $ref_int);
if (!$result) { if (!$result) {
throw new RestException(404, 'Invoice not found'); throw new RestException(404, 'Invoice not found');
} }
@ -87,7 +143,7 @@ class Invoices extends DolibarrApi
$this->invoice->fetchObjectLinked(); $this->invoice->fetchObjectLinked();
return $this->_cleanObjectDatas($this->invoice); return $this->_cleanObjectDatas($this->invoice);
} }
/** /**
* List invoices * List invoices
@ -242,10 +298,10 @@ class Invoices extends DolibarrApi
* @url POST /createfromorder/{orderid} * @url POST /createfromorder/{orderid}
* *
* @return int * @return int
* @throws RestException 400 * @throws 400
* @throws RestException 401 * @throws 401
* @throws RestException 404 * @throws 404
* @throws RestException 405 * @throws 405
*/ */
public function createInvoiceFromOrder($orderid) public function createInvoiceFromOrder($orderid)
{ {
@ -318,9 +374,10 @@ class Invoices extends DolibarrApi
* *
* @return array * @return array
* *
* @throws RestException 304 * @throws 200
* @throws RestException 401 * @throws 304
* @throws RestException 404 Invoice not found * @throws 401
* @throws 404
*/ */
public function putLine($id, $lineid, $request_data = null) public function putLine($id, $lineid, $request_data = null)
{ {
@ -382,9 +439,8 @@ class Invoices extends DolibarrApi
* @url POST {id}/contact/{contactid}/{type} * @url POST {id}/contact/{contactid}/{type}
* *
* @return int * @return int
* * @throws 401
* @throws RestException 401 * @throws 404
* @throws RestException 404
*/ */
public function postContact($id, $contactid, $type) public function postContact($id, $contactid, $type)
{ {
@ -424,10 +480,9 @@ class Invoices extends DolibarrApi
* @url DELETE {id}/contact/{rowid} * @url DELETE {id}/contact/{rowid}
* *
* @return array * @return array
* * @throws 401
* @throws RestException 401 * @throws 404
* @throws RestException 404 * @throws 500
* @throws RestException 500
*/ */
public function deleteContact($id, $rowid) public function deleteContact($id, $rowid)
{ {
@ -464,10 +519,10 @@ class Invoices extends DolibarrApi
* *
* @return array * @return array
* *
* @throws RestException 400 * @throws 400
* @throws RestException 401 * @throws 401
* @throws RestException 404 * @throws 404
* @throws RestException 405 * @throws 405
*/ */
public function deleteLine($id, $lineid) public function deleteLine($id, $lineid)
{ {
@ -592,9 +647,10 @@ class Invoices extends DolibarrApi
* *
* @return int * @return int
* *
* @throws RestException 401 * @throws 200
* @throws RestException 404 * @throws 401
* @throws RestException 400 * @throws 404
* @throws 400
*/ */
public function postLine($id, $request_data = null) public function postLine($id, $request_data = null)
{ {
@ -673,10 +729,11 @@ class Invoices extends DolibarrApi
* *
* @return array * @return array
* *
* @throws RestException 304 * @throws 200
* @throws RestException 401 * @throws 304
* @throws RestException 404 * @throws 401
* @throws RestException 500 * @throws 404
* @throws 500
* *
*/ */
public function addContact($id, $fk_socpeople, $type_contact, $source, $notrigger = 0) public function addContact($id, $fk_socpeople, $type_contact, $source, $notrigger = 0)
@ -722,10 +779,11 @@ class Invoices extends DolibarrApi
* *
* @return array * @return array
* *
* @throws RestException 304 * @throws 200
* @throws RestException 401 * @throws 304
* @throws RestException 404 * @throws 401
* @throws RestException 500 * @throws 404
* @throws 500
* *
*/ */
public function settodraft($id, $idwarehouse = -1) public function settodraft($id, $idwarehouse = -1)
@ -825,10 +883,11 @@ class Invoices extends DolibarrApi
* *
* @return array An invoice object * @return array An invoice object
* *
* @throws RestException 304 * @throws 200
* @throws RestException 401 * @throws 304
* @throws RestException 404 * @throws 401
* @throws RestException 500 * @throws 404
* @throws 500
*/ */
public function settopaid($id, $close_code = '', $close_note = '') public function settopaid($id, $close_code = '', $close_note = '')
{ {
@ -875,10 +934,11 @@ class Invoices extends DolibarrApi
* *
* @return array An invoice object * @return array An invoice object
* *
* @throws RestException 304 * @throws 200
* @throws RestException 401 * @throws 304
* @throws RestException 404 * @throws 401
* @throws RestException 500 * @throws 404
* @throws 500
*/ */
public function settounpaid($id) public function settounpaid($id)
{ {
@ -923,10 +983,11 @@ class Invoices extends DolibarrApi
* *
* @return array An invoice object * @return array An invoice object
* *
* @throws RestException 304 * @throws 200
* @throws RestException 401 * @throws 304
* @throws RestException 404 * @throws 401
* @throws RestException 500 * @throws 404
* @throws 500
*/ */
public function markAsCreditAvailable($id) public function markAsCreditAvailable($id)
{ {
@ -1098,10 +1159,10 @@ class Invoices extends DolibarrApi
* @url POST {id}/usediscount/{discountid} * @url POST {id}/usediscount/{discountid}
* *
* @return int * @return int
* @throws RestException 400 * @throws 400
* @throws RestException 401 * @throws 401
* @throws RestException 404 * @throws 404
* @throws RestException 405 * @throws 405
*/ */
public function useDiscount($id, $discountid) public function useDiscount($id, $discountid)
{ {
@ -1144,10 +1205,10 @@ class Invoices extends DolibarrApi
* @url POST {id}/usecreditnote/{discountid} * @url POST {id}/usecreditnote/{discountid}
* *
* @return int * @return int
* @throws RestException 400 * @throws 400
* @throws RestException 401 * @throws 401
* @throws RestException 404 * @throws 404
* @throws RestException 405 * @throws 405
*/ */
public function useCreditNote($id, $discountid) public function useCreditNote($id, $discountid)
{ {
@ -1189,11 +1250,10 @@ class Invoices extends DolibarrApi
* @url GET {id}/payments * @url GET {id}/payments
* *
* @return array * @return array
* * @throws 400
* @throws RestException 400 * @throws 401
* @throws RestException 401 * @throws 404
* @throws RestException 404 * @throws 405
* @throws RestException 405
*/ */
public function getPayments($id) public function getPayments($id)
{ {
@ -1239,9 +1299,9 @@ class Invoices extends DolibarrApi
* @url POST {id}/payments * @url POST {id}/payments
* *
* @return int Payment ID * @return int Payment ID
* @throws RestException 400 * @throws 400
* @throws RestException 401 * @throws 401
* @throws RestException 404 * @throws 404
*/ */
public function addPayment($id, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_paiement = '', $comment = '', $chqemetteur = '', $chqbank = '') public function addPayment($id, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_paiement = '', $comment = '', $chqemetteur = '', $chqbank = '')
{ {
@ -1358,10 +1418,10 @@ class Invoices extends DolibarrApi
* @url POST /paymentsdistributed * @url POST /paymentsdistributed
* *
* @return int Payment ID * @return int Payment ID
* @throws RestException 400 * @throws 400
* @throws RestException 401 * @throws 401
* @throws RestException 403 * @throws 403
* @throws RestException 404 * @throws 404
*/ */
public function addPaymentDistributed($arrayofamounts, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_paiement = '', $comment = '', $chqemetteur = '', $chqbank = '') public function addPaymentDistributed($arrayofamounts, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_paiement = '', $comment = '', $chqemetteur = '', $chqbank = '')
{ {