dolibarr 24.0.2
api_holidays.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-2026 Charlene Benke <charlene@patas-monkey.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.'/holiday/class/holiday.class.php';
26require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
27
28
37class Holidays extends DolibarrApi
38{
42 public static $FIELDS = array(
43 'fk_user',
44 'date_debut',
45 'date_fin',
46 );
47
54 public static $FIELDS_FORBIDDEN_FOR_API = array(
55 'status',
56 'statut',
57 'fk_validator',
58 'date_valid',
59 'fk_user_valid',
60 'date_approval',
61 'fk_user_approve',
62 'date_refuse',
63 'fk_user_refuse',
64 'detail_refuse',
65 );
66
70 public $holiday;
71
72
76 public function __construct()
77 {
78 global $db;
79
80 $this->db = $db;
81 $this->holiday = new Holiday($this->db);
82 }
83
96 public function get($id)
97 {
98 if (!DolibarrApiAccess::$user->hasRight('holiday', 'read')) {
99 throw new RestException(403);
100 }
101
102 $result = $this->holiday->fetch($id);
103 if (!$result) {
104 throw new RestException(404, 'Leave not found');
105 }
106
107 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
108 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
109 }
110
111 $this->holiday->fetchObjectLinked();
112 return $this->_cleanObjectDatas($this->holiday);
113 }
114
134 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = '', $sqlfilters = '', $properties = '', $pagination_data = false)
135 {
136 if (!DolibarrApiAccess::$user->hasRight('holiday', 'read') && !DolibarrApiAccess::$user->hasRight('holiday', 'readall')) {
137 throw new RestException(403);
138 }
139
140 $obj_ret = array();
141
142 // case of external user, $societe param is ignored and replaced by user's socid
143 //$socid = DolibarrApiAccess::$user->socid ?: $societe;
144
145 $sql = "SELECT t.rowid";
146 $sql .= " FROM ".MAIN_DB_PREFIX."holiday AS t LEFT JOIN ".MAIN_DB_PREFIX."holiday_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Link to extrafields is to allow to search parameters in the API GET call, so we will be able to filter on extrafields
147 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user AS u ON t.fk_user = u.rowid";
148 $sql .= ' WHERE t.entity IN ('.getEntity('holiday').')';
149 if ($user_ids) {
150 $sql .= " AND t.fk_user IN (".$this->db->sanitize($user_ids).")";
151 }
152 if (!DolibarrApiAccess::$user->hasRight('holiday', 'readall')) {
153 $childids = DolibarrApiAccess::$user->getAllChildIds(1);
154 $sql .= " AND t.fk_user IN (".$this->db->sanitize(implode(',', $childids)).")";
155 }
156
157 // Add sql filters
158 if ($sqlfilters) {
159 $errormessage = '';
160 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
161 if ($errormessage) {
162 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
163 }
164 }
165
166 //this query will return total orders with the filters given
167 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
168
169 $sql .= $this->db->order($sortfield, $sortorder);
170 if ($limit) {
171 if ($page < 0) {
172 $page = 0;
173 }
174 $offset = $limit * $page;
175
176 $sql .= $this->db->plimit($limit + 1, $offset);
177 }
178
179 $result = $this->db->query($sql);
180
181 if ($result) {
182 $num = $this->db->num_rows($result);
183 $min = min($num, ($limit <= 0 ? $num : $limit));
184 $i = 0;
185 while ($i < $min) {
186 $obj = $this->db->fetch_object($result);
187 $holiday_static = new Holiday($this->db);
188 if ($holiday_static->fetch($obj->rowid)) {
189 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($holiday_static), $properties);
190 }
191 $i++;
192 }
193 } else {
194 throw new RestException(503, 'Error when retrieve Leave list : '.$this->db->lasterror());
195 }
196
197 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
198 if ($pagination_data) {
199 $totalsResult = $this->db->query($sqlTotals);
200 $total = $this->db->fetch_object($totalsResult)->total;
201
202 $tmp = $obj_ret;
203 $obj_ret = [];
204
205 $obj_ret['data'] = $tmp;
206 $obj_ret['pagination'] = [
207 'total' => (int) $total,
208 'page' => $page, //count starts from 0
209 'page_count' => ceil((int) $total / $limit),
210 'limit' => $limit
211 ];
212 }
213
214 return $obj_ret;
215 }
216
229 public function post($request_data = null)
230 {
231 if (!DolibarrApiAccess::$user->hasRight('holiday', 'write')) {
232 throw new RestException(403, "Insufficiant rights");
233 }
234
235 // Check mandatory fields
236 $result = $this->_validate($request_data);
237
238 // Check that the leave is for the user himself or for a user of his hierarchy (same rule as holiday/card.php)
239 if (!DolibarrApiAccess::$user->hasRight('holiday', 'writeall') && !in_array((int) $request_data['fk_user'], DolibarrApiAccess::$user->getAllChildIds(1))) {
240 throw new RestException(403, 'UserNotInHierachy');
241 }
242
243 foreach ($request_data as $field => $value) {
244 if ($field === 'caller') {
245 // 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
246 $this->holiday->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
247 continue;
248 }
249 if (in_array($field, self::$FIELDS_FORBIDDEN_FOR_API) && $field !== 'fk_validator') {
250 throw new RestException(400, "Field '".$field."' is not allowed in create endpoint. Use dedicated routes (validate, approve, refuse, cancel, reopen) to change the workflow status.");
251 }
252
253 $this->holiday->$field = $this->_checkValForAPI($field, $value, $this->holiday);
254 }
255 /*if (isset($request_data["lines"])) {
256 $lines = array();
257 foreach ($request_data["lines"] as $line) {
258 array_push($lines, (object) $line);
259 }
260 $this->holiday->lines = $lines;
261 }*/
262 if ($this->holiday->create(DolibarrApiAccess::$user) < 0) {
263 throw new RestException(500, "Error creating holiday", array_merge(array($this->holiday->error), $this->holiday->errors));
264 }
265
266 return $this->holiday->id;
267 }
268
269
287 public function put($id, $request_data = null)
288 {
289 if (!DolibarrApiAccess::$user->hasRight('holiday', 'write')) {
290 throw new RestException(403);
291 }
292
293 $result = $this->holiday->fetch($id);
294 if (!$result) {
295 throw new RestException(404, 'Leave not found');
296 }
297
298 // Only a draft of the user himself or of his hierarchy can be modified (same rule as holiday/card.php)
299 if (!DolibarrApiAccess::$user->hasRight('holiday', 'writeall') && !in_array((int) $this->holiday->fk_user, DolibarrApiAccess::$user->getAllChildIds(1))) {
300 throw new RestException(403, 'UserNotInHierachy');
301 }
302 if ($this->holiday->status != Holiday::STATUS_DRAFT) {
303 throw new RestException(400, 'Only a draft leave can be modified');
304 }
305
306 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
307 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
308 }
309
310 if (!is_array($request_data)) {
311 $request_data = array();
312 }
313
314 foreach ($request_data as $field => $value) {
315 if ($field == 'id') {
316 continue;
317 }
318 if ($field === 'caller') {
319 // 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
320 $this->holiday->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
321 continue;
322 }
323 if (in_array($field, self::$FIELDS_FORBIDDEN_FOR_API)) {
324 throw new RestException(400, "Field '".$field."' is not allowed in update endpoint. Use dedicated routes (validate, approve, refuse, cancel, reopen) to change the workflow status.");
325 }
326
327 if ($field == 'array_options' && is_array($value)) {
328 foreach ($value as $index => $val) {
329 $this->holiday->array_options[$index] = $this->_checkValExtrafieldsForAPI($index, $val, $this->holiday);
330 }
331 continue;
332 }
333
334 $this->holiday->$field = $this->_checkValForAPI($field, $value, $this->holiday);
335 }
336
337 if ($this->holiday->update(DolibarrApiAccess::$user) > 0) {
338 return $this->get($id);
339 } else {
340 throw new RestException(500, $this->holiday->error);
341 }
342 }
343
356 public function delete($id)
357 {
358 if (!DolibarrApiAccess::$user->hasRight('holiday', 'delete')) {
359 throw new RestException(403);
360 }
361
362 $result = $this->holiday->fetch($id);
363 if (!$result) {
364 throw new RestException(404, 'Leave not found');
365 }
366
367 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
368 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
369 }
370
371 // Same rule as holiday/card.php
372 if (!in_array($this->holiday->status, array(Holiday::STATUS_DRAFT, Holiday::STATUS_CANCELED, Holiday::STATUS_REFUSED))) {
373 throw new RestException(400, 'Only a draft, canceled or refused leave can be deleted');
374 }
375
376 if (!$this->holiday->delete(DolibarrApiAccess::$user)) {
377 throw new RestException(500, 'Error when deleting Leave : '.$this->holiday->error);
378 }
379
380 return array(
381 'success' => array(
382 'code' => 200,
383 'message' => 'Leave deleted'
384 )
385 );
386 }
387
407 public function validate($id, $notrigger = 0)
408 {
409 if (!DolibarrApiAccess::$user->hasRight('holiday', 'write')) {
410 throw new RestException(403, "Insufficiant rights");
411 }
412 $result = $this->holiday->fetch($id);
413 if (!$result) {
414 throw new RestException(404, 'Leave not found');
415 }
416
417 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
418 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
419 }
420
421 // Only a draft can be validated, by its owner or his hierarchy (same rule as holiday/card.php)
422 if (!DolibarrApiAccess::$user->hasRight('holiday', 'writeall') && !in_array((int) $this->holiday->fk_user, DolibarrApiAccess::$user->getAllChildIds(1))) {
423 throw new RestException(403, 'UserNotInHierachy');
424 }
425 if ($this->holiday->status != Holiday::STATUS_DRAFT) {
426 throw new RestException(400, 'Only a draft leave can be validated');
427 }
428
429 $this->holiday->status = Holiday::STATUS_VALIDATED;
430 $result = $this->holiday->validate(DolibarrApiAccess::$user, $notrigger);
431 if ($result == 0) {
432 throw new RestException(304, 'Error nothing done. May be object is already validated');
433 }
434 if ($result < 0) {
435 throw new RestException(500, 'Error when validating leave: '.$this->holiday->error);
436 }
437
438 return $this->_cleanObjectDatas($this->holiday);
439 }
440
441
461 public function approve($id, $notrigger = 0)
462 {
463 if (!DolibarrApiAccess::$user->hasRight('holiday', 'approve')) {
464 throw new RestException(403, "Insufficiant rights");
465 }
466 $result = $this->holiday->fetch($id);
467 if (!$result) {
468 throw new RestException(404, 'Leave not found');
469 }
470
471 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
472 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
473 }
474
475 // Only a leave waiting for approval can be approved, by its approver (same rule as holiday/card.php)
476 if ($this->holiday->status != Holiday::STATUS_VALIDATED) {
477 throw new RestException(400, 'Only a validated leave can be approved');
478 }
479 if (DolibarrApiAccess::$user->id != $this->holiday->fk_validator && !DolibarrApiAccess::$user->hasRight('holiday', 'writeall')) {
480 throw new RestException(403, 'Only the approver of the leave can approve it');
481 }
482
483 $this->holiday->date_approval = dol_now();
484 $this->holiday->fk_user_approve = DolibarrApiAccess::$user->id;
485 $this->holiday->status = Holiday::STATUS_APPROVED;
486 $this->db->begin();
487 $result = $this->holiday->approve(DolibarrApiAccess::$user, $notrigger);
488 // Decrease the balance of the user (same code as holiday/card.php)
489 if ($result > 0 && !getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH')) {
490 global $langs;
491 $langs->load('holiday');
492
493 $tmpUser = new User($this->db);
494 $tmpUser->fetch($this->holiday->fk_user);
495
496 // Calculate number of days consumed
497 $nbopenedday = num_open_day($this->holiday->date_debut_gmt, $this->holiday->date_fin_gmt, 0, 1, $this->holiday->halfday, $tmpUser->country_id);
498 $soldeActuel = $this->holiday->getCpforUser($this->holiday->fk_user, $this->holiday->fk_type);
499 $newSolde = ($soldeActuel - $nbopenedday);
500 $label = $this->holiday->ref.' - '.$langs->transnoentitiesnoconv("HolidayConsumption");
501
502 // The modification is added to the LOG, then the balance is updated
503 if ($this->holiday->addLogCP(DolibarrApiAccess::$user->id, $this->holiday->fk_user, $label, $newSolde, $this->holiday->fk_type) < 0
504 || $this->holiday->updateSoldeCP($this->holiday->fk_user, $newSolde, $this->holiday->fk_type) < 0) {
505 $result = -1;
506 }
507 }
508 if ($result > 0) {
509 $this->db->commit();
510 } else {
511 $this->db->rollback();
512 }
513 if ($result == 0) {
514 throw new RestException(304, 'Error nothing done. May be object is already approved');
515 }
516 if ($result < 0) {
517 throw new RestException(500, 'Error when approving holiday: '.$this->holiday->error);
518 }
519
520 return $this->_cleanObjectDatas($this->holiday);
521 }
522
542 public function cancel($id, $notrigger = 0)
543 {
544 if (!DolibarrApiAccess::$user->hasRight('holiday', 'write')) {
545 throw new RestException(403, "Insufficient rights");
546 }
547
548 $result = $this->holiday->fetch($id);
549 if (!$result) {
550 throw new RestException(404, 'Leave not found');
551 }
552
553 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
554 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
555 }
556
557 // Only a leave waiting for approval or approved can be canceled (same rule as holiday/card.php)
558 if ($this->holiday->status != Holiday::STATUS_VALIDATED && $this->holiday->status != Holiday::STATUS_APPROVED) {
559 throw new RestException(400, 'Only a validated or approved leave can be canceled');
560 }
561 if (DolibarrApiAccess::$user->id != $this->holiday->fk_validator && !DolibarrApiAccess::$user->hasRight('holiday', 'writeall') && !DolibarrApiAccess::$user->hasRight('holiday', 'approve')
562 && !in_array((int) $this->holiday->fk_user, DolibarrApiAccess::$user->getAllChildIds(1))) {
563 throw new RestException(403, 'UserNotInHierachy');
564 }
565
566 $oldstatus = $this->holiday->status;
567 $this->holiday->date_cancel = dol_now();
568 $this->holiday->fk_user_cancel = DolibarrApiAccess::$user->id;
569 $this->holiday->status = Holiday::STATUS_CANCELED;
570 $this->db->begin();
571 $result = $this->holiday->update(DolibarrApiAccess::$user, $notrigger);
572 // The leave was approved, so the balance was decreased: increase it back (same code as holiday/card.php)
573 if ($result > 0 && $oldstatus == Holiday::STATUS_APPROVED) {
574 global $langs;
575 $langs->load('holiday');
576
577 if (!$notrigger && $this->holiday->call_trigger('HOLIDAY_CANCEL', DolibarrApiAccess::$user) < 0) {
578 $result = -1;
579 }
580
581 $startDate = $this->holiday->date_debut_gmt;
582 $endDate = $this->holiday->date_fin_gmt;
583 $alreadydebited = true;
584
585 if (getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH')) {
586 $lastUpdate = strtotime($this->holiday->getConfCP('lastUpdate', dol_print_date(dol_now(), '%Y%m%d%H%M%S')));
587 $date = strtotime('-1 month', $lastUpdate);
588 $endOfMonthBeforeLastUpdate = dol_mktime(0, 0, 0, (int) date('m', $date), (int) date('t', $date), (int) date('Y', $date), 1);
589 if ($this->holiday->date_debut_gmt < $endOfMonthBeforeLastUpdate && $this->holiday->date_fin_gmt > $endOfMonthBeforeLastUpdate) {
590 $endDate = $endOfMonthBeforeLastUpdate;
591 } elseif ($this->holiday->date_debut_gmt > $endOfMonthBeforeLastUpdate) {
592 $alreadydebited = false; // The leave starts after the last monthly update, nothing was debited yet
593 }
594 }
595
596 $tmpUser = new User($this->db);
597 $tmpUser->fetch($this->holiday->fk_user);
598
599 // Calculate number of days consumed
600 $nbopenedday = $alreadydebited ? num_open_day($startDate, $endDate, 0, 1, $this->holiday->halfday, $tmpUser->country_id) : 0;
601 $soldeActuel = $this->holiday->getCpforUser($this->holiday->fk_user, $this->holiday->fk_type);
602 $newSolde = ($soldeActuel + $nbopenedday);
603 $label = $this->holiday->ref.' - '.$langs->transnoentitiesnoconv("HolidayCreditAfterCancellation");
604
605 // The modification is added to the LOG, then the balance is updated
606 if ($this->holiday->addLogCP(DolibarrApiAccess::$user->id, $this->holiday->fk_user, $label, $newSolde, $this->holiday->fk_type) < 0
607 || $this->holiday->updateSoldeCP($this->holiday->fk_user, $newSolde, $this->holiday->fk_type) < 0) {
608 $result = -1;
609 }
610 }
611 if ($result > 0) {
612 $this->db->commit();
613 } else {
614 $this->db->rollback();
615 }
616 if ($result == 0) {
617 throw new RestException(304, 'Error nothing done. May be object is already canceled');
618 }
619 if ($result < 0) {
620 throw new RestException(500, 'Error when canceling holiday: '.$this->holiday->error);
621 }
622
623 return $this->_cleanObjectDatas($this->holiday);
624 }
625
646 public function refuse($id, $detail_refuse, $notrigger = 0)
647 {
648 if (!DolibarrApiAccess::$user->hasRight('holiday', 'approve')) {
649 throw new RestException(403, "Insufficient rights");
650 }
651
652 $result = $this->holiday->fetch($id);
653 if (!$result) {
654 throw new RestException(404, 'Leave not found');
655 }
656
657 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
658 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
659 }
660
661 // Only a leave waiting for approval can be refused, by its approver (same rule as holiday/card.php)
662 if ($this->holiday->status != Holiday::STATUS_VALIDATED) {
663 throw new RestException(400, 'Only a validated leave can be refused');
664 }
665 if (DolibarrApiAccess::$user->id != $this->holiday->fk_validator && !DolibarrApiAccess::$user->hasRight('holiday', 'writeall')) {
666 throw new RestException(403, 'Only the approver of the leave can refuse it');
667 }
668
669 $this->holiday->date_refuse = dol_now();
670 $this->holiday->fk_user_refuse = DolibarrApiAccess::$user->id;
671 $this->holiday->status = Holiday::STATUS_REFUSED;
672 $this->holiday->detail_refuse = $detail_refuse;
673 $result = $this->holiday->update(DolibarrApiAccess::$user, $notrigger);
674 if ($result == 0) {
675 throw new RestException(304, 'Error nothing done. May be object is already refused');
676 }
677 if ($result < 0) {
678 throw new RestException(500, 'Error when refusing holiday: '.$this->holiday->error);
679 }
680
681 return $this->_cleanObjectDatas($this->holiday);
682 }
683
706 public function reopen($id, $notrigger = 0)
707 {
708 if (!DolibarrApiAccess::$user->hasRight('holiday', 'write')) {
709 throw new RestException(403, "Insufficient rights");
710 }
711
712 $result = $this->holiday->fetch($id);
713 if (!$result) {
714 throw new RestException(404, 'Leave not found');
715 }
716
717 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
718 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
719 }
720
721 // Check if the holiday is actually canceled
722 if ($this->holiday->statut != Holiday::STATUS_CANCELED) {
723 throw new RestException(400, 'Holiday is not canceled. Only canceled holidays can be reopened.');
724 }
725 $this->holiday->status = Holiday::STATUS_VALIDATED;
726 $result = $this->holiday->validate(DolibarrApiAccess::$user, $notrigger);
727 if ($result < 0) {
728 throw new RestException(500, 'Error when canceling holiday: '.$this->holiday->error);
729 }
730
731 return $this->_cleanObjectDatas($this->holiday);
732 }
733
734 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
744 protected function _cleanObjectDatas($object)
745 {
746 // phpcs:enable
747 $object = parent::_cleanObjectDatas($object);
751 unset($object->statut);
752 unset($object->user);
753 unset($object->thirdparty);
754
755 unset($object->cond_reglement);
756 unset($object->shipping_method_id);
757
758 unset($object->barcode_type);
759 unset($object->barcode_type_code);
760 unset($object->barcode_type_label);
761 unset($object->barcode_type_coder);
762
763 unset($object->mode_reglement_id);
764 unset($object->cond_reglement_id);
765
766 unset($object->name);
767 unset($object->lastname);
768 unset($object->firstname);
769 unset($object->civility_id);
770 unset($object->cond_reglement_id);
771 unset($object->contact);
772 unset($object->contact_id);
773
774 unset($object->state);
775 unset($object->state_id);
776 unset($object->state_code);
777 unset($object->country);
778 unset($object->country_id);
779 unset($object->country_code);
780
781 unset($object->logs);
782 unset($object->events);
783 unset($object->holiday);
784 unset($object->canvas);
785 unset($object->lines);
786
787 unset($object->totalpaid);
788 unset($object->totalpaid_multicurrency);
789
790 unset($object->note); // We already use note_public and note_pricate
791
792 return $object;
793 }
794
802 private function _validate($data)
803 {
804 if ($data === null) {
805 $data = array();
806 }
807 $holiday = array();
808 foreach (self::$FIELDS as $field) {
809 if (!isset($data[$field])) {
810 throw new RestException(400, "$field field missing");
811 }
812 $holiday[$field] = $data[$field];
813 }
814 return $holiday;
815 }
816}
$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:35
_checkValExtrafieldsForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
_cleanObjectDatas($object)
Clean sensitive object data @phpstan-template T.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $parenttableforentity='')
Check access by user to a given resource.
Class of the module paid holiday.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
const STATUS_REFUSED
Refused.
const STATUS_CANCELED
Canceled.
const STATUS_APPROVED
Approved.
_validate($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 leaves.
put($id, $request_data=null)
Update holiday general fields.
validate($id, $notrigger=0)
Validate a holiday.
refuse($id, $detail_refuse, $notrigger=0)
Refuse a holiday.
__construct()
Constructor.
cancel($id, $notrigger=0)
Cancel a holiday.
reopen($id, $notrigger=0)
Reopen a canceled holiday.
approve($id, $notrigger=0)
Approve a leave.
post($request_data=null)
Create a leave.
Class to manage Dolibarr users.
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $countryCodeOrId='', $user_id=0)
Function to return number of working days (and text of units) between two dates (working days)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:492