From 80b832e90cd22e7025028d058b47b44a18670768 Mon Sep 17 00:00:00 2001 From: jfefe Date: Sun, 3 May 2015 19:13:14 +0200 Subject: [PATCH] Add API methods to retrieve customers, prospects and others --- htdocs/societe/class/api_thirdparty.class.php | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/class/api_thirdparty.class.php b/htdocs/societe/class/api_thirdparty.class.php index 140da5bfedb..d21bee80c41 100644 --- a/htdocs/societe/class/api_thirdparty.class.php +++ b/htdocs/societe/class/api_thirdparty.class.php @@ -30,6 +30,10 @@ */ class ThirdpartyApi extends DolibarrApi { + /** + * + * @var array $FIELDS Mandatory fields, checked when create and update object + */ static $FIELDS = array( 'name' ); @@ -89,10 +93,15 @@ class ThirdpartyApi extends DolibarrApi { * Fetch a list of thirdparties * * @url GET /thirdparties/ + * + * @param int $only_customer Set to 1 to show only customers + * @param int $only_prospect Set to 1 to show only prospects + * @param int $only_others Set to 1 to show only those are not customer neither prospect + * * * @return array Array of thirdparty objects */ - function getList() { + function getList($only_customer=0,$only_prospect=0,$only_others=0) { global $db, $conf; $obj_ret = array(); @@ -109,7 +118,9 @@ class ThirdpartyApi extends DolibarrApi { 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.= ", ".MAIN_DB_PREFIX."c_stcomm as st"; $sql.= " WHERE s.fk_stcomm = st.id"; - //$sql.= " AND s.client IN (1, 3)"; + if ($only_customer) $sql.= " AND s.client IN (1, 3)"; + if ($only_prospect) $sql.= " AND s.client IN (2, 3)"; + if ($only_others) $sql.= " AND s.client IN (0)"; $sql.= ' AND s.entity IN ('.getEntity('societe', 1).')'; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; if ($socid) $sql.= " AND s.rowid = ".$socid; @@ -151,6 +162,39 @@ class ThirdpartyApi extends DolibarrApi { return $obj_ret; } + /** + * Show customers + * + * @url GET /thirdparties/customers + * + * @return array List of customers + */ + function getListCustomers() { + return $this->getList(1); + } + + /** + * Show prospects + * + * @url GET /thirdparties/prospects + * + * @return array List of prospects + */ + function getListProspects() { + return $this->getList('',1); + } + + /** + * Show other + * + * @url GET /thirdparties/others + * + * @return array List of thirpdparties who are not customer neither prospect + */ + function getListOthers() { + return $this->getList('','',1); + } + /** * Create thirdparty object *