Set default limit to 100 on all rest api that list
This commit is contained in:
parent
98674f6d82
commit
c6e5115d34
@ -91,7 +91,7 @@ class Members extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $typeid = '', $sqlfilters = '') {
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $typeid = '', $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|||||||
@ -86,7 +86,7 @@ class MembersTypes extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|||||||
@ -85,7 +85,7 @@ class Subscriptions extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "dateadh", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
|
function index($sortfield = "dateadh", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
@ -98,7 +98,7 @@ class Subscriptions extends DolibarrApi
|
|||||||
$sql.= " FROM ".MAIN_DB_PREFIX."subscription as t";
|
$sql.= " FROM ".MAIN_DB_PREFIX."subscription as t";
|
||||||
$sql.= ' WHERE 1 = 1';
|
$sql.= ' WHERE 1 = 1';
|
||||||
// Add sql filters
|
// Add sql filters
|
||||||
if ($sqlfilters)
|
if ($sqlfilters)
|
||||||
{
|
{
|
||||||
if (! DolibarrApi::_checkFilters($sqlfilters))
|
if (! DolibarrApi::_checkFilters($sqlfilters))
|
||||||
{
|
{
|
||||||
@ -107,7 +107,7 @@ class Subscriptions extends DolibarrApi
|
|||||||
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
||||||
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql.= $db->order($sortfield, $sortorder);
|
$sql.= $db->order($sortfield, $sortorder);
|
||||||
if ($limit) {
|
if ($limit) {
|
||||||
if ($page < 0)
|
if ($page < 0)
|
||||||
|
|||||||
@ -103,7 +103,7 @@ class Categories extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $type = '', $sqlfilters = '') {
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|||||||
@ -94,7 +94,7 @@ class Proposals extends DolibarrApi
|
|||||||
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'20160101')"
|
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'20160101')"
|
||||||
* @return array Array of order objects
|
* @return array Array of order objects
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids = '', $sqlfilters = '') {
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|||||||
@ -107,7 +107,7 @@ class CommandeApi extends DolibarrApi
|
|||||||
* @url GET /order/list
|
* @url GET /order/list
|
||||||
* @return array Array of order objects
|
* @return array Array of order objects
|
||||||
*/
|
*/
|
||||||
function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $societe = 0) {
|
function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $societe = 0) {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|||||||
@ -61,7 +61,7 @@ class BankAccounts extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '')
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '')
|
||||||
{
|
{
|
||||||
$list = array();
|
$list = array();
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
* API class for invoice object
|
* API class for invoice object
|
||||||
*
|
*
|
||||||
* @smart-auto-routing false
|
* @smart-auto-routing false
|
||||||
* @access protected
|
* @access protected
|
||||||
* @class DolibarrApiAccess {@requires user,external}
|
* @class DolibarrApiAccess {@requires user,external}
|
||||||
* @deprecated Use Invoices instead (defined in api_invoices.class.php)
|
* @deprecated Use Invoices instead (defined in api_invoices.class.php)
|
||||||
*/
|
*/
|
||||||
@ -31,7 +31,7 @@ class InvoiceApi extends DolibarrApi
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||||
*/
|
*/
|
||||||
static $FIELDS = array(
|
static $FIELDS = array(
|
||||||
'socid'
|
'socid'
|
||||||
@ -46,7 +46,7 @@ class InvoiceApi extends DolibarrApi
|
|||||||
* Constructor <b>Warning: Deprecated</b>
|
* Constructor <b>Warning: Deprecated</b>
|
||||||
*
|
*
|
||||||
* @url GET invoice/
|
* @url GET invoice/
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
@ -59,7 +59,7 @@ class InvoiceApi extends DolibarrApi
|
|||||||
* Get properties of a invoice object <b>Warning: Deprecated</b>
|
* Get properties of a invoice object <b>Warning: Deprecated</b>
|
||||||
*
|
*
|
||||||
* Return an array with invoice informations
|
* Return an array with invoice informations
|
||||||
*
|
*
|
||||||
* @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
|
||||||
*
|
*
|
||||||
@ -67,16 +67,16 @@ class InvoiceApi extends DolibarrApi
|
|||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function get($id)
|
function get($id)
|
||||||
{
|
{
|
||||||
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);
|
||||||
if( ! $result ) {
|
if( ! $result ) {
|
||||||
throw new RestException(404, 'Facture not found');
|
throw new RestException(404, 'Facture not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
|
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
@ -86,9 +86,9 @@ class InvoiceApi extends DolibarrApi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* List invoices <b>Warning: Deprecated</b>
|
* List invoices <b>Warning: Deprecated</b>
|
||||||
*
|
*
|
||||||
* Get a list of invoices
|
* Get a list of invoices
|
||||||
*
|
*
|
||||||
* @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
|
||||||
@ -101,15 +101,15 @@ class InvoiceApi extends DolibarrApi
|
|||||||
* @url GET invoice/list
|
* @url GET invoice/list
|
||||||
* @url GET invoice/list/{mode}
|
* @url GET invoice/list/{mode}
|
||||||
* @url GET thirdparty/{socid}/invoice/list
|
* @url GET thirdparty/{socid}/invoice/list
|
||||||
* @url GET thirdparty/{socid}/invoice/list/{mode}
|
* @url GET thirdparty/{socid}/invoice/list/{mode}
|
||||||
*/
|
*/
|
||||||
function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $socid=0, $mode='') {
|
function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $socid=0, $mode='') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|
||||||
$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $socid;
|
$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $socid;
|
||||||
|
|
||||||
// If the internal user must only see his customers, force searching by him
|
// If the internal user must only see his customers, force searching by him
|
||||||
$search_sale = 0;
|
$search_sale = 0;
|
||||||
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
|
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
|
||||||
@ -117,27 +117,27 @@ class InvoiceApi extends DolibarrApi
|
|||||||
$sql = "SELECT s.rowid";
|
$sql = "SELECT s.rowid";
|
||||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
|
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture as s";
|
$sql.= " FROM ".MAIN_DB_PREFIX."facture as s";
|
||||||
|
|
||||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
|
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
|
||||||
|
|
||||||
$sql.= ' WHERE s.entity IN ('.getEntity('facture').')';
|
$sql.= ' WHERE s.entity IN ('.getEntity('facture').')';
|
||||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc";
|
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc";
|
||||||
if ($socid) $sql.= " AND s.fk_soc = ".$socid;
|
if ($socid) $sql.= " AND s.fk_soc = ".$socid;
|
||||||
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
|
// Example of use $mode
|
||||||
if ($mode == 'draft') $sql.= " AND s.fk_statut IN (0)";
|
if ($mode == 'draft') $sql.= " AND s.fk_statut IN (0)";
|
||||||
if ($mode == 'unpaid') $sql.= " AND s.fk_statut IN (1)";
|
if ($mode == 'unpaid') $sql.= " AND s.fk_statut IN (1)";
|
||||||
if ($mode == 'paid') $sql.= " AND s.fk_statut IN (2)";
|
if ($mode == 'paid') $sql.= " AND s.fk_statut IN (2)";
|
||||||
if ($mode == 'cancelled') $sql.= " AND s.fk_statut IN (3)";
|
if ($mode == 'cancelled') $sql.= " AND s.fk_statut IN (3)";
|
||||||
|
|
||||||
// Insert sale filter
|
// Insert sale filter
|
||||||
if ($search_sale > 0)
|
if ($search_sale > 0)
|
||||||
{
|
{
|
||||||
$sql .= " AND sc.fk_user = ".$search_sale;
|
$sql .= " AND sc.fk_user = ".$search_sale;
|
||||||
}
|
}
|
||||||
|
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
|
||||||
{
|
{
|
||||||
@ -180,10 +180,10 @@ class InvoiceApi extends DolibarrApi
|
|||||||
}
|
}
|
||||||
return $obj_ret;
|
return $obj_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create invoice object <b>Warning: Deprecated</b>
|
* Create invoice object <b>Warning: Deprecated</b>
|
||||||
*
|
*
|
||||||
* @param array $request_data Request datas
|
* @param array $request_data Request datas
|
||||||
* @return int ID of invoice
|
* @return int ID of invoice
|
||||||
*
|
*
|
||||||
@ -196,7 +196,7 @@ class InvoiceApi extends DolibarrApi
|
|||||||
}
|
}
|
||||||
// Check mandatory fields
|
// Check mandatory fields
|
||||||
$result = $this->_validate($request_data);
|
$result = $this->_validate($request_data);
|
||||||
|
|
||||||
foreach($request_data as $field => $value) {
|
foreach($request_data as $field => $value) {
|
||||||
$this->invoice->$field = $value;
|
$this->invoice->$field = $value;
|
||||||
}
|
}
|
||||||
@ -213,9 +213,9 @@ class InvoiceApi extends DolibarrApi
|
|||||||
* Update invoice <b>Warning: Deprecated</b>
|
* Update invoice <b>Warning: Deprecated</b>
|
||||||
*
|
*
|
||||||
* @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}
|
* @url PUT invoice/{id}
|
||||||
*/
|
*/
|
||||||
function put($id, $request_data = NULL)
|
function put($id, $request_data = NULL)
|
||||||
@ -223,12 +223,12 @@ class InvoiceApi extends DolibarrApi
|
|||||||
if(! DolibarrApiAccess::$user->rights->facture->creer) {
|
if(! DolibarrApiAccess::$user->rights->facture->creer) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->invoice->fetch($id);
|
$result = $this->invoice->fetch($id);
|
||||||
if( ! $result ) {
|
if( ! $result ) {
|
||||||
throw new RestException(404, 'Facture not found');
|
throw new RestException(404, 'Facture not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
|
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
@ -237,20 +237,20 @@ class InvoiceApi extends DolibarrApi
|
|||||||
if ($field == 'id') continue;
|
if ($field == 'id') continue;
|
||||||
$this->invoice->$field = $value;
|
$this->invoice->$field = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->invoice->update($id, DolibarrApiAccess::$user))
|
if($this->invoice->update($id, DolibarrApiAccess::$user))
|
||||||
return $this->get ($id);
|
return $this->get ($id);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete invoice <b>Warning: Deprecated</b>
|
* Delete invoice <b>Warning: Deprecated</b>
|
||||||
*
|
*
|
||||||
* @param int $id Invoice ID
|
* @param int $id Invoice ID
|
||||||
* @return type
|
* @return type
|
||||||
*
|
*
|
||||||
* @url DELETE invoice/{id}
|
* @url DELETE invoice/{id}
|
||||||
*/
|
*/
|
||||||
function delete($id)
|
function delete($id)
|
||||||
{
|
{
|
||||||
@ -261,31 +261,31 @@ class InvoiceApi extends DolibarrApi
|
|||||||
if( ! $result ) {
|
if( ! $result ) {
|
||||||
throw new RestException(404, 'Facture not found');
|
throw new RestException(404, 'Facture not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('facture',$this->facture->id)) {
|
if( ! DolibarrApi::_checkAccessToResource('facture',$this->facture->id)) {
|
||||||
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(DolibarrApiAccess::$user))
|
if( !$this->invoice->delete(DolibarrApiAccess::$user))
|
||||||
{
|
{
|
||||||
throw new RestException(500);
|
throw new RestException(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'success' => array(
|
'success' => array(
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'message' => 'Facture deleted'
|
'message' => 'Facture deleted'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate fields before create or update object
|
* Validate fields before create or update object
|
||||||
*
|
*
|
||||||
* @param array $data Datas to validate
|
* @param array $data Datas to validate
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function _validate($data)
|
function _validate($data)
|
||||||
|
|||||||
@ -95,7 +95,7 @@ class Invoices extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|||||||
@ -94,7 +94,7 @@ class ExpenseReports extends DolibarrApi
|
|||||||
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
|
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
|
||||||
* @return array Array of Expense Report objects
|
* @return array Array of Expense Report objects
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $user_ids = 0, $sqlfilters = '') {
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = 0, $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|||||||
@ -96,7 +96,7 @@ class SupplierInvoices extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|||||||
@ -96,7 +96,7 @@ class SupplierOrders extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|||||||
@ -102,7 +102,7 @@ class MyObjectApi extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @url GET /myobjects/
|
* @url GET /myobjects/
|
||||||
*/
|
*/
|
||||||
function index($mode, $sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
|
function index($mode, $sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|||||||
@ -96,7 +96,7 @@ class Products extends DolibarrApi
|
|||||||
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.tobuy:=:0) and (t.tosell:=:1)"
|
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.tobuy:=:0) and (t.tosell:=:1)"
|
||||||
* @return array Array of product objects
|
* @return array Array of product objects
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.ref", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $category=0, $sqlfilters = '') {
|
function index($sortfield = "t.ref", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $category=0, $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|||||||
@ -23,13 +23,13 @@ require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
|
|||||||
/**
|
/**
|
||||||
* API class for stock movements
|
* API class for stock movements
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @class DolibarrApiAccess {@requires user,external}
|
* @class DolibarrApiAccess {@requires user,external}
|
||||||
*/
|
*/
|
||||||
class StockMovements extends DolibarrApi
|
class StockMovements extends DolibarrApi
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||||
*/
|
*/
|
||||||
static $FIELDS = array(
|
static $FIELDS = array(
|
||||||
'product_id',
|
'product_id',
|
||||||
@ -59,21 +59,21 @@ class StockMovements extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @param int $id ID of movement
|
* @param int $id ID of movement
|
||||||
* @return array|mixed data without useless information
|
* @return array|mixed data without useless information
|
||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
function get($id)
|
function get($id)
|
||||||
{
|
{
|
||||||
if(! DolibarrApiAccess::$user->rights->stock->lire) {
|
if(! DolibarrApiAccess::$user->rights->stock->lire) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->stockmovement->fetch($id);
|
$result = $this->stockmovement->fetch($id);
|
||||||
if( ! $result ) {
|
if( ! $result ) {
|
||||||
throw new RestException(404, 'warehouse not found');
|
throw new RestException(404, 'warehouse not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('warehouse',$this->stockmovement->id)) {
|
if( ! DolibarrApi::_checkAccessToResource('warehouse',$this->stockmovement->id)) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
@ -93,21 +93,21 @@ class StockMovements extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|
||||||
if(! DolibarrApiAccess::$user->rights->stock->lire) {
|
if(! DolibarrApiAccess::$user->rights->stock->lire) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT t.rowid";
|
$sql = "SELECT t.rowid";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."stock_mouvement as t";
|
$sql.= " FROM ".MAIN_DB_PREFIX."stock_mouvement as t";
|
||||||
//$sql.= ' WHERE t.entity IN ('.getEntity('stock').')';
|
//$sql.= ' WHERE t.entity IN ('.getEntity('stock').')';
|
||||||
$sql.= ' WHERE 1 = 1';
|
$sql.= ' WHERE 1 = 1';
|
||||||
// Add sql filters
|
// Add sql filters
|
||||||
if ($sqlfilters)
|
if ($sqlfilters)
|
||||||
{
|
{
|
||||||
if (! DolibarrApi::_checkFilters($sqlfilters))
|
if (! DolibarrApi::_checkFilters($sqlfilters))
|
||||||
{
|
{
|
||||||
@ -116,7 +116,7 @@ class StockMovements extends DolibarrApi
|
|||||||
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
||||||
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql.= $db->order($sortfield, $sortorder);
|
$sql.= $db->order($sortfield, $sortorder);
|
||||||
if ($limit) {
|
if ($limit) {
|
||||||
if ($page < 0)
|
if ($page < 0)
|
||||||
@ -162,13 +162,13 @@ class StockMovements extends DolibarrApi
|
|||||||
* @param string $movementlabel Movement label {@example Inventory number 123}
|
* @param string $movementlabel Movement label {@example Inventory number 123}
|
||||||
* @param string $price To update AWP (Average Weighted Price) when you make a stock increase (qty must be higher then 0).
|
* @param string $price To update AWP (Average Weighted Price) when you make a stock increase (qty must be higher then 0).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create stock movement object.
|
* Create stock movement object.
|
||||||
* You can use the following message to test this RES API:
|
* You can use the following message to test this RES API:
|
||||||
* { "product_id": 1, "warehouse_id": 1, "qty": 1, "lot": "", "movementcode": "INV123", "movementlabel": "Inventory 123", "price": 0 }
|
* { "product_id": 1, "warehouse_id": 1, "qty": 1, "lot": "", "movementcode": "INV123", "movementlabel": "Inventory 123", "price": 0 }
|
||||||
*
|
*
|
||||||
* @param array $request_data Request data
|
* @param array $request_data Request data
|
||||||
* @return int ID of stock movement
|
* @return int ID of stock movement
|
||||||
*/
|
*/
|
||||||
@ -181,7 +181,7 @@ class StockMovements extends DolibarrApi
|
|||||||
|
|
||||||
// Check mandatory fields
|
// Check mandatory fields
|
||||||
//$result = $this->_validate($request_data);
|
//$result = $this->_validate($request_data);
|
||||||
|
|
||||||
foreach($request_data as $field => $value) {
|
foreach($request_data as $field => $value) {
|
||||||
//$this->stockmovement->$field = $value;
|
//$this->stockmovement->$field = $value;
|
||||||
if ($field == 'product_id') $product_id = $value;
|
if ($field == 'product_id') $product_id = $value;
|
||||||
@ -192,7 +192,7 @@ class StockMovements extends DolibarrApi
|
|||||||
if ($field == 'movementlabel') $movementlabel = $value;
|
if ($field == 'movementlabel') $movementlabel = $value;
|
||||||
if ($field == 'price') $price = $value;
|
if ($field == 'price') $price = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type increase or decrease
|
// Type increase or decrease
|
||||||
if ($qty >= 0) $type = 3;
|
if ($qty >= 0) $type = 3;
|
||||||
else $type = 2;
|
else $type = 2;
|
||||||
@ -200,16 +200,16 @@ class StockMovements extends DolibarrApi
|
|||||||
if($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', '', '', $lot) <= 0) {
|
if($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', '', '', $lot) <= 0) {
|
||||||
throw new RestException(503, 'Error when create stock movement : '.$this->stockmovement->error);
|
throw new RestException(503, 'Error when create stock movement : '.$this->stockmovement->error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->stockmovement->id;
|
return $this->stockmovement->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update stock movement
|
* Update stock movement
|
||||||
*
|
*
|
||||||
* @param int $id Id of warehouse to update
|
* @param int $id Id of warehouse to update
|
||||||
* @param array $request_data Datas
|
* @param array $request_data Datas
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
function put($id, $request_data = NULL)
|
function put($id, $request_data = NULL)
|
||||||
@ -217,12 +217,12 @@ class StockMovements extends DolibarrApi
|
|||||||
if(! DolibarrApiAccess::$user->rights->stock->creer) {
|
if(! DolibarrApiAccess::$user->rights->stock->creer) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->stockmovement->fetch($id);
|
$result = $this->stockmovement->fetch($id);
|
||||||
if( ! $result ) {
|
if( ! $result ) {
|
||||||
throw new RestException(404, 'stock movement not found');
|
throw new RestException(404, 'stock movement not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('stock',$this->stockmovement->id)) {
|
if( ! DolibarrApi::_checkAccessToResource('stock',$this->stockmovement->id)) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
@ -231,13 +231,13 @@ class StockMovements extends DolibarrApi
|
|||||||
if ($field == 'id') continue;
|
if ($field == 'id') continue;
|
||||||
$this->stockmovement->$field = $value;
|
$this->stockmovement->$field = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->stockmovement->update($id, DolibarrApiAccess::$user))
|
if($this->stockmovement->update($id, DolibarrApiAccess::$user))
|
||||||
return $this->get ($id);
|
return $this->get ($id);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete stock movement
|
* Delete stock movement
|
||||||
*
|
*
|
||||||
@ -254,15 +254,15 @@ class StockMovements extends DolibarrApi
|
|||||||
if( ! $result ) {
|
if( ! $result ) {
|
||||||
throw new RestException(404, 'stock movement not found');
|
throw new RestException(404, 'stock movement not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('stock',$this->stockmovement->id)) {
|
if( ! DolibarrApi::_checkAccessToResource('stock',$this->stockmovement->id)) {
|
||||||
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->stockmovement->delete(DolibarrApiAccess::$user)) {
|
if (! $this->stockmovement->delete(DolibarrApiAccess::$user)) {
|
||||||
throw new RestException(401,'error when delete stock movement');
|
throw new RestException(401,'error when delete stock movement');
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'success' => array(
|
'success' => array(
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
@ -270,9 +270,9 @@ class StockMovements extends DolibarrApi
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean sensible object datas
|
* Clean sensible object datas
|
||||||
*
|
*
|
||||||
@ -280,9 +280,9 @@ class StockMovements extends DolibarrApi
|
|||||||
* @return array Array of cleaned object properties
|
* @return array Array of cleaned object properties
|
||||||
*/
|
*/
|
||||||
function _cleanObjectDatas($object) {
|
function _cleanObjectDatas($object) {
|
||||||
|
|
||||||
$object = parent::_cleanObjectDatas($object);
|
$object = parent::_cleanObjectDatas($object);
|
||||||
|
|
||||||
// Remove useless data
|
// Remove useless data
|
||||||
unset($object->civility_id);
|
unset($object->civility_id);
|
||||||
unset($object->firstname);
|
unset($object->firstname);
|
||||||
@ -321,19 +321,19 @@ class StockMovements extends DolibarrApi
|
|||||||
unset($object->fk_project);
|
unset($object->fk_project);
|
||||||
unset($object->project);
|
unset($object->project);
|
||||||
unset($object->canvas);
|
unset($object->canvas);
|
||||||
|
|
||||||
//unset($object->eatby); Filled correctly in read mode
|
//unset($object->eatby); Filled correctly in read mode
|
||||||
//unset($object->sellby); Filled correctly in read mode
|
//unset($object->sellby); Filled correctly in read mode
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate fields before create or update object
|
* Validate fields before create or update object
|
||||||
*
|
*
|
||||||
* @param array|null $data Data to validate
|
* @param array|null $data Data to validate
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function _validate($data)
|
function _validate($data)
|
||||||
|
|||||||
@ -23,13 +23,13 @@
|
|||||||
/**
|
/**
|
||||||
* API class for warehouses
|
* API class for warehouses
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @class DolibarrApiAccess {@requires user,external}
|
* @class DolibarrApiAccess {@requires user,external}
|
||||||
*/
|
*/
|
||||||
class Warehouses extends DolibarrApi
|
class Warehouses extends DolibarrApi
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||||
*/
|
*/
|
||||||
static $FIELDS = array(
|
static $FIELDS = array(
|
||||||
'label',
|
'label',
|
||||||
@ -57,20 +57,20 @@ class Warehouses extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @param int $id ID of warehouse
|
* @param int $id ID of warehouse
|
||||||
* @return array|mixed data without useless information
|
* @return array|mixed data without useless information
|
||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function get($id)
|
function get($id)
|
||||||
{
|
{
|
||||||
if(! DolibarrApiAccess::$user->rights->stock->lire) {
|
if(! DolibarrApiAccess::$user->rights->stock->lire) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->warehouse->fetch($id);
|
$result = $this->warehouse->fetch($id);
|
||||||
if( ! $result ) {
|
if( ! $result ) {
|
||||||
throw new RestException(404, 'warehouse not found');
|
throw new RestException(404, 'warehouse not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('warehouse',$this->warehouse->id)) {
|
if( ! DolibarrApi::_checkAccessToResource('warehouse',$this->warehouse->id)) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ class Warehouses extends DolibarrApi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* List warehouses
|
* List warehouses
|
||||||
*
|
*
|
||||||
* Get a list of warehouses
|
* Get a list of warehouses
|
||||||
*
|
*
|
||||||
* @param string $sortfield Sort field
|
* @param string $sortfield Sort field
|
||||||
@ -92,20 +92,20 @@ class Warehouses extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|
||||||
if(! DolibarrApiAccess::$user->rights->stock->lire) {
|
if(! DolibarrApiAccess::$user->rights->stock->lire) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT t.rowid";
|
$sql = "SELECT t.rowid";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as t";
|
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as t";
|
||||||
$sql.= ' WHERE t.entity IN ('.getEntity('stock').')';
|
$sql.= ' WHERE t.entity IN ('.getEntity('stock').')';
|
||||||
// Add sql filters
|
// Add sql filters
|
||||||
if ($sqlfilters)
|
if ($sqlfilters)
|
||||||
{
|
{
|
||||||
if (! DolibarrApi::_checkFilters($sqlfilters))
|
if (! DolibarrApi::_checkFilters($sqlfilters))
|
||||||
{
|
{
|
||||||
@ -114,7 +114,7 @@ class Warehouses extends DolibarrApi
|
|||||||
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
||||||
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql.= $db->order($sortfield, $sortorder);
|
$sql.= $db->order($sortfield, $sortorder);
|
||||||
if ($limit) {
|
if ($limit) {
|
||||||
if ($page < 0)
|
if ($page < 0)
|
||||||
@ -154,7 +154,7 @@ class Warehouses extends DolibarrApi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create warehouse object
|
* Create warehouse object
|
||||||
*
|
*
|
||||||
* @param array $request_data Request data
|
* @param array $request_data Request data
|
||||||
* @return int ID of warehouse
|
* @return int ID of warehouse
|
||||||
*/
|
*/
|
||||||
@ -166,7 +166,7 @@ class Warehouses extends DolibarrApi
|
|||||||
|
|
||||||
// Check mandatory fields
|
// Check mandatory fields
|
||||||
$result = $this->_validate($request_data);
|
$result = $this->_validate($request_data);
|
||||||
|
|
||||||
foreach($request_data as $field => $value) {
|
foreach($request_data as $field => $value) {
|
||||||
$this->warehouse->$field = $value;
|
$this->warehouse->$field = $value;
|
||||||
}
|
}
|
||||||
@ -178,22 +178,22 @@ class Warehouses extends DolibarrApi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update warehouse
|
* Update warehouse
|
||||||
*
|
*
|
||||||
* @param int $id Id of warehouse to update
|
* @param int $id Id of warehouse to update
|
||||||
* @param array $request_data Datas
|
* @param array $request_data Datas
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function put($id, $request_data = NULL)
|
function put($id, $request_data = NULL)
|
||||||
{
|
{
|
||||||
if(! DolibarrApiAccess::$user->rights->stock->creer) {
|
if(! DolibarrApiAccess::$user->rights->stock->creer) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->warehouse->fetch($id);
|
$result = $this->warehouse->fetch($id);
|
||||||
if( ! $result ) {
|
if( ! $result ) {
|
||||||
throw new RestException(404, 'warehouse not found');
|
throw new RestException(404, 'warehouse not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('stock',$this->warehouse->id)) {
|
if( ! DolibarrApi::_checkAccessToResource('stock',$this->warehouse->id)) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
@ -202,13 +202,13 @@ class Warehouses extends DolibarrApi
|
|||||||
if ($field == 'id') continue;
|
if ($field == 'id') continue;
|
||||||
$this->warehouse->$field = $value;
|
$this->warehouse->$field = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->warehouse->update($id, DolibarrApiAccess::$user))
|
if($this->warehouse->update($id, DolibarrApiAccess::$user))
|
||||||
return $this->get ($id);
|
return $this->get ($id);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete warehouse
|
* Delete warehouse
|
||||||
*
|
*
|
||||||
@ -224,15 +224,15 @@ class Warehouses extends DolibarrApi
|
|||||||
if( ! $result ) {
|
if( ! $result ) {
|
||||||
throw new RestException(404, 'warehouse not found');
|
throw new RestException(404, 'warehouse not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('stock',$this->warehouse->id)) {
|
if( ! DolibarrApi::_checkAccessToResource('stock',$this->warehouse->id)) {
|
||||||
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->warehouse->delete(DolibarrApiAccess::$user)) {
|
if (! $this->warehouse->delete(DolibarrApiAccess::$user)) {
|
||||||
throw new RestException(401,'error when delete warehouse');
|
throw new RestException(401,'error when delete warehouse');
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'success' => array(
|
'success' => array(
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
@ -240,8 +240,8 @@ class Warehouses extends DolibarrApi
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean sensible object datas
|
* Clean sensible object datas
|
||||||
*
|
*
|
||||||
@ -249,22 +249,22 @@ class Warehouses extends DolibarrApi
|
|||||||
* @return array Array of cleaned object properties
|
* @return array Array of cleaned object properties
|
||||||
*/
|
*/
|
||||||
function _cleanObjectDatas($object) {
|
function _cleanObjectDatas($object) {
|
||||||
|
|
||||||
$object = parent::_cleanObjectDatas($object);
|
$object = parent::_cleanObjectDatas($object);
|
||||||
|
|
||||||
// Remove the subscriptions because they are handled as a subresource.
|
// Remove the subscriptions because they are handled as a subresource.
|
||||||
//unset($object->subscriptions);
|
//unset($object->subscriptions);
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate fields before create or update object
|
* Validate fields before create or update object
|
||||||
*
|
*
|
||||||
* @param array|null $data Data to validate
|
* @param array|null $data Data to validate
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function _validate($data)
|
function _validate($data)
|
||||||
|
|||||||
@ -102,7 +102,7 @@ class Contacts extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids = '', $sqlfilters = '') {
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|||||||
@ -22,14 +22,14 @@ use Luracast\Restler\RestException;
|
|||||||
/**
|
/**
|
||||||
* API class for users
|
* API class for users
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @class DolibarrApiAccess {@requires user,external}
|
* @class DolibarrApiAccess {@requires user,external}
|
||||||
*/
|
*/
|
||||||
class Users extends DolibarrApi
|
class Users extends DolibarrApi
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||||
*/
|
*/
|
||||||
static $FIELDS = array(
|
static $FIELDS = array(
|
||||||
'login'
|
'login'
|
||||||
@ -49,7 +49,7 @@ class Users extends DolibarrApi
|
|||||||
$this->useraccount = new User($this->db);
|
$this->useraccount = new User($this->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List Users
|
* List Users
|
||||||
*
|
*
|
||||||
@ -63,24 +63,24 @@ class Users extends DolibarrApi
|
|||||||
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
|
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
|
||||||
* @return array Array of User objects
|
* @return array Array of User objects
|
||||||
*/
|
*/
|
||||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $user_ids = 0, $sqlfilters = '') {
|
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = 0, $sqlfilters = '') {
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|
||||||
if(! DolibarrApiAccess::$user->rights->user->user->lire) {
|
if(! DolibarrApiAccess::$user->rights->user->user->lire) {
|
||||||
throw new RestException(401, "You are not allowed to read list of users");
|
throw new RestException(401, "You are not allowed to read list of users");
|
||||||
}
|
}
|
||||||
|
|
||||||
// case of external user, $societe param is ignored and replaced by user's socid
|
// case of external user, $societe param is ignored and replaced by user's socid
|
||||||
//$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe;
|
//$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe;
|
||||||
|
|
||||||
$sql = "SELECT t.rowid";
|
$sql = "SELECT t.rowid";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."user as t";
|
$sql.= " FROM ".MAIN_DB_PREFIX."user as t";
|
||||||
$sql.= ' WHERE t.entity IN ('.getEntity('user').')';
|
$sql.= ' WHERE t.entity IN ('.getEntity('user').')';
|
||||||
if ($user_ids) $sql.=" AND t.rowid IN (".$user_ids.")";
|
if ($user_ids) $sql.=" AND t.rowid IN (".$user_ids.")";
|
||||||
// Add sql filters
|
// Add sql filters
|
||||||
if ($sqlfilters)
|
if ($sqlfilters)
|
||||||
{
|
{
|
||||||
if (! DolibarrApi::_checkFilters($sqlfilters))
|
if (! DolibarrApi::_checkFilters($sqlfilters))
|
||||||
{
|
{
|
||||||
@ -89,7 +89,7 @@ class Users extends DolibarrApi
|
|||||||
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
||||||
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql.= $db->order($sortfield, $sortorder);
|
$sql.= $db->order($sortfield, $sortorder);
|
||||||
if ($limit) {
|
if ($limit) {
|
||||||
if ($page < 0)
|
if ($page < 0)
|
||||||
@ -97,12 +97,12 @@ class Users extends DolibarrApi
|
|||||||
$page = 0;
|
$page = 0;
|
||||||
}
|
}
|
||||||
$offset = $limit * $page;
|
$offset = $limit * $page;
|
||||||
|
|
||||||
$sql.= $db->plimit($limit + 1, $offset);
|
$sql.= $db->plimit($limit + 1, $offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $db->query($sql);
|
$result = $db->query($sql);
|
||||||
|
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$num = $db->num_rows($result);
|
$num = $db->num_rows($result);
|
||||||
@ -125,7 +125,7 @@ class Users extends DolibarrApi
|
|||||||
}
|
}
|
||||||
return $obj_ret;
|
return $obj_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get properties of an user object
|
* Get properties of an user object
|
||||||
*
|
*
|
||||||
@ -133,7 +133,7 @@ class Users extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @param int $id ID of user
|
* @param int $id ID of user
|
||||||
* @return array|mixed data without useless information
|
* @return array|mixed data without useless information
|
||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function get($id) {
|
function get($id) {
|
||||||
@ -154,8 +154,8 @@ class Users extends DolibarrApi
|
|||||||
|
|
||||||
return $this->_cleanObjectDatas($this->useraccount);
|
return $this->_cleanObjectDatas($this->useraccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create user account
|
* Create user account
|
||||||
*
|
*
|
||||||
@ -185,14 +185,14 @@ class Users extends DolibarrApi
|
|||||||
}
|
}
|
||||||
return $this->useraccount->id;
|
return $this->useraccount->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update account
|
* Update account
|
||||||
*
|
*
|
||||||
* @param int $id Id of account to update
|
* @param int $id Id of account to update
|
||||||
* @param array $request_data Datas
|
* @param array $request_data Datas
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function put($id, $request_data = NULL) {
|
function put($id, $request_data = NULL) {
|
||||||
//if (!DolibarrApiAccess::$user->rights->user->user->creer) {
|
//if (!DolibarrApiAccess::$user->rights->user->user->creer) {
|
||||||
@ -228,7 +228,7 @@ class Users extends DolibarrApi
|
|||||||
* @param int $id User ID
|
* @param int $id User ID
|
||||||
* @param int $group Group ID
|
* @param int $group Group ID
|
||||||
* @return int 1 if success
|
* @return int 1 if success
|
||||||
*
|
*
|
||||||
* @url GET {id}/setGroup/{group}
|
* @url GET {id}/setGroup/{group}
|
||||||
*/
|
*/
|
||||||
function setGroup($id, $group) {
|
function setGroup($id, $group) {
|
||||||
@ -240,18 +240,18 @@ class Users extends DolibarrApi
|
|||||||
{
|
{
|
||||||
throw new RestException(404, 'User not found');
|
throw new RestException(404, 'User not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
|
if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user'))
|
||||||
{
|
{
|
||||||
throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->useraccount->SetInGroup($group,1);
|
$result = $this->useraccount->SetInGroup($group,1);
|
||||||
if (! ($result > 0))
|
if (! ($result > 0))
|
||||||
{
|
{
|
||||||
throw new RestException(500, $this->useraccount->error);
|
throw new RestException(500, $this->useraccount->error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,25 +286,25 @@ class Users extends DolibarrApi
|
|||||||
* @return array Array of cleaned object properties
|
* @return array Array of cleaned object properties
|
||||||
*/
|
*/
|
||||||
function _cleanObjectDatas($object) {
|
function _cleanObjectDatas($object) {
|
||||||
|
|
||||||
$object = parent::_cleanObjectDatas($object);
|
$object = parent::_cleanObjectDatas($object);
|
||||||
|
|
||||||
unset($object->default_values);
|
unset($object->default_values);
|
||||||
unset($object->lastsearch_values);
|
unset($object->lastsearch_values);
|
||||||
unset($object->lastsearch_values_tmp);
|
unset($object->lastsearch_values_tmp);
|
||||||
|
|
||||||
unset($object->total_ht);
|
unset($object->total_ht);
|
||||||
unset($object->total_tva);
|
unset($object->total_tva);
|
||||||
unset($object->total_localtax1);
|
unset($object->total_localtax1);
|
||||||
unset($object->total_localtax2);
|
unset($object->total_localtax2);
|
||||||
unset($object->total_ttc);
|
unset($object->total_ttc);
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate fields before create or update object
|
* Validate fields before create or update object
|
||||||
*
|
*
|
||||||
* @param array|null $data Data to validate
|
* @param array|null $data Data to validate
|
||||||
* @return array
|
* @return array
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user