2
0
forked from Wavyzz/dolibarr

Fix: ajout d'une vrification de l'existence de la ref lorsque plusieurs utilisateurs cres des propales en mme temps

This commit is contained in:
Regis Houssin
2007-05-28 20:48:44 +00:00
parent c4745e1a81
commit 9863d4d7be

View File

@@ -463,15 +463,20 @@ class Propal extends CommonObject
function create($user='')
{
global $langs,$conf,$mysoc;
// Nettoyage/d<>finition param<61>tres
$this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
$soc = new Societe($this->db);
$soc->fetch($this->socid);
$this->verifyNumRef($soc);
dolibarr_syslog("Propal.class::create ref=".$this->ref);
// Nettoyage/d<>finition param<61>tres
$this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
$this->db->begin();
dolibarr_syslog("Propal.class::create ref=".$this->ref);
$this->fetch_client();
$this->db->begin();
$this->fetch_client();
// Insertion dans la base
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (fk_soc, price, remise, remise_percent, remise_absolue,";
@@ -2053,6 +2058,70 @@ class Propal extends CommonObject
return -1;
}
}
/**
* \brief V<>rifie si la ref n'est pas d<>j<EFBFBD> utilis<69>e
* \param soc objet societe
*/
function verifyNumRef($soc)
{
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref = '".$this->ref."'";
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
if ($num > 0)
{
$this->ref = $this->getNextNumRef($soc);
}
}
}
/**
* \brief Renvoie la r<>f<EFBFBD>rence de propale suivante non utilis<69>e en fonction du module
* de num<75>rotation actif d<>fini dans PROPALE_ADDON
* \param soc objet societe
* \return string reference libre pour la propale
*/
function getNextNumRef($soc)
{
global $db, $langs;
$langs->load("propal");
$dir = DOL_DOCUMENT_ROOT . "/includes/modules/propale/";
if (defined("PROPALE_ADDON") && PROPALE_ADDON)
{
$file = PROPALE_ADDON.".php";
// Chargement de la classe de num<75>rotation
$classname = PROPALE_ADDON;
require_once($dir.$file);
$obj = new $classname();
$numref = "";
$numref = $obj->getNextValue($soc,$this);
if ( $numref != "")
{
return $numref;
}
else
{
dolibarr_print_error($db,"Propale::getNextNumRef ".$obj->error);
return "";
}
}
else
{
print $langs->trans("Error")." ".$langs->trans("Error_PROPALE_ADDON_NotDefined");
return "";
}
}
}