dolibarr 20.0.0
mod_recruitmentjobposition_standard.php
1<?php
2/* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
27dol_include_once('/recruitment/core/modules/recruitment/modules_recruitmentjobposition.php');
28
29
34{
39 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
40
41 public $prefix = 'JOB';
42
46 public $error = '';
47
51 public $name = 'standard';
52
53
60 public function info($langs)
61 {
62 return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
63 }
64
65
71 public function getExample()
72 {
73 return $this->prefix."0501-0001";
74 }
75
76
84 public function canBeActivated($object)
85 {
86 global $conf, $langs, $db;
87
88 $coyymm = '';
89 $max = '';
90
91 $posindice = strlen($this->prefix) + 6;
92 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
93 $sql .= " FROM ".MAIN_DB_PREFIX."recruitment_recruitmentjobposition";
94 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
95 if ($object->ismultientitymanaged == 1) {
96 $sql .= " AND entity = ".$conf->entity;
97 } elseif ($object->ismultientitymanaged == 2) {
98 // TODO
99 }
100
101 $resql = $db->query($sql);
102 if ($resql) {
103 $row = $db->fetch_row($resql);
104 if ($row) {
105 $coyymm = substr($row[0], 0, 6);
106 $max = $row[0];
107 }
108 }
109 if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
110 $langs->load("errors");
111 $this->error = $langs->trans('ErrorNumRefModel', $max);
112 return false;
113 }
114
115 return true;
116 }
117
124 public function getNextValue($object)
125 {
126 global $db, $conf;
127
128 // First we get the max value
129 $posindice = strlen($this->prefix) + 6;
130 $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
131 $sql .= " FROM ".MAIN_DB_PREFIX."recruitment_recruitmentjobposition";
132 $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
133 if ($object->ismultientitymanaged == 1) {
134 $sql .= " AND entity = ".$conf->entity;
135 } elseif ($object->ismultientitymanaged == 2) {
136 // TODO
137 }
138
139 $resql = $db->query($sql);
140 if ($resql) {
141 $obj = $db->fetch_object($resql);
142 if ($obj) {
143 $max = intval($obj->max);
144 } else {
145 $max = 0;
146 }
147 } else {
148 dol_syslog("mod_recruitmentjobposition_standard::getNextValue", LOG_DEBUG);
149 return -1;
150 }
151
152 //$date=time();
153 $date = $object->date_creation;
154 $yymm = dol_print_date($date, "%y%m");
155
156 if ($max >= (pow(10, 4) - 1)) {
157 $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
158 } else {
159 $num = sprintf("%04d", $max + 1);
160 }
161
162 dol_syslog("mod_recruitmentjobposition_standard::getNextValue return ".$this->prefix.$yymm."-".$num);
163 return $this->prefix.$yymm."-".$num;
164 }
165}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Parent class to manage numbering of RecruitmentJobPosition.
Class to manage the Standard numbering rule for Job positions.
info($langs)
Return description of numbering module.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.