39 public $version =
'dolibarr';
44 public $prefix =
'MYOBJECT';
54 public $name =
'standard';
63 public function info($langs)
65 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
76 return $this->prefix.
"0501-0001";
89 global $conf, $langs, $db;
94 $posindice = strlen($this->prefix) + 6;
95 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
96 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mymodule_myobject";
97 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
98 if (
$object->ismultientitymanaged == 1) {
99 $sql .=
" AND entity = ".$conf->entity;
100 } elseif (
$object->ismultientitymanaged == 2) {
104 $resql = $db->query($sql);
106 $row = $db->fetch_row($resql);
108 $coyymm = substr($row[0], 0, 6);
112 if ($coyymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
113 $langs->load(
"errors");
114 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
132 $posindice = strlen($this->prefix) + 6;
133 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
134 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mymodule_myobject";
135 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
136 if (
$object->ismultientitymanaged == 1) {
137 $sql .=
" AND entity = ".$conf->entity;
138 } elseif (
$object->ismultientitymanaged == 2) {
142 $resql = $db->query($sql);
144 $obj = $db->fetch_object($resql);
146 $max = intval($obj->max);
151 dol_syslog(
"mod_myobject_standard::getNextValue", LOG_DEBUG);
156 $date =
$object->date_creation;
159 if ($max >= (pow(10, 4) - 1)) {
162 $num = sprintf(
"%04u", $max + 1);
165 dol_syslog(
"mod_myobject_standard::getNextValue return ".$this->prefix.$yymm.
"-".$num);
166 return $this->prefix.$yymm.
"-".$num;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Parent class to manage numbering of MyObject.
Class to manage the Standard numbering rule for MyObject.
getNextValue($object)
Return next free value.
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.
getExample()
Return an example of numbering.
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.