Fix: on prend le MAX des numéros de propal au lieu du COUNT
This commit is contained in:
parent
a7171c6aac
commit
0799742f3f
@ -91,30 +91,47 @@ class mod_propale_diamant extends ModeleNumRefPropales
|
|||||||
*/
|
*/
|
||||||
function getNextValue($objsoc=0)
|
function getNextValue($objsoc=0)
|
||||||
{
|
{
|
||||||
global $db;
|
global $db, $conf;
|
||||||
|
|
||||||
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."propal";
|
// D'abord on récupère la valeur max (réponse immédiate car champ indéxé)
|
||||||
|
$pryy = 'PR'.strftime("%y",time());
|
||||||
if ( $db->query($sql) )
|
$sql = "SELECT MAX(ref)";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
|
||||||
|
$sql.= " WHERE ref like '${pryy}%'";
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
if ($resql)
|
||||||
{
|
{
|
||||||
$row = $db->fetch_row(0);
|
$row = $db->fetch_row($resql);
|
||||||
|
$pryy='';
|
||||||
$num = $row[0];
|
if ($row) $pryy = substr($row[0],0,4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defined("PROPALE_DIAMANT_DELTA"))
|
// Si au moins un champ respectant le modèle a été trouvée
|
||||||
|
if (eregi('PR[0-9][0-9]',$pryy))
|
||||||
{
|
{
|
||||||
define("PROPALE_DIAMANT_DELTA", 0);
|
// Recherche rapide car restreint par un like sur champ indexé
|
||||||
|
$posindice=5;
|
||||||
|
$sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
|
||||||
|
$sql.= " WHERE ref like '${pryy}%'";
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$row = $db->fetch_row($resql);
|
||||||
|
$max = $row[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$max=$conf->global->PROPALE_DIAMANT_DELTA?$conf->global->PROPALE_DIAMANT_DELTA:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$num = $num + PROPALE_DIAMANT_DELTA;
|
$num = sprintf("%05s",$max+1);
|
||||||
|
$yy = strftime("%y",time());
|
||||||
|
|
||||||
$y = strftime("%y",time());
|
return "PR$yy$num";
|
||||||
|
|
||||||
return "PR" .$y. substr("0000".$num, strlen("0000".$num)-5,5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** \brief Renvoie la référence de propale suivante non utilisée
|
/** \brief Renvoie la référence de propale suivante non utilisée
|
||||||
* \param objsoc Objet société
|
* \param objsoc Objet société
|
||||||
* \return string Texte descripif
|
* \return string Texte descripif
|
||||||
|
|||||||
@ -72,18 +72,43 @@ class mod_propale_ivoire extends ModeleNumRefPropales
|
|||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
|
|
||||||
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."propal";
|
// D'abord on récupère la valeur max (réponse immédiate car champ indéxé)
|
||||||
|
$pryy = 'PR'.strftime("%y",time());
|
||||||
if ( $db->query($sql) )
|
$sql = "SELECT MAX(ref)";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
|
||||||
|
$sql.= " WHERE ref like '${pryy}%'";
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
if ($resql)
|
||||||
{
|
{
|
||||||
$row = $db->fetch_row(0);
|
$row = $db->fetch_row($resql);
|
||||||
|
$pryy='';
|
||||||
$num = $row[0];
|
if ($row) $pryy = substr($row[0],0,4);
|
||||||
}
|
}
|
||||||
|
|
||||||
$y = strftime("%y",time());
|
// Si au moins un champ respectant le modèle a été trouvée
|
||||||
|
if (eregi('PR[0-9][0-9]',$pryy))
|
||||||
|
{
|
||||||
|
// Recherche rapide car restreint par un like sur champ indexé
|
||||||
|
$posindice=5;
|
||||||
|
$sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
|
||||||
|
$sql.= " WHERE ref like '${pryy}%'";
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$row = $db->fetch_row($resql);
|
||||||
|
$max = $row[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$max=0;
|
||||||
|
}
|
||||||
|
|
||||||
return "PR" . "$y" . substr("000".$num, strlen("000".$num)-4,4);
|
$num = sprintf("%04s",$max+1);
|
||||||
|
$yy = strftime("%y",time());
|
||||||
|
|
||||||
|
return "PR$yy$num";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Renvoie la référence de propale suivante non utilisée
|
/** \brief Renvoie la référence de propale suivante non utilisée
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user