52 public $element =
'cchargesociales';
57 public $table_element =
'c_chargesociales';
95 public $accountancy_code;
100 public $errors = array();
142 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
144 $sql .=
'deductible,';
149 $sql .=
'accountancy_code';
150 $sql .=
') VALUES (';
151 $sql .=
' '.(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
',';
152 $sql .=
' '.(!isset($this->deductible) ?
'NULL' : $this->deductible).
',';
153 $sql .=
' '.(!isset($this->active) ?
'NULL' : $this->active).
',';
154 $sql .=
' '.(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
',';
155 $sql .=
' '.(!isset($this->fk_pays) ?
'NULL' : $this->fk_pays).
',';
156 $sql .=
' '.(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'").
',';
157 $sql .=
' '.(!isset($this->accountancy_code) ?
'NULL' :
"'".$this->db->escape($this->accountancy_code).
"'");
162 $resql = $this->db->query($sql);
165 $this->errors[] =
'Error '.$this->db->lasterror();
166 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
170 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
185 $this->db->rollback();
203 public function fetch($id, $ref =
null)
209 $sql .=
" t.libelle as label,";
210 $sql .=
" t.deductible,";
211 $sql .=
" t.active,";
213 $sql .=
" t.fk_pays,";
214 $sql .=
" t.module,";
215 $sql .=
" t.accountancy_code";
216 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
218 $sql .=
" WHERE t.code = '".$this->db->escape($ref).
"'";
220 $sql .=
' WHERE t.id = '.((int) $id);
223 $resql = $this->db->query($sql);
225 $numrows = $this->db->num_rows($resql);
227 $obj = $this->db->fetch_object($resql);
229 $this->
id = $obj->id;
231 $this->libelle = $obj->label;
232 $this->label = $obj->label;
233 $this->deductible = $obj->deductible;
234 $this->active = $obj->active;
235 $this->code = $obj->code;
236 $this->fk_pays = $obj->fk_pays;
237 $this->module = $obj->module;
238 $this->accountancy_code = $obj->accountancy_code;
240 $this->db->free($resql);
248 $this->errors[] =
'Error '.$this->db->lasterror();
249 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
287 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
288 $sql .=
' libelle = '.(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
',';
289 $sql .=
' deductible = '.(isset($this->deductible) ? ((int) $this->deductible) :
"null").
',';
290 $sql .=
' active = '.(isset($this->active) ? ((int) $this->active) :
"null").
',';
291 $sql .=
' code = '.(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
',';
292 $sql .=
' fk_pays = '.((isset($this->fk_pays) && $this->fk_pays > 0) ? ((
int) $this->fk_pays) :
"null").
',';
293 $sql .=
' module = '.(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null").
',';
294 $sql .=
' accountancy_code = '.(isset($this->accountancy_code) ?
"'".$this->db->escape($this->accountancy_code).
"'" :
"null");
295 $sql .=
' WHERE id='.((int) $this->
id);
299 $resql = $this->db->query($sql);
302 $this->errors[] =
'Error '.$this->db->lasterror();
303 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
318 $this->db->rollback();
335 public function delete(
User $user, $notrigger = 0)
356 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
357 $sql .=
' WHERE id = '.((int) $this->
id);
359 $resql = $this->db->query($sql);
362 $this->errors[] =
'Error '.$this->db->lasterror();
363 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
369 $this->db->rollback();
494 return $langs->trans(
'Enabled');
495 } elseif ($status == 0) {
496 return $langs->trans(
'Disabled');
498 } elseif ($mode == 1) {
500 return $langs->trans(
'Enabled');
501 } elseif ($status == 0) {
502 return $langs->trans(
'Disabled');
504 } elseif ($mode == 2) {
506 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
507 } elseif ($status == 0) {
508 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
510 } elseif ($mode == 3) {
512 return img_picto($langs->trans(
'Enabled'),
'statut4');
513 } elseif ($status == 0) {
514 return img_picto($langs->trans(
'Disabled'),
'statut5');
516 } elseif ($mode == 4) {
518 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
519 } elseif ($status == 0) {
520 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
522 } elseif ($mode == 5) {
524 return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
525 } elseif ($status == 0) {
526 return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
544 $this->deductible =
'';
549 $this->accountancy_code =
'';
562 foreach ($parameters as $parameter) {
563 if (isset($this->$parameter)) {
564 $this->$parameter = trim($this->$parameter);
fetch($id, $ref=null)
Load object in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
create(User $user, $notrigger=0)
Create object into database.
update(User $user, $notrigger=0)
Update object into database.
LibStatut($status, $mode=0)
Load an object from its id and create a new one in database.
trimParameters($parameters)
Trim object parameters.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.