From fe63898bb453a6117c81893ca4f07cddc033b4ac Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 3 May 2006 12:11:58 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20le=20compteur=20n'=E9tait=20pas=20remis?= =?UTF-8?q?=20=E0=20z=E9ro=20en=20d=E9but=20d'ann=E9e=20fiscale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commande/mod_commande_emeraude.php | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/htdocs/includes/modules/commande/mod_commande_emeraude.php b/htdocs/includes/modules/commande/mod_commande_emeraude.php index 7921555b84e..08fa66768c6 100644 --- a/htdocs/includes/modules/commande/mod_commande_emeraude.php +++ b/htdocs/includes/modules/commande/mod_commande_emeraude.php @@ -86,22 +86,38 @@ class mod_commande_emeraude extends ModeleNumRefCommandes function getNextValue() { global $db,$conf; - - // D'abord on récupère la valeur max (réponse immédiate car champ indéxé) + + // D'abord on défini l'année fiscale + $prefix='C'; + $current_month = date("n"); + if($conf->global->SOCIETE_FISCAL_MONTH_START && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START) + { + $yy = strftime("%y",mktime(0,0,0,date("m"),date("d"),date("Y")+1)); + } + else + { + $yy = strftime("%y",time()); + } + + // On récupère la valeur max (réponse immédiate car champ indéxé) + $fisc=$prefix.$yy; $cyy=''; $sql = "SELECT MAX(ref)"; $sql.= " FROM ".MAIN_DB_PREFIX."commande"; + $sql.= " WHERE ref like '${fisc}%'"; $resql=$db->query($sql); if ($resql) { $row = $db->fetch_row($resql); if ($row) $cyy = substr($row[0],0,3); } - + // Si au moins un champ respectant le modèle a été trouvée if (eregi('C[0-9][0-9]',$cyy)) { // Recherche rapide car restreint par un like sur champ indexé + $prefix='C'; + $date = strftime("%Y%m", time()); $posindice=4; $sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))"; $sql.= " FROM ".MAIN_DB_PREFIX."commande"; @@ -118,16 +134,6 @@ class mod_commande_emeraude extends ModeleNumRefCommandes $max=0; } - $current_month = date("n"); - if($conf->global->SOCIETE_FISCAL_MONTH_START && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START) - { - $yy = strftime("%y",mktime(0,0,0,date("m"),date("d"),date("Y")+1)); - } - else - { - $yy = strftime("%y",time()); - } - $num = sprintf("%05s",$max+1); return "C$yy$num";