28require_once DOL_DOCUMENT_ROOT.
'/core/modules/barcode/modules_barcode.class.php';
36 public $name =
'Standard';
38 public $code_modifiable;
40 public $code_modifiable_invalide;
42 public $code_modifiable_null;
50 public $version =
'dolibarr';
59 public $numbitcounter;
61 public $prefixIsRequired;
70 $this->code_modifiable = 1;
71 $this->code_modifiable_invalide = 1;
72 $this->code_modifiable_null = 1;
74 $this->prefixIsRequired = 0;
83 public function info($langs)
88 $langs->load(
"products");
90 $disabled = ((!empty($mc->sharings[
'referent']) && $mc->sharings[
'referent'] != $conf->entity) ?
' disabled' :
'');
92 $texte = $langs->trans(
'GenericNumRefModelDesc').
"<br>\n";
93 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
94 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
95 $texte .=
'<input type="hidden" name="page_y" value="">';
96 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
97 $texte .=
'<input type="hidden" name="param1" value="BARCODE_STANDARD_PRODUCT_MASK">';
98 $texte .=
'<table class="nobordernopadding" width="100%">';
100 $tooltip = $langs->trans(
"GenericMaskCodes", $langs->transnoentities(
"BarCode"), $langs->transnoentities(
"BarCode"));
101 $tooltip .= $langs->trans(
"GenericMaskCodes3EAN");
102 $tooltip .=
'<strong>'.$langs->trans(
"Example").
':</strong><br>';
103 $tooltip .=
'04{0000000000}? (for internal use)<br>';
104 $tooltip .=
'9771234{00000}? (example of ISSN code with prefix 1234)<br>';
105 $tooltip .=
'9791234{00000}? (example of ISMN code with prefix 1234)<br>';
110 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
':</td>';
111 $texte .=
'<td class="right">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value1" value="'.(!empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK) ? $conf->global->BARCODE_STANDARD_PRODUCT_MASK :
'').
'"'.$disabled.
'>', $tooltip, 1, 1).
'</td>';
112 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button button-edit reposition small" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
115 $texte .=
'</table>';
132 if (!$examplebarcode) {
133 $examplebarcode = $langs->trans(
'NotConfigured');
135 if ($examplebarcode ==
"ErrorBadMask") {
136 $langs->load(
"errors");
137 $examplebarcode = $langs->trans($examplebarcode);
140 return $examplebarcode;
154 $sql =
"SELECT rowid, code, libelle as label";
155 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_barcode_type";
156 $sql .=
" WHERE rowid = '".$db->escape($type).
"'";
157 $sql .=
" AND entity = ".((int) $conf->entity);
158 $result = $db->query($sql);
160 $num = $db->num_rows($result);
163 $obj = $db->fetch_object($result);
183 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
184 require_once DOL_DOCUMENT_ROOT.
'/core/lib/barcode.lib.php';
187 $type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
194 if (!empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) {
195 $mask = $conf->global->BARCODE_STANDARD_PRODUCT_MASK;
199 $this->error =
'NotConfigured';
208 $numFinal =
get_next_value($db, $mask,
'product', $field, $where,
'', $now);
210 if ((substr($numFinal, -1)==
'*') or (substr($numFinal, -1)==
'?')) {
213 switch ($literaltype) {
215 if (strlen($numFinal)==13) {
216 $ean = substr($numFinal, 0, 12);
246 public function verif($db, &$code, $product, $thirdparty_type, $type)
252 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
255 $code = strtoupper(trim($code));
257 if (empty($code) && $this->code_null && empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) {
259 } elseif (empty($code) && (!$this->code_null || !empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK))) {
263 $is_dispo = $this->
verif_dispo($db, $code, $product);
264 if ($is_dispo <> 0) {
278 dol_syslog(get_class($this).
"::verif type=".$thirdparty_type.
" result=".$result);
295 $sql =
"SELECT barcode FROM ".MAIN_DB_PREFIX.
"product";
296 $sql .=
" WHERE barcode = '".$db->escape($code).
"'";
297 $sql .=
" AND entity IN (".getEntity(
'product').
")";
299 if ($product->id > 0) {
300 $sql .=
" AND rowid <> ".$product->id;
303 $resql = $db->query($sql);
305 if ($db->num_rows($resql) == 0) {
331 $mask = empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK) ?
'' : $conf->global->BARCODE_STANDARD_PRODUCT_MASK;
333 $this->error =
'NotConfigured';
337 dol_syslog(get_class($this).
'::verif_syntax codefortest='.$codefortest.
" typefortest=".$typefortest);
339 $newcodefortest = $codefortest;
342 if (in_array($typefortest, array(
'EAN13',
'ISBN'))) {
343 if (preg_match(
'/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $mask, $reg)) {
344 if (strlen($reg[1]) == 12) {
345 $newcodefortest = substr($newcodefortest, 0, 12);
347 dol_syslog(get_class($this).
'::verif_syntax newcodefortest='.$newcodefortest);
352 if (is_string($result)) {
353 $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_dispo($db, $code, $product)
Return if a code is used (by other element)
__construct()
Constructor.
literalBarcodeType($db, $type='')
Return literal barcode type code from numerical rowid type of barcode.
verif($db, &$code, $product, $thirdparty_type, $type)
Check validity of code according to its rules.
getExample($langs, $objproduct=0)
Return an example of result returned by getNextValue.
verif_syntax($codefortest, $typefortest)
Return if a barcode value match syntax.
getNextValue($objproduct, $type='')
Return next value.
info($langs)
Return description of module.
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.