Fix: use FactureLigne class for delete line

This commit is contained in:
Regis Houssin 2011-04-10 09:47:12 +00:00
parent da05338224
commit 75bf04ec71
2 changed files with 61 additions and 28 deletions

View File

@ -1551,7 +1551,7 @@ class Commande extends CommonObject
if ($result > 0) if ($result > 0)
{ {
$result=$this->update_price(); $result=$this->update_price(1);
if ($result > 0) if ($result > 0)
{ {

View File

@ -1957,32 +1957,33 @@ class Facture extends CommonObject
return -1; return -1;
} }
// Efface ligne de facture $line=new FactureLigne($this->db);
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet';
$sql.= ' WHERE rowid = '.$rowid;
dol_syslog("Facture::Deleteline sql=".$sql); // For triggers
$result = $this->db->query($sql); $line->fetch($rowid);
if (! $result)
if ($line->delete($user) > 0)
{ {
$this->error=$this->db->error(); $result=$this->update_price(1);
dol_syslog("Facture::Deleteline Error ".$this->error, LOG_ERR);
$this->db->rollback(); if ($result > 0)
return -1; {
$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;
} }
$result=$this->update_price();
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result = $interface->run_triggers('LINEBILL_DELETE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
$this->db->commit();
return 1;
} }
/** /**
@ -3186,7 +3187,6 @@ class FactureLigne
} }
} }
/** /**
* \brief Insert line in database * \brief Insert line in database
* \param notrigger 1 no triggers * \param notrigger 1 no triggers
@ -3335,7 +3335,6 @@ class FactureLigne
} }
} }
/** /**
* Update line into database * Update line into database
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
@ -3407,6 +3406,40 @@ class FactureLigne
} }
} }
/**
* Delete line in database
* @return int <0 si ko, >0 si ok
*/
function delete($rowid)
{
global $conf,$langs,$user;
$this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$rowid;
dol_syslog("FactureLigne::delete sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql) )
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result = $interface->run_triggers('LINEBILL_DELETE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->error()." sql=".$sql;
dol_syslog("FactureLigne::delete Error ".$this->error, LOG_ERR);
$this->db->rollback();
return -1;
}
}
/** /**
* \brief Mise a jour en base des champs total_xxx de ligne de facture * \brief Mise a jour en base des champs total_xxx de ligne de facture
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok