dolibarr  21.0.0-alpha
mod_evaluation_standard.php
Go to the documentation of this file.
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 
27 require_once DOL_DOCUMENT_ROOT . '/core/modules/hrm/modules_evaluation.php';
28 
29 
34 {
39  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
40 
41  public $prefix = 'EVAL';
42 
46  public $error = '';
47 
51  public $name = 'standard';
52 
53 
60  public function info($langs)
61  {
62  global $langs;
63  return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
64  }
65 
66 
72  public function getExample()
73  {
74  return $this->prefix."0501-0001";
75  }
76 
77 
85  public function canBeActivated($object)
86  {
87  global $conf, $langs, $db;
88 
89  $coyymm = '';
90  $max = '';
91 
92  $posindice = strlen($this->prefix) + 6;
93  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
94  $sql .= " FROM ".MAIN_DB_PREFIX."hrm_evaluation";
95  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
96  if ($object->ismultientitymanaged == 1) {
97  $sql .= " AND entity = ".$conf->entity;
98  } elseif ($object->ismultientitymanaged == 2) {
99  // TODO
100  }
101 
102  $resql = $db->query($sql);
103  if ($resql) {
104  $row = $db->fetch_row($resql);
105  if ($row) {
106  $coyymm = substr($row[0], 0, 6);
107  $max = $row[0];
108  }
109  }
110  if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
111  $langs->load("errors");
112  $this->error = $langs->trans('ErrorNumRefModel', $max);
113  return false;
114  }
115 
116  return true;
117  }
118 
125  public function getNextValue($object)
126  {
127  global $db, $conf;
128 
129  // first we get the max value
130  $posindice = strlen($this->prefix) + 6;
131  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
132  $sql .= " FROM ".MAIN_DB_PREFIX."hrm_evaluation";
133  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
134  if ($object->ismultientitymanaged == 1) {
135  $sql .= " AND entity = ".$conf->entity;
136  } elseif ($object->ismultientitymanaged == 2) {
137  // TODO
138  }
139 
140  $resql = $db->query($sql);
141  if ($resql) {
142  $obj = $db->fetch_object($resql);
143  if ($obj) {
144  $max = intval($obj->max);
145  } else {
146  $max = 0;
147  }
148  } else {
149  dol_syslog("mod_evaluation_standard::getNextValue", LOG_DEBUG);
150  return -1;
151  }
152 
153  //$date=time();
154  $date = $object->date_creation;
155  $yymm = dol_print_date($date, "%y%m");
156 
157  if ($max >= (pow(10, 4) - 1)) {
158  $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
159  } else {
160  $num = sprintf("%04d", $max + 1);
161  }
162 
163  dol_syslog("mod_evaluation_standard::getNextValue return ".$this->prefix.$yymm."-".$num);
164  return $this->prefix.$yymm."-".$num;
165  }
166 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
Parent class to manage numbering of Evaluation.
Class to manage the Standard numbering rule for HR evaluation.
getExample()
Return an example of numbering.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
info($langs)
Return description of numbering module.
getNextValue($object)
Return next free value.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:751
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).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.