Merge pull request #5467 from atm-florian/add_update_trigger
NEW : review Propal/Order/Invoice class to be uniformize on triggers calls
This commit is contained in:
commit
dd7c7b9d4b
File diff suppressed because it is too large
Load Diff
@ -57,97 +57,99 @@ class Commande extends CommonOrder
|
|||||||
* Client ID
|
* Client ID
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
var $socid;
|
public $socid;
|
||||||
|
|
||||||
var $ref_client;
|
public $ref_client;
|
||||||
var $ref_int;
|
public $ref_int;
|
||||||
var $contactid;
|
public $contactid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Status of the order. Check the following constants:
|
* Status of the order. Check the following constants:
|
||||||
* @var int
|
* @var int
|
||||||
* @see Commande::STATUS_CANCELED, Commande::STATUS_DRAFT, Commande::STATUS_ACCEPTED, Commande::STATUS_CLOSED
|
* @see Commande::STATUS_CANCELED, Commande::STATUS_DRAFT, Commande::STATUS_ACCEPTED, Commande::STATUS_CLOSED
|
||||||
*/
|
*/
|
||||||
var $statut;
|
public $statut;
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* @see billed
|
* @see billed
|
||||||
*/
|
*/
|
||||||
var $facturee;
|
public $facturee;
|
||||||
var $billed; // billed or not
|
public $billed; // billed or not
|
||||||
|
|
||||||
var $brouillon;
|
public $brouillon;
|
||||||
var $cond_reglement_code;
|
public $cond_reglement_code;
|
||||||
|
|
||||||
var $fk_account;
|
public $fk_account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It holds the label of the payment mode. Use it in case translation cannot be found.
|
* It holds the label of the payment mode. Use it in case translation cannot be found.
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $mode_reglement;
|
public $mode_reglement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment mode id
|
* Payment mode id
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
var $mode_reglement_id;
|
public $mode_reglement_id;
|
||||||
/**
|
/**
|
||||||
* Payment mode code
|
* Payment mode code
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $mode_reglement_code;
|
public $mode_reglement_code;
|
||||||
/**
|
/**
|
||||||
* Availability delivery time id
|
* Availability delivery time id
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
var $availability_id;
|
public $availability_id;
|
||||||
/**
|
/**
|
||||||
* Availability delivery time code
|
* Availability delivery time code
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $availability_code;
|
public $availability_code;
|
||||||
/**
|
/**
|
||||||
* Label of availability delivery time. Use it in case translation cannot be found.
|
* Label of availability delivery time. Use it in case translation cannot be found.
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
var $availability;
|
public $availability;
|
||||||
|
|
||||||
var $demand_reason_id;
|
public $demand_reason_id;
|
||||||
var $demand_reason_code;
|
public $demand_reason_code;
|
||||||
var $address;
|
public $address;
|
||||||
var $date; // Date commande
|
public $date; // Date commande
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* @see date
|
* @see date
|
||||||
*/
|
*/
|
||||||
var $date_commande;
|
public $date_commande;
|
||||||
var $date_livraison; // Date livraison souhaitee
|
public $date_livraison; // Date livraison souhaitee
|
||||||
var $fk_remise_except;
|
public $fk_remise_except;
|
||||||
var $remise_percent;
|
public $remise_percent;
|
||||||
var $remise_absolue;
|
public $remise_absolue;
|
||||||
var $info_bits;
|
public $info_bits;
|
||||||
var $rang;
|
public $rang;
|
||||||
var $special_code;
|
public $special_code;
|
||||||
var $source; // Origin of order
|
public $source; // Origin of order
|
||||||
var $extraparams=array();
|
public $extraparams=array();
|
||||||
|
|
||||||
var $linked_objects=array();
|
public $linked_objects=array();
|
||||||
|
|
||||||
var $user_author_id;
|
public $user_author_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var OrderLine[]
|
* @var OrderLine[]
|
||||||
*/
|
*/
|
||||||
var $lines = array();
|
public $lines = array();
|
||||||
|
|
||||||
// Multicurrency
|
// Multicurrency
|
||||||
var $fk_multicurrency;
|
public $fk_multicurrency;
|
||||||
var $multicurrency_code;
|
public $multicurrency_code;
|
||||||
var $multicurrency_tx;
|
public $multicurrency_tx;
|
||||||
var $multicurrency_total_ht;
|
public $multicurrency_total_ht;
|
||||||
var $multicurrency_total_tva;
|
public $multicurrency_total_tva;
|
||||||
var $multicurrency_total_ttc;
|
public $multicurrency_total_ttc;
|
||||||
|
|
||||||
|
public $oldcopy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ERR Not enough stock
|
* ERR Not enough stock
|
||||||
@ -469,7 +471,7 @@ class Commande extends CommonOrder
|
|||||||
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
// Call trigger
|
// Call trigger
|
||||||
$result=$this->call_trigger('ORDER_SETDRAFT',$user);
|
$result=$this->call_trigger('ORDER_UNVALIDATE',$user);
|
||||||
if ($result < 0) $error++;
|
if ($result < 0) $error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2044,30 +2046,62 @@ 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 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @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))
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->remise_percent = $remise;
|
$this->errors[]=$this->db->error();
|
||||||
$this->update_price(1);
|
$error++;
|
||||||
return 1;
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->oldcopy= clone $this;
|
||||||
|
$this->remise_percent = $remise;
|
||||||
|
$this->update_price(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$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 +2112,62 @@ 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 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @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);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
if ($this->db->query($sql))
|
if (!$resql)
|
||||||
{
|
{
|
||||||
$this->remise_absolue = $remise;
|
$this->errors[]=$this->db->error();
|
||||||
$this->update_price(1);
|
$error++;
|
||||||
return 1;
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->oldcopy= clone $this;
|
||||||
|
$this->remise_absolue = $remise;
|
||||||
|
$this->update_price(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$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 +2176,59 @@ 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 1=Does not execute triggers, 0= execuete triggers
|
||||||
|
* @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 (! $error)
|
||||||
|
{
|
||||||
|
$this->oldcopy= clone $this;
|
||||||
|
$this->date = $date;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$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,29 +2240,59 @@ 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 1=Does not execute triggers, 0= execuete triggers
|
||||||
|
* @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)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."commande";
|
||||||
$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 (! $error)
|
||||||
|
{
|
||||||
|
$this->oldcopy= clone $this;
|
||||||
|
$this->date_livraison = $date_livraison;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$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,26 +2306,57 @@ 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 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @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)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande ";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."commande ";
|
||||||
$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 (! $error)
|
||||||
|
{
|
||||||
|
$this->oldcopy= clone $this;
|
||||||
|
$this->fk_availability = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$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,28 +2364,60 @@ 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 1=Does not execute triggers, 0= execuete triggers
|
||||||
|
* @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)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande ";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."commande ";
|
||||||
$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 (! $error)
|
||||||
|
{
|
||||||
|
$this->oldcopy= clone $this;
|
||||||
|
$this->fk_input_reason = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$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,69 +2496,137 @@ 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 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @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)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$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 (! $error)
|
||||||
|
{
|
||||||
|
$this->oldcopy= clone $this;
|
||||||
|
$this->availability_id = $availability_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$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 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @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)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$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 (! $error)
|
||||||
|
{
|
||||||
|
$this->oldcopy= clone $this;
|
||||||
|
$this->demand_reason_id = $demand_reason_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2381,27 +2636,57 @@ class Commande extends CommonOrder
|
|||||||
*
|
*
|
||||||
* @param User $user User that make change
|
* @param User $user User that make change
|
||||||
* @param string $ref_client Customer ref
|
* @param string $ref_client Customer ref
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_ref_client($user, $ref_client)
|
function set_ref_client($user, $ref_client, $notrigger=0)
|
||||||
{
|
{
|
||||||
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);
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$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 (! $error)
|
||||||
|
{
|
||||||
|
$this->oldcopy= clone $this;
|
||||||
|
$this->ref_client = $ref_client;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$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
|
||||||
@ -2413,10 +2698,11 @@ class Commande extends CommonOrder
|
|||||||
/**
|
/**
|
||||||
* Classify the order as invoiced
|
* Classify the order as invoiced
|
||||||
*
|
*
|
||||||
* @param User $user Object user making the change
|
* @param User $user Object user making the change
|
||||||
* @return int <0 if KO, >0 if OK
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function classifyBilled(User $user)
|
function classifyBilled(User $user, $notrigger=0)
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
@ -2429,16 +2715,24 @@ class Commande extends CommonOrder
|
|||||||
dol_syslog(get_class($this)."::classifyBilled", LOG_DEBUG);
|
dol_syslog(get_class($this)."::classifyBilled", LOG_DEBUG);
|
||||||
if ($this->db->query($sql))
|
if ($this->db->query($sql))
|
||||||
{
|
{
|
||||||
// Call trigger
|
|
||||||
$result=$this->call_trigger('ORDER_CLASSIFY_BILLED',$user);
|
|
||||||
if ($result < 0) $error++;
|
|
||||||
// End call triggers
|
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
$this->oldcopy= clone $this;
|
||||||
$this->facturee=1; // deprecated
|
$this->facturee=1; // deprecated
|
||||||
$this->billed=1;
|
$this->billed=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('ORDER_CLASSIFY_BILLED',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -2494,6 +2788,13 @@ class Commande extends CommonOrder
|
|||||||
dol_syslog(get_class($this)."::classifyUnBilled", LOG_DEBUG);
|
dol_syslog(get_class($this)."::classifyUnBilled", LOG_DEBUG);
|
||||||
if ($this->db->query($sql))
|
if ($this->db->query($sql))
|
||||||
{
|
{
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->oldcopy= clone $this;
|
||||||
|
$this->facturee=1; // deprecated
|
||||||
|
$this->billed=1;
|
||||||
|
}
|
||||||
|
|
||||||
// Call trigger
|
// Call trigger
|
||||||
$result=$this->call_trigger('ORDER_CLASSIFY_UNBILLED',$user);
|
$result=$this->call_trigger('ORDER_CLASSIFY_UNBILLED',$user);
|
||||||
if ($result < 0) $error++;
|
if ($result < 0) $error++;
|
||||||
|
|||||||
@ -59,63 +59,63 @@ class Facture extends CommonInvoice
|
|||||||
*/
|
*/
|
||||||
protected $table_ref_field = 'facnumber';
|
protected $table_ref_field = 'facnumber';
|
||||||
|
|
||||||
var $socid;
|
public $socid;
|
||||||
|
|
||||||
var $author;
|
public $author;
|
||||||
var $fk_user_author;
|
public $fk_user_author;
|
||||||
var $fk_user_valid;
|
public $fk_user_valid;
|
||||||
var $date; // Date invoice
|
public $date; // Date invoice
|
||||||
var $date_creation; // Creation date
|
public $date_creation; // Creation date
|
||||||
var $date_validation; // Validation date
|
public $date_validation; // Validation date
|
||||||
var $datem;
|
public $datem;
|
||||||
var $ref_client;
|
public $ref_client;
|
||||||
var $ref_int;
|
public $ref_int;
|
||||||
//Check constants for types
|
//Check constants for types
|
||||||
var $type = self::TYPE_STANDARD;
|
public $type = self::TYPE_STANDARD;
|
||||||
|
|
||||||
//var $amount;
|
//var $amount;
|
||||||
var $remise_absolue;
|
public $remise_absolue;
|
||||||
var $remise_percent;
|
public $remise_percent;
|
||||||
var $total_ht=0;
|
public $total_ht=0;
|
||||||
var $total_tva=0;
|
public $total_tva=0;
|
||||||
var $total_ttc=0;
|
public $total_ttc=0;
|
||||||
var $revenuestamp;
|
public $revenuestamp;
|
||||||
|
|
||||||
//! Fermeture apres paiement partiel: discount_vat, badcustomer, abandon
|
//! Fermeture apres paiement partiel: discount_vat, badcustomer, abandon
|
||||||
//! Fermeture alors que aucun paiement: replaced (si remplace), abandon
|
//! Fermeture alors que aucun paiement: replaced (si remplace), abandon
|
||||||
var $close_code;
|
public $close_code;
|
||||||
//! Commentaire si mis a paye sans paiement complet
|
//! Commentaire si mis a paye sans paiement complet
|
||||||
var $close_note;
|
public $close_note;
|
||||||
//! 1 if invoice paid COMPLETELY, 0 otherwise (do not use it anymore, use statut and close_code)
|
//! 1 if invoice paid COMPLETELY, 0 otherwise (do not use it anymore, use statut and close_code)
|
||||||
var $paye;
|
public $paye;
|
||||||
//! id of source invoice if replacement invoice or credit note
|
//! id of source invoice if replacement invoice or credit note
|
||||||
var $fk_facture_source;
|
public $fk_facture_source;
|
||||||
var $linked_objects=array();
|
public $linked_objects=array();
|
||||||
var $date_lim_reglement;
|
public $date_lim_reglement;
|
||||||
var $cond_reglement_code; // Code in llx_c_paiement
|
public $cond_reglement_code; // Code in llx_c_paiement
|
||||||
var $mode_reglement_code; // Code in llx_c_paiement
|
public $mode_reglement_code; // Code in llx_c_paiement
|
||||||
var $fk_bank; // Field to store bank id to use when payment mode is withdraw
|
public $fk_bank; // Field to store bank id to use when payment mode is withdraw
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
var $products=array();
|
public $products=array();
|
||||||
/**
|
/**
|
||||||
* @var FactureLigne[]
|
* @var FactureLigne[]
|
||||||
*/
|
*/
|
||||||
var $lines=array();
|
public $lines=array();
|
||||||
var $line;
|
public $line;
|
||||||
var $extraparams=array();
|
public $extraparams=array();
|
||||||
var $specimen;
|
public $specimen;
|
||||||
|
|
||||||
var $fac_rec;
|
public $fac_rec;
|
||||||
|
|
||||||
// Multicurrency
|
// Multicurrency
|
||||||
var $fk_multicurrency;
|
public $fk_multicurrency;
|
||||||
var $multicurrency_code;
|
public $multicurrency_code;
|
||||||
var $multicurrency_tx;
|
public $multicurrency_tx;
|
||||||
var $multicurrency_total_ht;
|
public $multicurrency_total_ht;
|
||||||
var $multicurrency_total_tva;
|
public $multicurrency_total_tva;
|
||||||
var $multicurrency_total_ttc;
|
public $multicurrency_total_ttc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int Situation cycle reference number
|
* @var int Situation cycle reference number
|
||||||
@ -142,6 +142,8 @@ class Facture extends CommonInvoice
|
|||||||
*/
|
*/
|
||||||
public $tab_next_situation_invoice=array();
|
public $tab_next_situation_invoice=array();
|
||||||
|
|
||||||
|
public $oldcopy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard invoice
|
* Standard invoice
|
||||||
*/
|
*/
|
||||||
@ -1486,25 +1488,60 @@ class Facture extends CommonInvoice
|
|||||||
* Set customer ref
|
* Set customer ref
|
||||||
*
|
*
|
||||||
* @param string $ref_client Customer ref
|
* @param string $ref_client Customer ref
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function set_ref_client($ref_client)
|
function set_ref_client($ref_client, $notrigger=0)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
||||||
if (empty($ref_client))
|
if (empty($ref_client))
|
||||||
$sql .= ' SET ref_client = NULL';
|
$sql .= ' SET ref_client = NULL';
|
||||||
else
|
else
|
||||||
$sql .= ' SET ref_client = \''.$this->db->escape($ref_client).'\'';
|
$sql .= ' SET ref_client = \''.$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->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
{
|
{
|
||||||
$this->ref_client = $ref_client;
|
$this->ref_client = $ref_client;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('BILL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->ref_client = $ref_client;
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_print_error($this->db);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2070,7 +2107,7 @@ class Facture extends CommonInvoice
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
if ($final) {
|
if ($final) {
|
||||||
$this->setFinal();
|
$this->setFinal($user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2760,9 +2797,10 @@ class Facture extends CommonInvoice
|
|||||||
*
|
*
|
||||||
* @param User $user User that set discount
|
* @param User $user User that set discount
|
||||||
* @param double $remise Discount
|
* @param double $remise Discount
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @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)
|
||||||
{
|
{
|
||||||
// Clean parameters
|
// Clean parameters
|
||||||
if (empty($remise)) $remise=0;
|
if (empty($remise)) $remise=0;
|
||||||
@ -2771,21 +2809,48 @@ class Facture extends CommonInvoice
|
|||||||
{
|
{
|
||||||
$remise=price2num($remise);
|
$remise=price2num($remise);
|
||||||
|
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
||||||
$sql.= ' SET remise_percent = '.$remise;
|
$sql.= ' SET remise_percent = '.$remise;
|
||||||
$sql.= ' WHERE rowid = '.$this->id;
|
$sql.= ' WHERE rowid = '.$this->id;
|
||||||
$sql.= ' AND fk_statut = '.self::STATUS_DRAFT;
|
$sql.= ' AND fk_statut = '.self::STATUS_DRAFT;
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
|
{
|
||||||
|
$this->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('BILL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
{
|
{
|
||||||
$this->remise_percent = $remise;
|
$this->remise_percent = $remise;
|
||||||
$this->update_price(1);
|
$this->update_price(1);
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
return 1;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2796,14 +2861,19 @@ class Facture extends CommonInvoice
|
|||||||
*
|
*
|
||||||
* @param User $user User that set discount
|
* @param User $user User that set discount
|
||||||
* @param double $remise Discount
|
* @param double $remise Discount
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
* @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)
|
||||||
{
|
{
|
||||||
if (empty($remise)) $remise=0;
|
if (empty($remise)) $remise=0;
|
||||||
|
|
||||||
if ($user->rights->facture->creer)
|
if ($user->rights->facture->creer)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$remise=price2num($remise);
|
$remise=price2num($remise);
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
||||||
@ -2811,18 +2881,43 @@ class Facture extends CommonInvoice
|
|||||||
$sql.= ' WHERE rowid = '.$this->id;
|
$sql.= ' WHERE rowid = '.$this->id;
|
||||||
$sql.= ' AND fk_statut = '.self::STATUS_DRAFT;
|
$sql.= ' AND fk_statut = '.self::STATUS_DRAFT;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::set_remise_absolue", LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
if ($this->db->query($sql))
|
if (!$resql)
|
||||||
{
|
{
|
||||||
|
$this->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->oldcopy= clone $this;
|
||||||
$this->remise_absolue = $remise;
|
$this->remise_absolue = $remise;
|
||||||
$this->update_price(1);
|
$this->update_price(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('BILL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
return 1;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3819,25 +3914,49 @@ class Facture extends CommonInvoice
|
|||||||
/**
|
/**
|
||||||
* Sets the invoice as a final situation
|
* Sets the invoice as a final situation
|
||||||
*
|
*
|
||||||
* @return int 1 if ok, -1 if error
|
* @param User $user Object user
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function setFinal()
|
function setFinal(User $user, $notrigger=0)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$this->situation_final = 1;
|
$this->situation_final = 1;
|
||||||
$sql = 'update ' . MAIN_DB_PREFIX . 'facture set situation_final = ' . $this->situation_final . ' where rowid = ' . $this->id;
|
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture SET situation_final = ' . $this->situation_final . ' where rowid = ' . $this->id;
|
||||||
$resql = $this->db->query($sql);
|
|
||||||
if ($resql) {
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
// FIXME: call triggers MODIFY because we modify invoice
|
$resql=$this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
|
{
|
||||||
|
$this->errors[]=$this->db->error();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $notrigger && empty($error))
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result=$this->call_trigger('BILL_MODIFY',$user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
}
|
||||||
$this->error = $this->db->lasterror();
|
else
|
||||||
dol_syslog(get_class($this) . "::update Error setFinal " . $sql, LOG_ERR);
|
{
|
||||||
|
foreach($this->errors as $errmsg)
|
||||||
|
{
|
||||||
|
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||||
|
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||||
|
}
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1*$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user