65 public function get($id)
67 if (!DolibarrApiAccess::$user->rights->expensereport->lire) {
68 throw new RestException(401);
71 $result = $this->expensereport->fetch($id);
73 throw new RestException(404,
'Expense report not found');
77 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
80 $this->expensereport->fetchObjectLinked();
98 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $user_ids = 0, $sqlfilters =
'', $properties =
'')
102 if (!DolibarrApiAccess::$user->rights->expensereport->lire) {
103 throw new RestException(401);
111 $sql =
"SELECT t.rowid";
112 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport AS t LEFT JOIN ".MAIN_DB_PREFIX.
"expensereport_extrafields AS ef ON (ef.fk_object = t.rowid)";
113 $sql .=
' WHERE t.entity IN ('.getEntity(
'expensereport').
')';
115 $sql .=
" AND t.fk_user_author IN (".$this->db->sanitize($user_ids).
")";
123 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
127 $sql .= $this->db->order($sortfield, $sortorder);
132 $offset = $limit * $page;
134 $sql .= $this->db->plimit($limit + 1, $offset);
137 $result = $this->db->query($sql);
140 $num = $this->db->num_rows($result);
141 $min = min($num, ($limit <= 0 ? $num : $limit));
144 $obj = $this->db->fetch_object($result);
146 if ($expensereport_static->fetch($obj->rowid)) {
152 throw new RestException(503,
'Error when retrieve Expense Report list : '.$this->db->lasterror());
164 public function post($request_data =
null)
166 if (!DolibarrApiAccess::$user->rights->expensereport->creer) {
167 throw new RestException(401,
"Insuffisant rights");
171 $result = $this->
_validate($request_data);
173 foreach ($request_data as $field => $value) {
174 if ($field ===
'caller') {
176 $this->expensereport->context[
'caller'] = $request_data[
'caller'];
180 $this->expensereport->$field = $value;
189 if ($this->expensereport->create(DolibarrApiAccess::$user) < 0) {
190 throw new RestException(500,
"Error creating expensereport", array_merge(array($this->expensereport->error), $this->expensereport->errors));
193 return $this->expensereport->id;
409 public function put($id, $request_data =
null)
411 if (!DolibarrApiAccess::$user->rights->expensereport->creer) {
412 throw new RestException(401);
415 $result = $this->expensereport->fetch($id);
417 throw new RestException(404,
'expensereport not found');
421 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
423 foreach ($request_data as $field => $value) {
424 if ($field ==
'id') {
427 if ($field ===
'caller') {
429 $this->expensereport->context[
'caller'] = $request_data[
'caller'];
433 $this->expensereport->$field = $value;
436 if ($this->expensereport->update(DolibarrApiAccess::$user) > 0) {
437 return $this->
get($id);
439 throw new RestException(500, $this->expensereport->error);
450 public function delete($id)
452 if (!DolibarrApiAccess::$user->rights->expensereport->supprimer) {
453 throw new RestException(401);
456 $result = $this->expensereport->fetch($id);
458 throw new RestException(404,
'Expense Report not found');
462 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
465 if (!$this->expensereport->delete(DolibarrApiAccess::$user)) {
466 throw new RestException(500,
'Error when delete Expense Report : '.$this->expensereport->error);
472 'message' =>
'Expense Report deleted'
530 $object = parent::_cleanObjectDatas($object);
532 unset($object->fk_statut);
533 unset($object->statut);
534 unset($object->user);
535 unset($object->thirdparty);
537 unset($object->cond_reglement);
538 unset($object->shipping_method_id);
540 unset($object->barcode_type);
541 unset($object->barcode_type_code);
542 unset($object->barcode_type_label);
543 unset($object->barcode_type_coder);
545 unset($object->code_paiement);
546 unset($object->code_statut);
547 unset($object->fk_c_paiement);
548 unset($object->fk_incoterms);
549 unset($object->label_incoterms);
550 unset($object->location_incoterms);
551 unset($object->mode_reglement_id);
552 unset($object->cond_reglement_id);
554 unset($object->name);
555 unset($object->lastname);
556 unset($object->firstname);
557 unset($object->civility_id);
558 unset($object->cond_reglement_id);
559 unset($object->contact);
560 unset($object->contact_id);
562 unset($object->state);
563 unset($object->state_id);
564 unset($object->state_code);
565 unset($object->country);
566 unset($object->country_id);
567 unset($object->country_code);
569 unset($object->note);