Merge remote-tracking branch 'refs/remotes/Dolibarr/develop' into develop-work-on-warehouse-status
This commit is contained in:
commit
c3b43e18d1
@ -143,7 +143,7 @@ class Members extends DolibarrApi
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve member list : '.$member->error);
|
||||
throw new RestException(503, 'Error when retrieve member list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No member found');
|
||||
@ -289,9 +289,6 @@ class Members extends DolibarrApi
|
||||
*
|
||||
* @param object $object Object to clean
|
||||
* @return array Array of cleaned object properties
|
||||
*
|
||||
* @todo use an array for properties to clean
|
||||
*
|
||||
*/
|
||||
function _cleanObjectDatas($object) {
|
||||
|
||||
|
||||
@ -135,7 +135,7 @@ class Subscriptions extends DolibarrApi
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve subscription list : '.$subscription->error);
|
||||
throw new RestException(503, 'Error when retrieve subscription list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No Subscription found');
|
||||
|
||||
@ -81,9 +81,6 @@ class DolibarrApi
|
||||
*
|
||||
* @param object $object Object to clean
|
||||
* @return array Array of cleaned object properties
|
||||
*
|
||||
* @todo use an array for properties to clean
|
||||
*
|
||||
*/
|
||||
function _cleanObjectDatas($object) {
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ class DictionnaryCountries extends DolibarrApi
|
||||
* @param int $page Page number (starting from zero)
|
||||
* @param string $filter To filter the countries by name
|
||||
* @param string $lang Code of the language the label of the countries must be translated to
|
||||
* @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.code:like:'A%') and (t.active:>=:0)"
|
||||
* @return List of countries
|
||||
*
|
||||
* @throws RestException
|
||||
|
||||
@ -47,7 +47,7 @@ class DictionnaryTowns extends DolibarrApi
|
||||
* @param int $page Page number (starting from zero)
|
||||
* @param string $zipcode To filter on zipcode
|
||||
* @param string $town To filter on city name
|
||||
* @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.code:like:'A%') and (t.active:>=:0)"
|
||||
* @return List of towns
|
||||
*
|
||||
* @throws RestException
|
||||
|
||||
@ -115,6 +115,10 @@ foreach ($modulesdir as $dir)
|
||||
elseif ($module == 'stock') {
|
||||
$moduledirforclass = 'product/stock';
|
||||
}
|
||||
elseif ($module == 'fournisseur') {
|
||||
$moduledirforclass = 'fourn';
|
||||
}
|
||||
//dol_syslog("Found module file ".$file." - module=".$module." - moduledirforclass=".$moduledirforclass);
|
||||
|
||||
// Defined if module is enabled
|
||||
$enabled=true;
|
||||
@ -137,6 +141,8 @@ foreach ($modulesdir as $dir)
|
||||
{
|
||||
while (($file_searched = readdir($handle_part))!==false)
|
||||
{
|
||||
if ($file_searched == 'api_access.class.php') continue;
|
||||
|
||||
// Support of the deprecated API.
|
||||
if (is_readable($dir_part.$file_searched) && preg_match("/^api_deprecated_(.*)\.class\.php$/i",$file_searched,$reg))
|
||||
{
|
||||
@ -144,19 +150,28 @@ foreach ($modulesdir as $dir)
|
||||
require_once $dir_part.$file_searched;
|
||||
if (class_exists($classname))
|
||||
{
|
||||
dol_syslog("Found deprecated API by index.php: classname=".$classname." into ".$dir." - ".$dir_part.$file_searched);
|
||||
//dol_syslog("Found deprecated API by index.php: classname=".$classname." for module ".$dir." into ".$dir_part.$file_searched);
|
||||
$api->r->addAPIClass($classname, '/');
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog("We found an api_xxx file (".$file_searched.") but class ".$classname." does not exists after loading file", LOG_WARNING);
|
||||
}
|
||||
}
|
||||
elseif (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i",$file_searched,$reg))
|
||||
{
|
||||
$classname = ucwords($reg[1]);
|
||||
$classname = str_replace('_', '', $classname);
|
||||
require_once $dir_part.$file_searched;
|
||||
if (class_exists($classname))
|
||||
{
|
||||
dol_syslog("Found API by index.php: classname=".$classname." into ".$dir." - ".$dir_part.$file_searched);
|
||||
//dol_syslog("Found API by index.php: classname=".$classname." for module ".$dir." into ".$dir_part.$file_searched);
|
||||
$listofapis[] = $classname;
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog("We found an api_xxx file (".$file_searched.") but class ".$classname." does not exists after loading file", LOG_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ class Categories extends DolibarrApi
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve category list : '.$category_static->error);
|
||||
throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No category found');
|
||||
@ -243,7 +243,7 @@ class Categories extends DolibarrApi
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve category list : '.$category_static->error);
|
||||
throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No category found');
|
||||
@ -346,9 +346,6 @@ class Categories extends DolibarrApi
|
||||
*
|
||||
* @param Categorie $object Object to clean
|
||||
* @return array Array of cleaned object properties
|
||||
*
|
||||
* @todo use an array for properties to clean
|
||||
*
|
||||
*/
|
||||
function _cleanObjectDatas($object) {
|
||||
|
||||
|
||||
@ -152,13 +152,13 @@ class CategoryApi extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$category_static = new Categorie($db);
|
||||
if($category_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($category_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($category_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve category list : '.$category_static->error);
|
||||
throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No category found');
|
||||
@ -233,13 +233,13 @@ class CategoryApi extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$category_static = new Categorie($db);
|
||||
if($category_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($category_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($category_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve category list : '.$category_static->error);
|
||||
throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No category found');
|
||||
|
||||
@ -146,13 +146,13 @@ class AgendaEvents extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$actioncomm_static = new ActionComm($db);
|
||||
if($actioncomm_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($actioncomm_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($actioncomm_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve Agenda Event list');
|
||||
throw new RestException(503, 'Error when retrieve Agenda Event list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No Agenda Event found');
|
||||
|
||||
@ -385,7 +385,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE cf.fk_soc = s.rowid";
|
||||
$sql.= " AND cf.fk_statut = 0";
|
||||
$sql.= " AND cf.entity IN (".getEntity('commande_fournisseur', 1).")";
|
||||
$sql.= " AND cf.entity IN (".getEntity('supplier_order', 1).")";
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
if ($socid) $sql.= " AND cf.fk_soc = ".$socid;
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ class Proposals extends DolibarrApi
|
||||
* @param int $limit Limit for list
|
||||
* @param int $page Page number
|
||||
* @param string $thirdparty_ids Thirdparty ids to filter commercial proposal of. Example: '1' or '1,2,3' {@pattern /^[0-9,]*$/i}
|
||||
* @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.datec:<:'20160101')"
|
||||
* @return array Array of order objects
|
||||
*/
|
||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids = '', $sqlfilters = '') {
|
||||
@ -150,13 +150,13 @@ class Proposals extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$propal_static = new Propal($db);
|
||||
if($propal_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($propal_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($propal_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve propal list');
|
||||
throw new RestException(503, 'Error when retrieve propal list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No order found');
|
||||
|
||||
@ -167,13 +167,13 @@ class CommandeApi extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$commande_static = new Commande($db);
|
||||
if($commande_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($commande_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($commande_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve commande list');
|
||||
throw new RestException(503, 'Error when retrieve commande list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No commande found');
|
||||
|
||||
@ -94,6 +94,8 @@ class Orders extends DolibarrApi
|
||||
* @param string $thirdparty_ids Thirdparty ids to filter orders of. {@example '1' or '1,2,3'} {@pattern /^[0-9,]*$/i}
|
||||
* @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 order objects
|
||||
*
|
||||
* @throws RestException
|
||||
*/
|
||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') {
|
||||
global $db, $conf;
|
||||
@ -153,13 +155,13 @@ class Orders extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$commande_static = new Commande($db);
|
||||
if($commande_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($commande_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($commande_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve commande list');
|
||||
throw new RestException(503, 'Error when retrieve commande list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No order found');
|
||||
|
||||
@ -165,13 +165,13 @@ class InvoiceApi extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$invoice_static = new Facture($db);
|
||||
if($invoice_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($invoice_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($invoice_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve invoice list');
|
||||
throw new RestException(503, 'Error when retrieve invoice list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No invoice found');
|
||||
|
||||
@ -83,23 +83,23 @@ class Invoices extends DolibarrApi
|
||||
*
|
||||
* Get a list of invoices
|
||||
*
|
||||
* @param string $sortfield Sort field
|
||||
* @param string $sortorder Sort order
|
||||
* @param int $limit Limit for list
|
||||
* @param int $page Page number
|
||||
* @param int $socid Filter list with thirdparty ID
|
||||
* @param string $status Filter by invoice status : draft | unpaid | paid | cancelled
|
||||
* @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 invoice objects
|
||||
* @param string $sortfield Sort field
|
||||
* @param string $sortorder Sort order
|
||||
* @param int $limit Limit for list
|
||||
* @param int $page Page number
|
||||
* @param string $thirdparty_ids Thirdparty ids to filter orders of. {@example '1' or '1,2,3'} {@pattern /^[0-9,]*$/i}
|
||||
* @param string $status Filter by invoice status : draft | unpaid | paid | cancelled
|
||||
* @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 invoice objects
|
||||
*
|
||||
* @throws RestException
|
||||
*/
|
||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $socid=0, $status='', $sqlfilters = '') {
|
||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
|
||||
global $db, $conf;
|
||||
|
||||
$obj_ret = array();
|
||||
|
||||
$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $socid;
|
||||
// case of external user, $thirdpartyid param is ignored and replaced by user's socid
|
||||
$socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $thirdparty_ids;
|
||||
|
||||
// If the internal user must only see his customers, force searching by him
|
||||
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
|
||||
@ -112,7 +112,7 @@ class Invoices extends DolibarrApi
|
||||
|
||||
$sql.= ' WHERE t.entity IN ('.getEntity('facture', 1).')';
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
|
||||
if ($socid) $sql.= " AND t.fk_soc = ".$socid;
|
||||
if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")";
|
||||
if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
|
||||
|
||||
// Filter by status
|
||||
@ -156,13 +156,13 @@ class Invoices extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$invoice_static = new Facture($db);
|
||||
if($invoice_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($invoice_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($invoice_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve invoice list');
|
||||
throw new RestException(503, 'Error when retrieve invoice list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No invoice found');
|
||||
@ -255,7 +255,7 @@ class Invoices extends DolibarrApi
|
||||
throw new RestException(404, 'Invoice not found');
|
||||
}
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('facture',$this->facture->id)) {
|
||||
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ class Invoices extends DolibarrApi
|
||||
return array(
|
||||
'success' => array(
|
||||
'code' => 200,
|
||||
'message' => 'Facture deleted'
|
||||
'message' => 'Invoice deleted'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -1183,10 +1183,10 @@ else
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans("ExportCardToFormat").'</td><td colspan="3">';
|
||||
print $langs->trans("VCard").'</td><td colspan="3">';
|
||||
print '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'">';
|
||||
print img_picto($langs->trans("VCard"),'vcard.png').' ';
|
||||
print $langs->trans("VCard");
|
||||
print img_picto($langs->trans("Download"),'vcard.png').' ';
|
||||
print $langs->trans("Download");
|
||||
print '</a>';
|
||||
print '</td></tr>';
|
||||
|
||||
|
||||
@ -1390,7 +1390,7 @@ function show_subsidiaries($conf,$langs,$db,$object)
|
||||
{
|
||||
$socstatic = new Societe($db);
|
||||
|
||||
print load_fiche_titre($langs->trans("Subsidiaries"));
|
||||
print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
|
||||
print "\n".'<table class="noborder" width="100%">'."\n";
|
||||
|
||||
print '<tr class="liste_titre"><td>'.$langs->trans("Company").'</td>';
|
||||
|
||||
@ -380,7 +380,7 @@ class modFournisseur extends DolibarrModules
|
||||
$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
|
||||
$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
|
||||
$this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
|
||||
$this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('facture_fournisseur',1).')';
|
||||
$this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice',1).')';
|
||||
if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
|
||||
|
||||
$r++;
|
||||
@ -443,7 +443,7 @@ class modFournisseur extends DolibarrModules
|
||||
$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
|
||||
$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
|
||||
$this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid';
|
||||
$this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('facture_fournisseur',1).')';
|
||||
$this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice',1).')';
|
||||
if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
|
||||
|
||||
// Order
|
||||
@ -552,7 +552,7 @@ class modFournisseur extends DolibarrModules
|
||||
$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields as extraline ON fd.rowid = extraline.fk_object';
|
||||
$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
|
||||
$this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
|
||||
$this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('commande_fournisseur',1).')';
|
||||
$this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_order',1).')';
|
||||
if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
|
||||
}
|
||||
|
||||
|
||||
@ -144,13 +144,13 @@ class ExpenseReports extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$expensereport_static = new ExpenseReport($db);
|
||||
if($expensereport_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($expensereport_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($expensereport_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve Expense Report list');
|
||||
throw new RestException(503, 'Error when retrieve Expense Report list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No Expense Report found');
|
||||
|
||||
310
htdocs/fourn/class/api_supplier_invoices.class.php
Normal file
310
htdocs/fourn/class/api_supplier_invoices.class.php
Normal file
@ -0,0 +1,310 @@
|
||||
<?php
|
||||
/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
||||
* Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use Luracast\Restler\RestException;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
|
||||
|
||||
/**
|
||||
* API class for supplier invoices
|
||||
*
|
||||
* @access protected
|
||||
* @class DolibarrApiAccess {@requires user,external}
|
||||
*/
|
||||
class SupplierInvoices extends DolibarrApi
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var array $FIELDS Mandatory fields, checked when create and update object
|
||||
*/
|
||||
static $FIELDS = array(
|
||||
'socid'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var FactureFournisseur $invoice {@type FactureFournisseur}
|
||||
*/
|
||||
public $invoice;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
global $db, $conf;
|
||||
$this->db = $db;
|
||||
$this->invoice = new FactureFournisseur($this->db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get properties of a supplier invoice object
|
||||
*
|
||||
* Return an array with supplier invoice information
|
||||
*
|
||||
* @param int $id ID of supplier invoice
|
||||
* @return array|mixed data without useless information
|
||||
*
|
||||
* @throws RestException
|
||||
*/
|
||||
function get($id)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->fournisseur->facture->lire) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
$result = $this->invoice->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Supplier invoice not found');
|
||||
}
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
return $this->_cleanObjectDatas($this->invoice);
|
||||
}
|
||||
|
||||
/**
|
||||
* List invoices
|
||||
*
|
||||
* Get a list of supplier invoices
|
||||
*
|
||||
* @param string $sortfield Sort field
|
||||
* @param string $sortorder Sort order
|
||||
* @param int $limit Limit for list
|
||||
* @param int $page Page number
|
||||
* @param string $thirdparty_ids Thirdparty ids to filter invoices of. {@example '1' or '1,2,3'} {@pattern /^[0-9,]*$/i}
|
||||
* @param string $status Filter by invoice status : draft | unpaid | paid | cancelled
|
||||
* @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 invoice objects
|
||||
*
|
||||
* @throws RestException
|
||||
*/
|
||||
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
|
||||
global $db, $conf;
|
||||
|
||||
$obj_ret = array();
|
||||
// case of external user, $thirdpartyid param is ignored and replaced by user's socid
|
||||
$socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $thirdparty_ids;
|
||||
|
||||
// If the internal user must only see his customers, force searching by him
|
||||
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
|
||||
|
||||
$sql = "SELECT t.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)
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as t";
|
||||
|
||||
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 t.entity IN ('.getEntity('supplier_invoice', 1).')';
|
||||
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc";
|
||||
if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")";
|
||||
if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
|
||||
|
||||
// Filter by status
|
||||
if ($status == 'draft') $sql.= " AND t.fk_statut IN (0)";
|
||||
if ($status == 'unpaid') $sql.= " AND t.fk_statut IN (1)";
|
||||
if ($status == 'paid') $sql.= " AND t.fk_statut IN (2)";
|
||||
if ($status == 'cancelled') $sql.= " AND t.fk_statut IN (3)";
|
||||
// Insert sale filter
|
||||
if ($search_sale > 0)
|
||||
{
|
||||
$sql .= " AND sc.fk_user = ".$search_sale;
|
||||
}
|
||||
// Add sql filters
|
||||
if ($sqlfilters)
|
||||
{
|
||||
if (! DolibarrApi::_checkFilters($sqlfilters))
|
||||
{
|
||||
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
|
||||
}
|
||||
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
||||
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
|
||||
}
|
||||
|
||||
$sql.= $db->order($sortfield, $sortorder);
|
||||
if ($limit) {
|
||||
if ($page < 0)
|
||||
{
|
||||
$page = 0;
|
||||
}
|
||||
$offset = $limit * $page;
|
||||
|
||||
$sql.= $db->plimit($limit + 1, $offset);
|
||||
}
|
||||
|
||||
$result = $db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $db->num_rows($result);
|
||||
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
|
||||
{
|
||||
$obj = $db->fetch_object($result);
|
||||
$invoice_static = new FactureFournisseur($db);
|
||||
if($invoice_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = $this->_cleanObjectDatas($invoice_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve supplier invoice list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No supplier invoice found');
|
||||
}
|
||||
return $obj_ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create supplier invoice object
|
||||
*
|
||||
* @param array $request_data Request datas
|
||||
* @return int ID of supplier invoice
|
||||
*/
|
||||
function post($request_data = NULL)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
|
||||
throw new RestException(401, "Insuffisant rights");
|
||||
}
|
||||
// Check mandatory fields
|
||||
$result = $this->_validate($request_data);
|
||||
|
||||
foreach($request_data as $field => $value) {
|
||||
$this->invoice->$field = $value;
|
||||
}
|
||||
if(! array_keys($request_data,'date')) {
|
||||
$this->invoice->date = dol_now();
|
||||
}
|
||||
/* We keep lines as an array
|
||||
if (isset($request_data["lines"])) {
|
||||
$lines = array();
|
||||
foreach ($request_data["lines"] as $line) {
|
||||
array_push($lines, (object) $line);
|
||||
}
|
||||
$this->invoice->lines = $lines;
|
||||
}*/
|
||||
|
||||
if ($this->invoice->create(DolibarrApiAccess::$user) <= 0) {
|
||||
$errormsg = $this->invoice->error;
|
||||
throw new RestException(500, $errormsg ? $errormsg : "Error while creating order");
|
||||
}
|
||||
return $this->invoice->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update supplier invoice
|
||||
*
|
||||
* @param int $id Id of supplier invoice to update
|
||||
* @param array $request_data Datas
|
||||
* @return int
|
||||
*/
|
||||
function put($id, $request_data = NULL)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->fournisseur->facture->creer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
|
||||
$result = $this->invoice->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Supplier invoice not found');
|
||||
}
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
foreach($request_data as $field => $value) {
|
||||
if ($field == 'id') continue;
|
||||
$this->invoice->$field = $value;
|
||||
}
|
||||
|
||||
if($this->invoice->update($id, DolibarrApiAccess::$user))
|
||||
return $this->get ($id);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete supplier invoice
|
||||
*
|
||||
* @param int $id Supplier invoice ID
|
||||
* @return type
|
||||
*/
|
||||
function delete($id)
|
||||
{
|
||||
if(! DolibarrApiAccess::$user->rights->fournisseur->facture->supprimer) {
|
||||
throw new RestException(401);
|
||||
}
|
||||
$result = $this->invoice->fetch($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Supplier invoice not found');
|
||||
}
|
||||
|
||||
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
|
||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||
}
|
||||
|
||||
if( $this->invoice->delete($id) < 0)
|
||||
{
|
||||
throw new RestException(500);
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => array(
|
||||
'code' => 200,
|
||||
'message' => 'Supplier invoice deleted'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean sensible object datas
|
||||
*
|
||||
* @param Object $object Object to clean
|
||||
* @return array Array of cleaned object properties
|
||||
*/
|
||||
function _cleanObjectDatas($object) {
|
||||
|
||||
$object = parent::_cleanObjectDatas($object);
|
||||
|
||||
unset($object->rowid);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate fields before create or update object
|
||||
*
|
||||
* @param array $data Datas to validate
|
||||
* @return array
|
||||
*
|
||||
* @throws RestException
|
||||
*/
|
||||
function _validate($data)
|
||||
{
|
||||
$invoice = array();
|
||||
foreach (Invoices::$FIELDS as $field) {
|
||||
if (!isset($data[$field]))
|
||||
throw new RestException(400, "$field field missing");
|
||||
$invoice[$field] = $data[$field];
|
||||
}
|
||||
return $invoice;
|
||||
}
|
||||
}
|
||||
@ -208,7 +208,7 @@ class FactureFournisseur extends CommonInvoice
|
||||
* Create supplier invoice into database
|
||||
*
|
||||
* @param User $user object utilisateur qui cree
|
||||
* @return int id facture si ok, < 0 si erreur
|
||||
* @return int Id invoice created if OK, < 0 if KO
|
||||
*/
|
||||
public function create($user)
|
||||
{
|
||||
@ -313,32 +313,84 @@ class FactureFournisseur extends CommonInvoice
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->lines as $i => $val)
|
||||
{
|
||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn)';
|
||||
$sql .= ' VALUES ('.$this->id.');';
|
||||
|
||||
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||
$resql_insert=$this->db->query($sql);
|
||||
if ($resql_insert)
|
||||
if (count($this->lines) && is_object($this->lines[0])) // If this->lines is array of InvoiceLines (preferred mode)
|
||||
{
|
||||
dol_syslog("There is ".count($this->lines)." lines that are invoice lines objects");
|
||||
foreach ($this->lines as $i => $val)
|
||||
{
|
||||
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det');
|
||||
|
||||
$this->updateline(
|
||||
$idligne,
|
||||
$this->lines[$i]->description,
|
||||
$this->lines[$i]->pu_ht,
|
||||
$this->lines[$i]->tva_tx,
|
||||
$this->lines[$i]->localtax1_tx,
|
||||
$this->lines[$i]->localtax2_tx,
|
||||
$this->lines[$i]->qty,
|
||||
$this->lines[$i]->fk_product,
|
||||
'HT',
|
||||
(! empty($this->lines[$i]->info_bits)?$this->lines[$i]->info_bits:''),
|
||||
$this->lines[$i]->product_type
|
||||
);
|
||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn)';
|
||||
$sql .= ' VALUES ('.$this->id.')';
|
||||
|
||||
$resql_insert=$this->db->query($sql);
|
||||
if ($resql_insert)
|
||||
{
|
||||
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det');
|
||||
|
||||
var_dump($this->lines[$i]);exit;
|
||||
$this->updateline(
|
||||
$idligne,
|
||||
$this->lines[$i]->description,
|
||||
$this->lines[$i]->pu_ht,
|
||||
$this->lines[$i]->tva_tx,
|
||||
$this->lines[$i]->localtax1_tx,
|
||||
$this->lines[$i]->localtax2_tx,
|
||||
$this->lines[$i]->qty,
|
||||
$this->lines[$i]->fk_product,
|
||||
'HT',
|
||||
(! empty($this->lines[$i]->info_bits)?$this->lines[$i]->info_bits:''),
|
||||
$this->lines[$i]->product_type
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
$this->db->rollback();
|
||||
return -5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else // If this->lines is an array of invoice line arrays
|
||||
{
|
||||
dol_syslog("There is ".count($this->lines)." lines that are array lines");
|
||||
foreach ($this->lines as $i => $val)
|
||||
{
|
||||
$line = $this->lines[$i];
|
||||
|
||||
// Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
|
||||
//if (! is_object($line)) $line=json_decode(json_encode($line), FALSE); // convert recursively array into object.
|
||||
if (! is_object($line)) $line = (object) $line;
|
||||
|
||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn)';
|
||||
$sql .= ' VALUES ('.$this->id.')';
|
||||
|
||||
$resql_insert=$this->db->query($sql);
|
||||
if ($resql_insert)
|
||||
{
|
||||
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det');
|
||||
|
||||
$this->updateline(
|
||||
$idligne,
|
||||
$line->description,
|
||||
$line->pu_ht,
|
||||
$line->tva_tx,
|
||||
$line->localtax1_tx,
|
||||
$line->localtax2_tx,
|
||||
$line->qty,
|
||||
$line->fk_product,
|
||||
'HT',
|
||||
(! empty($line->info_bits)?$line->info_bits:''),
|
||||
$line->product_type
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
$this->db->rollback();
|
||||
return -5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update total price
|
||||
$result=$this->update_price();
|
||||
if ($result > 0)
|
||||
|
||||
@ -293,7 +293,7 @@ if ($search_user > 0)
|
||||
$sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
|
||||
}
|
||||
$sql.= ' WHERE cf.fk_soc = s.rowid';
|
||||
$sql.= ' AND cf.entity IN ('.getEntity('commande_fournisseur', 1).')';
|
||||
$sql.= ' AND cf.entity IN ('.getEntity('supplier_order', 1).')';
|
||||
if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
if ($search_ref) $sql .= natural_search('cf.ref', $search_ref);
|
||||
|
||||
@ -248,7 +248,7 @@ llxHeader('',$langs->trans("SuppliersInvoices"),'EN:Suppliers_Invoices|FR:Factur
|
||||
$sql = "SELECT";
|
||||
if ($search_all || $search_product_category > 0) $sql = 'SELECT DISTINCT';
|
||||
$sql.= " f.rowid as facid, f.ref, f.ref_supplier, f.datef, f.date_lim_reglement as datelimite, f.fk_mode_reglement,";
|
||||
$sql.= " f.total_ht, f.total_ttc, f.total_tva as total_vat, f.paye as paye, f.fk_statut as fk_statut, f.libelle as label,";
|
||||
$sql.= " f.total_ht, f.total_ttc, f.total_tva as total_vat, f.paye as paye, f.fk_statut as fk_statut, f.libelle as label, f.datec as date_creation, f.tms as date_update,";
|
||||
$sql.= " s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client,";
|
||||
$sql.= " typent.code as typent_code,";
|
||||
$sql.= " state.code_departement as state_code, state.nom as state_name,";
|
||||
|
||||
@ -154,13 +154,13 @@ class ProductApi extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$product_static = new Product($db);
|
||||
if($product_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($product_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($product_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve product list');
|
||||
throw new RestException(503, 'Error when retrieve product list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No product found');
|
||||
@ -240,13 +240,13 @@ class ProductApi extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$product_static = new Product($db);
|
||||
if($product_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($product_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($product_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve product list');
|
||||
throw new RestException(503, 'Error when retrieve product list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No product found');
|
||||
|
||||
@ -151,13 +151,13 @@ class Products extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$product_static = new Product($db);
|
||||
if($product_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($product_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($product_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve product list');
|
||||
throw new RestException(503, 'Error when retrieve product list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No product found');
|
||||
|
||||
@ -2054,7 +2054,7 @@ class Product extends CommonObject
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE c.rowid = cd.fk_commande";
|
||||
$sql.= " AND c.fk_soc = s.rowid";
|
||||
$sql.= " AND c.entity IN (".getEntity('commande_fournisseur', 1).")";
|
||||
$sql.= " AND c.entity IN (".getEntity('supplier_order', 1).")";
|
||||
$sql.= " AND cd.fk_product = ".$this->id;
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid;
|
||||
@ -2142,7 +2142,7 @@ class Product extends CommonObject
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE cf.rowid = fd.fk_commande";
|
||||
$sql.= " AND cf.fk_soc = s.rowid";
|
||||
$sql.= " AND cf.entity IN (".getEntity('commande_fournisseur', 1).")";
|
||||
$sql.= " AND cf.entity IN (".getEntity('supplier_order', 1).")";
|
||||
$sql.= " AND fd.fk_product = ".$this->id;
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
if ($socid > 0) $sql.= " AND cf.fk_soc = ".$socid;
|
||||
@ -2530,7 +2530,7 @@ class Product extends CommonObject
|
||||
else $sql.=" AND d.fk_product > 0";
|
||||
if ($filteronproducttype >= 0) $sql.= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype;
|
||||
$sql.= " AND c.fk_soc = s.rowid";
|
||||
$sql.= " AND c.entity IN (".getEntity('commande_fournisseur', 1).")";
|
||||
$sql.= " AND c.entity IN (".getEntity('supplier_order', 1).")";
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid;
|
||||
$sql.= " GROUP BY date_format(c.date_commande,'%Y%m')";
|
||||
|
||||
@ -144,7 +144,7 @@ class StockMovements extends DolibarrApi
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve stock movement list : '.$stockmovement_static->error);
|
||||
throw new RestException(503, 'Error when retrieve stock movement list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No stock movement found');
|
||||
@ -277,9 +277,6 @@ class StockMovements extends DolibarrApi
|
||||
*
|
||||
* @param MouvementStock $object Object to clean
|
||||
* @return array Array of cleaned object properties
|
||||
*
|
||||
* @todo use an array for properties to clean
|
||||
*
|
||||
*/
|
||||
function _cleanObjectDatas($object) {
|
||||
|
||||
|
||||
@ -142,7 +142,7 @@ class Warehouses extends DolibarrApi
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve warehouse list : '.$warehouse_static->error);
|
||||
throw new RestException(503, 'Error when retrieve warehouse list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No warehouse found');
|
||||
@ -246,9 +246,6 @@ class Warehouses extends DolibarrApi
|
||||
*
|
||||
* @param Entrepot $object Object to clean
|
||||
* @return array Array of cleaned object properties
|
||||
*
|
||||
* @todo use an array for properties to clean
|
||||
*
|
||||
*/
|
||||
function _cleanObjectDatas($object) {
|
||||
|
||||
|
||||
@ -352,14 +352,14 @@ if ($usevirtualstock)
|
||||
$sqlCommandesFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd";
|
||||
$sqlCommandesFourn.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
|
||||
$sqlCommandesFourn.= " WHERE c.rowid = cd.fk_commande";
|
||||
$sqlCommandesFourn.= " AND c.entity IN (".getEntity('commande_fournisseur', 1).")";
|
||||
$sqlCommandesFourn.= " AND c.entity IN (".getEntity('supplier_order', 1).")";
|
||||
$sqlCommandesFourn.= " AND cd.fk_product = p.rowid";
|
||||
$sqlCommandesFourn.= " AND c.fk_statut IN (3,4))";
|
||||
|
||||
$sqlReceptionFourn = "(SELECT ".$db->ifsql("SUM(fd.qty) IS NULL", "0", "SUM(fd.qty)")." as qty";
|
||||
$sqlReceptionFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
|
||||
$sqlReceptionFourn.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd ON (fd.fk_commande = cf.rowid)";
|
||||
$sqlReceptionFourn.= " WHERE cf.entity IN (".getEntity('commande_fournisseur', 1).")";
|
||||
$sqlReceptionFourn.= " WHERE cf.entity IN (".getEntity('supplier_order', 1).")";
|
||||
$sqlReceptionFourn.= " AND fd.fk_product = p.rowid";
|
||||
$sqlReceptionFourn.= " AND cf.fk_statut IN (3,4))";
|
||||
|
||||
|
||||
@ -162,7 +162,7 @@ class Projects extends DolibarrApi
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve project list');
|
||||
throw new RestException(503, 'Error when retrieve project list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No project found');
|
||||
@ -531,9 +531,6 @@ class Projects extends DolibarrApi
|
||||
*
|
||||
* @param object $object Object to clean
|
||||
* @return array Array of cleaned object properties
|
||||
*
|
||||
* @todo use an array for properties to clean
|
||||
*
|
||||
*/
|
||||
function _cleanObjectDatas($object) {
|
||||
|
||||
|
||||
@ -169,7 +169,7 @@ class Tasks extends DolibarrApi
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve task list');
|
||||
throw new RestException(503, 'Error when retrieve task list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No task found');
|
||||
@ -544,9 +544,6 @@ class Tasks extends DolibarrApi
|
||||
*
|
||||
* @param object $object Object to clean
|
||||
* @return array Array of cleaned object properties
|
||||
*
|
||||
* @todo use an array for properties to clean
|
||||
*
|
||||
*/
|
||||
function _cleanObjectDatas($object) {
|
||||
|
||||
|
||||
@ -160,7 +160,7 @@ class Contacts extends DolibarrApi
|
||||
$contact_static = new Contact($db);
|
||||
if ($contact_static->fetch($obj->rowid))
|
||||
{
|
||||
$obj_ret[] = parent::_cleanObjectDatas($contact_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($contact_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ class ContactApi extends DolibarrApi
|
||||
$contact_static = new Contact($db);
|
||||
if ($contact_static->fetch($obj->rowid))
|
||||
{
|
||||
$obj_ret[] = parent::_cleanObjectDatas($contact_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($contact_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
@ -218,13 +218,13 @@ class ThirdpartyApi extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$soc_static = new Societe($db);
|
||||
if($soc_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($soc_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($soc_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve thirdparties : ' . $sql);
|
||||
throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'Thirdparties not found');
|
||||
|
||||
@ -159,13 +159,13 @@ class Thirdparties extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$soc_static = new Societe($db);
|
||||
if($soc_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($soc_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($soc_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve thirdparties : ' . $sql);
|
||||
throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'Thirdparties not found');
|
||||
|
||||
@ -111,13 +111,13 @@ class Users extends DolibarrApi
|
||||
$obj = $db->fetch_object($result);
|
||||
$user_static = new User($db);
|
||||
if($user_static->fetch($obj->rowid)) {
|
||||
$obj_ret[] = parent::_cleanObjectDatas($user_static);
|
||||
$obj_ret[] = $this->_cleanObjectDatas($user_static);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new RestException(503, 'Error when retrieve User list');
|
||||
throw new RestException(503, 'Error when retrieve User list : '.$db->lasterror());
|
||||
}
|
||||
if( ! count($obj_ret)) {
|
||||
throw new RestException(404, 'No User found');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user