Merge pull request #15918 from zuiko/patch-1
Fix #15633: Product creation: EAN13 barcode automatic generation incompatible with EAN13 existing barcode scanning, unusable function.
This commit is contained in:
commit
8e5b971c49
@ -99,9 +99,9 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode
|
||||
$tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("BarCode"), $langs->transnoentities("BarCode"));
|
||||
$tooltip .= $langs->trans("GenericMaskCodes3");
|
||||
$tooltip .= '<strong>'.$langs->trans("Example").':</strong><br>';
|
||||
$tooltip .= '020{000000000} (for internal use)<br>';
|
||||
$tooltip .= '9771234{00000} (example of ISSN code with prefix 1234)<br>';
|
||||
$tooltip .= '9791234{00000} (example of ISMN code with prefix 1234)<br>';
|
||||
$tooltip .= '020{000000000}? (for internal use)<br>';
|
||||
$tooltip .= '9771234{00000}? (example of ISSN code with prefix 1234)<br>';
|
||||
$tooltip .= '9791234{00000}? (example of ISMN code with prefix 1234)<br>';
|
||||
//$tooltip.=$langs->trans("GenericMaskCodes5");
|
||||
|
||||
// Mask parameter
|
||||
@ -140,7 +140,37 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode
|
||||
|
||||
return $examplebarcode;
|
||||
}
|
||||
/**
|
||||
* Return literal barcode type code from numerical rowid type of barcode
|
||||
*
|
||||
* @param Database $db Database
|
||||
* @param int $type Type of barcode (EAN, ISBN, ...) as rowid
|
||||
* @return string
|
||||
*/
|
||||
public function literalBarcodeType($db, $type = '')
|
||||
{
|
||||
global $conf;
|
||||
$out = '';
|
||||
|
||||
$sql = "SELECT rowid, code, libelle as label";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
|
||||
$sql .= " WHERE rowid = '".$db->escape($type)."'";
|
||||
$sql .= " AND entity = ".((int) $conf->entity);
|
||||
$result = $db->query($sql);
|
||||
if ($result) {
|
||||
$num = $db->num_rows($result);
|
||||
|
||||
if ($num > 0) {
|
||||
$obj = $db->fetch_object($result);
|
||||
$out .= $obj->label; //take the label corresponding to the type rowid in the database
|
||||
}
|
||||
}
|
||||
else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
/**
|
||||
* Return next value
|
||||
*
|
||||
@ -153,6 +183,11 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode
|
||||
global $db, $conf;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // to be able to call function barcode_gen_ean_sum($ean)
|
||||
|
||||
if (empty($type)) {
|
||||
$type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
|
||||
} //get barcode type configuration for products if $type not set
|
||||
|
||||
// TODO
|
||||
|
||||
@ -171,7 +206,28 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode
|
||||
$now = dol_now();
|
||||
|
||||
$numFinal = get_next_value($db, $mask, 'product', $field, $where, '', $now);
|
||||
|
||||
//Begin barcode with key: for barcode with key (EAN13...) calculate and substitute the last character (* or ?) used in the mask by the key
|
||||
if ((substr($numFinal, -1)=='*') or (substr($numFinal, -1)=='?')) // if last mask character is * or ? a joker, probably we have to calculate a key as last character (EAN13...)
|
||||
{
|
||||
$literaltype = '';
|
||||
$literaltype = $this->literalBarcodeType($db, $type);//get literal_Barcode_Type
|
||||
switch ($literaltype)
|
||||
{
|
||||
case 'EAN13': //EAN13 rowid = 2
|
||||
if (strlen($numFinal)==13)// be sure that the mask length is correct for EAN13
|
||||
{
|
||||
$ean = substr($numFinal, 0, 12); //take first 12 digits
|
||||
$eansum = barcode_gen_ean_sum($ean);
|
||||
$ean .= $eansum; //substitute the las character by the key
|
||||
$numFinal = $ean;
|
||||
}
|
||||
break;
|
||||
// Other barcode cases with key could be written here
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
//End barcode with key
|
||||
return $numFinal;
|
||||
}
|
||||
|
||||
|
||||
@ -349,7 +349,7 @@ UpdateServerOffline=Update server offline
|
||||
WithCounter=Manage a counter
|
||||
GenericMaskCodes=You may enter any numbering mask. In this mask, the following tags could be used:<br><b>{000000}</b> corresponds to a number which will be incremented on each %s. Enter as many zeros as the desired length of the counter. The counter will be completed by zeros from the left in order to have as many zeros as the mask. <br><b>{000000+000}</b> same as previous but an offset corresponding to the number to the right of the + sign is applied starting on first %s. <br><b>{000000@x}</b> same as previous but the counter is reset to zero when month x is reached (x between 1 and 12, or 0 to use the early months of fiscal year defined in your configuration, or 99 to reset to zero every month). If this option is used and x is 2 or higher, then sequence {yy}{mm} or {yyyy}{mm} is also required. <br><b>{dd}</b> day (01 to 31).<br><b>{mm}</b> month (01 to 12).<br><b>{yy}</b>, <b>{yyyy}</b> or <b>{y}</b> year over 2, 4 or 1 numbers. <br>
|
||||
GenericMaskCodes2=<b>{cccc}</b> the client code on n characters<br><b>{cccc000}</b> the client code on n characters is followed by a counter dedicated for customer. This counter dedicated to customer is reset at same time than global counter.<br><b>{tttt}</b> The code of third party type on n characters (see menu Home - Setup - Dictionary - Types of third parties). If you add this tag, the counter will be different for each type of third party.<br>
|
||||
GenericMaskCodes3=All other characters in the mask will remain intact.<br>Spaces are not allowed.<br>
|
||||
GenericMaskCodes3=All other characters in the mask will remain intact (except * or ? in 13th position in EAN13).<br>Spaces are not allowed.<br>In EAN13 the last character after the last } in 13th position<br> should be * or ? it will be replaced by the calculated key.<br>
|
||||
GenericMaskCodes4a=<u>Example on the 99th %s of the third party TheCompany, with date 2007-01-31:</u><br>
|
||||
GenericMaskCodes4b=<u>Example on third party created on 2007-03-01:</u><br>
|
||||
GenericMaskCodes4c=<u>Example on product created on 2007-03-01:</u><br>
|
||||
|
||||
@ -349,7 +349,7 @@ UpdateServerOffline=Serveur de mise à jour hors ligne
|
||||
WithCounter=Gérer un compteur
|
||||
GenericMaskCodes=Vous pouvez saisir tout masque de numérotation. Dans ce masque, les balises suivantes peuvent être utilisées:<br><b>{000000}</b> correspond à un numéro qui sera incrémenté à chaque %s. Mettre autant de zéro que la longueur désirée du compteur. Le compteur sera complété par des 0 à gauche afin d'avoir autant de zéro que dans le masque.<br><b>{000000+000}</b> idem que précédemment mais un décalage correspondant au nombre à droite du + est appliqué dès la première %s.<br><b>{000000@x}</b> idem que précédemment mais le compteur est remis à zéro le xème mois de l'année (x entre 1 et 12, ou 0 pour utiliser le mois de début d'exercice fiscal défini dans votre configuration, ou 99 pour remise à zéro chaque mois). Si cette option est utilisée et x vaut 2 ou plus, alors la séquence {yy}{mm} ou {yyyy}{mm} est obligatoire. <br><b>{dd}</b> jour (01 à 31).<br><b>{mm}</b> mois (01 à 12).<br><b>{yy}</b>, <b>{yyyy}</b> ou <b>{y}</b> année sur 2, 4 ou 1 chiffres.<br>
|
||||
GenericMaskCodes2=<b>{cccc}</b> : code client sur n caractères<br><b>{cccc000}</b> : code client sur n caractères suivi d'un compteur propre au client. Ce compteur propre au client est remis à zéro en même temps que le compteur général.<br><b>{tttt}</b> code du type de tiers sur n caractères (Voir menu Accueil > Configuration > Dictionnaires > Types de tiers). Si vous ajoutez cet élément au masque de numérotation, le compteur sera différent pour chaque type de tiers.<br>
|
||||
GenericMaskCodes3=Tout autre caractère dans le masque sera laissé inchangé.<br>Les espaces ne sont pas permis.<br>
|
||||
GenericMaskCodes3=Tout autre caractère dans le masque sera laissé inchangé (sauf * ou ? en 13ème position en EAN13).<br>Les espaces ne sont pas permis.<br>En EAN13 le dernier caractère après la dernière } se plaçant en 13ème position<br>devra être * ou ? il sera remplacé par la clé calculée.<br>
|
||||
GenericMaskCodes4a=<u>Exemple sur la 99eme %s du tiers LaCompanie faite le 31/01/2007:</u><br>
|
||||
GenericMaskCodes4b=<u>Exemple sur un tiers créé le 31/03/2007 :</u><br>
|
||||
GenericMaskCodes4c=<u>Exemple sur un produit/service créé le 31/03/2007 :</u><br>
|
||||
|
||||
@ -1052,7 +1052,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
|
||||
if ($conf->browser->layout == 'phone') print '</tr><tr>';
|
||||
print '<td>'.$langs->trans("BarcodeValue").'</td><td>';
|
||||
$tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode;
|
||||
if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $type);
|
||||
if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type);
|
||||
print '<input class="maxwidth100" type="text" name="barcode" value="'.dol_escape_htmltag($tmpcode).'">';
|
||||
print '</td></tr>';
|
||||
}
|
||||
@ -1512,7 +1512,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
|
||||
print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
|
||||
print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>';
|
||||
$tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode;
|
||||
if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $type);
|
||||
if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type);
|
||||
print '<input size="40" class="maxwidthonsmartphone" type="text" name="barcode" value="'.dol_escape_htmltag($tmpcode).'">';
|
||||
print '</td></tr>';
|
||||
}
|
||||
@ -1837,11 +1837,15 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
|
||||
$formbarcode = new FormBarCode($db);
|
||||
}
|
||||
|
||||
$fk_barcode_type='';
|
||||
if ($action == 'editbarcodetype')
|
||||
{
|
||||
print $formbarcode->formBarcodeType($_SERVER['PHP_SELF'].'?id='.$object->id, $object->barcode_type, 'fk_barcode_type');
|
||||
$fk_barcode_type = $object->barcode_type;
|
||||
} else {
|
||||
$object->fetch_barcode();
|
||||
$fk_barcode_type = $object->barcode_type;
|
||||
print $object->barcode_type_label ? $object->barcode_type_label : ($object->barcode ? '<div class="warning">'.$langs->trans("SetDefaultBarcodeType").'<div>' : '');
|
||||
}
|
||||
print '</td></tr>'."\n";
|
||||
@ -1857,7 +1861,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
|
||||
if ($action == 'editbarcode')
|
||||
{
|
||||
$tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode;
|
||||
if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $type);
|
||||
if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type);
|
||||
|
||||
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user