diff --git a/ChangeLog b/ChangeLog
index b995520482e..654817fb168 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,11 +16,12 @@ For users:
to automatically add timestamp and user line into editionf field when editing a note.
- New: Add button cancel into edition of notes.
- New: Improved Opensurvey module and added options to disable comments and disable
- public votes
+ public votes.
- New: The box "balance of bank accounts" show all opened accounts.
- New: Add option MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE.
- New: Add warning if supplier payment is higher that due amount.
-- New increase length of url into bookmark module.
+- New: Increase length of url into bookmark module.
+- New: Add an admin page to make a mass init of barcode values for all products.
TODO
- New: Predefined product and free product use same form.
diff --git a/htdocs/barcode/codeinit.php b/htdocs/barcode/codeinit.php
index f016423f44b..bae8d90e589 100644
--- a/htdocs/barcode/codeinit.php
+++ b/htdocs/barcode/codeinit.php
@@ -46,16 +46,109 @@ $action=GETPOST('action');
$producttmp=new Product($db);
$thirdpartytmp=new Societe($db);
+$modBarCodeProduct='';
+
/*
* Actions
*/
-if ($action == 'init')
+// Define barcode template for products
+if (! empty($conf->global->BARCODE_PRODUCT_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_product_.*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);
+ }
+
+ $modBarCodeProduct = new $file();
+ break;
+ }
+ }
+ closedir($handle);
+ }
+ }
+}
+
+if ($action == 'initbarcodeproducts')
+{
+ if (! is_object($modBarCodeProduct))
+ {
+ $error++;
+ setEventMessage($langs->trans("NoBarcodeNumberingTemplateDefined"),'errors');
+ }
+
+ if (! $error)
+ {
+ $productstatic=new Product($db);
+
+ $db->begin();
+
+ $sql="SELECT rowid, ref, fk_product_type FROM ".MAIN_DB_PREFIX."product where barcode IS NULL or barcode = ''";
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $num=$db->num_rows($resql);
+
+ $i=0; $nbok=$nbtry=0;
+ while ($i < $num)
+ {
+ $obj=$db->fetch_object($resql);
+ if ($obj)
+ {
+ $productstatic->id=$obj->rowid;
+ $productstatic->ref=$obj->ref;
+ $productstatic->type=$obj->fk_product_type;
+ $nextvalue=$modBarCodeProduct->getNextValue($productstatic,'');
+
+ print 'Set value '.$nextvalue.' to product '.$productstatic->id." ".$productstatic->ref." ".$productstatic->type."
\n";
+ $result=$productstatic->setValueFrom('barcode', $nextvalue);
+
+ $nbtry++;
+ if ($result > 0) $nbok++;
+ }
+
+ $i++;
+ }
+ }
+ else
+ {
+ $error++;
+ dol_print_error($db);
+ }
+
+ if (! $error)
+ {
+ setEventMessage($langs->trans("RecordsModified",$nbok),'mesgs');
+
+ //$db->rollback();
+ $db->commit();
+ }
+ else
+ {
+ $db->rollback();
+ }
+ }
+
$action='';
-
-
}
@@ -64,6 +157,9 @@ if ($action == 'init')
* View
*/
+if (!$user->admin) accessforbidden();
+if (empty($conf->barcode->enabled)) accessforbidden();
+
$form=new Form($db);
llxHeader('',$langs->trans("MassBarcodeInit"));
@@ -81,9 +177,101 @@ dol_htmloutput_errors($mesg);
print '