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
File diff suppressed because it is too large
Load Diff
@ -59,63 +59,63 @@ class Facture extends CommonInvoice
|
||||
*/
|
||||
protected $table_ref_field = 'facnumber';
|
||||
|
||||
var $socid;
|
||||
public $socid;
|
||||
|
||||
var $author;
|
||||
var $fk_user_author;
|
||||
var $fk_user_valid;
|
||||
var $date; // Date invoice
|
||||
var $date_creation; // Creation date
|
||||
var $date_validation; // Validation date
|
||||
var $datem;
|
||||
var $ref_client;
|
||||
var $ref_int;
|
||||
public $author;
|
||||
public $fk_user_author;
|
||||
public $fk_user_valid;
|
||||
public $date; // Date invoice
|
||||
public $date_creation; // Creation date
|
||||
public $date_validation; // Validation date
|
||||
public $datem;
|
||||
public $ref_client;
|
||||
public $ref_int;
|
||||
//Check constants for types
|
||||
var $type = self::TYPE_STANDARD;
|
||||
public $type = self::TYPE_STANDARD;
|
||||
|
||||
//var $amount;
|
||||
var $remise_absolue;
|
||||
var $remise_percent;
|
||||
var $total_ht=0;
|
||||
var $total_tva=0;
|
||||
var $total_ttc=0;
|
||||
var $revenuestamp;
|
||||
public $remise_absolue;
|
||||
public $remise_percent;
|
||||
public $total_ht=0;
|
||||
public $total_tva=0;
|
||||
public $total_ttc=0;
|
||||
public $revenuestamp;
|
||||
|
||||
//! Fermeture apres paiement partiel: discount_vat, badcustomer, abandon
|
||||
//! Fermeture alors que aucun paiement: replaced (si remplace), abandon
|
||||
var $close_code;
|
||||
public $close_code;
|
||||
//! 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)
|
||||
var $paye;
|
||||
public $paye;
|
||||
//! id of source invoice if replacement invoice or credit note
|
||||
var $fk_facture_source;
|
||||
var $linked_objects=array();
|
||||
var $date_lim_reglement;
|
||||
var $cond_reglement_code; // Code in llx_c_paiement
|
||||
var $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_facture_source;
|
||||
public $linked_objects=array();
|
||||
public $date_lim_reglement;
|
||||
public $cond_reglement_code; // Code in llx_c_paiement
|
||||
public $mode_reglement_code; // Code in llx_c_paiement
|
||||
public $fk_bank; // Field to store bank id to use when payment mode is withdraw
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
var $products=array();
|
||||
public $products=array();
|
||||
/**
|
||||
* @var FactureLigne[]
|
||||
*/
|
||||
var $lines=array();
|
||||
var $line;
|
||||
var $extraparams=array();
|
||||
var $specimen;
|
||||
public $lines=array();
|
||||
public $line;
|
||||
public $extraparams=array();
|
||||
public $specimen;
|
||||
|
||||
var $fac_rec;
|
||||
public $fac_rec;
|
||||
|
||||
// Multicurrency
|
||||
var $fk_multicurrency;
|
||||
var $multicurrency_code;
|
||||
var $multicurrency_tx;
|
||||
var $multicurrency_total_ht;
|
||||
var $multicurrency_total_tva;
|
||||
var $multicurrency_total_ttc;
|
||||
public $fk_multicurrency;
|
||||
public $multicurrency_code;
|
||||
public $multicurrency_tx;
|
||||
public $multicurrency_total_ht;
|
||||
public $multicurrency_total_tva;
|
||||
public $multicurrency_total_ttc;
|
||||
|
||||
/**
|
||||
* @var int Situation cycle reference number
|
||||
@ -142,6 +142,8 @@ class Facture extends CommonInvoice
|
||||
*/
|
||||
public $tab_next_situation_invoice=array();
|
||||
|
||||
public $oldcopy;
|
||||
|
||||
/**
|
||||
* Standard invoice
|
||||
*/
|
||||
@ -1486,25 +1488,60 @@ class Facture extends CommonInvoice
|
||||
* Set 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
|
||||
*/
|
||||
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';
|
||||
if (empty($ref_client))
|
||||
$sql .= ' SET ref_client = NULL';
|
||||
else
|
||||
$sql .= ' SET ref_client = \''.$this->db->escape($ref_client).'\'';
|
||||
$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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
return -1;
|
||||
foreach($this->errors as $errmsg)
|
||||
{
|
||||
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++;
|
||||
}
|
||||
if ($final) {
|
||||
$this->setFinal();
|
||||
$this->setFinal($user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2760,9 +2797,10 @@ class Facture extends CommonInvoice
|
||||
*
|
||||
* @param User $user User that set discount
|
||||
* @param double $remise Discount
|
||||
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||
* @return int <0 if ko, >0 if ok
|
||||
*/
|
||||
function set_remise($user, $remise)
|
||||
function set_remise($user, $remise, $notrigger=0)
|
||||
{
|
||||
// Clean parameters
|
||||
if (empty($remise)) $remise=0;
|
||||
@ -2771,21 +2809,48 @@ class Facture extends CommonInvoice
|
||||
{
|
||||
$remise=price2num($remise);
|
||||
|
||||
$error=0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
||||
$sql.= ' SET remise_percent = '.$remise;
|
||||
$sql.= ' WHERE rowid = '.$this->id;
|
||||
$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->update_price(1);
|
||||
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
foreach($this->errors as $errmsg)
|
||||
{
|
||||
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 double $remise Discount
|
||||
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
|
||||
* @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 ($user->rights->facture->creer)
|
||||
{
|
||||
$error=0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$remise=price2num($remise);
|
||||
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
|
||||
@ -2811,18 +2881,43 @@ class Facture extends CommonInvoice
|
||||
$sql.= ' WHERE rowid = '.$this->id;
|
||||
$sql.= ' AND fk_statut = '.self::STATUS_DRAFT;
|
||||
|
||||
dol_syslog(get_class($this)."::set_remise_absolue", LOG_DEBUG);
|
||||
|
||||
if ($this->db->query($sql))
|
||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if (!$resql)
|
||||
{
|
||||
$this->errors[]=$this->db->error();
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->oldcopy= clone $this;
|
||||
$this->remise_absolue = $remise;
|
||||
$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;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
foreach($this->errors as $errmsg)
|
||||
{
|
||||
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
|
||||
*
|
||||
* @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;
|
||||
$sql = 'update ' . MAIN_DB_PREFIX . 'facture set situation_final = ' . $this->situation_final . ' where rowid = ' . $this->id;
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
// FIXME: call triggers MODIFY because we modify invoice
|
||||
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture SET situation_final = ' . $this->situation_final . ' where rowid = ' . $this->id;
|
||||
|
||||
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->db->commit();
|
||||
return 1;
|
||||
} else {
|
||||
$this->error = $this->db->lasterror();
|
||||
dol_syslog(get_class($this) . "::update Error setFinal " . $sql, LOG_ERR);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($this->errors as $errmsg)
|
||||
{
|
||||
dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR);
|
||||
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||
}
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
return -1*$error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user