44 public $element =
'cchargesociales';
49 public $table_element =
'c_chargesociales';
75 public $accountancy_code;
80 public $errors = array();
123 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
125 $sql .=
'deductible,';
130 $sql .=
'accountancy_code';
131 $sql .=
') VALUES (';
132 $sql .=
' '.(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
',';
133 $sql .=
' '.(!isset($this->deductible) ?
'NULL' : $this->deductible).
',';
134 $sql .=
' '.(!isset($this->active) ?
'NULL' : $this->active).
',';
135 $sql .=
' '.(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
',';
136 $sql .=
' '.(!isset($this->fk_pays) ?
'NULL' : $this->fk_pays).
',';
137 $sql .=
' '.(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'").
',';
138 $sql .=
' '.(!isset($this->accountancy_code) ?
'NULL' :
"'".$this->db->escape($this->accountancy_code).
"'");
143 $resql = $this->db->query($sql);
146 $this->errors[] =
'Error '.$this->db->lasterror();
147 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
151 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
166 $this->db->rollback();
184 public function fetch($id, $ref =
null)
190 $sql .=
" t.libelle as label,";
191 $sql .=
" t.deductible,";
192 $sql .=
" t.active,";
194 $sql .=
" t.fk_pays,";
195 $sql .=
" t.module,";
196 $sql .=
" t.accountancy_code";
197 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
199 $sql .=
" WHERE t.code = '".$this->db->escape($ref).
"'";
201 $sql .=
' WHERE t.id = '.((int) $id);
204 $resql = $this->db->query($sql);
206 $numrows = $this->db->num_rows($resql);
208 $obj = $this->db->fetch_object($resql);
210 $this->
id = $obj->id;
212 $this->libelle = $obj->label;
213 $this->label = $obj->label;
214 $this->deductible = $obj->deductible;
215 $this->active = $obj->active;
216 $this->code = $obj->code;
217 $this->fk_pays = $obj->fk_pays;
218 $this->module = $obj->module;
219 $this->accountancy_code = $obj->accountancy_code;
221 $this->db->free($resql);
229 $this->errors[] =
'Error '.$this->db->lasterror();
230 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
269 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
270 $sql .=
' libelle = '.(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
',';
271 $sql .=
' deductible = '.(isset($this->deductible) ? ((int) $this->deductible) :
"null").
',';
272 $sql .=
' active = '.(isset($this->active) ? ((int) $this->active) :
"null").
',';
273 $sql .=
' code = '.(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
',';
274 $sql .=
' fk_pays = '.((isset($this->fk_pays) && $this->fk_pays > 0) ? ((
int) $this->fk_pays) :
"null").
',';
275 $sql .=
' module = '.(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null").
',';
276 $sql .=
' accountancy_code = '.(isset($this->accountancy_code) ?
"'".$this->db->escape($this->accountancy_code).
"'" :
"null");
277 $sql .=
' WHERE id='.((int) $this->
id);
281 $resql = $this->db->query($sql);
284 $this->errors[] =
'Error '.$this->db->lasterror();
285 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
300 $this->db->rollback();
318 public function delete(
User $user, $notrigger =
false)
339 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
340 $sql .=
' WHERE id = '.((int) $this->
id);
342 $resql = $this->db->query($sql);
345 $this->errors[] =
'Error '.$this->db->lasterror();
346 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
352 $this->db->rollback();
477 return $langs->trans(
'Enabled');
478 } elseif ($status == 0) {
479 return $langs->trans(
'Disabled');
481 } elseif ($mode == 1) {
483 return $langs->trans(
'Enabled');
484 } elseif ($status == 0) {
485 return $langs->trans(
'Disabled');
487 } elseif ($mode == 2) {
489 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
490 } elseif ($status == 0) {
491 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
493 } elseif ($mode == 3) {
495 return img_picto($langs->trans(
'Enabled'),
'statut4');
496 } elseif ($status == 0) {
497 return img_picto($langs->trans(
'Disabled'),
'statut5');
499 } elseif ($mode == 4) {
501 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
502 } elseif ($status == 0) {
503 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
505 } elseif ($mode == 5) {
507 return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
508 } elseif ($status == 0) {
509 return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
528 $this->deductible =
'';
533 $this->accountancy_code =
'';
544 foreach ($parameters as $parameter) {
545 if (isset($this->$parameter)) {
546 $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.
LibStatut($status, $mode=0)
Load an object from its id and create a new one in database.
trimParameters($parameters)
Trim object parameters.
update(User $user, $notrigger=false)
Update object into database.
__construct(DoliDB $db)
Constructor.
create(User $user, $notrigger=false)
Create object into database.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $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.