66 public function get($id)
68 if (!DolibarrApiAccess::$user->rights->expensereport->lire) {
69 throw new RestException(401);
72 $result = $this->expensereport->fetch($id);
74 throw new RestException(404,
'Expense report not found');
78 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
81 $this->expensereport->fetchObjectLinked();
98 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $user_ids = 0, $sqlfilters =
'')
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());
154 if (!count($obj_ret)) {
155 throw new RestException(404,
'No Expense Report found');
166 public function post($request_data =
null)
168 if (!DolibarrApiAccess::$user->rights->expensereport->creer) {
169 throw new RestException(401,
"Insuffisant rights");
173 $result = $this->
_validate($request_data);
175 foreach ($request_data as $field => $value) {
176 $this->expensereport->$field = $value;
185 if ($this->expensereport->create(DolibarrApiAccess::$user) < 0) {
186 throw new RestException(500,
"Error creating expensereport", array_merge(array($this->expensereport->error), $this->expensereport->errors));
189 return $this->expensereport->id;
405 public function put($id, $request_data =
null)
407 if (!DolibarrApiAccess::$user->rights->expensereport->creer) {
408 throw new RestException(401);
411 $result = $this->expensereport->fetch($id);
413 throw new RestException(404,
'expensereport not found');
417 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
419 foreach ($request_data as $field => $value) {
420 if ($field ==
'id') {
423 $this->expensereport->$field = $value;
426 if ($this->expensereport->update(DolibarrApiAccess::$user) > 0) {
427 return $this->
get($id);
429 throw new RestException(500, $this->expensereport->error);
440 public function delete($id)
442 if (!DolibarrApiAccess::$user->rights->expensereport->supprimer) {
443 throw new RestException(401);
446 $result = $this->expensereport->fetch($id);
448 throw new RestException(404,
'Expense Report not found');
452 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
455 if (!$this->expensereport->delete(DolibarrApiAccess::$user)) {
456 throw new RestException(500,
'Error when delete Expense Report : '.$this->expensereport->error);
462 'message' =>
'Expense Report deleted'
520 $object = parent::_cleanObjectDatas($object);
522 unset($object->fk_statut);
523 unset($object->statut);
524 unset($object->user);
525 unset($object->thirdparty);
527 unset($object->cond_reglement);
528 unset($object->shipping_method_id);
530 unset($object->barcode_type);
531 unset($object->barcode_type_code);
532 unset($object->barcode_type_label);
533 unset($object->barcode_type_coder);
535 unset($object->code_paiement);
536 unset($object->code_statut);
537 unset($object->fk_c_paiement);
538 unset($object->fk_incoterms);
539 unset($object->label_incoterms);
540 unset($object->location_incoterms);
541 unset($object->mode_reglement_id);
542 unset($object->cond_reglement_id);
544 unset($object->name);
545 unset($object->lastname);
546 unset($object->firstname);
547 unset($object->civility_id);
548 unset($object->cond_reglement_id);
549 unset($object->contact);
550 unset($object->contact_id);
552 unset($object->state);
553 unset($object->state_id);
554 unset($object->state_code);
555 unset($object->country);
556 unset($object->country_id);
557 unset($object->country_code);
559 unset($object->note);