dolibarr 19.0.3
cpaiement.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
6 * Copyright (C) 2023 Frédéric France <frederic.france@netlogic.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Put here all includes required by your class file
29require_once DOL_DOCUMENT_ROOT.'/core/class/commondict.class.php';
30
31
35class Cpaiement extends CommonDict
36{
40 public $element = 'cpaiement';
41
45 public $table_element = 'c_paiement';
46
52 public $libelle;
53
54 public $type;
55 public $active;
56 public $accountancy_code;
57 public $module;
58
59
65 public function __construct(DoliDB $db)
66 {
67 $this->db = $db;
68 }
69
78 public function create(User $user, $notrigger = false)
79 {
80 dol_syslog(__METHOD__, LOG_DEBUG);
81
82 $error = 0;
83
84 // Clean parameters
85
86 if (isset($this->code)) {
87 $this->code = trim($this->code);
88 }
89 if (isset($this->libelle)) {
90 $this->libelle = trim($this->libelle);
91 }
92 if (isset($this->label)) {
93 $this->label = trim($this->label);
94 }
95 if (isset($this->type)) {
96 $this->type = trim($this->type);
97 }
98 if (isset($this->active)) {
99 $this->active = trim($this->active);
100 }
101 if (isset($this->accountancy_code)) {
102 $this->accountancy_code = trim($this->accountancy_code);
103 }
104 if (isset($this->module)) {
105 $this->module = trim($this->module);
106 }
107
108
109
110 // Check parameters
111 // Put here code to add control on parameters values
112
113 // Insert request
114 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'(';
115 $sql .= 'entity,';
116 $sql .= 'code,';
117 $sql .= 'libelle,';
118 $sql .= 'type,';
119 $sql .= 'active,';
120 $sql .= 'accountancy_code,';
121 $sql .= 'module';
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)."'");
130 $sql .= ')';
131
132 $this->db->begin();
133
134 $resql = $this->db->query($sql);
135 if (!$resql) {
136 $error++;
137 $this->errors[] = 'Error '.$this->db->lasterror();
138 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
139 }
140
141 if (!$error) {
142 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
143
144 // Uncomment this and change MYOBJECT to your own tag if you
145 // want this action to call a trigger.
146 //if (!$notrigger) {
147
148 // // Call triggers
149 // $result=$this->call_trigger('MYOBJECT_CREATE',$user);
150 // if ($result < 0) $error++;
151 // // End call triggers
152 //}
153 }
154
155 // Commit or rollback
156 if ($error) {
157 $this->db->rollback();
158
159 return -1 * $error;
160 } else {
161 $this->db->commit();
162
163 return $this->id;
164 }
165 }
166
175 public function fetch($id, $ref = null)
176 {
177 dol_syslog(__METHOD__, LOG_DEBUG);
178
179 $sql = 'SELECT';
180 $sql .= ' t.id,';
181 $sql .= " t.code,";
182 $sql .= " t.libelle as label,";
183 $sql .= " t.type,";
184 $sql .= " t.active,";
185 $sql .= " t.accountancy_code,";
186 $sql .= " t.module";
187 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
188 if (null !== $ref) {
189 $sql .= ' WHERE t.entity IN ('.getEntity('c_paiement').')';
190 $sql .= " AND t.code = '".$this->db->escape($ref)."'";
191 } else {
192 $sql .= ' WHERE t.id = '.((int) $id);
193 }
194
195 $resql = $this->db->query($sql);
196 if ($resql) {
197 $numrows = $this->db->num_rows($resql);
198 if ($numrows) {
199 $obj = $this->db->fetch_object($resql);
200
201 $this->id = $obj->id;
202
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;
210 }
211 $this->db->free($resql);
212
213 if ($numrows) {
214 return 1;
215 } else {
216 return 0;
217 }
218 } else {
219 $this->errors[] = 'Error '.$this->db->lasterror();
220 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
221
222 return -1;
223 }
224 }
225
234 public function update(User $user, $notrigger = false)
235 {
236 $error = 0;
237
238 dol_syslog(__METHOD__, LOG_DEBUG);
239
240 // Clean parameters
241
242 if (isset($this->code)) {
243 $this->code = trim($this->code);
244 }
245 if (isset($this->libelle)) {
246 $this->libelle = trim($this->libelle);
247 }
248 if (isset($this->label)) {
249 $this->label = trim($this->label);
250 }
251 if (isset($this->type)) {
252 $this->type = trim($this->type);
253 }
254 if (isset($this->active)) {
255 $this->active = trim($this->active);
256 }
257 if (isset($this->accountancy_code)) {
258 $this->accountancy_code = trim($this->accountancy_code);
259 }
260 if (isset($this->module)) {
261 $this->module = trim($this->module);
262 }
263
264
265
266 // Check parameters
267 // Put here code to add a control on parameters values
268
269 // Update request
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);
279
280 $this->db->begin();
281
282 $resql = $this->db->query($sql);
283 if (!$resql) {
284 $error++;
285 $this->errors[] = 'Error '.$this->db->lasterror();
286 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
287 }
288
289 // Uncomment this and change MYOBJECT to your own tag if you
290 // want this action calls a trigger.
291 //if (!$error && !$notrigger) {
292
293 // // Call triggers
294 // $result=$this->call_trigger('MYOBJECT_MODIFY',$user);
295 // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
296 // // End call triggers
297 //}
298
299 // Commit or rollback
300 if ($error) {
301 $this->db->rollback();
302
303 return -1 * $error;
304 } else {
305 $this->db->commit();
306
307 return 1;
308 }
309 }
310
319 public function delete(User $user, $notrigger = false)
320 {
321 dol_syslog(__METHOD__, LOG_DEBUG);
322
323 $error = 0;
324
325 $this->db->begin();
326
327 // Uncomment this and change MYOBJECT to your own tag if you
328 // want this action calls a trigger.
329 //if (!$error && !$notrigger) {
330
331 // // Call triggers
332 // $result=$this->call_trigger('MYOBJECT_DELETE',$user);
333 // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
334 // // End call triggers
335 //}
336
337 if (!$error) {
338 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
339 $sql .= ' WHERE id = '.((int) $this->id);
340
341 $resql = $this->db->query($sql);
342 if (!$resql) {
343 $error++;
344 $this->errors[] = 'Error '.$this->db->lasterror();
345 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
346 }
347 }
348
349 // Commit or rollback
350 if ($error) {
351 $this->db->rollback();
352
353 return -1 * $error;
354 } else {
355 $this->db->commit();
356
357 return 1;
358 }
359 }
360
361
368 public function initAsSpecimen()
369 {
370 $this->id = 0;
371
372 $this->code = '';
373 $this->libelle = '';
374 $this->label = '';
375 $this->type = '';
376 $this->active = '';
377 $this->accountancy_code = '';
378 $this->module = '';
379 }
380}
Parent class of all other dictionary classes.
Class Cpaiement.
create(User $user, $notrigger=false)
Create object into database.
__construct(DoliDB $db)
Constructor.
fetch($id, $ref=null)
Load object in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
update(User $user, $notrigger=false)
Update object into database.
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:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:121