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 ".MAIN_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(MAIN_DB_PREFIX.$this->table_element);
142 public function fetch($id, $code =
'')
151 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
152 $sql_where = array();
153 if ($id) $sql_where[] =
" t.rowid = ".$id;
154 if ($code >= 0) $sql_where[] =
" t.code = ".((int) $code);
155 if (count($sql_where) > 0) {
156 $sql .=
' WHERE '.implode(
' AND ', $sql_where);
164 $obj = $this->
db->fetch_object(
$resql);
166 $this->
id = $obj->rowid;
167 $this->
code = $obj->code;
168 $this->label = $obj->label;
169 $this->active = $obj->active;
175 $this->error =
"Error ".$this->db->lasterror();
192 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
203 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
206 if (count($filter) > 0) {
207 foreach ($filter as $key => $value) {
208 if ($key ==
't.rowid' || $key ==
't.active' || $key ==
't.code') {
209 $sqlwhere[] = $key.
'='.(int) $value;
210 } elseif (strpos($key,
'date') !==
false) {
211 $sqlwhere[] = $key.
' = \''.$this->
db->idate($value).
'\'';
212 } elseif ($key ==
't.label') {
213 $sqlwhere[] = $key.
' = \''.$this->
db->escape($value).
'\'';
215 $sqlwhere[] = $key.
' LIKE \'%'.$this->
db->escape($value).
'%\'';
219 if (count($sqlwhere) > 0) {
220 $sql .=
' WHERE ('.implode(
' '.$filtermode.
' ', $sqlwhere).
')';
223 if (!empty($sortfield)) {
224 $sql .= $this->
db->order($sortfield, $sortorder);
226 if (!empty($limit)) {
227 $sql .=
' '.$this->db->plimit($limit, $offset);
232 $this->records = array();
235 while ($obj = $this->
db->fetch_object(
$resql))
237 $record =
new self($this->db);
239 $record->id = $obj->rowid;
240 $record->code = $obj->code;
241 $record->label = $obj->label;
242 $this->records[$record->id] = $record;
247 return $this->records;
249 $this->errors[] =
'Error '.$this->db->lasterror();
250 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
264 public function update($user = null, $notrigger = 0)
266 global $conf, $langs;
269 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
270 $sql .=
" code=".(isset($this->
code) ? ((int) $this->
code) :
"null").
",";
271 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape(trim($this->label)).
"'" :
"null").
",";
272 $sql .=
" active=".(isset($this->active) ? ((int) $this->active) :
"null");
273 $sql .=
" WHERE rowid=".(int) $this->
id;
277 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
281 dol_syslog(get_class($this).
"::update Error ".$this->
db->lasterror(), LOG_ERR);
282 $this->error =
"Error ".$this->db->lasterror();
283 $this->
db->rollback();
299 public function delete($user, $notrigger = 0)
301 global $conf, $langs;
304 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
305 $sql .=
" WHERE rowid=".(int) $this->
id;
309 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
313 dol_syslog(get_class($this).
"::delete Error ".$this->
db->lasterror(), LOG_ERR);
314 $this->error =
"Error ".$this->db->lasterror();
315 $this->
db->rollback();
332 if ($mode ==
'label') {
334 } elseif ($mode ==
'code') {
if(!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'] country if(!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'] typent code
$conf db
API class for accounts.
update($user=null, $notrigger=0)
Update object into database.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
fetch($id, $code= '')
Load object in memory from database.
__construct($db)
Constructor.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
Class of dictionary of nature of product (used by imports)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
create($user, $notrigger=0)
Create object into database.
fetchAll($sortorder= '', $sortfield= '', $limit=0, $offset=0, array $filter=array(), $filtermode= 'AND')
Load list of objects in memory from the database.
getProductNatureFromCode($code, $mode= 'code')
Get unit from code.