64 public function get($id)
66 if (!DolibarrApiAccess::$user->rights->supplier_proposal->lire) {
67 throw new RestException(401);
70 $result = $this->supplier_proposal->fetch($id);
72 throw new RestException(404,
'Supplier Proposal not found');
76 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
79 $this->supplier_proposal->fetchObjectLinked();
97 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $thirdparty_ids =
'', $sqlfilters =
'', $properties =
'')
99 if (!DolibarrApiAccess::$user->rights->supplier_proposal->lire) {
100 throw new RestException(401);
106 $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
110 if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
111 $search_sale = DolibarrApiAccess::$user->id;
114 $sql =
"SELECT t.rowid";
115 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
116 $sql .=
", sc.fk_soc, sc.fk_user";
118 $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)";
120 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
121 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
124 $sql .=
' WHERE t.entity IN ('.getEntity(
'propal').
')';
125 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
126 $sql .=
" AND t.fk_soc = sc.fk_soc";
129 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socids).
")";
131 if ($search_sale > 0) {
132 $sql .=
" AND t.rowid = sc.fk_soc";
135 if ($search_sale > 0) {
136 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
143 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
147 $sql .= $this->db->order($sortfield, $sortorder);
152 $offset = $limit * $page;
154 $sql .= $this->db->plimit($limit + 1, $offset);
157 $result = $this->db->query($sql);
160 $num = $this->db->num_rows($result);
161 $min = min($num, ($limit <= 0 ? $num : $limit));
164 $obj = $this->db->fetch_object($result);
166 if ($propal_static->fetch($obj->rowid)) {
172 throw new RestException(503,
'Error when retrieving supplier proposal list : '.$this->db->lasterror());