Merge pull request #5759 from IonAgorria/fix-sorder-delete
FIX: Move order supplier deleteline code to line class
This commit is contained in:
commit
83ba44c418
@ -1627,57 +1627,36 @@ 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);
|
||||||
|
|
||||||
|
if ($line->fetch($idline) <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->begin();
|
if ($line->delete($notrigger) > 0)
|
||||||
|
|
||||||
if (! $notrigger)
|
|
||||||
{
|
{
|
||||||
// Call trigger
|
$this->update_price();
|
||||||
$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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $error)
|
|
||||||
{
|
|
||||||
$result=$this->update_price();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $error)
|
|
||||||
{
|
|
||||||
$this->db->commit();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->error = $line->error;
|
||||||
|
$this->errors = $line->errors;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an order
|
* Delete an order
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user