135 if (isset($this->fk_pays)) {
136 $this->fk_pays = (int) $this->fk_pays;
138 if (isset($this->
active)) {
146 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
148 $sql .=
'deductible,';
153 $sql .=
'accountancy_code';
154 $sql .=
') VALUES (';
155 $sql .=
' '.(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
',';
156 $sql .=
' '.(!isset($this->deductible) ?
'NULL' :
"'".$this->db->escape($this->deductible).
"'").
',';
157 $sql .=
' ' . (int) $this->
active .
',';
158 $sql .=
' '.(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
',';
159 $sql .=
' '.(!isset($this->fk_pays) ?
'NULL' : ((int) $this->fk_pays)).
',';
160 $sql .=
' '.(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'").
',';
161 $sql .=
' '.(!isset($this->accountancy_code) ?
'NULL' :
"'".$this->db->escape($this->accountancy_code).
"'");
166 $resql = $this->db->query($sql);
169 $this->errors[] =
'Error '.$this->db->lasterror();
170 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
174 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
189 $this->db->rollback();
207 public function fetch($id, $ref =
null)
213 $sql .=
" t.libelle as label,";
214 $sql .=
" t.deductible,";
215 $sql .=
" t.active,";
217 $sql .=
" t.fk_pays,";
218 $sql .=
" t.module,";
219 $sql .=
" t.accountancy_code";
220 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
222 $sql .=
" WHERE t.code = '".$this->db->escape($ref).
"'";
224 $sql .=
' WHERE t.id = '.((int) $id);
227 $resql = $this->db->query($sql);
229 $numrows = $this->db->num_rows($resql);
231 $obj = $this->db->fetch_object($resql);
233 $this->
id = $obj->id;
235 $this->libelle = $obj->label;
236 $this->label = $obj->label;
237 $this->deductible = $obj->deductible;
238 $this->
active = $obj->active;
239 $this->code = $obj->code;
240 $this->fk_pays = $obj->fk_pays;
241 $this->module = $obj->module;
242 $this->accountancy_code = $obj->accountancy_code;
244 $this->db->free($resql);
252 $this->errors[] =
'Error '.$this->db->lasterror();
253 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
283 if (isset($this->fk_pays)) {
284 $this->fk_pays = (int) $this->fk_pays;
286 if (isset($this->
active)) {
294 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
295 $sql .=
' libelle = '.(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
',';
296 $sql .=
' deductible = '.(isset($this->deductible) ? ((int) $this->deductible) :
"null").
',';
297 $sql .=
' active = '.(isset($this->
active) ? ((int) $this->
active) :
"null").
',';
298 $sql .=
' code = '.(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
',';
299 $sql .=
' fk_pays = '.((isset($this->fk_pays) && $this->fk_pays > 0) ? ((
int) $this->fk_pays) :
"null").
',';
300 $sql .=
' module = '.(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null").
',';
301 $sql .=
' accountancy_code = '.(isset($this->accountancy_code) ?
"'".$this->db->escape($this->accountancy_code).
"'" :
"null");
302 $sql .=
' WHERE id='.((int) $this->
id);
306 $resql = $this->db->query($sql);
309 $this->errors[] =
'Error '.$this->db->lasterror();
310 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
325 $this->db->rollback();
501 return $langs->trans(
'Enabled');
502 } elseif ($status == 0) {
503 return $langs->trans(
'Disabled');
505 } elseif ($mode == 1) {
507 return $langs->trans(
'Enabled');
508 } elseif ($status == 0) {
509 return $langs->trans(
'Disabled');
511 } elseif ($mode == 2) {
513 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
514 } elseif ($status == 0) {
515 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
517 } elseif ($mode == 3) {
519 return img_picto($langs->trans(
'Enabled'),
'statut4');
520 } elseif ($status == 0) {
521 return img_picto($langs->trans(
'Disabled'),
'statut5');
523 } elseif ($mode == 4) {
525 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
526 } elseif ($status == 0) {
527 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
529 } elseif ($mode == 5) {
531 return $langs->trans(
'Enabled').
' '.img_picto($langs->trans(
'Enabled'),
'statut4');
532 } elseif ($status == 0) {
533 return $langs->trans(
'Disabled').
' '.img_picto($langs->trans(
'Disabled'),
'statut5');