86 if (isset($this->code)) {
87 $this->code = trim($this->code);
89 if (isset($this->libelle)) {
90 $this->libelle = trim($this->libelle);
92 if (isset($this->label)) {
93 $this->label = trim($this->label);
95 if (isset($this->
type)) {
98 if (isset($this->active)) {
99 $this->active = trim($this->active);
101 if (isset($this->accountancy_code)) {
102 $this->accountancy_code = trim($this->accountancy_code);
104 if (isset($this->module)) {
105 $this->module = trim($this->module);
114 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
120 $sql .=
'accountancy_code,';
122 $sql .=
') VALUES (';
123 $sql .=
' '.(!isset($this->entity) ?
getEntity(
'c_paiement') : $this->entity).
',';
124 $sql .=
' '.(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
',';
125 $sql .=
' '.(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
',';
126 $sql .=
' '.(!isset($this->
type) ?
'NULL' : $this->type).
',';
127 $sql .=
' '.(!isset($this->active) ?
'NULL' : $this->active).
',';
128 $sql .=
' '.(!isset($this->accountancy_code) ?
'NULL' :
"'".$this->db->escape($this->accountancy_code).
"'").
',';
129 $sql .=
' '.(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'");
134 $resql = $this->db->query($sql);
137 $this->errors[] =
'Error '.$this->db->lasterror();
138 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
142 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
157 $this->db->rollback();
175 public function fetch($id, $ref =
null)
182 $sql .=
" t.libelle as label,";
184 $sql .=
" t.active,";
185 $sql .=
" t.accountancy_code,";
187 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
189 $sql .=
' WHERE t.entity IN ('.getEntity(
'c_paiement').
')';
190 $sql .=
" AND t.code = '".$this->db->escape($ref).
"'";
192 $sql .=
' WHERE t.id = '.((int) $id);
195 $resql = $this->db->query($sql);
197 $numrows = $this->db->num_rows($resql);
199 $obj = $this->db->fetch_object($resql);
201 $this->
id = $obj->id;
203 $this->code = $obj->code;
204 $this->libelle = $obj->label;
205 $this->label = $obj->label;
206 $this->
type = $obj->type;
207 $this->active = $obj->active;
208 $this->accountancy_code = $obj->accountancy_code;
209 $this->module = $obj->module;
211 $this->db->free($resql);
219 $this->errors[] =
'Error '.$this->db->lasterror();
220 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
242 if (isset($this->code)) {
243 $this->code = trim($this->code);
245 if (isset($this->libelle)) {
246 $this->libelle = trim($this->libelle);
248 if (isset($this->label)) {
249 $this->label = trim($this->label);
251 if (isset($this->
type)) {
254 if (isset($this->active)) {
255 $this->active = trim($this->active);
257 if (isset($this->accountancy_code)) {
258 $this->accountancy_code = trim($this->accountancy_code);
260 if (isset($this->module)) {
261 $this->module = trim($this->module);
270 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
271 $sql .=
' id = '.(isset($this->
id) ? $this->id :
"null").
',';
272 $sql .=
' code = '.(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
',';
273 $sql .=
' libelle = '.(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
',';
274 $sql .=
' type = '.(isset($this->
type) ? $this->
type :
"null").
',';
275 $sql .=
' active = '.(isset($this->active) ? $this->active :
"null").
',';
276 $sql .=
' accountancy_code = '.(isset($this->accountancy_code) ?
"'".$this->db->escape($this->accountancy_code).
"'" :
"null").
',';
277 $sql .=
' module = '.(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null");
278 $sql .=
' WHERE id = '.((int) $this->
id);
282 $resql = $this->db->query($sql);
285 $this->errors[] =
'Error '.$this->db->lasterror();
286 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
301 $this->db->rollback();