85 if (isset($this->code)) {
86 $this->code = trim($this->code);
88 if (isset($this->libelle)) {
89 $this->libelle = trim($this->libelle);
91 if (isset($this->label)) {
92 $this->label = trim($this->label);
94 if (isset($this->
type)) {
97 if (isset($this->active)) {
98 $this->active = (int) $this->active;
100 if (isset($this->accountancy_code)) {
101 $this->accountancy_code = trim($this->accountancy_code);
103 if (isset($this->module)) {
104 $this->module = trim($this->module);
113 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
119 $sql .=
'accountancy_code,';
121 $sql .=
') VALUES (';
122 $sql .=
' '.(!isset($this->entity) ?
getEntity(
'c_paiement') : $this->entity).
',';
123 $sql .=
' '.(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
',';
124 $sql .=
' '.(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
',';
125 $sql .=
' '.(!isset($this->
type) ?
'NULL' : $this->type).
',';
126 $sql .=
' '.(!isset($this->active) ?
'NULL' : $this->active).
',';
127 $sql .=
' '.(!isset($this->accountancy_code) ?
'NULL' :
"'".$this->db->escape($this->accountancy_code).
"'").
',';
128 $sql .=
' '.(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'");
133 $resql = $this->db->query($sql);
136 $this->errors[] =
'Error '.$this->db->lasterror();
137 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
141 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
156 $this->db->rollback();
174 public function fetch($id, $ref =
null)
181 $sql .=
" t.libelle as label,";
183 $sql .=
" t.active,";
184 $sql .=
" t.accountancy_code,";
186 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
188 $sql .=
' WHERE t.entity IN ('.getEntity(
'c_paiement').
')';
189 $sql .=
" AND t.code = '".$this->db->escape($ref).
"'";
191 $sql .=
' WHERE t.id = '.((int) $id);
194 $resql = $this->db->query($sql);
196 $numrows = $this->db->num_rows($resql);
198 $obj = $this->db->fetch_object($resql);
200 $this->
id = $obj->id;
202 $this->code = $obj->code;
203 $this->libelle = $obj->label;
204 $this->label = $obj->label;
205 $this->
type = $obj->type;
206 $this->active = $obj->active;
207 $this->accountancy_code = $obj->accountancy_code;
208 $this->module = $obj->module;
210 $this->db->free($resql);
218 $this->errors[] =
'Error '.$this->db->lasterror();
219 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
240 if (isset($this->code)) {
241 $this->code = trim($this->code);
243 if (isset($this->libelle)) {
244 $this->libelle = trim($this->libelle);
246 if (isset($this->label)) {
247 $this->label = trim($this->label);
249 if (isset($this->
type)) {
252 if (isset($this->active)) {
253 $this->active = (int) $this->active;
255 if (isset($this->accountancy_code)) {
256 $this->accountancy_code = trim($this->accountancy_code);
258 if (isset($this->module)) {
259 $this->module = trim($this->module);
268 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
269 $sql .=
' id = '.(isset($this->
id) ? $this->id :
"null").
',';
270 $sql .=
' code = '.(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
',';
271 $sql .=
' libelle = '.(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
',';
272 $sql .=
' type = '.(isset($this->
type) ? $this->
type :
"null").
',';
273 $sql .=
' active = '.(isset($this->active) ? $this->active :
"null").
',';
274 $sql .=
' accountancy_code = '.(isset($this->accountancy_code) ?
"'".$this->db->escape($this->accountancy_code).
"'" :
"null").
',';
275 $sql .=
' module = '.(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null");
276 $sql .=
' WHERE id = '.((int) $this->
id);
280 $resql = $this->db->query($sql);
283 $this->errors[] =
'Error '.$this->db->lasterror();
284 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
299 $this->db->rollback();