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,9 +353,12 @@ print "</table>\n";
print '<br>'; print '<br>';
// Select barcode numbering module
print_titre($langs->trans("BarCodeNumberManager"));
// Select barcode numbering module
if ($conf->produit->enabled)
{
print_titre($langs->trans("BarCodeNumberManager")." (".$langs->trans("Product").")");
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
@ -375,7 +380,7 @@ foreach ($dirbarcodenum as $dirroot)
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (preg_match('/^mod_barcode_.*php$/', $file)) if (preg_match('/^mod_barcode_product_.*php$/', $file))
{ {
$file = substr($file, 0, dol_strlen($file)-4); $file = substr($file, 0, dol_strlen($file)-4);
@ -396,15 +401,15 @@ foreach ($dirbarcodenum as $dirroot)
print '</td>'; print '</td>';
print '<td class="nowrap">'.$modBarCode->getExample($langs)."</td>\n"; print '<td class="nowrap">'.$modBarCode->getExample($langs)."</td>\n";
if ($conf->global->BARCODE_ADDON_NUM == "$file") if ($conf->global->BARCODE_PRODUCT_ADDON_NUM == "$file")
{ {
print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeoff&value='.$file.'">'; print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproductoff&value='.$file.'">';
print img_picto($langs->trans("Activated"),'switch_on'); print img_picto($langs->trans("Activated"),'switch_on');
print '</a></td>'; print '</a></td>';
} }
else else
{ {
print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeon&value='.$file.'">'; print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbarcodeproducton&value='.$file.'">';
print img_picto($langs->trans("Disabled"),'switch_off'); print img_picto($langs->trans("Disabled"),'switch_off');
print '</a></td>'; print '</a></td>';
} }
@ -419,6 +424,7 @@ foreach ($dirbarcodenum as $dirroot)
} }
} }
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,22 +158,6 @@ 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
* *
@ -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,13 +201,13 @@ 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

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)
@ -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).")";
@ -329,7 +332,7 @@ class Product extends CommonObject
$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");
@ -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);