/** * update * * @param User $fuser User * @return int <0 if KO, >0 if OK */ function update($fuser) { global $fuser, $langs, $conf; $error = 0; // Clean parameters $this->comments = trim($this->comments); $this->vatrate = price2num($this->vatrate); $this->db->begin(); // Mise a jour ligne en base $sql = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det SET"; $sql .= " comments='" . $this->db->escape($this->comments) . "'"; $sql .= ",value_unit=" . $this->value_unit . ""; $sql .= ",qty=" . $this->qty . ""; $sql .= ",date='" . $this->db->idate($this->date) . "'"; $sql .= ",total_ht=" . $this->total_ht . ""; $sql .= ",total_tva=" . $this->total_tva . ""; $sql .= ",total_ttc=" . $this->total_ttc . ""; $sql .= ",tva_tx=" . $this->vatrate; if ($this->fk_c_type_fees) { $sql .= ",fk_c_type_fees=" . $this->fk_c_type_fees; } else { $sql .= ",fk_c_type_fees=null"; } if ($this->fk_projet) { $sql .= ",fk_projet=" . $this->fk_projet; } else { $sql .= ",fk_projet=null"; } $sql .= " WHERE rowid = " . $this->rowid; dol_syslog("ExpenseReportLine::update sql=" . $sql); $resql = $this->db->query($sql); if ($resql) { $tmpparent = new ExpenseReport($this->db); $result = $tmpparent->fetch($this->fk_expensereport); if ($result > 0) { $result = $tmpparent->update_price(); if ($result < 0) { $error++; $this->error = $tmpparent->error; $this->errors = $tmpparent->errors; } } else { $error++; $this->error = $tmpparent->error; $this->errors = $tmpparent->errors; } } else { $error++; dol_print_error($this->db); } if (!$error) { $this->db->commit(); return 1; } else { $this->error = $this->db->lasterror(); dol_syslog("ExpenseReportLine::update Error " . $this->error, LOG_ERR); $this->db->rollback(); return -2; } }