New: Generation auto of barcode is available for product.

This commit is contained in:
Laurent Destailleur 2014-02-10 00:24:20 +01:00
parent 70ab096b79
commit bd25a98e03
6 changed files with 175 additions and 148 deletions

View File

@ -39,15 +39,16 @@ $action = GETPOST('action','alpha');
* Actions * Actions
*/ */
if ($action == 'setbarcodeon') if ($action == 'setbarcodeproducton')
{ {
$res=dolibarr_set_const($db, "BARCODE_ADDON_NUM", GETPOST('value'), 'chaine', 0, '', $conf->entity); $res=dolibarr_set_const($db, "BARCODE_PRODUCT_ADDON_NUM", GETPOST('value'), 'chaine', 0, '', $conf->entity);
} }
elseif ($action == 'setbarcodeoff') elseif ($action == 'setbarcodeproductoff')
{ {
$res=dolibarr_del_const($db, "BARCODE_ADDON_NUM", $conf->entity); $res=dolibarr_del_const($db, "BARCODE_PRODUCT_ADDON_NUM", $conf->entity);
} }
else if ($action == 'setcoder')
if ($action == 'setcoder')
{ {
$coder = GETPOST('coder','alpha'); $coder = GETPOST('coder','alpha');
$code_id = GETPOST('code_id','alpha'); $code_id = GETPOST('code_id','alpha');
@ -125,7 +126,8 @@ if ($action && $action != 'setcoder' && $action != 'setModuleOptions')
$form = new Form($db); $form = new Form($db);
$formbarcode = new FormBarCode($db); $formbarcode = new FormBarCode($db);
llxHeader('',$langs->trans("BarcodeSetup"),'BarcodeConfiguration'); $help_url='EN:Module_Barcode|FR:Module_Codes_Barre|ES:Módulo Código de barra';
llxHeader('',$langs->trans("BarcodeSetup"),$help_url);
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>'; $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans("BarcodeSetup"),$linkback,'setup'); print_fiche_titre($langs->trans("BarcodeSetup"),$linkback,'setup');
@ -351,74 +353,78 @@ print "</table>\n";
print '<br>'; print '<br>';
// Select barcode numbering module // Select barcode numbering module
if ($conf->produit->enabled)
print_titre($langs->trans("BarCodeNumberManager"));
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td width="140">'.$langs->trans("Name").'</td>';
print '<td>'.$langs->trans("Description").'</td>';
print '<td>'.$langs->trans("Example").'</td>';
print '<td align="center" width="80">'.$langs->trans("Status").'</td>';
print '<td align="center" width="60">'.$langs->trans("ShortInfo").'</td>';
print "</tr>\n";
$dirbarcodenum=array_merge(array('/core/modules/barcode/'),$conf->modules_parts['barcode']);
foreach ($dirbarcodenum as $dirroot)
{ {
$dir = dol_buildpath($dirroot,0); print_titre($langs->trans("BarCodeNumberManager")." (".$langs->trans("Product").")");
$handle = @opendir($dir); print '<table class="noborder" width="100%">';
if (is_resource($handle)) print '<tr class="liste_titre">';
{ print '<td width="140">'.$langs->trans("Name").'</td>';
while (($file = readdir($handle))!==false) print '<td>'.$langs->trans("Description").'</td>';
{ print '<td>'.$langs->trans("Example").'</td>';
if (preg_match('/^mod_barcode_.*php$/', $file)) print '<td align="center" width="80">'.$langs->trans("Status").'</td>';
{ print '<td align="center" width="60">'.$langs->trans("ShortInfo").'</td>';
$file = substr($file, 0, dol_strlen($file)-4); print "</tr>\n";
try { $dirbarcodenum=array_merge(array('/core/modules/barcode/'),$conf->modules_parts['barcode']);
dol_include_once($dirroot.$file.'.php');
}
catch(Exception $e)
{
dol_syslog($e->getMessage(), LOG_ERR);
}
$modBarCode = new $file(); foreach ($dirbarcodenum as $dirroot)
$var = !$var; {
$dir = dol_buildpath($dirroot,0);
print '<tr '.$bc[$var].'>'; $handle = @opendir($dir);
print '<td>'.$modBarCode->nom."</td><td>\n"; if (is_resource($handle))
print $modBarCode->info($langs); {
print '</td>'; while (($file = readdir($handle))!==false)
print '<td class="nowrap">'.$modBarCode->getExample($langs)."</td>\n"; {
if (preg_match('/^mod_barcode_product_.*php$/', $file))
{
$file = substr($file, 0, dol_strlen($file)-4);
if ($conf->global->BARCODE_ADDON_NUM == "$file") try {
{ dol_include_once($dirroot.$file.'.php');
print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeoff&value='.$file.'">'; }
print img_picto($langs->trans("Activated"),'switch_on'); catch(Exception $e)
print '</a></td>'; {
} dol_syslog($e->getMessage(), LOG_ERR);
else }
{
print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeon&value='.$file.'">'; $modBarCode = new $file();
print img_picto($langs->trans("Disabled"),'switch_off'); $var = !$var;
print '</a></td>';
} print '<tr '.$bc[$var].'>';
print '<td align="center">'; print '<td>'.$modBarCode->nom."</td><td>\n";
$s=$modBarCode->getToolTip($langs,null,-1); print $modBarCode->info($langs);
print $form->textwithpicto('',$s,1); print '</td>';
print '</td>'; print '<td class="nowrap">'.$modBarCode->getExample($langs)."</td>\n";
print "</tr>\n";
} if ($conf->global->BARCODE_PRODUCT_ADDON_NUM == "$file")
} {
closedir($handle); print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproductoff&value='.$file.'">';
} print img_picto($langs->trans("Activated"),'switch_on');
print '</a></td>';
}
else
{
print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproducton&value='.$file.'">';
print img_picto($langs->trans("Disabled"),'switch_off');
print '</a></td>';
}
print '<td align="center">';
$s=$modBarCode->getToolTip($langs,null,-1);
print $form->textwithpicto('',$s,1);
print '</td>';
print "</tr>\n";
}
}
closedir($handle);
}
}
print "</table>\n";
} }
print "</table>\n";
print '</form>'; print '</form>';

View File

@ -20,7 +20,7 @@
*/ */
/** /**
* \file htdocs/core/modules/product/mod_barcode_standard.php * \file htdocs/core/modules/product/mod_barcode_product_standard.php
* \ingroup barcode * \ingroup barcode
* \brief File of class to manage barcode numbering with standard rule * \brief File of class to manage barcode numbering with standard rule
*/ */
@ -31,7 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/barcode/modules_barcode.class.php'
/** /**
* Class to manage barcode with standard rule * Class to manage barcode with standard rule
*/ */
class mod_barcode_standard extends ModeleNumRefBarCode class mod_barcode_product_standard extends ModeleNumRefBarCode
{ {
var $nom='Standard'; // Nom du modele var $nom='Standard'; // Nom du modele
var $code_modifiable; // Code modifiable var $code_modifiable; // Code modifiable
@ -78,7 +78,7 @@ class mod_barcode_standard extends ModeleNumRefBarCode
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$texte.= '<input type="hidden" name="action" value="setModuleOptions">'; $texte.= '<input type="hidden" name="action" value="setModuleOptions">';
$texte.= '<input type="hidden" name="param1" value="BARCODE_STANDARD_MASK">'; $texte.= '<input type="hidden" name="param1" value="BARCODE_STANDARD_PRODUCT_MASK">';
$texte.= '<table class="nobordernopadding" width="100%">'; $texte.= '<table class="nobordernopadding" width="100%">';
$tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("BarCode"),$langs->transnoentities("BarCode")); $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("BarCode"),$langs->transnoentities("BarCode"));
@ -89,7 +89,7 @@ class mod_barcode_standard extends ModeleNumRefBarCode
// Mask parameter // Mask parameter
//$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("BarCodeModel").'):</td>'; //$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("BarCodeModel").'):</td>';
$texte.= '<tr><td>'.$langs->trans("Mask").':</td>'; $texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.(! empty($conf->global->BARCODE_STANDARD_MASK)?$conf->global->BARCODE_STANDARD_MASK:'').'"'.$disabled.'>',$tooltip,1,1).'</td>'; $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.(! empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)?$conf->global->BARCODE_STANDARD_PRODUCT_MASK:'').'"'.$disabled.'>',$tooltip,1,1).'</td>';
$texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>'; $texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>';
$texte.= '</tr>'; $texte.= '</tr>';
@ -140,7 +140,7 @@ class mod_barcode_standard extends ModeleNumRefBarCode
// Get Mask value // Get Mask value
$mask = ''; $mask = '';
if (! empty($conf->global->BARCODE_STANDARD_MASK)) $mask = $conf->global->BARCODE_STANDARD_MASK; if (! empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) $mask = $conf->global->BARCODE_STANDARD_PRODUCT_MASK;
if (empty($mask)) if (empty($mask))
{ {
@ -158,34 +158,18 @@ class mod_barcode_standard extends ModeleNumRefBarCode
} }
/**
* Check if mask/numbering use prefix
*
* @return int 0 or 1
*/
function verif_prefixIsUsed()
{
global $conf;
$mask = $conf->global->BARCODE_STANDARD_MASK;
if (preg_match('/\{pre\}/i',$mask)) return 1;
return 0;
}
/** /**
* Check validity of code according to its rules * Check validity of code according to its rules
* *
* @param DoliDB $db Database handler * @param DoliDB $db Database handler
* @param string &$code Code to check/correct * @param string &$code Code to check/correct
* @param Product $product Object product * @param Product $product Object product
* @param int $type 0 = customer/prospect , 1 = supplier * @param int $type 0 = customer/prospect , 1 = supplier
* @return int 0 if OK * @return int 0 if OK
* -1 ErrorBadCustomerCodeSyntax * -1 ErrorBadCustomerCodeSyntax
* -2 ErrorCustomerCodeRequired * -2 ErrorCustomerCodeRequired
* -3 ErrorCustomerCodeAlreadyUsed * -3 ErrorCustomerCodeAlreadyUsed
* -4 ErrorPrefixRequired * -4 ErrorPrefixRequired
*/ */
function verif($db, &$code, $product, $type) function verif($db, &$code, $product, $type)
{ {
@ -196,20 +180,18 @@ class mod_barcode_standard extends ModeleNumRefBarCode
$result=0; $result=0;
$code = strtoupper(trim($code)); $code = strtoupper(trim($code));
if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) if (empty($code) && $this->code_null && empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK))
{ {
$result=0; $result=0;
} }
else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) ) else if (empty($code) && (! $this->code_null || ! empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) )
{ {
$result=-2; $result=-2;
} }
else else
{ {
// Get Mask value // Get Mask value
$mask = ''; $mask = empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)?'':$conf->global->BARCODE_STANDARD_PRODUCT_MASK;
if ($type==0) $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT)?'':$conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT;
if ($type==1) $mask = empty($conf->global->PRODUCT_ELEPHANT_MASK_SSERVICE)?'':$conf->global->PRODUCT_ELEPHANT_MASK_SERVICE;
if (! $mask) if (! $mask)
{ {
$this->error='NotConfigured'; $this->error='NotConfigured';
@ -219,17 +201,17 @@ class mod_barcode_standard extends ModeleNumRefBarCode
$result=check_value($mask,$code); $result=check_value($mask,$code);
} }
dol_syslog("mod_codeclient_elephant::verif type=".$type." result=".$result); dol_syslog(get_class($this)."::verif type=".$type." result=".$result);
return $result; return $result;
} }
/** /**
* Renvoi si un code est pris ou non (par autre tiers) * Return if a code is used (by other element)
* *
* @param DoliDB $db Handler acces base * @param DoliDB $db Handler acces base
* @param string $code Code a verifier * @param string $code Code a verifier
* @param Product $product Objet product * @param Product $product Objet product
* @return int 0 if available, <0 if KO * @return int 0 if available, <0 if KO
*/ */
function verif_dispo($db, $code, $product) function verif_dispo($db, $code, $product)

