27require
'../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
32$langs->loadLangs(array(
'admin',
'members',
'errors',
'other'));
39$forbarcode =
GETPOST(
'forbarcode');
40$fk_barcode_type =
GETPOST(
'fk_barcode_type');
41$eraseallproductbarcode =
GETPOST(
'eraseallproductbarcode');
42$eraseallthirdpartybarcode =
GETPOST(
'eraseallthirdpartybarcode');
44$action =
GETPOST(
'action',
'aZ09');
47$thirdpartytmp =
new Societe($db);
49$modBarCodeProduct =
'';
50$modBarCodeThirdparty =
'';
52$maxperinit = !
getDolGlobalString(
'BARCODE_INIT_MAX') ? 1000 : $conf->global->BARCODE_INIT_MAX;
57if (!isModEnabled(
'barcode')) {
61if (empty($user->admin)) {
72 $dirbarcodenum = array_merge(array(
'/core/modules/barcode/'), $conf->modules_parts[
'barcode']);
74 foreach ($dirbarcodenum as $dirroot) {
77 $handle = @opendir($dir);
78 if (is_resource($handle)) {
79 while (($file = readdir($handle)) !==
false) {
80 if (preg_match(
'/^mod_barcode_thirdparty_.*php$/', $file)) {
81 $file = substr($file, 0,
dol_strlen($file) - 4);
89 $modBarCodeThirdparty =
new $file();
90 '@phan-var-force ModeleNumRefBarCode $modBarCodeThirdparty';
99if ($action ==
'initbarcodethirdparties' && $user->hasRight(
'societe',
'lire')) {
100 if (!is_object($modBarCodeThirdparty)) {
102 setEventMessages($langs->trans(
"NoBarcodeNumberingTemplateDefined"),
null,
'errors');
106 $thirdpartystatic =
new Societe($db);
111 if (!empty($eraseallthirdpartybarcode)) {
112 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
113 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
114 $sql .=
" SET barcode = NULL";
115 $resql = $db->query($sql);
123 $sql =
"SELECT rowid";
124 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe";
125 $sql .=
" WHERE barcode IS NULL or barcode = ''";
126 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
127 $sql .= $db->order(
"datec",
"ASC");
128 $sql .= $db->plimit($maxperinit);
131 $resql = $db->query($sql);
133 $num = $db->num_rows($resql);
137 while ($i < min($num, $maxperinit)) {
138 $obj = $db->fetch_object($resql);
140 $thirdpartystatic->id = $obj->rowid;
141 $nextvalue = $modBarCodeThirdparty->getNextValue($thirdpartystatic,
'');
143 $result = $thirdpartystatic->setValueFrom(
'barcode', $nextvalue,
'',
null,
'text',
'', $user,
'THIRDPARTY_MODIFY');
176 $dirbarcodenum = array_merge(array(
'/core/modules/barcode/'), $conf->modules_parts[
'barcode']);
178 foreach ($dirbarcodenum as $dirroot) {
181 $handle = @opendir($dir);
182 if (is_resource($handle)) {
183 while (($file = readdir($handle)) !==
false) {
184 if (preg_match(
'/^mod_barcode_product_.*php$/', $file)) {
185 $file = substr($file, 0,
dol_strlen($file) - 4);
194 $modBarCodeProduct =
new $file();
195 '@phan-var-force ModeleNumRefBarCode $modBarCodeProduct';
205if ($action ==
'initbarcodeproducts' && $user->hasRight(
'produit',
'lire')) {
206 if (!is_object($modBarCodeProduct)) {
208 setEventMessages($langs->trans(
"NoBarcodeNumberingTemplateDefined"),
null,
'errors');
212 $productstatic =
new Product($db);
217 if (!empty($eraseallproductbarcode)) {
218 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product";
219 $sql .=
" SET barcode = NULL";
220 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
221 $resql = $db->query($sql);
229 $sql =
"SELECT rowid, ref, fk_product_type";
230 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
231 $sql .=
" WHERE barcode IS NULL or barcode = ''";
232 $sql .=
" AND entity IN (".getEntity(
'product').
")";
233 $sql .= $db->order(
"datec",
"ASC");
234 $sql .= $db->plimit($maxperinit);
237 $resql = $db->query($sql);
239 $num = $db->num_rows($resql);
243 while ($i < min($num, $maxperinit)) {
244 $obj = $db->fetch_object($resql);
246 $productstatic->id = $obj->rowid;
247 $productstatic->ref = $obj->ref;
248 $productstatic->type = $obj->fk_product_type;
249 $nextvalue = $modBarCodeProduct->getNextValue($productstatic,
'');
252 $result = $productstatic->setValueFrom(
'barcode', $nextvalue,
'',
null,
'text',
'', $user,
'PRODUCT_MODIFY');
288llxHeader(
'', $langs->trans(
"MassBarcodeInit"),
'',
'', 0, 0,
'',
'',
'',
'mod-barcode page-codeinit');
290print
load_fiche_titre($langs->trans(
"MassBarcodeInit"),
'',
'title_setup.png');
293print
'<span class="opacitymedium">'.$langs->trans(
"MassBarcodeInitDesc").
'</span><br>';
304print
'<script type="text/javascript">
305function confirm_erase() {
306 return confirm("'.dol_escape_js($langs->trans(
"ConfirmEraseAllCurrentBarCode")).
'");
312if (isModEnabled(
'societe')) {
313 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
314 print
'<input type="hidden" name="mode" value="label">';
315 print
'<input type="hidden" name="action" value="initbarcodethirdparties">';
316 print
'<input type="hidden" name="token" value="'.newToken().
'">';
317 $nbthirdpartyno = $nbthirdpartytotal = 0;
319 print
'<div class="divsection">';
321 print
load_fiche_titre($langs->trans(
"BarcodeInitForThirdparties"),
'',
'company');
323 $sql =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"societe where barcode IS NULL or barcode = ''";
324 $resql = $db->query($sql);
326 $obj = $db->fetch_object($resql);
327 $nbthirdpartyno = $obj->nb;
332 $sql =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"societe";
333 $sql .=
" WHERE entity IN (".getEntity(
'societe').
")";
334 $resql = $db->query($sql);
336 $obj = $db->fetch_object($resql);
337 $nbthirdpartytotal = $obj->nb;
342 print $langs->trans(
"CurrentlyNWithoutBarCode", $nbthirdpartyno, $nbthirdpartytotal, $langs->transnoentitiesnoconv(
"ThirdParties")).
"\n";
344 $disabledthirdparty = $disabledthirdparty1 = 0;
347 if (is_object($modBarCodeThirdparty)) {
348 print
'<br>'.$langs->trans(
"BarCodeNumberManager").
": ";
349 $objthirdparty =
new Societe($db);
350 print
'<b>'.(isset($modBarCodeThirdparty->name) ? $modBarCodeThirdparty->name : $modBarCodeThirdparty->nom).
'</b> - '.$langs->trans(
"NextValue").
': <b>'.$modBarCodeThirdparty->getNextValue($objthirdparty).
'</b><br>';
351 $disabledthirdparty = 0;
354 $disabledthirdparty = 1;
355 $titleno = $langs->trans(
"NoBarcodeNumberingTemplateDefined");
356 print
'<div class="warning">'.$langs->trans(
"NoBarcodeNumberingTemplateDefined");
357 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/barcode.php">'.$langs->trans(
"ToGenerateCodeDefineAutomaticRuleFirst").
'</a>';
360 if (empty($nbthirdpartyno)) {
361 $disabledthirdparty1 = 1;
364 $moretagsthirdparty1 = (($disabledthirdparty || $disabledthirdparty1) ?
' disabled title="'.
dol_escape_htmltag($titleno).
'"' :
'');
365 print
'<input class="button button-add" type="submit" id="submitformbarcodethirdpartygen" value="'.$langs->trans(
"InitEmptyBarCode", $nbthirdpartyno).
'"'.$moretagsthirdparty1.
'>';
366 $moretagsthirdparty2 = (($nbthirdpartyno == $nbthirdpartytotal) ?
' disabled' :
'');
368 print
'<input type="submit" class="button butActionDelete" name="eraseallthirdpartybarcode" id="eraseallthirdpartybarcode" value="'.$langs->trans(
"EraseAllCurrentBarCode").
'"'.$moretagsthirdparty2.
' onClick="return confirm_erase();">';
377if (isModEnabled(
'product') || isModEnabled(
'service')) {
378 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
379 print
'<input type="hidden" name="mode" value="label">';
380 print
'<input type="hidden" name="action" value="initbarcodeproducts">';
381 print
'<input type="hidden" name="token" value="'.newToken().
'">';
383 $nbproductno = $nbproducttotal = 0;
385 print
'<div class="divsection">';
387 print
load_fiche_titre($langs->trans(
"BarcodeInitForProductsOrServices"),
'',
'product');
389 $sql =
"SELECT count(rowid) as nb, fk_product_type, datec";
390 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
391 $sql .=
" WHERE barcode IS NULL OR barcode = ''";
392 $sql .=
" AND entity IN (".getEntity(
'product').
")";
393 $sql .=
" GROUP BY fk_product_type, datec";
394 $sql .=
" ORDER BY datec";
395 $resql = $db->query($sql);
397 $num = $db->num_rows($resql);
401 $obj = $db->fetch_object($resql);
402 $nbproductno += $obj->nb;
410 $sql =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"product";
411 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
412 $resql = $db->query($sql);
414 $obj = $db->fetch_object($resql);
415 $nbproducttotal = $obj->nb;
420 print $langs->trans(
"CurrentlyNWithoutBarCode", $nbproductno, $nbproducttotal, $langs->transnoentitiesnoconv(
"ProductsOrServices")).
"\n";
422 $disabledproduct = $disabledproduct1 = 0;
425 if (is_object($modBarCodeProduct)) {
426 print
'<br>'.$langs->trans(
"BarCodeNumberManager").
": ";
427 $objproduct =
new Product($db);
428 print
'<b>'.(isset($modBarCodeProduct->name) ? $modBarCodeProduct->name : $modBarCodeProduct->nom).
'</b> - '.$langs->trans(
"NextValue").
': <b>'.$modBarCodeProduct->getNextValue($objproduct).
'</b><br>';
429 $disabledproduct = 0;
432 $disabledproduct = 1;
433 $titleno = $langs->trans(
"NoBarcodeNumberingTemplateDefined");
434 print
'<br><div class="warning">'.$langs->trans(
"NoBarcodeNumberingTemplateDefined");
435 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/barcode.php">'.$langs->trans(
"ToGenerateCodeDefineAutomaticRuleFirst").
'</a>';
438 if (empty($nbproductno)) {
439 $disabledproduct1 = 1;
443 $moretagsproduct1 = (($disabledproduct || $disabledproduct1) ?
' disabled title="'.
dol_escape_htmltag($titleno).
'"' :
'');
444 print
'<input type="submit" class="button" name="submitformbarcodeproductgen" id="submitformbarcodeproductgen" value="'.$langs->trans(
"InitEmptyBarCode", min($maxperinit, $nbproductno)).
'"'.$moretagsproduct1.
'>';
445 $moretagsproduct2 = (($nbproductno == $nbproducttotal) ?
' disabled' :
'');
447 print
'<input type="submit" class="button butActionDelete" name="eraseallproductbarcode" id="eraseallproductbarcode" value="'.$langs->trans(
"EraseAllCurrentBarCode").
'"'.$moretagsproduct2.
' onClick="return confirm_erase();">';
455print
'<div class="divsection">';
458print $langs->trans(
"ClickHereToGoTo").
' : <a href="'.DOL_URL_ROOT.
'/barcode/printsheet.php">'.$langs->trans(
"BarCodePrintsheet").
'</a>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.