28require
'../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
41$langs->loadLangs(array(
'admin',
'members',
'errors',
'other'));
48$forbarcode =
GETPOST(
'forbarcode');
49$fk_barcode_type =
GETPOST(
'fk_barcode_type');
50$eraseallproductbarcode =
GETPOST(
'eraseallproductbarcode');
51$eraseallthirdpartybarcode =
GETPOST(
'eraseallthirdpartybarcode');
53$action =
GETPOST(
'action',
'aZ09');
56$thirdpartytmp =
new Societe($db);
58$modBarCodeProduct =
'';
59$modBarCodeThirdparty =
'';
66if (!isModEnabled(
'barcode')) {
70if (empty($user->admin)) {
82 $dirbarcodenum = array_merge(array(
'/core/modules/barcode/'),
$conf->modules_parts[
'barcode']);
84 foreach ($dirbarcodenum as $dirroot) {
87 $handle = @opendir($dir);
88 if (is_resource($handle)) {
89 while (($file = readdir($handle)) !==
false) {
90 if (preg_match(
'/^mod_barcode_thirdparty_.*php$/', $file)) {
91 $file = substr($file, 0,
dol_strlen($file) - 4);
99 $modBarCodeThirdparty =
new $file();
100 '@phan-var-force ModeleNumRefBarCode $modBarCodeThirdparty';
109if ($action ==
'initbarcodethirdparties' && $user->hasRight(
'societe',
'lire')) {
110 if (!is_object($modBarCodeThirdparty)) {
112 setEventMessages($langs->trans(
"NoBarcodeNumberingTemplateDefined"),
null,
'errors');
116 $thirdpartystatic =
new Societe($db);
121 if (!empty($eraseallthirdpartybarcode)) {
122 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe";
123 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
124 $sql .=
" SET barcode = NULL";
125 $resql = $db->query($sql);
133 $sql =
"SELECT rowid";
134 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe";
135 $sql .=
" WHERE barcode IS NULL or barcode = ''";
136 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
137 $sql .= $db->order(
"datec",
"ASC");
138 $sql .= $db->plimit($maxperinit);
141 $resql = $db->query($sql);
143 $num = $db->num_rows($resql);
147 while ($i < min($num, $maxperinit)) {
148 $obj = $db->fetch_object($resql);
150 $thirdpartystatic->id = $obj->rowid;
151 $nextvalue = $modBarCodeThirdparty->getNextValue($thirdpartystatic,
'');
153 $result = $thirdpartystatic->setValueFrom(
'barcode', $nextvalue,
'',
null,
'text',
'', $user,
'THIRDPARTY_MODIFY');
186 $dirbarcodenum = array_merge(array(
'/core/modules/barcode/'),
$conf->modules_parts[
'barcode']);
188 foreach ($dirbarcodenum as $dirroot) {
191 $handle = @opendir($dir);
192 if (is_resource($handle)) {
193 while (($file = readdir($handle)) !==
false) {
194 if (preg_match(
'/^mod_barcode_product_.*php$/', $file)) {
195 $file = substr($file, 0,
dol_strlen($file) - 4);
204 $modBarCodeProduct =
new $file();
205 '@phan-var-force ModeleNumRefBarCode $modBarCodeProduct';
215if ($action ==
'initbarcodeproducts' && $user->hasRight(
'produit',
'lire')) {
216 if (!is_object($modBarCodeProduct)) {
218 setEventMessages($langs->trans(
"NoBarcodeNumberingTemplateDefined"),
null,
'errors');
222 $productstatic =
new Product($db);
227 if (!empty($eraseallproductbarcode)) {
228 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product";
229 $sql .=
" SET barcode = NULL";
230 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
231 $resql = $db->query($sql);
239 $sql =
"SELECT rowid, ref, fk_product_type";
240 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
241 $sql .=
" WHERE barcode IS NULL or barcode = ''";
242 $sql .=
" AND entity IN (".getEntity(
'product').
")";
243 $sql .= $db->order(
"datec",
"ASC");
244 $sql .= $db->plimit($maxperinit);
247 $resql = $db->query($sql);
249 $num = $db->num_rows($resql);
253 while ($i < min($num, $maxperinit)) {
254 $obj = $db->fetch_object($resql);
256 $productstatic->id = $obj->rowid;
257 $productstatic->ref = $obj->ref;
258 $productstatic->type = $obj->fk_product_type;
259 $nextvalue = $modBarCodeProduct->getNextValue($productstatic,
'');
262 $result = $productstatic->setValueFrom(
'barcode', $nextvalue,
'',
null,
'text',
'', $user,
'PRODUCT_MODIFY');
298llxHeader(
'', $langs->trans(
"MassBarcodeInit"),
'',
'', 0, 0,
'',
'',
'',
'mod-barcode page-codeinit');
300print
load_fiche_titre($langs->trans(
"MassBarcodeInit"),
'',
'title_setup.png');
303print
'<span class="opacitymedium">'.$langs->trans(
"MassBarcodeInitDesc").
'</span><br>';
314print
'<script type="text/javascript">
315function confirm_erase() {
316 return confirm("'.dol_escape_js($langs->trans(
"ConfirmEraseAllCurrentBarCode")).
'");
322if (isModEnabled(
'societe')) {
323 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
324 print
'<input type="hidden" name="mode" value="label">';
325 print
'<input type="hidden" name="action" value="initbarcodethirdparties">';
326 print
'<input type="hidden" name="token" value="'.newToken().
'">';
327 $nbthirdpartyno = $nbthirdpartytotal = 0;
329 print
'<div class="divsection">';
331 print
load_fiche_titre($langs->trans(
"BarcodeInitForThirdparties"),
'',
'company');
333 $sql =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"societe where barcode IS NULL or barcode = ''";
334 $resql = $db->query($sql);
336 $obj = $db->fetch_object($resql);
337 $nbthirdpartyno = $obj->nb;
342 $sql =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"societe";
343 $sql .=
" WHERE entity IN (".getEntity(
'societe').
")";
344 $resql = $db->query($sql);
346 $obj = $db->fetch_object($resql);
347 $nbthirdpartytotal = $obj->nb;
352 print $langs->trans(
"CurrentlyNWithoutBarCode", $nbthirdpartyno, $nbthirdpartytotal, $langs->transnoentitiesnoconv(
"ThirdParties")).
"\n";
354 $disabledthirdparty = $disabledthirdparty1 = 0;
357 if (is_object($modBarCodeThirdparty)) {
358 print
'<br>'.$langs->trans(
"BarCodeNumberManager").
": ";
359 $objthirdparty =
new Societe($db);
360 print
'<b>'.(isset($modBarCodeThirdparty->name) ? $modBarCodeThirdparty->name : $modBarCodeThirdparty->nom).
'</b> - '.$langs->trans(
"NextValue").
': <b>'.$modBarCodeThirdparty->getNextValue($objthirdparty).
'</b><br>';
361 $disabledthirdparty = 0;
364 $disabledthirdparty = 1;
365 $titleno = $langs->trans(
"NoBarcodeNumberingTemplateDefined");
366 print
'<div class="warning">'.$langs->trans(
"NoBarcodeNumberingTemplateDefined");
367 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/barcode.php">'.$langs->trans(
"ToGenerateCodeDefineAutomaticRuleFirst").
'</a>';
370 if (empty($nbthirdpartyno)) {
371 $disabledthirdparty1 = 1;
374 $moretagsthirdparty1 = (($disabledthirdparty || $disabledthirdparty1) ?
' disabled title="'.
dol_escape_htmltag($titleno).
'"' :
'');
375 print
'<input class="button button-add" type="submit" id="submitformbarcodethirdpartygen" value="'.$langs->trans(
"InitEmptyBarCode", $nbthirdpartyno).
'"'.$moretagsthirdparty1.
'>';
376 $moretagsthirdparty2 = (($nbthirdpartyno == $nbthirdpartytotal) ?
' disabled' :
'');
378 print
'<input type="submit" class="button butActionDelete" name="eraseallthirdpartybarcode" id="eraseallthirdpartybarcode" value="'.$langs->trans(
"EraseAllCurrentBarCode").
'"'.$moretagsthirdparty2.
' onClick="return confirm_erase();">';
387if (isModEnabled(
'product') || isModEnabled(
'service')) {
388 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
389 print
'<input type="hidden" name="mode" value="label">';
390 print
'<input type="hidden" name="action" value="initbarcodeproducts">';
391 print
'<input type="hidden" name="token" value="'.newToken().
'">';
393 $nbproductno = $nbproducttotal = 0;
395 print
'<div class="divsection">';
397 print
load_fiche_titre($langs->trans(
"BarcodeInitForProductsOrServices"),
'',
'product');
399 $sql =
"SELECT count(rowid) as nb, fk_product_type, datec";
400 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
401 $sql .=
" WHERE barcode IS NULL OR barcode = ''";
402 $sql .=
" AND entity IN (".getEntity(
'product').
")";
403 $sql .=
" GROUP BY fk_product_type, datec";
404 $sql .=
" ORDER BY datec";
405 $resql = $db->query($sql);
407 $num = $db->num_rows($resql);
411 $obj = $db->fetch_object($resql);
412 $nbproductno += $obj->nb;
420 $sql =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"product";
421 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
422 $resql = $db->query($sql);
424 $obj = $db->fetch_object($resql);
425 $nbproducttotal = $obj->nb;
430 print $langs->trans(
"CurrentlyNWithoutBarCode", $nbproductno, $nbproducttotal, $langs->transnoentitiesnoconv(
"ProductsOrServices")).
"\n";
432 $disabledproduct = $disabledproduct1 = 0;
435 if (is_object($modBarCodeProduct)) {
436 print
'<br>'.$langs->trans(
"BarCodeNumberManager").
": ";
437 $objproduct =
new Product($db);
438 print
'<b>'.(isset($modBarCodeProduct->name) ? $modBarCodeProduct->name : $modBarCodeProduct->nom).
'</b> - '.$langs->trans(
"NextValue").
': <b>'.$modBarCodeProduct->getNextValue($objproduct).
'</b><br>';
439 $disabledproduct = 0;
442 $disabledproduct = 1;
443 $titleno = $langs->trans(
"NoBarcodeNumberingTemplateDefined");
444 print
'<br><div class="warning">'.$langs->trans(
"NoBarcodeNumberingTemplateDefined");
445 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/barcode.php">'.$langs->trans(
"ToGenerateCodeDefineAutomaticRuleFirst").
'</a>';
448 if (empty($nbproductno)) {
449 $disabledproduct1 = 1;
453 $moretagsproduct1 = (($disabledproduct || $disabledproduct1) ?
' disabled title="'.
dol_escape_htmltag($titleno).
'"' :
'');
454 print
'<input type="submit" class="button" name="submitformbarcodeproductgen" id="submitformbarcodeproductgen" value="'.$langs->trans(
"InitEmptyBarCode", min($maxperinit, $nbproductno)).
'"'.$moretagsproduct1.
'>';
455 $moretagsproduct2 = (($nbproductno == $nbproducttotal) ?
' disabled' :
'');
457 print
'<input type="submit" class="button butActionDelete" name="eraseallproductbarcode" id="eraseallproductbarcode" value="'.$langs->trans(
"EraseAllCurrentBarCode").
'"'.$moretagsproduct2.
' onClick="return confirm_erase();">';
465print
'<div class="divsection">';
468print $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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.