diff --git a/htdocs/barcode/codeinit.php b/htdocs/barcode/codeinit.php
index b4e365fe018..65ca10a8794 100644
--- a/htdocs/barcode/codeinit.php
+++ b/htdocs/barcode/codeinit.php
@@ -35,7 +35,8 @@ $month = dol_print_date($now, '%m');
$day = dol_print_date($now, '%d');
$forbarcode = GETPOST('forbarcode');
$fk_barcode_type = GETPOST('fk_barcode_type');
-$eraseallbarcode = GETPOST('eraseallbarcode');
+$eraseallproductbarcode = GETPOST('eraseallproductbarcode');
+$eraseallthirdpartybarcode = GETPOST('eraseallthirdpartybarcode');
$action = GETPOST('action', 'aZ09');
@@ -43,6 +44,7 @@ $producttmp = new Product($db);
$thirdpartytmp = new Societe($db);
$modBarCodeProduct = '';
+$modBarCodeThirdparty = '';
$maxperinit = 1000;
@@ -51,6 +53,106 @@ $maxperinit = 1000;
* Actions
*/
+// Define barcode template for third-party
+if (!empty($conf->global->BARCODE_THIRDPARTY_ADDON_NUM)) {
+ $dirbarcodenum = array_merge(array('/core/modules/barcode/'), $conf->modules_parts['barcode']);
+
+ foreach ($dirbarcodenum as $dirroot) {
+ $dir = dol_buildpath($dirroot, 0);
+
+ $handle = @opendir($dir);
+ if (is_resource($handle)) {
+ while (($file = readdir($handle)) !== false) {
+ if (preg_match('/^mod_barcode_thirdparty_.*php$/', $file)) {
+ $file = substr($file, 0, dol_strlen($file) - 4);
+
+ try {
+ dol_include_once($dirroot.$file.'.php');
+ } catch (Exception $e) {
+ dol_syslog($e->getMessage(), LOG_ERR);
+ }
+
+ $modBarCodeThirdparty = new $file();
+ break;
+ }
+ }
+ closedir($handle);
+ }
+ }
+}
+
+if ($action == 'initbarcodethirdparties') {
+ if (!is_object($modBarCodeThirdparty)) {
+ $error++;
+ setEventMessages($langs->trans("NoBarcodeNumberingTemplateDefined"), null, 'errors');
+ }
+
+ if (!$error) {
+ $thirdpartystatic = new Societe($db);
+
+ $db->begin();
+
+ $nbok = 0;
+ if (!empty($eraseallthirdpartybarcode)) {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."societe";
+ $sql .= " SET barcode = NULL";
+ $resql = $db->query($sql);
+ if ($resql) {
+ setEventMessages($langs->trans("AllBarcodeReset"), null, 'mesgs');
+ } else {
+ $error++;
+ dol_print_error($db);
+ }
+ } else {
+ $sql = "SELECT rowid";
+ $sql .= " FROM ".MAIN_DB_PREFIX."societe";
+ $sql .= " WHERE barcode IS NULL or barcode = ''";
+ $sql .= $db->order("datec", "ASC");
+ $sql .= $db->plimit($maxperinit);
+
+ dol_syslog("codeinit", LOG_DEBUG);
+ $resql = $db->query($sql);
+ if ($resql) {
+ $num = $db->num_rows($resql);
+
+ $i = 0; $nbok = $nbtry = 0;
+ while ($i < min($num, $maxperinit)) {
+ $obj = $db->fetch_object($resql);
+ if ($obj) {
+ $thirdpartystatic->id = $obj->rowid;
+ $nextvalue = $modBarCodeThirdparty->getNextValue($thirdpartystatic, '');
+
+ $result = $thirdpartystatic->setValueFrom('barcode', $nextvalue, '', '', 'text', '', $user, 'THIRDPARTY_MODIFY');
+
+ $nbtry++;
+ if ($result > 0) {
+ $nbok++;
+ }
+ }
+
+ $i++;
+ }
+ } else {
+ $error++;
+ dol_print_error($db);
+ }
+
+ if (!$error) {
+ setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
+ }
+ }
+
+ if (!$error) {
+ //$db->rollback();
+ $db->commit();
+ } else {
+ $db->rollback();
+ }
+ }
+
+ $action = '';
+}
+
// Define barcode template for products
if (!empty($conf->global->BARCODE_PRODUCT_ADDON_NUM)) {
$dirbarcodenum = array_merge(array('/core/modules/barcode/'), $conf->modules_parts['barcode']);
@@ -91,7 +193,7 @@ if ($action == 'initbarcodeproducts') {
$db->begin();
$nbok = 0;
- if (!empty($eraseallbarcode)) {
+ if (!empty($eraseallproductbarcode)) {
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
$sql .= " SET barcode = NULL";
$resql = $db->query($sql);
@@ -155,7 +257,6 @@ if ($action == 'initbarcodeproducts') {
}
-
/*
* View
*/
@@ -189,7 +290,11 @@ print '
';
// For thirdparty
if (isModEnabled('societe')) {
- $nbno = $nbtotal = 0;
+ print '