dolibarr  20.0.0-alpha
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 
24 // Put here all includes required by your class file
25 require_once DOL_DOCUMENT_ROOT.'/core/class/commondict.class.php';
26 
27 
31 class Ctypent extends CommonDict
32 {
36  public $country_id;
37 
38  public $libelle;
39  public $module;
40 
46  public function __construct($db)
47  {
48  $this->db = $db;
49  }
50 
51 
59  public function create($user, $notrigger = 0)
60  {
61  global $conf, $langs;
62  $error = 0;
63 
64  // Clean parameters
65 
66  if (isset($this->id)) {
67  $this->id = (int) $this->id;
68  }
69  if (isset($this->code)) {
70  $this->code = trim($this->code);
71  }
72  if (isset($this->libelle)) {
73  $this->libelle = trim($this->libelle);
74  }
75  if (isset($this->active)) {
76  $this->active = (int) $this->active;
77  }
78  if (isset($this->module)) {
79  $this->module = trim($this->module);
80  }
81 
82  // Check parameters
83  // Put here code to add control on parameters values
84 
85  // Insert request
86  $sql = "INSERT INTO ".$this->db->prefix()."c_typent(";
87  $sql .= "id,";
88  $sql .= "code,";
89  $sql .= "libelle,";
90  $sql .= "active,";
91  $sql .= "module";
92  $sql .= ") VALUES (";
93  $sql .= " ".(!isset($this->id) ? 'NULL' : "'".$this->db->escape($this->id)."'").",";
94  $sql .= " ".(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").",";
95  $sql .= " ".(!isset($this->libelle) ? 'NULL' : "'".$this->db->escape($this->libelle)."'").",";
96  $sql .= " ".(!isset($this->active) ? 'NULL' : "'".$this->db->escape($this->active)."'").",";
97  $sql .= " ".(!isset($this->module) ? 'NULL' : "'".$this->db->escape($this->module)."'");
98  $sql .= ")";
99 
100  $this->db->begin();
101 
102  dol_syslog(get_class($this)."::create", LOG_DEBUG);
103  $resql = $this->db->query($sql);
104  if (!$resql) {
105  $error++;
106  $this->errors[] = "Error ".$this->db->lasterror();
107  }
108 
109  if (!$error) {
110  $this->id = $this->db->last_insert_id($this->db->prefix()."c_typent");
111  }
112 
113  // Commit or rollback
114  if ($error) {
115  foreach ($this->errors as $errmsg) {
116  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
117  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
118  }
119  $this->db->rollback();
120  return -1 * $error;
121  } else {
122  $this->db->commit();
123  return $this->id;
124  }
125  }
126 
127 
136  public function fetch($id, $code = '', $label = '')
137  {
138  $sql = "SELECT";
139  $sql .= " t.id,";
140  $sql .= " t.code,";
141  $sql .= " t.libelle as label,";
142  $sql .= " t.fk_country as country_id,";
143  $sql .= " t.active,";
144  $sql .= " t.module";
145  $sql .= " FROM ".$this->db->prefix()."c_typent as t";
146  if ($id) {
147  $sql .= " WHERE t.id = ".((int) $id);
148  } elseif ($code) {
149  $sql .= " WHERE t.code = '".$this->db->escape($code)."'";
150  } elseif ($label) {
151  $sql .= " WHERE t.libelle = '".$this->db->escape($label)."'";
152  }
153 
154  $resql = $this->db->query($sql);
155  if ($resql) {
156  if ($this->db->num_rows($resql)) {
157  $obj = $this->db->fetch_object($resql);
158 
159  $this->id = $obj->id;
160  $this->code = $obj->code;
161  $this->libelle = $obj->label;
162  $this->country_id = $obj->country_id;
163  $this->active = $obj->active;
164  $this->module = $obj->module;
165  }
166  $this->db->free($resql);
167 
168  return 1;
169  } else {
170  $this->error = "Error ".$this->db->lasterror();
171  return -1;
172  }
173  }
174 
175 
183  public function update($user = null, $notrigger = 0)
184  {
185  global $conf, $langs;
186  $error = 0;
187 
188  // Clean parameters
189  if (isset($this->code)) {
190  $this->code = trim($this->code);
191  }
192  if (isset($this->libelle)) {
193  $this->libelle = trim($this->libelle);
194  }
195  if (isset($this->active)) {
196  $this->active = (int) $this->active;
197  }
198  if (isset($this->module)) {
199  $this->module = trim($this->module);
200  }
201 
202 
203  // Check parameters
204  // Put here code to add control on parameters values
205 
206  // Update request
207  $sql = "UPDATE ".$this->db->prefix()."c_typent SET";
208  $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").",";
209  $sql .= " libelle=".(isset($this->libelle) ? "'".$this->db->escape($this->libelle)."'" : "null").",";
210  $sql .= " active=".(isset($this->active) ? ((int) $this->active) : "null").",";
211  $sql .= " module=".(isset($this->module) ? "'".$this->db->escape($this->module)."'" : "null");
212  $sql .= " WHERE id=".$this->id;
213 
214  $this->db->begin();
215 
216  dol_syslog(get_class($this)."::update", LOG_DEBUG);
217  $resql = $this->db->query($sql);
218  if (!$resql) {
219  $error++;
220  $this->errors[] = "Error ".$this->db->lasterror();
221  }
222 
223  // Commit or rollback
224  if ($error) {
225  foreach ($this->errors as $errmsg) {
226  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
227  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
228  }
229  $this->db->rollback();
230  return -1 * $error;
231  } else {
232  $this->db->commit();
233  return 1;
234  }
235  }
236 
237 
245  public function delete($user, $notrigger = 0)
246  {
247  global $conf, $langs;
248  $error = 0;
249 
250  $sql = "DELETE FROM ".$this->db->prefix()."c_typent";
251  $sql .= " WHERE id = ".$this->id;
252 
253  $this->db->begin();
254 
255  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
256  $resql = $this->db->query($sql);
257  if (!$resql) {
258  $error++;
259  $this->errors[] = "Error ".$this->db->lasterror();
260  }
261 
262  // Commit or rollback
263  if ($error) {
264  foreach ($this->errors as $errmsg) {
265  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
266  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
267  }
268  $this->db->rollback();
269  return -1 * $error;
270  } else {
271  $this->db->commit();
272  return 1;
273  }
274  }
275 }
Parent class of all other dictionary classes.
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('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:744
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print *****$script_file(".$version.") pid code
1: frais de port 2: ecotaxe 3: option line (when qty = 0)