dolibarr 21.0.0-alpha
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-2024 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;
62 public $active;
66 public $accountancy_code;
70 public $module;
71
72
78 public function __construct(DoliDB $db)
79 {
80 $this->db = $db;
81 }
82
90 public function create(User $user, $notrigger = 0)
91 {
92 dol_syslog(__METHOD__, LOG_DEBUG);
93
94 $error = 0;
95
96 // Clean parameters
97
98 if (isset($this->code)) {
99 $this->code = trim($this->code);
100 }
101 if (isset($this->libelle)) {
102 $this->libelle = trim($this->libelle);
103 }
104 if (isset($this->label)) {
105 $this->label = trim($this->label);
106 }
107 if (isset($this->type)) {
108 $this->type = trim($this->type);
109 }
110 if (isset($this->active)) {
111 $this->active = (int) $this->active;
112 }
113 if (isset($this->accountancy_code)) {
114 $this->accountancy_code = trim($this->accountancy_code);
115 }
116 if (isset($this->module)) {
117 $this->module = trim($this->module);
118 }
119
120
121
122 // Check parameters
123 // Put here code to add control on parameters values
124
125 // Insert request
126 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'(';
127 $sql .= 'entity,';
128 $sql .= 'code,';
129 $sql .= 'libelle,';
130 $sql .= 'type,';
131 $sql .= 'active,';
132 $sql .= 'accountancy_code,';
133 $sql .= 'module';
134 $sql .= ') VALUES (';
135 $sql .= ' '.(!isset($this->entity) ? getEntity('c_paiement') : $this->entity).',';
136 $sql .= ' '.(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").',';
137 $sql .= ' '.(!isset($this->libelle) ? 'NULL' : "'".$this->db->escape($this->libelle)."'").',';
138 $sql .= ' '.(!isset($this->type) ? 'NULL' : $this->type).',';
139 $sql .= ' '.(!isset($this->active) ? 'NULL' : $this->active).',';
140 $sql .= ' '.(!isset($this->accountancy_code) ? 'NULL' : "'".$this->db->escape($this->accountancy_code)."'").',';
141 $sql .= ' '.(!isset($this->module) ? 'NULL' : "'".$this->db->escape($this->module)."'");
142 $sql .= ')';
143
144 $this->db->begin();
145
146 $resql = $this->db->query($sql);
147 if (!$resql) {
148 $error++;
149 $this->errors[] = 'Error '.$this->db->lasterror();
150 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
151 }
152
153 if (!$error) {
154 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
155
156 // Uncomment this and change MYOBJECT to your own tag if you
157 // want this action to call a trigger.
158 //if (!$notrigger) {
159
160 // // Call triggers
161 // $result=$this->call_trigger('MYOBJECT_CREATE',$user);
162 // if ($result < 0) $error++;
163 // // End call triggers
164 //}
165 }
166
167 // Commit or rollback
168 if ($error) {
169 $this->db->rollback();
170
171 return -1 * $error;
172 } else {
173 $this->db->commit();
174
175 return $this->id;
176 }
177 }
178
187 public function fetch($id, $ref = null)
188 {
189 dol_syslog(__METHOD__, LOG_DEBUG);
190
191 $sql = 'SELECT';
192 $sql .= ' t.id,';
193 $sql .= " t.code,";
194 $sql .= " t.libelle as label,";
195 $sql .= " t.type,";
196 $sql .= " t.active,";
197 $sql .= " t.accountancy_code,";
198 $sql .= " t.module";
199 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
200 if (null !== $ref) {
201 $sql .= ' WHERE t.entity IN ('.getEntity('c_paiement').')';
202 $sql .= " AND t.code = '".$this->db->escape($ref)."'";
203 } else {
204 $sql .= ' WHERE t.id = '.((int) $id);
205 }
206
207 $resql = $this->db->query($sql);
208 if ($resql) {
209 $numrows = $this->db->num_rows($resql);
210 if ($numrows) {
211 $obj = $this->db->fetch_object($resql);
212
213 $this->id = $obj->id;
214
215 $this->code = $obj->code;
216 $this->libelle = $obj->label;
217 $this->label = $obj->label;
218 $this->type = $obj->type;
219 $this->active = $obj->active;
220 $this->accountancy_code = $obj->accountancy_code;
221 $this->module = $obj->module;
222 }
223 $this->db->free($resql);
224
225 if ($numrows) {
226 return 1;
227 } else {
228 return 0;
229 }
230 } else {
231 $this->errors[] = 'Error '.$this->db->lasterror();
232 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
233
234 return -1;
235 }
236 }
237
245 public function update(User $user, $notrigger = 0)
246 {
247 $error = 0;
248
249 dol_syslog(__METHOD__, LOG_DEBUG);
250
251 // Clean parameters
252
253 if (isset($this->code)) {
254 $this->code = trim($this->code);
255 }
256 if (isset($this->libelle)) {
257 $this->libelle = trim($this->libelle);
258 }
259 if (isset($this->label)) {
260 $this->label = trim($this->label);
261 }
262 if (isset($this->type)) {
263 $this->type = trim($this->type);
264 }
265 if (isset($this->active)) {
266 $this->active = (int) $this->active;
267 }
268 if (isset($this->accountancy_code)) {
269 $this->accountancy_code = trim($this->accountancy_code);
270 }
271 if (isset($this->module)) {
272 $this->module = trim($this->module);
273 }
274
275
276
277 // Check parameters
278 // Put here code to add a control on parameters values
279
280 // Update request
281 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET';
282 $sql .= ' id = '.(isset($this->id) ? $this->id : "null").',';
283 $sql .= ' code = '.(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").',';
284 $sql .= ' libelle = '.(isset($this->libelle) ? "'".$this->db->escape($this->libelle)."'" : "null").',';
285 $sql .= ' type = '.(isset($this->type) ? $this->type : "null").',';
286 $sql .= ' active = '.(isset($this->active) ? $this->active : "null").',';
287 $sql .= ' accountancy_code = '.(isset($this->accountancy_code) ? "'".$this->db->escape($this->accountancy_code)."'" : "null").',';
288 $sql .= ' module = '.(isset($this->module) ? "'".$this->db->escape($this->module)."'" : "null");
289 $sql .= ' WHERE id = '.((int) $this->id);
290
291 $this->db->begin();
292
293 $resql = $this->db->query($sql);
294 if (!$resql) {
295 $error++;
296 $this->errors[] = 'Error '.$this->db->lasterror();
297 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
298 }
299
300 // Uncomment this and change MYOBJECT to your own tag if you
301 // want this action calls a trigger.
302 //if (!$error && !$notrigger) {
303
304 // // Call triggers
305 // $result=$this->call_trigger('MYOBJECT_MODIFY',$user);
306 // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
307 // // End call triggers
308 //}
309
310 // Commit or rollback
311 if ($error) {
312 $this->db->rollback();
313
314 return -1 * $error;
315 } else {
316 $this->db->commit();
317
318 return 1;
319 }
320 }
321
329 public function delete(User $user, $notrigger = 0)
330 {
331 dol_syslog(__METHOD__, LOG_DEBUG);
332
333 $error = 0;
334
335 $this->db->begin();
336
337 // Uncomment this and change MYOBJECT to your own tag if you
338 // want this action calls a trigger.
339 //if (!$error && !$notrigger) {
340
341 // // Call triggers
342 // $result=$this->call_trigger('MYOBJECT_DELETE',$user);
343 // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
344 // // End call triggers
345 //}
346
347 if (!$error) {
348 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
349 $sql .= ' WHERE id = '.((int) $this->id);
350
351 $resql = $this->db->query($sql);
352 if (!$resql) {
353 $error++;
354 $this->errors[] = 'Error '.$this->db->lasterror();
355 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
356 }
357 }
358
359 // Commit or rollback
360 if ($error) {
361 $this->db->rollback();
362
363 return -1 * $error;
364 } else {
365 $this->db->commit();
366
367 return 1;
368 }
369 }
370
371
378 public function initAsSpecimen()
379 {
380 $this->id = 0;
381 $this->code = '';
382 $this->libelle = '';
383 $this->label = '';
384 $this->type = '';
385 $this->active = 1;
386 $this->accountancy_code = '';
387 $this->module = '';
388
389 return 1;
390 }
391}
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.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137