52 public $element =
'cchargesociales';
57 public $table_element =
'c_chargesociales';
95 public $accountancy_code;
100 public $errors = array();
135 if (isset($this->fk_pays)) {
136 $this->fk_pays = (int) $this->fk_pays;
138 if (isset($this->
active)) {
146 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
148 $sql .=
'deductible,';
153 $sql .=
'accountancy_code';
154 $sql .=
') VALUES (';
155 $sql .=
' '.(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
',';
156 $sql .=
' '.(!isset($this->deductible) ?
'NULL' : $this->deductible).
',';
157 $sql .=
' ' . (int) $this->
active .
',';
158 $sql .=
' '.(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
',';
159 $sql .=
' '.(!isset($this->fk_pays) ?
'NULL' : $this->fk_pays).
',';
160 $sql .=
' '.(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'").
',';
161 $sql .=
' '.(!isset($this->accountancy_code) ?
'NULL' :
"'".$this->db->escape($this->accountancy_code).
"'");
166 $resql = $this->db->query($sql);
169 $this->errors[] =
'Error '.$this->db->lasterror();
170 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
174 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
189 $this->db->rollback();
207 public function fetch($id, $ref =
null)
213 $sql .=
" t.libelle as label,";
214 $sql .=
" t.deductible,";
215 $sql .=
" t.active,";
217 $sql .=
" t.fk_pays,";
218 $sql .=
" t.module,";
219 $sql .=
" t.accountancy_code";
220 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
222 $sql .=
" WHERE t.code = '".$this->db->escape($ref).
"'";
224 $sql .=
' WHERE t.id = '.((int) $id);
227 $resql = $this->db->query($sql);
229 $numrows = $this->db->num_rows($resql);
231 $obj = $this->db->fetch_object($resql);
233 $this->
id = $obj->id;
235 $this->libelle = $obj->label;
236 $this->label = $obj->label;
237 $this->deductible = $obj->deductible;
238 $this->
active = $obj->active;
239 $this->code = $obj->code;
240 $this->fk_pays = $obj->fk_pays;
241 $this->module = $obj->module;
242 $this->accountancy_code = $obj->accountancy_code;
244 $this->db->free($resql);
252 $this->errors[] =
'Error '.$this->db->lasterror();
253 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
283 if (isset($this->fk_pays)) {
284 $this->fk_pays = (int) $this->fk_pays;
286 if (isset($this->
active)) {
294 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
295 $sql .=
' libelle = '.(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
',';
296 $sql .=
' deductible = '.(isset($this->deductible) ? ((int) $this->deductible) :
"null").
',';
297 $sql .=
' active = '.(isset($this->
active) ? ((int) $this->
active) :
"null").
',';
298 $sql .=
' code = '.(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
',';
299 $sql .=
' fk_pays = '.((isset($this->fk_pays) && $this->fk_pays > 0) ? ((
int) $this->fk_pays) :
"null").
',';
300 $sql .=
' module = '.(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null").
',';
301 $sql .=
' accountancy_code = '.(isset($this->accountancy_code) ?
"'".$this->db->escape($this->accountancy_code).
"'" :
"null");
302 $sql .=
' WHERE id='.((int) $this->
id);
306 $resql = $this->db->query($sql);
309 $this->errors[] =
'Error '.$this->db->lasterror();
310 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
325 $this->db->rollback();
342 public function delete(
User $user, $notrigger = 0)
363 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
364 $sql .=
' WHERE id = '.((int) $this->
id);
366 $resql = $this->db->query($sql);
369 $this->errors[] =
'Error '.$this->db->lasterror();
370 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
376 $this->db->rollback();
501 return $langs->trans(
'Enabled');
502 } elseif ($status == 0) {
503 return $langs->trans(
'Disabled');
505 } elseif ($mode == 1) {
507 return $langs->trans(
'Enabled');
508 } elseif ($status == 0) {
509 return $langs->trans(
'Disabled');
511 } elseif ($mode == 2) {
513 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
514 } elseif ($status == 0) {
515 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
517 } elseif ($mode == 3) {
519 return img_picto($langs->trans(
'Enabled'),
'statut4');
520 } elseif ($status == 0) {
521 return img_picto($langs->trans(
'Disabled'),
'statut5');
523 } elseif ($mode == 4) {
525 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
526 } elseif ($status == 0) {
527 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
529 } elseif ($mode == 5) {
531 return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
532 } elseif ($status == 0) {
533 return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
551 $this->deductible =
'';
556 $this->accountancy_code =
'';
569 foreach ($parameters as $parameter) {
570 if (isset($this->$parameter)) {
571 $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, $allowothertags=array())
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.