Skip to content
Snippets Groups Projects
Commit 83ba44c4 authored by Laurent Destailleur's avatar Laurent Destailleur Committed by GitHub
Browse files

Merge pull request #5759 from IonAgorria/fix-sorder-delete

FIX: Move order supplier deleteline code to line class
parents d0136f5c 7fe0c421
No related branches found
No related tags found
No related merge requests found
......@@ -1627,55 +1627,34 @@ class CommandeFournisseur extends CommonOrder
*
* @param int $idline Id of line to delete
* @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)
{
global $user,$langs,$conf;
$error = 0;
if ($this->statut != 0)
if ($this->statut == 0)
{
return -1;
}
$this->db->begin();
if (! $notrigger)
{
// Call trigger
$result=$this->call_trigger('LINEORDER_SUPPLIER_DELETE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (! $error)
{
$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++;
}
}
$line = new CommandeFournisseurLigne($this->db);
if (! $error)
{
$result=$this->update_price();
}
if ($line->fetch($idline) <= 0)
{
return 0;
}
if (! $error)
{
$this->db->commit();
return 1;
if ($line->delete($notrigger) > 0)
{
$this->update_price();
return 1;
}
else
{
$this->error = $line->error;
$this->errors = $line->errors;
return -1;
}
}
else
{
$this->db->rollback();
return -1;
{
return -2;
}
}
......@@ -3202,5 +3181,55 @@ class CommandeFournisseurLigne extends CommonOrderLine
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;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment