REST API: replace the /invoice/ API by /invoices/.
Rename the 'mode' parameter to 'status' in GET /invoices.
Fix the error handling in DELETE /invoices/{id}.
This commit is contained in:
parent
db77efc067
commit
8cf0bceadd
@ -20,14 +20,12 @@
|
|||||||
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API class for invoice object
|
* API class for invoices
|
||||||
*
|
*
|
||||||
* @smart-auto-routing false
|
|
||||||
* @access protected
|
* @access protected
|
||||||
* @class DolibarrApiAccess {@requires user,external}
|
* @class DolibarrApiAccess {@requires user,external}
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class InvoiceApi extends DolibarrApi
|
class Invoices extends DolibarrApi
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -44,9 +42,6 @@ class InvoiceApi extends DolibarrApi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
|
||||||
* @url GET invoice/
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
@ -63,7 +58,6 @@ class InvoiceApi extends DolibarrApi
|
|||||||
* @param int $id ID of invoice
|
* @param int $id ID of invoice
|
||||||
* @return array|mixed data without useless information
|
* @return array|mixed data without useless information
|
||||||
*
|
*
|
||||||
* @url GET invoice/{id}
|
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function get($id)
|
function get($id)
|
||||||
@ -89,21 +83,18 @@ class InvoiceApi extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* Get a list of invoices
|
* Get a list of invoices
|
||||||
*
|
*
|
||||||
|
* FIXME this parameter is overwritten in the code and thus ignored
|
||||||
* @param int $socid Filter list with thirdparty ID
|
* @param int $socid Filter list with thirdparty ID
|
||||||
* @param string $mode Filter by invoice status : draft | unpaid | paid | cancelled
|
* @param string $status Filter by invoice status : draft | unpaid | paid | cancelled
|
||||||
* @param string $sortfield Sort field
|
* @param string $sortfield Sort field
|
||||||
* @param string $sortorder Sort order
|
* @param string $sortorder Sort order
|
||||||
* @param int $limit Limit for list
|
* @param int $limit Limit for list
|
||||||
* @param int $page Page number
|
* @param int $page Page number
|
||||||
*
|
|
||||||
* @return array Array of invoice objects
|
* @return array Array of invoice objects
|
||||||
*
|
*
|
||||||
* @url GET invoice/list
|
* @throws RestException
|
||||||
* @url GET invoice/list/{mode}
|
|
||||||
* @url GET thirdparty/{socid}/invoice/list
|
|
||||||
* @url GET thirdparty/{socid}/invoice/list/{mode}
|
|
||||||
*/
|
*/
|
||||||
function getList($socid=0, $mode='', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
|
function index($socid=0, $status='', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
@ -125,11 +116,11 @@ class InvoiceApi extends DolibarrApi
|
|||||||
if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
|
if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
|
||||||
|
|
||||||
|
|
||||||
// Example of use $mode
|
// Filter by status
|
||||||
if ($mode == 'draft') $sql.= " AND s.fk_statut IN (0)";
|
if ($status == 'draft') $sql.= " AND s.fk_statut IN (0)";
|
||||||
if ($mode == 'unpaid') $sql.= " AND s.fk_statut IN (1)";
|
if ($status == 'unpaid') $sql.= " AND s.fk_statut IN (1)";
|
||||||
if ($mode == 'paid') $sql.= " AND s.fk_statut IN (2)";
|
if ($status == 'paid') $sql.= " AND s.fk_statut IN (2)";
|
||||||
if ($mode == 'cancelled') $sql.= " AND s.fk_statut IN (3)";
|
if ($status == 'cancelled') $sql.= " AND s.fk_statut IN (3)";
|
||||||
|
|
||||||
// Insert sale filter
|
// Insert sale filter
|
||||||
if ($search_sale > 0)
|
if ($search_sale > 0)
|
||||||
@ -183,8 +174,6 @@ class InvoiceApi extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @param array $request_data Request datas
|
* @param array $request_data Request datas
|
||||||
* @return int ID of invoice
|
* @return int ID of invoice
|
||||||
*
|
|
||||||
* @url POST invoice/
|
|
||||||
*/
|
*/
|
||||||
function post($request_data = NULL)
|
function post($request_data = NULL)
|
||||||
{
|
{
|
||||||
@ -212,8 +201,6 @@ class InvoiceApi extends DolibarrApi
|
|||||||
* @param int $id Id of invoice to update
|
* @param int $id Id of invoice to update
|
||||||
* @param array $request_data Datas
|
* @param array $request_data Datas
|
||||||
* @return int
|
* @return int
|
||||||
*
|
|
||||||
* @url PUT invoice/{id}
|
|
||||||
*/
|
*/
|
||||||
function put($id, $request_data = NULL)
|
function put($id, $request_data = NULL)
|
||||||
{
|
{
|
||||||
@ -245,8 +232,6 @@ class InvoiceApi extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @param int $id Invoice ID
|
* @param int $id Invoice ID
|
||||||
* @return type
|
* @return type
|
||||||
*
|
|
||||||
* @url DELETE invoice/{id}
|
|
||||||
*/
|
*/
|
||||||
function delete($id)
|
function delete($id)
|
||||||
{
|
{
|
||||||
@ -262,7 +247,7 @@ class InvoiceApi extends DolibarrApi
|
|||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !$this->invoice->delete($id))
|
if( $this->invoice->delete($id) < 0)
|
||||||
{
|
{
|
||||||
throw new RestException(500);
|
throw new RestException(500);
|
||||||
}
|
}
|
||||||
@ -273,7 +258,6 @@ class InvoiceApi extends DolibarrApi
|
|||||||
'message' => 'Facture deleted'
|
'message' => 'Facture deleted'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -287,7 +271,7 @@ class InvoiceApi extends DolibarrApi
|
|||||||
function _validate($data)
|
function _validate($data)
|
||||||
{
|
{
|
||||||
$invoice = array();
|
$invoice = array();
|
||||||
foreach (InvoiceApi::$FIELDS as $field) {
|
foreach (Invoices::$FIELDS as $field) {
|
||||||
if (!isset($data[$field]))
|
if (!isset($data[$field]))
|
||||||
throw new RestException(400, "$field field missing");
|
throw new RestException(400, "$field field missing");
|
||||||
$invoice[$field] = $data[$field];
|
$invoice[$field] = $data[$field];
|
||||||
Loading…
Reference in New Issue
Block a user