39 public $version =
'dolibarr';
44 public $prefix =
'MYOBJECT';
54 public $name =
'standard';
59 public $position = 40;
68 public function info($langs)
70 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
81 return $this->prefix.
"0501-0001";
94 global
$conf, $langs, $db;
99 $posindice = strlen($this->prefix) + 6;
100 $sql =
"SELECT MAX(CAST(SUBSTRING(t.ref FROM ".$posindice.
") AS SIGNED)) as max";
101 $sql .=
" FROM ".$db->prefix().
"mymodule_myobject as t";
102 $sql .=
" WHERE t.ref LIKE '".$db->escape($this->prefix).
"____-%'";
103 if (
$object->ismultientitymanaged == 1) {
104 $sql .=
" AND t.entity = ".((int)
$conf->entity);
105 } elseif (preg_match(
'/^\w+@\w+$/', (
string)
$object->ismultientitymanaged)) {
106 $tmparray = explode(
'@', (
string)
$object->ismultientitymanaged);
107 $sql .=
" LEFT JOIN ".$db->prefix().$tmparray[1].
" as pt ON t.".
$db->sanitize($tmparray[0]).
" = pt.rowid";
108 $sql .=
" WHERE pt.entity IN (".getEntity(
$object->element).
")";
111 $resql =
$db->query($sql);
113 $row =
$db->fetch_row($resql);
115 $coyymm = substr($row[0], 0, 6);
119 if ($coyymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
120 $langs->load(
"errors");
121 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
139 $posindice = strlen($this->prefix) + 6;
140 $sql =
"SELECT MAX(CAST(SUBSTRING(t.ref FROM ".$posindice.
") AS SIGNED)) as max";
141 $sql .=
" FROM ".$db->prefix().
"mymodule_myobject as t";
142 $sql .=
" WHERE t.ref LIKE '".$db->escape($this->prefix).
"____-%'";
143 if (
$object->ismultientitymanaged == 1) {
144 $sql .=
" AND t.entity = ".((int)
$conf->entity);
145 } elseif (preg_match(
'/^\w+@\w+$/', (
string)
$object->ismultientitymanaged)) {
146 $tmparray = explode(
'@', (
string)
$object->ismultientitymanaged);
147 $sql .=
" LEFT JOIN ".$db->prefix().$tmparray[1].
" as pt ON t.".
$db->sanitize($tmparray[0]).
" = pt.rowid";
148 $sql .=
" WHERE pt.entity IN (".getEntity(
$object->element).
")";
151 $resql =
$db->query($sql);
153 $obj =
$db->fetch_object($resql);
155 $max = intval($obj->max);
160 dol_syslog(
"mod_myobject_standard::getNextValue", LOG_DEBUG);
165 $date =
$object->date_creation;
168 if ($max >= (pow(10, 4) - 1)) {
171 $num = sprintf(
"%04u", $max + 1);
174 dol_syslog(
"mod_myobject_standard::getNextValue return ".$this->prefix.$yymm.
"-".$num);
175 return $this->prefix.$yymm.
"-".$num;
if(! $sortfield) if(! $sortorder) $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.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.