dolibarr  17.0.4
ctypent.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
28 class Ctypent // extends CommonObject
29 {
33  public $db;
34 
38  public $error = '';
39 
43  public $errors = array();
44 
45  //var $element='ctypent'; //!< Id that identify managed objects
46  //var $table_element='ctypent'; //!< Name of table without prefix where object is stored
47 
51  public $id;
52 
53  public $code;
54  public $libelle;
55  public $active;
56  public $module;
57 
58 
59 
60 
66  public function __construct($db)
67  {
68  $this->db = $db;
69  }
70 
71 
79  public function create($user, $notrigger = 0)
80  {
81  global $conf, $langs;
82  $error = 0;
83 
84  // Clean parameters
85 
86  if (isset($this->id)) {
87  $this->id = trim($this->id);
88  }
89  if (isset($this->code)) {
90  $this->code = trim($this->code);
91  }
92  if (isset($this->libelle)) {
93  $this->libelle = trim($this->libelle);
94  }
95  if (isset($this->active)) {
96  $this->active = trim($this->active);
97  }
98  if (isset($this->module)) {
99  $this->module = trim($this->module);
100  }
101 
102  // Check parameters
103  // Put here code to add control on parameters values
104 
105  // Insert request
106  $sql = "INSERT INTO ".$this->db->prefix()."c_typent(";
107  $sql .= "id,";
108  $sql .= "code,";
109  $sql .= "libelle,";
110  $sql .= "active,";
111  $sql .= "module";
112  $sql .= ") VALUES (";
113  $sql .= " ".(!isset($this->id) ? 'NULL' : "'".$this->db->escape($this->id)."'").",";
114  $sql .= " ".(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").",";
115  $sql .= " ".(!isset($this->libelle) ? 'NULL' : "'".$this->db->escape($this->libelle)."'").",";
116  $sql .= " ".(!isset($this->active) ? 'NULL' : "'".$this->db->escape($this->active)."'").",";
117  $sql .= " ".(!isset($this->module) ? 'NULL' : "'".$this->db->escape($this->module)."'")."";
118  $sql .= ")";
119 
120  $this->db->begin();
121 
122  dol_syslog(get_class($this)."::create", LOG_DEBUG);
123  $resql = $this->db->query($sql);
124  if (!$resql) {
125  $error++;
126  $this->errors[] = "Error ".$this->db->lasterror();
127  }
128 
129  if (!$error) {
130  $this->id = $this->db->last_insert_id($this->db->prefix()."c_typent");
131  }
132 
133  // Commit or rollback
134  if ($error) {
135  foreach ($this->errors as $errmsg) {
136  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
137  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
138  }
139  $this->db->rollback();
140  return -1 * $error;
141  } else {
142  $this->db->commit();
143  return $this->id;
144  }
145  }
146 
147 
156  public function fetch($id, $code = '', $label = '')
157  {
158  $sql = "SELECT";
159  $sql .= " t.id,";
160  $sql .= " t.code,";
161  $sql .= " t.libelle as label,";
162  $sql .= " t.fk_country as country_id,";
163  $sql .= " t.active,";
164  $sql .= " t.module";
165  $sql .= " FROM ".$this->db->prefix()."c_typent as t";
166  if ($id) {
167  $sql .= " WHERE t.id = ".((int) $id);
168  } elseif ($code) {
169  $sql .= " WHERE t.code = '".$this->db->escape($code)."'";
170  } elseif ($label) {
171  $sql .= " WHERE t.libelle = '".$this->db->escape($label)."'";
172  }
173 
174  $resql = $this->db->query($sql);
175  if ($resql) {
176  if ($this->db->num_rows($resql)) {
177  $obj = $this->db->fetch_object($resql);
178 
179  $this->id = $obj->id;
180  $this->code = $obj->code;
181  $this->libelle = $obj->label;
182  $this->country_id = $obj->country_id;
183  $this->active = $obj->active;
184  $this->module = $obj->module;
185  }
186  $this->db->free($resql);
187 
188  return 1;
189  } else {
190  $this->error = "Error ".$this->db->lasterror();
191  return -1;
192  }
193  }
194 
195 
203  public function update($user = null, $notrigger = 0)
204  {
205  global $conf, $langs;
206  $error = 0;
207 
208  // Clean parameters
209  if (isset($this->code)) {
210  $this->code = trim($this->code);
211  }
212  if (isset($this->libelle)) {
213  $this->libelle = trim($this->libelle);
214  }
215  if (isset($this->active)) {
216  $this->active = trim($this->active);
217  }
218  if (isset($this->module)) {
219  $this->module = trim($this->module);
220  }
221 
222 
223  // Check parameters
224  // Put here code to add control on parameters values
225 
226  // Update request
227  $sql = "UPDATE ".$this->db->prefix()."c_typent SET";
228  $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").",";
229  $sql .= " libelle=".(isset($this->libelle) ? "'".$this->db->escape($this->libelle)."'" : "null").",";
230  $sql .= " active=".(isset($this->active) ? $this->active : "null").",";
231  $sql .= " module=".(isset($this->module) ? "'".$this->db->escape($this->module)."'" : "null")."";
232  $sql .= " WHERE id=".$this->id;
233 
234  $this->db->begin();
235 
236  dol_syslog(get_class($this)."::update", LOG_DEBUG);
237  $resql = $this->db->query($sql);
238  if (!$resql) {
239  $error++;
240  $this->errors[] = "Error ".$this->db->lasterror();
241  }
242 
243  // Commit or rollback
244  if ($error) {
245  foreach ($this->errors as $errmsg) {
246  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
247  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
248  }
249  $this->db->rollback();
250  return -1 * $error;
251  } else {
252  $this->db->commit();
253  return 1;
254  }
255  }
256 
257 
265  public function delete($user, $notrigger = 0)
266  {
267  global $conf, $langs;
268  $error = 0;
269 
270  $sql = "DELETE FROM ".$this->db->prefix()."c_typent";
271  $sql .= " WHERE id = ".$this->id;
272 
273  $this->db->begin();
274 
275  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
276  $resql = $this->db->query($sql);
277  if (!$resql) {
278  $error++;
279  $this->errors[] = "Error ".$this->db->lasterror();
280  }
281 
282  // Commit or rollback
283  if ($error) {
284  foreach ($this->errors as $errmsg) {
285  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
286  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
287  }
288  $this->db->rollback();
289  return -1 * $error;
290  } else {
291  $this->db->commit();
292  return 1;
293  }
294  }
295 }
Class of dictionary type of thirdparty (used by imports)
create($user, $notrigger=0)
Create object into database.
__construct($db)
Constructor.
update($user=null, $notrigger=0)
Update object into database.
fetch($id, $code='', $label='')
Load object in memory from database.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.
Definition: inc.php:41
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge,...