44 public $errors = array();
49 public $records = array();
54 public $element =
'cproductnbature';
59 public $table_element =
'c_product_nature';
100 public function create($user, $notrigger = 0)
102 global $conf, $langs;
105 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
"(";
110 $sql .=
") VALUES (";
111 $sql .=
" ".(!isset($this->
id) ?
'NULL' : ((int) $this->
id)).
",";
112 $sql .=
" ".(!isset($this->
code) ?
'NULL' : ((int) $this->
code)).
",";
113 $sql .=
" ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape(trim($this->label)).
"'").
",";
114 $sql .=
" ".(!isset($this->active) ?
'NULL' : ((int) $this->active)).
",";
119 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
123 dol_syslog(get_class($this).
"::create ".$this->
db->lasterror(), LOG_ERR);
124 $this->error =
"Error ".$this->db->lasterror();
125 $this->
db->rollback();
128 $this->
id = $this->
db->last_insert_id($this->
db->prefix().$this->table_element);
142 public function fetch($id, $code =
'')
151 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
152 $sql_where = array();
154 $sql_where[] =
" t.rowid = ".((int) $id);
157 $sql_where[] =
" t.code = ".((int) $code);
159 if (count($sql_where) > 0) {
160 $sql .=
' WHERE '.implode(
' AND ', $sql_where);
166 $obj = $this->
db->fetch_object(
$resql);
168 $this->
id = $obj->rowid;
169 $this->
code = $obj->code;
170 $this->label = $obj->label;
171 $this->active = $obj->active;
177 $this->error =
"Error ".$this->db->lasterror();
194 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
205 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
208 if (count($filter) > 0) {
209 foreach ($filter as $key => $value) {
210 if ($key ==
't.rowid' || $key ==
't.active' || $key ==
't.code') {
211 $sqlwhere[] = $key.
" = ".((int) $value);
212 } elseif (strpos($key,
'date') !==
false) {
213 $sqlwhere[] = $key.
" = '".$this->
db->idate($value).
"'";
214 } elseif ($key ==
't.label') {
215 $sqlwhere[] = $key.
" = '".$this->
db->escape($value).
"'";
217 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
221 if (count($sqlwhere) > 0) {
222 $sql .=
' WHERE ('.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
225 if (!empty($sortfield)) {
226 $sql .= $this->
db->order($sortfield, $sortorder);
228 if (!empty($limit)) {
229 $sql .= $this->
db->plimit($limit, $offset);
234 $this->records = array();
237 while ($obj = $this->
db->fetch_object(
$resql)) {
238 $record =
new self($this->db);
240 $record->id = $obj->rowid;
241 $record->code = $obj->code;
242 $record->label = $obj->label;
243 $this->records[$record->id] = $record;
248 return $this->records;
250 $this->errors[] =
'Error '.$this->db->lasterror();
251 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
265 public function update($user =
null, $notrigger = 0)
267 global $conf, $langs;
270 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
271 $sql .=
" code=".(isset($this->
code) ? ((int) $this->
code) :
"null").
",";
272 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape(trim($this->label)).
"'" :
"null").
",";
273 $sql .=
" active=".(isset($this->active) ? ((int) $this->active) :
"null");
274 $sql .=
" WHERE rowid=".(int) $this->
id;
278 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
282 dol_syslog(get_class($this).
"::update Error ".$this->
db->lasterror(), LOG_ERR);
283 $this->error =
"Error ".$this->db->lasterror();
284 $this->
db->rollback();
300 public function delete($user, $notrigger = 0)
302 global $conf, $langs;
305 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
306 $sql .=
" WHERE rowid=".(int) $this->
id;
310 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
314 dol_syslog(get_class($this).
"::delete Error ".$this->
db->lasterror(), LOG_ERR);
315 $this->error =
"Error ".$this->db->lasterror();
316 $this->
db->rollback();
333 if ($mode ==
'label') {
335 } elseif ($mode ==
'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, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
create($user, $notrigger=0)
Create object into database.
__construct($db)
Constructor.
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.
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.
$conf db
API class for accounts.
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge,...