From 4aa12da33d41acd20ae6aff224bb44292b2f238e Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 25 Apr 2007 22:56:14 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20fonctionnalit=E9es=20sur=20le=20mo?= =?UTF-8?q?dele=20de=20num=E9rotation=20param=E9trable=20"pluton"=20-=20to?= =?UTF-8?q?ujours=20en=20phase=20de=20test=20!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/facture/pluton/pluton.modules.php | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/htdocs/includes/modules/facture/pluton/pluton.modules.php b/htdocs/includes/modules/facture/pluton/pluton.modules.php index c1f9e13d74f..1983f37b17e 100644 --- a/htdocs/includes/modules/facture/pluton/pluton.modules.php +++ b/htdocs/includes/modules/facture/pluton/pluton.modules.php @@ -123,10 +123,10 @@ function info() $texte.= ' ('.$langs->trans('IsNotDefined').')
'; } - $texte.= 'Le compteur se remet à zéro en début d\'année'; - if ($conf->global->FACTURE_NUM_RESTART_BEGIN_YEAR) + $texte.= 'Le compteur se remet à zéro en début d\'année ou chaque mois (1:année, 2:mois)'; + if ($conf->global->FACTURE_NUM_RESTART_BEGIN_YEAR_OR_MONTH) { - $texte.= ' ('.$langs->trans('DefinedAndHasThisValue').' : '.$conf->global->FACTURE_NUM_RESTART_BEGIN_YEAR.')
'; + $texte.= ' ('.$langs->trans('DefinedAndHasThisValue').' : '.$conf->global->FACTURE_NUM_RESTART_BEGIN_YEAR_OR_MONTH.')
'; } else { @@ -185,7 +185,7 @@ function info() $num = sprintf($arg,1); // Construction de l'exemple de numérotation - $numExample = $prefix.$mm.$yy.$num; + $numExample = $prefix.$yy.$mm.$num; return $numExample; } @@ -231,8 +231,8 @@ function info() $prefix=$this->prefixinvoice; } - // On défini l'année fiscale - $current_month = date("n"); + // On défini le mois du début d'année fiscale + $fiscal_current_month = date("n"); if (is_object($facture) && $facture->date) { @@ -240,12 +240,13 @@ function info() } else { - $create_month = $current_month; + $create_month = $fiscal_current_month; } $numbityear = 4 - $conf->global->FACTURE_NUM_BIT_YEAR; - if($conf->global->SOCIETE_FISCAL_MONTH_START && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START && $create_month >= $conf->global->SOCIETE_FISCAL_MONTH_START) + // On change d'année fiscal si besoin + if($conf->global->SOCIETE_FISCAL_MONTH_START && $fiscal_current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START && $create_month >= $conf->global->SOCIETE_FISCAL_MONTH_START) { $yy = substr(strftime("%Y",mktime(0,0,0,date("m"),date("d"),date("Y")+1)),$numbityear); } @@ -253,27 +254,31 @@ function info() { $yy = substr(strftime("%Y",time()),$numbityear); } + + // Si besoin on récupère le mois en cours + if ($conf->global->FACTURE_VIEW_MONTH) $mm = strftime("%m",time()); // On récupère la valeur max (réponse immédiate car champ indéxé) - $numQuantify = ($conf->global->FACTURE_NUM_QUANTIFY_METER - 1); + $posindice = $conf->global->FACTURE_NUM_QUANTIFY_METER; $fisc=$prefix.$yy; + $current_month=$prefix.$yy.$mm; $fayy=''; $sql = "SELECT MAX(facnumber)"; $sql.= " FROM ".MAIN_DB_PREFIX."facture"; $sql.= " WHERE facnumber like '${prefix}%'"; - if ($conf->global->FACTURE_NUM_RESTART_BEGIN_YEAR == 1) $sql.= " AND facnumber like '${fisc}%'"; + if ($conf->global->FACTURE_NUM_RESTART_BEGIN_YEAR_OR_MONTH == 1) $sql.= " AND facnumber like '${fisc}%'"; + if ($conf->global->FACTURE_NUM_RESTART_BEGIN_YEAR_OR_MONTH == 2) $sql.= " AND facnumber like '${current_month}%'"; $resql=$db->query($sql); if ($resql) { $row = $db->fetch_row($resql); - if ($row) $fayy = substr($row[0],0,$numQuantify); + if ($row) $fayy = substr($row[0],0,-$posindice); } - + // Si au moins un champ respectant le modèle a été trouvée if (eregi('^'.$prefix.'[0-9][0-9]',$fayy)) { // Recherche rapide car restreint par un like sur champ indexé - $posindice = $conf->global->FACTURE_NUM_QUANTIFY_METER; $sql = "SELECT MAX(0+SUBSTRING(facnumber,$posindice))"; $sql.= " FROM ".MAIN_DB_PREFIX."facture"; $sql.= " WHERE facnumber like '${fayy}%'"; @@ -297,8 +302,8 @@ function info() $arg = '%0'.$conf->global->FACTURE_NUM_QUANTIFY_METER.'s'; $num = sprintf($arg,$max+1); - dolibarr_syslog("mod_facture_pluton::getNextValue return ".$prefix.$yy.$num); - return $prefix.$yy.$num; + dolibarr_syslog("mod_facture_pluton::getNextValue return ".$prefix.$yy.$mm.$num); + return $prefix.$yy.$mm.$num; }