NEW : Add ORDER_MODIFY trigger on each order modification
This commit is contained in:
parent
a95335d869
commit
80d3c68c07
@ -2044,30 +2044,57 @@ class Commande extends CommonOrder
|
|||||||
*
|
*
|
||||||
* @param User $user User qui positionne la remise
|
* @param User $user User qui positionne la remise
|
||||||
* @param float $remise Discount (percent)
|
* @param float $remise Discount (percent)
|
||||||
|
* @param int $notrigger Not Trigger
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_remise($user, $remise)
|
function set_remise($user, $remise, $notrigger=0)
|
||||||
{
|
{
|
||||||
$remise=trim($remise)?trim($remise):0;
|
$remise=trim($remise)?trim($remise):0;
|
||||||
|
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$remise=price2num($remise);
|
$remise=price2num($remise);
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
||||||
$sql.= ' SET remise_percent = '.$remise;
|
$sql.= ' SET remise_percent = '.$remise;
|
||||||
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;';
|
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;';
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->remise_percent = $remise;
|
$this->errors[]=$this->db->error();
|
||||||
$this->update_price(1);
|
$error++;
|
||||||
return 1;
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->remise_percent = $remise;
|
||||||
|
$this->update_price(1);
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
return -1;
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2078,32 +2105,59 @@ class Commande extends CommonOrder
|
|||||||
*
|
*
|
||||||
* @param User $user User qui positionne la remise
|
* @param User $user User qui positionne la remise
|
||||||
* @param float $remise Discount
|
* @param float $remise Discount
|
||||||
|
* @param int $notrigger Not Trigger
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_remise_absolue($user, $remise)
|
function set_remise_absolue($user, $remise, $notrigger=0)
|
||||||
{
|
{
|
||||||
$remise=trim($remise)?trim($remise):0;
|
$remise=trim($remise)?trim($remise):0;
|
||||||
|
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$remise=price2num($remise);
|
$remise=price2num($remise);
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
||||||
$sql.= ' SET remise_absolue = '.$remise;
|
$sql.= ' SET remise_absolue = '.$remise;
|
||||||
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;';
|
$sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;';
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::set_remise_absolue", LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->remise_absolue = $remise;
|
$this->errors[]=$this->db->error();
|
||||||
$this->update_price(1);
|
$error++;
|
||||||
return 1;
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->remise_absolue = $remise;
|
||||||
|
$this->update_price(1);
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
return -1;
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2112,29 +2166,56 @@ class Commande extends CommonOrder
|
|||||||
/**
|
/**
|
||||||
* Set the order date
|
* Set the order date
|
||||||
*
|
*
|
||||||
* @param User $user Object user making change
|
* @param User $user Object user making change
|
||||||
* @param int $date Date
|
* @param int $date Date
|
||||||
* @return int <0 if KO, >0 if OK
|
* @param int $notrigger Not Trigger
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_date($user, $date)
|
function set_date($user, $date, $notrigger=0)
|
||||||
{
|
{
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."commande";
|
||||||
$sql.= " SET date_commande = ".($date ? $this->db->idate($date) : 'null');
|
$sql.= " SET date_commande = ".($date ? $this->db->idate($date) : 'null');
|
||||||
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT;
|
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::set_date",LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->date = $date;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->date = $date;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
return -1;
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2146,11 +2227,12 @@ class Commande extends CommonOrder
|
|||||||
/**
|
/**
|
||||||
* Set the planned delivery date
|
* Set the planned delivery date
|
||||||
*
|
*
|
||||||
* @param User $user Objet utilisateur qui modifie
|
* @param User $user Objet utilisateur qui modifie
|
||||||
* @param int $date_livraison Date de livraison
|
* @param int $date_livraison Date de livraison
|
||||||
* @return int <0 si ko, >0 si ok
|
* @param int $notrigger Not Trigger
|
||||||
|
* @return int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
function set_date_livraison($user, $date_livraison)
|
function set_date_livraison($user, $date_livraison, $notrigger=0)
|
||||||
{
|
{
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
@ -2158,17 +2240,38 @@ class Commande extends CommonOrder
|
|||||||
$sql.= " SET date_livraison = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
|
$sql.= " SET date_livraison = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->date_livraison = $date_livraison;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->date_livraison = $date_livraison;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
return -1;
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2182,9 +2285,10 @@ class Commande extends CommonOrder
|
|||||||
*
|
*
|
||||||
* @param User $user Object user making change
|
* @param User $user Object user making change
|
||||||
* @param int $id If of availability delay
|
* @param int $id If of availability delay
|
||||||
|
* @param int $notrigger Not Trigger
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_availability($user, $id)
|
function set_availability($user, $id, $notrigger=0)
|
||||||
{
|
{
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
@ -2192,16 +2296,38 @@ class Commande extends CommonOrder
|
|||||||
$sql.= " SET fk_availability = '".$id."'";
|
$sql.= " SET fk_availability = '".$id."'";
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->fk_availability = $id;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->fk_availability = $id;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
dol_syslog(get_class($this)."::set_availability Erreur SQL");
|
{
|
||||||
return -1;
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2209,11 +2335,12 @@ class Commande extends CommonOrder
|
|||||||
/**
|
/**
|
||||||
* Set source of demand
|
* Set source of demand
|
||||||
*
|
*
|
||||||
* @param User $user Object user making change
|
* @param User $user Object user making change
|
||||||
* @param int $id Id of source
|
* @param int $id Id of source
|
||||||
* @return int <0 if KO, >0 if OK
|
* @param int $notrigger Not Trigger
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_demand_reason($user, $id)
|
function set_demand_reason($user, $id, $notrigger=0)
|
||||||
{
|
{
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
@ -2221,16 +2348,38 @@ class Commande extends CommonOrder
|
|||||||
$sql.= " SET fk_input_reason = '".$id."'";
|
$sql.= " SET fk_input_reason = '".$id."'";
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->fk_input_reason = $id;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->fk_input_reason = $id;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
foreach($this->errors as $errmsg)
|
||||||
dol_syslog(get_class($this)."::set_demand_reason Erreur SQL");
|
{
|
||||||
return -1;
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2309,12 +2458,13 @@ class Commande extends CommonOrder
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change le delai de livraison
|
* Update delivery delay
|
||||||
*
|
*
|
||||||
* @param int $availability_id Id du nouveau mode
|
* @param int $availability_id Id du nouveau mode
|
||||||
|
* @param int $notrigger Not Trigger
|
||||||
* @return int >0 if OK, <0 if KO
|
* @return int >0 if OK, <0 if KO
|
||||||
*/
|
*/
|
||||||
function availability($availability_id)
|
function availability($availability_id, $notrigger=0)
|
||||||
{
|
{
|
||||||
dol_syslog('Commande::availability('.$availability_id.')');
|
dol_syslog('Commande::availability('.$availability_id.')');
|
||||||
if ($this->statut >= self::STATUS_DRAFT)
|
if ($this->statut >= self::STATUS_DRAFT)
|
||||||
@ -2322,33 +2472,59 @@ class Commande extends CommonOrder
|
|||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
||||||
$sql .= ' SET fk_availability = '.$availability_id;
|
$sql .= ' SET fk_availability = '.$availability_id;
|
||||||
$sql .= ' WHERE rowid='.$this->id;
|
$sql .= ' WHERE rowid='.$this->id;
|
||||||
if ( $this->db->query($sql) )
|
|
||||||
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->availability_id = $availability_id;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->availability_id = $availability_id;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_syslog('Commande::availability Erreur '.$sql.' - '.$this->db->error(), LOG_ERR);
|
foreach($this->errors as $errmsg)
|
||||||
$this->error=$this->db->lasterror();
|
{
|
||||||
return -1;
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_syslog('Commande::availability, etat facture incompatible', LOG_ERR);
|
$error_str='Command status do not meet requirement '.$this->statut;
|
||||||
$this->error='Etat commande incompatible '.$this->statut;
|
dol_syslog(__METHOD__.$error_str, LOG_ERR);
|
||||||
|
$this->error=$error_str;
|
||||||
|
$this->errors[]= $this->error;
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change la source de la demande
|
* Update order demand_reason
|
||||||
*
|
*
|
||||||
* @param int $demand_reason_id Id of new demand
|
* @param int $demand_reason_id Id of new demand
|
||||||
|
* @param int $notrigger Not Trigger
|
||||||
* @return int >0 if ok, <0 if ko
|
* @return int >0 if ok, <0 if ko
|
||||||
*/
|
*/
|
||||||
function demand_reason($demand_reason_id)
|
function demand_reason($demand_reason_id, $notrigger=0)
|
||||||
{
|
{
|
||||||
dol_syslog('Commande::demand_reason('.$demand_reason_id.')');
|
dol_syslog('Commande::demand_reason('.$demand_reason_id.')');
|
||||||
if ($this->statut >= self::STATUS_DRAFT)
|
if ($this->statut >= self::STATUS_DRAFT)
|
||||||
@ -2356,22 +2532,47 @@ class Commande extends CommonOrder
|
|||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
||||||
$sql .= ' SET fk_input_reason = '.$demand_reason_id;
|
$sql .= ' SET fk_input_reason = '.$demand_reason_id;
|
||||||
$sql .= ' WHERE rowid='.$this->id;
|
$sql .= ' WHERE rowid='.$this->id;
|
||||||
if ( $this->db->query($sql) )
|
|
||||||
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->demand_reason_id = $demand_reason_id;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->demand_reason_id = $demand_reason_id;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_syslog('Commande::demand_reason Erreur '.$sql.' - '.$this->db->error(), LOG_ERR);
|
foreach($this->errors as $errmsg)
|
||||||
$this->error=$this->db->lasterror();
|
{
|
||||||
return -1;
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_syslog('Commande::demand_reason, etat facture incompatible', LOG_ERR);
|
$error_str='order status do not meet requirement '.$this->statut;
|
||||||
$this->error='Etat commande incompatible '.$this->statut;
|
dol_syslog(__METHOD__.$error_str, LOG_ERR);
|
||||||
|
$this->error=$error_str;
|
||||||
|
$this->errors[]= $this->error;
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2387,21 +2588,42 @@ class Commande extends CommonOrder
|
|||||||
{
|
{
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
dol_syslog(get_class($this).'::set_ref_client this->id='.$this->id.', ref_client='.$ref_client);
|
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET';
|
||||||
$sql.= ' ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\'');
|
$sql.= ' ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\'');
|
||||||
$sql.= ' WHERE rowid = '.$this->id;
|
$sql.= ' WHERE rowid = '.$this->id;
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
dol_syslog(__METHOD__.' this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->ref_client = $ref_client;
|
$this->errors[]=$this->db->error();
|
||||||
return 1;
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->ref_client = $ref_client;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->lasterror();
|
foreach($this->errors as $errmsg)
|
||||||
return -2;
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user