Fix avoid duplicate fetch_optionnal when updating contract lines

This commit is contained in:
Laurent Destailleur 2021-10-25 18:28:04 +02:00
parent 4869f2ea2d
commit 1aa59a8b73

View File

@ -1729,85 +1729,77 @@ class Contrat extends CommonObject
} }
} }
$sql = "UPDATE ".MAIN_DB_PREFIX."contratdet set description='".$this->db->escape($desc)."'"; $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet set description = '".$this->db->escape($desc)."'";
$sql .= ",price_ht='".price2num($price)."'"; $sql .= ",price_ht = ".((float) price2num($price));
$sql .= ",subprice='".price2num($subprice)."'"; $sql .= ",subprice = ".((float) price2num($subprice));
$sql .= ",remise='".price2num($remise)."'"; $sql .= ",remise = ".((float) price2num($remise));
$sql .= ",remise_percent='".price2num($remise_percent)."'"; $sql .= ",remise_percent = ".((float) price2num($remise_percent));
$sql .= ",qty='".$qty."'"; $sql .= ",qty = ".((float) $qty);
$sql .= ",tva_tx='".price2num($tvatx)."'"; $sql .= ",tva_tx = ".((float) price2num($tvatx));
$sql .= ",localtax1_tx='".price2num($localtax1tx)."'"; $sql .= ",localtax1_tx = ".((float) price2num($localtax1tx));
$sql .= ",localtax2_tx='".price2num($localtax2tx)."'"; $sql .= ",localtax2_tx = ".((float) price2num($localtax2tx));
$sql .= ",localtax1_type='".$this->db->escape($localtax1_type)."'"; $sql .= ",localtax1_type='".$this->db->escape($localtax1_type);
$sql .= ",localtax2_type='".$this->db->escape($localtax2_type)."'"; $sql .= ",localtax2_type='".$this->db->escape($localtax2_type);
$sql .= ", total_ht='".price2num($total_ht)."'"; $sql .= ", total_ht = ".((float) price2num($total_ht));
$sql .= ", total_tva='".price2num($total_tva)."'"; $sql .= ", total_tva = ".((float) price2num($total_tva));
$sql .= ", total_localtax1='".price2num($total_localtax1)."'"; $sql .= ", total_localtax1 = ".((float) price2num($total_localtax1));
$sql .= ", total_localtax2='".price2num($total_localtax2)."'"; $sql .= ", total_localtax2 = ".((float) price2num($total_localtax2));
$sql .= ", total_ttc='".price2num($total_ttc)."'"; $sql .= ", total_ttc = ".((float) price2num($total_ttc));
$sql .= ", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice : "null"); $sql .= ", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice : "null");
$sql .= ", buy_price_ht='".price2num($pa_ht)."'"; $sql .= ", buy_price_ht = ".((float) price2num($pa_ht));
if ($date_start > 0) { if ($date_start > 0) {
$sql .= ",date_ouverture_prevue='".$this->db->idate($date_start)."'"; $sql .= ",date_ouverture_prevue = '".$this->db->idate($date_start)."'";
} else { } else {
$sql .= ",date_ouverture_prevue=null"; $sql .= ",date_ouverture_prevue = null";
} }
if ($date_end > 0) { if ($date_end > 0) {
$sql .= ",date_fin_validite='".$this->db->idate($date_end)."'"; $sql .= ",date_fin_validite = '".$this->db->idate($date_end)."'";
} else { } else {
$sql .= ",date_fin_validite=null"; $sql .= ",date_fin_validite = null";
} }
if ($date_debut_reel > 0) { if ($date_debut_reel > 0) {
$sql .= ",date_ouverture='".$this->db->idate($date_debut_reel)."'"; $sql .= ",date_ouverture = '".$this->db->idate($date_debut_reel)."'";
} else { } else {
$sql .= ",date_ouverture=null"; $sql .= ",date_ouverture = null";
} }
if ($date_fin_reel > 0) { if ($date_fin_reel > 0) {
$sql .= ",date_cloture='".$this->db->idate($date_fin_reel)."'"; $sql .= ",date_cloture = '".$this->db->idate($date_fin_reel)."'";
} else { } else {
$sql .= ",date_cloture=null"; $sql .= ",date_cloture = null";
} }
$sql .= ", fk_unit=".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null"); $sql .= ", fk_unit = ".($fk_unit > 0 ? ((int) $fk_unit) : "null");
$sql .= " WHERE rowid = ".((int) $rowid); $sql .= " WHERE rowid = ".((int) $rowid);
dol_syslog(get_class($this)."::updateline", LOG_DEBUG); dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) { if ($result) {
$result = $this->update_statut($user); if (is_array($array_options) && count($array_options) > 0) { // For avoid conflicts if trigger used
if ($result >= 0) { $contractline = new ContratLigne($this->db);
if (is_array($array_options) && count($array_options) > 0) { // For avoid conflicts if trigger used $contractline->fetch($rowid);
$contractline = new ContratLigne($this->db);
$contractline->fetch($rowid);
$contractline->fetch_optionals();
// We replace values in $contractline->array_options only for entries defined into $array_options // We replace values in $contractline->array_options only for entries defined into $array_options
foreach ($array_options as $key => $value) { foreach ($array_options as $key => $value) {
$contractline->array_options[$key] = $array_options[$key]; $contractline->array_options[$key] = $array_options[$key];
}
$result = $contractline->insertExtraFields();
if ($result < 0) {
$this->error[] = $contractline->error;
$error++;
}
} }
if (empty($error)) { $result = $contractline->insertExtraFields();
// Call trigger if ($result < 0) {
$result = $this->call_trigger('LINECONTRACT_UPDATE', $user); $this->error[] = $contractline->error;
if ($result < 0) { $error++;
$this->db->rollback();
return -3;
}
// End call triggers
$this->db->commit();
return 1;
} }
} else { }
$this->db->rollback();
dol_syslog(get_class($this)."::updateline Erreur -2"); if (empty($error)) {
return -2; // Call trigger
$result = $this->call_trigger('LINECONTRACT_UPDATE', $user);
if ($result < 0) {
$this->db->rollback();
return -3;
}
// End call triggers
$this->db->commit();
return 1;
} }
} else { } else {
$this->db->rollback(); $this->db->rollback();