From 0ff21f0beebaef57301faec7840f8e4642c7df27 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 5 Dec 2016 12:04:22 +0100 Subject: [PATCH 1/4] Fix example --- htdocs/comm/propal/class/api_proposals.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index 00850fc7adf..c1b223f6f28 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -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 = '') { From 761a7952949c80b464302b9c7ae087d3a65e8e86 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 5 Dec 2016 13:31:29 +0100 Subject: [PATCH 2/4] Maxi debug on REST APIs --- htdocs/adherents/class/api_members.class.php | 5 +- .../class/api_subscriptions.class.php | 2 +- htdocs/api/class/api.class.php | 3 - .../class/api_dictionnarycountries.class.php | 2 +- .../api/class/api_dictionnarytowns.class.php | 2 +- htdocs/api/index.php | 19 +++- .../categories/class/api_categories.class.php | 7 +- .../class/api_deprecated_category.class.php | 8 +- .../action/class/api_agendaevents.class.php | 4 +- htdocs/comm/index.php | 2 +- .../comm/propal/class/api_proposals.class.php | 4 +- .../class/api_deprecated_commande.class.php | 4 +- htdocs/commande/class/api_orders.class.php | 6 +- .../class/api_deprecated_invoice.class.php | 4 +- .../facture/class/api_invoices.class.php | 32 +++--- htdocs/core/modules/modFournisseur.class.php | 6 +- .../class/api_expensereports.class.php | 4 +- .../fourn/class/fournisseur.facture.class.php | 102 +++++++++++++----- htdocs/fourn/commande/list.php | 2 +- htdocs/fourn/facture/list.php | 2 +- .../class/api_deprecated_product.class.php | 8 +- htdocs/product/class/api_products.class.php | 4 +- htdocs/product/class/product.class.php | 6 +- .../stock/class/api_stockmovements.class.php | 5 +- .../stock/class/api_warehouses.class.php | 5 +- htdocs/product/stock/replenish.php | 4 +- htdocs/projet/class/api_projects.class.php | 5 +- htdocs/projet/class/api_tasks.class.php | 5 +- htdocs/societe/class/api_contacts.class.php | 2 +- .../class/api_deprecated_contact.class.php | 2 +- .../class/api_deprecated_thirdparty.class.php | 4 +- .../societe/class/api_thirdparties.class.php | 4 +- htdocs/user/class/api_users.class.php | 4 +- 33 files changed, 163 insertions(+), 115 deletions(-) diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index 59d52094515..779b5213666 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -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) { diff --git a/htdocs/adherents/class/api_subscriptions.class.php b/htdocs/adherents/class/api_subscriptions.class.php index 10f25e88e42..1917e3b84ed 100644 --- a/htdocs/adherents/class/api_subscriptions.class.php +++ b/htdocs/adherents/class/api_subscriptions.class.php @@ -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'); diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index 75c814860a3..5ffae225df1 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -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) { diff --git a/htdocs/api/class/api_dictionnarycountries.class.php b/htdocs/api/class/api_dictionnarycountries.class.php index 9b7b409ef19..ddb3e2474a9 100644 --- a/htdocs/api/class/api_dictionnarycountries.class.php +++ b/htdocs/api/class/api_dictionnarycountries.class.php @@ -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 diff --git a/htdocs/api/class/api_dictionnarytowns.class.php b/htdocs/api/class/api_dictionnarytowns.class.php index b5813d07792..da58c9109eb 100644 --- a/htdocs/api/class/api_dictionnarytowns.class.php +++ b/htdocs/api/class/api_dictionnarytowns.class.php @@ -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 diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 99ad91adde9..8ad60c4b340 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -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); + } } } } diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index 471c6b2fdde..921198ab1be 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -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) { diff --git a/htdocs/categories/class/api_deprecated_category.class.php b/htdocs/categories/class/api_deprecated_category.class.php index 2cb25b70779..8ec125290c5 100644 --- a/htdocs/categories/class/api_deprecated_category.class.php +++ b/htdocs/categories/class/api_deprecated_category.class.php @@ -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'); diff --git a/htdocs/comm/action/class/api_agendaevents.class.php b/htdocs/comm/action/class/api_agendaevents.class.php index 3c2f84b4700..931283b0ab0 100644 --- a/htdocs/comm/action/class/api_agendaevents.class.php +++ b/htdocs/comm/action/class/api_agendaevents.class.php @@ -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'); diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index ad2bf294e6b..4e99b7072fc 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -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; diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index c1b223f6f28..b4a15c2aa97 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -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'); diff --git a/htdocs/commande/class/api_deprecated_commande.class.php b/htdocs/commande/class/api_deprecated_commande.class.php index b0b22764ec7..f5d799dd477 100644 --- a/htdocs/commande/class/api_deprecated_commande.class.php +++ b/htdocs/commande/class/api_deprecated_commande.class.php @@ -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'); diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 646e9ead270..cc186367588 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -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'); diff --git a/htdocs/compta/facture/class/api_deprecated_invoice.class.php b/htdocs/compta/facture/class/api_deprecated_invoice.class.php index a2706b3150f..b87bb2e9dc0 100644 --- a/htdocs/compta/facture/class/api_deprecated_invoice.class.php +++ b/htdocs/compta/facture/class/api_deprecated_invoice.class.php @@ -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'); diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index e0a2e12695a..888c05bff26 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -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' ) ); } diff --git a/htdocs/core/modules/modFournisseur.class.php b/htdocs/core/modules/modFournisseur.class.php index c0203f7e490..2999bddd1bd 100644 --- a/htdocs/core/modules/modFournisseur.class.php +++ b/htdocs/core/modules/modFournisseur.class.php @@ -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; } diff --git a/htdocs/expensereport/class/api_expensereports.class.php b/htdocs/expensereport/class/api_expensereports.class.php index ce7ce544f12..bf07089b71b 100644 --- a/htdocs/expensereport/class/api_expensereports.class.php +++ b/htdocs/expensereport/class/api_expensereports.class.php @@ -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'); diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index af7bec526a6..878c0886918 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -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) diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php index 706ca4e143f..97153d94e2f 100644 --- a/htdocs/fourn/commande/list.php +++ b/htdocs/fourn/commande/list.php @@ -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); diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php index 84b91bd3a27..a66e624619c 100644 --- a/htdocs/fourn/facture/list.php +++ b/htdocs/fourn/facture/list.php @@ -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,"; diff --git a/htdocs/product/class/api_deprecated_product.class.php b/htdocs/product/class/api_deprecated_product.class.php index cdda0c45fbb..938e591226f 100644 --- a/htdocs/product/class/api_deprecated_product.class.php +++ b/htdocs/product/class/api_deprecated_product.class.php @@ -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'); diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 0c08fb0dc35..19fae0b6342 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -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'); diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index bb122dc70e8..46da76a5f57 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -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')"; diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index a246e7fc135..677d34d9fcb 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -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) { diff --git a/htdocs/product/stock/class/api_warehouses.class.php b/htdocs/product/stock/class/api_warehouses.class.php index 79eefc821c3..d19918f0789 100644 --- a/htdocs/product/stock/class/api_warehouses.class.php +++ b/htdocs/product/stock/class/api_warehouses.class.php @@ -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) { diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 5281d913d95..bb755868f24 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -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))"; diff --git a/htdocs/projet/class/api_projects.class.php b/htdocs/projet/class/api_projects.class.php index f36df0773eb..2b5ee92d878 100644 --- a/htdocs/projet/class/api_projects.class.php +++ b/htdocs/projet/class/api_projects.class.php @@ -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) { diff --git a/htdocs/projet/class/api_tasks.class.php b/htdocs/projet/class/api_tasks.class.php index a5bab614a4a..c88850ca403 100644 --- a/htdocs/projet/class/api_tasks.class.php +++ b/htdocs/projet/class/api_tasks.class.php @@ -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) { diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index 775d9d48cf4..9f09f7f7408 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -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++; } diff --git a/htdocs/societe/class/api_deprecated_contact.class.php b/htdocs/societe/class/api_deprecated_contact.class.php index d3d085e7135..e229dc5f79b 100644 --- a/htdocs/societe/class/api_deprecated_contact.class.php +++ b/htdocs/societe/class/api_deprecated_contact.class.php @@ -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++; } diff --git a/htdocs/societe/class/api_deprecated_thirdparty.class.php b/htdocs/societe/class/api_deprecated_thirdparty.class.php index 3e937557941..6086f2366d8 100644 --- a/htdocs/societe/class/api_deprecated_thirdparty.class.php +++ b/htdocs/societe/class/api_deprecated_thirdparty.class.php @@ -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'); diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 13f28aea705..bc156b5cc4a 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -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'); diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index db18bea229a..3fc44104628 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -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'); From 5edf215b74aab9392f49103bf3068293d60650d9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 5 Dec 2016 13:32:08 +0100 Subject: [PATCH 3/4] Add missing api file --- .../class/api_supplier_invoices.class.php | 310 ++++++++++++++++++ 1 file changed, 310 insertions(+) create mode 100644 htdocs/fourn/class/api_supplier_invoices.class.php diff --git a/htdocs/fourn/class/api_supplier_invoices.class.php b/htdocs/fourn/class/api_supplier_invoices.class.php new file mode 100644 index 00000000000..660e64147ed --- /dev/null +++ b/htdocs/fourn/class/api_supplier_invoices.class.php @@ -0,0 +1,310 @@ + + * Copyright (C) 2016 Laurent Destailleur + * + * 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 . + */ + + 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; + } +} From 1a842d8366ff653d1e85deccc59dc66560764d71 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 5 Dec 2016 13:45:57 +0100 Subject: [PATCH 4/4] Fix translation --- htdocs/contact/card.php | 6 +++--- htdocs/core/lib/company.lib.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 5050e6f7c9b..e7896d9b9ac 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -1183,10 +1183,10 @@ else print ''; print ''; - print $langs->trans("ExportCardToFormat").''; + print $langs->trans("VCard").''; print ''; - 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 ''; print ''; diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 948ce7271da..b9619c278bd 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -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".''."\n"; print '';
'.$langs->trans("Company").'