forked from Dolibarr/dolibarr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
12 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
* Copyright (C) 2007-2012 Regis Houssin <[email protected]> | ||
* Copyright (C) 2011 Juanjo Menent <[email protected]> | ||
* Copyright (C) 2024 Frédéric France <[email protected]> | ||
* Copyright (C) 2024 MDW <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -157,14 +158,19 @@ public function literalBarcodeType($db, $type = 0) | |
/** | ||
* Return next value | ||
* | ||
* @param Product $objproduct Object product | ||
* @param string $type Type of barcode (EAN, ISBN, ...) | ||
* @param CommonObject $objproduct Object product | ||
* @param string $type Type of barcode (EAN, ISBN, ...) | ||
* @return string Value if OK, '' if module not configured, <0 if KO | ||
*/ | ||
public function getNextValue($objproduct, $type = '') | ||
{ | ||
global $db, $conf; | ||
|
||
if (!$objproduct instanceof Product) { | ||
dol_syslog(get_class($this)."::getNextValue used on incompatible".get_class($objproduct), LOG_ERR); | ||
return -1; | ||
} | ||
|
||
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) | ||
|
||
|
@@ -192,19 +198,19 @@ public function getNextValue($objproduct, $type = '') | |
|
||
$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...) | ||
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 | ||
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); | ||
$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 | ||
// Other barcode cases with key could be written here | ||
default: | ||
break; | ||
} | ||
|