fix: remove invoice line id and invoice on time spend when delete line

This commit is contained in:
Florian HENRY 2023-03-03 10:22:18 +01:00
parent 10fff59357
commit 919d87a49e

View File

@ -4230,19 +4230,6 @@ class Facture extends CommonInvoice
$this->db->begin();
// Free discount linked to invoice line
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql .= ' SET fk_facture_line = NULL';
$sql .= ' WHERE fk_facture_line = '.((int) $rowid);
dol_syslog(get_class($this)."::deleteline", LOG_DEBUG);
$result = $this->db->query($sql);
if (!$result) {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
}
// Memorize previous line for triggers
$staticline = clone $line;
$line->oldline = $staticline;
@ -6441,13 +6428,38 @@ class FactureLigne extends CommonInvoiceLine
return -1;
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".((int) $this->rowid);
// Free discount linked to invoice line
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except';
$sql .= ' SET fk_facture_line = NULL';
$sql .= ' WHERE fk_facture_line = '.((int) $this->id);
dol_syslog(get_class($this)."::deleteline", LOG_DEBUG);
$result = $this->db->query($sql);
if (!$result) {
$this->error = $this->db->error();
$this->errors[] = $this->error;
$this->db->rollback();
return -1;
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.'projet_task_time';
$sql .= ' SET invoice_id = NULL, invoice_line_id = NULL';
$sql .= ' WHERE invoice_line_id = '.((int) $this->id);
if (!$this->db->query($sql)) {
$this->error = $this->db->error()." sql=".$sql;
$this->errors[] = $this->error;
$this->db->rollback();
return -1;
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".((int) $this->id);
if ($this->db->query($sql)) {
$this->db->commit();
return 1;
} else {
$this->error = $this->db->error()." sql=".$sql;
$this->errors[] = $this->error;
$this->db->rollback();
return -1;
}