Fix do not lose the user of expense report when we edit it.

This commit is contained in:
Laurent Destailleur 2017-02-24 15:51:10 +01:00
parent e981e719a1
commit 5733826a68

View File

@ -60,7 +60,7 @@ class ExpenseReport extends CommonObject
// Create // Create
var $date_create; var $date_create;
var $fk_user_author; // the user the expense report is for (not really the author) var $fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for.
// Update // Update
var $date_modif; var $date_modif;
@ -126,7 +126,7 @@ class ExpenseReport extends CommonObject
$now = dol_now(); $now = dol_now();
$fuserid = $this->fk_user_author; $fuserid = $this->fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for.
if (empty($fuserid)) $fuserid = $user->id; if (empty($fuserid)) $fuserid = $user->id;
$this->db->begin(); $this->db->begin();
@ -254,7 +254,7 @@ class ExpenseReport extends CommonObject
$this->statut=0; $this->statut=0;
// Clear fields // Clear fields
$this->fk_user_author = $user->id; $this->fk_user_author = $user->id; // Note fk_user_author is not the 'author' but the guy the expense report is for.
$this->fk_user_valid = ''; $this->fk_user_valid = '';
$this->date_create = ''; $this->date_create = '';
$this->date_creation = ''; $this->date_creation = '';
@ -301,9 +301,10 @@ class ExpenseReport extends CommonObject
* update * update
* *
* @param User $user User making change * @param User $user User making change
* @param User $newuser New user we want to have the expense report on.
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function update($user) function update($user, $userofexpensereport=null)
{ {
global $langs; global $langs;
@ -313,10 +314,13 @@ class ExpenseReport extends CommonObject
$sql.= " , total_tva = ".$this->total_tva; $sql.= " , total_tva = ".$this->total_tva;
$sql.= " , date_debut = '".$this->db->idate($this->date_debut)."'"; $sql.= " , date_debut = '".$this->db->idate($this->date_debut)."'";
$sql.= " , date_fin = '".$this->db->idate($this->date_fin)."'"; $sql.= " , date_fin = '".$this->db->idate($this->date_fin)."'";
$sql.= " , fk_user_author = ".($user->id > 0 ? "'".$user->id."'":"null"); if ($userofexpensereport && is_object($userofexpensereport))
{
$sql.= " , fk_user_author = ".($userofexpensereport->id > 0 ? "'".$userofexpensereport->id."'":"null"); // Note fk_user_author is not the 'author' but the guy the expense report is for.
}
$sql.= " , fk_user_validator = ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null"); $sql.= " , fk_user_validator = ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null");
$sql.= " , fk_user_valid = ".($this->fk_user_valid > 0 ? $this->fk_user_valid:"null"); $sql.= " , fk_user_valid = ".($this->fk_user_valid > 0 ? $this->fk_user_valid:"null");
$sql.= " , fk_user_modif = ".($this->fk_user_modif > 0 ? $this->fk_user_modif:"null"); $sql.= " , fk_user_modif = ".$user->id;
$sql.= " , fk_statut = ".($this->fk_statut >= 0 ? $this->fk_statut:'0'); $sql.= " , fk_statut = ".($this->fk_statut >= 0 ? $this->fk_statut:'0');
$sql.= " , fk_c_paiement = ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:"null"); $sql.= " , fk_c_paiement = ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:"null");
$sql.= " , note_public = ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"''"); $sql.= " , note_public = ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"''");
@ -388,7 +392,7 @@ class ExpenseReport extends CommonObject
$this->date_refuse = $this->db->jdate($obj->date_refuse); $this->date_refuse = $this->db->jdate($obj->date_refuse);
$this->date_cancel = $this->db->jdate($obj->date_cancel); $this->date_cancel = $this->db->jdate($obj->date_cancel);
$this->fk_user_author = $obj->fk_user_author; $this->fk_user_author = $obj->fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for.
$this->fk_user_modif = $obj->fk_user_modif; $this->fk_user_modif = $obj->fk_user_modif;
$this->fk_user_validator = $obj->fk_user_validator; $this->fk_user_validator = $obj->fk_user_validator;
$this->fk_user_valid = $obj->fk_user_valid; $this->fk_user_valid = $obj->fk_user_valid;