26 require
'../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
31 $langs->loadLangs(array(
'admin',
'members',
'errors',
'other'));
38 $forbarcode =
GETPOST(
'forbarcode');
39 $fk_barcode_type =
GETPOST(
'fk_barcode_type');
40 $eraseallproductbarcode =
GETPOST(
'eraseallproductbarcode');
41 $eraseallthirdpartybarcode =
GETPOST(
'eraseallthirdpartybarcode');
43 $action =
GETPOST(
'action',
'aZ09');
46 $thirdpartytmp =
new Societe($db);
48 $modBarCodeProduct =
'';
49 $modBarCodeThirdparty =
'';
51 $maxperinit = empty($conf->global->BARCODE_INIT_MAX) ? 1000 : $conf->global->BARCODE_INIT_MAX;
60 if (empty($user->admin)) {
70 if (!empty($conf->global->BARCODE_THIRDPARTY_ADDON_NUM)) {
71 $dirbarcodenum = array_merge(array(
'/core/modules/barcode/'), $conf->modules_parts[
'barcode']);
73 foreach ($dirbarcodenum as $dirroot) {
76 $handle = @opendir($dir);
77 if (is_resource($handle)) {
78 while (($file = readdir($handle)) !==
false) {
79 if (preg_match(
'/^mod_barcode_thirdparty_.*php$/', $file)) {
80 $file = substr($file, 0,
dol_strlen($file) - 4);
88 $modBarCodeThirdparty =
new $file();
97 if ($action ==
'initbarcodethirdparties') {
98 if (!is_object($modBarCodeThirdparty)) {
100 setEventMessages($langs->trans(
"NoBarcodeNumberingTemplateDefined"),
null,
'errors');
104 $thirdpartystatic =
new Societe($db);
109 if (!empty($eraseallthirdpartybarcode)) {
110 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
111 $sql .=
" SET barcode = NULL";
112 $resql = $db->query(
$sql);
120 $sql =
"SELECT rowid";
121 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe";
122 $sql .=
" WHERE barcode IS NULL or barcode = ''";
123 $sql .= $db->order(
"datec",
"ASC");
124 $sql .= $db->plimit($maxperinit);
127 $resql = $db->query(
$sql);
129 $num = $db->num_rows($resql);
131 $i = 0; $nbok = $nbtry = 0;
132 while ($i < min($num, $maxperinit)) {
133 $obj = $db->fetch_object($resql);
135 $thirdpartystatic->id = $obj->rowid;
136 $nextvalue = $modBarCodeThirdparty->getNextValue($thirdpartystatic,
'');
138 $result = $thirdpartystatic->setValueFrom(
'barcode', $nextvalue,
'',
'',
'text',
'', $user,
'THIRDPARTY_MODIFY');
170 if (!empty($conf->global->BARCODE_PRODUCT_ADDON_NUM)) {
171 $dirbarcodenum = array_merge(array(
'/core/modules/barcode/'), $conf->modules_parts[
'barcode']);
173 foreach ($dirbarcodenum as $dirroot) {
176 $handle = @opendir($dir);
177 if (is_resource($handle)) {
178 while (($file = readdir($handle)) !==
false) {
179 if (preg_match(
'/^mod_barcode_product_.*php$/', $file)) {
180 $file = substr($file, 0,
dol_strlen($file) - 4);
182 if ($file == $conf->global->BARCODE_PRODUCT_ADDON_NUM) {
189 $modBarCodeProduct =
new $file();
199 if ($action ==
'initbarcodeproducts') {
200 if (!is_object($modBarCodeProduct)) {
202 setEventMessages($langs->trans(
"NoBarcodeNumberingTemplateDefined"),
null,
'errors');
206 $productstatic =
new Product($db);
211 if (!empty($eraseallproductbarcode)) {
212 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product";
213 $sql .=
" SET barcode = NULL";
214 $resql = $db->query(
$sql);
222 $sql =
"SELECT rowid, ref, fk_product_type";
223 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
224 $sql .=
" WHERE barcode IS NULL or barcode = ''";
225 $sql .= $db->order(
"datec",
"ASC");
226 $sql .= $db->plimit($maxperinit);
229 $resql = $db->query(
$sql);
231 $num = $db->num_rows($resql);
233 $i = 0; $nbok = $nbtry = 0;
234 while ($i < min($num, $maxperinit)) {
235 $obj = $db->fetch_object($resql);
237 $productstatic->id = $obj->rowid;
238 $productstatic->ref = $obj->ref;
239 $productstatic->type = $obj->fk_product_type;
240 $nextvalue = $modBarCodeProduct->getNextValue($productstatic,
'');
243 $result = $productstatic->setValueFrom(
'barcode', $nextvalue,
'',
'',
'text',
'', $user,
'PRODUCT_MODIFY');
281 llxHeader(
'', $langs->trans(
"MassBarcodeInit"));
283 print
load_fiche_titre($langs->trans(
"MassBarcodeInit"),
'',
'title_setup.png');
286 print
'<span class="opacitymedium">'.$langs->trans(
"MassBarcodeInitDesc").
'</span><br>';
297 print
'<script type="text/javascript">
298 function confirm_erase() {
299 return confirm("'.dol_escape_js($langs->trans(
"ConfirmEraseAllCurrentBarCode")).
'");
306 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
307 print
'<input type="hidden" name="mode" value="label">';
308 print
'<input type="hidden" name="action" value="initbarcodethirdparties">';
309 print
'<input type="hidden" name="token" value="'.newToken().
'">';
310 $nbthirdpartyno = $nbthirdpartytotal = 0;
312 print
load_fiche_titre($langs->trans(
"BarcodeInitForThirdparties"),
'',
'company');
315 $sql =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"societe where barcode IS NULL or barcode = ''";
316 $resql = $db->query(
$sql);
318 $obj = $db->fetch_object($resql);
319 $nbthirdpartyno = $obj->nb;
324 $sql =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"societe";
325 $resql = $db->query(
$sql);
327 $obj = $db->fetch_object($resql);
328 $nbthirdpartytotal = $obj->nb;
333 print $langs->trans(
"CurrentlyNWithoutBarCode", $nbthirdpartyno, $nbthirdpartytotal, $langs->transnoentitiesnoconv(
"ThirdParties")).
"\n";
335 $disabledthirdparty = $disabledthirdparty1 = 0;
337 if (is_object($modBarCodeThirdparty)) {
338 print
'<br>'.$langs->trans(
"BarCodeNumberManager").
": ";
339 $objthirdparty =
new Societe($db);
340 print
'<b>'.(isset($modBarCodeThirdparty->name) ? $modBarCodeThirdparty->name : $modBarCodeThirdparty->nom).
'</b> - '.$langs->trans(
"NextValue").
': <b>'.$modBarCodeThirdparty->getNextValue($objthirdparty).
'</b><br>';
341 $disabledthirdparty = 0;
344 $disabledthirdparty = 1;
345 $titleno = $langs->trans(
"NoBarcodeNumberingTemplateDefined");
346 print
'<div class="warning">'.$langs->trans(
"NoBarcodeNumberingTemplateDefined");
347 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/barcode.php">'.$langs->trans(
"ToGenerateCodeDefineAutomaticRuleFirst").
'</a>';
350 if (empty($nbthirdpartyno)) {
351 $disabledthirdparty1 = 1;
354 $moretagsthirdparty1 = (($disabledthirdparty || $disabledthirdparty1) ?
' disabled title="'.
dol_escape_htmltag($titleno).
'"' :
'');
355 print
'<br><input class="button button-add" type="submit" id="submitformbarcodethirdpartygen" value="'.$langs->trans(
"InitEmptyBarCode", $nbthirdpartyno).
'"'.$moretagsthirdparty1.
'>';
356 $moretagsthirdparty2 = (($nbthirdpartyno == $nbthirdpartytotal) ?
' disabled' :
'');
358 print
'<input type="submit" class="button butActionDelete" name="eraseallthirdpartybarcode" id="eraseallthirdpartybarcode" value="'.$langs->trans(
"EraseAllCurrentBarCode").
'"'.$moretagsthirdparty2.
' onClick="return confirm_erase();">';
359 print
'<br><br><br><br>';
366 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
367 print
'<input type="hidden" name="mode" value="label">';
368 print
'<input type="hidden" name="action" value="initbarcodeproducts">';
369 print
'<input type="hidden" name="token" value="'.newToken().
'">';
371 $nbproductno = $nbproducttotal = 0;
373 print
load_fiche_titre($langs->trans(
"BarcodeInitForProductsOrServices"),
'',
'product');
376 $sql =
"SELECT count(rowid) as nb, fk_product_type, datec";
377 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
378 $sql .=
" WHERE barcode IS NULL OR barcode = ''";
379 $sql .=
" GROUP BY fk_product_type, datec";
380 $sql .=
" ORDER BY datec";
381 $resql = $db->query(
$sql);
383 $num = $db->num_rows($resql);
387 $obj = $db->fetch_object($resql);
388 $nbproductno += $obj->nb;
396 $sql =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"product";
397 $resql = $db->query(
$sql);
399 $obj = $db->fetch_object($resql);
400 $nbproducttotal = $obj->nb;
405 print $langs->trans(
"CurrentlyNWithoutBarCode", $nbproductno, $nbproducttotal, $langs->transnoentitiesnoconv(
"ProductsOrServices")).
"\n";
407 $disabledproduct = $disabledproduct1 = 0;
409 if (is_object($modBarCodeProduct)) {
410 print
'<br>'.$langs->trans(
"BarCodeNumberManager").
": ";
411 $objproduct =
new Product($db);
412 print
'<b>'.(isset($modBarCodeProduct->name) ? $modBarCodeProduct->name : $modBarCodeProduct->nom).
'</b> - '.$langs->trans(
"NextValue").
': <b>'.$modBarCodeProduct->getNextValue($objproduct).
'</b><br>';
413 $disabledproduct = 0;
416 $disabledproduct = 1;
417 $titleno = $langs->trans(
"NoBarcodeNumberingTemplateDefined");
418 print
'<br><div class="warning">'.$langs->trans(
"NoBarcodeNumberingTemplateDefined");
419 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/barcode.php">'.$langs->trans(
"ToGenerateCodeDefineAutomaticRuleFirst").
'</a>';
422 if (empty($nbproductno)) {
423 $disabledproduct1 = 1;
427 $moretagsproduct1 = (($disabledproduct || $disabledproduct1) ?
' disabled title="'.
dol_escape_htmltag($titleno).
'"' :
'');
428 print
'<input type="submit" class="button" name="submitformbarcodeproductgen" id="submitformbarcodeproductgen" value="'.$langs->trans(
"InitEmptyBarCode", min($maxperinit, $nbproductno)).
'"'.$moretagsproduct1.
'>';
429 $moretagsproduct2 = (($nbproductno == $nbproducttotal) ?
' disabled' :
'');
431 print
'<input type="submit" class="button butActionDelete" name="eraseallproductbarcode" id="eraseallproductbarcode" value="'.$langs->trans(
"EraseAllCurrentBarCode").
'"'.$moretagsproduct2.
' onClick="return confirm_erase();">';
432 print
'<br><br><br><br>';
439 print $langs->trans(
"ClickHereToGoTo").
' : <a href="'.DOL_URL_ROOT.
'/barcode/printsheet.php">'.$langs->trans(
"BarCodePrintsheet").
'</a>';