Fix: Error in numbering module for receiving receipts
This commit is contained in:
parent
744bd69757
commit
5139288c18
@ -40,6 +40,8 @@ class mod_livraison_jade extends ModeleNumRefDeliveryOrder
|
|||||||
var $error = '';
|
var $error = '';
|
||||||
var $nom = "Jade";
|
var $nom = "Jade";
|
||||||
|
|
||||||
|
var $prefix='BL';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Renvoi la description du modele de numerotation
|
* \brief Renvoi la description du modele de numerotation
|
||||||
@ -57,10 +59,45 @@ class mod_livraison_jade extends ModeleNumRefDeliveryOrder
|
|||||||
*/
|
*/
|
||||||
function getExample()
|
function getExample()
|
||||||
{
|
{
|
||||||
return "BL0600001";
|
return $this->prefix."0501-0001";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** \brief Test si les numeros deja en vigueur dans la base ne provoquent pas de
|
||||||
|
* de conflits qui empechera cette numerotation de fonctionner.
|
||||||
|
* \return boolean false si conflit, true si ok
|
||||||
|
*/
|
||||||
|
function canBeActivated()
|
||||||
|
{
|
||||||
|
global $langs,$conf;
|
||||||
|
|
||||||
|
$langs->load("bills");
|
||||||
|
|
||||||
|
// Check invoice num
|
||||||
|
$fayymm=''; $max='';
|
||||||
|
|
||||||
|
$posindice=8;
|
||||||
|
$sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max"; // This is standard SQL
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."livraison";
|
||||||
|
$sql.= " WHERE facnumber LIKE '".$this->prefix."____-%'";
|
||||||
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
|
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$row = $db->fetch_row($resql);
|
||||||
|
if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; }
|
||||||
|
}
|
||||||
|
if ($fayymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$fayymm))
|
||||||
|
{
|
||||||
|
$langs->load("errors");
|
||||||
|
$this->error=$langs->trans('ErrorNumRefModel',$max);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* \brief Return next value
|
* \brief Return next value
|
||||||
* \param objsoc Object third party
|
* \param objsoc Object third party
|
||||||
* \param delivery Object delivery
|
* \param delivery Object delivery
|
||||||
@ -70,49 +107,34 @@ class mod_livraison_jade extends ModeleNumRefDeliveryOrder
|
|||||||
{
|
{
|
||||||
global $db,$conf;
|
global $db,$conf;
|
||||||
|
|
||||||
// D'abord on recupere la valeur max (reponse immediate car champ indexe)
|
// D'abord on recupere la valeur max
|
||||||
$blyy='';
|
$posindice=8;
|
||||||
|
$sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max"; // This is standard SQL
|
||||||
$sql = "SELECT MAX(ref)";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."livraison";
|
$sql.= " FROM ".MAIN_DB_PREFIX."livraison";
|
||||||
$sql.= " WHERE entity = ".$conf->entity;
|
$sql.= " WHERE ref LIKE '".$this->prefix."____-%'";
|
||||||
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
|
|
||||||
$resql=$db->query($sql);
|
$resql=$db->query($sql);
|
||||||
|
dol_syslog("mod_livraison_jade::getNextValue sql=".$sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$row = $db->fetch_row($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
if ($row) $blyy = substr($row[0],0,4);
|
if ($obj) $max = intval($obj->max);
|
||||||
}
|
else $max=0;
|
||||||
|
|
||||||
// Si au moins un champ respectant le modele a ete trouvee
|
|
||||||
if (preg_match('/BL[0-9][0-9]/i',$blyy))
|
|
||||||
{
|
|
||||||
// Recherche rapide car restreint par un like sur champ indexe
|
|
||||||
$posindice=5;
|
|
||||||
|
|
||||||
$sql = "SELECT MAX(SUBSTRING(ref,$posindice)) as max";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."livraison";
|
|
||||||
$sql.= " WHERE ref like '".$blyy."%'";
|
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
|
||||||
|
|
||||||
$resql=$db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
|
||||||
if ($obj) $max = intval($obj->max);
|
|
||||||
else $max=0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$max=0;
|
dol_syslog("mod_livraison_jade::getNextValue sql=".$sql, LOG_ERR);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$date = $delivery->date_delivery;
|
$date=$delivery->date;
|
||||||
$yy = strftime("%y",$date);
|
if (empty($date)) $date=dol_now();
|
||||||
$num = sprintf("%05s",$max+1);
|
$yymm = strftime("%y%m",$date);
|
||||||
|
$num = sprintf("%04s",$max+1);
|
||||||
|
|
||||||
return "BL$yy$num";
|
dol_syslog("mod_livraison_jade::getNextValue return ".$this->prefix.$yymm."-".$num);
|
||||||
|
return $this->prefix.$yymm."-".$num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user