29require_once DOL_DOCUMENT_ROOT.
'/core/modules/societe/modules_societe.class.php';
38 public $name =
'Monkey';
39 public $version =
'dolibarr';
45 public $prefixcustomer =
'CU';
49 public $prefixsupplier =
'SU';
62 $this->code_modifiable = 1;
63 $this->code_modifiable_invalide = 1;
64 $this->code_modifiable_null = 1;
66 $this->prefixIsRequired = 0;
76 public function info($langs)
78 return $langs->trans(
"MonkeyNumRefModelDesc", $this->prefixcustomer, $this->prefixsupplier);
90 public function getExample($langs =
null, $objsoc =
'', $type = -1)
92 return $this->prefixcustomer.
'0901-00001<br>'.$this->prefixsupplier.
'0901-00001';
110 $field =
'code_client';
111 $prefix = $this->prefixcustomer;
112 } elseif ($type == 1) {
113 $field =
'code_fournisseur';
114 $prefix = $this->prefixsupplier;
120 $posindice = strlen($prefix) + 6;
121 $sql =
"SELECT MAX(CAST(SUBSTRING(".$db->sanitize($field).
" FROM ".$posindice.
") AS SIGNED)) as max";
122 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe";
123 $sql .=
" WHERE ".$db->sanitize($field).
" LIKE '".$db->escape($prefix).
"____-%'";
124 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
126 dol_syslog(get_class($this).
"::getNextValue", LOG_DEBUG);
128 $resql = $db->query($sql);
130 $obj = $db->fetch_object($resql);
132 $max = intval($obj->max);
143 if ($max >= (pow(10, 5) - 1)) {
146 $num = sprintf(
"%05d", $max + 1);
149 dol_syslog(get_class($this).
"::getNextValue return ".$prefix.$yymm.
"-".$num);
150 return $prefix.$yymm.
"-".$num;
169 public function verif($db, &$code, $soc, $type)
172 $code = strtoupper(trim($code));
174 if (empty($code) && $this->code_null && !
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
176 } elseif (empty($code) && (!$this->code_null ||
getDolGlobalString(
'MAIN_COMPANY_CODE_ALWAYS_REQUIRED'))) {
180 $is_dispo = $this->
verif_dispo($db, $code, $soc, $type);
181 if ($is_dispo != 0) {
195 dol_syslog(get_class($this).
"::verif code=".$code.
" type=".$type.
" result=".$result);
213 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
215 $sql .=
" WHERE code_fournisseur = '".$db->escape($code).
"'";
217 $sql .=
" WHERE code_client = '".$db->escape($code).
"'";
219 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
221 $sql .=
" AND rowid <> ".$soc->id;
224 dol_syslog(get_class($this).
"::verif_dispo", LOG_DEBUG);
225 $resql = $db->query($sql);
227 if ($db->num_rows($resql) == 0) {
Parent class for third parties code generators.
Class permettant la gestion monkey des codes tiers.
verif_syntax($code)
Renvoi si un code respecte la syntax.
getExample($langs=null, $objsoc='', $type=-1)
Return an example of result returned by getNextValue.
info($langs)
Return description of module.
__construct($db)
Constructor.
verif_dispo($db, $code, $soc, $type=0)
Indicates if the code is available or not (by another third party)
verif($db, &$code, $soc, $type)
Check validity of code according to its rules.
getNextValue($objsoc='', $type=-1)
Return next value.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.