From 44b84b21772b694f6293c3f26f956a55226aee58 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 9 Aug 2012 01:41:55 +0200 Subject: [PATCH 1/5] task # 326 : Add a numbering module to suggest automatically a product ref --- ChangeLog | 1 + .../product/mod_codeproduct_elephant.php | 302 ++++++++++++++++++ .../product/mod_codeproduct_leopard.php | 123 +++++++ .../modules/product/modules_product.class.php | 213 ++++++++++++ htdocs/install/mysql/data/llx_const.sql | 4 + htdocs/langs/fr_FR/admin.lang | 3 + htdocs/langs/fr_FR/companies.lang | 2 +- htdocs/langs/fr_FR/products.lang | 4 +- htdocs/product/admin/product.php | 137 ++++++++ htdocs/product/fiche.php | 14 +- 10 files changed, 800 insertions(+), 3 deletions(-) create mode 100644 htdocs/core/modules/product/mod_codeproduct_elephant.php create mode 100644 htdocs/core/modules/product/mod_codeproduct_leopard.php create mode 100644 htdocs/core/modules/product/modules_product.class.php diff --git a/ChangeLog b/ChangeLog index bddd25d5dd1..7c180afdb68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -38,6 +38,7 @@ For users: - New: Update libs/tools/logo for DoliWamp. - Fix: No images into product description lines as PDF generation does not work with this. +- New: [ task #326 ]: Add a numbering module to suggest automatically a product ref For developers: - New: Add webservice for thirdparty creation and list. diff --git a/htdocs/core/modules/product/mod_codeproduct_elephant.php b/htdocs/core/modules/product/mod_codeproduct_elephant.php new file mode 100644 index 00000000000..437e9e6f4e8 --- /dev/null +++ b/htdocs/core/modules/product/mod_codeproduct_elephant.php @@ -0,0 +1,302 @@ + + * Copyright (C) 2006-2009 Laurent Destailleur + * Copyright (C) 2007-2012 Regis Houssin + * Copyright (C) 2011 Juanjo Menent + * + * 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 2 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 . + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/core/modules/product/mod_codeproduct_elephant.php + * \ingroup product + * \brief File of class to manage product code with elephant rule + */ + +require_once(DOL_DOCUMENT_ROOT."/core/modules/product/modules_product.class.php"); + + +/** + * \class mod_codeproduct_elephant + * \brief Class to manage product code with elephant rule + */ +class mod_codeproduct_elephant extends ModeleProductCode +{ + var $nom='Elephant'; // 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; + + $langs->load("products"); + + $form = new Form($this->db); + + $disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled="disabled"' : ''); + + $texte = $langs->trans('GenericNumRefModelDesc')."
\n"; + $texte.= '
'; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + + $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Product"),$langs->transnoentities("Product")); + $tooltip.=$langs->trans("GenericMaskCodes3"); + $tooltip.=$langs->trans("GenericMaskCodes4c"); + $tooltip.=$langs->trans("GenericMaskCodes5"); + + // Parametrage du prefix customers + $texte.= ''; + $texte.= ''; + + $texte.= ''; + + $texte.= ''; + + // Parametrage du prefix suppliers + $texte.= ''; + $texte.= ''; + $texte.= ''; + + $texte.= '
'.$langs->trans("Mask").' ('.$langs->trans("ProductCodeModel").'):'.$form->textwithpicto('',$tooltip,1,1).' 
'.$langs->trans("Mask").' ('.$langs->trans("ServiceCodeModel").'):'.$form->textwithpicto('',$tooltip,1,1).'
'; + $texte.= '
'; + + 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.'
'.$exampleservice; + } + + /** + * Return next value + * + * @param Product $objproduct Object product + * @param int $type Produit ou service (0:product, 1:service) + * @return string Value if OK, '' if module not configured, <0 if KO + */ + function getNextValue($objproduct=0,$type=-1) + { + global $db,$conf; + + require_once(DOL_DOCUMENT_ROOT ."/core/lib/functions2.lib.php"); + + // Get Mask value + $mask = ''; + if ($type==0) $mask = $conf->global->PRODUCT_ELEPHANT_MASK_PRODUCT; + if ($type==1) $mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE; + if (! $mask) + { + $this->error='NotConfigured'; + return ''; + } + + $field='';$where=''; + if ($type == 0) + { + $field = 'ref'; + //$where = ' AND client in (1,2)'; + } + else if ($type == 1) + { + $field = 'ref'; + //$where = ' AND fournisseur = 1'; + } + else return -1; + + $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->PRODUCT_ELEPHANT_MASK_PRODUCT; + if (preg_match('/\{pre\}/i',$mask)) return 1; + + $mask = $conf->global->PRODUCT_ELEPHANT_MASK_SERVICE; + 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; + } + + } + +} + +?> diff --git a/htdocs/core/modules/product/mod_codeproduct_leopard.php b/htdocs/core/modules/product/mod_codeproduct_leopard.php new file mode 100644 index 00000000000..d1a6b529da9 --- /dev/null +++ b/htdocs/core/modules/product/mod_codeproduct_leopard.php @@ -0,0 +1,123 @@ + + * Copyright (C) 2006-2009 Laurent Destailleur + * + * 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 2 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 . + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/core/modules/product/mod_codeproduct_leopard.php + * \ingroup product + * \brief Fichier de la classe des gestion leopard des codes produits + */ + +require_once(DOL_DOCUMENT_ROOT."/core/modules/product/modules_product.class.php"); + + +/** + * \class mod_codeproduct_leopard + * \brief Classe permettant la gestion leopard des codes produits + */ +class mod_codeproduct_leopard extends ModeleProductCode +{ + /* + * Attention ce module est utilise par defaut si aucun module n'a + * ete definit dans la configuration + * + * Le fonctionnement de celui-ci doit donc rester le plus ouvert possible + */ + + var $nom='Leopard'; // 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 + + + /** + * Constructor + */ + function __construct() + { + $this->code_null = 1; + $this->code_modifiable = 1; + $this->code_modifiable_invalide = 1; + $this->code_modifiable_null = 1; + $this->code_auto = 0; + } + + + /** Return description of module + * + * @param string $langs Object langs + * @return string Description of module + */ + function info($langs) + { + return $langs->trans("LeopardNumRefModelDesc"); + } + + + /** + * Return an example of result returned by getNextValue + * + * @param product $objproduct Object product + * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) + * @return string Return next value + */ + function getNextValue($objproduct=0,$type=-1) + { + global $langs; + return ''; + } + + + /** + * 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 = product , 1 = service + * @return int 0 if OK + * -1 ErrorBadProductCodeSyntax + * -2 ErrorProductCodeRequired + * -3 ErrorProductCodeAlreadyUsed + * -4 ErrorPrefixRequired + */ + function verif($db, &$code, $product, $type) + { + global $conf; + + $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; + } + + dol_syslog("mod_codeproduct_leopard::verif type=".$type." result=".$result); + return $result; + } +} + +?> diff --git a/htdocs/core/modules/product/modules_product.class.php b/htdocs/core/modules/product/modules_product.class.php new file mode 100644 index 00000000000..26a5ad6aab4 --- /dev/null +++ b/htdocs/core/modules/product/modules_product.class.php @@ -0,0 +1,213 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2012 Regis Houssin + * + * 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 2 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 . + * or see http://www.gnu.org/ + */ + + +/** + * \class ModeleProductCode + * \brief Parent class for product code generators + */ +abstract class ModeleProductCode +{ + var $error=''; + + /** Renvoi la description par defaut du modele de numerotation + * + * @param Translate $langs Object langs + * @return string Texte descripif + */ + function info($langs) + { + $langs->load("bills"); + return $langs->trans("NoDescription"); + } + + /** Renvoi nom module + * + * @param Translate $langs Object langs + * @return string Nom du module + */ + function getNom($langs) + { + return $this->nom; + } + + + /** Renvoi un exemple de numerotation + * + * @param Translate $langs Object langs + * @return string Example + */ + function getExample($langs) + { + $langs->load("bills"); + return $langs->trans("NoExample"); + } + + /** Test si les numeros deja en vigueur dans la base ne provoquent pas de + * de conflits qui empechera cette numerotation de fonctionner. + * + * @return boolean false si conflit, true si ok + */ + function canBeActivated() + { + return true; + } + + /** + * Return next value available + * + * @param Product $objproduct Object product + * @param int $type Type + * @return string Value + */ + function getNextValue($objproduct=0,$type=-1) + { + global $langs; + return $langs->trans("Function_getNextValue_InModuleNotWorking"); + } + + + /** Return version of module + * + * @return string Version + */ + function getVersion() + { + global $langs; + $langs->load("admin"); + + if ($this->version == 'development') return $langs->trans("VersionDevelopment"); + if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); + if ($this->version == 'dolibarr') return DOL_VERSION; + return $langs->trans("NotAvailable"); + } + + /** + * Renvoi la liste des modeles de numérotation + * + * @param DoliDB $db Database handler + * @param string $maxfilenamelength Max length of value to show + * @return array List of numbers + */ + static function liste_modeles($db,$maxfilenamelength=0) + { + $liste=array(); + $sql =""; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($resql); + $liste[$row[0]]=$row[1]; + $i++; + } + } + else + { + return -1; + } + return $liste; + } + + /** + * Return description of module parameters + * + * @param Translate $langs Output language + * @param Product $product Product object + * @param int $type -1=Nothing, 0=Customer, 1=Supplier + * @return string HTML translated description + */ + function getToolTip($langs,$product,$type) + { + global $conf; + + $langs->load("admin"); + + $s=''; + if ($type == -1) $s.=$langs->trans("Name").': '.$this->nom.'
'; + if ($type == -1) $s.=$langs->trans("Version").': '.$this->getVersion().'
'; + if ($type == 0) $s.=$langs->trans("ProductCodeDesc").'
'; + if ($type == 1) $s.=$langs->trans("ServiceCodeDesc").'
'; + if ($type != -1) $s.=$langs->trans("ValidityControledByModule").': '.$this->getNom($langs).'
'; + $s.='
'; + $s.=''.$langs->trans("ThisIsModuleRules").':
'; + if ($type == 0) + { + $s.=$langs->trans("RequiredIfProduct").': '; + if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.=''; + $s.=yn(!$this->code_null,1,2); + if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.=' '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')'; + $s.='
'; + } + if ($type == 1) + { + $s.=$langs->trans("RequiredIfService").': '; + if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.=''; + $s.=yn(!$this->code_null,1,2); + if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.=' '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')'; + $s.='
'; + } + if ($type == -1) + { + $s.=$langs->trans("Required").': '; + if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.=''; + $s.=yn(!$this->code_null,1,2); + if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.=' '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')'; + $s.='
'; + } + $s.=$langs->trans("CanBeModifiedIfOk").': '; + $s.=yn($this->code_modifiable,1,2); + $s.='
'; + $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,2).'
'; + $s.=$langs->trans("AutomaticCode").': '.yn($this->code_auto,1,2).'
'; + $s.='
'; + if ($type == 0 || $type == -1) + { + $nextval=$this->getNextValue($product,0); + if (empty($nextval)) $nextval=$langs->trans("Undefined"); + $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Product").')':'').': '.$nextval.'
'; + } + if ($type == 1 || $type == -1) + { + $nextval=$this->getNextValue($product,1); + if (empty($nextval)) $nextval=$langs->trans("Undefined"); + $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Service").')':'').': '.$nextval.''; + } + return $s; + } + + /** + * Check if mask/numbering use prefix + * + * @return int 0=no, 1=yes + */ + function verif_prefixIsUsed() + { + return 0; + } + +} + +?> diff --git a/htdocs/install/mysql/data/llx_const.sql b/htdocs/install/mysql/data/llx_const.sql index 18a81459535..8d7434e80a6 100644 --- a/htdocs/install/mysql/data/llx_const.sql +++ b/htdocs/install/mysql/data/llx_const.sql @@ -89,3 +89,7 @@ insert into llx_const (name, value, type, note, visible) values('SOCIETE_CODECOM -- insert into llx_const (name, value, type, note, visible) values ('MAILING_EMAIL_FROM','dolibarr@domain.com','chaine','EMail emmetteur pour les envois d emailings',0); +-- +-- Product +-- +insert into llx_const (name, value, type, note, visible) values('PRODUCT_CODEPRODUCT_ADDON','mod_codeproduct_leopard','yesno','Module to control product codes',0); \ No newline at end of file diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index a6b91499d6b..3f4b5b69751 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -278,6 +278,7 @@ GenericMaskCodes2= {cccc} le code client sur n lettres
{cccc000}Les espaces ne sont pas permis.
GenericMaskCodes4a= Exemple sur la 99eme %s du tiers LaCompanie faite le 31/03/2007:
GenericMaskCodes4b= Exemple sur un tiers créé le 31/03/2007:
+GenericMaskCodes4c= Exemple sur un produit/service créé le 31/03/2007:
GenericMaskCodes5= ABC{yy}{mm}-{000000} donnera ABC0703-000099
{0000+100}-XXX/{dd}/YYY donnera 0199-XXX/31/YYY GenericNumRefModelDesc= Renvoie un numéro personnalisable selon un masque à définir. ServerAvailableOnIPOrPort= Serveur disponible à l'adresse %s sur le port %s @@ -1144,6 +1145,8 @@ UseSearchToSelectProduct= Utiliser un formulaire de recherche pour le choix d'un UseEcoTaxeAbility= Prise en charge des éco-taxes (DEEE) SetDefaultBarcodeTypeProducts= Type de code-barres utilisé par défaut pour les produits SetDefaultBarcodeTypeThirdParties= Type de code-barres utilisé par défaut pour les tiers +ProductCodeChecker= Modèle de numérotation des produits / services +ProductOtherConf= Paramètres des produits / services ##### Syslog ##### SyslogSetup= Configuration du module Logs et traces SyslogOutput= Sortie des log diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang index acd7e4eeacf..ae6b8c44369 100644 --- a/htdocs/langs/fr_FR/companies.lang +++ b/htdocs/langs/fr_FR/companies.lang @@ -394,4 +394,4 @@ ActivityStateFilter=Statut d'activité # Monkey MonkeyNumRefModelDesc=Renvoie le numéro sous la forme %syymm-nnnn pour les codes clients et %syymm-nnnn pour les codes fournisseurs où yy est l'année, mm le mois et nnnn un compteur séquentiel sans rupture et sans remise à 0. # Leopard -LeopardNumRefModelDesc=Code client/fournisseur libre sans vérification. Peut être modifié à tout moment. +LeopardNumRefModelDesc=Code libre sans vérification. Peut être modifié à tout moment. diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index 2d3dfd12b2d..4484e5686c8 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -169,4 +169,6 @@ SuppliersPrices=Prix fournisseurs CustomCode=Code douane CountryOrigin=Pays d'origine HiddenIntoCombo=Caché dans les listes -Nature=Nature \ No newline at end of file +Nature=Nature +ProductCodeModel=Modèle de code produit +ServiceCodeModel=Modèle de code service \ No newline at end of file diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index 9c12199496c..eddac8c041d 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -46,6 +46,47 @@ $value = GETPOST('value','alpha'); /* * Actions */ +if ($action == 'setcodeproduct') +{ + if (dolibarr_set_const($db, "PRODUCT_CODEPRODUCT_ADDON",$value,'chaine',0,'',$conf->entity) > 0) + { + Header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + dol_print_error($db); + } +} + +// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) +if ($action == 'setModuleOptions') +{ + $post_size=count($_POST); + + $db->begin(); + + for($i=0;$i < $post_size;$i++) + { + if (array_key_exists('param'.$i,$_POST)) + { + $param=GETPOST("param".$i,'alpha'); + $value=GETPOST("value".$i,'alpha'); + if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } + } + if (! $error) + { + $db->commit(); + $mesg = "".$langs->trans("SetupSaved").""; + } + else + { + $db->rollback(); + $mesg = "".$langs->trans("Error").""; + } +} if ($action == 'nbprod') { @@ -136,6 +177,102 @@ $head = product_admin_prepare_head(); dol_fiche_head($head, 'general', $tab, 0, 'product'); $form=new Form($db); + +/* + * Module to manage product / services code + */ +$dirproduct=array('/core/modules/product/'); + +print_titre($langs->trans("ProductCodeChecker")); + +print ''."\n"; +print ''."\n"; +print ' '; +print ' '; +print ' '; +print ' '; +print ' '; +print "\n"; + +$var = true; +foreach ($dirproduct as $dirroot) +{ + $dir = dol_buildpath($dirroot,0); + + $handle = @opendir($dir); + if (is_resource($handle)) + { + // Loop on each module find in opened directory + while (($file = readdir($handle))!==false) + { + if (substr($file, 0, 16) == 'mod_codeproduct_' && substr($file, -3) == 'php') + { + $file = substr($file, 0, dol_strlen($file)-4); + + try { + dol_include_once($dirroot.$file.".php"); + } + catch(Exception $e) + { + dol_syslog($e->getMessage(), LOG_ERR); + } + + $modCodeProduct = new $file; + + // Show modules according to features level + if ($modCodeProduct->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; + if ($modCodeProduct->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; + + $var = !$var; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + + if ($conf->global->PRODUCT_CODEPRODUCT_ADDON == "$file") + { + print '\n"; + } + else + { + // @todo : What's that ? + /*$disabled = false; + if (! empty($conf->multicompany->enabled) && (is_object($mc) && ! empty($mc->sharings['referent']) && $mc->sharings['referent'] == $conf->entity) ? false : true); + print '';*/ + print ''; + } + + print ''; + + print ''; + } + } + closedir($handle); + } +} +print '
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Example").''.$langs->trans("Status").''.$langs->trans("Infos").'
'.$modCodeProduct->nom.''.$modCodeProduct->info($langs).''.$modCodeProduct->getExample($langs).''."\n"; + print img_picto($langs->trans("Activated"),'switch_on'); + print "'; + if (! $disabled) print ''; + print img_picto($langs->trans("Disabled"),'switch_off'); + if (! $disabled) print ''; + print ''; + print ''; + print img_picto($langs->trans("Disabled"),'switch_off'); + print ''; + print ''; + $s=$modCodeProduct->getToolTip($langs,null,-1); + print $form->textwithpicto('',$s,1); + print '
'; + +/* + * Other conf + */ + +print "
"; + +print_titre($langs->trans("ProductOtherConf")); + $var=true; print ''; print ''; diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index ce4573e47a5..4aa49ee651a 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -696,11 +696,22 @@ else { //WYSIWYG Editor require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"); + + // Load object modCodeProduct + $module=$conf->global->PRODUCT_CODEPRODUCT_ADDON; + if (! $module) dolibarr_error('',$langs->trans("ErrorModuleThirdPartyCodeInCompanyModuleNotDefined")); + if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') + { + $module = substr($module, 0, dol_strlen($module)-4); + } + dol_include_once('/core/modules/product/'.$module.".php"); + $modCodeProduct = new $module; print ''; print ''; print ''; print ''."\n"; + if ($modCodeProduct->code_auto) print ''; if ($type==1) $title=$langs->trans("NewService"); else $title=$langs->trans("NewProduct"); @@ -710,7 +721,8 @@ else print '
'; print ''; - print '';*/ - print ''; } From b3b598c068f5be3050b71114c3a54f949fcd4c93 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 9 Aug 2012 18:33:45 +0200 Subject: [PATCH 3/5] New input reason into dictionnary. --- htdocs/install/mysql/data/llx_c_input_reason.sql | 3 ++- htdocs/install/mysql/migration/3.2.0-3.3.0.sql | 4 ++-- htdocs/langs/en_US/dict.lang | 6 +++++- htdocs/langs/fr_FR/dict.lang | 4 ++++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/htdocs/install/mysql/data/llx_c_input_reason.sql b/htdocs/install/mysql/data/llx_c_input_reason.sql index 703cbd7bcb2..b8919b8a43e 100755 --- a/htdocs/install/mysql/data/llx_c_input_reason.sql +++ b/htdocs/install/mysql/data/llx_c_input_reason.sql @@ -28,6 +28,7 @@ INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES ( 4, 'SRC_CAMP_F INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES ( 5, 'SRC_COMM', 'Commercial contact', 1); INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES ( 6, 'SRC_SHOP', 'Shop contact', 1); INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES ( 7, 'SRC_CAMP_EMAIL', 'EMailing campaign', 1); -INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES ( 8, 'SRC_WOM', 'Word of mount', 1); +INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES ( 8, 'SRC_WOM', 'Word of mouth', 1); INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES ( 9, 'SRC_PARTNER', 'Partner', 1); INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (10, 'SRC_EMPLOYEE', 'Employee', 1); +INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (11, 'SRC_SPONSORING', 'Sponsorship', 1); diff --git a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql index 88401d22179..a2213e7aaaf 100755 --- a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql +++ b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql @@ -26,10 +26,10 @@ insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 2 insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 276, 27, '2.1','0','VAT super-reduced rate',1); insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 277, 27, '7','0','VAT reduced rate',1); -INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES ( 8, 'SRC_WOM', 'Word of mount', 1); +INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES ( 8, 'SRC_WOM', 'Word of mouth', 1); INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES ( 9, 'SRC_PARTNER', 'Partner', 1); INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (10, 'SRC_EMPLOYEE', 'Employee', 1); - +INSERT INTO llx_c_input_reason (rowid,code,label,active) VALUES (11, 'SRC_SPONSORING', 'Sponsoring', 1); ALTER TABLE llx_commande_fournisseur CHANGE COLUMN date_cloture date_approve datetime; ALTER TABLE llx_commande_fournisseur CHANGE COLUMN fk_user_cloture fk_user_approve integer; diff --git a/htdocs/langs/en_US/dict.lang b/htdocs/langs/en_US/dict.lang index 36949159b52..7db388745c6 100644 --- a/htdocs/langs/en_US/dict.lang +++ b/htdocs/langs/en_US/dict.lang @@ -300,4 +300,8 @@ DemandReasonTypeSRC_CAMP_EMAIL=EMailing campaign DemandReasonTypeSRC_CAMP_PHO=Phone campaign DemandReasonTypeSRC_CAMP_FAX=Fax campaign DemandReasonTypeSRC_COMM=Commercial contact -DemandReasonTypeSRC_SHOP=Shop contact \ No newline at end of file +DemandReasonTypeSRC_SHOP=Shop contact +DemandReasonTypeSRC_WOM=Word of mouth +DemandReasonTypeSRC_PARTNER=Partner +DemandReasonTypeSRC_EMPLOYEE=Employee +DemandReasonTypeSRC_SPONSORSHIP=Sponsorship \ No newline at end of file diff --git a/htdocs/langs/fr_FR/dict.lang b/htdocs/langs/fr_FR/dict.lang index 18a1f8f504d..d8b066765cd 100644 --- a/htdocs/langs/fr_FR/dict.lang +++ b/htdocs/langs/fr_FR/dict.lang @@ -305,3 +305,7 @@ DemandReasonTypeSRC_CAMP_PHO=Campagne Téléphonique DemandReasonTypeSRC_CAMP_FAX=Campagne Fax DemandReasonTypeSRC_COMM=Contact commercial DemandReasonTypeSRC_SHOP=Contact en magazin +DemandReasonTypeSRC_WOM=Bouche à oreille +DemandReasonTypeSRC_PARTNER=Partenaire +DemandReasonTypeSRC_EMPLOYEE=Employé +DemandReasonTypeSRC_SPONSORSHIP=Parrainage/Sponsoring From a7d9f13287b17a5982261a962f910fdd40c88416 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 9 Aug 2012 18:45:56 +0200 Subject: [PATCH 4/5] Qual: Removed deprecated columns --- htdocs/install/mysql/migration/3.2.0-3.3.0.sql | 3 +++ htdocs/install/mysql/tables/llx_societe.sql | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql index a2213e7aaaf..68166b2292f 100755 --- a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql +++ b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql @@ -16,6 +16,9 @@ -- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); ALTER TABLE llx_societe ADD COLUMN idprof6 varchar(128) after idprof5; +ALTER TABLE llx_societe DROP COLUMN fk_secteur; +ALTER TABLE llx_societe DROP COLUMN description; +ALTER TABLE llx_societe DROP COLUMN services; -- Monaco VAT Rates insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 271, 27,'19.6','0','VAT standard rate (France hors DOM-TOM)',1); diff --git a/htdocs/install/mysql/tables/llx_societe.sql b/htdocs/install/mysql/tables/llx_societe.sql index a791880eb96..de753f26bbd 100644 --- a/htdocs/install/mysql/tables/llx_societe.sql +++ b/htdocs/install/mysql/tables/llx_societe.sql @@ -49,7 +49,6 @@ create table llx_societe fax varchar(20), -- fax number url varchar(255), -- email varchar(128), -- - fk_secteur integer DEFAULT 0, -- fk_effectif integer DEFAULT 0, -- fk_typent integer DEFAULT 0, -- fk_forme_juridique integer DEFAULT 0, -- juridical status @@ -62,10 +61,8 @@ create table llx_societe idprof6 varchar(128), -- IDProf6: nu for france tva_intra varchar(20), -- tva capital real, -- capital de la societe - description text, -- fk_stcomm integer DEFAULT 0 NOT NULL, -- commercial statut note text, -- - services tinyint DEFAULT 0, -- prefix_comm varchar(5), -- prefix commercial client tinyint DEFAULT 0, -- client 0/1/2 fournisseur tinyint DEFAULT 0, -- fournisseur 0/1 From 84d5b75518af34675e39a94d675556ab55b545ff Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 9 Aug 2012 19:04:39 +0200 Subject: [PATCH 5/5] New: Add field tms into llx_bank --- htdocs/install/mysql/migration/3.2.0-3.3.0.sql | 2 ++ htdocs/install/mysql/tables/llx_bank.sql | 1 + 2 files changed, 3 insertions(+) diff --git a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql index 68166b2292f..fd93777605c 100755 --- a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql +++ b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql @@ -20,6 +20,8 @@ ALTER TABLE llx_societe DROP COLUMN fk_secteur; ALTER TABLE llx_societe DROP COLUMN description; ALTER TABLE llx_societe DROP COLUMN services; +ALTER TABLE llx_bank ADD COLUMN tms timestamp after datec; + -- Monaco VAT Rates insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 271, 27,'19.6','0','VAT standard rate (France hors DOM-TOM)',1); insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 272, 27, '8.5','0','VAT standard rate (DOM sauf Guyane et Saint-Martin)',0); diff --git a/htdocs/install/mysql/tables/llx_bank.sql b/htdocs/install/mysql/tables/llx_bank.sql index e868aa054a5..b2a27c0e6b7 100644 --- a/htdocs/install/mysql/tables/llx_bank.sql +++ b/htdocs/install/mysql/tables/llx_bank.sql @@ -21,6 +21,7 @@ create table llx_bank ( rowid integer AUTO_INCREMENT PRIMARY KEY, datec datetime, + tms timestamp, datev date, -- date de valeur dateo date, -- date operation amount double(24,8) NOT NULL default 0,
'.$langs->trans("Ref").''; + if ($modCodeProduct->code_auto) $tmpcode=$modCodeProduct->getNextValue($object,$type); + print ''.$langs->trans("Ref").''; if ($_error) { print $langs->trans("RefAlreadyExists"); From d0fbca4c37e65bd3d3a73fccfb4047f20ad9caf8 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 9 Aug 2012 01:51:45 +0200 Subject: [PATCH 2/5] task # 326 : en_US translations :) --- htdocs/langs/en_US/admin.lang | 3 +++ htdocs/langs/en_US/companies.lang | 2 +- htdocs/langs/en_US/products.lang | 4 +++- htdocs/product/admin/product.php | 10 ++-------- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 2dc2d0fb45c..34f14a23500 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -277,6 +277,7 @@ GenericMaskCodes2={cccc} the client code
{cccc000} the client c GenericMaskCodes3=All other characters in the mask will remain intact.
Spaces are not allowed.
GenericMaskCodes4a=Example on the 99th %s of the third party TheCompany done 2007-01-31:
GenericMaskCodes4b=Example on third party created on 2007-03-01:
+GenericMaskCodes4c=Example on product created on 2007-03-01:
GenericMaskCodes5=ABC{yy}{mm}-{000000} will give ABC0701-000099
{0000+100}-ZZZ/{dd}/XXX will give 0199-ZZZ/31/XXX GenericNumRefModelDesc=Return a customizable number according to a defined mask. ServerAvailableOnIPOrPort=Server is available at address %s on port %s @@ -1137,6 +1138,8 @@ UseSearchToSelectProduct=Use a search form to choose a product (instead of using UseEcoTaxeAbility=Support Eco-Taxe (WEEE) SetDefaultBarcodeTypeProducts=Default barcode type to use for products SetDefaultBarcodeTypeThirdParties=Default barcode type to use for third parties +ProductCodeChecker= Module for product code generation and checking (product or service) +ProductOtherConf= Product / Service configuration ##### Syslog ##### SyslogSetup=Logs module setup SyslogOutput=Logs outputs diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index 0fef5378091..b2bf2106f90 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -392,4 +392,4 @@ ActivityStateFilter=Activity status # Monkey MonkeyNumRefModelDesc=Return numero with format %syymm-nnnn for customer code and %syymm-nnnn for supplier code where yy is year, mm is month and nnnn is a sequence with no break and no return to 0. # Leopard -LeopardNumRefModelDesc=Customer/supplier code is free. This code can be modified at any time. +LeopardNumRefModelDesc=The code is free. This code can be modified at any time. diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 7c6a28231dc..5c3b330410c 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -169,4 +169,6 @@ SuppliersPrices=Suppliers prices CustomCode=Customs code CountryOrigin=Origin country HiddenIntoCombo=Hidden into select lists -Nature=Nature \ No newline at end of file +Nature=Nature +ProductCodeModel=Product code model +ServiceCodeModel=Service code model \ No newline at end of file diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index eddac8c041d..1ac75474ea3 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -237,18 +237,12 @@ foreach ($dirproduct as $dirroot) } else { - // @todo : What's that ? - /*$disabled = false; + $disabled = false; if (! empty($conf->multicompany->enabled) && (is_object($mc) && ! empty($mc->sharings['referent']) && $mc->sharings['referent'] == $conf->entity) ? false : true); print '
'; - if (! $disabled) print ''; + if (! $disabled) print ''; print img_picto($langs->trans("Disabled"),'switch_off'); if (! $disabled) print ''; - print ''; - print ''; - print img_picto($langs->trans("Disabled"),'switch_off'); - print ''; print '