dolibarr 23.0.3
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-2025 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 * Copyright (C) 2025 Kowal Jessica <jessicakowal69@gmail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23use Luracast\Restler\RestException;
24
25require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
26require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
28
38{
42 public static $FIELDS = array(
43 'fk_user_author',
44 'date_debut',
45 'date_fin',
46 );
47
51 public static $FIELDSLINE = array(
52 'date',
53 'fk_c_type_fees',
54 'qty',
55 'value_unit',
56 'vatrate'
57 );
58
62 public static $FIELDSPAYMENT = array(
63 "fk_typepayment",
64 'datepaid',
65 'amounts',
66 );
67
71 public $expensereport;
72
73
77 public function __construct()
78 {
79 global $db;
80
81 $this->db = $db;
82 $this->expensereport = new ExpenseReport($this->db);
83 }
84
97 public function get($id)
98 {
99 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'lire')) {
100 throw new RestException(403);
101 }
102
103 $result = $this->expensereport->fetch($id);
104 if (!$result) {
105 throw new RestException(404, 'Expense report not found');
106 }
107
108 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport)) {
109 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
110 }
111
112 $this->expensereport->fetchObjectLinked();
113 return $this->_cleanObjectDatas($this->expensereport);
114 }
115
137 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = '', $sqlfilters = '', $properties = '', $pagination_data = false)
138 {
139 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'lire')) {
140 throw new RestException(403);
141 }
142
143 $obj_ret = array();
144
145 // case of external user, $societe param is ignored and replaced by user's socid
146 //$socid = DolibarrApiAccess::$user->socid ?: $societe;
147
148 $sql = "SELECT t.rowid";
149 $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
150 $sql .= ' WHERE t.entity IN ('.getEntity('expensereport').')';
151 if ($user_ids) {
152 $sql .= " AND t.fk_user_author IN (".$this->db->sanitize($user_ids).")";
153 }
154
155 // Add sql filters
156 if ($sqlfilters) {
157 $errormessage = '';
158 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
159 if ($errormessage) {
160 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
161 }
162 }
163
164 //this query will return total orders with the filters given
165 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
166
167 $sql .= $this->db->order($sortfield, $sortorder);
168 if ($limit) {
169 if ($page < 0) {
170 $page = 0;
171 }
172 $offset = $limit * $page;
173
174 $sql .= $this->db->plimit($limit + 1, $offset);
175 }
176
177 $result = $this->db->query($sql);
178
179 if ($result) {
180 $num = $this->db->num_rows($result);
181 $min = min($num, ($limit <= 0 ? $num : $limit));
182 $i = 0;
183 while ($i < $min) {
184 $obj = $this->db->fetch_object($result);
185 $expensereport_static = new ExpenseReport($this->db);
186 if ($expensereport_static->fetch($obj->rowid)) {
187 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($expensereport_static), $properties);
188 }
189 $i++;
190 }
191 } else {
192 throw new RestException(503, 'Error when retrieve Expense Report list : '.$this->db->lasterror());
193 }
194
195 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
196 if ($pagination_data) {
197 $totalsResult = $this->db->query($sqlTotals);
198 $total = $this->db->fetch_object($totalsResult)->total;
199
200 $tmp = $obj_ret;
201 $obj_ret = [];
202
203 $obj_ret['data'] = $tmp;
204 $obj_ret['pagination'] = [
205 'total' => (int) $total,
206 'page' => $page, //count starts from 0
207 'page_count' => ceil((int) $total / $limit),
208 'limit' => $limit
209 ];
210 }
211
212 return $obj_ret;
213 }
214
227 public function post($request_data = null)
228 {
229 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
230 throw new RestException(403, "Insufficiant rights");
231 }
232
233 // Check mandatory fields
234 $result = $this->_validate($request_data);
235
236 foreach ($request_data as $field => $value) {
237 if ($field === 'caller') {
238 // 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
239 $this->expensereport->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
240 continue;
241 }
242
243 $this->expensereport->$field = $this->_checkValForAPI($field, $value, $this->expensereport);
244 }
245 /*if (isset($request_data["lines"])) {
246 $lines = array();
247 foreach ($request_data["lines"] as $line) {
248 array_push($lines, (object) $line);
249 }
250 $this->expensereport->lines = $lines;
251 }*/
252 if ($this->expensereport->create(DolibarrApiAccess::$user) < 0) {
253 throw new RestException(500, "Error creating expensereport", array_merge(array($this->expensereport->error), $this->expensereport->errors));
254 }
255
256 return $this->expensereport->id;
257 }
258
275 public function getLines($id)
276 {
277 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'lire')) {
278 throw new RestException(403);
279 }
280
281 $result = $this->expensereport->fetch($id);
282 if (!$result) {
283 throw new RestException(404, 'Expense report not found');
284 }
285
286 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport)) {
287 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
288 }
289 $this->expensereport->fetch_lines();
290 $result = array();
291 foreach ($this->expensereport->lines as $line) {
292 $result[] = $this->_cleanObjectDatas($line);
293 }
294 return $result;
295 }
296
313 public function postLine($id, $request_data = null)
314 {
315 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
316 throw new RestException(403);
317 }
318
319 $result = $this->_validateLine($request_data);
320
321 $result = $this->expensereport->fetch($id);
322 if (!$result) {
323 throw new RestException(404, 'Expense report not found');
324 }
325
326 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport)) {
327 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
328 }
329
330 if ($this->expensereport->status != ExpenseReport::STATUS_DRAFT) {
331 throw new RestException(403, 'Expense report must be in draft status to add lines');
332 }
333
334 $request_data = (object) $request_data;
335
336 $request_data->comments = sanitizeVal($request_data->comments, 'restricthtml');
337
338 $result = $this->expensereport->addline(
339 $request_data->qty,
340 $request_data->value_unit,
341 (int) $request_data->fk_c_type_fees,
342 $request_data->vatrate,
343 $request_data->date,
344 $request_data->comments,
345 $request_data->fk_project,
346 $request_data->fk_c_exp_tax_cat,
347 $request_data->type,
348 $request_data->fk_ecm_files
349 );
350
351 if ($result > 0) {
352 return $result;
353 } else {
354 throw new RestException(500, 'Error adding line to expense report: '.$this->expensereport->error);
355 }
356 }
357
377 public function putLine($id, $lineid, $request_data = null)
378 {
379 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
380 throw new RestException(403);
381 }
382
383 $result = $this->expensereport->fetch($id);
384 if (!$result) {
385 throw new RestException(404, 'Expense report not found');
386 }
387
388 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport)) {
389 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
390 }
391
392 if ($this->expensereport->status != ExpenseReport::STATUS_DRAFT) {
393 throw new RestException(403, 'Expense report must be in draft status to update lines');
394 }
395
396 $line = new ExpenseReportLine($this->db);
397 $result = $line->fetch($lineid);
398 if ($result <= 0) {
399 throw new RestException(404, 'Expense report line not found');
400 }
401
402 $request_data = (object) $request_data;
403
404 $request_data->comments = sanitizeVal($request_data->comments, 'restricthtml');
405
406 $updateRes = $this->expensereport->updateline(
407 $lineid,
408 (int) $request_data->fk_c_type_fees,
409 $request_data->fk_project,
410 $request_data->vatrate,
411 $request_data->comments,
412 $request_data->qty,
413 $request_data->value_unit,
414 $request_data->date,
415 $id,
416 $request_data->fk_c_exp_tax_cat,
417 $request_data->fk_ecm_files
418 );
419
420 if ($updateRes > 0) {
421 $result = $this->get($id);
422 unset($result->line);
423 return $this->_cleanObjectDatas($result);
424 } else {
425 throw new RestException(500, 'Error updating line: '.$this->expensereport->error);
426 }
427 }
428
445 public function deleteLine($id, $lineid)
446 {
447 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
448 throw new RestException(403);
449 }
450
451 $result = $this->expensereport->fetch($id);
452 if (!$result) {
453 throw new RestException(404, 'Expense report not found');
454 }
455
456 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport)) {
457 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
458 }
459
460 // Check if line exists
461 $lineExists = false;
462 $this->expensereport->fetch_lines();
463 foreach ($this->expensereport->lines as $line) {
464 if ($line->id == $lineid) {
465 $lineExists = true;
466 break;
467 }
468 }
469
470 if (!$lineExists) {
471 throw new RestException(404, 'Line not found');
472 }
473
474 if ($this->expensereport->status != ExpenseReport::STATUS_DRAFT) {
475 throw new RestException(403, 'Expense report must be in draft status to delete lines');
476 }
477
478 $result = $this->expensereport->deleteLine($lineid);
479 if ($result > 0) {
480 return $this->get($id);
481 } else {
482 throw new RestException(500, 'Error deleting line: '.$this->expensereport->error);
483 }
484 }
485
503 public function put($id, $request_data = null)
504 {
505 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
506 throw new RestException(403);
507 }
508
509 $result = $this->expensereport->fetch($id);
510 if (!$result) {
511 throw new RestException(404, 'Expense report not found');
512 }
513
514 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport)) {
515 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
516 }
517 foreach ($request_data as $field => $value) {
518 if ($field == 'id') {
519 continue;
520 }
521 if ($field === 'caller') {
522 // 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
523 $this->expensereport->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
524 continue;
525 }
526
527 if ($field == 'array_options' && is_array($value)) {
528 foreach ($value as $index => $val) {
529 $this->expensereport->array_options[$index] = $this->_checkValForAPI($field, $val, $this->expensereport);
530 }
531 continue;
532 }
533
534 $this->expensereport->$field = $this->_checkValForAPI($field, $value, $this->expensereport);
535 }
536
537 if ($this->expensereport->update(DolibarrApiAccess::$user) > 0) {
538 return $this->get($id);
539 } else {
540 throw new RestException(500, $this->expensereport->error);
541 }
542 }
543
556 public function delete($id)
557 {
558 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'supprimer')) {
559 throw new RestException(403);
560 }
561
562 $result = $this->expensereport->fetch($id);
563 if (!$result) {
564 throw new RestException(404, 'Expense report not found');
565 }
566
567 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport)) {
568 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
569 }
570
571 if (!$this->expensereport->delete(DolibarrApiAccess::$user)) {
572 throw new RestException(500, 'Error when delete Expense Report : '.$this->expensereport->error);
573 }
574
575 return array(
576 'success' => array(
577 'code' => 200,
578 'message' => 'Expense Report deleted'
579 )
580 );
581 }
582
598 public function setToDraft($id)
599 {
600 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
601 throw new RestException(403, "Insufficiant rights");
602 }
603 $result = $this->expensereport->fetch($id);
604 if (!$result) {
605 throw new RestException(404, 'Expense report not found');
606 }
607
608 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport)) {
609 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
610 }
611
612 $result = $this->expensereport->setStatut(0);
613 if ($result == 0) {
614 throw new RestException(304, 'Error nothing done. May be object is already draft');
615 }
616 if ($result < 0) {
617 throw new RestException(500, 'Error when setting to draft expense report: '.$this->expensereport->error);
618 }
619
620 return $this->_cleanObjectDatas($this->expensereport);
621 }
622
642 public function validate($id, $notrigger = 0)
643 {
644 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
645 throw new RestException(403, "Insufficiant rights");
646 }
647 $result = $this->expensereport->fetch($id);
648 if (!$result) {
649 throw new RestException(404, 'Expense report not found');
650 }
651
652 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport)) {
653 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
654 }
655
656 $result = $this->expensereport->setValidate(DolibarrApiAccess::$user, $notrigger);
657 if ($result == 0) {
658 throw new RestException(304, 'Error nothing done. May be object is already validated');
659 }
660 if ($result < 0) {
661 throw new RestException(500, 'Error when validating expense report: '.$this->expensereport->error);
662 }
663
664 return $this->_cleanObjectDatas($this->expensereport);
665 }
666
667
687 public function approve($id, $notrigger = 0)
688 {
689 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'approve')) {
690 throw new RestException(403, "Insufficiant rights");
691 }
692 $result = $this->expensereport->fetch($id);
693 if (!$result) {
694 throw new RestException(404, 'Expense report not found');
695 }
696
697 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport)) {
698 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
699 }
700
701 $result = $this->expensereport->setApproved(DolibarrApiAccess::$user, $notrigger);
702 if ($result == 0) {
703 throw new RestException(304, 'Error nothing done. May be object is already approved');
704 }
705 if ($result < 0) {
706 throw new RestException(500, 'Error when approving expense report: '.$this->expensereport->error);
707 }
708
709 return $this->_cleanObjectDatas($this->expensereport);
710 }
711
712
733 public function deny($id, $details, $notrigger = 0)
734 {
735 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'approve')) {
736 throw new RestException(403, "Insufficiant rights");
737 }
738 $result = $this->expensereport->fetch($id);
739 if (!$result) {
740 throw new RestException(404, 'Expense report not found');
741 }
742
743 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport)) {
744 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
745 }
746
747 $result = $this->expensereport->setDeny(DolibarrApiAccess::$user, $details, $notrigger);
748 if ($result == 0) {
749 throw new RestException(304, 'Error nothing done. May be object is already denied');
750 }
751 if ($result < 0) {
752 throw new RestException(500, 'Error when denying expense report: '.$this->expensereport->error);
753 }
754
755
756
757 return $this->_cleanObjectDatas($this->expensereport);
758 }
759
777 public function cancel($id, $detail, $notrigger = 0)
778 {
779 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
780 throw new RestException(403, "Insufficiant rights");
781 }
782 $result = $this->expensereport->fetch($id);
783 if (!$result) {
784 throw new RestException(404, 'Expense report not found');
785 }
786
787 if (!DolibarrApi::_checkAccessToResource('expensereport', $this->expensereport)) {
788 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
789 }
790
791 if ($this->expensereport->status == ExpenseReport::STATUS_CANCELED) {
792 throw new RestException(403, 'Expense report already canceled');
793 }
794 $result = $this->expensereport->set_cancel(DolibarrApiAccess::$user, $detail, $notrigger);
795 if ($result < 0) {
796 throw new RestException(500, 'Error when cancelling expense report: '.$this->expensereport->error);
797 }
798
799 $result = $this->expensereport->fetch($id);
800 return $this->_cleanObjectDatas($this->expensereport);
801 }
802
820 public function getAllPayments($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0)
821 {
822 $list = array();
823
824 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'lire')) {
825 throw new RestException(403);
826 }
827
828 $sql = "SELECT t.rowid FROM " . MAIN_DB_PREFIX . "payment_expensereport as t, ".MAIN_DB_PREFIX."expensereport as e";
829 $sql .= " WHERE e.rowid = t.fk_expensereport";
830 $sql .= ' AND e.entity IN ('.getEntity('expensereport').')';
831
832 $sql .= $this->db->order($sortfield, $sortorder);
833 if ($limit) {
834 if ($page < 0) {
835 $page = 0;
836 }
837 $offset = $limit * $page;
838
839 $sql .= $this->db->plimit($limit + 1, $offset);
840 }
841
842 dol_syslog("API Rest request");
843 $result = $this->db->query($sql);
844
845 if ($result) {
846 $num = $this->db->num_rows($result);
847 $min = min($num, ($limit <= 0 ? $num : $limit));
848 for ($i = 0; $i < $min; $i++) {
849 $obj = $this->db->fetch_object($result);
850 $paymentExpenseReport = new PaymentExpenseReport($this->db);
851 if ($paymentExpenseReport->fetch($obj->rowid) > 0) {
852 $list[] = $this->_cleanObjectDatas($paymentExpenseReport);
853 }
854 }
855 } else {
856 throw new RestException(503, 'Error when retrieving list of paymentexpensereport: ' . $this->db->lasterror());
857 }
858
859 return $list;
860 }
861
874 public function getPayments($pid)
875 {
876 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'lire')) {
877 throw new RestException(403);
878 }
879
880 $paymentExpenseReport = new PaymentExpenseReport($this->db);
881 $result = $paymentExpenseReport->fetch($pid);
882 if (!$result) {
883 throw new RestException(404, 'paymentExpenseReport not found');
884 }
885
886 return $this->_cleanObjectDatas($paymentExpenseReport);
887 }
888
903 public function addPayment($id, $request_data = null)
904 {
905 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
906 throw new RestException(403);
907 }
908 // Check mandatory fields
909 $result = $this->_validatepayment($request_data);
910
911 $paymentExpenseReport = new PaymentExpenseReport($this->db);
912 $paymentExpenseReport->fk_expensereport = $id;
913 foreach ($request_data as $field => $value) {
914 $paymentExpenseReport->$field = $this->_checkValForAPI($field, $value, $paymentExpenseReport);
915 }
916
917 if ($paymentExpenseReport->create(DolibarrApiAccess::$user) < 0) {
918 throw new RestException(500, 'Error creating paymentExpenseReport', array_merge(array($paymentExpenseReport->error), $paymentExpenseReport->errors));
919 }
920 if (isModEnabled("bank")) {
921 $paymentExpenseReport->addPaymentToBank(
922 DolibarrApiAccess::$user,
923 'payment_expensereport',
924 '(ExpenseReportPayment)',
925 (int) $request_data['accountid'],
926 '',
927 ''
928 );
929 }
930
931 return $paymentExpenseReport->id;
932 }
933
948 public function updatePayment($id, $request_data = null)
949 {
950 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer')) {
951 throw new RestException(403);
952 }
953
954 $paymentExpenseReport = new PaymentExpenseReport($this->db);
955 $result = $paymentExpenseReport->fetch($id);
956 if (!$result) {
957 throw new RestException(404, 'payment of expense report not found');
958 }
959
960 foreach ($request_data as $field => $value) {
961 if ($field == 'id') {
962 continue;
963 }
964 $paymentExpenseReport->$field = $this->_checkValForAPI($field, $value, $paymentExpenseReport);
965 }
966
967 if ($paymentExpenseReport->update(DolibarrApiAccess::$user) > 0) {
968 return $this->get($id);
969 } else {
970 throw new RestException(500, $paymentExpenseReport->error);
971 }
972 }
973
982 /*public function delete($id)
983 {
984 if (!DolibarrApiAccess::$user->hasRight('expensereport', 'creer') {
985 throw new RestException(403);
986 }
987 $paymentExpenseReport = new PaymentExpenseReport($this->db);
988 $result = $paymentExpenseReport->fetch($id);
989 if (!$result) {
990 throw new RestException(404, 'paymentExpenseReport not found');
991 }
992
993 if ($paymentExpenseReport->delete(DolibarrApiAccess::$user) < 0) {
994 throw new RestException(403, 'error when deleting paymentExpenseReport');
995 }
996
997 return array(
998 'success' => array(
999 'code' => 200,
1000 'message' => 'paymentExpenseReport deleted'
1001 )
1002 );
1003 }*/
1004
1005
1006
1007 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1017 protected function _cleanObjectDatas($object)
1018 {
1019 // phpcs:enable
1020 $object = parent::_cleanObjectDatas($object);
1021
1022 unset($object->fk_statut);
1023 unset($object->statut);
1024 unset($object->user);
1025 unset($object->thirdparty);
1026
1027 unset($object->cond_reglement);
1028 unset($object->shipping_method_id);
1029
1030 unset($object->barcode_type);
1031 unset($object->barcode_type_code);
1032 unset($object->barcode_type_label);
1033 unset($object->barcode_type_coder);
1034
1035 unset($object->code_paiement);
1036 unset($object->code_statut);
1037 unset($object->fk_c_paiement);
1038 unset($object->fk_incoterms);
1039 unset($object->label_incoterms);
1040 unset($object->location_incoterms);
1041 unset($object->mode_reglement_id);
1042 unset($object->cond_reglement_id);
1043
1044 unset($object->name);
1045 unset($object->lastname);
1046 unset($object->firstname);
1047 unset($object->civility_id);
1048 unset($object->cond_reglement_id);
1049 unset($object->contact);
1050 unset($object->contact_id);
1051
1052 unset($object->state);
1053 unset($object->state_id);
1054 unset($object->state_code);
1055 unset($object->country);
1056 unset($object->country_id);
1057 unset($object->country_code);
1058
1059 unset($object->note); // We already use note_public and note_pricate
1060
1061 return $object;
1062 }
1063
1071 private function _validate($data)
1072 {
1073 if ($data === null) {
1074 $data = array();
1075 }
1076 $expensereport = array();
1077 foreach (ExpenseReports::$FIELDS as $field) {
1078 if (!isset($data[$field])) {
1079 throw new RestException(400, "$field field missing");
1080 }
1081 $expensereport[$field] = $data[$field];
1082 }
1083 return $expensereport;
1084 }
1085
1093 private function _validatepayment($data)
1094 {
1095 if ($data === null) {
1096 $data = array();
1097 }
1098 $expensereport = array();
1099 foreach (ExpenseReports::$FIELDSPAYMENT as $field) {
1100 if (!isset($data[$field])) {
1101 throw new RestException(400, "$field field missing");
1102 }
1103 $expensereport[$field] = $data[$field];
1104 }
1105 return $expensereport;
1106 }
1107
1116 private function _validateLine($data)
1117 {
1118 if ($data === null) {
1119 $data = array();
1120 }
1121 $expenseReport = array();
1122 foreach (ExpenseReports::$FIELDSLINE as $field) {
1123 if (!isset($data[$field])) {
1124 throw new RestException(400, "$field field missing");
1125 }
1126 $expenseReport[$field] = $data[$field];
1127 }
1128 return $expenseReport;
1129 }
1130}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
const STATUS_DRAFT
Draft status.
const STATUS_CANCELED
Classified canceled.
Class of expense report details lines.
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.
deleteLine($id, $lineid)
Delete a line from an expense report.
getLines($id)
Get lines of 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)
Update expense report general fields.
cancel($id, $detail, $notrigger=0)
Cancel 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.
_validateLine($data)
Validate fields before create or update object.
setToDraft($id)
Set an expense report to draft.
putLine($id, $lineid, $request_data=null)
Update a line of an expense report.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $user_ids='', $sqlfilters='', $properties='', $pagination_data=false)
List expense reports.
postLine($id, $request_data=null)
Add a line to an expense report.
Class to manage payments of expense report.
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.