From 1b3da4a1382b077750d838cd8cd3529e41ccc88d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 22 Aug 2005 19:39:55 +0000 Subject: [PATCH] =?UTF-8?q?Am=E9lioration=20de=20la=20gestion=20des=20modu?= =?UTF-8?q?les=20de=20num=E9rotation.=20Ajout=20du=20module=20mod=5Fpropal?= =?UTF-8?q?e=5Fmarbre=20(PRYYMM-9999)=20Ajout=20du=20module=20mod=5Ffactur?= =?UTF-8?q?e=5Fterre=20(FAYYMM-9999)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/admin/facture.php | 62 ++++---- htdocs/admin/propale.php | 111 +++++++------- .../modules/facture/modules_facture.php | 28 ++-- .../modules/facture/terre/terre.modules.php | 135 ++++++++++++++++++ .../modules/fichinter/modules_fichinter.php | 8 -- .../modules/propale/mod_propale_ivoire.php | 31 ++-- .../modules/propale/mod_propale_jade.php | 20 +-- .../modules/propale/mod_propale_marbre.php | 15 +- 8 files changed, 275 insertions(+), 135 deletions(-) create mode 100644 htdocs/includes/modules/facture/terre/terre.modules.php diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index 1db72516b9b..be729112cbf 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -91,6 +91,11 @@ if ($_GET["action"] == 'delete') } } + +/* + * Affiche page + */ + $dir = "../includes/modules/facture/"; @@ -109,9 +114,10 @@ print ''; print ''; print ''; print ''; -print ''; +print ''; print ''; -print "\n"; +print ''; +print ''."\n"; clearstatcache(); @@ -120,37 +126,39 @@ $handle=opendir($dir); $var=True; while (($file = readdir($handle))!==false) { - if (is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') + if (is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') { - $var = !$var; - print ''; + print ''; - // Affiche example - print ''; - - print '\n"; + // Affiche example + print ''; + + print '\n"; + } + else + { + print ''.$langs->trans("Default").''; + print "\n"; + } + print "\n"; } } closedir($handle); diff --git a/htdocs/admin/propale.php b/htdocs/admin/propale.php index 2ee9c0f2d6b..45fb77ef62b 100644 --- a/htdocs/admin/propale.php +++ b/htdocs/admin/propale.php @@ -23,7 +23,8 @@ * $Source$ */ -/** \file htdocs/admin/propale.php +/** + \file htdocs/admin/propale.php \ingroup propale \brief Page d'administration/configuration du module Propale \version $Revision$ @@ -40,35 +41,30 @@ if (!$user->admin) if ($_POST["action"] == 'nbprod') { - dolibarr_set_const($db, "PROPALE_NEW_FORM_NB_PRODUCT",$value); - Header("Location: propale.php"); + dolibarr_set_const($db, "PROPALE_NEW_FORM_NB_PRODUCT",$value); + Header("Location: propale.php"); } - -llxHeader(); - - if ($_GET["action"] == 'set') { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal_model_pdf (nom) VALUES ('".$_GET["value"]."')"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal_model_pdf (nom) VALUES ('".$_GET["value"]."')"; - if ($db->query($sql)) + if ($db->query($sql)) { } } if ($_GET["action"] == 'del') { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_model_pdf WHERE nom='".$_GET["value"]."'"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_model_pdf WHERE nom='".$_GET["value"]."'"; - if ($db->query($sql)) + if ($db->query($sql)) { } } -// positionne la variable pour le test d'affichage de l'icone -$propale_addon_var_pdf = PROPALE_ADDON_PDF; +$propale_addon_var_pdf = $conf->global->PROPALE_ADDON_PDF; if ($_GET["action"] == 'setpdf') { @@ -90,10 +86,15 @@ if ($_GET["action"] == 'setpdf') } } -$propale_addon_var = PROPALE_ADDON; +$propale_addon_var = $conf->global->PROPALE_ADDON; if ($_GET["action"] == 'setmod') { + // \todo Verifier si module numerotation choisi peut etre activé + // par appel methode canBeActivated + + + if (dolibarr_set_const($db, "PROPALE_ADDON",$_GET["value"])) { // la constante qui a été lue en avant du nouveau set @@ -103,62 +104,72 @@ if ($_GET["action"] == 'setmod') } - /* * Affiche page */ +$dir = "../includes/modules/propale/"; + + +llxHeader('',$langs->trans("PropalSetup")); + print_titre($langs->trans("PropalSetup")); -print "
"; +/* + * Module numérotation + */ +print "
"; print_titre($langs->trans("ProposalsNumberingModules")); -print "
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Example").''.$langs->trans("Example").''.$langs->trans("Default").'
'.$langs->trans("NextValue").'
'; - echo "$file"; - print "\n"; + $var = !$var; + print '
'; + echo "$file"; + print "\n"; - $filebis = $file."/".$file.".modules.php"; + $filebis = $file."/".$file.".modules.php"; - // Chargement de la classe de numérotation - $classname = "mod_facture_".$file; - require_once($dir.$filebis); + // Chargement de la classe de numérotation + $classname = "mod_facture_".$file; + require_once($dir.$filebis); - $obj = new $classname($db); - print $obj->info(); + $obj = new $classname($db); + print $obj->info(); - print ''.$obj->getExample().''; - if ($facture_addon_var == "$file") - { - print img_tick(); - } - else - { - print ''.$langs->trans("Default").''; - } - print "
'.$obj->getExample().''; + if ($facture_addon_var == "$file") + { + print img_tick(); + print "".$obj->getNextValue()." 
\n"; -print "\n"; -print " \n"; -print " \n"; -print " \n"; -print " \n"; -print "\n"; +print '
".$langs->trans("Name")."".$langs->trans("Description")."".$langs->trans("Example")."".$langs->trans("Activated")."
'; +print ''; +print '\n"; +print '\n"; +print '\n"; +print '\n"; +print '\n"; +print ''."\n"; clearstatcache(); -$dir = "../includes/modules/propale/"; $handle = opendir($dir); if ($handle) { - $var=true; - while (($file = readdir($handle))!==false) + $var=true; + while (($file = readdir($handle))!==false) { - if (substr($file, 0, 12) == 'mod_propale_' && substr($file, strlen($file)-3, 3) == 'php') - { - $file = substr($file, 0, strlen($file)-4); + if (substr($file, 0, 12) == 'mod_propale_' && substr($file, strlen($file)-3, 3) == 'php') + { + $file = substr($file, 0, strlen($file)-4); - require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/".$file.".php"); + require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/".$file.".php"); - $modPropale = new $file; + $modPropale = new $file; - $var=!$var; - print "\n "; - print "\n \n"; - print "\n \n"; - - if ($propale_addon_var == "$file") - { - print ''; - } - else - { - print "\n"; - } - - print "\n"; - } + $var=!$var; + print "\n "; + print "\n \n"; + print "\n \n"; + + if ($propale_addon_var == "$file") + { + print ''; + print "\n \n"; + } + else + { + print "\n"; + print "\n \n"; + } + + + print "\n"; + } } - closedir($handle); + closedir($handle); } print "
'.$langs->trans("Name")."'.$langs->trans("Description")."'.$langs->trans("Example")."'.$langs->trans("Activated")."'.$langs->trans("NextValue")."
".$file."".$modPropale->info()."".$modPropale->getExample()."'; - print img_tick(); - print '".$langs->trans("Activate")."
".$file."".$modPropale->info()."".$modPropale->getExample()."'; + print img_tick(); + print '".$modPropale->getNextValue()."".$langs->trans("Activate")." 

\n"; diff --git a/htdocs/includes/modules/facture/modules_facture.php b/htdocs/includes/modules/facture/modules_facture.php index ec8008f3a45..06e0b14bdbf 100644 --- a/htdocs/includes/modules/facture/modules_facture.php +++ b/htdocs/includes/modules/facture/modules_facture.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004 Laurent Destailleur + * Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005 Regis Houssin * @@ -21,10 +21,10 @@ * * $Id$ * $Source$ - * */ -/** \file htdocs/includes/modules/facture/modules_facture.php +/** + \file htdocs/includes/modules/facture/modules_facture.php \ingroup facture \brief Fichier contenant la classe mère de generation des factures en PDF et la classe mère de numérotation des factures @@ -83,14 +83,23 @@ class ModeleNumRefFactures return $langs->trans("NoExample"); } - /** - \brief Renvoi le dernier message d'erreur de création de facture - */ - function numreferror() + /** \brief Test si les numéros déjà en vigueur dans la base ne provoquent pas de + * de conflits qui empechera cette numérotation de fonctionner. + * \return boolean false si conflit, true si ok + */ + function canBeActivated() { - return $this->error; + return true; } + /** \brief Renvoi prochaine valeur attribuée + * \return string Valeur + */ + function getNextValue() + { + global $langs; + return $langs->trans("NotAvailable"); + } } @@ -235,8 +244,7 @@ function facture_get_num($soc, $prefixe_additionnel='') } else { - dolibarr_syslog("Erreur dans facture_get_num"); - dolibarr_print_error($db,$obj->numreferror()); + dolibarr_print_error($db,"modules_facture::facture_get_num ".$obj->error); return ""; } } diff --git a/htdocs/includes/modules/facture/terre/terre.modules.php b/htdocs/includes/modules/facture/terre/terre.modules.php new file mode 100644 index 00000000000..d61ecf4b345 --- /dev/null +++ b/htdocs/includes/modules/facture/terre/terre.modules.php @@ -0,0 +1,135 @@ + + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/includes/modules/facture/terre/terre.modules.php + \ingroup facture + \brief Fichier contenant la classe du modèle de numérotation de référence de facture Terre + \version $Revision$ +*/ + + +/** \class mod_facture_terre + \brief Classe du modèle de numérotation de référence de facture Terre +*/ + +class mod_facture_terre extends ModeleNumRefFactures +{ + + /** \brief Renvoi la description du modele de numérotation + * \return string Texte descripif + */ + function info() + { + return "Renvoie le numéro sous la forme FAyymm-nnnn où yy est l'année, mm le mois et nnnn un compteur séquentiel sans rupture et sans remise à 0"; + } + + /** \brief Renvoi un exemple de numérotation + * \return string Example + */ + function getExample() + { + return "FA0501-0001"; + } + + /** \brief Test si les numéros déjà en vigueur dans la base ne provoquent pas de + * de conflits qui empechera cette numérotation de fonctionner. + * \return boolean false si conflit, true si ok + */ + function canBeActivated() + { + $fayymm=''; + + $sql = "SELECT MAX(facnumber)"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) $fayymm = substr($row[0],0,6); + } + if (! $fayymm || eregi('FA[0-9][0-9][0-9][0-9]',$fayymm)) + { + return true; + } + else + { + $this->error='Une facture commençant par $fayymm existe en base et est incompatible avec cette numérotation. Supprimer la ou renommer la pour activer ce module.'; + return false; + } + } + + /** \brief Renvoi prochaine valeur attribuée + * \return string Valeur + */ + function getNextValue() + { + global $db; + + // D'abord on récupère la valeur max (réponse immédiate car champ indéxé) + $fayymm=''; + $sql = "SELECT MAX(facnumber)"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) $fayymm = substr($row[0],0,6); + } + + // Si au moins un champ respectant le modèle a été trouvée + if (eregi('FA[0-9][0-9][0-9][0-9]',$fayymm)) + { + // Recherche rapide car restreint par un like sur champ indexé + $posindice=8; + $sql = "SELECT MAX(0+SUBSTR(facnumber,$posindice))"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; + $sql.= " WHERE facnumber like '${fayymm}%'"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + $max = $row[0]; + } + } + else + { + $max=0; + } + $yymm = strftime("%y%m",time()); + $num = sprintf("%04s",$max+1); + + return "FA$yymm-$num"; + } + + /** \brief Renvoie la référence de facture suivante non utilisée + * \param objsoc Objet société + * \return string Texte descripif + */ + function getNumRef($objsoc=0) + { + return $this->getNextValue(); + } + +} + +?> diff --git a/htdocs/includes/modules/fichinter/modules_fichinter.php b/htdocs/includes/modules/fichinter/modules_fichinter.php index 64e6c5d759e..35a41dbb8ab 100644 --- a/htdocs/includes/modules/fichinter/modules_fichinter.php +++ b/htdocs/includes/modules/fichinter/modules_fichinter.php @@ -86,14 +86,6 @@ class ModeleNumRefFicheinter return $langs->trans("NoExample"); } - /** - \brief Renvoi le dernier message d'erreur de création de fiche intervention - */ - function numreferror() - { - return $this->error; - } - } diff --git a/htdocs/includes/modules/propale/mod_propale_ivoire.php b/htdocs/includes/modules/propale/mod_propale_ivoire.php index 53a44da133c..53a2d231a37 100644 --- a/htdocs/includes/modules/propale/mod_propale_ivoire.php +++ b/htdocs/includes/modules/propale/mod_propale_ivoire.php @@ -60,7 +60,20 @@ class mod_propale_ivoire extends ModeleNumRefPropales */ function getNextValue() { - return $this->propale_get_num(); + global $db; + + $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."propal"; + + if ( $db->query($sql) ) + { + $row = $db->fetch_row(0); + + $num = $row[0]; + } + + $y = strftime("%y",time()); + + return "PR" . "$y" . substr("000".$num, strlen("000".$num)-4,4); } @@ -70,21 +83,7 @@ class mod_propale_ivoire extends ModeleNumRefPropales */ function propale_get_num($objsoc=0) { - global $db; - - $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."propal"; - - if ( $db->query($sql) ) - { - $row = $db->fetch_row(0); - - $num = $row[0]; - } - - $y = strftime("%y",time()); - - return "PR" . "$y" . substr("000".$num, strlen("000".$num)-4,4); - + return $this->propale_get_num(); } } diff --git a/htdocs/includes/modules/propale/mod_propale_jade.php b/htdocs/includes/modules/propale/mod_propale_jade.php index 9a2c45ff3e1..8e9d7dddbe4 100644 --- a/htdocs/includes/modules/propale/mod_propale_jade.php +++ b/htdocs/includes/modules/propale/mod_propale_jade.php @@ -60,16 +60,6 @@ class mod_propale_jade extends ModeleNumRefPropales * \return string Valeur */ function getNextValue() - { - return $this->propale_get_num(); - } - - - /** \brief Renvoie la référence de propale suivante non utilisée - * \param objsoc Objet société - * \return string Texte descripif - */ - function propale_get_num($objsoc=0) { global $db; @@ -86,6 +76,16 @@ class mod_propale_jade extends ModeleNumRefPropales return "PROP" . ($num+1); } + + + /** \brief Renvoie la référence de propale suivante non utilisée + * \param objsoc Objet société + * \return string Texte descripif + */ + function propale_get_num($objsoc=0) + { + return $this->propale_get_num(); + } } ?> diff --git a/htdocs/includes/modules/propale/mod_propale_marbre.php b/htdocs/includes/modules/propale/mod_propale_marbre.php index d22761174a2..a164190074d 100644 --- a/htdocs/includes/modules/propale/mod_propale_marbre.php +++ b/htdocs/includes/modules/propale/mod_propale_marbre.php @@ -131,20 +131,7 @@ class mod_propale_marbre extends ModeleNumRefPropales */ function propale_get_num($objsoc=0) { - global $db; - - $sql = "SELECT MAX(ref) as nb FROM ".MAIN_DB_PREFIX."propal"; - $resql=$db->query($sql); - if ($resql) - { - $row = $db->fetch_row($resql); - $num = $row[0]; - } - - $yymm = strftime("%y%m",time()); - - return "PR$yymm-".$obj->prefix.'-'.substr("000".$num, 0,-4); - + return $this->getNextValue(); } }