Fix: First try to uniformize code was not a success. Another try.

This commit is contained in:
Laurent Destailleur 2009-09-13 20:19:59 +00:00
parent 733b633ef7
commit bf13666d26
3 changed files with 38 additions and 40 deletions

View File

@ -502,12 +502,15 @@ class Commande extends CommonObject
}
/**
* \brief Create order
* \param user Objet utilisateur qui cree
* \brief Create order
* \param user Objet user that make creation
* \return int <0 if KO, >0 if OK
* \remarks this->ref can be set or empty. If empty, we will use "(PROV)"
*/
function create($user)
{
global $conf,$langs,$mysoc;
$error=0;
// Clean parameters
$this->brouillon = 1; // On positionne en mode brouillon la commande
@ -515,11 +518,13 @@ class Commande extends CommonObject
dol_syslog("Commande::create user=".$user->id);
// Check parameters
if (empty($this->ref))
{
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Ref"));
$soc = new Societe($this->db);
$result=$soc->fetch($this->socid);
if ($result < 0)
{
$this->error="Failed to fetch company";
dol_syslog("Commande::create ".$this->error, LOG_ERR);
return -1;
return -2;
}
if (! empty($conf->global->COMMANDE_REQUIRE_SOURCE) && $this->source < 0)
{
@ -530,14 +535,6 @@ class Commande extends CommonObject
if (! $remise) $remise=0;
if (! $this->projetid) $this->projetid = 0;
$soc = new Societe($this->db);
$result=$soc->fetch($this->socid);
if ($result < 0)
{
$this->error="Failed to fetch company";
dol_syslog("Commande::create ".$this->error, LOG_ERR);
return -2;
}
$this->db->begin();

View File

@ -130,11 +130,13 @@ class Facture extends CommonObject
* \brief Create invoice in database
* \param user Object user that create
* \param notrigger 1 ne declenche pas les triggers, 0 sinon
* \return int <0 si ko, >0 si ok
* \return int <0 if KO, >0 if OK
* \remarks this->ref can be set or empty. If empty, we will use "(PROV)"
*/
function create($user,$notrigger=0)
{
global $langs,$conf,$mysoc;
$error=0;
// Clean parameters
if (! $this->type) $this->type = 0;
@ -148,21 +150,15 @@ class Facture extends CommonObject
dol_syslog("Facture::Create user=".$user->id);
// Check parameters
// TODO suppression de cette verification a confirmer
// la ref est toujours vide puisque c'est une création
/*
if (empty($this->ref))
{
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Ref"));
dol_syslog("Facture::create ".$this->error, LOG_ERR);
return -1;
}
*/
$soc = new Societe($this->db);
$soc->fetch($this->socid);
$result=$soc->fetch($this->socid);
if ($result < 0)
{
$this->error="Failed to fetch company";
dol_syslog("Facture::create ".$this->error, LOG_ERR);
return -2;
}
$error=0;
$this->db->begin();

View File

@ -512,27 +512,32 @@ class Propal extends CommonObject
/**
* \brief Create commercial proposal
* \param user User that create
* \return int <0 si ko, >=0 si ok
* \return int <0 if KO, >=0 if OK
* \remarks this->ref can be set or empty. If empty, we will use "(PROV)"
*/
function create($user='')
{
global $langs,$conf,$mysoc;
$error=0;
// Clean parameters
$this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
dol_syslog("Propal::Create");
// Check parameters
if (empty($this->ref))
{
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Ref"));
dol_syslog("Facture::create ".$this->error, LOG_ERR);
return -1;
}
$soc = new Societe($this->db);
$soc->fetch($this->socid);
$this->verifyNumRef($soc); // Check ref is not yet used
$result=$soc->fetch($this->socid);
if ($result < 0)
{
$this->error="Failed to fetch company";
dol_syslog("Propal::create ".$this->error, LOG_ERR);
return -2;
}
if (! empty($this->ref))
{
$this->verifyNumRef($soc); // Check ref is not yet used
}
$this->db->begin();
@ -1972,7 +1977,7 @@ class Propal extends CommonObject
}
/**
* \brief Verifie si la ref n'est pas deja utilisee
* \brief Check if ref is used. And if used tkae next one.
* \param soc objet societe
*/
function verifyNumRef($soc)