90 if (isset($this->code)) {
91 $this->code = trim($this->code);
93 if (isset($this->libelle)) {
94 $this->libelle = trim($this->libelle);
96 if (isset($this->label)) {
97 $this->label = trim($this->label);
99 if (isset($this->
type)) {
102 if (isset($this->active)) {
103 $this->active = trim($this->active);
105 if (isset($this->accountancy_code)) {
106 $this->accountancy_code = trim($this->accountancy_code);
108 if (isset($this->module)) {
109 $this->module = trim($this->module);
118 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
124 $sql .=
'accountancy_code,';
126 $sql .=
') VALUES (';
127 $sql .=
' '.(!isset($this->entity) ?
getEntity(
'c_paiement') : $this->entity).
',';
128 $sql .=
' '.(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
',';
129 $sql .=
' '.(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
',';
130 $sql .=
' '.(!isset($this->
type) ?
'NULL' : $this->type).
',';
131 $sql .=
' '.(!isset($this->active) ?
'NULL' : $this->active).
',';
132 $sql .=
' '.(!isset($this->accountancy_code) ?
'NULL' :
"'".$this->db->escape($this->accountancy_code).
"'").
',';
133 $sql .=
' '.(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'");
138 $resql = $this->db->query($sql);
141 $this->errors[] =
'Error '.$this->db->lasterror();
142 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
146 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
161 $this->db->rollback();
179 public function fetch($id, $ref =
null)
186 $sql .=
" t.libelle as label,";
188 $sql .=
" t.active,";
189 $sql .=
" t.accountancy_code,";
191 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
193 $sql .=
' WHERE t.entity IN ('.getEntity(
'c_paiement').
')';
194 $sql .=
" AND t.code = '".$this->db->escape($ref).
"'";
196 $sql .=
' WHERE t.id = '.((int) $id);
199 $resql = $this->db->query($sql);
201 $numrows = $this->db->num_rows($resql);
203 $obj = $this->db->fetch_object($resql);
205 $this->
id = $obj->id;
207 $this->code = $obj->code;
208 $this->libelle = $obj->label;
209 $this->label = $obj->label;
210 $this->
type = $obj->type;
211 $this->active = $obj->active;
212 $this->accountancy_code = $obj->accountancy_code;
213 $this->module = $obj->module;
215 $this->db->free($resql);
223 $this->errors[] =
'Error '.$this->db->lasterror();
224 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
246 if (isset($this->code)) {
247 $this->code = trim($this->code);
249 if (isset($this->libelle)) {
250 $this->libelle = trim($this->libelle);
252 if (isset($this->label)) {
253 $this->label = trim($this->label);
255 if (isset($this->
type)) {
258 if (isset($this->active)) {
259 $this->active = trim($this->active);
261 if (isset($this->accountancy_code)) {
262 $this->accountancy_code = trim($this->accountancy_code);
264 if (isset($this->module)) {
265 $this->module = trim($this->module);
274 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
275 $sql .=
' id = '.(isset($this->
id) ? $this->id :
"null").
',';
276 $sql .=
' code = '.(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
',';
277 $sql .=
' libelle = '.(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
',';
278 $sql .=
' type = '.(isset($this->
type) ? $this->
type :
"null").
',';
279 $sql .=
' active = '.(isset($this->active) ? $this->active :
"null").
',';
280 $sql .=
' accountancy_code = '.(isset($this->accountancy_code) ?
"'".$this->db->escape($this->accountancy_code).
"'" :
"null").
',';
281 $sql .=
' module = '.(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null");
282 $sql .=
' WHERE id = '.((int) $this->
id);
286 $resql = $this->db->query($sql);
289 $this->errors[] =
'Error '.$this->db->lasterror();
290 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
305 $this->db->rollback();