dolibarr  7.0.0-beta
cpaiement.class.php
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  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
31 class Cpaiement
32 {
36  public $element = 'cpaiement';
40  public $table_element = 'c_paiement';
41 
42 
46  public $code;
47  public $libelle;
48  public $type;
49  public $active;
50  public $accountancy_code;
51  public $module;
52 
62  public function __construct(DoliDB $db)
63  {
64  $this->db = $db;
65  }
66 
75  public function create(User $user, $notrigger = false)
76  {
77  dol_syslog(__METHOD__, LOG_DEBUG);
78 
79  $error = 0;
80 
81  // Clean parameters
82 
83  if (isset($this->code)) {
84  $this->code = trim($this->code);
85  }
86  if (isset($this->libelle)) {
87  $this->libelle = trim($this->libelle);
88  }
89  if (isset($this->type)) {
90  $this->type = trim($this->type);
91  }
92  if (isset($this->active)) {
93  $this->active = trim($this->active);
94  }
95  if (isset($this->accountancy_code)) {
96  $this->accountancy_code = trim($this->accountancy_code);
97  }
98  if (isset($this->module)) {
99  $this->module = trim($this->module);
100  }
101 
102 
103 
104  // Check parameters
105  // Put here code to add control on parameters values
106 
107  // Insert request
108  $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
109 
110  $sql.= 'id,';
111  $sql.= 'code,';
112  $sql.= 'libelle,';
113  $sql.= 'type,';
114  $sql.= 'active,';
115  $sql.= 'accountancy_code,';
116  $sql.= 'module';
117 
118 
119  $sql .= ') VALUES (';
120 
121  $sql .= ' '.(! isset($this->id)?'NULL':$this->id).',';
122  $sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").',';
123  $sql .= ' '.(! isset($this->libelle)?'NULL':"'".$this->db->escape($this->libelle)."'").',';
124  $sql .= ' '.(! isset($this->type)?'NULL':$this->type).',';
125  $sql .= ' '.(! isset($this->active)?'NULL':$this->active).',';
126  $sql .= ' '.(! isset($this->accountancy_code)?'NULL':"'".$this->db->escape($this->accountancy_code)."'").',';
127  $sql .= ' '.(! isset($this->module)?'NULL':"'".$this->db->escape($this->module)."'");
128 
129 
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  if (!$notrigger) {
145  // Uncomment this and change MYOBJECT to your own tag if you
146  // want this action to call a trigger.
147 
149  //$result=$this->call_trigger('MYOBJECT_CREATE',$user);
150  //if ($result < 0) $error++;
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,";
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.code = ' . '\'' . $ref . '\'';
190  } else {
191  $sql .= ' WHERE t.id = ' . $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->libelle;
204  $this->type = $obj->type;
205  $this->active = $obj->active;
206  $this->accountancy_code = $obj->accountancy_code;
207  $this->module = $obj->module;
208 
209 
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->type)) {
249  $this->type = trim($this->type);
250  }
251  if (isset($this->active)) {
252  $this->active = trim($this->active);
253  }
254  if (isset($this->accountancy_code)) {
255  $this->accountancy_code = trim($this->accountancy_code);
256  }
257  if (isset($this->module)) {
258  $this->module = trim($this->module);
259  }
260 
261 
262 
263  // Check parameters
264  // Put here code to add a control on parameters values
265 
266  // Update request
267  $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
268  $sql .= ' id = '.(isset($this->id)?$this->id:"null").',';
269  $sql .= ' code = '.(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").',';
270  $sql .= ' libelle = '.(isset($this->libelle)?"'".$this->db->escape($this->libelle)."'":"null").',';
271  $sql .= ' type = '.(isset($this->type)?$this->type:"null").',';
272  $sql .= ' active = '.(isset($this->active)?$this->active:"null").',';
273  $sql .= ' accountancy_code = '.(isset($this->accountancy_code)?"'".$this->db->escape($this->accountancy_code)."'":"null").',';
274  $sql .= ' module = '.(isset($this->module)?"'".$this->db->escape($this->module)."'":"null");
275  $sql .= ' WHERE id=' . $this->id;
276 
277  $this->db->begin();
278 
279  $resql = $this->db->query($sql);
280  if (!$resql) {
281  $error ++;
282  $this->errors[] = 'Error ' . $this->db->lasterror();
283  dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
284  }
285 
286  if (!$error && !$notrigger) {
287  // Uncomment this and change MYOBJECT to your own tag if you
288  // want this action calls a trigger.
289 
291  //$result=$this->call_trigger('MYOBJECT_MODIFY',$user);
292  //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
294  }
295 
296  // Commit or rollback
297  if ($error) {
298  $this->db->rollback();
299 
300  return - 1 * $error;
301  } else {
302  $this->db->commit();
303 
304  return 1;
305  }
306  }
307 
316  public function delete(User $user, $notrigger = false)
317  {
318  dol_syslog(__METHOD__, LOG_DEBUG);
319 
320  $error = 0;
321 
322  $this->db->begin();
323 
324  if (!$error) {
325  if (!$notrigger) {
326  // Uncomment this and change MYOBJECT to your own tag if you
327  // want this action calls a trigger.
328 
330  //$result=$this->call_trigger('MYOBJECT_DELETE',$user);
331  //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
333  }
334  }
335 
336  if (!$error) {
337  $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
338  $sql .= ' WHERE id=' . $this->id;
339 
340  $resql = $this->db->query($sql);
341  if (!$resql) {
342  $error ++;
343  $this->errors[] = 'Error ' . $this->db->lasterror();
344  dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
345  }
346  }
347 
348  // Commit or rollback
349  if ($error) {
350  $this->db->rollback();
351 
352  return - 1 * $error;
353  } else {
354  $this->db->commit();
355 
356  return 1;
357  }
358  }
359 
360 
367  public function initAsSpecimen()
368  {
369  $this->id = 0;
370 
371  $this->code = '';
372  $this->libelle = '';
373  $this->type = '';
374  $this->active = '';
375  $this->accountancy_code = '';
376  $this->module = '';
377 
378 
379  }
380 
381 }
__construct(DoliDB $db)
Constructor.
create(User $user, $notrigger=false)
Create object into database.
Class to manage Dolibarr users.
Definition: user.class.php:39
Class Cpaiement.
Class to manage Dolibarr database access.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
update(User $user, $notrigger=false)
Update object into database.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
type
Definition: viewcat.php:283