diff --git a/htdocs/barcode/codeinit.php b/htdocs/barcode/codeinit.php
index a5db78f368f..22bcf77267a 100644
--- a/htdocs/barcode/codeinit.php
+++ b/htdocs/barcode/codeinit.php
@@ -35,7 +35,7 @@ $month=dol_print_date($now,'%m');
$day=dol_print_date($now,'%d');
$forbarcode=GETPOST('forbarcode');
$fk_barcode_type=GETPOST('fk_barcode_type');
-$submitformbarcodeproductgenall=GETPOST('submitformbarcodeproductgenall');
+$eraseallbarcode=GETPOST('eraseallbarcode');
$mesg='';
@@ -46,6 +46,8 @@ $thirdpartytmp=new Societe($db);
$modBarCodeProduct='';
+$maxperinit=1000;
+
/*
* Actions
@@ -100,54 +102,71 @@ if ($action == 'initbarcodeproducts')
$db->begin();
- if (! empty($submitformbarcodeproductgenall))
+ $nbok=0;
+ if (! empty($eraseallbarcode))
{
$sql ="UPDATE ".MAIN_DB_PREFIX."product";
$sql.=" SET barcode = NULL";
$resql=$db->query($sql);
- if (! $resql) dol_print_error($db);
- }
-
- $sql ="SELECT rowid, ref, fk_product_type";
- $sql.=" FROM ".MAIN_DB_PREFIX."product";
- $sql.=" WHERE barcode IS NULL or barcode = ''";
- $sql.=" ORDER BY datec ASC";
- $resql=$db->query($sql);
- if ($resql)
- {
- $num=$db->num_rows($resql);
-
- $i=0; $nbok=$nbtry=0;
- while ($i < $num)
+ if ($resql)
{
- $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++;
+ setEventMessage($langs->trans("AllBarcodeReset"),'mesgs');
+ }
+ else
+ {
+ $error++;
+ dol_print_error($db);
}
}
else
{
- $error++;
- dol_print_error($db);
+ $sql ="SELECT rowid, ref, fk_product_type";
+ $sql.=" FROM ".MAIN_DB_PREFIX."product";
+ $sql.=" WHERE barcode IS NULL or barcode = ''";
+ $sql.=$db->order("datec","ASC");
+ $sql.=$db->plimit($maxperinit);
+
+ dol_syslog("codeinit sql=".$sql, 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)
+ {
+ $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');
+ }
}
if (! $error)
{
- setEventMessage($langs->trans("RecordsModified",$nbok),'mesgs');
-
//$db->rollback();
$db->commit();
}
@@ -229,7 +248,7 @@ if ($conf->product->enabled || $conf->product->service)
$nbno=$nbtotal=0;
print_fiche_titre($langs->trans("BarcodeInitForProductsOrServices"),'','').' '."\n";
- $sql="SELECT count(rowid) as nb, fk_product_type";
+ $sql ="SELECT count(rowid) as nb, fk_product_type";
$sql.=" FROM ".MAIN_DB_PREFIX."product";
$sql.=" WHERE barcode IS NULL OR barcode = ''";
$sql.=" GROUP BY fk_product_type";
@@ -284,9 +303,10 @@ if ($conf->product->enabled || $conf->product->service)
print ' ';
//print ' '.$langs->trans("ResetBarcodeForAllRecords").' ';
$moretags1=(($disabled||$disabled1)?' disabled="disabled" title="'.dol_escape_htmltag($titleno).'"':'');
- print '';
- $moretags2=(($disabled || ! $nbtotal)?' disabled="disabled"':'');
- print '';
+ print '';
+ $moretags2=(($nbno == $nbtotal)?' disabled="disabled"':'');
+ print ' ';
+ print '';
print '
';
}
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index e00d5664a5b..7f891bc4195 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -382,8 +382,9 @@ ExternalModule=External module - Installed into directory %s
BarcodeInitForThirdparties=Mass barcode init for thirdparties
BarcodeInitForProductsOrServices=Mass barcode init for products or services
CurrentlyNWithoutBarCode=Currently, you have %s records on %s %s without barcode defined.
-InitEmptyBarCode=Init value for the %s empty barcode
-EraseAndResetBarCode=Erase and reset barcode for all the %s records
+InitEmptyBarCode=Init value for next %s empty records
+EraseAllCurrentBarCode=Erase all current barcode values
+AllBarcodeReset=All barcode values have been removed
NoBarcodeNumberingTemplateDefined=No numbering barcode template enabled into barcode module setup.
NoRecordWithoutBarcodeDefined=No record with no barcode value defined.