Fix: le compteur n'était pas remis à zéro en début d'année fiscale

This commit is contained in:
Regis Houssin 2006-05-03 12:11:58 +00:00
parent 1710b3ecf0
commit fe63898bb4

View File

@ -87,10 +87,24 @@ class mod_commande_emeraude extends ModeleNumRefCommandes
{ {
global $db,$conf; 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=''; $cyy='';
$sql = "SELECT MAX(ref)"; $sql = "SELECT MAX(ref)";
$sql.= " FROM ".MAIN_DB_PREFIX."commande"; $sql.= " FROM ".MAIN_DB_PREFIX."commande";
$sql.= " WHERE ref like '${fisc}%'";
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
@ -102,6 +116,8 @@ class mod_commande_emeraude extends ModeleNumRefCommandes
if (eregi('C[0-9][0-9]',$cyy)) if (eregi('C[0-9][0-9]',$cyy))
{ {
// Recherche rapide car restreint par un like sur champ indexé // Recherche rapide car restreint par un like sur champ indexé
$prefix='C';
$date = strftime("%Y%m", time());
$posindice=4; $posindice=4;
$sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))"; $sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))";
$sql.= " FROM ".MAIN_DB_PREFIX."commande"; $sql.= " FROM ".MAIN_DB_PREFIX."commande";
@ -118,16 +134,6 @@ class mod_commande_emeraude extends ModeleNumRefCommandes
$max=0; $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); $num = sprintf("%05s",$max+1);
return "C$yy$num"; return "C$yy$num";