26require
'../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
28require_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;
56if (!isModEnabled(
'barcode')) {
60if (empty($user->admin)) {
70if (!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();
97if ($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 .=
" AND entity IN (".getEntity(
'societe').
")";
112 $sql .=
" SET barcode = NULL";
113 $resql = $db->query($sql);
121 $sql =
"SELECT rowid";
122 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe";
123 $sql .=
" WHERE barcode IS NULL or barcode = ''";
124 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
125 $sql .= $db->order(
"datec",
"ASC");
126 $sql .= $db->plimit($maxperinit);
129 $resql = $db->query($sql);
131 $num = $db->num_rows($resql);
133 $i = 0; $nbok = $nbtry = 0;
134 while ($i < min($num, $maxperinit)) {
135 $obj = $db->fetch_object($resql);
137 $thirdpartystatic->id = $obj->rowid;
138 $nextvalue = $modBarCodeThirdparty->getNextValue($thirdpartystatic,
'');
140 $result = $thirdpartystatic->setValueFrom(
'barcode', $nextvalue,
'',
'',
'text',
'', $user,
'THIRDPARTY_MODIFY');
172if (!empty($conf->global->BARCODE_PRODUCT_ADDON_NUM)) {
173 $dirbarcodenum = array_merge(array(
'/core/modules/barcode/'), $conf->modules_parts[
'barcode']);
175 foreach ($dirbarcodenum as $dirroot) {
178 $handle = @opendir($dir);
179 if (is_resource($handle)) {
180 while (($file = readdir($handle)) !==
false) {
181 if (preg_match(
'/^mod_barcode_product_.*php$/', $file)) {
182 $file = substr($file, 0,
dol_strlen($file) - 4);
184 if ($file == $conf->global->BARCODE_PRODUCT_ADDON_NUM) {
191 $modBarCodeProduct =
new $file();
201if ($action ==
'initbarcodeproducts') {
202 if (!is_object($modBarCodeProduct)) {
204 setEventMessages($langs->trans(
"NoBarcodeNumberingTemplateDefined"),
null,
'errors');
208 $productstatic =
new Product($db);
213 if (!empty($eraseallproductbarcode)) {
214 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product";
215 $sql .=
" SET barcode = NULL";
216 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
217 $resql = $db->query($sql);
225 $sql =
"SELECT rowid, ref, fk_product_type";
226 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
227 $sql .=
" WHERE barcode IS NULL or barcode = ''";
228 $sql .=
" AND entity IN (".getEntity(
'product').
")";
229 $sql .= $db->order(
"datec",
"ASC");
230 $sql .= $db->plimit($maxperinit);
233 $resql = $db->query($sql);
235 $num = $db->num_rows($resql);
237 $i = 0; $nbok = $nbtry = 0;
238 while ($i < min($num, $maxperinit)) {
239 $obj = $db->fetch_object($resql);
241 $productstatic->id = $obj->rowid;
242 $productstatic->ref = $obj->ref;
243 $productstatic->type = $obj->fk_product_type;
244 $nextvalue = $modBarCodeProduct->getNextValue($productstatic,
'');
247 $result = $productstatic->setValueFrom(
'barcode', $nextvalue,
'',
'',
'text',
'', $user,
'PRODUCT_MODIFY');
283$form =
new Form($db);
285llxHeader(
'', $langs->trans(
"MassBarcodeInit"));
287print
load_fiche_titre($langs->trans(
"MassBarcodeInit"),
'',
'title_setup.png');
290print
'<span class="opacitymedium">'.$langs->trans(
"MassBarcodeInitDesc").
'</span><br>';
301print
'<script type="text/javascript">
302function confirm_erase() {
303 return confirm("'.dol_escape_js($langs->trans(
"ConfirmEraseAllCurrentBarCode")).
'");
309if (isModEnabled(
'societe')) {
310 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
311 print
'<input type="hidden" name="mode" value="label">';
312 print
'<input type="hidden" name="action" value="initbarcodethirdparties">';
313 print
'<input type="hidden" name="token" value="'.newToken().
'">';
314 $nbthirdpartyno = $nbthirdpartytotal = 0;
316 print
load_fiche_titre($langs->trans(
"BarcodeInitForThirdparties"),
'',
'company');
319 $sql =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"societe where barcode IS NULL or barcode = ''";
320 $resql = $db->query($sql);
322 $obj = $db->fetch_object($resql);
323 $nbthirdpartyno = $obj->nb;
328 $sql =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"societe";
329 $sql .=
" WHERE entity IN (".getEntity(
'societe').
")";
330 $resql = $db->query($sql);
332 $obj = $db->fetch_object($resql);
333 $nbthirdpartytotal = $obj->nb;
338 print $langs->trans(
"CurrentlyNWithoutBarCode", $nbthirdpartyno, $nbthirdpartytotal, $langs->transnoentitiesnoconv(
"ThirdParties")).
"\n";
340 $disabledthirdparty = $disabledthirdparty1 = 0;
342 if (is_object($modBarCodeThirdparty)) {
343 print
'<br>'.$langs->trans(
"BarCodeNumberManager").
": ";
344 $objthirdparty =
new Societe($db);
345 print
'<b>'.(isset($modBarCodeThirdparty->name) ? $modBarCodeThirdparty->name : $modBarCodeThirdparty->nom).
'</b> - '.$langs->trans(
"NextValue").
': <b>'.$modBarCodeThirdparty->getNextValue($objthirdparty).
'</b><br>';
346 $disabledthirdparty = 0;
349 $disabledthirdparty = 1;
350 $titleno = $langs->trans(
"NoBarcodeNumberingTemplateDefined");
351 print
'<div class="warning">'.$langs->trans(
"NoBarcodeNumberingTemplateDefined");
352 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/barcode.php">'.$langs->trans(
"ToGenerateCodeDefineAutomaticRuleFirst").
'</a>';
355 if (empty($nbthirdpartyno)) {
356 $disabledthirdparty1 = 1;
359 $moretagsthirdparty1 = (($disabledthirdparty || $disabledthirdparty1) ?
' disabled title="'.
dol_escape_htmltag($titleno).
'"' :
'');
360 print
'<br><input class="button button-add" type="submit" id="submitformbarcodethirdpartygen" value="'.$langs->trans(
"InitEmptyBarCode", $nbthirdpartyno).
'"'.$moretagsthirdparty1.
'>';
361 $moretagsthirdparty2 = (($nbthirdpartyno == $nbthirdpartytotal) ?
' disabled' :
'');
363 print
'<input type="submit" class="button butActionDelete" name="eraseallthirdpartybarcode" id="eraseallthirdpartybarcode" value="'.$langs->trans(
"EraseAllCurrentBarCode").
'"'.$moretagsthirdparty2.
' onClick="return confirm_erase();">';
364 print
'<br><br><br><br>';
370if (isModEnabled(
'product') || isModEnabled(
'service')) {
371 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
372 print
'<input type="hidden" name="mode" value="label">';
373 print
'<input type="hidden" name="action" value="initbarcodeproducts">';
374 print
'<input type="hidden" name="token" value="'.newToken().
'">';
376 $nbproductno = $nbproducttotal = 0;
378 print
load_fiche_titre($langs->trans(
"BarcodeInitForProductsOrServices"),
'',
'product');
381 $sql =
"SELECT count(rowid) as nb, fk_product_type, datec";
382 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
383 $sql .=
" WHERE barcode IS NULL OR barcode = ''";
384 $sql .=
" AND entity IN (".getEntity(
'product').
")";
385 $sql .=
" GROUP BY fk_product_type, datec";
386 $sql .=
" ORDER BY datec";
387 $resql = $db->query($sql);
389 $num = $db->num_rows($resql);
393 $obj = $db->fetch_object($resql);
394 $nbproductno += $obj->nb;
402 $sql =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"product";
403 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
404 $resql = $db->query($sql);
406 $obj = $db->fetch_object($resql);
407 $nbproducttotal = $obj->nb;
412 print $langs->trans(
"CurrentlyNWithoutBarCode", $nbproductno, $nbproducttotal, $langs->transnoentitiesnoconv(
"ProductsOrServices")).
"\n";
414 $disabledproduct = $disabledproduct1 = 0;
416 if (is_object($modBarCodeProduct)) {
417 print
'<br>'.$langs->trans(
"BarCodeNumberManager").
": ";
418 $objproduct =
new Product($db);
419 print
'<b>'.(isset($modBarCodeProduct->name) ? $modBarCodeProduct->name : $modBarCodeProduct->nom).
'</b> - '.$langs->trans(
"NextValue").
': <b>'.$modBarCodeProduct->getNextValue($objproduct).
'</b><br>';
420 $disabledproduct = 0;
423 $disabledproduct = 1;
424 $titleno = $langs->trans(
"NoBarcodeNumberingTemplateDefined");
425 print
'<br><div class="warning">'.$langs->trans(
"NoBarcodeNumberingTemplateDefined");
426 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/barcode.php">'.$langs->trans(
"ToGenerateCodeDefineAutomaticRuleFirst").
'</a>';
429 if (empty($nbproductno)) {
430 $disabledproduct1 = 1;
434 $moretagsproduct1 = (($disabledproduct || $disabledproduct1) ?
' disabled title="'.
dol_escape_htmltag($titleno).
'"' :
'');
435 print
'<input type="submit" class="button" name="submitformbarcodeproductgen" id="submitformbarcodeproductgen" value="'.$langs->trans(
"InitEmptyBarCode", min($maxperinit, $nbproductno)).
'"'.$moretagsproduct1.
'>';
436 $moretagsproduct2 = (($nbproductno == $nbproducttotal) ?
' disabled' :
'');
438 print
'<input type="submit" class="button butActionDelete" name="eraseallproductbarcode" id="eraseallproductbarcode" value="'.$langs->trans(
"EraseAllCurrentBarCode").
'"'.$moretagsproduct2.
' onClick="return confirm_erase();">';
439 print
'<br><br><br><br>';
446print $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()
Empty header.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.