Move order supplier deleteline code to line class

This commit is contained in:
Ion Agorria 2016-09-17 02:35:02 +02:00
parent d0136f5c85
commit 7fe0c4211c

View File

@ -1627,55 +1627,34 @@ class CommandeFournisseur extends CommonOrder
* *
* @param int $idline Id of line to delete * @param int $idline Id of line to delete
* @param int $notrigger 1=Disable call to triggers * @param int $notrigger 1=Disable call to triggers
* @return <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
public function deleteline($idline, $notrigger=0) public function deleteline($idline, $notrigger=0)
{ {
global $user,$langs,$conf; if ($this->statut == 0)
$error = 0;
if ($this->statut != 0)
{ {
return -1; $line = new CommandeFournisseurLigne($this->db);
}
$this->db->begin(); if ($line->fetch($idline) <= 0)
{
return 0;
}
if (! $notrigger) if ($line->delete($notrigger) > 0)
{ {
// Call trigger $this->update_price();
$result=$this->call_trigger('LINEORDER_SUPPLIER_DELETE',$user); return 1;
if ($result < 0) $error++; }
// End call triggers else
} {
$this->error = $line->error;
if (! $error) $this->errors = $line->errors;
{ return -1;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid = ".$idline; }
$resql=$this->db->query($sql);
dol_syslog(get_class($this)."::deleteline sql=".$sql);
if (! $resql)
{
$this->error=$this->db->lasterror();
$error++;
}
}
if (! $error)
{
$result=$this->update_price();
}
if (! $error)
{
$this->db->commit();
return 1;
} }
else else
{ {
$this->db->rollback(); return -2;
return -1;
} }
} }
@ -3202,5 +3181,55 @@ class CommandeFournisseurLigne extends CommonOrderLine
return -1; return -1;
} }
} }
/**
* Delete line in database
*
* @param int $notrigger 1=Disable call to triggers
* @return int <0 if KO, >0 if OK
*/
function delete($notrigger)
{
global $user;
$error=0;
$this->db->begin();
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid='".$this->rowid."';";
dol_syslog(__METHOD__, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
if (!$notrigger)
{
// Call trigger
$result=$this->call_trigger('LINEORDER_SUPPLIER_DELETE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (!$error)
{
$this->db->commit();
return 1;
}
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->error=$this->db->lasterror();
return -1;
}
}
} }