This commit is contained in:
Laurent Destailleur 2019-06-24 18:40:31 +02:00
parent 35c3eb0d7e
commit 28deca7100

View File

@ -227,6 +227,14 @@ class DiscountAbsolute
return -1;
}
$userid = $user->id;
if (! ($userid > 0)) // For example when record is saved into an anonymous context with a not loaded object $user.
{
$tmpinvoice = new Facture($this->db);
$tmpinvoice->fetch($this->fk_facture_source);
$userid = $tmpinvoice->fk_user_author; // We use the author of invoice
}
// Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except";
$sql.= " (entity, datec, fk_soc, discount_type, fk_user, description,";
@ -234,7 +242,7 @@ class DiscountAbsolute
$sql.= " multicurrency_amount_ht, multicurrency_amount_tva, multicurrency_amount_ttc,";
$sql.= " fk_facture_source, fk_invoice_supplier_source";
$sql.= ")";
$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".(empty($this->discount_type)?0:intval($this->discount_type)).", ".$user->id.", '".$this->db->escape($this->description)."',";
$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".(empty($this->discount_type)?0:intval($this->discount_type)).", ".$userid.", '".$this->db->escape($this->description)."',";
$sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.",";
$sql.= " ".$this->multicurrency_amount_ht.", ".$this->multicurrency_amount_tva.", ".$this->multicurrency_amount_ttc.", ";
$sql.= " ".($this->fk_facture_source ? "'".$this->db->escape($this->fk_facture_source)."'":"null").",";