View File

@ -1014,6 +1014,7 @@ FieldEdition=Edition of field %s
FixTZ=TimeZone fix FixTZ=TimeZone fix
FillThisOnlyIfRequired=Example: +2 (fill only if timezone offset problems are experienced) FillThisOnlyIfRequired=Example: +2 (fill only if timezone offset problems are experienced)
GetBarCode=Get barcode GetBarCode=Get barcode
EmptyNumRefModelDesc=The code is free. This code can be modified at any time.
##### Module password generation ##### Module password generation
PasswordGenerationStandard=Return a password generated according to internal Dolibarr algorithm: 8 characters containing shared numbers and characters in lowercase. PasswordGenerationStandard=Return a password generated according to internal Dolibarr algorithm: 8 characters containing shared numbers and characters in lowercase.
PasswordGenerationNone=Do not suggest any generated password. Password must be type in manually. PasswordGenerationNone=Do not suggest any generated password. Password must be type in manually.
@ -1040,8 +1041,8 @@ DocumentModelOdt=Generate documents from OpenDocuments templates (.ODT or .ODS f
WatermarkOnDraft=Watermark on draft document WatermarkOnDraft=Watermark on draft document
CompanyIdProfChecker=Rules on Professional Ids CompanyIdProfChecker=Rules on Professional Ids
MustBeUnique=Must be unique ? MustBeUnique=Must be unique ?
MustBeMandatory=Must be mandatory to create thirds? MustBeMandatory=Mandatory to create third parties ?
MustBeInvoiceMandatory=Must be mandatory to validate invoices? MustBeInvoiceMandatory=Mandatory to validate invoices ?
Miscellaneous=Miscellaneous Miscellaneous=Miscellaneous
##### Webcal setup ##### ##### Webcal setup #####
WebCalSetup=Webcalendar link setup WebCalSetup=Webcalendar link setup

View File

@ -117,7 +117,7 @@ class Product extends CommonObject
//! barcode //! barcode
var $barcode; // value var $barcode; // value
var $barcode_type; // id var $barcode_type; // id
var $barcode_type_code; // code (loaded by fetch_barcode) var $barcode_type_code; // code (loaded by fetch_barcode). Example ean, isbn...
var $barcode_type_label; // label (loaded by fetch_barcode) var $barcode_type_label; // label (loaded by fetch_barcode)
var $barcode_type_coder; // coder (loaded by fetch_barcode) var $barcode_type_coder; // coder (loaded by fetch_barcode)
@ -257,7 +257,7 @@ class Product extends CommonObject
$price_min_ttc = price2num($this->price_min * (1 + ($this->tva_tx / 100)),'MU'); $price_min_ttc = price2num($this->price_min * (1 + ($this->tva_tx / 100)),'MU');
} }
$this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_buy = trim($this->accountancy_code_buy);
$this->accountancy_code_sell= trim($this->accountancy_code_sell); $this->accountancy_code_sell= trim($this->accountancy_code_sell);
// Check parameters // Check parameters
@ -297,6 +297,9 @@ class Product extends CommonObject
$this->db->begin(); $this->db->begin();
// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
if ($this->barcode == -1) $this->get_barcode($this,$this->barcode_type_code);
$sql = "SELECT count(*) as nb"; $sql = "SELECT count(*) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."product"; $sql.= " FROM ".MAIN_DB_PREFIX."product";
$sql.= " WHERE entity IN (".getEntity('product', 1).")"; $sql.= " WHERE entity IN (".getEntity('product', 1).")";
@ -324,12 +327,12 @@ class Product extends CommonObject
$sql.= ", price_base_type"; $sql.= ", price_base_type";
$sql.= ", tobuy"; $sql.= ", tobuy";
$sql.= ", tosell"; $sql.= ", tosell";
$sql.= ", accountancy_code_buy"; $sql.= ", accountancy_code_buy";
$sql.= ", accountancy_code_sell"; $sql.= ", accountancy_code_sell";
$sql.= ", canvas"; $sql.= ", canvas";
$sql.= ", finished"; $sql.= ", finished";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= $this->db->idate($now); $sql.= "'".$this->db->idate($now)."'";
$sql.= ", ".$conf->entity; $sql.= ", ".$conf->entity;
$sql.= ", '".$this->db->escape($this->ref)."'"; $sql.= ", '".$this->db->escape($this->ref)."'";
$sql.= ", ".(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null"); $sql.= ", ".(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null");
@ -343,8 +346,8 @@ class Product extends CommonObject
$sql.= ", '".$this->price_base_type."'"; $sql.= ", '".$this->price_base_type."'";
$sql.= ", ".$this->status; $sql.= ", ".$this->status;
$sql.= ", ".$this->status_buy; $sql.= ", ".$this->status_buy;
$sql.= ", '".$this->accountancy_code_buy."'"; $sql.= ", '".$this->accountancy_code_buy."'";
$sql.= ", '".$this->accountancy_code_sell."'"; $sql.= ", '".$this->accountancy_code_sell."'";
$sql.= ", '".$this->canvas."'"; $sql.= ", '".$this->canvas."'";
$sql.= ", ".((empty($this->finished) || $this->finished < 0)?'null':$this->finished); $sql.= ", ".((empty($this->finished) || $this->finished < 0)?'null':$this->finished);
$sql.= ")"; $sql.= ")";
@ -467,6 +470,12 @@ class Product extends CommonObject
if (empty($this->country_id)) $this->country_id = 0; if (empty($this->country_id)) $this->country_id = 0;
//Gencod
$this->barcode=trim($this->barcode);
// For automatic creation
if ($this->barcode == -1) $this->get_barcode($this,$this->barcode_type_code);
$this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_buy = trim($this->accountancy_code_buy);
$this->accountancy_code_sell= trim($this->accountancy_code_sell); $this->accountancy_code_sell= trim($this->accountancy_code_sell);
@ -3095,6 +3104,34 @@ class Product extends CommonObject
return ($this->type == 1 ? true : false); return ($this->type == 1 ? true : false);
} }
/**
* Attribut un code barre a partir du module de controle des codes.
* Return value is stored into this->barcode
*
* @param Product $object Object product or service
* @param int $type Barcode type (ean, isbn, ...)
* @return void
*/
function get_barcode($object,$type='')
{
global $conf;
if (! empty($conf->global->BARCODE_PRODUCT_ADDON_NUM))
{
$dirsociete=array_merge(array('/core/modules/barcode/'),$conf->modules_parts['barcode']);
foreach ($dirsociete as $dirroot)
{
$res=dol_include_once($dirroot.$conf->global->BARCODE_PRODUCT_ADDON_NUM.'.php');
if ($res) break;
}
$var = $conf->global->BARCODE_PRODUCT_ADDON_NUM;
$mod = new $var;
$this->barcode = $mod->getNextValue($object,$type);
dol_syslog(get_class($this)."::get_barcode barcode=".$this->barcode." module=".$var);
}
}
/** /**
* Initialise an instance with random values. * Initialise an instance with random values.
* Used to build previews or test instances. * Used to build previews or test instances.

View File

@ -646,8 +646,8 @@ if (GETPOST("cancel") == $langs->trans("Cancel"))
*/ */
$helpurl=''; $helpurl='';
if (GETPOST("type") == '0') $helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos'; if (GETPOST("type") == '0' || ($object->type == '0')) $helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
if (GETPOST("type") == '1') $helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios'; if (GETPOST("type") == '1' || ($object->type == '1')) $helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
if (isset($_GET['type'])) $title = $langs->trans('CardProduct'.GETPOST('type')); if (isset($_GET['type'])) $title = $langs->trans('CardProduct'.GETPOST('type'));
else $title = $langs->trans('ProductServiceCard'); else $title = $langs->trans('ProductServiceCard');
@ -695,10 +695,10 @@ else
} }
// Load object modBarCodeProduct // Load object modBarCodeProduct
if (! empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) if (! empty($conf->barcode->enabled) && ! empty($conf->global->BARCODE_PRODUCT_ADDON_NUM))
{ {
$module='mod_barcode_'.strtolower($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE); $module=strtolower($conf->global->BARCODE_PRODUCT_ADDON_NUM);
$result=dol_include_once('/core/modules/barcode/doc/'.$module.'.php'); $result=dol_include_once('/core/modules/barcode/'.$module.'.php');
if ($result > 0) if ($result > 0)
{ {
$modBarCodeProduct =new $module(); $modBarCodeProduct =new $module();

View File

@ -579,7 +579,8 @@ else
if ($res) break; if ($res) break;
} }
$modCodeClient = new $module; $modCodeClient = new $module;
$module=$conf->global->SOCIETE_CODECLIENT_ADDON; // Load object modCodeFournisseur
$module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
{ {
$module = substr($module, 0, dol_strlen($module)-4); $module = substr($module, 0, dol_strlen($module)-4);