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(t.ref FROM ".$posindice.
") AS SIGNED)) as max";
96 $sql .=
" FROM ".$db->prefix().
"mymodule_myobject as t";
97 $sql .=
" WHERE t.ref LIKE '".$db->escape($this->prefix).
"____-%'";
98 if (
$object->ismultientitymanaged == 1) {
99 $sql .=
" AND t.entity = ".((int) $conf->entity);
100 } elseif (preg_match(
'/^\w+@\w+$/', (
string)
$object->ismultientitymanaged)) {
101 $tmparray = explode(
'@', (
string)
$object->ismultientitymanaged);
102 $sql .=
" LEFT JOIN ".$db->prefix().$tmparray[1].
" as pt ON t.".$db->sanitize($tmparray[0]).
" = pt.rowid";
103 $sql .=
" WHERE pt.entity IN (".getEntity(
$object->element).
")";
106 $resql = $db->query($sql);
108 $row = $db->fetch_row($resql);
110 $coyymm = substr($row[0], 0, 6);
114 if ($coyymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
115 $langs->load(
"errors");
116 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
134 $posindice = strlen($this->prefix) + 6;
135 $sql =
"SELECT MAX(CAST(SUBSTRING(t.ref FROM ".$posindice.
") AS SIGNED)) as max";
136 $sql .=
" FROM ".$db->prefix().
"mymodule_myobject as t";
137 $sql .=
" WHERE t.ref LIKE '".$db->escape($this->prefix).
"____-%'";
138 if (
$object->ismultientitymanaged == 1) {
139 $sql .=
" AND t.entity = ".((int) $conf->entity);
140 } elseif (preg_match(
'/^\w+@\w+$/', (
string)
$object->ismultientitymanaged)) {
141 $tmparray = explode(
'@', (
string)
$object->ismultientitymanaged);
142 $sql .=
" LEFT JOIN ".$db->prefix().$tmparray[1].
" as pt ON t.".$db->sanitize($tmparray[0]).
" = pt.rowid";
143 $sql .=
" WHERE pt.entity IN (".getEntity(
$object->element).
")";
146 $resql = $db->query($sql);
148 $obj = $db->fetch_object($resql);
150 $max = intval($obj->max);
155 dol_syslog(
"mod_myobject_standard::getNextValue", LOG_DEBUG);
160 $date =
$object->date_creation;
163 if ($max >= (pow(10, 4) - 1)) {
166 $num = sprintf(
"%04u", $max + 1);
169 dol_syslog(
"mod_myobject_standard::getNextValue return ".$this->prefix.$yymm.
"-".$num);
170 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.