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';
91 if (isset($this->
code)) {
94 if (isset($this->label)) {
95 $this->label = trim($this->label);
97 if (isset($this->active)) {
98 $this->active = trim($this->active);
102 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'(';
106 $sql .=
') VALUES (';
107 $sql .=
' '.(!isset($this->
code) ?
'NULL' :
"'".$this->db->escape($this->
code).
"'").
',';
108 $sql .=
' '.(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
',';
109 $sql .=
' '.(!isset($this->active) ?
'NULL' : $this->active);
117 $this->errors[] =
'Error '.$this->db->lasterror();
118 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
122 $this->
id = $this->
db->last_insert_id($this->
db->prefix().$this->table_element);
137 $this->
db->rollback();
156 public function fetch($id, $code =
'', $label =
'')
160 $fieldrowid =
'rowid';
161 $fieldlabel =
'label';
162 if ($this->table_element ==
'c_stcomm') {
164 $fieldlabel =
'libelle';
168 $sql .=
" t.".$fieldrowid.
",";
170 $sql .=
" t.".$fieldlabel.
" as label,";
172 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
174 $sql .=
" WHERE t.".$fieldrowid.
" = ".((int) $id);
176 $sql .=
" WHERE t.code = '".$this->db->escape($code).
"'";
178 $sql .=
" WHERE t.label = '".$this->db->escape($label).
"'";
183 $numrows = $this->
db->num_rows(
$resql);
185 $obj = $this->
db->fetch_object(
$resql);
187 $this->
id = $obj->$fieldrowid;
189 $this->
code = $obj->code;
190 $this->label = $obj->label;
191 $this->active = $obj->active;
208 $this->errors[] =
'Error '.$this->db->lasterror();
209 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
227 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
231 $fieldrowid =
'rowid';
232 $fieldlabel =
'label';
233 if ($this->table_element ==
'c_stcomm') {
235 $fieldlabel =
'libelle';
239 $sql .=
" t.".$fieldrowid.
",";
241 $sql .=
" t.".$fieldlabel.
" as label,";
243 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
247 if (count($filter) > 0) {
248 foreach ($filter as $key => $value) {
249 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
253 if (count($sqlwhere) > 0) {
254 $sql .=
" WHERE ".implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere);
256 if (!empty($sortfield)) {
257 $sql .= $this->
db->order($sortfield, $sortorder);
259 if (!empty($limit)) {
260 $sql .= $this->
db->plimit($limit, $offset);
267 while ($obj = $this->
db->fetch_object(
$resql)) {
268 $line =
new self($this->db);
270 $line->id = $obj->$fieldrowid;
272 $line->code = $obj->code;
273 $line->label = $obj->label;
274 $line->active = $obj->active;
280 $this->errors[] =
'Error '.$this->db->lasterror();
281 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
301 $fieldrowid =
'rowid';
302 $fieldlabel =
'label';
303 if ($this->table_element ==
'c_stcomm') {
305 $fieldlabel =
'libelle';
310 if (isset($this->
code)) {
313 if (isset($this->label)) {
314 $this->label = trim($this->label);
316 if (isset($this->active)) {
317 $this->active = trim($this->active);
324 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
' SET';
325 $sql .=
" code = ".(isset($this->
code) ?
"'".$this->db->escape($this->
code).
"'" :
"null").
',';
326 $sql .=
" ".$fieldlabel.
" = ".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
',';
327 $sql .=
" active = ".(isset($this->active) ? $this->active :
"null");
328 $sql .=
" WHERE ".$fieldrowid.
" = ".((int) $this->
id);
335 $this->errors[] =
'Error '.$this->db->lasterror();
336 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
351 $this->
db->rollback();
369 public function delete(
User $user, $notrigger =
false)
373 $fieldrowid =
'rowid';
392 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
393 $sql .=
" WHERE ".$fieldrowid.
" = ".((int) $this->
id);
398 $this->errors[] =
'Error '.$this->db->lasterror();
399 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
405 $this->
db->rollback();
432 $object->fetch($fromid);
440 $object->context[
'createfromclone'] =
'createfromclone';
441 $result = $object->create($user);
446 $this->errors = $object->errors;
447 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
450 unset($object->context[
'createfromclone']);
458 $this->
db->rollback();
474 $this->
code =
'CODE';
475 $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,...