29require_once DOL_DOCUMENT_ROOT.
'/core/modules/asset/modules_asset.php';
40 public $version =
'dolibarr';
42 public $prefix =
'ASSET';
52 public $name =
'standard';
61 public function info($langs)
64 return $langs->trans(
"SimpleNumRefModelDesc", $this->prefix);
75 return $this->prefix.
"0501-0001";
88 global $conf, $langs, $db;
93 $posindice = strlen($this->prefix) + 6;
94 $sql =
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max";
95 $sql .=
" FROM ".MAIN_DB_PREFIX.
"asset_asset";
96 $sql .=
" WHERE ref LIKE '".$db->escape($this->prefix).
"____-%'";
97 if (
$object->ismultientitymanaged == 1) {
98 $sql .=
" AND entity = ".$conf->entity;
99 } elseif (
$object->ismultientitymanaged == 2) {
103 $resql = $db->query($sql);
105 $row = $db->fetch_row($resql);
107 $coyymm = substr($row[0], 0, 6);
111 if ($coyymm && !preg_match(
'/'.$this->prefix.
'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
112 $langs->load(
"errors");
113 $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.
"asset";
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_asset_standard::getNextValue", LOG_DEBUG);
156 $date =
$object->date_creation;
159 if ($max >= (pow(10, 4) - 1)) {
162 $num = sprintf(
"%04d", $max + 1);
165 dol_syslog(
"mod_asset_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 Asset.
Class to manage the Standard numbering rule for Asset.
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).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.