From e8046c2186327483b2e30f7d64fc66d4d1c4e80c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 28 May 2007 14:31:30 +0000 Subject: [PATCH] =?UTF-8?q?Add:=20mod=E8le=20de=20num=E9rotation=20param?= =?UTF-8?q?=E9trable=20"arctic"=20pour=20les=20fiches=20d'interventions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/admin/fichinter.php | 2 +- htdocs/fichinter/fiche.php | 12 +- htdocs/fichinter/fichinter.class.php | 41 -- .../includes/modules/fichinter/mod_arctic.php | 405 ++++++++++++++++++ .../modules/fichinter/mod_pacific.php | 11 +- 5 files changed, 418 insertions(+), 53 deletions(-) create mode 100644 htdocs/includes/modules/fichinter/mod_arctic.php diff --git a/htdocs/admin/fichinter.php b/htdocs/admin/fichinter.php index e366b141c25..b0117e43557 100644 --- a/htdocs/admin/fichinter.php +++ b/htdocs/admin/fichinter.php @@ -103,7 +103,7 @@ if ($_GET["action"] == 'setmod') dolibarr_set_const($db, "FICHEINTER_ADDON",$_GET["value"]); } -// défini les constantes du modèle pluton +// défini les constantes du modèle arctic if ($_POST["action"] == 'updateMatrice') dolibarr_set_const($db, "FICHEINTER_NUM_MATRICE",$_POST["matrice"]); if ($_POST["action"] == 'updatePrefix') dolibarr_set_const($db, "FICHEINTER_NUM_PREFIX",$_POST["prefix"]); if ($_POST["action"] == 'setOffset') dolibarr_set_const($db, "FICHEINTER_NUM_DELTA",$_POST["offset"]); diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 5db6d762d2a..0c9629a7a91 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -32,9 +32,9 @@ require_once(DOL_DOCUMENT_ROOT."/fichinter/fichinter.class.php"); require_once(DOL_DOCUMENT_ROOT."/includes/modules/fichinter/modules_fichinter.php"); require_once(DOL_DOCUMENT_ROOT."/project.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/fichinter.lib.php"); -if (defined("FICHEINTER_ADDON") && is_readable(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/mod_".FICHEINTER_ADDON.".php")) +if (defined("FICHEINTER_ADDON") && is_readable(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/".FICHEINTER_ADDON.".php")) { - require_once(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/mod_".FICHEINTER_ADDON.".php"); + require_once(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/".FICHEINTER_ADDON.".php"); } $langs->load("companies"); @@ -166,13 +166,13 @@ if ($_GET["action"] == 'create') exit; } - $fix = new Fichinter($db); + $ficheinter = new Fichinter($db); - $file = "mod_".$conf->global->FICHEINTER_ADDON.".php"; + $obj = $conf->global->FICHEINTER_ADDON; + $file = $obj.".php"; - $obj = "mod_".$conf->global->FICHEINTER_ADDON; $modFicheinter = new $obj; - $numpr = $modFicheinter->getNextValue($societe); + $numpr = $modFicheinter->getNextValue($societe,$ficheinter); print "
"; diff --git a/htdocs/fichinter/fichinter.class.php b/htdocs/fichinter/fichinter.class.php index be420f206d5..7bd48dd87f4 100644 --- a/htdocs/fichinter/fichinter.class.php +++ b/htdocs/fichinter/fichinter.class.php @@ -143,47 +143,6 @@ class Fichinter extends CommonObject return 1; } - /* - * \todo A virer quand module de numerotation dispo sur les fiches interventions - * - */ - function get_new_num($societe) - { - $socprefix = sanitize_string($societe->prefix_comm); - - $sql = "SELECT max(ref) FROM ".MAIN_DB_PREFIX."fichinter"; - $sql.= " WHERE ref like 'FI-".$socprefix."%'"; - - $result=$this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { - $row = $this->db->fetch_row(0); - $num = $row[0]; - - /* - *$num = substr($num, strlen($num) - 4, 4); - *$num = $num + 1; - *$num = '0000' . $num; - *$num = 'FI-' . $prefix_comm . '-' . substr($num, strlen($num) - 4, 4); - */ - $num = substr($num, 3); - $num = substr(strstr($num, "-"),1); - - $num = $num + 1; - //$num = '0000' . $num; - //$num = 'FI-' . $prefix_comm . '-' . substr($num, strlen($num) - 4, 4); - $num = 'FI-' . $socprefix . '-' . $num; - return $num; - } - } - else - { - print $this->db->error(); - } - } - /** * \brief Charge en mémoire la fiche intervention * \param rowid Id de la fiche à charger diff --git a/htdocs/includes/modules/fichinter/mod_arctic.php b/htdocs/includes/modules/fichinter/mod_arctic.php new file mode 100644 index 00000000000..8372d84c936 --- /dev/null +++ b/htdocs/includes/modules/fichinter/mod_arctic.php @@ -0,0 +1,405 @@ + + * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2005-2007 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/fichinter/mod_arctic.php + \ingroup fiche intervention + \brief Fichier contenant la classe du modèle de numérotation de référence de fiche intervention Arctic + \version $Revision$ +*/ + +require_once(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/modules_fichinter.php"); + +/** + \class mod_commande_saphir + \brief Classe du modèle de numérotation de référence de fiche intervention Arctic +*/ +class mod_arctic extends ModeleNumRefFicheinter +{ + var $prefix; + var $matrice; + var $numMatrice = Array(); + var $yy; + var $mm; + var $numbitcounter; + var $searchLast; + var $searchLastWithNoYear; + var $searchLastWithPreviousYear; + var $error = ''; + + /** \brief Constructeur + */ + function mod_arctic() + { + $this->nom = "arctic"; + } + + /** \brief Renvoi la description du modele de numérotation + * \return string Texte descripif + */ +function info() + { + global $conf,$langs; + + $langs->load("bills"); + + $form = new Form($db); + + $texte = $langs->trans('ArcticNumRefModelDesc1')."
\n"; + $texte.= ''; + + // Paramétrage de la matrice + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + + // Paramétrage du prefix des commandes + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + + // On détermine un offset sur le compteur + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + + // On défini le debut d'année fiscale + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + + // On défini si le compteur se remet à zero en debut d'année + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + + $texte.= '
Matrice de disposition des objets (prefix,mois,année,compteur...)'.$form->textwithhelp('',$langs->trans("MatriceOrderDesc"),1,1).'
Préfix des fiches d\'interventions
'.$form->textwithhelp('',$langs->trans("PrefixOrderDesc"),1,1).'
Appliquer un offset sur le compteur
'.$form->textwithhelp('',$langs->trans("OffsetDesc"),1,1).'
Début d\'année fiscale
'; + $texte.= $form->select_month($conf->global->SOCIETE_FISCAL_MONTH_START,'fiscalmonth',1); + $texte.= ''.$form->textwithwarning('',$langs->trans("FiscalMonthStartDesc"),1).'
Le compteur se remet à zéro en début d\'année
'; + $texte.= $form->selectyesno('numrestart',$conf->global->FICHEINTER_NUM_RESTART_BEGIN_YEAR,1); + $texte.= ''.$form->textwithhelp('',$langs->trans("NumRestartDesc"),1,1).'

'; + + return $texte; + } + + /** \brief Renvoi un exemple de numérotation + * \return string Example + */ + function getExample() + { + global $conf,$langs; + + $numExample = ''; + + //On construit la matrice + $buildResult = $this->buildMatrice(); + + if ($buildResult == 1) + { + // On récupère le nombre de chiffres du compteur + $arg = '%0'.$this->numbitcounter.'s'; + $num = sprintf($arg,$conf->global->FICHEINTER_NUM_DELTA?$conf->global->FICHEINTER_NUM_DELTA:1); + + //On construit le numéro à partir de la matrice + foreach($this->numMatrice as $objetMatrice) + { + if ($objetMatrice == '-') $numExample .= $objetMatrice; + if ($objetMatrice == '$prefix') $numExample .= $this->prefix; + if ($objetMatrice == '$yy') $numExample .= $this->yy; + if ($objetMatrice == '$mm') $numExample .= $this->mm; + if ($objetMatrice == '$num') $numExample .= $num; + } + } + else + { + $numExample = $langs->trans('NotConfigured'); + } + return $numExample; + } + + /** \brief Renvoi prochaine valeur attribuée + * \param objsoc Objet société + * \return string Valeur + */ + function getNextValue($objsoc=0,$ficheinter='') + { + global $db,$conf; + + //On construit la matrice + $buildResult = $this->buildMatrice($objsoc,$ficheinter); + + if ($buildResult == 1) + { + // On récupère la valeur max (réponse immédiate car champ indéxé) + $posindice = $this->numbitcounter; + $searchyy=''; + $sql = "SELECT MAX(ref)"; + $sql.= " FROM ".MAIN_DB_PREFIX."fichinter"; + if ($conf->global->FICHEINTER_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref like '".$this->searchLast."%'"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) $searchyy = substr($row[0],0,-$posindice); + } + if ($conf->global->FICHEINTER_NUM_DELTA != '') + { + //on vérifie si il y a une année précédente + //pour éviter que le delta soit appliqué de nouveau sur la nouvelle année + $previousyy=''; + $sql = "SELECT MAX(ref)"; + $sql.= " FROM ".MAIN_DB_PREFIX."fichinter"; + $sql.= " WHERE ref like '".$this->searchLastWithPreviousYear."%'"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) $previousyy = substr($row[0],0,-$posindice); + } + } + + // Si au moins un champ respectant le modèle a été trouvée + if (eregi('^'.$this->searchLastWithNoYear.'',$searchyy)) + { + // Recherche rapide car restreint par un like sur champ indexé + $sql = "SELECT MAX(0+SUBSTRING(ref,-".$posindice."))"; + $sql.= " FROM ".MAIN_DB_PREFIX."fichinter"; + $sql.= " WHERE ref like '${searchyy}%'"; + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + $max = $row[0]; + } + } + else if ($conf->global->FICHEINTER_NUM_DELTA != '' && !eregi('^'.$this->searchLastWithPreviousYear.'',$previousyy)) + { + // on applique le delta une seule fois + $max=$conf->global->FICHEINTER_NUM_DELTA?$conf->global->FICHEINTER_NUM_DELTA-1:0; + } + else + { + $max=0; + } + + // On applique le nombre de chiffres du compteur + $arg = '%0'.$this->numbitcounter.'s'; + $num = sprintf($arg,$max+1); + $numFinal = ''; + + foreach($this->numMatrice as $objetMatrice) + { + if ($objetMatrice == '-') $numFinal .= $objetMatrice; + if ($objetMatrice == '$prefix') $numFinal .= $this->prefix; + if ($objetMatrice == '$yy') $numFinal .= $this->yy; + if ($objetMatrice == '$mm') $numFinal .= $this->mm; + if ($objetMatrice == '$num') $numFinal .= $num; + } + + dolibarr_syslog("mod_arctic::getNextValue return ".$numFinal); + return $numFinal; + } + } + + + /** \brief Renvoie la référence de commande suivante non utilisée + * \param objsoc Objet société + * \param commande Objet commande + * \return string Texte descripif + */ + function getNumRef($objsoc=0,$ficheinter='') + { + return $this->getNextValue($objsoc,$ficheinter); + } + + + /** \brief Construction de la matrice de numérotation + * \param objsoc Objet société + * \return string Valeur + */ + function buildMatrice($objsoc=0,$fichinter='') + { + global $conf; + + $this->prefix = $conf->global->FICHEINTER_NUM_PREFIX; + $this->matrice = $conf->global->FICHEINTER_NUM_MATRICE; + $this->searchLast = ''; + $this->searchLastWithNoYear = ''; + $this->searchLastWithPreviousYear = ''; + + if ($this->matrice != '') + { + $resultatMatrice = Array(); + + $matricePrefix = "PREF|COM"; // PREF : prefix libre (ex: FI pour fiche intervention), COM : prefix du client + $matriceYear = "[A]{2,4}"; // l'année est sur 2 ou 4 chiffres + $matriceMonth = "[M]{2}"; // le mois est sur 2 chiffres + $matriceCounter = "[C]{1,}"; //le compteur a un nombre de chiffres libre + $matriceTiret = "[-]{1}"; // on recherche si il y a des tirets de séparation + + $matriceSearch = Array('prefix'=>$matricePrefix, + 'year'=>$matriceYear, + 'month'=>$matriceMonth, + 'counter'=>$matriceCounter + ); + + // on détermine l'emplacement des tirets + $resultTiret = preg_split('/'.$matriceTiret.'/',$this->matrice, -1, PREG_SPLIT_OFFSET_CAPTURE); + + $j = 0; + $k = 0; + + // on détermine les objets de la matrice + for ($i = 0; $i < count($resultTiret); $i++) + { + foreach($resultTiret[$i] as $idResultTiret => $valueResultTiret) + { + // Ajout des tirets + if ($j != $resultTiret[$i][1]) + { + $this->numMatrice[$k] = '-'; + $this->searchLast .= '-'; + $this->searchLastWithNoYear .= '-'; + $this->searchLastWithPreviousYear .= '-'; + $j = $resultTiret[$i][1]; + $k++; + } + foreach($matriceSearch as $idMatrice => $valueMatrice) + { + $resultCount = eregi(''.$valueMatrice.'',$valueResultTiret,$resultatMatrice); + if ($resultCount) + { + // On récupère le préfix utilisé + if ($idMatrice == 'prefix') + { + if ($resultatMatrice[0] == 'COM') + { + if ($objsoc->prefix_comm) + { + $this->prefix = $objsoc->prefix_comm; + } + else + { + $this->prefix = 'COM'; + } + $this->numMatrice[$k] = '$prefix'; + $this->searchLast .= $this->prefix; + $this->searchLastWithNoYear .= $this->prefix; + $this->searchLastWithPreviousYear .= $this->prefix; + $k++; + } + else if ($resultatMatrice[0] == 'PREF') + { + $this->numMatrice[$k] = '$prefix'; + $this->searchLast .= $this->prefix; + $this->searchLastWithNoYear .= $this->prefix; + $this->searchLastWithPreviousYear .= $this->prefix; + $k++; + } + } + else if ($idMatrice == 'year') + { + // On récupère le nombre de chiffres pour l'année + $numbityear = $resultCount; + // On défini le mois du début d'année fiscale + $current_month = date("n"); + + if (is_object($ficheinter) && $ficheinter->date) + { + $create_month = strftime("%m",$ficheinter->date); + } + else + { + $create_month = $current_month; + } + + // On change d'année fiscal si besoin + if($conf->global->SOCIETE_FISCAL_MONTH_START && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START && $create_month >= $conf->global->SOCIETE_FISCAL_MONTH_START) + { + $this->yy = substr(strftime("%Y",mktime(0,0,0,date("m"),date("d"),date("Y")+1)),$numbityear); + } + else + { + $this->yy = substr(strftime("%Y",time()),$numbityear); + } + $this->numMatrice[$k] = '$yy'; + $this->searchLast .= $this->yy; + for ($l = 1; $l <= $numbityear; $l++) + { + $this->searchLastWithNoYear .= '[0-9]'; + } + $previousYear = substr(strftime("%Y",mktime(0,0,0,date("m"),date("d"),date("Y")-1)),$numbityear); + $this->searchLastWithPreviousYear .= $previousYear; + $k++; + } + else if ($idMatrice == 'month') + { + // On récupère le mois si besoin + $this->mm = strftime("%m",time()); + $this->numMatrice[$k] = '$mm'; + $this->searchLast .= $this->mm; + $this->searchLastWithNoYear .= '[0-9][0-9]'; + $this->searchLastWithPreviousYear .= $this->mm; + $k++; + } + else if ($idMatrice == 'counter') + { + // On récupère le nombre de chiffres pour le compteur + $this->numbitcounter = $resultCount; + $this->numMatrice[$k] = '$num'; + $k++; + } + } + } + } + } + return 1; + } + else + { + return -3; + } + } +} + +?> \ No newline at end of file diff --git a/htdocs/includes/modules/fichinter/mod_pacific.php b/htdocs/includes/modules/fichinter/mod_pacific.php index f8731e151e5..300f422220e 100644 --- a/htdocs/includes/modules/fichinter/mod_pacific.php +++ b/htdocs/includes/modules/fichinter/mod_pacific.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005 Regis Houssin + * Copyright (C) 2005-2007 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 @@ -22,15 +22,16 @@ */ /** - \file htdocs/includes/modules/fichinter/mod_pacific.php - \ingroup facture + \file htdocs/includes/modules/fichinter/mod_pacific.php + \ingroup fiche intervention \brief Fichier contenant la classe du modèle de numérotation de référence de fiche intervention Pacific \version $Revision$ */ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/modules_fichinter.php"); -/** \class mod_facture_terre +/** + \class mod_pacific \brief Classe du modèle de numérotation de référence de fiche intervention Pacific */ @@ -142,7 +143,7 @@ class mod_pacific extends ModeleNumRefFicheinter return $this->prefix."$yymm-$num"; } - /** \brief Renvoie la référence de facture suivante non utilisée + /** \brief Renvoie la référence de fiche d'intervention suivante non utilisée * \param objsoc Objet société * \return string Texte descripif */