29require_once DOL_DOCUMENT_ROOT.
'/core/modules/barcode/modules_barcode.class.php';
37 public $name =
'Standard';
39 public $code_modifiable;
41 public $code_modifiable_invalide;
43 public $code_modifiable_null;
51 public $version =
'dolibarr';
60 public $numbitcounter;
62 public $prefixIsRequired;
71 $this->code_modifiable = 1;
72 $this->code_modifiable_invalide = 1;
73 $this->code_modifiable_null = 1;
75 $this->prefixIsRequired = 0;
84 public function info($langs)
89 $langs->load(
"thirdparties");
91 $disabled = ((!empty($mc->sharings[
'referent']) && $mc->sharings[
'referent'] != $conf->entity) ?
' disabled' :
'');
93 $texte = $langs->trans(
'GenericNumRefModelDesc').
"<br>\n";
94 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
95 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
96 $texte .=
'<input type="hidden" name="page_y" value="">';
97 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
98 $texte .=
'<input type="hidden" name="param1" value="BARCODE_STANDARD_THIRDPARTY_MASK">';
99 $texte .=
'<table class="nobordernopadding" width="100%">';
101 $tooltip = $langs->trans(
"GenericMaskCodes", $langs->transnoentities(
"BarCode"), $langs->transnoentities(
"BarCode"));
102 $tooltip .= $langs->trans(
"GenericMaskCodes3EAN");
103 $tooltip .=
'<strong>'.$langs->trans(
"Example").
':</strong><br>';
104 $tooltip .=
'04{0000000000}? (for internal use)<br>';
105 $tooltip .=
'9771234{00000}? (example of ISSN code with prefix 1234)<br>';
106 $tooltip .=
'9791234{00000}? (example of ISMN code with prefix 1234)<br>';
111 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
':</td>';
112 $texte .=
'<td class="right">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value1" value="'.(!empty($conf->global->BARCODE_STANDARD_THIRDPARTY_MASK) ? $conf->global->BARCODE_STANDARD_THIRDPARTY_MASK :
'').
'"'.$disabled.
'>', $tooltip, 1, 1).
'</td>';
113 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button button-edit reposition small" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
116 $texte .=
'</table>';
132 $examplebarcode = $this->
getNextValue($objthirdparty,
'');
133 if (!$examplebarcode) {
134 $examplebarcode = $langs->trans(
'NotConfigured');
136 if ($examplebarcode ==
"ErrorBadMask") {
137 $langs->load(
"errors");
138 $examplebarcode = $langs->trans($examplebarcode);
141 return $examplebarcode;
155 $sql =
"SELECT rowid, code, libelle as label";
156 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_barcode_type";
157 $sql .=
" WHERE rowid = '".$db->escape($type).
"'";
158 $sql .=
" AND entity = ".((int) $conf->entity);
159 $result = $db->query($sql);
161 $num = $db->num_rows($result);
164 $obj = $db->fetch_object($result);
184 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
185 require_once DOL_DOCUMENT_ROOT.
'/core/lib/barcode.lib.php';
188 $type = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
195 if (!empty($conf->global->BARCODE_STANDARD_THIRDPARTY_MASK)) {
196 $mask = $conf->global->BARCODE_STANDARD_THIRDPARTY_MASK;
200 $this->error =
'NotConfigured';
209 $numFinal =
get_next_value($db, $mask,
'societe', $field, $where,
'', $now);
211 if ((substr($numFinal, -1)==
'*') or (substr($numFinal, -1)==
'?')) {
214 switch ($literaltype) {
216 if (strlen($numFinal)==13) {
217 $ean = substr($numFinal, 0, 12);
247 public function verif($db, &$code, $thirdparty, $thirdparty_type, $type)
253 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
256 $code = strtoupper(trim($code));
258 if (empty($code) && $this->code_null && empty($conf->global->BARCODE_STANDARD_THIRDPARTY_MASK)) {
260 } elseif (empty($code) && (!$this->code_null || !empty($conf->global->BARCODE_STANDARD_THIRDPARTY_MASK))) {
264 $is_dispo = $this->
verif_dispo($db, $code, $thirdparty);
265 if ($is_dispo <> 0) {
279 dol_syslog(get_class($this).
"::verif type=".$thirdparty_type.
" result=".$result);
296 $sql =
"SELECT barcode FROM ".MAIN_DB_PREFIX.
"societe";
297 $sql .=
" WHERE barcode = '".$db->escape($code).
"'";
298 if ($thirdparty->id > 0) {
299 $sql .=
" AND rowid <> ".$thirdparty->id;
302 $resql = $db->query($sql);
304 if ($db->num_rows($resql) == 0) {
330 $mask = empty($conf->global->BARCODE_STANDARD_THIRDPARTY_MASK) ?
'' : $conf->global->BARCODE_STANDARD_THIRDPARTY_MASK;
332 $this->error =
'NotConfigured';
336 dol_syslog(get_class($this).
'::verif_syntax codefortest='.$codefortest.
" typefortest=".$typefortest);
338 $newcodefortest = $codefortest;
341 if (in_array($typefortest, array(
'EAN13',
'ISBN'))) {
342 if (preg_match(
'/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $mask, $reg)) {
343 if (strlen($reg[1]) == 12) {
344 $newcodefortest = substr($newcodefortest, 0, 12);
346 dol_syslog(get_class($this).
'::verif_syntax newcodefortest='.$newcodefortest);
351 if (is_string($result)) {
352 $this->error = $result;
barcode_gen_ean_sum($ean)
Calculate EAN sum.
Parent class for barcode numbering models.
Class to manage barcode with standard rule.
verif($db, &$code, $thirdparty, $thirdparty_type, $type)
Check validity of code according to its rules.
verif_syntax($codefortest, $typefortest)
Return if a barcode value match syntax.
literalBarcodeType($db, $type='')
Return literal barcode type code from numerical rowid type of barcode.
verif_dispo($db, $code, $thirdparty)
Return if a code is used (by other element)
info($langs)
Return description of module.
getExample($langs, $objthirdparty=0)
Return an example of result returned by getNextValue.
__construct()
Constructor.
getNextValue($objthirdparty, $type='')
Return next value.
check_value($mask, $value)
Check value.
get_next_value($db, $mask, $table, $field, $where='', $objsoc='', $date='', $mode='next', $bentityon=true, $objuser=null, $forceentity=null)
Return last or next value for a mask (according to area we should not reset)
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.