dolibarr 23.0.4
holiday.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
3 * Copyright (C) 2012-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012-2016 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
6 * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30
31
35class Holiday extends CommonObject
36{
40 public $element = 'holiday';
41
46 public $TRIGGER_PREFIX = 'HOLIDAY';
47
51 public $table_element = 'holiday';
52
56 public $fk_element = 'fk_holiday';
57
61 public $picto = 'holiday';
62
66 public $fk_user;
67
71 public $date_create = '';
72
76 public $description;
77
81 public $date_debut = '';
82
86 public $date_fin = '';
87
91 public $date_debut_gmt = '';
92
96 public $date_fin_gmt = '';
97
101 public $halfday = '';
102
107 public $statut = 0;
108
112 public $fk_validator;
113
117 public $date_valid = 0;
118
122 public $fk_user_valid;
123
127 public $date_approval;
128
132 public $fk_user_approve;
133
137 public $user_approve_id;
138
142 public $date_refuse = 0;
143
147 public $fk_user_refuse;
148
152 public $date_cancel = 0;
153
157 public $fk_user_cancel;
158
162 public $fk_user_create;
163
167 public $detail_refuse = '';
168
172 public $fk_type;
173
174 public $holiday = array();
175 public $events = array();
176
180 public $logs = array();
181
182
186 const STATUS_DRAFT = 1;
202 const STATUS_REFUSED = 5;
203
204
210 public function __construct($db)
211 {
212 $this->db = $db;
213
214 $this->ismultientitymanaged = 0;
215 }
216
217
225 public function getNextNumRef($objsoc)
226 {
227 global $langs, $conf;
228 $langs->load("order");
229
230 if (!getDolGlobalString('HOLIDAY_ADDON')) {
231 $conf->global->HOLIDAY_ADDON = 'mod_holiday_madonna';
232 }
233
234 if (getDolGlobalString('HOLIDAY_ADDON')) {
235 $mybool = false;
236
237 $file = getDolGlobalString('HOLIDAY_ADDON') . ".php";
238 $classname = getDolGlobalString('HOLIDAY_ADDON');
239
240 // Include file with class
241 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
242 foreach ($dirmodels as $reldir) {
243 $dir = dol_buildpath($reldir."core/modules/holiday/");
244
245 // Load file with numbering class (if found)
246 $mybool = ((bool) @include_once $dir.$file) || $mybool;
247 }
248
249 if (!$mybool) {
250 dol_print_error(null, "Failed to include file ".$file);
251 return '';
252 }
253
254 $obj = new $classname();
255 '@phan-var-force ModelNumRefHolidays $obj';
256 $numref = $obj->getNextValue($objsoc, $this);
257
258 if ($numref != "") {
259 return $numref;
260 } else {
261 $this->error = $obj->error;
262 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
263 return "";
264 }
265 } else {
266 print $langs->trans("Error")." ".$langs->trans("Error_HOLIDAY_ADDON_NotDefined");
267 return "";
268 }
269 }
270
276 public function updateBalance()
277 {
278 $this->db->begin();
279
280 // Update sold of vocations
281 $result = $this->updateSoldeCP();
282
283 // Check nb of users into table llx_holiday_users and update with empty lines
284 //if ($result > 0) $result = $this->verifNbUsers($this->countActiveUsersWithoutCP(), $this->getConfCP('nbUser'));
285
286 if ($result >= 0) {
287 $this->db->commit();
288 return 0; // for cronjob use (0 is OK, any other value is an error code)
289 } else {
290 $this->db->rollback();
291 return -1;
292 }
293 }
294
302 public function create($user, $notrigger = 0)
303 {
304 global $conf;
305 $error = 0;
306
307 $now = dol_now();
308
309 // Check parameters
310 if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) {
311 $this->error = "ErrorBadParameterFkUser";
312 return -1;
313 }
314 if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) {
315 $this->error = "ErrorBadParameterFkValidator";
316 return -1;
317 }
318 if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) {
319 $this->error = "ErrorBadParameterFkType";
320 return -1;
321 }
322
323 // Insert request
324 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday(";
325 $sql .= "ref,";
326 $sql .= "fk_user,";
327 $sql .= "date_create,";
328 $sql .= "description,";
329 $sql .= "date_debut,";
330 $sql .= "date_fin,";
331 $sql .= "halfday,";
332 $sql .= "statut,";
333 $sql .= "fk_validator,";
334 $sql .= "fk_type,";
335 $sql .= "fk_user_create,";
336 $sql .= "entity";
337 $sql .= ") VALUES (";
338 $sql .= "'(PROV)',";
339 $sql .= " ".((int) $this->fk_user).",";
340 $sql .= " '".$this->db->idate($now)."',";
341 $sql .= " '".$this->db->escape($this->description)."',";
342 $sql .= " '".$this->db->idate($this->date_debut)."',";
343 $sql .= " '".$this->db->idate($this->date_fin)."',";
344 $sql .= " ".((int) $this->halfday).",";
345 $sql .= " '1',";
346 $sql .= " ".((int) $this->fk_validator).",";
347 $sql .= " ".((int) $this->fk_type).",";
348 $sql .= " ".((int) $user->id).",";
349 $sql .= " ".((int) $conf->entity);
350 $sql .= ")";
351
352 $this->db->begin();
353
354 dol_syslog(get_class($this)."::create", LOG_DEBUG);
355 $resql = $this->db->query($sql);
356 if (!$resql) {
357 $error++;
358 $this->errors[] = "Error ".$this->db->lasterror();
359 }
360
361 if (!$error) {
362 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday");
363
364 if ($this->id) {
365 // update ref
366 $initialref = '(PROV'.$this->id.')';
367 if (!empty($this->ref)) {
368 $initialref = $this->ref;
369 }
370
371 $sql = 'UPDATE '.MAIN_DB_PREFIX."holiday SET ref='".$this->db->escape($initialref)."' WHERE rowid=".((int) $this->id);
372 if ($this->db->query($sql)) {
373 $this->ref = $initialref;
374
375 if (!$error) {
376 $result = $this->insertExtraFields();
377 if ($result < 0) {
378 $error++;
379 }
380 }
381
382 if (!$error && !$notrigger) {
383 // Call trigger
384 $result = $this->call_trigger('HOLIDAY_CREATE', $user);
385 if ($result < 0) {
386 $error++;
387 }
388 // End call triggers
389 }
390 }
391 }
392 }
393
394 // Commit or rollback
395 if ($error) {
396 foreach ($this->errors as $errmsg) {
397 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
398 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
399 }
400 $this->db->rollback();
401 return -1 * $error;
402 } else {
403 $this->db->commit();
404 return $this->id;
405 }
406 }
407
408
416 public function fetch($id, $ref = '')
417 {
418 $sql = "SELECT";
419 $sql .= " cp.rowid,";
420 $sql .= " cp.ref,";
421 $sql .= " cp.fk_user,";
422 $sql .= " cp.date_create,";
423 $sql .= " cp.description,";
424 $sql .= " cp.date_debut,";
425 $sql .= " cp.date_fin,";
426 $sql .= " cp.halfday,";
427 $sql .= " cp.statut as status,";
428 $sql .= " cp.fk_validator,";
429 $sql .= " cp.date_valid,";
430 $sql .= " cp.fk_user_valid,";
431 $sql .= " cp.date_approval,";
432 $sql .= " cp.fk_user_approve,";
433 $sql .= " cp.date_refuse,";
434 $sql .= " cp.fk_user_refuse,";
435 $sql .= " cp.date_cancel,";
436 $sql .= " cp.fk_user_cancel,";
437 $sql .= " cp.detail_refuse,";
438 $sql .= " cp.note_private,";
439 $sql .= " cp.note_public,";
440 $sql .= " cp.fk_user_create,";
441 $sql .= " cp.fk_type,";
442 $sql .= " cp.entity";
443 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
444 if ($id > 0) {
445 $sql .= " WHERE cp.rowid = ".((int) $id);
446 } else {
447 $sql .= " WHERE cp.ref = '".$this->db->escape($ref)."'";
448 }
449
450 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
451 $resql = $this->db->query($sql);
452 if ($resql) {
453 if ($this->db->num_rows($resql)) {
454 $obj = $this->db->fetch_object($resql);
455
456 $this->id = $obj->rowid;
457 $this->ref = ($obj->ref ? $obj->ref : $obj->rowid);
458 $this->fk_user = $obj->fk_user;
459 $this->date_create = $this->db->jdate($obj->date_create);
460 $this->description = $obj->description;
461 $this->date_debut = $this->db->jdate($obj->date_debut);
462 $this->date_fin = $this->db->jdate($obj->date_fin);
463 $this->date_debut_gmt = $this->db->jdate($obj->date_debut, 1);
464 $this->date_fin_gmt = $this->db->jdate($obj->date_fin, 1);
465 $this->halfday = $obj->halfday;
466 $this->status = $obj->status;
467 $this->statut = $obj->status; // deprecated
468 $this->fk_validator = $obj->fk_validator;
469 $this->date_valid = $this->db->jdate($obj->date_valid);
470 $this->fk_user_valid = $obj->fk_user_valid;
471 $this->user_validation_id = $obj->fk_user_valid;
472 $this->date_approval = $this->db->jdate($obj->date_approval);
473 $this->fk_user_approve = $obj->fk_user_approve;
474 $this->date_refuse = $this->db->jdate($obj->date_refuse);
475 $this->fk_user_refuse = $obj->fk_user_refuse;
476 $this->date_cancel = $this->db->jdate($obj->date_cancel);
477 $this->fk_user_cancel = $obj->fk_user_cancel;
478 $this->detail_refuse = $obj->detail_refuse;
479 $this->note_private = $obj->note_private;
480 $this->note_public = $obj->note_public;
481 $this->fk_user_create = $obj->fk_user_create;
482 $this->fk_type = $obj->fk_type;
483 $this->entity = $obj->entity;
484
485 $this->fetch_optionals();
486
487 $result = 1;
488 } else {
489 $result = 0;
490 }
491 $this->db->free($resql);
492
493 return $result;
494 } else {
495 $this->error = "Error ".$this->db->lasterror();
496 return -1;
497 }
498 }
499
508 public function fetchByUser($user_id, $order = '', $filter = '')
509 {
510 $this->holiday = [];
511 $sql = "SELECT";
512 $sql .= " cp.rowid,";
513 $sql .= " cp.ref,";
514
515 $sql .= " cp.fk_user,";
516 $sql .= " cp.fk_type,";
517 $sql .= " cp.date_create,";
518 $sql .= " cp.description,";
519 $sql .= " cp.date_debut,";
520 $sql .= " cp.date_fin,";
521 $sql .= " cp.halfday,";
522 $sql .= " cp.statut as status,";
523 $sql .= " cp.fk_validator,";
524 $sql .= " cp.date_valid,";
525 $sql .= " cp.fk_user_valid,";
526 $sql .= " cp.date_approval,";
527 $sql .= " cp.fk_user_approve,";
528 $sql .= " cp.date_refuse,";
529 $sql .= " cp.fk_user_refuse,";
530 $sql .= " cp.date_cancel,";
531 $sql .= " cp.fk_user_cancel,";
532 $sql .= " cp.detail_refuse,";
533
534 $sql .= " uu.lastname as user_lastname,";
535 $sql .= " uu.firstname as user_firstname,";
536 $sql .= " uu.login as user_login,";
537 $sql .= " uu.statut as user_status,";
538 $sql .= " uu.photo as user_photo,";
539 $sql .= " uu.fk_country as country_id,";
540
541 $sql .= " ua.lastname as validator_lastname,";
542 $sql .= " ua.firstname as validator_firstname,";
543 $sql .= " ua.login as validator_login,";
544 $sql .= " ua.statut as validator_status,";
545 $sql .= " ua.photo as validator_photo";
546
547 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
548 $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
549 $sql .= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid"; // Hack pour la recherche sur le tableau
550 $sql .= " AND cp.fk_user IN (".$this->db->sanitize($user_id).")";
551
552 // Selection filter
553 if (!empty($filter)) {
554 $sql .= $filter;
555 }
556
557 // Order of display of the result
558 if (!empty($order)) {
559 $sql .= $order;
560 }
561
562 dol_syslog(get_class($this)."::fetchByUser", LOG_DEBUG);
563 $resql = $this->db->query($sql);
564
565 // If no SQL error
566 if ($resql) {
567 $i = 0;
568 $tab_result = $this->holiday;
569 $num = $this->db->num_rows($resql);
570
571 // If no registration
572 if (!$num) {
573 return 2;
574 }
575
576 // List the records and add them to the table
577 while ($i < $num) {
578 $obj = $this->db->fetch_object($resql);
579
580 $tab_result[$i]['rowid'] = $obj->rowid;
581 $tab_result[$i]['id'] = $obj->rowid;
582 $tab_result[$i]['ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
583
584 $tab_result[$i]['fk_user'] = $obj->fk_user;
585 $tab_result[$i]['fk_type'] = $obj->fk_type;
586 $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
587 $tab_result[$i]['description'] = $obj->description;
588 $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
589 $tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin);
590 $tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
591 $tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
592 $tab_result[$i]['halfday'] = $obj->halfday;
593 $tab_result[$i]['statut'] = $obj->status;
594 $tab_result[$i]['status'] = $obj->status;
595 $tab_result[$i]['fk_validator'] = $obj->fk_validator;
596 $tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid);
597 $tab_result[$i]['fk_user_valid'] = $obj->fk_user_valid;
598 $tab_result[$i]['date_approval'] = $this->db->jdate($obj->date_approval);
599 $tab_result[$i]['fk_user_approve'] = $obj->fk_user_approve;
600 $tab_result[$i]['date_refuse'] = $this->db->jdate($obj->date_refuse);
601 $tab_result[$i]['fk_user_refuse'] = $obj->fk_user_refuse;
602 $tab_result[$i]['date_cancel'] = $this->db->jdate($obj->date_cancel);
603 $tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel;
604 $tab_result[$i]['detail_refuse'] = $obj->detail_refuse;
605
606 $tab_result[$i]['user_firstname'] = $obj->user_firstname;
607 $tab_result[$i]['user_lastname'] = $obj->user_lastname;
608 $tab_result[$i]['user_login'] = $obj->user_login;
609 $tab_result[$i]['user_statut'] = $obj->user_status;
610 $tab_result[$i]['user_status'] = $obj->user_status;
611 $tab_result[$i]['user_photo'] = $obj->user_photo;
612
613 $tab_result[$i]['validator_firstname'] = $obj->validator_firstname;
614 $tab_result[$i]['validator_lastname'] = $obj->validator_lastname;
615 $tab_result[$i]['validator_login'] = $obj->validator_login;
616 $tab_result[$i]['validator_statut'] = $obj->validator_status;
617 $tab_result[$i]['validator_status'] = $obj->validator_status;
618 $tab_result[$i]['validator_photo'] = $obj->validator_photo;
619
620 $tab_result[$i]['country_id'] = (int) $obj->country_id; // id of country of user
621
622 $i++;
623 }
624
625 // Returns 1 with the filled array
626 $this->holiday = $tab_result;
627 return 1;
628 } else {
629 // SQL Error
630 $this->error = "Error ".$this->db->lasterror();
631 return -1;
632 }
633 }
634
642 public function fetchAll($order, $filter)
643 {
644 $sql = "SELECT";
645 $sql .= " cp.rowid,";
646 $sql .= " cp.ref,";
647 $sql .= " cp.fk_user,";
648 $sql .= " cp.fk_type,";
649 $sql .= " cp.date_create,";
650 $sql .= " cp.tms as date_modification,";
651 $sql .= " cp.description,";
652 $sql .= " cp.date_debut,";
653 $sql .= " cp.date_fin,";
654 $sql .= " cp.halfday,";
655 $sql .= " cp.statut as status,";
656 $sql .= " cp.fk_validator,";
657 $sql .= " cp.date_valid,";
658 $sql .= " cp.fk_user_valid,";
659 $sql .= " cp.date_approval,";
660 $sql .= " cp.fk_user_approve,";
661 $sql .= " cp.date_refuse,";
662 $sql .= " cp.fk_user_refuse,";
663 $sql .= " cp.date_cancel,";
664 $sql .= " cp.fk_user_cancel,";
665 $sql .= " cp.detail_refuse,";
666
667 $sql .= " uu.lastname as user_lastname,";
668 $sql .= " uu.firstname as user_firstname,";
669 $sql .= " uu.login as user_login,";
670 $sql .= " uu.statut as user_status,";
671 $sql .= " uu.photo as user_photo,";
672
673 $sql .= " ua.lastname as validator_lastname,";
674 $sql .= " ua.firstname as validator_firstname,";
675 $sql .= " ua.login as validator_login,";
676 $sql .= " ua.statut as validator_status,";
677 $sql .= " ua.photo as validator_photo";
678
679 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
680 $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
681 $sql .= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
682
683 // Selection filtering
684 if (!empty($filter)) {
685 $sql .= $filter;
686 }
687
688 // order of display
689 if (!empty($order)) {
690 $sql .= $order;
691 }
692
693 dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
694 $resql = $this->db->query($sql);
695
696 // If no SQL error
697 if ($resql) {
698 $i = 0;
699 $tab_result = $this->holiday;
700 $num = $this->db->num_rows($resql);
701
702 // If no registration
703 if (!$num) {
704 return 2;
705 }
706
707 // List the records and add them to the table
708 while ($i < $num) {
709 $obj = $this->db->fetch_object($resql);
710
711 $tab_result[$i]['rowid'] = $obj->rowid;
712 $tab_result[$i]['id'] = $obj->rowid;
713 $tab_result[$i]['ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
714
715 $tab_result[$i]['fk_user'] = $obj->fk_user;
716 $tab_result[$i]['fk_type'] = $obj->fk_type;
717 $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
718 $tab_result[$i]['date_modification'] = $this->db->jdate($obj->date_modification);
719 $tab_result[$i]['description'] = $obj->description;
720 $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
721 $tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin);
722 $tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
723 $tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
724 $tab_result[$i]['halfday'] = $obj->halfday;
725 $tab_result[$i]['statut'] = $obj->status;
726 $tab_result[$i]['status'] = $obj->status;
727 $tab_result[$i]['fk_validator'] = $obj->fk_validator;
728 $tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid);
729 $tab_result[$i]['fk_user_valid'] = $obj->fk_user_valid;
730 $tab_result[$i]['date_approval'] = $this->db->jdate($obj->date_approval);
731 $tab_result[$i]['fk_user_approve'] = $obj->fk_user_approve;
732 $tab_result[$i]['date_refuse'] = $obj->date_refuse;
733 $tab_result[$i]['fk_user_refuse'] = $obj->fk_user_refuse;
734 $tab_result[$i]['date_cancel'] = $obj->date_cancel;
735 $tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel;
736 $tab_result[$i]['detail_refuse'] = $obj->detail_refuse;
737
738 $tab_result[$i]['user_firstname'] = $obj->user_firstname;
739 $tab_result[$i]['user_lastname'] = $obj->user_lastname;
740 $tab_result[$i]['user_login'] = $obj->user_login;
741 $tab_result[$i]['user_statut'] = $obj->user_status;
742 $tab_result[$i]['user_status'] = $obj->user_status;
743 $tab_result[$i]['user_photo'] = $obj->user_photo;
744
745 $tab_result[$i]['validator_firstname'] = $obj->validator_firstname;
746 $tab_result[$i]['validator_lastname'] = $obj->validator_lastname;
747 $tab_result[$i]['validator_login'] = $obj->validator_login;
748 $tab_result[$i]['validator_statut'] = $obj->validator_status;
749 $tab_result[$i]['validator_status'] = $obj->validator_status;
750 $tab_result[$i]['validator_photo'] = $obj->validator_photo;
751
752 $i++;
753 }
754 // Returns 1 and adds the array to the variable
755 $this->holiday = $tab_result;
756 return 1;
757 } else {
758 // SQL Error
759 $this->error = "Error ".$this->db->lasterror();
760 return -1;
761 }
762 }
763
764
772 public function validate($user = null, $notrigger = 0)
773 {
774 global $conf, $langs;
775 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
776 $error = 0;
777
778
779 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
780
781 if ($checkBalance > 0) {
782 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
783 // Use the GMT variants: num_public_holiday(), called by num_open_day(), refuses a range whose
784 // length is not a whole number of days, and a range spanning a DST transition is 23h or 25h
785 // long in the server timezone. It then returns a string and the subtraction fatals.
786 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
787 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
788 $daysAsked = num_open_day($datedebutforcount, $datefinforcount, 0, 1, (int) $this->halfday);
789
790 if (($balance - $daysAsked) < 0) {
791 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
792 return -1;
793 }
794 }
795
796 // Define new ref
797 if (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->id) {
798 $num = $this->getNextNumRef(null);
799 } else {
800 $num = (string) $this->ref;
801 }
802 $this->newref = dol_sanitizeFileName($num);
803
804 // Update status
805 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
806 $sql .= " fk_user_valid = ".((int) $user->id).",";
807 $sql .= " date_valid = '".$this->db->idate(dol_now())."',";
808 if (!empty($this->status) && is_numeric($this->status)) {
809 $sql .= " statut = ".((int) $this->status).",";
810 } else {
811 $this->error = 'Property status must be a numeric value';
812 $error++;
813 }
814 $sql .= " ref = '".$this->db->escape($num)."'";
815 $sql .= " WHERE rowid = ".((int) $this->id);
816
817 $this->db->begin();
818
819 dol_syslog(get_class($this)."::validate", LOG_DEBUG);
820 $resql = $this->db->query($sql);
821 if (!$resql) {
822 $error++;
823 $this->errors[] = "Error ".$this->db->lasterror();
824 }
825
826 if (!$error) {
827 if (!$notrigger) {
828 // Call trigger
829 $result = $this->call_trigger('HOLIDAY_VALIDATE', $user);
830 if ($result < 0) {
831 $error++;
832 }
833 // End call triggers
834 }
835 }
836
837 if (!$error) {
838 $this->oldref = $this->ref;
839
840 // Rename directory if dir was a temporary ref
841 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
842 // Now we rename also files into index
843 $sql = 'UPDATE ' . MAIN_DB_PREFIX . "ecm_files set filename = CONCAT('" . $this->db->escape($this->newref) . "', SUBSTR(filename, " . (strlen($this->ref) + 1) . ")), filepath = 'holiday/" . $this->db->escape($this->newref) . "'";
844 $sql .= " WHERE filename LIKE '" . $this->db->escape($this->ref) . "%' AND filepath = 'holiday/" . $this->db->escape($this->ref) . "' and entity = " . ((int) $conf->entity);
845 $resql = $this->db->query($sql);
846 if (!$resql) {
847 $error++;
848 $this->error = $this->db->lasterror();
849 }
850 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'holiday/".$this->db->escape($this->newref)."'";
851 $sql .= " WHERE filepath = 'holiday/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
852 $resql = $this->db->query($sql);
853 if (!$resql) {
854 $error++;
855 $this->error = $this->db->lasterror();
856 }
857
858 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
859 $oldref = dol_sanitizeFileName($this->ref);
860 $newref = dol_sanitizeFileName($num);
861 $dirsource = $conf->holiday->multidir_output[$this->entity] . '/' . $oldref;
862 $dirdest = $conf->holiday->multidir_output[$this->entity] . '/' . $newref;
863 if (!$error && file_exists($dirsource)) {
864 dol_syslog(get_class($this) . "::validate rename dir " . $dirsource . " into " . $dirdest);
865 if (@rename($dirsource, $dirdest)) {
866 dol_syslog("Rename ok");
867 // Rename docs starting with $oldref with $newref
868 $listoffiles = dol_dir_list($dirdest, 'files', 1, '^' . preg_quote($oldref, '/'));
869 foreach ($listoffiles as $fileentry) {
870 $dirsource = $fileentry['name'];
871 $dirdest = preg_replace('/^' . preg_quote($oldref, '/') . '/', $newref, $dirsource);
872 $dirsource = $fileentry['path'] . '/' . $dirsource;
873 $dirdest = $fileentry['path'] . '/' . $dirdest;
874 @rename($dirsource, $dirdest);
875 }
876 }
877 }
878 }
879 }
880
881
882 // Commit or rollback
883 if ($error) {
884 foreach ($this->errors as $errmsg) {
885 dol_syslog(get_class($this)."::validate ".$errmsg, LOG_ERR);
886 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
887 }
888 $this->db->rollback();
889 return -1 * $error;
890 } else {
891 $this->db->commit();
892 return 1;
893 }
894 }
895
896
904 public function approve($user = null, $notrigger = 0)
905 {
906 $error = 0;
907
908 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
909
910 if ($checkBalance > 0) {
911 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
912 // Use the GMT variants: num_public_holiday(), called by num_open_day(), refuses a range whose
913 // length is not a whole number of days, and a range spanning a DST transition is 23h or 25h
914 // long in the server timezone. It then returns a string and the subtraction fatals.
915 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
916 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
917 $daysAsked = num_open_day($datedebutforcount, $datefinforcount, 0, 1, (int) $this->halfday);
918
919 if (($balance - $daysAsked) < 0) {
920 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
921 return -1;
922 }
923 }
924
925 // Update request
926 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
927 $sql .= " description= '".$this->db->escape($this->description)."',";
928 if (!empty($this->date_debut)) {
929 $sql .= " date_debut = '".$this->db->idate($this->date_debut)."',";
930 } else {
931 $error++;
932 }
933 if (!empty($this->date_fin)) {
934 $sql .= " date_fin = '".$this->db->idate($this->date_fin)."',";
935 } else {
936 $error++;
937 }
938 $sql .= " halfday = ".((int) $this->halfday).",";
939 if (!empty($this->status) && is_numeric($this->status)) {
940 $sql .= " statut = ".((int) $this->status).",";
941 } else {
942 $error++;
943 }
944 if (!empty($this->fk_validator)) {
945 $sql .= " fk_validator = ".((int) $this->fk_validator).",";
946 } else {
947 $error++;
948 }
949 if (!empty($this->date_valid)) {
950 $sql .= " date_valid = '".$this->db->idate($this->date_valid)."',";
951 } else {
952 $sql .= " date_valid = NULL,";
953 }
954 if (!empty($this->fk_user_valid)) {
955 $sql .= " fk_user_valid = ".((int) $this->fk_user_valid).",";
956 } else {
957 $sql .= " fk_user_valid = NULL,";
958 }
959 if (!empty($this->date_approval)) {
960 $sql .= " date_approval = '".$this->db->idate($this->date_approval)."',";
961 } else {
962 $sql .= " date_approval = NULL,";
963 }
964 if (!empty($this->fk_user_approve)) {
965 $sql .= " fk_user_approve = ".((int) $this->fk_user_approve).",";
966 } else {
967 $sql .= " fk_user_approve = NULL,";
968 }
969 if (!empty($this->date_refuse)) {
970 $sql .= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
971 } else {
972 $sql .= " date_refuse = NULL,";
973 }
974 if (!empty($this->fk_user_refuse)) {
975 $sql .= " fk_user_refuse = ".((int) $this->fk_user_refuse).",";
976 } else {
977 $sql .= " fk_user_refuse = NULL,";
978 }
979 if (!empty($this->date_cancel)) {
980 $sql .= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
981 } else {
982 $sql .= " date_cancel = NULL,";
983 }
984 if (!empty($this->fk_user_cancel)) {
985 $sql .= " fk_user_cancel = ".((int) $this->fk_user_cancel).",";
986 } else {
987 $sql .= " fk_user_cancel = NULL,";
988 }
989 if (!empty($this->detail_refuse)) {
990 $sql .= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
991 } else {
992 $sql .= " detail_refuse = NULL";
993 }
994 $sql .= " WHERE rowid = ".((int) $this->id);
995
996 $this->db->begin();
997
998 dol_syslog(get_class($this)."::approve", LOG_DEBUG);
999 $resql = $this->db->query($sql);
1000 if (!$resql) {
1001 $error++;
1002 $this->errors[] = "Error ".$this->db->lasterror();
1003 }
1004
1005 if (!$error) {
1006 if (!$notrigger) {
1007 // Call trigger
1008 $result = $this->call_trigger('HOLIDAY_APPROVE', $user);
1009 if ($result < 0) {
1010 $error++;
1011 }
1012 // End call triggers
1013 }
1014 }
1015
1016 // Commit or rollback
1017 if ($error) {
1018 foreach ($this->errors as $errmsg) {
1019 dol_syslog(get_class($this)."::approve ".$errmsg, LOG_ERR);
1020 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1021 }
1022 $this->db->rollback();
1023 return -1 * $error;
1024 } else {
1025 $this->db->commit();
1026 return 1;
1027 }
1028 }
1029
1037 public function update($user = null, $notrigger = 0)
1038 {
1039 global $conf, $langs;
1040 $error = 0;
1041
1042 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
1043 if ($this->status == self::STATUS_REFUSED || $this->status == self::STATUS_APPROVED) {
1044 $checkBalance = 0; // No balance check to refuse a request, nor on an approved request (its days are already debited)
1045 }
1046
1047 if ($checkBalance > 0 && $this->statut != self::STATUS_DRAFT && $this->statut != self::STATUS_CANCELED) {
1048 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
1049 // Use the GMT variants: num_public_holiday(), called by num_open_day(), refuses a range whose
1050 // length is not a whole number of days, and a range spanning a DST transition is 23h or 25h
1051 // long in the server timezone. It then returns a string and the subtraction fatals.
1052 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
1053 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
1054 $daysAsked = num_open_day($datedebutforcount, $datefinforcount, 0, 1, (int) $this->halfday);
1055
1056 if (($balance - $daysAsked) < 0) {
1057 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
1058 return -1;
1059 }
1060 }
1061
1062 // Update request
1063 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
1064
1065 $sql .= " description= '".$this->db->escape($this->description)."',";
1066
1067 if (!empty($this->date_debut)) {
1068 $sql .= " date_debut = '".$this->db->idate($this->date_debut)."',";
1069 } else {
1070 $error++;
1071 }
1072 if (!empty($this->date_fin)) {
1073 $sql .= " date_fin = '".$this->db->idate($this->date_fin)."',";
1074 } else {
1075 $error++;
1076 }
1077 $sql .= " halfday = ".((int) $this->halfday).",";
1078 if (!empty($this->status) && is_numeric($this->status)) {
1079 $sql .= " statut = ".((int) $this->status).",";
1080 } else {
1081 $error++;
1082 }
1083 if (!empty($this->fk_validator)) {
1084 $sql .= " fk_validator = ".((int) $this->fk_validator).",";
1085 } else {
1086 $error++;
1087 }
1088 if (!empty($this->date_valid)) {
1089 $sql .= " date_valid = '".$this->db->idate($this->date_valid)."',";
1090 } else {
1091 $sql .= " date_valid = NULL,";
1092 }
1093 if (!empty($this->fk_user_valid)) {
1094 $sql .= " fk_user_valid = ".((int) $this->fk_user_valid).",";
1095 } else {
1096 $sql .= " fk_user_valid = NULL,";
1097 }
1098 if (!empty($this->date_approval)) {
1099 $sql .= " date_approval = '".$this->db->idate($this->date_approval)."',";
1100 } else {
1101 $sql .= " date_approval = NULL,";
1102 }
1103 if (!empty($this->fk_user_approve)) {
1104 $sql .= " fk_user_approve = ".((int) $this->fk_user_approve).",";
1105 } else {
1106 $sql .= " fk_user_approve = NULL,";
1107 }
1108 if (!empty($this->date_refuse)) {
1109 $sql .= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
1110 } else {
1111 $sql .= " date_refuse = NULL,";
1112 }
1113 if (!empty($this->fk_user_refuse)) {
1114 $sql .= " fk_user_refuse = ".((int) $this->fk_user_refuse).",";
1115 } else {
1116 $sql .= " fk_user_refuse = NULL,";
1117 }
1118 if (!empty($this->date_cancel)) {
1119 $sql .= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
1120 } else {
1121 $sql .= " date_cancel = NULL,";
1122 }
1123 if (!empty($this->fk_user_cancel)) {
1124 $sql .= " fk_user_cancel = ".((int) $this->fk_user_cancel).",";
1125 } else {
1126 $sql .= " fk_user_cancel = NULL,";
1127 }
1128 if (!empty($this->detail_refuse)) {
1129 $sql .= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
1130 } else {
1131 $sql .= " detail_refuse = NULL";
1132 }
1133
1134 $sql .= " WHERE rowid = ".((int) $this->id);
1135
1136 $this->db->begin();
1137
1138 dol_syslog(get_class($this)."::update", LOG_DEBUG);
1139 $resql = $this->db->query($sql);
1140 if (!$resql) {
1141 $error++;
1142 $this->errors[] = "Error ".$this->db->lasterror();
1143 }
1144
1145 if (!$error) {
1146 $result = $this->insertExtraFields();
1147 if ($result < 0) {
1148 $error++;
1149 }
1150 }
1151
1152 if (!$error) {
1153 if (!$notrigger && $user !== null) {
1154 // Call trigger
1155 $result = $this->call_trigger('HOLIDAY_MODIFY', $user);
1156 if ($result < 0) {
1157 $error++;
1158 }
1159 // End call triggers
1160 }
1161 }
1162
1163 // Commit or rollback
1164 if ($error) {
1165 foreach ($this->errors as $errmsg) {
1166 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1167 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1168 }
1169 $this->db->rollback();
1170 return -1 * $error;
1171 } else {
1172 $this->db->commit();
1173 return 1;
1174 }
1175 }
1176
1177
1185 public function delete($user, $notrigger = 0)
1186 {
1187 global $conf, $langs;
1188 $error = 0;
1189
1190 $sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday";
1191 $sql .= " WHERE rowid=".((int) $this->id);
1192
1193 $this->db->begin();
1194
1195 // Delete extrafields before the leave request
1196 $result = $this->deleteExtraFields();
1197 if ($result < 0) {
1198 $error++;
1199 }
1200
1201 if (!$error) {
1202 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1203 $resql = $this->db->query($sql);
1204 if (!$resql) {
1205 $error++;
1206 $this->errors[] = "Error ".$this->db->lasterror();
1207 }
1208 }
1209
1210 if (!$error) {
1211 if (!$notrigger) {
1212 // Call trigger
1213 $result = $this->call_trigger('HOLIDAY_DELETE', $user);
1214 if ($result < 0) {
1215 $error++;
1216 }
1217 // End call triggers
1218 }
1219 }
1220
1221 // Commit or rollback
1222 if ($error) {
1223 foreach ($this->errors as $errmsg) {
1224 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
1225 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1226 }
1227 $this->db->rollback();
1228 return -1 * $error;
1229 } else {
1230 $this->db->commit();
1231 return 1;
1232 }
1233 }
1234
1248 public function verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday = 0)
1249 {
1250 $this->fetchByUser($fk_user, '', '');
1251
1252 foreach ($this->holiday as $infos_CP) {
1253 if ($infos_CP['statut'] == Holiday::STATUS_CANCELED) {
1254 continue; // ignore not validated holidays
1255 }
1256 if ($infos_CP['statut'] == Holiday::STATUS_REFUSED) {
1257 continue; // ignore refused holidays
1258 }
1259 //var_dump("--");
1260 //var_dump("old: ".dol_print_date($infos_CP['date_debut'],'dayhour').' '.dol_print_date($infos_CP['date_fin'],'dayhour').' '.$infos_CP['halfday']);
1261 //var_dump("new: ".dol_print_date($dateStart,'dayhour').' '.dol_print_date($dateEnd,'dayhour').' '.$halfday);
1262
1263 if ($halfday == 0) {
1264 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1265 return false;
1266 }
1267 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1268 return false;
1269 }
1270 } elseif ($halfday == -1) {
1271 // new start afternoon, new end afternoon
1272 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1273 if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1274 return false;
1275 }
1276 }
1277 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1278 if ($dateStart < $dateEnd) {
1279 return false;
1280 }
1281 if ($dateEnd < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1282 return false;
1283 }
1284 }
1285 } elseif ($halfday == 1) {
1286 // new start morning, new end morning
1287 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1288 if ($dateStart < $dateEnd) {
1289 return false;
1290 }
1291 if ($dateStart > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1292 return false;
1293 }
1294 }
1295 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1296 if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1297 return false;
1298 }
1299 }
1300 } elseif ($halfday == 2) {
1301 // new start afternoon, new end morning
1302 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1303 if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1304 return false;
1305 }
1306 }
1307 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1308 if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1309 return false;
1310 }
1311 }
1312 } else {
1313 dol_print_error(null, 'Bad value of parameter halfday when calling function verifDateHolidayCP');
1314 }
1315 }
1316
1317 return true;
1318 }
1319
1320
1330 public function verifDateHolidayForTimestamp($fk_user, $timestamp, $status = '-1')
1331 {
1332 $isavailablemorning = true;
1333 $isavailableafternoon = true;
1334
1335 // Check into leave requests
1336 $sql = "SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut as status";
1337 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
1338 $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
1339 $sql .= " AND cp.fk_user = ".(int) $fk_user;
1340 $sql .= " AND cp.date_debut <= '".$this->db->idate($timestamp)."' AND cp.date_fin >= '".$this->db->idate($timestamp)."'";
1341 if ($status != '-1') {
1342 $sql .= " AND cp.statut IN (".$this->db->sanitize($status).")";
1343 }
1344
1345 $resql = $this->db->query($sql);
1346 if ($resql) {
1347 $num_rows = $this->db->num_rows($resql); // Note, we can have 2 records if on is morning and the other one is afternoon
1348 if ($num_rows > 0) {
1349 $arrayofrecord = array();
1350 $i = 0;
1351 while ($i < $num_rows) {
1352 $obj = $this->db->fetch_object($resql);
1353
1354 // Note: $obj->halfday is 0:Full days, 2:Start afternoon end morning, -1:Start afternoon, 1:End morning
1355 $arrayofrecord[$obj->rowid] = array('date_start' => $this->db->jdate($obj->date_start), 'date_end' => $this->db->jdate($obj->date_end), 'halfday' => $obj->halfday, 'status' => $obj->status);
1356 $i++;
1357 }
1358
1359 // We found a record, user is on holiday by default, so is not available is true.
1360 $isavailablemorning = true;
1361 foreach ($arrayofrecord as $record) {
1362 if ($timestamp == $record['date_start'] && $record['halfday'] == 2) {
1363 continue;
1364 }
1365 if ($timestamp == $record['date_start'] && $record['halfday'] == -1) {
1366 continue;
1367 }
1368 $isavailablemorning = false;
1369 break;
1370 }
1371 $isavailableafternoon = true;
1372 foreach ($arrayofrecord as $record) {
1373 if ($timestamp == $record['date_end'] && $record['halfday'] == 2) {
1374 continue;
1375 }
1376 if ($timestamp == $record['date_end'] && $record['halfday'] == 1) {
1377 continue;
1378 }
1379 $isavailableafternoon = false;
1380 break;
1381 }
1382 }
1383 } else {
1384 dol_print_error($this->db);
1385 }
1386
1387 $result = array('morning' => (int) $isavailablemorning, 'afternoon' => (int) $isavailableafternoon);
1388 if (!$isavailablemorning) {
1389 $result['morning_reason'] = 'leave_request';
1390 }
1391 if (!$isavailableafternoon) {
1392 $result['afternoon_reason'] = 'leave_request';
1393 }
1394 return $result;
1395 }
1396
1403 public function getTooltipContentArray($params)
1404 {
1405 global $langs;
1406
1407 $langs->load('holiday');
1408 $nofetch = !empty($params['nofetch']);
1409
1410 $datas = array();
1411 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Holiday").'</u>';
1412 if (isset($this->status)) {
1413 $datas['picto'] .= ' '.$this->getLibStatut(5);
1414 }
1415 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1416 // show type for this record only in ajax to not overload lists
1417 if (!$nofetch && !empty($this->fk_type)) {
1418 $typeleaves = $this->getTypes(1, -1);
1419 if (empty($typeleaves[$this->fk_type])) {
1420 $labeltoshow = $langs->trans("TypeWasDisabledOrRemoved", $this->fk_type);
1421 } else {
1422 $labeltoshow = (($typeleaves[$this->fk_type]['code'] && $langs->trans($typeleaves[$this->fk_type]['code']) != $typeleaves[$this->fk_type]['code']) ? $langs->trans($typeleaves[$this->fk_type]['code']) : $typeleaves[$this->fk_type]['label']);
1423 }
1424 $datas['type'] = '<br><b>'.$langs->trans("Type") . ':</b> ' . $labeltoshow;
1425 }
1426 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1427 $listhalfday = array(
1428 'morning' => $langs->trans("Morning"),
1429 "afternoon" => $langs->trans("Afternoon")
1430 );
1431 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ? 'afternoon' : 'morning';
1432 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ? 'morning' : 'afternoon';
1433 $datas['date_start'] = '<br><b>'.$langs->trans('DateDebCP') . '</b>: '. dol_print_date($this->date_debut, 'day') . '&nbsp;&nbsp;<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
1434 $datas['date_end'] = '<br><b>'.$langs->trans('DateFinCP') . '</b>: '. dol_print_date($this->date_fin, 'day') . '&nbsp;&nbsp;<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
1435 }
1436
1437
1438 return $datas;
1439 }
1440
1450 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss = '')
1451 {
1452 global $conf, $langs, $hookmanager;
1453
1454 if (!empty($conf->dol_no_mouse_hover)) {
1455 $notooltip = 1; // Force disable tooltips
1456 }
1457
1458 $result = '';
1459 $params = [
1460 'id' => $this->id,
1461 'objecttype' => $this->element,
1462 'nofetch' => 1,
1463 ];
1464 $classfortooltip = 'classfortooltip';
1465 $dataparams = '';
1466 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1467 $classfortooltip = 'classforajaxtooltip';
1468 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1469 $label = '';
1470 } else {
1471 $label = implode($this->getTooltipContentArray($params));
1472 }
1473
1474 $url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id;
1475
1476 //if ($option != 'nolink')
1477 //{
1478 // Add param to save lastsearch_values or not
1479 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1480 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1481 $add_save_lastsearch_values = 1;
1482 }
1483 if ($add_save_lastsearch_values) {
1484 $url .= '&save_lastsearch_values=1';
1485 }
1486 //}
1487
1488 $linkclose = '';
1489 if (empty($notooltip)) {
1490 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1491 $label = $langs->trans("ShowMyObject");
1492 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1493 }
1494 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1495 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1496 } else {
1497 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1498 }
1499
1500 $linkstart = '<a href="'.$url.'"';
1501 $linkstart .= $linkclose.'>';
1502 $linkend = '</a>';
1503
1504 $result .= $linkstart;
1505
1506 if ($withpicto) {
1507 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1508 }
1509 if ($withpicto != 2) {
1510 $result .= $this->ref;
1511 }
1512 $result .= $linkend;
1513
1514 global $action;
1515 $hookmanager->initHooks(array($this->element . 'dao'));
1516 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1517 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1518 if ($reshook > 0) {
1519 $result = $hookmanager->resPrint;
1520 } else {
1521 $result .= $hookmanager->resPrint;
1522 }
1523 return $result;
1524 }
1525
1526
1533 public function getLibStatut($mode = 0)
1534 {
1535 return $this->LibStatut($this->status, $mode, $this->date_debut);
1536 }
1537
1538 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1547 public function LibStatut($status, $mode = 0, $startdate = '')
1548 {
1549 // phpcs:enable
1550 global $langs;
1551
1552 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1553 global $langs;
1554 //$langs->load("mymodule");
1555 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('DraftCP');
1556 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ToReviewCP');
1557 $this->labelStatus[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('ApprovedCP');
1558 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('CancelCP');
1559 $this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('RefuseCP');
1560 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('DraftCP');
1561 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ToReviewCP');
1562 $this->labelStatusShort[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('ApprovedCP');
1563 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('CancelCP');
1564 $this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('RefuseCP');
1565 }
1566
1567 $params = array();
1568 $statusType = 'status6';
1569 if (!empty($startdate) && $startdate >= dol_now()) { // If not yet passed, we use a green "in live" color
1570 $statusType = 'status4';
1571 $params = array('tooltip' => $this->labelStatus[$status].' - '.$langs->trans("Forthcoming"));
1572 }
1573 if ($status == self::STATUS_DRAFT) {
1574 $statusType = 'status0';
1575 }
1576 if ($status == self::STATUS_VALIDATED) {
1577 $statusType = 'status1';
1578 }
1579 if ($status == self::STATUS_CANCELED) {
1580 $statusType = 'status9';
1581 }
1582 if ($status == self::STATUS_REFUSED) {
1583 $statusType = 'status9';
1584 }
1585
1586 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode, '', $params);
1587 }
1588
1589
1598 public function selectStatutCP($selected = 0, $htmlname = 'select_statut', $morecss = 'minwidth125')
1599 {
1600 global $langs;
1601
1602 // List of status label
1603 $name = array('DraftCP', 'ToReviewCP', 'ApprovedCP', 'CancelCP', 'RefuseCP');
1604 $nb = count($name) + 1;
1605
1606 // Select HTML
1607 $out = '<select name="'.$htmlname.'" id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">'."\n";
1608 $out .= '<option value="-1">&nbsp;</option>'."\n";
1609
1610 // Loop on status
1611 for ($i = 1; $i < $nb; $i++) {
1612 if ($i == $selected) {
1613 $out .= '<option value="'.$i.'" selected>'.$langs->trans($name[$i - 1]).'</option>'."\n";
1614 } else {
1615 $out .= '<option value="'.$i.'">'.$langs->trans($name[$i - 1]).'</option>'."\n";
1616 }
1617 }
1618
1619 $out .= "</select>\n";
1620
1621 $showempty = 0;
1622 $out .= ajax_combobox($htmlname, array(), 0, 0, 'resolve', ($showempty < 0 ? (string) $showempty : '-1'), $morecss);
1623
1624 return $out;
1625 }
1626
1634 public function updateConfCP($name, $value)
1635 {
1636 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1637 $sql .= " value = '".$this->db->escape($value)."'";
1638 $sql .= " WHERE name = '".$this->db->escape($name)."'";
1639
1640 dol_syslog(get_class($this).'::updateConfCP name='.$name, LOG_DEBUG);
1641 $result = $this->db->query($sql);
1642 if ($result) {
1643 return true;
1644 }
1645
1646 return false;
1647 }
1648
1657 public function getConfCP($name, $createifnotfound = '')
1658 {
1659 $sql = "SELECT value";
1660 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_config";
1661 $sql .= " WHERE name = '".$this->db->escape($name)."'";
1662
1663 dol_syslog(get_class($this).'::getConfCP name='.$name.' createifnotfound='.$createifnotfound, LOG_DEBUG);
1664 $result = $this->db->query($sql);
1665
1666 if ($result) {
1667 $obj = $this->db->fetch_object($result);
1668 // Return value
1669 if (empty($obj)) {
1670 if ($createifnotfound) {
1671 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_config(name, value)";
1672 $sql .= " VALUES('".$this->db->escape($name)."', '".$this->db->escape($createifnotfound)."')";
1673 $result = $this->db->query($sql);
1674 if ($result) {
1675 return $createifnotfound;
1676 } else {
1677 $this->error = $this->db->lasterror();
1678 return -2;
1679 }
1680 } else {
1681 return '';
1682 }
1683 } else {
1684 return $obj->value;
1685 }
1686 } else {
1687 // Erreur SQL
1688 $this->error = $this->db->lasterror();
1689 return -1;
1690 }
1691 }
1692
1701 public function updateSoldeCP($userID = 0, $nbHoliday = 0, $fk_type = 0)
1702 {
1703 global $user, $langs;
1704
1705 $error = 0;
1706
1707 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1708 $langs->load("holiday");
1709
1710 $decrease = getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH');
1711
1712 // Si mise à jour pour tout le monde en début de mois
1713 $now = dol_now();
1714
1715 // Get month of last update
1716 $stringInDBForLastUpdate = $this->getConfCP('lastUpdate', dol_print_date($now, '%Y%m%d%H%M%S')); // Example '20200101120000'
1717 // The lastUpdate config row is created empty (value NULL) at install, so getConfCP() returns an empty value
1718 // the first time. Treat an empty value as "start from now" instead of a very old date, otherwise the catch-up
1719 // loop below would credit every user with years of monthly accrual at once. Store it, because the loop is the
1720 // only other place that writes it: an empty value would stay empty and no month would ever be credited.
1721 if (empty($stringInDBForLastUpdate)) {
1722 $stringInDBForLastUpdate = dol_print_date($now, '%Y%m%d%H%M%S');
1723
1724 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1725 $sql .= " value = '".$this->db->escape($stringInDBForLastUpdate)."'";
1726 $sql .= " WHERE name = 'lastUpdate'";
1727 $result = $this->db->query($sql);
1728 if (!$result) {
1729 $this->error = $this->db->lasterror();
1730 return -1;
1731 }
1732 }
1733 // Protection when $lastUpdate has a not valid value
1734 if ($stringInDBForLastUpdate < '20000101000000') {
1735 $stringInDBForLastUpdate = '20000101000000';
1736 }
1737 $lastUpdate = dol_stringtotime($stringInDBForLastUpdate);
1738 //print 'lastUpdate:'.$lastUpdate;exit;
1739
1740 $yearMonthLastUpdate = dol_print_date($lastUpdate, '%Y%m');
1741 $yearMonthNow = dol_print_date($now, '%Y%m');
1742 //print 'yearMonthLastUpdate='.$yearMonthLastUpdate.' yearMonthNow='.$yearMonthNow;
1743
1744 // If month date is not same than the one of last update (the one we saved in database), then we update the timestamp and balance of each open user,
1745 // catching up to the current month if a gap is detected
1746 while ($yearMonthLastUpdate < $yearMonthNow) {
1747 $this->db->begin();
1748
1749 $year = dol_print_date($lastUpdate, '%Y');
1750 $month = dol_print_date($lastUpdate, '%m');
1751
1752 $users = $this->fetchUsers(false, false, ' AND u.statut > 0');
1753 $nbUser = count($users);
1754
1755 $typeleaves = $this->getTypes(1, 1);
1756
1757 // Update each user counter
1758 foreach ($users as $userCounter) {
1759 $nbDaysToAdd = (isset($typeleaves[$userCounter['type']]['newbymonth']) ? $typeleaves[$userCounter['type']]['newbymonth'] : 0);
1760 if (empty($nbDaysToAdd)) {
1761 continue;
1762 }
1763
1764 dol_syslog("We update leave type id ".$userCounter['type']." for user id ".$userCounter['rowid'], LOG_DEBUG);
1765
1766 $nowHoliday = (float) $userCounter['nb_holiday'];
1767 $newSolde = $nowHoliday + $nbDaysToAdd;
1768
1769 // We add a log for each user when its balance gets increased
1770 $this->addLogCP($user->id, $userCounter['rowid'], $langs->trans('HolidayMonthlyCredit'), $newSolde, $userCounter['type']);
1771
1772 $result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type']);
1773
1774 if ($result < 0) {
1775 $this->db->rollback();
1776 return -1;
1777 }
1778
1779 if (empty($decrease)) {
1780 continue;
1781 }
1782
1783 // We fetch a user's holiday in the current month and then calculate the number of days to deduct if he has at least one registered
1784 $filter = " AND cp.statut = ".((int) self::STATUS_APPROVED);
1785 $filter .= " AND cp.date_fin >= '".$this->db->idate(dol_stringtotime(dol_print_date($lastUpdate, '%Y-%m-01')))."'";
1786 $filter .= " AND cp.date_debut <= '".$this->db->idate(dol_stringtotime(dol_print_date($lastUpdate, '%Y-%m-t')))."'";
1787 $filter .= " AND cp.fk_type = ".((int) $userCounter['type']);
1788 $this->fetchByUser($userCounter['id'], '', $filter);
1789
1790 if (empty($this->holiday)) {
1791 continue;
1792 }
1793
1794 $startOfMonth = dol_mktime(0, 0, 0, (int) $month, 1, (int) $year, 1);
1795 $endOfMonth = dol_mktime(0, 0, 0, (int) $month, (int) dol_print_date($lastUpdate, 't'), (int) $year, 1);
1796
1797 foreach ($this->holiday as $obj) {
1798 $startDate = $obj['date_debut_gmt'];
1799 $endDate = $obj['date_fin_gmt'];
1800
1801 if ($startDate <= $endOfMonth && $startDate < $startOfMonth) {
1802 $startDate = $startOfMonth;
1803 }
1804
1805 if ($startOfMonth <= $endDate && $endDate > $endOfMonth) {
1806 $endDate = $endOfMonth;
1807 }
1808
1809 $nbDaysToDeduct = (float) num_open_day($startDate, $endDate, 0, 1, $obj['halfday'], $obj['country_id']);
1810
1811 if ($nbDaysToDeduct <= 0) {
1812 continue;
1813 }
1814
1815 $newSolde -= $nbDaysToDeduct;
1816
1817 // We add a log for each user when its balance gets decreased
1818 $this->addLogCP($user->id, $userCounter['rowid'], $obj['ref'].' - '.$langs->trans('HolidayConsumption'), $newSolde, $userCounter['type']);
1819
1820 $result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type']);
1821
1822 if ($result < 0) {
1823 $this->db->rollback();
1824 return -1;
1825 }
1826 }
1827 }
1828
1829 //updating the date of the last monthly balance update
1830 $newMonth = dol_get_next_month((int) dol_print_date($lastUpdate, '%m'), (int) dol_print_date($lastUpdate, '%Y'));
1831 $lastUpdate = dol_mktime(0, 0, 0, (int) $newMonth['month'], 1, (int) $newMonth['year']);
1832
1833 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1834 $sql .= " value = '".$this->db->escape(dol_print_date($lastUpdate, '%Y%m%d%H%M%S'))."'";
1835 $sql .= " WHERE name = 'lastUpdate'";
1836 $result = $this->db->query($sql);
1837
1838 if (!$result) {
1839 $this->db->rollback();
1840 return -1;
1841 }
1842
1843 $this->db->commit();
1844
1845 $yearMonthLastUpdate = dol_print_date($lastUpdate, '%Y%m');
1846 }
1847
1848 if (!$error) {
1849 return 1;
1850 } else {
1851 return 0;
1852 }
1853 } else {
1854 // Mise à jour pour un utilisateur
1855 $nbHoliday = price2num($nbHoliday, 5);
1856
1857 $sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users";
1858 $sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
1859 $resql = $this->db->query($sql);
1860 if ($resql) {
1861 $num = $this->db->num_rows($resql);
1862
1863 if ($num > 0) {
1864 // Update for user
1865 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
1866 $sql .= " nb_holiday = ".((float) $nbHoliday);
1867 $sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
1868 $result = $this->db->query($sql);
1869 if (!$result) {
1870 $error++;
1871 $this->errors[] = $this->db->lasterror();
1872 }
1873 } else {
1874 // Insert for user
1875 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1876 $sql .= ((float) $nbHoliday);
1877 $sql .= ", ".(int) $userID.", ".(int) $fk_type.")";
1878 $result = $this->db->query($sql);
1879 if (!$result) {
1880 $error++;
1881 $this->errors[] = $this->db->lasterror();
1882 }
1883 }
1884 } else {
1885 $this->errors[] = $this->db->lasterror();
1886 $error++;
1887 }
1888
1889 if (!$error) {
1890 return 1;
1891 } else {
1892 return -1;
1893 }
1894 }
1895 }
1896
1904 public function createCPusers($single = false, $userid = 0)
1905 {
1906 // do we have to add balance for all users ?
1907 if (!$single) {
1908 dol_syslog(get_class($this).'::createCPusers');
1909 $arrayofusers = $this->fetchUsers(false, true);
1910
1911 foreach ($arrayofusers as $users) {
1912 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1913 $sql .= " (fk_user, nb_holiday)";
1914 $sql .= " VALUES (".((int) $users['rowid'])."', '0')";
1915
1916 $resql = $this->db->query($sql);
1917 if (!$resql) {
1918 dol_print_error($this->db);
1919 }
1920 }
1921 } else {
1922 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1923 $sql .= " (fk_user, nb_holiday)";
1924 $sql .= " VALUES (".((int) $userid)."', '0')";
1925
1926 $resql = $this->db->query($sql);
1927 if (!$resql) {
1928 dol_print_error($this->db);
1929 }
1930 }
1931 }
1932
1940 public function getCPforUser($user_id, $fk_type = 0)
1941 {
1942 $sql = "SELECT nb_holiday";
1943 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users";
1944 $sql .= " WHERE fk_user = ".(int) $user_id;
1945 if ($fk_type > 0) {
1946 $sql .= " AND fk_type = ".(int) $fk_type;
1947 }
1948
1949 dol_syslog(get_class($this).'::getCPforUser user_id='.$user_id.' type_id='.$fk_type, LOG_DEBUG);
1950 $result = $this->db->query($sql);
1951 if ($result) {
1952 $obj = $this->db->fetch_object($result);
1953 //return number_format($obj->nb_holiday,2);
1954 if ($obj) {
1955 return $obj->nb_holiday;
1956 } else {
1957 return null;
1958 }
1959 } else {
1960 return null;
1961 }
1962 }
1963
1972 public function fetchUsers($stringlist = true, $type = true, $filters = '')
1973 {
1974 dol_syslog(get_class($this)."::fetchUsers", LOG_DEBUG);
1975
1976 if ($stringlist) {
1977 if ($type) {
1978 // If user of Dolibarr
1979 $sql = "SELECT";
1980 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
1981 $sql .= " DISTINCT";
1982 }
1983 $sql .= " u.rowid";
1984 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
1985
1986 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
1987 $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1988 $sql .= " WHERE ((ug.fk_user = u.rowid";
1989 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
1990 $sql .= " OR u.entity = 0)"; // Show always superadmin
1991 } else {
1992 $sql .= " WHERE u.entity IN (".getEntity('user').")";
1993 }
1994 $sql .= " AND u.statut > 0";
1995 $sql .= " AND u.employee = 1"; // We only want employee users for holidays
1996 if ($filters) {
1997 $sql .= $filters;
1998 }
1999
2000 $resql = $this->db->query($sql);
2001
2002 // Si pas d'erreur SQL
2003 if ($resql) {
2004 $i = 0;
2005 $num = $this->db->num_rows($resql);
2006 $stringlist = '';
2007
2008 // Boucles du listage des utilisateurs
2009 while ($i < $num) {
2010 $obj = $this->db->fetch_object($resql);
2011
2012 if ($i == 0) {
2013 $stringlist .= $obj->rowid;
2014 } else {
2015 $stringlist .= ', '.$obj->rowid;
2016 }
2017
2018 $i++;
2019 }
2020 // Retoune le tableau des utilisateurs
2021 return $stringlist;
2022 } else {
2023 // Erreur SQL
2024 $this->error = "Error ".$this->db->lasterror();
2025 return -1;
2026 }
2027 } else {
2028 // We want only list of vacation balance for user ids
2029 $sql = "SELECT DISTINCT cpu.fk_user";
2030 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
2031 $sql .= " WHERE cpu.fk_user = u.rowid";
2032 if ($filters) {
2033 $sql .= $filters;
2034 }
2035
2036 $resql = $this->db->query($sql);
2037
2038 // Si pas d'erreur SQL
2039 if ($resql) {
2040 $i = 0;
2041 $num = $this->db->num_rows($resql);
2042 $stringlist = '';
2043
2044 // Boucles du listage des utilisateurs
2045 while ($i < $num) {
2046 $obj = $this->db->fetch_object($resql);
2047
2048 if ($i == 0) {
2049 $stringlist .= $obj->fk_user;
2050 } else {
2051 $stringlist .= ', '.$obj->fk_user;
2052 }
2053
2054 $i++;
2055 }
2056 // Retoune le tableau des utilisateurs
2057 return $stringlist;
2058 } else {
2059 // Erreur SQL
2060 $this->error = "Error ".$this->db->lasterror();
2061 return -1;
2062 }
2063 }
2064 } else {
2065 // Si faux donc return array
2066 // List for Dolibarr users
2067 if ($type) {
2068 // If we need users of Dolibarr
2069 $sql = "SELECT";
2070 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
2071 $sql .= " DISTINCT";
2072 }
2073 $sql .= " u.rowid, u.lastname, u.firstname, u.gender, u.fk_country as country_id, u.photo, u.employee, u.statut as status, u.fk_user";
2074 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
2075
2076 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
2077 $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
2078 $sql .= " WHERE ((ug.fk_user = u.rowid";
2079 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
2080 $sql .= " OR u.entity = 0)"; // Show always superadmin
2081 } else {
2082 $sql .= " WHERE u.entity IN (".getEntity('user').")";
2083 }
2084
2085 $sql .= " AND u.statut > 0";
2086 $sql .= " AND u.employee = 1"; // We only want employee users for holidays
2087 if ($filters) {
2088 $sql .= $filters;
2089 }
2090
2091 $resql = $this->db->query($sql);
2092
2093 // Si pas d'erreur SQL
2094 if ($resql) {
2095 $i = 0;
2096 $tab_result = $this->holiday;
2097 $num = $this->db->num_rows($resql);
2098
2099 // Boucles du listage des utilisateurs
2100 while ($i < $num) {
2101 $obj = $this->db->fetch_object($resql);
2102
2103 $tab_result[$i]['rowid'] = (int) $obj->rowid; // rowid of user
2104 $tab_result[$i]['id'] = (int) $obj->rowid; // id of user
2105 $tab_result[$i]['name'] = $obj->lastname; // deprecated
2106 $tab_result[$i]['lastname'] = $obj->lastname;
2107 $tab_result[$i]['firstname'] = $obj->firstname;
2108 $tab_result[$i]['gender'] = $obj->gender;
2109 $tab_result[$i]['status'] = (int) $obj->status;
2110 $tab_result[$i]['employee'] = (int) $obj->employee;
2111 $tab_result[$i]['photo'] = $obj->photo;
2112 $tab_result[$i]['fk_user'] = (int) $obj->fk_user; // rowid of manager
2113 $tab_result[$i]['country_id'] = (int) $obj->country_id; // id of country of user
2114 //$tab_result[$i]['type'] = $obj->type;
2115 //$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
2116
2117 $i++;
2118 }
2119 // Retoune le tableau des utilisateurs
2120 return $tab_result;
2121 } else {
2122 // Erreur SQL
2123 $this->errors[] = "Error ".$this->db->lasterror();
2124 return -1;
2125 }
2126 } else {
2127 // List of vacation balance users
2128 $sql = "SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut as status, u.fk_user";
2129 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
2130 $sql .= " WHERE cpu.fk_user = u.rowid";
2131 if ($filters) {
2132 $sql .= $filters;
2133 }
2134
2135 $resql = $this->db->query($sql);
2136
2137 // Si pas d'erreur SQL
2138 if ($resql) {
2139 $i = 0;
2140 $tab_result = $this->holiday;
2141 $num = $this->db->num_rows($resql);
2142
2143 // Boucles du listage des utilisateurs
2144 while ($i < $num) {
2145 $obj = $this->db->fetch_object($resql);
2146
2147 $tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
2148 $tab_result[$i]['id'] = $obj->rowid; // id of user
2149 $tab_result[$i]['name'] = $obj->lastname; // deprecated
2150 $tab_result[$i]['lastname'] = $obj->lastname;
2151 $tab_result[$i]['firstname'] = $obj->firstname;
2152 $tab_result[$i]['gender'] = $obj->gender;
2153 $tab_result[$i]['status'] = $obj->status;
2154 $tab_result[$i]['employee'] = $obj->employee;
2155 $tab_result[$i]['photo'] = $obj->photo;
2156 $tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
2157
2158 $tab_result[$i]['type'] = $obj->fk_type;
2159 $tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
2160
2161 $i++;
2162 }
2163 // Retoune le tableau des utilisateurs
2164 return $tab_result;
2165 } else {
2166 // Erreur SQL
2167 $this->error = "Error ".$this->db->lasterror();
2168 return -1;
2169 }
2170 }
2171 }
2172 }
2173
2174
2175 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2183 {
2184 // phpcs:enable
2185 $users_validator = array();
2186
2187 $sql = "SELECT DISTINCT ur.fk_user";
2188 $sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd";
2189 $sql .= " WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'"; // Permission 'Approve';
2190 $sql .= "UNION";
2191 $sql .= " SELECT DISTINCT ugu.fk_user";
2192 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_user as ugu, ".MAIN_DB_PREFIX."usergroup_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd";
2193 $sql .= " WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'"; // Permission 'Approve';
2194 //print $sql;
2195
2196 dol_syslog(get_class($this)."::fetch_users_approver_holiday sql=".$sql);
2197 $result = $this->db->query($sql);
2198 if ($result) {
2199 $num_rows = $this->db->num_rows($result);
2200 $i = 0;
2201 while ($i < $num_rows) {
2202 $objp = $this->db->fetch_object($result);
2203 array_push($users_validator, $objp->fk_user);
2204 $i++;
2205 }
2206 return $users_validator;
2207 } else {
2208 $this->error = $this->db->lasterror();
2209 dol_syslog(get_class($this)."::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2210 return -1;
2211 }
2212 }
2213
2214
2220 public function countActiveUsers()
2221 {
2222 $sql = "SELECT count(u.rowid) as compteur";
2223 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
2224 $sql .= " WHERE u.statut > 0";
2225
2226 $result = $this->db->query($sql);
2227 $object = $this->db->fetch_object($result);
2228
2229 return $object->compteur;
2230 }
2237 {
2238 $sql = "SELECT count(u.rowid) as compteur";
2239 $sql .= " FROM ".MAIN_DB_PREFIX."user as u LEFT JOIN ".MAIN_DB_PREFIX."holiday_users hu ON (hu.fk_user=u.rowid)";
2240 $sql .= " WHERE u.statut > 0 AND hu.fk_user IS NULL";
2241
2242 $result = $this->db->query($sql);
2243 $object = $this->db->fetch_object($result);
2244
2245 return $object->compteur;
2246 }
2247
2255 public function verifNbUsers($userDolibarrWithoutCP, $userCP)
2256 {
2257 if (empty($userCP)) {
2258 $userCP = 0;
2259 }
2260 dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP);
2261 return 1;
2262 }
2263
2264
2275 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2276 {
2277 $error = 0;
2278
2279 $prev_solde = price2num((float) $this->getCPforUser($fk_user_update, $fk_type), 5);
2280 $new_solde = price2num($new_solde, 5);
2281 //print "$prev_solde == $new_solde";
2282
2283 if ($prev_solde == $new_solde) {
2284 return 0;
2285 }
2286
2287 $this->db->begin();
2288
2289 // Insert request
2290 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_logs (";
2291 $sql .= "date_action,";
2292 $sql .= "fk_user_action,";
2293 $sql .= "fk_user_update,";
2294 $sql .= "type_action,";
2295 $sql .= "prev_solde,";
2296 $sql .= "new_solde,";
2297 $sql .= "fk_type";
2298 $sql .= ") VALUES (";
2299 $sql .= " '".$this->db->idate(dol_now())."',";
2300 $sql .= " ".((int) $fk_user_action).",";
2301 $sql .= " ".((int) $fk_user_update).",";
2302 $sql .= " '".$this->db->escape($label)."',";
2303 $sql .= " ".((float) $prev_solde).",";
2304 $sql .= " ".((float) $new_solde).",";
2305 $sql .= " ".((int) $fk_type);
2306 $sql .= ")";
2307
2308 $resql = $this->db->query($sql);
2309 if (!$resql) {
2310 $error++;
2311 $this->errors[] = "Error ".$this->db->lasterror();
2312 }
2313
2314 $optRowid = 0;
2315 if (!$error) {
2316 $optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs");
2317 }
2318
2319 // Commit or rollback
2320 if ($error) {
2321 foreach ($this->errors as $errmsg) {
2322 dol_syslog(get_class($this)."::addLogCP ".$errmsg, LOG_ERR);
2323 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
2324 }
2325 $this->db->rollback();
2326 return -1 * $error;
2327 } else {
2328 $this->db->commit();
2329 return $optRowid;
2330 }
2331 }
2332
2340 public function fetchLog($sqlorder, $sqlwhere)
2341 {
2342 $sql = "SELECT";
2343 $sql .= " cpl.rowid,";
2344 $sql .= " cpl.date_action,";
2345 $sql .= " cpl.fk_user_action,";
2346 $sql .= " cpl.fk_user_update,";
2347 $sql .= " cpl.type_action,";
2348 $sql .= " cpl.prev_solde,";
2349 $sql .= " cpl.new_solde,";
2350 $sql .= " cpl.fk_type";
2351 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_logs as cpl";
2352 $sql .= " WHERE cpl.rowid > 0"; // To avoid error with other search and criteria
2353
2354 // Filter
2355 if (!empty($sqlwhere)) {
2356 $sql .= " ".$sqlwhere;
2357 }
2358
2359 // Order
2360 if (!empty($sqlorder)) {
2361 $sql .= " ".$sqlorder;
2362 }
2363
2364 dol_syslog(get_class($this)."::fetchLog", LOG_DEBUG);
2365 $resql = $this->db->query($sql);
2366
2367 // If no error SQL
2368 if ($resql) {
2369 $i = 0;
2370 $tab_result = $this->logs;
2371 $num = $this->db->num_rows($resql);
2372
2373 // If no record
2374 if (!$num) {
2375 return 2;
2376 }
2377
2378 // Loop on result to fill the array
2379 while ($i < $num) {
2380 $obj = $this->db->fetch_object($resql);
2381
2382 $tab_result[$i]['rowid'] = (int) $obj->rowid;
2383 $tab_result[$i]['id'] = (int) $obj->rowid;
2384 $tab_result[$i]['date_action'] = (string) $obj->date_action;
2385 $tab_result[$i]['fk_user_action'] = (int) $obj->fk_user_action;
2386 $tab_result[$i]['fk_user_update'] = (int) $obj->fk_user_update;
2387 $tab_result[$i]['type_action'] = (string) $obj->type_action;
2388 $tab_result[$i]['prev_solde'] = (float) $obj->prev_solde;
2389 $tab_result[$i]['new_solde'] = (float) $obj->new_solde;
2390 $tab_result[$i]['fk_type'] = (int) $obj->fk_type;
2391
2392 $i++;
2393 }
2394 // Retourne 1 et ajoute le tableau à la variable
2395 $this->logs = $tab_result;
2396 return 1;
2397 } else {
2398 // Erreur SQL
2399 $this->error = "Error ".$this->db->lasterror();
2400 return -1;
2401 }
2402 }
2403
2404
2412 public function getTypes($active = -1, $affect = -1)
2413 {
2414 global $mysoc;
2415
2416 $sql = "SELECT rowid, code, label, affect, delay, newbymonth";
2417 $sql .= " FROM ".MAIN_DB_PREFIX."c_holiday_types";
2418 $sql .= " WHERE (fk_country IS NULL OR fk_country = ".((int) $mysoc->country_id).')';
2419 $sql .= " AND entity IN (0, ".getEntity('c_holiday_types').")"; // Need entity 0 (holiday types common to all countries= + current entity).
2420 if ($active >= 0) {
2421 $sql .= " AND active = ".((int) $active);
2422 }
2423 if ($affect >= 0) {
2424 $sql .= " AND affect = ".((int) $affect);
2425 }
2426 $sql .= " ORDER BY sortorder";
2427
2428 $result = $this->db->query($sql);
2429 if ($result) {
2430 $num = $this->db->num_rows($result);
2431 if ($num) {
2432 $types = array();
2433 while ($obj = $this->db->fetch_object($result)) {
2434 $types[$obj->rowid] = array(
2435 'id' => $obj->rowid,
2436 'rowid' => $obj->rowid,
2437 'code' => $obj->code,
2438 'label' => $obj->label,
2439 'affect' => $obj->affect,
2440 'delay' => $obj->delay,
2441 'newbymonth' => $obj->newbymonth
2442 );
2443 }
2444
2445 return $types;
2446 }
2447 } else {
2448 dol_print_error($this->db);
2449 }
2450
2451 return array();
2452 }
2453
2454
2461 public function info($id)
2462 {
2463 global $conf;
2464
2465 $sql = "SELECT f.rowid, f.statut as status,";
2466 $sql .= " f.date_create as datec,";
2467 $sql .= " f.tms as date_modification,";
2468 $sql .= " f.date_valid as datev,";
2469 $sql .= " f.date_approval as datea,";
2470 $sql .= " f.date_refuse as dater,";
2471 $sql .= " f.fk_user_create as fk_user_creation,";
2472 $sql .= " f.fk_user_modif as fk_user_modification,";
2473 $sql .= " f.fk_user_valid as fk_user_validation,";
2474 $sql .= " f.fk_user_approve as fk_user_approval_done,";
2475 $sql .= " f.fk_validator as fk_user_approval_expected,";
2476 $sql .= " f.fk_user_refuse as fk_user_refuse";
2477 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as f";
2478 $sql .= " WHERE f.rowid = ".((int) $id);
2479 $sql .= " AND f.entity = ".$conf->entity;
2480
2481 $resql = $this->db->query($sql);
2482 if ($resql) {
2483 if ($this->db->num_rows($resql)) {
2484 $obj = $this->db->fetch_object($resql);
2485
2486 $this->id = $obj->rowid;
2487
2488 $this->date_creation = $this->db->jdate($obj->datec);
2489 $this->date_modification = $this->db->jdate($obj->date_modification);
2490 $this->date_validation = $this->db->jdate($obj->datev);
2491 $this->date_approval = $this->db->jdate($obj->datea);
2492
2493 $this->user_creation_id = $obj->fk_user_creation;
2494 $this->user_validation_id = $obj->fk_user_validation;
2495 $this->user_modification_id = $obj->fk_user_modification;
2496
2497 if ($obj->status == Holiday::STATUS_APPROVED || $obj->status == Holiday::STATUS_CANCELED) {
2498 if ($obj->fk_user_approval_done) {
2499 $this->fk_user_approve = $obj->fk_user_approval_done;
2500 $this->user_approve_id = $obj->fk_user_approval_done;
2501 }
2502 }
2503 }
2504 $this->db->free($resql);
2505 } else {
2506 dol_print_error($this->db);
2507 }
2508 }
2509
2510
2518 public function initAsSpecimen()
2519 {
2520 global $user, $langs;
2521
2522 // Initialise parameters
2523 $this->id = 0;
2524 $this->specimen = 1;
2525
2526 $this->fk_user = $user->id;
2527 $this->description = 'SPECIMEN description';
2528 $this->date_debut = dol_now();
2529 $this->date_fin = dol_now() + (24 * 3600);
2530 $this->date_valid = dol_now();
2531 $this->fk_validator = $user->id;
2532 $this->halfday = 0;
2533 $this->fk_type = 1;
2535
2536 return 1;
2537 }
2538
2544 public function loadStateBoard()
2545 {
2546 global $user;
2547
2548 $this->nb = array();
2549
2550 $sql = "SELECT count(h.rowid) as nb";
2551 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
2552 $sql .= " WHERE h.statut > 1";
2553 $sql .= " AND h.entity IN (".getEntity('holiday').")";
2554 if (!$user->hasRight('holiday', 'readall')) {
2555 $userchildids = $user->getAllChildIds(1);
2556 $sql .= " AND (h.fk_user IN (".$this->db->sanitize(implode(',', $userchildids)).")";
2557 $sql .= " OR h.fk_validator IN (".$this->db->sanitize(implode(',', $userchildids))."))";
2558 }
2559
2560 $resql = $this->db->query($sql);
2561 if ($resql) {
2562 while ($obj = $this->db->fetch_object($resql)) {
2563 $this->nb["holidays"] = $obj->nb;
2564 }
2565 $this->db->free($resql);
2566 return 1;
2567 } else {
2568 dol_print_error($this->db);
2569 $this->error = $this->db->error();
2570 return -1;
2571 }
2572 }
2573
2574 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2581 public function load_board($user)
2582 {
2583 // phpcs:enable
2584 global $conf, $langs;
2585
2586 if ($user->socid) {
2587 return -1; // protection pour eviter appel par utilisateur externe
2588 }
2589
2590 $now = dol_now();
2591
2592 $sql = "SELECT h.rowid, h.date_debut";
2593 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
2594 $sql .= " WHERE h.statut = 2";
2595 $sql .= " AND h.entity IN (".getEntity('holiday').")";
2596 if (!$user->hasRight('holiday', 'read_all')) {
2597 $userchildids = $user->getAllChildIds(1);
2598 $sql .= " AND (h.fk_user IN (".$this->db->sanitize(implode(',', $userchildids)).")";
2599 $sql .= " OR h.fk_validator IN (".$this->db->sanitize(implode(',', $userchildids))."))";
2600 }
2601
2602 $resql = $this->db->query($sql);
2603 if ($resql) {
2604 $langs->load("members");
2605
2606 $response = new WorkboardResponse();
2607 $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24;
2608 $response->label = $langs->trans("HolidaysToApprove");
2609 $response->labelShort = $langs->trans("ToApprove");
2610 $response->url = DOL_URL_ROOT.'/holiday/list.php?search_status=2&amp;mainmenu=hrm&amp;leftmenu=holiday';
2611 $response->img = img_object('', "holiday");
2612
2613 while ($obj = $this->db->fetch_object($resql)) {
2614 $response->nbtodo++;
2615
2616 if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
2617 $response->nbtodolate++;
2618 }
2619 }
2620
2621 return $response;
2622 } else {
2623 dol_print_error($this->db);
2624 $this->error = $this->db->error();
2625 return -1;
2626 }
2627 }
2635 public function getKanbanView($option = '', $arraydata = null)
2636 {
2637 global $langs;
2638
2639 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2640
2641 $return = '<div class="box-flex-item box-flex-grow-zero">';
2642 $return .= '<div class="info-box info-box-sm">';
2643 $return .= '<span class="info-box-icon bg-infobox-action">';
2644 $return .= img_picto('', $this->picto);
2645 $return .= '</span>';
2646 $return .= '<div class="info-box-content">';
2647 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().'</span>';
2648 if ($selected >= 0) {
2649 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2650 }
2651 if (property_exists($this, 'fk_type')) {
2652 $return .= '<br>';
2653 //$return .= '<span class="opacitymedium">'.$langs->trans("Type").'</span> : ';
2654 $return .= '<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata['labeltype']).'">'.dol_escape_htmltag($arraydata['labeltype']).'</div>';
2655 }
2656 if (property_exists($this, 'date_debut') && property_exists($this, 'date_fin')) {
2657 $return .= '<span class="info-box-label small">'.dol_print_date($this->date_debut, 'day').'</span>';
2658 $return .= ' <span class="opacitymedium small">'.$langs->trans("To").'</span> ';
2659 $return .= '<span class="info-box-label small">'.dol_print_date($this->date_fin, 'day').'</span>';
2660 if (!empty($arraydata['nbopenedday'])) {
2661 $return .= ' ('.$arraydata['nbopenedday'].')';
2662 }
2663 }
2664 if (method_exists($this, 'getLibStatut')) {
2665 $return .= '<div class="info-box-status">'.$this->getLibStatut(3).'</div>';
2666 }
2667 $return .= '</div>';
2668 $return .= '</div>';
2669 $return .= '</div>';
2670 return $return;
2671 }
2672}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:475
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class of the module paid holiday.
getTypes($active=-1, $affect=-1)
Return array with list of types.
getNomUrl($withpicto=0, $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Return clickable name (with picto eventually)
verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday=0)
Check if a user is on holiday (partially or completely) into a period.
validate($user=null, $notrigger=0)
Validate leave request.
info($id)
Load information on object.
updateBalance()
Update balance of vacations and check table of users for holidays is complete.
updateConfCP($name, $value)
Met à jour une option du module Holiday Payés.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
fetch($id, $ref='')
Load object in memory from database.
addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
addLogCP
verifNbUsers($userDolibarrWithoutCP, $userCP)
Compare le nombre d'utilisateur actif de Dolibarr à celui des utilisateurs des congés payés.
verifDateHolidayForTimestamp($fk_user, $timestamp, $status='-1')
Check that a user is not on holiday for a particular timestamp.
approve($user=null, $notrigger=0)
Approve leave request.
getNextNumRef($objsoc)
Returns the reference to the following non used Order depending on the active numbering module define...
const STATUS_REFUSED
Refused.
getConfCP($name, $createifnotfound='')
Return value of a conf parameter for leave module TODO Move this into llx_const table.
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
initAsSpecimen()
Initialise an instance with random values.
create($user, $notrigger=0)
Créer un congés payés dans la base de données.
selectStatutCP($selected=0, $htmlname='select_statut', $morecss='minwidth125')
Show select with list of leave status.
countActiveUsersWithoutCP()
Compte le nombre d'utilisateur actifs dans Dolibarr sans CP.
updateSoldeCP($userID=0, $nbHoliday=0, $fk_type=0)
Met à jour le timestamp de la dernière mise à jour du solde des CP.
update($user=null, $notrigger=0)
Update database.
getCPforUser($user_id, $fk_type=0)
Return the balance of annual leave of a user.
fetch_users_approver_holiday()
Return list of people with permission to validate leave requests.
__construct($db)
Constructor.
loadStateBoard()
Load this->nb for dashboard.
getLibStatut($mode=0)
Returns the label status.
createCPusers($single=false, $userid=0)
Create entries for each user at setup step.
fetchAll($order, $filter)
List all holidays of all users.
const STATUS_CANCELED
Canceled.
fetchLog($sqlorder, $sqlwhere)
List log of leaves.
countActiveUsers()
Compte le nombre d'utilisateur actifs dans Dolibarr.
fetchByUser($user_id, $order='', $filter='')
List holidays for a particular user or list of users.
const STATUS_APPROVED
Approved.
getTooltipContentArray($params)
getTooltipContentArray
fetchUsers($stringlist=true, $type=true, $filters='')
Get list of Users or list of vacation balance.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
LibStatut($status, $mode=0, $startdate='')
Returns the label of a status.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
global $mysoc
dol_get_next_month($month, $year)
Return next month.
Definition date.lib.php:556
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $countryCodeOrId='')
Function to return number of working days (and text of units) between two dates (working days)
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition date.lib.php:449
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
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...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...