Maxi debug on REST APIs
This commit is contained in:
parent
0ff21f0bee
commit
761a795294
@ -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;
|
||||
|
||||
|
||||
@ -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'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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