98 if (isset($this->code)) {
99 $this->code = trim($this->code);
101 if (isset($this->libelle)) {
102 $this->libelle = trim($this->libelle);
104 if (isset($this->label)) {
105 $this->label = trim($this->label);
107 if (isset($this->
type)) {
110 if (isset($this->active)) {
111 $this->active = (int) $this->active;
113 if (isset($this->accountancy_code)) {
114 $this->accountancy_code = trim($this->accountancy_code);
116 if (isset($this->module)) {
117 $this->module = trim($this->module);
126 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
132 $sql .=
'accountancy_code,';
134 $sql .=
') VALUES (';
135 $sql .=
' '.(!isset($this->entity) ?
getEntity(
'c_paiement') : $this->entity).
',';
136 $sql .=
' '.(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
',';
137 $sql .=
' '.(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
',';
138 $sql .=
' '.(!isset($this->
type) ?
'NULL' : $this->type).
',';
139 $sql .=
' '.(!isset($this->active) ?
'NULL' : $this->active).
',';
140 $sql .=
' '.(!isset($this->accountancy_code) ?
'NULL' :
"'".$this->db->escape($this->accountancy_code).
"'").
',';
141 $sql .=
' '.(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'");
146 $resql = $this->db->query($sql);
149 $this->errors[] =
'Error '.$this->db->lasterror();
150 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
154 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
169 $this->db->rollback();
187 public function fetch($id, $ref =
null)
194 $sql .=
" t.libelle as label,";
196 $sql .=
" t.active,";
197 $sql .=
" t.accountancy_code,";
199 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
201 $sql .=
' WHERE t.entity IN ('.getEntity(
'c_paiement').
')';
202 $sql .=
" AND t.code = '".$this->db->escape($ref).
"'";
204 $sql .=
' WHERE t.id = '.((int) $id);
207 $resql = $this->db->query($sql);
209 $numrows = $this->db->num_rows($resql);
211 $obj = $this->db->fetch_object($resql);
213 $this->
id = $obj->id;
215 $this->code = $obj->code;
216 $this->libelle = $obj->label;
217 $this->label = $obj->label;
218 $this->
type = $obj->type;
219 $this->active = $obj->active;
220 $this->accountancy_code = $obj->accountancy_code;
221 $this->module = $obj->module;
223 $this->db->free($resql);
231 $this->errors[] =
'Error '.$this->db->lasterror();
232 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
253 if (isset($this->code)) {
254 $this->code = trim($this->code);
256 if (isset($this->libelle)) {
257 $this->libelle = trim($this->libelle);
259 if (isset($this->label)) {
260 $this->label = trim($this->label);
262 if (isset($this->
type)) {
265 if (isset($this->active)) {
266 $this->active = (int) $this->active;
268 if (isset($this->accountancy_code)) {
269 $this->accountancy_code = trim($this->accountancy_code);
271 if (isset($this->module)) {
272 $this->module = trim($this->module);
281 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
282 $sql .=
' id = '.(isset($this->
id) ? $this->id :
"null").
',';
283 $sql .=
' code = '.(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
',';
284 $sql .=
' libelle = '.(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
',';
285 $sql .=
' type = '.(isset($this->
type) ? $this->
type :
"null").
',';
286 $sql .=
' active = '.(isset($this->active) ? $this->active :
"null").
',';
287 $sql .=
' accountancy_code = '.(isset($this->accountancy_code) ?
"'".$this->db->escape($this->accountancy_code).
"'" :
"null").
',';
288 $sql .=
' module = '.(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null");
289 $sql .=
' WHERE id = '.((int) $this->
id);
293 $resql = $this->db->query($sql);
296 $this->errors[] =
'Error '.$this->db->lasterror();
297 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
312 $this->db->rollback();