diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index 845b8d3d3d9..18439f484a3 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -160,9 +160,10 @@ class Proposals extends DolibarrApi * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'2016-01-01')" * @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names * @param bool $pagination_data If this parameter is set to true the response will include pagination data. Default value is false. Page starts from 0* + * @param int $loadlinkedobjects Load also linked object * @return array Array of order objects */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $properties = '', $pagination_data = false) + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $properties = '', $pagination_data = false, $loadlinkedobjects = 0) { if (!DolibarrApiAccess::$user->hasRight('propal', 'lire')) { throw new RestException(403); @@ -226,12 +227,18 @@ class Proposals extends DolibarrApi while ($i < $min) { $obj = $this->db->fetch_object($result); $proposal_static = new Propal($this->db); - if ($proposal_static->fetch($obj->rowid)) { + if ($proposal_static->fetch($obj->rowid) > 0) { // Add external contacts ids $tmparray = $proposal_static->liste_contact(-1, 'external', 1); if (is_array($tmparray)) { $proposal_static->contacts_ids = $tmparray; } + + if ($loadlinkedobjects) { + // retrieve linked objects + $proposal_static->fetchObjectLinked(); + } + $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($proposal_static), $properties); } $i++; diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 91912192b0d..583e77a0ece 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -47,7 +47,8 @@ class Orders extends DolibarrApi */ public function __construct() { - global $db, $conf; + global $db; + $this->db = $db; $this->commande = new Commande($this->db); } @@ -160,12 +161,13 @@ class Orders extends DolibarrApi * @param string $sqlfilterlines Other criteria to filter answers separated by a comma. Syntax example "(tl.fk_product:=:'17') and (tl.price:<:'250')" * @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names * @param bool $pagination_data If this parameter is set to true the response will include pagination data. Default value is false. Page starts from 0* + * @param int $loadlinkedobjects Load also linked object * @return array Array of order objects * * @throws RestException 404 Not found * @throws RestException 503 Error */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $sqlfilterlines = '', $properties = '', $pagination_data = false) + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $sqlfilterlines = '', $properties = '', $pagination_data = false, $loadlinkedobjects = 0) { if (!DolibarrApiAccess::$user->hasRight('commande', 'lire')) { throw new RestException(403); @@ -239,14 +241,18 @@ class Orders extends DolibarrApi while ($i < $min) { $obj = $this->db->fetch_object($result); $commande_static = new Commande($this->db); - if ($commande_static->fetch($obj->rowid)) { + if ($commande_static->fetch($obj->rowid) > 0) { // Add external contacts ids $tmparray = $commande_static->liste_contact(-1, 'external', 1); if (is_array($tmparray)) { $commande_static->contacts_ids = $tmparray; } - // retrieve linked objects - $commande_static->fetchObjectLinked(); + + if ($loadlinkedobjects) { + // retrieve linked objects + $commande_static->fetchObjectLinked(); + } + // Add online_payment_url, cf #20477 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; $commande_static->online_payment_url = getOnlinePaymentUrl(0, 'order', $commande_static->ref); diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index b4867e8168a..78c2f2a3a3b 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -171,21 +171,22 @@ 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 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')" - * @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names - * @param bool $pagination_data If this parameter is set to true the response will include pagination data. Default value is false. Page starts from 0 - * @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')" + * @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names + * @param bool $pagination_data If this parameter is set to true the response will include pagination data. Default value is false. Page starts from 0 + * @param int $loadlinkedobjects Load also linked object + * @return array Array of invoice objects * * @throws RestException 404 Not found * @throws RestException 503 Error */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $status = '', $sqlfilters = '', $properties = '', $pagination_data = false) + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $status = '', $sqlfilters = '', $properties = '', $pagination_data = false, $loadlinkedobjects = 0) { if (!DolibarrApiAccess::$user->hasRight('facture', 'lire')) { throw new RestException(403); @@ -260,7 +261,7 @@ class Invoices extends DolibarrApi while ($i < $min) { $obj = $this->db->fetch_object($result); $invoice_static = new Facture($this->db); - if ($invoice_static->fetch($obj->rowid)) { + if ($invoice_static->fetch($obj->rowid) > 0) { // Get payment details $invoice_static->totalpaid = $invoice_static->getSommePaiement(); $invoice_static->totalcreditnotes = $invoice_static->getSumCreditNotesUsed(); @@ -272,6 +273,12 @@ class Invoices extends DolibarrApi if (is_array($tmparray)) { $invoice_static->contacts_ids = $tmparray; } + + if ($loadlinkedobjects) { + // retrieve linked objects + $invoice_static->fetchObjectLinked(); + } + // Add online_payment_url, copied from order require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; $invoice_static->online_payment_url = getOnlinePaymentUrl(0, 'invoice', $invoice_static->ref);