From 8a598504af308b8bac5208b2094cbab58d9e17a1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 29 Apr 2006 11:03:30 +0000 Subject: [PATCH] =?UTF-8?q?Qual:=20Supprime=20module=20num=E9rotation=20pl?= =?UTF-8?q?uton=20qui=20fait=20doublon=20avec=20neptune?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../facture/neptune/neptune.modules.php | 72 ++++++++++------ .../modules/facture/pluton/pluton.modules.php | 84 ------------------- .../modules/facture/terre/terre.modules.php | 8 +- mysql/migration/2.0.0-2.1.0.sql | 3 + 4 files changed, 55 insertions(+), 112 deletions(-) delete mode 100644 htdocs/includes/modules/facture/pluton/pluton.modules.php diff --git a/htdocs/includes/modules/facture/neptune/neptune.modules.php b/htdocs/includes/modules/facture/neptune/neptune.modules.php index a693ef4dc4e..7a1cb31f6dd 100644 --- a/htdocs/includes/modules/facture/neptune/neptune.modules.php +++ b/htdocs/includes/modules/facture/neptune/neptune.modules.php @@ -62,9 +62,10 @@ class mod_facture_neptune extends ModeleNumRefFactures */ function getExample() { - if (defined("FACTURE_NEPTUNE_DELTA")) + global $conf; + if ($conf->global->FACTURE_NEPTUNE_DELTA) { - return "FA0400".sprintf("%02d",FACTURE_NEPTUNE_DELTA); + return "FA04".sprintf("%04d",$conf->global->FACTURE_NEPTUNE_DELTA); } else { @@ -72,34 +73,57 @@ class mod_facture_neptune extends ModeleNumRefFactures } } + /** \brief Renvoie la référence de facture suivante non utilisée + * \param objsoc Objet société + * \return string Texte descripif + */ + function getNextValue($objsoc=0) + { + global $db,$conf; + + // D'abord on récupère la valeur max (réponse immédiate car champ indéxé) + $fayy=''; + $sql = "SELECT MAX(facnumber)"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) $fayy = substr($row[0],0,4); + } + + // Si champ respectant le modèle a été trouvée + if (eregi('^FA[0-9][0-9]',$fayy)) + { + // Recherche rapide car restreint par un like sur champ indexé + $posindice=5; + $sql = "SELECT MAX(0+SUBSTRING(facnumber,$posindice))"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; + $sql.= " WHERE facnumber like '${fayy}%'"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + $max = $row[0]; + } + } + else + { + $max=$conf->global->FACTURE_NEPTUNE_DELTA?$conf->global->FACTURE_NEPTUNE_DELTA:0; + } + $yy = strftime("%y",time()); + $num = sprintf("%04s",$max+1); + + return "FA$yy$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) { - global $db; - - $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."facture WHERE fk_statut > 0"; - - if ( $db->query($sql) ) - { - $row = $db->fetch_row(0); - - $num = $row[0]; - } - - if (!defined("FACTURE_NEPTUNE_DELTA")) - { - define("FACTURE_NEPTUNE_DELTA", 0); - } - - $num = $num + FACTURE_NEPTUNE_DELTA; - - $y = strftime("%y",time()); - - return "FA" . "$y" . substr("000".$num, strlen("000".$num)-4,4); - + return $this->getNextValue($objsoc); } } diff --git a/htdocs/includes/modules/facture/pluton/pluton.modules.php b/htdocs/includes/modules/facture/pluton/pluton.modules.php deleted file mode 100644 index bbfb62ebed1..00000000000 --- a/htdocs/includes/modules/facture/pluton/pluton.modules.php +++ /dev/null @@ -1,84 +0,0 @@ - - * Copyright (C) 2004 Laurent Destailleur - * Copyright (C) 2005 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, 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/pluton/pluton.modules.php - \ingroup facture - \brief Fichier contenant la classe du modèle de numérotation de référence de facture Pluton - \version $Revision$ -*/ - -require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php"); - -/*! \class mod_facture_pluton - \brief Classe du modèle de numérotation de référence de facture Pluton -*/ - -class mod_facture_pluton extends ModeleNumRefFactures -{ - - /*! \brief Renvoi la description du modele de numérotation - * \return string Texte descripif - */ - function info() - { - return ' - Renvoie le numéro de facture sous une forme numérique simple, la première facture porte le numéro 1, la quinzième facture ayant le numéro 15.'; - } - - /*! \brief Renvoi un exemple de numérotation - * \return string Example - */ - function getExample() - { - return "FA040001"; - } - - /*! \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) - { - global $db; - - $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."facture WHERE fk_statut > 0"; - - if ( $db->query($sql) ) - { - $row = $db->fetch_row(0); - - $num = $row[0]; - } - - - $y = strftime("%y",time()); - - return "FA" . "$y" . substr("000".$num, strlen("000".$num)-4,4); - - } - -} - -?> diff --git a/htdocs/includes/modules/facture/terre/terre.modules.php b/htdocs/includes/modules/facture/terre/terre.modules.php index 7a2246c58cc..7e7d5f2affb 100644 --- a/htdocs/includes/modules/facture/terre/terre.modules.php +++ b/htdocs/includes/modules/facture/terre/terre.modules.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005 Regis Houssin +/* Copyright (C) 2005-2006 Laurent Destailleur + * Copyright (C) 2005 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 @@ -98,8 +98,8 @@ class mod_facture_terre extends ModeleNumRefFactures 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)) + // Si 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; diff --git a/mysql/migration/2.0.0-2.1.0.sql b/mysql/migration/2.0.0-2.1.0.sql index 90dad7b4427..020608e6d11 100644 --- a/mysql/migration/2.0.0-2.1.0.sql +++ b/mysql/migration/2.0.0-2.1.0.sql @@ -158,3 +158,6 @@ insert into llx_document_model(nom,type) values('rouget','shipping'); delete from llx_document_model where nom='adytek'; delete from llx_document_model where nom='rouge' and type='order'; delete from llx_document_model where nom='azur' and type='order'; + + +update llx_const set value='neptune' where value='pluton' and name = 'FACTURE_ADDON'; \ No newline at end of file