30require_once DOL_DOCUMENT_ROOT.
'/core/modules/barcode/modules_barcode.class.php';
38 public $name =
'Standard';
44 public $version =
'dolibarr';
48 public $numbitcounter;
56 $this->code_modifiable = 1;
57 $this->code_modifiable_invalide = 1;
58 $this->code_modifiable_null = 1;
60 $this->prefixIsRequired = 0;
69 public function info($langs)
74 $langs->load(
"products");
76 $disabled = ((!empty($mc->sharings[
'referent']) && $mc->sharings[
'referent'] != $conf->entity) ?
' disabled' :
'');
78 $texte = $langs->trans(
'GenericNumRefModelDesc').
"<br>\n";
79 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
80 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
81 $texte .=
'<input type="hidden" name="page_y" value="">';
82 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
83 $texte .=
'<input type="hidden" name="param1" value="BARCODE_STANDARD_PRODUCT_MASK">';
84 $texte .=
'<table class="nobordernopadding" width="100%">';
86 $tooltip = $langs->trans(
"GenericMaskCodes", $langs->transnoentities(
"BarCode"), $langs->transnoentities(
"BarCode"));
87 $tooltip .= $langs->trans(
"GenericMaskCodes3EAN");
88 $tooltip .=
'<strong>'.$langs->trans(
"Example").
':</strong><br>';
89 $tooltip .=
'04{0000000000}? (for internal use)<br>';
90 $tooltip .=
'9771234{00000}? (example of ISSN code with prefix 1234)<br>';
91 $tooltip .=
'9791234{00000}? (example of ISMN code with prefix 1234)<br>';
97 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
':</td>';
98 $texte .=
'<td class="right">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value1" value="'.(
getDolGlobalString(
'BARCODE_STANDARD_PRODUCT_MASK') ? $conf->global->BARCODE_STANDARD_PRODUCT_MASK :
'').
'"'.$disabled.
'>', $tooltip, 1, 1).
'</td>';
99 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
102 $texte .=
'</table>';
116 public function getExample($langs =
null, $objproduct =
null)
119 $langs = $GLOBALS[
'langs'];
120 '@phan-var-force Translate $langs';
123 if (!$examplebarcode) {
124 $examplebarcode = $langs->trans(
'NotConfigured');
126 if ($examplebarcode ==
"ErrorBadMask") {
127 $langs->load(
"errors");
128 $examplebarcode = $langs->trans($examplebarcode);
131 return $examplebarcode;
145 $sql =
"SELECT rowid, code, libelle as label";
146 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_barcode_type";
147 $sql .=
" WHERE rowid = ".(int) $type;
148 $sql .=
" AND entity = ".((int) $conf->entity);
149 $result = $db->query($sql);
151 $num = $db->num_rows($result);
154 $obj = $db->fetch_object($result);
175 if (is_object($objproduct) && !$objproduct instanceof
Product) {
176 dol_syslog(get_class($this).
"::getNextValue used on incompatible".get_class($objproduct), LOG_ERR);
180 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
181 require_once DOL_DOCUMENT_ROOT.
'/core/lib/barcode.lib.php';
192 $this->error =
'NotConfigured';
201 $numFinal =
get_next_value($db, $mask,
'product', $field, $where,
'', $now);
203 if ((substr($numFinal, -1) ==
'*') or (substr($numFinal, -1) ==
'?')) {
206 switch ($literaltype) {
208 if (strlen($numFinal) == 13) {
209 $ean = substr($numFinal, 0, 12);
241 public function verif($db, &$code, $product, $thirdparty_type, $type)
243 if (!$product instanceof
Product) {
244 dol_syslog(get_class($this).
"::verif called with ".get_class($product).
" Expected Product", LOG_ERR);
250 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
253 $code = strtoupper(trim($code));
255 if (empty($code) && $this->code_null && !
getDolGlobalString(
'BARCODE_STANDARD_PRODUCT_MASK')) {
257 } elseif (empty($code) && (!$this->code_null ||
getDolGlobalString(
'BARCODE_STANDARD_PRODUCT_MASK'))) {
261 $is_dispo = $this->
verif_dispo($db, $code, $product);
262 if ($is_dispo != 0) {
276 dol_syslog(get_class($this).
"::verif type=".$thirdparty_type.
" result=".$result);
293 $sql =
"SELECT barcode FROM ".MAIN_DB_PREFIX.
"product";
294 $sql .=
" WHERE barcode = '".$db->escape($code).
"'";
295 $sql .=
" AND entity IN (".getEntity(
'product').
")";
297 if ($product->id > 0) {
298 $sql .=
" AND rowid <> ".$product->id;
301 $resql = $db->query($sql);
303 if ($db->num_rows($resql) == 0) {
329 $mask = !
getDolGlobalString(
'BARCODE_STANDARD_PRODUCT_MASK') ?
'' : $conf->global->BARCODE_STANDARD_PRODUCT_MASK;
331 $this->error =
'NotConfigured';
335 dol_syslog(get_class($this).
'::verif_syntax codefortest='.$codefortest.
" typefortest=".$typefortest);
337 $newcodefortest = $codefortest;
340 if (in_array($typefortest, array(
'EAN13',
'ISBN'))) {
341 if (preg_match(
'/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $mask, $reg)) {
342 if (strlen($reg[1]) == 12) {
343 $newcodefortest = substr($newcodefortest, 0, 12);
345 dol_syslog(get_class($this).
'::verif_syntax newcodefortest='.$newcodefortest);
350 if (is_string($result)) {
351 $this->error = $result;
barcode_gen_ean_sum($ean)
Calculate EAN sum.
Class to manage products or services.
Class to manage translations.
Class to manage barcode with standard rule.
getNextValue($objproduct=null, $type='')
Return next value.
verif_dispo($db, $code, $product)
Return if a code is used (by other element)
__construct()
Constructor.
verif($db, &$code, $product, $thirdparty_type, $type)
Check validity of code according to its rules.
literalBarcodeType($db, $type=0)
Return literal barcode type code from numerical rowid type of barcode.
verif_syntax($codefortest, $typefortest)
Return if a barcode value match syntax.
getExample($langs=null, $objproduct=null)
Return an example of result returned by getNextValue.
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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.