dolibarr 22.0.5
api_expensereports.class.php
1<?php
2/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
3 * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2020-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2025 William Mead <william@m34d.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22use Luracast\Restler\RestException;
23
24require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
25require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
26
27
37{
41 public static $FIELDS = array(
42 'fk_user_author',
43 'date_debut',
44 'date_fin',
45 );
46
50 public static $FIELDSPAYMENT = array(
51 "fk_typepayment",
52 'datep',
53 'amounts',
54 );
55
59 public $expensereport;
60
61
65 public function __construct()
66 {
67 global $db;
68
69 $this->db = $db;
70 $this->expensereport = new ExpenseReport($this->db);
71 }
72
85 public function get($id)
86 {
87 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'lire')) {
88 throw new RestException(403);
89 }
90
91 $result = $this->expensereport->fetch($id);
92 if (!$result) {
93 throw new RestException(404, 'Expense report not found');
94 }
95
96 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport->id)) {
97 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
98 }
99
100 $this->expensereport->fetchObjectLinked();
101 return $this->_cleanObjectDatas($this->expensereport);
102 }
103
125 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = '', $sqlfilters = '', $properties = '', $pagination_data = false)
126 {
127 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'lire')) {
128 throw new RestException(403);
129 }
130
131 $obj_ret = array();
132
133 // case of external user, $societe param is ignored and replaced by user's socid
134 //$socid = DolibarrApiAccess::$user->socid ?: $societe;
135
136 $sql = "SELECT t.rowid";
137 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport AS t LEFT JOIN ".MAIN_DB_PREFIX."expensereport_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields
138 $sql .= ' WHERE t.entity IN ('.getEntity('expensereport').')';
139 if ($user_ids) {
140 $sql .= " AND t.fk_user_author IN (".$this->db->sanitize($user_ids).")";
141 }
142
143 // Add sql filters
144 if ($sqlfilters) {
145 $errormessage = '';
146 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
147 if ($errormessage) {
148 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
149 }
150 }
151
152 //this query will return total orders with the filters given
153 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
154
155 $sql .= $this->db->order($sortfield, $sortorder);
156 if ($limit) {
157 if ($page < 0) {
158 $page = 0;
159 }
160 $offset = $limit * $page;
161
162 $sql .= $this->db->plimit($limit + 1, $offset);
163 }
164
165 $result = $this->db->query($sql);
166
167 if ($result) {
168 $num = $this->db->num_rows($result);
169 $min = min($num, ($limit <= 0 ? $num : $limit));
170 $i = 0;
171 while ($i < $min) {
172 $obj = $this->db->fetch_object($result);
173 $expensereport_static = new ExpenseReport($this->db);
174 if ($expensereport_static->fetch($obj->rowid)) {
175 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($expensereport_static), $properties);
176 }
177 $i++;
178 }
179 } else {
180 throw new RestException(503, 'Error when retrieve Expense Report list : '.$this->db->lasterror());
181 }
182
183 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
184 if ($pagination_data) {
185 $totalsResult = $this->db->query($sqlTotals);
186 $total = $this->db->fetch_object($totalsResult)->total;
187
188 $tmp = $obj_ret;
189 $obj_ret = [];
190
191 $obj_ret['data'] = $tmp;
192 $obj_ret['pagination'] = [
193 'total' => (int) $total,
194 'page' => $page, //count starts from 0
195 'page_count' => ceil((int) $total / $limit),
196 'limit' => $limit
197 ];
198 }
199
200 return $obj_ret;
201 }
202
215 public function post($request_data = null)
216 {
217 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
218 throw new RestException(403, "Insuffisant rights");
219 }
220
221 // Check mandatory fields
222 $result = $this->_validate($request_data);
223
224 foreach ($request_data as $field => $value) {
225 if ($field === 'caller') {
226 // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
227 $this->expensereport->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
228 continue;
229 }
230
231 $this->expensereport->$field = $this->_checkValForAPI($field, $value, $this->expensereport);
232 }
233 /*if (isset($request_data["lines"])) {
234 $lines = array();
235 foreach ($request_data["lines"] as $line) {
236 array_push($lines, (object) $line);
237 }
238 $this->expensereport->lines = $lines;
239 }*/
240 if ($this->expensereport->create(DolibarrApiAccess::$user) < 0) {
241 throw new RestException(500, "Error creating expensereport", array_merge(array($this->expensereport->error), $this->expensereport->errors));
242 }
243
244 return $this->expensereport->id;
245 }
246
256 /*
257 public function getLines($id)
258 {
259 if(! DolibarrApiAccess::$user->hasRight('expensereport', 'lire')) {
260 throw new RestException(403);
261 }
262
263 $result = $this->expensereport->fetch($id);
264 if( ! $result ) {
265 throw new RestException(404, 'expensereport not found');
266 }
267
268 if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
269 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
270 }
271 $this->expensereport->getLinesArray();
272 $result = array();
273 foreach ($this->expensereport->lines as $line) {
274 array_push($result,$this->_cleanObjectDatas($line));
275 }
276 return $result;
277 }
278 */
279
292 /*
293 public function postLine($id, $request_data = null)
294 {
295 if(! DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
296 throw new RestException(403);
297 }
298
299 $result = $this->expensereport->fetch($id);
300 if( ! $result ) {
301 throw new RestException(404, 'expensereport not found');
302 }
303
304 if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
305 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
306 }
307
308 $request_data = (object) $request_data;
309
310 $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml');
311 $request_data->label = sanitizeVal($request_data->label);
312
313 $updateRes = $this->expensereport->addline(
314 $request_data->desc,
315 $request_data->subprice,
316 $request_data->qty,
317 $request_data->tva_tx,
318 $request_data->localtax1_tx,
319 $request_data->localtax2_tx,
320 $request_data->fk_product,
321 $request_data->remise_percent,
322 $request_data->info_bits,
323 $request_data->fk_remise_except,
324 'HT',
325 0,
326 $request_data->date_start,
327 $request_data->date_end,
328 $request_data->product_type,
329 $request_data->rang,
330 $request_data->special_code,
331 $fk_parent_line,
332 $request_data->fk_fournprice,
333 $request_data->pa_ht,
334 $request_data->label,
335 $request_data->array_options,
336 $request_data->fk_unit,
337 $this->element,
338 $request_data->id
339 );
340
341 if ($updateRes > 0) {
342 return $updateRes;
343
344 }
345 return false;
346 }
347 */
348
362 /*
363 public function putLine($id, $lineid, $request_data = null)
364 {
365 if(! DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
366 throw new RestException(403);
367 }
368
369 $result = $this->expensereport->fetch($id);
370 if( ! $result ) {
371 throw new RestException(404, 'expensereport not found');
372 }
373
374 if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
375 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
376 }
377
378 $request_data = (object) $request_data;
379
380 $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml');
381 $request_data->label = sanitizeVal($request_data->label);
382
383 $updateRes = $this->expensereport->updateline(
384 $lineid,
385 $request_data->desc,
386 $request_data->subprice,
387 $request_data->qty,
388 $request_data->remise_percent,
389 $request_data->tva_tx,
390 $request_data->localtax1_tx,
391 $request_data->localtax2_tx,
392 'HT',
393 $request_data->info_bits,
394 $request_data->date_start,
395 $request_data->date_end,
396 $request_data->product_type,
397 $request_data->fk_parent_line,
398 0,
399 $request_data->fk_fournprice,
400 $request_data->pa_ht,
401 $request_data->label,
402 $request_data->special_code,
403 $request_data->array_options,
404 $request_data->fk_unit
405 );
406
407 if ($updateRes > 0) {
408 $result = $this->get($id);
409 unset($result->line);
410 return $this->_cleanObjectDatas($result);
411 }
412 return false;
413 }
414 */
415
426 /*
427 public function deleteLine($id, $lineid)
428 {
429 if(! DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
430 throw new RestException(403);
431 }
432
433 $result = $this->expensereport->fetch($id);
434 if( ! $result ) {
435 throw new RestException(404, 'expensereport not found');
436 }
437
438 if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
439 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
440 }
441
442 // TODO Check the lineid $lineid is a line of object
443
444 $updateRes = $this->expensereport->deleteLine($lineid);
445 if ($updateRes == 1) {
446 return $this->get($id);
447 }
448 return false;
449 }
450 */
451
469 public function put($id, $request_data = null)
470 {
471 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
472 throw new RestException(403);
473 }
474
475 $result = $this->expensereport->fetch($id);
476 if (!$result) {
477 throw new RestException(404, 'expensereport not found');
478 }
479
480 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport->id)) {
481 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
482 }
483 foreach ($request_data as $field => $value) {
484 if ($field == 'id') {
485 continue;
486 }
487 if ($field === 'caller') {
488 // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
489 $this->expensereport->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
490 continue;
491 }
492
493 if ($field == 'array_options' && is_array($value)) {
494 foreach ($value as $index => $val) {
495 $this->expensereport->array_options[$index] = $this->_checkValForAPI($field, $val, $this->expensereport);
496 }
497 continue;
498 }
499
500 $this->expensereport->$field = $this->_checkValForAPI($field, $value, $this->expensereport);
501 }
502
503 if ($this->expensereport->update(DolibarrApiAccess::$user) > 0) {
504 return $this->get($id);
505 } else {
506 throw new RestException(500, $this->expensereport->error);
507 }
508 }
509
522 public function delete($id)
523 {
524 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'supprimer')) {
525 throw new RestException(403);
526 }
527
528 $result = $this->expensereport->fetch($id);
529 if (!$result) {
530 throw new RestException(404, 'Expense Report not found');
531 }
532
533 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport->id)) {
534 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
535 }
536
537 if (!$this->expensereport->delete(DolibarrApiAccess::$user)) {
538 throw new RestException(500, 'Error when delete Expense Report : '.$this->expensereport->error);
539 }
540
541 return array(
542 'success' => array(
543 'code' => 200,
544 'message' => 'Expense Report deleted'
545 )
546 );
547 }
548
568 public function validate($id, $notrigger = 0)
569 {
570 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
571 throw new RestException(403, "Insuffisant rights");
572 }
573 $result = $this->expensereport->fetch($id);
574 if (!$result) {
575 throw new RestException(404, 'Expense report not found');
576 }
577
578 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport->id)) {
579 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
580 }
581
582 $result = $this->expensereport->setValidate(DolibarrApiAccess::$user, $notrigger);
583 if ($result == 0) {
584 throw new RestException(304, 'Error nothing done. May be object is already validated');
585 }
586 if ($result < 0) {
587 throw new RestException(500, 'Error when validating expense report: '.$this->expensereport->error);
588 }
589
590 $this->expensereport->fetchObjectLinked();
591
592 return $this->_cleanObjectDatas($this->expensereport);
593 }
594
595
615 public function approve($id, $notrigger = 0)
616 {
617 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'approve')) {
618 throw new RestException(403, "Insuffisant rights");
619 }
620 $result = $this->expensereport->fetch($id);
621 if (!$result) {
622 throw new RestException(404, 'Expense report not found');
623 }
624
625 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport->id)) {
626 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
627 }
628
629 $result = $this->expensereport->setApproved(DolibarrApiAccess::$user, $notrigger);
630 if ($result == 0) {
631 throw new RestException(304, 'Error nothing done. May be object is already approved');
632 }
633 if ($result < 0) {
634 throw new RestException(500, 'Error when approving expense report: '.$this->expensereport->error);
635 }
636
637 $this->expensereport->fetchObjectLinked();
638
639 return $this->_cleanObjectDatas($this->expensereport);
640 }
641
642
663 public function deny($id, $details, $notrigger = 0)
664 {
665 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'approve')) {
666 throw new RestException(403, "Insuffisant rights");
667 }
668 $result = $this->expensereport->fetch($id);
669 if (!$result) {
670 throw new RestException(404, 'Expense report not found');
671 }
672
673 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport->id)) {
674 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
675 }
676
677 $result = $this->expensereport->setDeny(DolibarrApiAccess::$user, $details, $notrigger);
678 if ($result == 0) {
679 throw new RestException(304, 'Error nothing done. May be object is already denied');
680 }
681 if ($result < 0) {
682 throw new RestException(500, 'Error when denying expense report: '.$this->expensereport->error);
683 }
684
685 $this->expensereport->fetchObjectLinked();
686
687 return $this->_cleanObjectDatas($this->expensereport);
688 }
689
690
708 public function getAllPayments($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0)
709 {
710 $list = array();
711
712 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'lire')) {
713 throw new RestException(403);
714 }
715
716 $sql = "SELECT t.rowid FROM " . MAIN_DB_PREFIX . "payment_expensereport as t, ".MAIN_DB_PREFIX."expensereport as e";
717 $sql .= " WHERE e.rowid = t.fk_expensereport";
718 $sql .= ' AND e.entity IN ('.getEntity('expensereport').')';
719
720 $sql .= $this->db->order($sortfield, $sortorder);
721 if ($limit) {
722 if ($page < 0) {
723 $page = 0;
724 }
725 $offset = $limit * $page;
726
727 $sql .= $this->db->plimit($limit + 1, $offset);
728 }
729
730 dol_syslog("API Rest request");
731 $result = $this->db->query($sql);
732
733 if ($result) {
734 $num = $this->db->num_rows($result);
735 $min = min($num, ($limit <= 0 ? $num : $limit));
736 for ($i = 0; $i < $min; $i++) {
737 $obj = $this->db->fetch_object($result);
738 $paymentExpenseReport = new PaymentExpenseReport($this->db);
739 if ($paymentExpenseReport->fetch($obj->rowid) > 0) {
740 $list[] = $this->_cleanObjectDatas($paymentExpenseReport);
741 }
742 }
743 } else {
744 throw new RestException(503, 'Error when retrieving list of paymentexpensereport: ' . $this->db->lasterror());
745 }
746
747 return $list;
748 }
749
762 public function getPayments($pid)
763 {
764 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'lire')) {
765 throw new RestException(403);
766 }
767
768 $paymentExpenseReport = new PaymentExpenseReport($this->db);
769 $result = $paymentExpenseReport->fetch($pid);
770 if (!$result) {
771 throw new RestException(404, 'paymentExpenseReport not found');
772 }
773
774 return $this->_cleanObjectDatas($paymentExpenseReport);
775 }
776
791 public function addPayment($id, $request_data = null)
792 {
793 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
794 throw new RestException(403);
795 }
796 // Check mandatory fields
797 $result = $this->_validatepayment($request_data);
798
799 if ($this->expensereport->fetch($id) <= 0) {
800 throw new RestException(404, 'Expense report not found');
801 }
802 if (isModEnabled("bank") && !((int) ($request_data['accountid'] ?? 0) > 0)) {
803 throw new RestException(400, "accountid field missing");
804 }
805
806 $paymentExpenseReport = new PaymentExpenseReport($this->db);
807 $paymentExpenseReport->fk_expensereport = $id;
808 foreach ($request_data as $field => $value) {
809 $paymentExpenseReport->$field = $this->_checkValForAPI($field, $value, $paymentExpenseReport);
810 }
811
812 // Same sequence as expensereport/payment/payment.php: all or nothing
813 $this->db->begin();
814
815 if ($paymentExpenseReport->create(DolibarrApiAccess::$user) < 0) {
816 $this->db->rollback();
817 throw new RestException(400, 'Payment error : '.$paymentExpenseReport->errorsToString());
818 }
819 if (isModEnabled("bank")) {
820 $result = $paymentExpenseReport->addPaymentToBank(
821 DolibarrApiAccess::$user,
822 'payment_expensereport',
823 '(ExpenseReportPayment)',
824 (int) $request_data['accountid'],
825 '',
826 ''
827 );
828 if ($result <= 0) {
829 $this->db->rollback();
830 throw new RestException(400, 'Add payment to bank error : '.$paymentExpenseReport->errorsToString());
831 }
832 }
833
834 $remaintopay = price2num($this->expensereport->total_ttc - $this->expensereport->getSumPayments(), 'MT');
835 if ($remaintopay == 0 && $this->expensereport->setPaid($this->expensereport->id, DolibarrApiAccess::$user) < 0) {
836 $this->db->rollback();
837 throw new RestException(400, 'Set paid error : '.$this->expensereport->errorsToString());
838 }
839
840 $this->db->commit();
841
842 return $paymentExpenseReport->id;
843 }
844
859 public function updatePayment($id, $request_data = null)
860 {
861 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
862 throw new RestException(403);
863 }
864
865 $paymentExpenseReport = new PaymentExpenseReport($this->db);
866 $result = $paymentExpenseReport->fetch($id);
867 if (!$result) {
868 throw new RestException(404, 'payment of expense report not found');
869 }
870
871 foreach ($request_data as $field => $value) {
872 if ($field == 'id') {
873 continue;
874 }
875 $paymentExpenseReport->$field = $this->_checkValForAPI($field, $value, $paymentExpenseReport);
876 }
877
878 if ($paymentExpenseReport->update(DolibarrApiAccess::$user) > 0) {
879 return $this->get($id);
880 } else {
881 throw new RestException(500, $paymentExpenseReport->error);
882 }
883 }
884
893 /*public function delete($id)
894 {
895 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer') {
896 throw new RestException(403);
897 }
898 $paymentExpenseReport = new PaymentExpenseReport($this->db);
899 $result = $paymentExpenseReport->fetch($id);
900 if (!$result) {
901 throw new RestException(404, 'paymentExpenseReport not found');
902 }
903
904 if ($paymentExpenseReport->delete(DolibarrApiAccess::$user) < 0) {
905 throw new RestException(403, 'error when deleting paymentExpenseReport');
906 }
907
908 return array(
909 'success' => array(
910 'code' => 200,
911 'message' => 'paymentExpenseReport deleted'
912 )
913 );
914 }*/
915
916
917
918 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
925 protected function _cleanObjectDatas($object)
926 {
927 // phpcs:enable
928 $object = parent::_cleanObjectDatas($object);
929
930 unset($object->fk_statut);
931 unset($object->statut);
932 unset($object->user);
933 unset($object->thirdparty);
934
935 unset($object->cond_reglement);
936 unset($object->shipping_method_id);
937
938 unset($object->barcode_type);
939 unset($object->barcode_type_code);
940 unset($object->barcode_type_label);
941 unset($object->barcode_type_coder);
942
943 unset($object->code_paiement);
944 unset($object->code_statut);
945 unset($object->fk_c_paiement);
946 unset($object->fk_incoterms);
947 unset($object->label_incoterms);
948 unset($object->location_incoterms);
949 unset($object->mode_reglement_id);
950 unset($object->cond_reglement_id);
951
952 unset($object->name);
953 unset($object->lastname);
954 unset($object->firstname);
955 unset($object->civility_id);
956 unset($object->cond_reglement_id);
957 unset($object->contact);
958 unset($object->contact_id);
959
960 unset($object->state);
961 unset($object->state_id);
962 unset($object->state_code);
963 unset($object->country);
964 unset($object->country_id);
965 unset($object->country_code);
966
967 unset($object->note); // We already use note_public and note_pricate
968
969 return $object;
970 }
971
979 private function _validate($data)
980 {
981 if ($data === null) {
982 $data = array();
983 }
984 $expensereport = array();
985 foreach (ExpenseReports::$FIELDS as $field) {
986 if (!isset($data[$field])) {
987 throw new RestException(400, "$field field missing");
988 }
989 $expensereport[$field] = $data[$field];
990 }
991 return $expensereport;
992 }
993
1001 private function _validatepayment($data)
1002 {
1003 if ($data === null) {
1004 $data = array();
1005 }
1006 $expensereport = array();
1007 foreach (ExpenseReports::$FIELDSPAYMENT as $field) {
1008 if (!isset($data[$field])) {
1009 throw new RestException(400, "$field field missing");
1010 }
1011 $expensereport[$field] = $data[$field];
1012 }
1013 return $expensereport;
1014 }
1015}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
Class for API REST v1.
Definition api.class.php:33
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Definition api.class.php:98
Class to manage Trips and Expenses.
getPayments($pid)
Get an expense report payment.
deny($id, $details, $notrigger=0)
Deny an expense report.
_cleanObjectDatas($object)
Delete paymentExpenseReport.
_validate($data)
Validate fields before create or update object.
validate($id, $notrigger=0)
Validate an expense report.
updatePayment($id, $request_data=null)
Update a payment of an expense report.
approve($id, $notrigger=0)
Approve an expense report.
put($id, $request_data=null)
Get lines of an Expense Report.
addPayment($id, $request_data=null)
Create a payment for an expense report.
getAllPayments($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0)
Get the list of payments of an expense report.
post($request_data=null)
Create an expense report.
_validatepayment($data)
Validate fields before create or update object.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $user_ids='', $sqlfilters='', $properties='', $pagination_data=false)
List expense reports.
Class to manage payments of expense report.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.