dolibarr 20.0.0
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 *
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
77 public function create(User $user, $notrigger = 0)
78 {
79 dol_syslog(__METHOD__, LOG_DEBUG);
80
81 $error = 0;
82
83 // Clean parameters
84
85 if (isset($this->code)) {
86 $this->code = trim($this->code);
87 }
88 if (isset($this->libelle)) {
89 $this->libelle = trim($this->libelle);
90 }
91 if (isset($this->label)) {
92 $this->label = trim($this->label);
93 }
94 if (isset($this->type)) {
95 $this->type = trim($this->type);
96 }
97 if (isset($this->active)) {
98 $this->active = (int) $this->active;
99 }
100 if (isset($this->accountancy_code)) {
101 $this->accountancy_code = trim($this->accountancy_code);
102 }
103 if (isset($this->module)) {
104 $this->module = trim($this->module);
105 }
106
107
108
109 // Check parameters
110 // Put here code to add control on parameters values
111
112 // Insert request
113 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'(';
114 $sql .= 'entity,';
115 $sql .= 'code,';
116 $sql .= 'libelle,';
117 $sql .= 'type,';
118 $sql .= 'active,';
119 $sql .= 'accountancy_code,';
120 $sql .= 'module';
121 $sql .= ') VALUES (';
122 $sql .= ' '.(!isset($this->entity) ? getEntity('c_paiement') : $this->entity).',';
123 $sql .= ' '.(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").',';
124 $sql .= ' '.(!isset($this->libelle) ? 'NULL' : "'".$this->db->escape($this->libelle)."'").',';
125 $sql .= ' '.(!isset($this->type) ? 'NULL' : $this->type).',';
126 $sql .= ' '.(!isset($this->active) ? 'NULL' : $this->active).',';
127 $sql .= ' '.(!isset($this->accountancy_code) ? 'NULL' : "'".$this->db->escape($this->accountancy_code)."'").',';
128 $sql .= ' '.(!isset($this->module) ? 'NULL' : "'".$this->db->escape($this->module)."'");
129 $sql .= ')';
130
131 $this->db->begin();
132
133 $resql = $this->db->query($sql);
134 if (!$resql) {
135 $error++;
136 $this->errors[] = 'Error '.$this->db->lasterror();
137 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
138 }
139
140 if (!$error) {
141 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
142
143 // Uncomment this and change MYOBJECT to your own tag if you
144 // want this action to call a trigger.
145 //if (!$notrigger) {
146
147 // // Call triggers
148 // $result=$this->call_trigger('MYOBJECT_CREATE',$user);
149 // if ($result < 0) $error++;
150 // // End call triggers
151 //}
152 }
153
154 // Commit or rollback
155 if ($error) {
156 $this->db->rollback();
157
158 return -1 * $error;
159 } else {
160 $this->db->commit();
161
162 return $this->id;
163 }
164 }
165
174 public function fetch($id, $ref = null)
175 {
176 dol_syslog(__METHOD__, LOG_DEBUG);
177
178 $sql = 'SELECT';
179 $sql .= ' t.id,';
180 $sql .= " t.code,";
181 $sql .= " t.libelle as label,";
182 $sql .= " t.type,";
183 $sql .= " t.active,";
184 $sql .= " t.accountancy_code,";
185 $sql .= " t.module";
186 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
187 if (null !== $ref) {
188 $sql .= ' WHERE t.entity IN ('.getEntity('c_paiement').')';
189 $sql .= " AND t.code = '".$this->db->escape($ref)."'";
190 } else {
191 $sql .= ' WHERE t.id = '.((int) $id);
192 }
193
194 $resql = $this->db->query($sql);
195 if ($resql) {
196 $numrows = $this->db->num_rows($resql);
197 if ($numrows) {
198 $obj = $this->db->fetch_object($resql);
199
200 $this->id = $obj->id;
201
202 $this->code = $obj->code;
203 $this->libelle = $obj->label;
204 $this->label = $obj->label;
205 $this->type = $obj->type;
206 $this->active = $obj->active;
207 $this->accountancy_code = $obj->accountancy_code;
208 $this->module = $obj->module;
209 }
210 $this->db->free($resql);
211
212 if ($numrows) {
213 return 1;
214 } else {
215 return 0;
216 }
217 } else {
218 $this->errors[] = 'Error '.$this->db->lasterror();
219 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
220
221 return -1;
222 }
223 }
224
232 public function update(User $user, $notrigger = 0)
233 {
234 $error = 0;
235
236 dol_syslog(__METHOD__, LOG_DEBUG);
237
238 // Clean parameters
239
240 if (isset($this->code)) {
241 $this->code = trim($this->code);
242 }
243 if (isset($this->libelle)) {
244 $this->libelle = trim($this->libelle);
245 }
246 if (isset($this->label)) {
247 $this->label = trim($this->label);
248 }
249 if (isset($this->type)) {
250 $this->type = trim($this->type);
251 }
252 if (isset($this->active)) {
253 $this->active = (int) $this->active;
254 }
255 if (isset($this->accountancy_code)) {
256 $this->accountancy_code = trim($this->accountancy_code);
257 }
258 if (isset($this->module)) {
259 $this->module = trim($this->module);
260 }
261
262
263
264 // Check parameters
265 // Put here code to add a control on parameters values
266
267 // Update request
268 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET';
269 $sql .= ' id = '.(isset($this->id) ? $this->id : "null").',';
270 $sql .= ' code = '.(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").',';
271 $sql .= ' libelle = '.(isset($this->libelle) ? "'".$this->db->escape($this->libelle)."'" : "null").',';
272 $sql .= ' type = '.(isset($this->type) ? $this->type : "null").',';
273 $sql .= ' active = '.(isset($this->active) ? $this->active : "null").',';
274 $sql .= ' accountancy_code = '.(isset($this->accountancy_code) ? "'".$this->db->escape($this->accountancy_code)."'" : "null").',';
275 $sql .= ' module = '.(isset($this->module) ? "'".$this->db->escape($this->module)."'" : "null");
276 $sql .= ' WHERE id = '.((int) $this->id);
277
278 $this->db->begin();
279
280 $resql = $this->db->query($sql);
281 if (!$resql) {
282 $error++;
283 $this->errors[] = 'Error '.$this->db->lasterror();
284 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
285 }
286
287 // Uncomment this and change MYOBJECT to your own tag if you
288 // want this action calls a trigger.
289 //if (!$error && !$notrigger) {
290
291 // // Call triggers
292 // $result=$this->call_trigger('MYOBJECT_MODIFY',$user);
293 // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
294 // // End call triggers
295 //}
296
297 // Commit or rollback
298 if ($error) {
299 $this->db->rollback();
300
301 return -1 * $error;
302 } else {
303 $this->db->commit();
304
305 return 1;
306 }
307 }
308
316 public function delete(User $user, $notrigger = 0)
317 {
318 dol_syslog(__METHOD__, LOG_DEBUG);
319
320 $error = 0;
321
322 $this->db->begin();
323
324 // Uncomment this and change MYOBJECT to your own tag if you
325 // want this action calls a trigger.
326 //if (!$error && !$notrigger) {
327
328 // // Call triggers
329 // $result=$this->call_trigger('MYOBJECT_DELETE',$user);
330 // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
331 // // End call triggers
332 //}
333
334 if (!$error) {
335 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
336 $sql .= ' WHERE id = '.((int) $this->id);
337
338 $resql = $this->db->query($sql);
339 if (!$resql) {
340 $error++;
341 $this->errors[] = 'Error '.$this->db->lasterror();
342 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
343 }
344 }
345
346 // Commit or rollback
347 if ($error) {
348 $this->db->rollback();
349
350 return -1 * $error;
351 } else {
352 $this->db->commit();
353
354 return 1;
355 }
356 }
357
358
365 public function initAsSpecimen()
366 {
367 $this->id = 0;
368 $this->code = '';
369 $this->libelle = '';
370 $this->label = '';
371 $this->type = '';
372 $this->active = 1;
373 $this->accountancy_code = '';
374 $this->module = '';
375
376 return 1;
377 }
378}
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:139