mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Work on barcode number generation.
Normalize code for barcode module.
This commit is contained in:
parent
8abde9e11f
commit
a2afea7ba9
|
|
@ -39,13 +39,14 @@ For developers:
|
|||
- New: Triggers OPENSURVEY_CREATE, OPENSURVEY_DELETE added.
|
||||
- New: Add new hook function addMoreActionsButtons to allow a module to add/replace
|
||||
action buttons into an element.
|
||||
- New: Normalize code for barcode generation to match other modules.
|
||||
|
||||
WARNING: Following change may create regression for some external modules, but was necessary to make
|
||||
Dolibarr better:
|
||||
|
||||
- The deprecated way (with 4 parameters) to declare a new tab into a module descriptor file has been
|
||||
removed. You must now use the 6 parameters way. See file modMyModule.class.php for example.
|
||||
|
||||
-
|
||||
|
||||
***** ChangeLog for 3.5 compared to 3.4.* *****
|
||||
For users:
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ clearstatcache();
|
|||
|
||||
|
||||
// Scan list of all barcode included provided by external modules
|
||||
$dirbarcode=array_merge(array("/core/modules/barcode/"), $conf->modules_parts['barcode']);
|
||||
$dirbarcode=array_merge(array("/core/modules/barcode/doc/"), $conf->modules_parts['barcode']);
|
||||
|
||||
foreach($dirbarcode as $reldir)
|
||||
{
|
||||
|
|
@ -289,8 +289,8 @@ if (! isset($_SERVER['WINDIR']))
|
|||
print '</form>';
|
||||
}
|
||||
|
||||
// Module produits
|
||||
if (! empty($conf->societe->enabled))
|
||||
// Module products
|
||||
if (! empty($conf->product->enabled))
|
||||
{
|
||||
$var=!$var;
|
||||
print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
|
||||
|
|
@ -307,8 +307,8 @@ if (! empty($conf->societe->enabled))
|
|||
print '</form>';
|
||||
}
|
||||
|
||||
// Module produits
|
||||
if (! empty($conf->product->enabled))
|
||||
// Module thirdparty
|
||||
if (! empty($conf->societe->enabled))
|
||||
{
|
||||
$var=!$var;
|
||||
print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ if ($action == 'builddoc')
|
|||
dol_mkdir($diroutput);
|
||||
|
||||
// Generate barcode
|
||||
$dirbarcode=array_merge(array("/core/modules/barcode/"),$conf->modules_parts['barcode']);
|
||||
$dirbarcode=array_merge(array("/core/modules/barcode/doc/"),$conf->modules_parts['barcode']);
|
||||
|
||||
foreach($dirbarcode as $reldir)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/modules/barcode/phpbarcode.modules.php
|
||||
* \file htdocs/core/modules/barcode/doc/phpbarcode.modules.php
|
||||
* \ingroup barcode
|
||||
* \brief File with class to generate barcode images using php barcode generator
|
||||
*/
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/modules/barcode/modules_barcode.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/modules/barcode/modules_barcode.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // This is to include def like $genbarcode_loc and $font_loc
|
||||
|
||||
|
||||
280
htdocs/core/modules/barcode/mod_barcode_standard.php
Normal file
280
htdocs/core/modules/barcode/mod_barcode_standard.php
Normal file
|
|
@ -0,0 +1,280 @@
|
|||
<?php
|
||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2014 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2007-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* or see http://www.gnu.org/
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/modules/product/mod_barcode_standard.php
|
||||
* \ingroup barcode
|
||||
* \brief File of class to manage barcode numbering with standard rule
|
||||
*/
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/modules/barcode/modules_barcode.class.php';
|
||||
|
||||
|
||||
/**
|
||||
* Class to manage barcode with standard rule
|
||||
*/
|
||||
class mod_barcode_standard extends ModeleNumRefBarCode
|
||||
{
|
||||
var $nom='Standard'; // Nom du modele
|
||||
var $code_modifiable; // Code modifiable
|
||||
var $code_modifiable_invalide; // Code modifiable si il est invalide
|
||||
var $code_modifiable_null; // Code modifiables si il est null
|
||||
var $code_null; // Code facultatif
|
||||
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
|
||||
var $code_auto; // Numerotation automatique
|
||||
|
||||
var $searchcode; // String de recherche
|
||||
var $numbitcounter; // Nombre de chiffres du compteur
|
||||
var $prefixIsRequired; // Le champ prefix du tiers doit etre renseigne quand on utilise {pre}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
$this->code_null = 0;
|
||||
$this->code_modifiable = 1;
|
||||
$this->code_modifiable_invalide = 1;
|
||||
$this->code_modifiable_null = 1;
|
||||
$this->code_auto = 1;
|
||||
$this->prefixIsRequired = 0;
|
||||
}
|
||||
|
||||
|
||||
/** Return description of module
|
||||
*
|
||||
* @param string $langs Object langs
|
||||
* @return string Description of module
|
||||
*/
|
||||
function info($langs)
|
||||
{
|
||||
global $conf, $mc;
|
||||
global $form;
|
||||
|
||||
$langs->load("products");
|
||||
|
||||
$disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled="disabled"' : '');
|
||||
|
||||
$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
|
||||
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||
$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
|
||||
$texte.= '<input type="hidden" name="param1" value="BARCODE_STANDARD_MASK">';
|
||||
$texte.= '<table class="nobordernopadding" width="100%">';
|
||||
|
||||
$tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Product"),$langs->transnoentities("Product"));
|
||||
$tooltip.=$langs->trans("GenericMaskCodes3");
|
||||
$tooltip.=$langs->trans("GenericMaskCodes4c");
|
||||
$tooltip.=$langs->trans("GenericMaskCodes5");
|
||||
|
||||
// Mask parameter
|
||||
$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("BarCodeModel").'):</td>';
|
||||
$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.(! empty($conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT)?$conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT:'').'"'.$disabled.'>',$tooltip,1,1).'</td>';
|
||||
$texte.= '<td align="left" rowspan="2"> <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>';
|
||||
$texte.= '</tr>';
|
||||
|
||||
$texte.= '</table>';
|
||||
$texte.= '</form>';
|
||||
|
||||
return $texte;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an example of result returned by getNextValue
|
||||
*
|
||||
* @param Translate $langs Object langs
|
||||
* @param product $objproduct Object product
|
||||
* @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect)
|
||||
* @return string Return string example
|
||||
*/
|
||||
function getExample($langs,$objproduct=0,$type=-1)
|
||||
{
|
||||
if ($type == 0 || $type == -1)
|
||||
{
|
||||
$exampleproduct = $this->getNextValue($objproduct,0);
|
||||
if (! $exampleproduct)
|
||||
{
|
||||
$exampleproduct = $langs->trans('NotConfigured');
|
||||
}
|
||||
if($exampleproduct=="ErrorBadMask")
|
||||
{
|
||||
$langs->load("errors");
|
||||
$exampleproduct=$langs->trans($exampleproduct);
|
||||
}
|
||||
}
|
||||
if ($type == 1 || $type == -1)
|
||||
{
|
||||
$exampleservice = $this->getNextValue($objproduct,1);
|
||||
if (! $exampleservice)
|
||||
{
|
||||
$exampleservice = $langs->trans('NotConfigured');
|
||||
}
|
||||
if($exampleservice=="ErrorBadMask")
|
||||
{
|
||||
$langs->load("errors");
|
||||
$exampleservice=$langs->trans($exampleservice);
|
||||
}
|
||||
}
|
||||
|
||||
if ($type == 0) return $exampleproduct;
|
||||
if ($type == 1) return $exampleservice;
|
||||
return $exampleproduct.'<br>'.$exampleservice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return next value
|
||||
*
|
||||
* @param Product $objproduct Object product
|
||||
* @param string $type type of barcode (EAN, ISBN, ...)
|
||||
* @return string Value if OK, '' if module not configured, <0 if KO
|
||||
*/
|
||||
function getNextValue($objproduct,$type='')
|
||||
{
|
||||
global $db,$conf;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
|
||||
|
||||
// TODO
|
||||
|
||||
// Get Mask value
|
||||
$mask = '';
|
||||
if (! empty($conf->global->BARCODE_STANDARD_MASK)) $mask = $conf->global->BARCODE_STANDARD_MASK;
|
||||
|
||||
if (empty($mask))
|
||||
{
|
||||
$this->error='NotConfigured';
|
||||
return '';
|
||||
}
|
||||
|
||||
$field='barcode';$where='';
|
||||
|
||||
$now=dol_now();
|
||||
|
||||
$numFinal=get_next_value($db,$mask,'product',$field,$where,'',$now);
|
||||
|
||||
return $numFinal;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
* @param string &$code Code to check/correct
|
||||
* @param Product $product Object product
|
||||
* @param int $type 0 = customer/prospect , 1 = supplier
|
||||
* @return int 0 if OK
|
||||
* -1 ErrorBadCustomerCodeSyntax
|
||||
* -2 ErrorCustomerCodeRequired
|
||||
* -3 ErrorCustomerCodeAlreadyUsed
|
||||
* -4 ErrorPrefixRequired
|
||||
*/
|
||||
function verif($db, &$code, $product, $type)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
|
||||
|
||||
$result=0;
|
||||
$code = strtoupper(trim($code));
|
||||
|
||||
if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
|
||||
{
|
||||
$result=0;
|
||||
}
|
||||
else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
|
||||
{
|
||||
$result=-2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get Mask value
|
||||
$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)
|
||||
{
|
||||
$this->error='NotConfigured';
|
||||
return '';
|
||||
}
|
||||
|
||||
$result=check_value($mask,$code);
|
||||
}
|
||||
|
||||
dol_syslog("mod_codeclient_elephant::verif type=".$type." result=".$result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renvoi si un code est pris ou non (par autre tiers)
|
||||
*
|
||||
* @param DoliDB $db Handler acces base
|
||||
* @param string $code Code a verifier
|
||||
* @param Product $product Objet product
|
||||
* @return int 0 if available, <0 if KO
|
||||
*/
|
||||
function verif_dispo($db, $code, $product)
|
||||
{
|
||||
$sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product";
|
||||
$sql.= " WHERE ref = '".$code."'";
|
||||
if ($product->id > 0) $sql.= " AND rowid <> ".$product->id;
|
||||
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($db->num_rows($resql) == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -1,8 +1,5 @@
|
|||
<?php
|
||||
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
||||
* Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
/* Copyright (C) 2014 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -20,16 +17,15 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/modules/barcode/modules_barcode.php
|
||||
* \file htdocs/core/modules/barcode/modules_barcode.class.php
|
||||
* \ingroup barcode
|
||||
* \brief Fichier contenant la classe mere de generation des codes barres
|
||||
* \brief File with parent classes for barcode document modules and numbering modules
|
||||
*/
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
|
||||
|
||||
|
||||
/**
|
||||
* \class ModeleBarCode
|
||||
* \brief Classe mere des modeles de code barre
|
||||
* Parent class for barcode document modules
|
||||
*/
|
||||
abstract class ModeleBarCode
|
||||
{
|
||||
|
|
@ -46,6 +42,18 @@ abstract class ModeleBarCode
|
|||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parent class for barcode numbering modules
|
||||
*/
|
||||
abstract class ModeleNumRefBarCode
|
||||
{
|
||||
var $error='';
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
|
||||
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
||||
|
|
@ -683,16 +683,32 @@ else
|
|||
{
|
||||
$module = substr($module, 0, dol_strlen($module)-4);
|
||||
}
|
||||
dol_include_once('/core/modules/product/'.$module.'.php');
|
||||
$modCodeProduct = new $module;
|
||||
$result=dol_include_once('/core/modules/product/'.$module.'.php');
|
||||
if ($result > 0)
|
||||
{
|
||||
$modCodeProduct = new $module();
|
||||
}
|
||||
|
||||
// Load object modBarCodeProduct
|
||||
if (! empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE))
|
||||
{
|
||||
$module='mod_barcode_'.strtolower($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE);
|
||||
$result=dol_include_once('/core/modules/barcode/doc/'.$module.'.php');
|
||||
if ($result > 0)
|
||||
{
|
||||
$modBarCodeProduct =new $module();
|
||||
}
|
||||
}
|
||||
|
||||
print '<form action="fiche.php" method="post">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
print '<input type="hidden" name="type" value="'.$type.'">'."\n";
|
||||
if (! empty($modCodeProduct->code_auto))
|
||||
print '<input type="hidden" name="code_auto" value="1">';
|
||||
|
||||
if (! empty($modBarCodeProduct->code_auto))
|
||||
print '<input type="hidden" name="barcode_auto" value="1">';
|
||||
|
||||
if ($type==1) $title=$langs->trans("NewService");
|
||||
else $title=$langs->trans("NewProduct");
|
||||
print_fiche_titre($title);
|
||||
|
|
@ -700,8 +716,7 @@ else
|
|||
print '<table class="border" width="100%">';
|
||||
print '<tr>';
|
||||
$tmpcode='';
|
||||
if (! empty($modCodeProduct->code_auto))
|
||||
$tmpcode=$modCodeProduct->getNextValue($object,$type);
|
||||
if (! empty($modCodeProduct->code_auto)) $tmpcode=$modCodeProduct->getNextValue($object,$type);
|
||||
print '<td class="fieldrequired" width="20%">'.$langs->trans("Ref").'</td><td colspan="3"><input name="ref" size="20" maxlength="128" value="'.dol_escape_htmltag(GETPOST('ref')?GETPOST('ref'):$tmpcode).'">';
|
||||
if ($_error)
|
||||
{
|
||||
|
|
@ -742,7 +757,7 @@ else
|
|||
print $formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1);
|
||||
print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>';
|
||||
$tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode;
|
||||
//if (empty($tmpcode) $tmpcode=$modBarCodeProduct->getNextValue($object,0);
|
||||
if (! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type);
|
||||
print '<input size="40" type="text" name="barcode" value="'.$tmpcode.'">';
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ if ($modulepart == 'barcode')
|
|||
exit;
|
||||
}
|
||||
|
||||
$dirbarcode=array_merge(array("/core/modules/barcode/"),$conf->modules_parts['barcode']);
|
||||
$dirbarcode=array_merge(array("/core/modules/barcode/doc/"),$conf->modules_parts['barcode']);
|
||||
|
||||
$result=0;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user