27 require_once DOL_DOCUMENT_ROOT.
'/core/class/commondict.class.php';
38 public $records = array();
43 public $element =
'cproductnbature';
48 public $table_element =
'c_product_nature';
69 public function create($user, $notrigger = 0)
74 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
"(";
80 $sql .=
" ".(!isset($this->
id) ?
'NULL' : ((int) $this->
id)).
",";
81 $sql .=
" ".(!isset($this->
code) ?
'NULL' : ((int) $this->
code)).
",";
82 $sql .=
" ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape(trim($this->label)).
"'").
",";
83 $sql .=
" ".(!isset($this->active) ?
'NULL' : ((int) $this->active)).
",";
88 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
89 $resql = $this->db->query(
$sql);
92 dol_syslog(get_class($this).
"::create ".$this->db->lasterror(), LOG_ERR);
93 $this->error =
"Error ".$this->db->lasterror();
94 $this->db->rollback();
97 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
111 public function fetch($id, $code =
'')
120 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
121 $sql_where = array();
123 $sql_where[] =
" t.rowid = ".((int) $id);
126 $sql_where[] =
" t.code = ".((int) $code);
128 if (count($sql_where) > 0) {
129 $sql .=
' WHERE '.implode(
' AND ', $sql_where);
132 $resql = $this->db->query(
$sql);
134 if ($this->db->num_rows($resql)) {
135 $obj = $this->db->fetch_object($resql);
137 $this->
id = $obj->rowid;
138 $this->
code = $obj->code;
139 $this->label = $obj->label;
140 $this->active = $obj->active;
142 $this->db->free($resql);
146 $this->error =
"Error ".$this->db->lasterror();
163 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
172 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
173 $sql .=
" WHERE 1 = 1";
176 if (is_array($filter)) {
178 if (count($filter) > 0) {
179 foreach ($filter as $key => $value) {
180 if ($key ==
't.rowid' || $key ==
't.active' || $key ==
't.code') {
181 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
182 } elseif (strpos($key,
'date') !==
false) {
183 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate($value).
"'";
184 } elseif ($key ==
't.label') {
185 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->escape($value).
"'";
187 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($value).
"%'";
191 if (count($sqlwhere) > 0) {
192 $sql .=
" AND ".implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
202 $this->errors[] = $errormessage;
203 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
207 if (!empty($sortfield)) {
208 $sql .= $this->db->order($sortfield, $sortorder);
210 if (!empty($limit)) {
211 $sql .= $this->db->plimit($limit, $offset);
214 $resql = $this->db->query(
$sql);
216 $this->records = array();
217 $num = $this->db->num_rows($resql);
219 while ($obj = $this->db->fetch_object($resql)) {
220 $record =
new self($this->db);
222 $record->id = $obj->rowid;
223 $record->code = $obj->code;
224 $record->label = $obj->label;
225 $this->records[$record->id] = $record;
228 $this->db->free($resql);
230 return $this->records;
232 $this->errors[] =
'Error '.$this->db->lasterror();
233 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
247 public function update($user =
null, $notrigger = 0)
249 global $conf, $langs;
252 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
253 $sql .=
" code=".(isset($this->
code) ? ((int) $this->
code) :
"null").
",";
254 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape(trim($this->label)).
"'" :
"null").
",";
255 $sql .=
" active=".(isset($this->active) ? ((int) $this->active) :
"null");
256 $sql .=
" WHERE rowid=".(int) $this->
id;
260 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
261 $resql = $this->db->query(
$sql);
264 dol_syslog(get_class($this).
"::update Error ".$this->db->lasterror(), LOG_ERR);
265 $this->error =
"Error ".$this->db->lasterror();
266 $this->db->rollback();
282 public function delete($user, $notrigger = 0)
284 global $conf, $langs;
287 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
288 $sql .=
" WHERE rowid=".(int) $this->
id;
292 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
293 $resql = $this->db->query(
$sql);
296 dol_syslog(get_class($this).
"::delete Error ".$this->db->lasterror(), LOG_ERR);
297 $this->error =
"Error ".$this->db->lasterror();
298 $this->db->rollback();
315 if ($mode ==
'label') {
316 return dol_getIdFromCode($this->db, $code, $this->table_element,
'label',
'code');
317 } elseif ($mode ==
'code') {
318 return dol_getIdFromCode($this->db, $code, $this->table_element,
'code',
'code');
Class of dictionary of nature of product (used by imports)
fetch($id, $code='')
Load object in memory from database.
getProductNatureFromCode($code, $mode='code')
Get unit from code.
update($user=null, $notrigger=0)
Update object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
create($user, $notrigger=0)
Create object into database.
__construct($db)
Constructor.
Parent class of all other dictionary classes.
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.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
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)