2
0
forked from Wavyzz/dolibarr

Fix: Error management

This commit is contained in:
Laurent Destailleur
2010-11-11 22:15:54 +00:00
parent 74cb81b8d3
commit a40aed2c88

View File

@@ -556,10 +556,10 @@ class Propal extends CommonObject
/**
* \brief Create commercial proposal
* \param user User that create
* \return int <0 if KO, >=0 if OK
* \remarks this->ref can be set or empty. If empty, we will use "(PROV)"
* Create commercial proposal into database
* this->ref can be set or empty. If empty, we will use "(PROVid)"
* @param user User that create
* @return int <0 if KO, >=0 if OK
*/
function create($user='', $notrigger=0)
{
@@ -578,7 +578,7 @@ class Propal extends CommonObject
{
$this->error="Failed to fetch company";
dol_syslog("Propal::create ".$this->error, LOG_ERR);
return -2;
return -3;
}
if (! empty($this->ref))
{
@@ -590,7 +590,7 @@ class Propal extends CommonObject
$this->fetch_thirdparty();
// Insertion dans la base
// Insert into database
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (";
$sql.= "fk_soc";
$sql.= ", price";
@@ -654,6 +654,8 @@ class Propal extends CommonObject
/*
* Insertion du detail des produits dans la base
*/
if (! $error)
{
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
{
$resql = $this->addline(
@@ -676,21 +678,23 @@ class Propal extends CommonObject
if ($resql < 0)
{
$error++;
$this->error=$this->db->error;
dol_print_error($this->db);
break;
}
}
}
// Add linked object
if ($this->origin && $this->origin_id)
if (! $error && $this->origin && $this->origin_id)
{
$ret = $this->add_object_linked();
if (! $ret) dol_print_error($this->db);
}
// Affectation au projet
if ($resql && $this->fk_project)
if (! $error && $this->fk_project)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."propal";
$sql.= " SET fk_projet=".$this->fk_project;
@@ -701,7 +705,7 @@ class Propal extends CommonObject
}
// Affectation de l'adresse de livraison
if ($resql && $this->fk_delivery_address)
if (! $error && $this->fk_delivery_address)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."propal";
$sql.= " SET fk_adresse_livraison = ".$this->fk_delivery_address;
@@ -711,7 +715,7 @@ class Propal extends CommonObject
$result=$this->db->query($sql);
}
if ($resql)
if (! $error)
{
// Mise a jour infos denormalisees
$resql=$this->update_price();
@@ -726,9 +730,22 @@ class Propal extends CommonObject
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
}
else
{
$error++;
}
}
}
else
{
$error++;
}
if (! $error)
{
$this->db->commit();
dol_syslog("Propal::ass::Create done id=".$this->id);
dol_syslog("Propal::Create done id=".$this->id);
return $this->id;
}
else
@@ -739,8 +756,6 @@ class Propal extends CommonObject
return -2;
}
}
}
}
else
{
$this->error=$this->db->error();
@@ -748,10 +763,6 @@ class Propal extends CommonObject
$this->db->rollback();
return -1;
}
$this->db->commit();
dol_syslog("Propal::Create done id=".$this->id, LOG_ERR);
return $this->id;
}