27require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions.lib.php';
40 public $version =
'dolibarr';
45 public $prefix =
'MYOBJECT';
55 public $name =
'standard';
60 public $position = 40;
69 public function info($langs)
71 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
82 return $this->prefix.
"0501-0001";
95 global
$conf, $langs, $db;
101 $sql =
"SELECT MAX(CAST(SUBSTRING(t.ref FROM ".((int) $posindice).
") AS SIGNED)) as max";
102 $sql .=
" FROM ".$db->prefix().
"mymodule_myobject as t";
103 $sql .=
" WHERE t.ref LIKE '".$db->escape($this->prefix).
"____-%'";
104 if (
$object->ismultientitymanaged == 1) {
105 $sql .=
" AND t.entity = ".((int)
$conf->entity);
106 } elseif (preg_match(
'/^\w+@\w+$/', (
string)
$object->ismultientitymanaged)) {
107 $tmparray = explode(
'@', (
string)
$object->ismultientitymanaged);
108 $sql .=
" LEFT JOIN ".$db->prefix().$db->sanitize($tmparray[1]).
" as pt ON t.".$db->sanitize($tmparray[0]).
" = pt.rowid";
109 $sql .=
" WHERE pt.entity IN (".getEntity(
$object->element).
")";
112 $resql = $db->query($sql);
114 $row = $db->fetch_row($resql);
120 if ($coyymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
121 $langs->load(
"errors");
122 $this->error = $langs->trans(
'ErrorNumRefModel', $max);
141 $sql =
"SELECT MAX(CAST(SUBSTRING(t.ref FROM ".((int) $posindice).
") AS SIGNED)) as max";
142 $sql .=
" FROM ".$db->prefix().
"mymodule_myobject as t";
143 $sql .=
" WHERE t.ref LIKE '".$db->escape($this->prefix).
"____-%'";
144 if (
$object->ismultientitymanaged == 1) {
145 $sql .=
" AND t.entity = ".((int)
$conf->entity);
146 } elseif (preg_match(
'/^\w+@\w+$/', (
string)
$object->ismultientitymanaged)) {
147 $tmparray = explode(
'@', (
string)
$object->ismultientitymanaged);
148 $sql .=
" LEFT JOIN ".$db->prefix().$db->sanitize($tmparray[1]).
" as pt ON t.".$db->sanitize($tmparray[0]).
" = pt.rowid";
149 $sql .=
" WHERE pt.entity IN (".getEntity(
$object->element).
")";
152 $resql = $db->query($sql);
154 $obj = $db->fetch_object($resql);
156 $max = intval($obj->max);
161 dol_syslog(
"mod_myobject_standard::getNextValue", LOG_DEBUG);
166 $date =
$object->date_creation;
169 if ($max >= (pow(10, 4) - 1)) {
172 $num = sprintf(
"%04u", $max + 1);
175 dol_syslog(
"mod_myobject_standard::getNextValue return ".$this->prefix.$yymm.
"-".$num);
176 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.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
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.