19 use Luracast\Restler\RestException;
21 require_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
36 public static $FIELDS = array(
43 public $supplier_proposal;
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";
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);
144 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
146 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
147 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
150 $sql .= $this->
db->order($sortfield, $sortorder);
155 $offset = $limit * $page;
157 $sql .= $this->
db->plimit($limit + 1, $offset);
160 $result = $this->
db->query($sql);
163 $num = $this->
db->num_rows($result);
164 $min = min($num, ($limit <= 0 ? $num : $limit));
167 $obj = $this->
db->fetch_object($result);
169 if ($propal_static->fetch($obj->rowid)) {
175 throw new RestException(503,
'Error when retrieving supplier proposal list : '.$this->
db->lasterror());
177 if (!count($obj_ret)) {
178 throw new RestException(404,
'No supplier proposal found');
194 foreach (SupplierProposals::$FIELDS as $field) {
195 if (!isset($data[$field])) {
196 throw new RestException(400,
"$field field missing");
198 $propal[$field] = $data[$field];
214 $object = parent::_cleanObjectDatas($object);
216 unset($object->name);
217 unset($object->lastname);
218 unset($object->firstname);
219 unset($object->civility_id);
220 unset($object->address);
221 unset($object->datec);
222 unset($object->datev);
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid.
Class to manage price ask supplier.
__construct()
Constructor.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $thirdparty_ids='', $sqlfilters='')
List supplier proposals.
_cleanObjectDatas($object)
Clean sensible object datas.
_validate($data)
Validate fields before create or update object.
$conf db
API class for accounts.