36 public $element =
'undefined';
41 public $table_element =
'undefined';
46 public $lines = array();
82 $fieldlabel =
'label';
83 if ($this->table_element ==
'c_stcomm') {
84 $fieldlabel =
'libelle';
85 } elseif ($this->table_element ==
'c_type_fees') {
93 if (isset($this->
code)) {
96 if (isset($this->label)) {
97 $this->label = trim($this->label);
99 if (isset($this->active)) {
100 $this->active = trim($this->active);
104 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'(';
108 $sql .=
') VALUES (';
109 $sql .=
' '.(!isset($this->
code) ?
'NULL' :
"'".$this->db->escape($this->
code).
"'").
',';
110 $sql .=
' '.(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
',';
111 $sql .=
' '.(!isset($this->active) ?
'NULL' : $this->active);
119 $this->errors[] =
'Error '.$this->db->lasterror();
120 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
124 $this->
id = $this->
db->last_insert_id($this->
db->prefix().$this->table_element);
139 $this->
db->rollback();
158 public function fetch($id, $code =
'', $label =
'')
162 $fieldrowid =
'rowid';
163 $fieldlabel =
'label';
164 if ($this->table_element ==
'c_stcomm') {
166 $fieldlabel =
'libelle';
167 } elseif ($this->table_element ==
'c_type_fees') {
172 $sql .=
" t.".$fieldrowid.
",";
174 $sql .=
" t.".$fieldlabel.
" as label,";
176 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
178 $sql .=
" WHERE t.".$fieldrowid.
" = ".((int) $id);
180 $sql .=
" WHERE t.code = '".$this->db->escape($code).
"'";
182 $sql .=
" WHERE t.label = '".$this->db->escape($label).
"'";
187 $numrows = $this->
db->num_rows(
$resql);
189 $obj = $this->
db->fetch_object(
$resql);
191 $this->
id = $obj->$fieldrowid;
193 $this->
code = $obj->code;
194 $this->label = $obj->label;
195 $this->active = $obj->active;
212 $this->errors[] =
'Error '.$this->db->lasterror();
213 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
231 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
235 $fieldrowid =
'rowid';
236 $fieldlabel =
'label';
237 if ($this->table_element ==
'c_stcomm') {
239 $fieldlabel =
'libelle';
240 } elseif ($this->table_element ==
'c_type_fees') {
245 $sql .=
" t.".$fieldrowid.
",";
247 $sql .=
" t.".$fieldlabel.
" as label,";
249 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
253 if (count($filter) > 0) {
254 foreach ($filter as $key => $value) {
255 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
259 if (count($sqlwhere) > 0) {
260 $sql .=
" WHERE ".implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere);
262 if (!empty($sortfield)) {
263 $sql .= $this->
db->order($sortfield, $sortorder);
265 if (!empty($limit)) {
266 $sql .= $this->
db->plimit($limit, $offset);
273 while ($obj = $this->
db->fetch_object(
$resql)) {
274 $line =
new self($this->db);
276 $line->id = $obj->$fieldrowid;
278 $line->code = $obj->code;
279 $line->label = $obj->label;
280 $line->active = $obj->active;
286 $this->errors[] =
'Error '.$this->db->lasterror();
287 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
307 $fieldrowid =
'rowid';
308 $fieldlabel =
'label';
309 if ($this->table_element ==
'c_stcomm') {
311 $fieldlabel =
'libelle';
312 } elseif ($this->table_element ==
'c_type_fees') {
318 if (isset($this->
code)) {
321 if (isset($this->label)) {
322 $this->label = trim($this->label);
324 if (isset($this->active)) {
325 $this->active = trim($this->active);
332 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
' SET';
333 $sql .=
" code = ".(isset($this->
code) ?
"'".$this->db->escape($this->
code).
"'" :
"null").
',';
334 $sql .=
" ".$fieldlabel.
" = ".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
',';
335 $sql .=
" active = ".(isset($this->active) ? $this->active :
"null");
336 $sql .=
" WHERE ".$fieldrowid.
" = ".((int) $this->
id);
343 $this->errors[] =
'Error '.$this->db->lasterror();
344 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
359 $this->
db->rollback();
377 public function delete(
User $user, $notrigger =
false)
381 $fieldrowid =
'rowid';
400 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
401 $sql .=
" WHERE ".$fieldrowid.
" = ".((int) $this->
id);
406 $this->errors[] =
'Error '.$this->db->lasterror();
407 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
413 $this->
db->rollback();
440 $object->fetch($fromid);
448 $object->context[
'createfromclone'] =
'createfromclone';
449 $result = $object->create($user);
454 $this->errors = $object->errors;
455 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
458 unset($object->context[
'createfromclone']);
466 $this->
db->rollback();
482 $this->
code =
'CODE';
483 $this->label =
'Label';
create(User $user, $notrigger=false)
Create object into database.
update(User $user, $notrigger=false)
Update object into database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load object in memory from the database.
fetch($id, $code='', $label='')
Load object in memory from the database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
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_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,...