dolibarr 25.0.0-alpha
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-2026 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 // List of properties we can't filter on, whatever are permissions (to avoid guess by search binary attack).
160 // This includes sensitive properties of table llx_user joined by the request
161 $forbiddenfilterfields = array(
162 'pass',
163 'pass_crypted',
164 'pass_temp',
165 'api_key',
166 'openid',
167 'national_registration_number',
168 'salary',
169 'salaryextra',
170 'birth',
171 'address',
172 'personal_mobile',
173 'personal_email',
174 'note_private',
175 'iplastlogin',
176 'ippreviouslogin'
177 );
178 $errormessage = '';
179 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage, 0, 0, 0, $forbiddenfilterfields);
180 if ($errormessage) {
181 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
182 }
183 }
184
185 //this query will return total orders with the filters given
186 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
187
188 $sql .= $this->db->order($sortfield, $sortorder);
189 if ($limit) {
190 if ($page < 0) {
191 $page = 0;
192 }
193 $offset = $limit * $page;
194
195 $sql .= $this->db->plimit($limit + 1, $offset);
196 }
197
198 $result = $this->db->query($sql);
199
200 if ($result) {
201 $num = $this->db->num_rows($result);
202 $min = min($num, ($limit <= 0 ? $num : $limit));
203 $i = 0;
204 while ($i < $min) {
205 $obj = $this->db->fetch_object($result);
206 $holiday_static = new Holiday($this->db);
207 if ($holiday_static->fetch($obj->rowid)) {
208 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($holiday_static), $properties);
209 }
210 $i++;
211 }
212 } else {
213 throw new RestException(503, 'Error when retrieve Leave list : '.$this->db->lasterror());
214 }
215
216 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
217 if ($pagination_data) {
218 $totalsResult = $this->db->query($sqlTotals);
219 $total = $this->db->fetch_object($totalsResult)->total;
220
221 $tmp = $obj_ret;
222 $obj_ret = [];
223
224 $obj_ret['data'] = $tmp;
225 $obj_ret['pagination'] = [
226 'total' => (int) $total,
227 'page' => $page, //count starts from 0
228 'page_count' => ceil((int) $total / $limit),
229 'limit' => $limit
230 ];
231 }
232
233 return $obj_ret;
234 }
235
248 public function post($request_data = null)
249 {
250 if (!DolibarrApiAccess::$user->hasRight('holiday', 'write')) {
251 throw new RestException(403, "Insufficiant rights");
252 }
253
254 // Check mandatory fields
255 $result = $this->_validate($request_data);
256
257 // Check that the leave is for the user himself or for a user of his hierarchy (same rule as holiday/card.php)
258 if (!DolibarrApiAccess::$user->hasRight('holiday', 'writeall') && !in_array((int) $request_data['fk_user'], DolibarrApiAccess::$user->getAllChildIds(1))) {
259 throw new RestException(403, 'UserNotInHierachy');
260 }
261
262 foreach ($request_data as $field => $value) {
263 if ($field === 'caller') {
264 // 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
265 $this->holiday->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
266 continue;
267 }
268 if (in_array($field, self::$FIELDS_FORBIDDEN_FOR_API) && $field !== 'fk_validator') {
269 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.");
270 }
271
272 $this->holiday->$field = $this->_checkValForAPI($field, $value, $this->holiday);
273 }
274 /*if (isset($request_data["lines"])) {
275 $lines = array();
276 foreach ($request_data["lines"] as $line) {
277 array_push($lines, (object) $line);
278 }
279 $this->holiday->lines = $lines;
280 }*/
281 if ($this->holiday->create(DolibarrApiAccess::$user) < 0) {
282 throw new RestException(500, "Error creating holiday", array_merge(array($this->holiday->error), $this->holiday->errors));
283 }
284
285 return $this->holiday->id;
286 }
287
288
306 public function put($id, $request_data = null)
307 {
308 if (!DolibarrApiAccess::$user->hasRight('holiday', 'write')) {
309 throw new RestException(403);
310 }
311
312 $result = $this->holiday->fetch($id);
313 if (!$result) {
314 throw new RestException(404, 'Leave not found');
315 }
316
317 // Only a draft of the user himself or of his hierarchy can be modified (same rule as holiday/card.php)
318 if (!DolibarrApiAccess::$user->hasRight('holiday', 'writeall') && !in_array((int) $this->holiday->fk_user, DolibarrApiAccess::$user->getAllChildIds(1))) {
319 throw new RestException(403, 'UserNotInHierachy');
320 }
321 if ($this->holiday->status != Holiday::STATUS_DRAFT) {
322 throw new RestException(400, 'Only a draft leave can be modified');
323 }
324
325 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
326 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
327 }
328
329 if (!is_array($request_data)) {
330 $request_data = array();
331 }
332
333 foreach ($request_data as $field => $value) {
334 if ($field == 'id') {
335 continue;
336 }
337 if ($field === 'caller') {
338 // 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
339 $this->holiday->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
340 continue;
341 }
342 if (in_array($field, self::$FIELDS_FORBIDDEN_FOR_API)) {
343 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.");
344 }
345
346 if ($field == 'array_options' && is_array($value)) {
347 foreach ($value as $index => $val) {
348 $this->holiday->array_options[$index] = $this->_checkValExtrafieldsForAPI($index, $val, $this->holiday);
349 }
350 continue;
351 }
352
353 $this->holiday->$field = $this->_checkValForAPI($field, $value, $this->holiday);
354 }
355
356 if ($this->holiday->update(DolibarrApiAccess::$user) > 0) {
357 return $this->get($id);
358 } else {
359 throw new RestException(500, $this->holiday->errorsToString());
360 }
361 }
362
375 public function delete($id)
376 {
377 if (!DolibarrApiAccess::$user->hasRight('holiday', 'delete')) {
378 throw new RestException(403);
379 }
380
381 $result = $this->holiday->fetch($id);
382 if (!$result) {
383 throw new RestException(404, 'Leave not found');
384 }
385
386 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
387 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
388 }
389
390 // Same rule as holiday/card.php
391 if (!in_array($this->holiday->status, array(Holiday::STATUS_DRAFT, Holiday::STATUS_CANCELED, Holiday::STATUS_REFUSED))) {
392 throw new RestException(400, 'Only a draft, canceled or refused leave can be deleted');
393 }
394
395 if (!$this->holiday->delete(DolibarrApiAccess::$user)) {
396 throw new RestException(500, 'Error when deleting Leave : '.$this->holiday->errorsToString());
397 }
398
399 return array(
400 'success' => array(
401 'code' => 200,
402 'message' => 'Leave deleted'
403 )
404 );
405 }
406
426 public function validate($id, $notrigger = 0)
427 {
428 if (!DolibarrApiAccess::$user->hasRight('holiday', 'write')) {
429 throw new RestException(403, "Insufficiant rights");
430 }
431 $result = $this->holiday->fetch($id);
432 if (!$result) {
433 throw new RestException(404, 'Leave not found');
434 }
435
436 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
437 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
438 }
439
440 // Only a draft can be validated, by its owner or his hierarchy (same rule as holiday/card.php)
441 if (!DolibarrApiAccess::$user->hasRight('holiday', 'writeall') && !in_array((int) $this->holiday->fk_user, DolibarrApiAccess::$user->getAllChildIds(1))) {
442 throw new RestException(403, 'UserNotInHierachy');
443 }
444 if ($this->holiday->status != Holiday::STATUS_DRAFT) {
445 throw new RestException(400, 'Only a draft leave can be validated');
446 }
447
448 $this->holiday->status = Holiday::STATUS_VALIDATED;
449 $result = $this->holiday->validate(DolibarrApiAccess::$user, $notrigger);
450 if ($result == 0) {
451 throw new RestException(304, 'Error nothing done. May be object is already validated');
452 }
453 if ($result < 0) {
454 throw new RestException(500, 'Error when validating leave: '.$this->holiday->errorsToString());
455 }
456
457 return $this->_cleanObjectDatas($this->holiday);
458 }
459
460
480 public function approve($id, $notrigger = 0)
481 {
482 if (!DolibarrApiAccess::$user->hasRight('holiday', 'approve')) {
483 throw new RestException(403, "Insufficiant rights");
484 }
485 $result = $this->holiday->fetch($id);
486 if (!$result) {
487 throw new RestException(404, 'Leave not found');
488 }
489
490 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
491 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
492 }
493
494 // Only a leave waiting for approval can be approved, by its approver (same rule as holiday/card.php)
495 if ($this->holiday->status != Holiday::STATUS_VALIDATED) {
496 throw new RestException(400, 'Only a validated leave can be approved');
497 }
498 if (DolibarrApiAccess::$user->id != $this->holiday->fk_validator && !DolibarrApiAccess::$user->hasRight('holiday', 'writeall')) {
499 throw new RestException(403, 'Only the approver of the leave can approve it');
500 }
501
502 $this->holiday->date_approval = dol_now();
503 $this->holiday->fk_user_approve = DolibarrApiAccess::$user->id;
504 $this->holiday->status = Holiday::STATUS_APPROVED;
505 $this->db->begin();
506 $result = $this->holiday->approve(DolibarrApiAccess::$user, $notrigger);
507 // Decrease the balance of the user (same code as holiday/card.php)
508 if ($result > 0 && !getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH')) {
509 global $langs;
510 $langs->load('holiday');
511
512 $tmpUser = new User($this->db);
513 $tmpUser->fetch($this->holiday->fk_user);
514
515 // Calculate number of days consumed
516 $nbopenedday = num_open_day($this->holiday->date_debut_gmt, $this->holiday->date_fin_gmt, 0, 1, $this->holiday->halfday, $tmpUser->country_id);
517 $soldeActuel = $this->holiday->getCpforUser($this->holiday->fk_user, $this->holiday->fk_type);
518 $newSolde = ($soldeActuel - $nbopenedday);
519 $label = $this->holiday->ref.' - '.$langs->transnoentitiesnoconv("HolidayConsumption");
520
521 // The modification is added to the LOG, then the balance is updated
522 if ($this->holiday->addLogCP(DolibarrApiAccess::$user->id, $this->holiday->fk_user, $label, $newSolde, $this->holiday->fk_type) < 0
523 || $this->holiday->updateSoldeCP($this->holiday->fk_user, $newSolde, $this->holiday->fk_type) < 0) {
524 $result = -1;
525 }
526 }
527 if ($result > 0) {
528 $this->db->commit();
529 } else {
530 $this->db->rollback();
531 }
532 if ($result == 0) {
533 throw new RestException(304, 'Error nothing done. May be object is already approved');
534 }
535 if ($result < 0) {
536 throw new RestException(500, 'Error when approving holiday: '.$this->holiday->errorsToString());
537 }
538
539 return $this->_cleanObjectDatas($this->holiday);
540 }
541
561 public function cancel($id, $notrigger = 0)
562 {
563 if (!DolibarrApiAccess::$user->hasRight('holiday', 'write')) {
564 throw new RestException(403, "Insufficient rights");
565 }
566
567 $result = $this->holiday->fetch($id);
568 if (!$result) {
569 throw new RestException(404, 'Leave not found');
570 }
571
572 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
573 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
574 }
575
576 // Only a leave waiting for approval or approved can be canceled (same rule as holiday/card.php)
577 if ($this->holiday->status != Holiday::STATUS_VALIDATED && $this->holiday->status != Holiday::STATUS_APPROVED) {
578 throw new RestException(400, 'Only a validated or approved leave can be canceled');
579 }
580 if (DolibarrApiAccess::$user->id != $this->holiday->fk_validator && !DolibarrApiAccess::$user->hasRight('holiday', 'writeall') && !DolibarrApiAccess::$user->hasRight('holiday', 'approve')
581 && !in_array((int) $this->holiday->fk_user, DolibarrApiAccess::$user->getAllChildIds(1))) {
582 throw new RestException(403, 'UserNotInHierachy');
583 }
584
585 $oldstatus = $this->holiday->status;
586 $this->holiday->date_cancel = dol_now();
587 $this->holiday->fk_user_cancel = DolibarrApiAccess::$user->id;
588 $this->holiday->status = Holiday::STATUS_CANCELED;
589 $this->db->begin();
590 $result = $this->holiday->update(DolibarrApiAccess::$user, $notrigger);
591 // The leave was approved, so the balance was decreased: increase it back (same code as holiday/card.php)
592 if ($result > 0 && $oldstatus == Holiday::STATUS_APPROVED) {
593 global $langs;
594 $langs->load('holiday');
595
596 if (!$notrigger && $this->holiday->call_trigger('HOLIDAY_CANCEL', DolibarrApiAccess::$user) < 0) {
597 $result = -1;
598 }
599
600 $startDate = $this->holiday->date_debut_gmt;
601 $endDate = $this->holiday->date_fin_gmt;
602 $alreadydebited = true;
603
604 if (getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH')) {
605 $lastUpdate = strtotime($this->holiday->getConfCP('lastUpdate', dol_print_date(dol_now(), '%Y%m%d%H%M%S')));
606 $date = strtotime('-1 month', $lastUpdate);
607 $endOfMonthBeforeLastUpdate = dol_mktime(0, 0, 0, (int) date('m', $date), (int) date('t', $date), (int) date('Y', $date), 1);
608 if ($this->holiday->date_debut_gmt < $endOfMonthBeforeLastUpdate && $this->holiday->date_fin_gmt > $endOfMonthBeforeLastUpdate) {
609 $endDate = $endOfMonthBeforeLastUpdate;
610 } elseif ($this->holiday->date_debut_gmt > $endOfMonthBeforeLastUpdate) {
611 $alreadydebited = false; // The leave starts after the last monthly update, nothing was debited yet
612 }
613 }
614
615 $tmpUser = new User($this->db);
616 $tmpUser->fetch($this->holiday->fk_user);
617
618 // Calculate number of days consumed
619 $nbopenedday = $alreadydebited ? num_open_day($startDate, $endDate, 0, 1, $this->holiday->halfday, $tmpUser->country_id) : 0;
620 $soldeActuel = $this->holiday->getCpforUser($this->holiday->fk_user, $this->holiday->fk_type);
621 $newSolde = ($soldeActuel + $nbopenedday);
622 $label = $this->holiday->ref.' - '.$langs->transnoentitiesnoconv("HolidayCreditAfterCancellation");
623
624 // The modification is added to the LOG, then the balance is updated
625 if ($this->holiday->addLogCP(DolibarrApiAccess::$user->id, $this->holiday->fk_user, $label, $newSolde, $this->holiday->fk_type) < 0
626 || $this->holiday->updateSoldeCP($this->holiday->fk_user, $newSolde, $this->holiday->fk_type) < 0) {
627 $result = -1;
628 }
629 }
630 if ($result > 0) {
631 $this->db->commit();
632 } else {
633 $this->db->rollback();
634 }
635 if ($result == 0) {
636 throw new RestException(304, 'Error nothing done. May be object is already canceled');
637 }
638 if ($result < 0) {
639 throw new RestException(500, 'Error when canceling holiday: '.$this->holiday->errorsToString());
640 }
641
642 return $this->_cleanObjectDatas($this->holiday);
643 }
644
665 public function refuse($id, $detail_refuse, $notrigger = 0)
666 {
667 if (!DolibarrApiAccess::$user->hasRight('holiday', 'approve')) {
668 throw new RestException(403, "Insufficient rights");
669 }
670
671 $result = $this->holiday->fetch($id);
672 if (!$result) {
673 throw new RestException(404, 'Leave not found');
674 }
675
676 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
677 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
678 }
679
680 // Only a leave waiting for approval can be refused, by its approver (same rule as holiday/card.php)
681 if ($this->holiday->status != Holiday::STATUS_VALIDATED) {
682 throw new RestException(400, 'Only a validated leave can be refused');
683 }
684 if (DolibarrApiAccess::$user->id != $this->holiday->fk_validator && !DolibarrApiAccess::$user->hasRight('holiday', 'writeall')) {
685 throw new RestException(403, 'Only the approver of the leave can refuse it');
686 }
687
688 $this->holiday->date_refuse = dol_now();
689 $this->holiday->fk_user_refuse = DolibarrApiAccess::$user->id;
690 $this->holiday->status = Holiday::STATUS_REFUSED;
691 $this->holiday->detail_refuse = $detail_refuse;
692 $result = $this->holiday->update(DolibarrApiAccess::$user, $notrigger);
693 if ($result == 0) {
694 throw new RestException(304, 'Error nothing done. May be object is already refused');
695 }
696 if ($result < 0) {
697 throw new RestException(500, 'Error when refusing holiday: '.$this->holiday->errorsToString());
698 }
699
700 return $this->_cleanObjectDatas($this->holiday);
701 }
702
725 public function reopen($id, $notrigger = 0)
726 {
727 if (!DolibarrApiAccess::$user->hasRight('holiday', 'write')) {
728 throw new RestException(403, "Insufficient rights");
729 }
730
731 $result = $this->holiday->fetch($id);
732 if (!$result) {
733 throw new RestException(404, 'Leave not found');
734 }
735
736 if (!DolibarrApi::_checkAccessToResource('holiday', $this->holiday)) {
737 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
738 }
739
740 // Check if the holiday is actually canceled
741 if ($this->holiday->status != Holiday::STATUS_CANCELED) {
742 throw new RestException(400, 'Holiday is not canceled. Only canceled holidays can be reopened.');
743 }
744 $this->holiday->status = Holiday::STATUS_VALIDATED;
745 $result = $this->holiday->validate(DolibarrApiAccess::$user, $notrigger);
746 if ($result < 0) {
747 throw new RestException(500, 'Error when canceling holiday: '.$this->holiday->errorsToString());
748 }
749
750 return $this->_cleanObjectDatas($this->holiday);
751 }
752
753 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
763 protected function _cleanObjectDatas($object)
764 {
765 // phpcs:enable
766 $object = parent::_cleanObjectDatas($object);
770 unset($object->statut);
771 unset($object->user);
772 unset($object->thirdparty);
773
774 unset($object->cond_reglement);
775 unset($object->shipping_method_id);
776
777 unset($object->barcode_type);
778 unset($object->barcode_type_code);
779 unset($object->barcode_type_label);
780 unset($object->barcode_type_coder);
781
782 unset($object->mode_reglement_id);
783 unset($object->cond_reglement_id);
784
785 unset($object->name);
786 unset($object->lastname);
787 unset($object->firstname);
788 unset($object->civility_id);
789 unset($object->cond_reglement_id);
790 unset($object->contact);
791 unset($object->contact_id);
792
793 unset($object->state);
794 unset($object->state_id);
795 unset($object->state_code);
796 unset($object->country);
797 unset($object->country_id);
798 unset($object->country_code);
799
800 unset($object->logs);
801 unset($object->events);
802 unset($object->holiday);
803 unset($object->canvas);
804 unset($object->lines);
805
806 unset($object->totalpaid);
807 unset($object->totalpaid_multicurrency);
808
809 unset($object->note); // We already use note_public and note_pricate
810
811 return $object;
812 }
813
821 private function _validate($data)
822 {
823 if ($data === null) {
824 $data = array();
825 }
826 $holiday = array();
827 foreach (self::$FIELDS as $field) {
828 if (!isset($data[$field])) {
829 throw new RestException(400, "$field field missing");
830 }
831 $holiday[$field] = $data[$field];
832 }
833 return $holiday;
834 }
835}
$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)
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