Qual: Gestion du delete au sein d'une transaction
This commit is contained in:
parent
b40d98badc
commit
7dc522c946
@ -1294,42 +1294,80 @@ class Commande extends CommonObject
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Supprime une ligne de la commande
|
* \brief Supprime une ligne de la commande
|
||||||
* \param idligne Id de la ligne à supprimer
|
* \param idligne Id de la ligne à supprimer
|
||||||
* \return int >0 si ok, <0 si ko
|
* \return int >0 si ok, 0 si rien à supprimer, <0 si ko
|
||||||
* \todo ajouter une transaction SQL
|
*/
|
||||||
*/
|
function delete_line($idligne)
|
||||||
function delete_line($idligne)
|
{
|
||||||
{
|
if ($this->statut == 0)
|
||||||
if ($this->statut == 0)
|
{
|
||||||
{
|
$this->db->begin();
|
||||||
$sql = "SELECT fk_product, qty";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet";
|
|
||||||
$sql.= " WHERE rowid = '$idligne';";
|
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$sql = "SELECT fk_product, qty";
|
||||||
if ($result)
|
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet";
|
||||||
{
|
$sql.= " WHERE rowid = '$idligne'";
|
||||||
while ($obj = $this->db->fetch_object($result))
|
|
||||||
{
|
|
||||||
$product = new Product($this->db);
|
|
||||||
$product->id = $obj->fk_product;
|
|
||||||
$product->ajust_stock_commande($obj->qty, 1);
|
|
||||||
}
|
|
||||||
$this->db->free($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
$Ligne = new CommandeLigne($this->db);
|
$result = $this->db->query($sql);
|
||||||
$Ligne->id = $idligne;
|
if ($result)
|
||||||
$Ligne->fk_commande = $this->id; // On en a besoin dans les triggers
|
{
|
||||||
$result = $Ligne->Delete();
|
$obj = $this->db->fetch_object($result);
|
||||||
|
|
||||||
$this->update_price();
|
if ($obj)
|
||||||
|
{
|
||||||
|
$product = new Product($this->db);
|
||||||
|
$product->id = $obj->fk_product;
|
||||||
|
|
||||||
return $result;
|
$result=$product->ajust_stock_commande($obj->qty, 1);
|
||||||
}
|
|
||||||
}
|
// Supprime ligne
|
||||||
|
$ligne = new CommandeLigne($this->db);
|
||||||
|
$ligne->id = $idligne;
|
||||||
|
$ligne->fk_commande = $this->id; // On en a besoin dans les triggers
|
||||||
|
$result=$ligne->delete();
|
||||||
|
|
||||||
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
$result=$this->update_price();
|
||||||
|
|
||||||
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Applique une remise relative
|
* \brief Applique une remise relative
|
||||||
@ -1871,6 +1909,7 @@ class Commande extends CommonObject
|
|||||||
global $conf, $lang;
|
global $conf, $lang;
|
||||||
|
|
||||||
$err = 0;
|
$err = 0;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = $this->id ;";
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = $this->id ;";
|
||||||
@ -2325,17 +2364,18 @@ class CommandeLigne
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Supprime la ligne de commande en base
|
* \brief Supprime la ligne de commande en base
|
||||||
* \return int <0 si ko, 0 si ok
|
* \return int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
function Delete()
|
function delete()
|
||||||
{
|
{
|
||||||
global $langs, $conf, $user;
|
global $langs, $conf, $user;
|
||||||
|
|
||||||
dolibarr_syslog("CommandeLigne::Delete id=".$this->id);
|
|
||||||
|
|
||||||
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid='".$this->id."';";
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid='".$this->id."';";
|
||||||
if ($this->db->query($sql) )
|
|
||||||
|
dolibarr_syslog("CommandeLigne::delete sql=".$sql);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
{
|
{
|
||||||
// Appel des triggers
|
// Appel des triggers
|
||||||
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||||
@ -2343,11 +2383,12 @@ class CommandeLigne
|
|||||||
$result=$interface->run_triggers('LINEORDER_DELETE',$this,$user,$langs,$conf);
|
$result=$interface->run_triggers('LINEORDER_DELETE',$this,$user,$langs,$conf);
|
||||||
// Fin appel triggers
|
// Fin appel triggers
|
||||||
|
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_syslog("CommandeLigne::Delete id=".$this->id." ERROR SQL $sql");
|
$this->error=$this->db->lasterror();
|
||||||
|
dolibarr_syslog("CommandeLigne::delete ".$this->error);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user