dolibarr 23.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-2025 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Put here all includes required by your class file
30require_once DOL_DOCUMENT_ROOT.'/core/class/commondict.class.php';
31
32
36class Cpaiement extends CommonDict
37{
41 public $element = 'cpaiement';
42
46 public $table_element = 'c_paiement';
47
53 public $libelle;
54
58 public $type;
59
63 public $accountancy_code;
64
68 public $module;
69
70
76 public function __construct(DoliDB $db)
77 {
78 $this->db = $db;
79 }
80
88 public function create(User $user, $notrigger = 0)
89 {
90 dol_syslog(__METHOD__, LOG_DEBUG);
91
92 $error = 0;
93
94 // Clean parameters
95
96 if (isset($this->code)) {
97 $this->code = trim($this->code);
98 }
99 if (isset($this->libelle)) {
100 $this->libelle = trim($this->libelle);
101 }
102 if (isset($this->label)) {
103 $this->label = trim($this->label);
104 }
105 if (isset($this->type)) {
106 $this->type = trim($this->type);
107 }
108 if (isset($this->active)) {
109 $this->active = (int) $this->active;
110 }
111 if (isset($this->accountancy_code)) {
112 $this->accountancy_code = trim($this->accountancy_code);
113 }
114 if (isset($this->module)) {
115 $this->module = trim($this->module);
116 }
117
118
119
120 // Check parameters
121 // Put here code to add control on parameters values
122
123 // Insert request
124 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'(';
125 $sql .= 'entity,';
126 $sql .= 'code,';
127 $sql .= 'libelle,';
128 $sql .= 'type,';
129 $sql .= 'active,';
130 $sql .= 'accountancy_code,';
131 $sql .= 'module';
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)."'");
140 $sql .= ')';
141
142 $this->db->begin();
143
144 $resql = $this->db->query($sql);
145 if (!$resql) {
146 $error++;
147 $this->errors[] = 'Error '.$this->db->lasterror();
148 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
149 }
150
151 if (!$error) {
152 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
153
154 // Uncomment this and change MYOBJECT to your own tag if you
155 // want this action to call a trigger.
156 //if (!$notrigger) {
157
158 // // Call triggers
159 // $result=$this->call_trigger('MYOBJECT_CREATE',$user);
160 // if ($result < 0) $error++;
161 // // End call triggers
162 //}
163 }
164
165 // Commit or rollback
166 if ($error) {
167 $this->db->rollback();
168
169 return -1 * $error;
170 } else {
171 $this->db->commit();
172
173 return $this->id;
174 }
175 }
176
185 public function fetch($id, $ref = null)
186 {
187 dol_syslog(__METHOD__, LOG_DEBUG);
188
189 $sql = 'SELECT';
190 $sql .= ' t.id,';
191 $sql .= " t.code,";
192 $sql .= " t.libelle as label,";
193 $sql .= " t.type,";
194 $sql .= " t.active,";
195 $sql .= " t.accountancy_code,";
196 $sql .= " t.module";
197 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
198 if (null !== $ref) {
199 $sql .= ' WHERE t.entity IN ('.getEntity('c_paiement').')';
200 $sql .= " AND t.code = '".$this->db->escape($ref)."'";
201 } else {
202 $sql .= ' WHERE t.id = '.((int) $id);
203 }
204
205 $resql = $this->db->query($sql);
206 if ($resql) {
207 $numrows = $this->db->num_rows($resql);
208 if ($numrows) {
209 $obj = $this->db->fetch_object($resql);
210
211 $this->id = $obj->id;
212
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;
220 }
221 $this->db->free($resql);
222
223 if ($numrows) {
224 return 1;
225 } else {
226 return 0;
227 }
228 } else {
229 $this->errors[] = 'Error '.$this->db->lasterror();
230 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
231
232 return -1;
233 }
234 }
235
243 public function update(User $user, $notrigger = 0)
244 {
245 $error = 0;
246
247 dol_syslog(__METHOD__, LOG_DEBUG);
248
249 // Clean parameters
250
251 if (isset($this->code)) {
252 $this->code = trim($this->code);
253 }
254 if (isset($this->libelle)) {
255 $this->libelle = trim($this->libelle);
256 }
257 if (isset($this->label)) {
258 $this->label = trim($this->label);
259 }
260 if (isset($this->type)) {
261 $this->type = trim($this->type);
262 }
263 if (isset($this->active)) {
264 $this->active = (int) $this->active;
265 }
266 if (isset($this->accountancy_code)) {
267 $this->accountancy_code = trim($this->accountancy_code);
268 }
269 if (isset($this->module)) {
270 $this->module = trim($this->module);
271 }
272
273
274
275 // Check parameters
276 // Put here code to add a control on parameters values
277
278 // Update request
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);
288
289 $this->db->begin();
290
291 $resql = $this->db->query($sql);
292 if (!$resql) {
293 $error++;
294 $this->errors[] = 'Error '.$this->db->lasterror();
295 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
296 }
297
298 // Uncomment this and change MYOBJECT to your own tag if you
299 // want this action calls a trigger.
300 //if (!$error && !$notrigger) {
301
302 // // Call triggers
303 // $result=$this->call_trigger('MYOBJECT_MODIFY',$user);
304 // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
305 // // End call triggers
306 //}
307
308 // Commit or rollback
309 if ($error) {
310 $this->db->rollback();
311
312 return -1 * $error;
313 } else {
314 $this->db->commit();
315
316 return 1;
317 }
318 }
319
327 public function delete(User $user, $notrigger = 0)
328 {
329 dol_syslog(__METHOD__, LOG_DEBUG);
330
331 $error = 0;
332
333 $this->db->begin();
334
335 // Uncomment this and change MYOBJECT to your own tag if you
336 // want this action calls a trigger.
337 //if (!$error && !$notrigger) {
338
339 // // Call triggers
340 // $result=$this->call_trigger('MYOBJECT_DELETE',$user);
341 // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
342 // // End call triggers
343 //}
344
345 if (!$error) {
346 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
347 $sql .= ' WHERE id = '.((int) $this->id);
348
349 $resql = $this->db->query($sql);
350 if (!$resql) {
351 $error++;
352 $this->errors[] = 'Error '.$this->db->lasterror();
353 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
354 }
355 }
356
357 // Commit or rollback
358 if ($error) {
359 $this->db->rollback();
360
361 return -1 * $error;
362 } else {
363 $this->db->commit();
364
365 return 1;
366 }
367 }
368
369
376 public function initAsSpecimen()
377 {
378 $this->id = 0;
379 $this->code = '';
380 $this->libelle = '';
381 $this->label = '';
382 $this->type = '';
383 $this->active = 1;
384 $this->accountancy_code = '';
385 $this->module = '';
386
387 return 1;
388 }
389}
Parent class of all other dictionary classes.
Class Cpaiement.
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.
editval_textarea active
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]]]',...
Definition repair.php:125