30require_once DOL_DOCUMENT_ROOT.
'/core/class/commondict.class.php';
41 public $element =
'cpaiement';
46 public $table_element =
'c_paiement';
63 public $accountancy_code;
96 if (isset($this->code)) {
97 $this->code = trim($this->code);
99 if (isset($this->libelle)) {
100 $this->libelle = trim($this->libelle);
102 if (isset($this->label)) {
103 $this->label = trim($this->label);
105 if (isset($this->
type)) {
108 if (isset($this->
active)) {
111 if (isset($this->accountancy_code)) {
112 $this->accountancy_code = trim($this->accountancy_code);
114 if (isset($this->module)) {
115 $this->module = trim($this->module);
124 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
130 $sql .=
'accountancy_code,';
132 $sql .=
') VALUES (';
133 $sql .=
' '.(!isset($this->entity) ?
getEntity(
'c_paiement') : $this->entity).
',';
134 $sql .=
' '.(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
',';
135 $sql .=
' '.(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
',';
136 $sql .=
' '.(!isset($this->
type) ?
'NULL' : $this->type).
',';
137 $sql .=
' '.(!isset($this->
active) ?
'NULL' : $this->active).
',';
138 $sql .=
' '.(!isset($this->accountancy_code) ?
'NULL' :
"'".$this->db->escape($this->accountancy_code).
"'").
',';
139 $sql .=
' '.(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'");
144 $resql = $this->db->query($sql);
147 $this->errors[] =
'Error '.$this->db->lasterror();
148 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
152 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
167 $this->db->rollback();
185 public function fetch($id, $ref =
null)
192 $sql .=
" t.libelle as label,";
194 $sql .=
" t.active,";
195 $sql .=
" t.accountancy_code,";
197 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
199 $sql .=
' WHERE t.entity IN ('.getEntity(
'c_paiement').
')';
200 $sql .=
" AND t.code = '".$this->db->escape($ref).
"'";
202 $sql .=
' WHERE t.id = '.((int) $id);
205 $resql = $this->db->query($sql);
207 $numrows = $this->db->num_rows($resql);
209 $obj = $this->db->fetch_object($resql);
211 $this->
id = $obj->id;
213 $this->code = $obj->code;
214 $this->libelle = $obj->label;
215 $this->label = $obj->label;
216 $this->
type = $obj->type;
217 $this->
active = $obj->active;
218 $this->accountancy_code = $obj->accountancy_code;
219 $this->module = $obj->module;
221 $this->db->free($resql);
229 $this->errors[] =
'Error '.$this->db->lasterror();
230 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
251 if (isset($this->code)) {
252 $this->code = trim($this->code);
254 if (isset($this->libelle)) {
255 $this->libelle = trim($this->libelle);
257 if (isset($this->label)) {
258 $this->label = trim($this->label);
260 if (isset($this->
type)) {
263 if (isset($this->
active)) {
266 if (isset($this->accountancy_code)) {
267 $this->accountancy_code = trim($this->accountancy_code);
269 if (isset($this->module)) {
270 $this->module = trim($this->module);
279 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
280 $sql .=
' id = '.(isset($this->
id) ? $this->id :
"null").
',';
281 $sql .=
' code = '.(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
',';
282 $sql .=
' libelle = '.(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
',';
283 $sql .=
' type = '.(isset($this->
type) ? $this->
type :
"null").
',';
284 $sql .=
' active = '.(isset($this->
active) ? $this->
active :
"null").
',';
285 $sql .=
' accountancy_code = '.(isset($this->accountancy_code) ?
"'".$this->db->escape($this->accountancy_code).
"'" :
"null").
',';
286 $sql .=
' module = '.(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null");
287 $sql .=
' WHERE id = '.((int) $this->
id);
291 $resql = $this->db->query($sql);
294 $this->errors[] =
'Error '.$this->db->lasterror();
295 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
310 $this->db->rollback();
327 public function delete(
User $user, $notrigger = 0)
346 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
347 $sql .=
' WHERE id = '.((int) $this->
id);
349 $resql = $this->db->query($sql);
352 $this->errors[] =
'Error '.$this->db->lasterror();
353 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
359 $this->db->rollback();
384 $this->accountancy_code =
'';
Parent class of all other dictionary classes.
update(User $user, $notrigger=0)
Update object into database.
__construct(DoliDB $db)
Constructor.
fetch($id, $ref=null)
Load object in memory from the database.
create(User $user, $notrigger=0)
Create object into database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...