65 public function get($id)
67 if (!DolibarrApiAccess::$user->rights->supplier_proposal->lire) {
68 throw new RestException(401);
71 $result = $this->supplier_proposal->fetch($id);
73 throw new RestException(404,
'Supplier Proposal not found');
77 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
80 $this->supplier_proposal->fetchObjectLinked();
97 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $sqlfilters =
'')
101 if (!DolibarrApiAccess::$user->rights->supplier_proposal->lire) {
102 throw new RestException(401);
108 $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
112 if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
113 $search_sale = DolibarrApiAccess::$user->id;
116 $sql =
"SELECT t.rowid";
117 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
118 $sql .=
", sc.fk_soc, sc.fk_user";
120 $sql .=
" FROM ".MAIN_DB_PREFIX.
"supplier_proposal AS t LEFT JOIN ".MAIN_DB_PREFIX.
"supplier_proposal_extrafields AS ef ON (ef.fk_object = t.rowid)";
122 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
123 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
126 $sql .=
' WHERE t.entity IN ('.getEntity(
'propal').
')';
127 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
128 $sql .=
" AND t.fk_soc = sc.fk_soc";
131 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
133 if ($search_sale > 0) {
134 $sql .=
" AND t.rowid = sc.fk_soc";
137 if ($search_sale > 0) {
138 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
145 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
149 $sql .= $this->db->order($sortfield, $sortorder);
154 $offset = $limit * $page;
156 $sql .= $this->db->plimit($limit + 1, $offset);
159 $result = $this->db->query($sql);
162 $num = $this->db->num_rows($result);
163 $min = min($num, ($limit <= 0 ? $num : $limit));
166 $obj = $this->db->fetch_object($result);
168 if ($propal_static->fetch($obj->rowid)) {
174 throw new RestException(503,
'Error when retrieving supplier proposal list : '.$this->db->lasterror());
176 if (!count($obj_ret)) {
177 throw new RestException(404,
'No supplier proposal found');