27require_once DOL_DOCUMENT_ROOT.
'/core/modules/societe/modules_societe.class.php';
38 public $name =
'Monkey';
40 public $code_modifiable;
42 public $code_modifiable_invalide;
44 public $code_modifiable_null;
52 public $version =
'dolibarr';
59 public $prefixcustomer =
'CU';
61 public $prefixsupplier =
'SU';
63 public $prefixIsRequired;
72 $this->code_modifiable = 1;
73 $this->code_modifiable_invalide = 1;
74 $this->code_modifiable_null = 1;
76 $this->prefixIsRequired = 0;
86 public function info($langs)
88 return $langs->trans(
"MonkeyNumRefModelDesc", $this->prefixcustomer, $this->prefixsupplier);
102 return $this->prefixcustomer.
'0901-00001<br>'.$this->prefixsupplier.
'0901-00001';
115 global $db, $conf, $mc;
120 $field =
'code_client';
121 $prefix = $this->prefixcustomer;
122 } elseif ($type == 1) {
123 $field =
'code_fournisseur';
124 $prefix = $this->prefixsupplier;
130 $posindice = strlen($prefix) + 6;
131 $sql =
"SELECT MAX(CAST(SUBSTRING(".$field.
" FROM ".$posindice.
") AS SIGNED)) as max";
132 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe";
133 $sql .=
" WHERE ".$field.
" LIKE '".$db->escape($prefix).
"____-%'";
134 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
136 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
138 $resql = $db->query($sql);
140 $obj = $db->fetch_object($resql);
142 $max = intval($obj->max);
153 if ($max >= (pow(10, 5) - 1)) {
156 $num = sprintf(
"%05s", $max + 1);
159 dol_syslog(get_class($this).
"::getNextValue return ".$prefix.$yymm.
"-".$num);
160 return $prefix.$yymm.
"-".$num;
177 public function verif($db, &$code, $soc, $type)
182 $code = strtoupper(trim($code));
184 if (empty($code) && $this->code_null && !
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
186 } elseif (empty($code) && (!$this->code_null ||
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED'))) {
190 $is_dispo = $this->
verif_dispo($db, $code, $soc, $type);
191 if ($is_dispo != 0) {
205 dol_syslog(get_class($this).
"::verif code=".$code.
" type=".$type.
" result=".$result);
225 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
227 $sql .=
" WHERE code_fournisseur = '".$db->escape($code).
"'";
229 $sql .=
" WHERE code_client = '".$db->escape($code).
"'";
231 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
233 $sql .=
" AND rowid <> ".$soc->id;
236 dol_syslog(get_class($this).
"::verif_dispo", LOG_DEBUG);
237 $resql = $db->query($sql);
239 if ($db->num_rows($resql) == 0) {
Parent class for third parties code generators.
Classe permettant la gestion monkey des codes tiers.
verif_syntax($code)
Renvoi si un code respecte la syntaxe.
getExample($langs, $objsoc=0, $type=-1)
Return an example of result returned by getNextValue.
info($langs)
Return description of module.
__construct()
Constructor.
verif_dispo($db, $code, $soc, $type=0)
Renvoi si un code est pris ou non (par autre tiers)
verif($db, &$code, $soc, $type)
Check validity of code according to its rules.
getNextValue($objsoc=0, $type=-1)
Return next value.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.