31require_once DOL_DOCUMENT_ROOT.
'/core/modules/barcode/modules_barcode.class.php';
39 public $name =
'Standard';
44 public $code_modifiable;
49 public $code_modifiable_invalide;
54 public $code_modifiable_null;
65 public $version =
'dolibarr';
77 public $numbitcounter;
82 public $prefixIsRequired;
91 $this->code_modifiable = 1;
92 $this->code_modifiable_invalide = 1;
93 $this->code_modifiable_null = 1;
95 $this->prefixIsRequired = 0;
110 $langs->load(
"thirdparties");
112 $disabled = ((!empty($mc->sharings[
'referent']) && $mc->sharings[
'referent'] !=
$conf->entity) ?
' disabled' :
'');
114 $texte = $langs->trans(
'GenericNumRefModelDesc').
"<br>\n";
115 $texte .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
116 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
117 $texte .=
'<input type="hidden" name="page_y" value="">';
118 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
119 $texte .=
'<input type="hidden" name="param1" value="BARCODE_STANDARD_THIRDPARTY_MASK">';
120 $texte .=
'<table class="nobordernopadding" width="100%">';
122 $tooltip = $langs->trans(
"GenericMaskCodes", $langs->transnoentities(
"BarCode"), $langs->transnoentities(
"BarCode"));
123 $tooltip .= $langs->trans(
"GenericMaskCodes3EAN");
124 $tooltip .=
'<strong>'.$langs->trans(
"Example").
':</strong><br>';
125 $tooltip .=
'04{0000000000}? (for internal use)<br>';
126 $tooltip .=
'9771234{00000}? (example of ISSN code with prefix 1234)<br>';
127 $tooltip .=
'9791234{00000}? (example of ISMN code with prefix 1234)<br>';
133 $texte .=
'<tr><td>'.$langs->trans(
"Mask").
':</td>';
134 $texte .=
'<td class="right">'.$form->textwithpicto(
'<input type="text" class="flat minwidth175" name="value1" value="'.(
getDolGlobalString(
'BARCODE_STANDARD_THIRDPARTY_MASK') ?
$conf->global->BARCODE_STANDARD_THIRDPARTY_MASK :
'').
'"'.$disabled.
'>', $tooltip, 1, 1).
'</td>';
135 $texte .=
'<td class="left" rowspan="2"> <input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.$langs->trans(
"Modify").
'"'.$disabled.
'></td>';
138 $texte .=
'</table>';
152 public function getExample($langs =
null, $objthirdparty =
null)
155 $langs = $GLOBALS[
'langs'];
156 '@phan-var-force Translate $langs';
158 $examplebarcode = $this->
getNextValue($objthirdparty,
'');
159 if (!$examplebarcode) {
160 $examplebarcode = $langs->trans(
'NotConfigured');
162 if ($examplebarcode ==
"ErrorBadMask") {
163 $langs->load(
"errors");
164 $examplebarcode = $langs->trans($examplebarcode);
167 return $examplebarcode;
181 $sql =
"SELECT rowid, code, libelle as label";
182 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_barcode_type";
183 $sql .=
" WHERE rowid = ". (int) $type;
184 $sql .=
" AND entity = ".((int)
$conf->entity);
185 $result = $db->query($sql);
187 $num = $db->num_rows($result);
190 $obj = $db->fetch_object($result);
210 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
211 require_once DOL_DOCUMENT_ROOT.
'/core/lib/barcode.lib.php';
222 $this->error =
'NotConfigured';
231 $numFinal =
get_next_value($db, $mask,
'societe', $field, $where,
'', $now);
233 if ((substr($numFinal, -1) ==
'*') or (substr($numFinal, -1) ==
'?')) {
236 switch ($literaltype) {
238 if (strlen($numFinal) == 13) {
239 $ean = substr($numFinal, 0, 12);
271 public function verif($db, &$code, $thirdparty, $thirdparty_type, $type)
273 if (!$thirdparty instanceof
Societe) {
274 dol_syslog(get_class($this).
"::verif called with ".get_class($thirdparty).
" Expected Societe", LOG_ERR);
277 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
280 $code = strtoupper(trim($code));
282 if (empty($code) && $this->code_null && !
getDolGlobalString(
'BARCODE_STANDARD_THIRDPARTY_MASK')) {
284 } elseif (empty($code) && (!$this->code_null ||
getDolGlobalString(
'BARCODE_STANDARD_THIRDPARTY_MASK'))) {
288 $is_dispo = $this->
verif_dispo($db, $code, $thirdparty);
289 if ($is_dispo != 0) {
303 dol_syslog(get_class($this).
"::verif type=".$thirdparty_type.
" result=".$result);
321 $sql =
"SELECT barcode FROM ".MAIN_DB_PREFIX.
"societe";
322 $sql .=
" WHERE barcode = '".$db->escape($code).
"'";
323 if ($thirdparty->id > 0) {
324 $sql .=
" AND rowid <> ".$thirdparty->id;
327 $resql = $db->query($sql);
329 if ($db->num_rows($resql) == 0) {
355 $mask = !
getDolGlobalString(
'BARCODE_STANDARD_THIRDPARTY_MASK') ?
'' :
$conf->global->BARCODE_STANDARD_THIRDPARTY_MASK;
357 $this->error =
'NotConfigured';
361 dol_syslog(get_class($this).
'::verif_syntax codefortest='.$codefortest.
" typefortest=".$typefortest);
363 $newcodefortest = $codefortest;
366 if (in_array($typefortest, array(
'EAN13',
'ISBN'))) {
367 if (preg_match(
'/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $mask, $reg)) {
368 if (strlen($reg[1]) == 12) {
369 $newcodefortest = substr($newcodefortest, 0, 12);
371 dol_syslog(get_class($this).
'::verif_syntax newcodefortest='.$newcodefortest);
376 if (is_string($result)) {
377 $this->error = $result;
barcode_gen_ean_sum($ean)
Calculate EAN sum.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage barcode with standard rule.
verif($db, &$code, $thirdparty, $thirdparty_type, $type)
Check validity of code according to its rules.
getNextValue($objthirdparty=null, $type='')
Return next value.
verif_syntax($codefortest, $typefortest)
Return if a barcode value match syntax.
getExample($langs=null, $objthirdparty=null)
Return an example of result returned by getNextValue.
verif_dispo($db, $code, $thirdparty)
Return if a code is used (by other element)
info($langs)
Return description of module.
__construct()
Constructor.
literalBarcodeType($db, $type=0)
Return literal barcode type code from numerical rowid type of barcode.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...