40 public $element =
'cchargesociales';
45 public $table_element =
'c_chargesociales';
71 public $accountancy_code;
115 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
117 $sql .=
'deductible,';
122 $sql .=
'accountancy_code';
123 $sql .=
') VALUES (';
124 $sql .=
' '.(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
',';
125 $sql .=
' '.(!isset($this->deductible) ?
'NULL' : $this->deductible).
',';
126 $sql .=
' '.(!isset($this->active) ?
'NULL' : $this->active).
',';
127 $sql .=
' '.(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
',';
128 $sql .=
' '.(!isset($this->fk_pays) ?
'NULL' : $this->fk_pays).
',';
129 $sql .=
' '.(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'").
',';
130 $sql .=
' '.(!isset($this->accountancy_code) ?
'NULL' :
"'".$this->db->escape($this->accountancy_code).
"'");
135 $resql = $this->db->query($sql);
138 $this->errors[] =
'Error '.$this->db->lasterror();
139 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
143 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
158 $this->db->rollback();
176 public function fetch($id, $ref =
null)
182 $sql .=
" t.libelle as label,";
183 $sql .=
" t.deductible,";
184 $sql .=
" t.active,";
186 $sql .=
" t.fk_pays,";
187 $sql .=
" t.module,";
188 $sql .=
" t.accountancy_code";
189 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
191 $sql .=
" WHERE t.code = '".$this->db->escape($ref).
"'";
193 $sql .=
' WHERE t.id = '.((int) $id);
196 $resql = $this->db->query($sql);
198 $numrows = $this->db->num_rows($resql);
200 $obj = $this->db->fetch_object($resql);
202 $this->
id = $obj->id;
204 $this->libelle = $obj->label;
205 $this->label = $obj->label;
206 $this->deductible = $obj->deductible;
207 $this->active = $obj->active;
208 $this->code = $obj->code;
209 $this->fk_pays = $obj->fk_pays;
210 $this->module = $obj->module;
211 $this->accountancy_code = $obj->accountancy_code;
213 $this->db->free($resql);
221 $this->errors[] =
'Error '.$this->db->lasterror();
222 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
261 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
262 $sql .=
' libelle = '.(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
',';
263 $sql .=
' deductible = '.(isset($this->deductible) ? ((int) $this->deductible) :
"null").
',';
264 $sql .=
' active = '.(isset($this->active) ? ((int) $this->active) :
"null").
',';
265 $sql .=
' code = '.(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
',';
266 $sql .=
' fk_pays = '.((isset($this->fk_pays) && $this->fk_pays > 0) ? ((
int) $this->fk_pays) :
"null").
',';
267 $sql .=
' module = '.(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null").
',';
268 $sql .=
' accountancy_code = '.(isset($this->accountancy_code) ?
"'".$this->db->escape($this->accountancy_code).
"'" :
"null");
269 $sql .=
' WHERE id='.((int) $this->
id);
273 $resql = $this->db->query($sql);
276 $this->errors[] =
'Error '.$this->db->lasterror();
277 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
292 $this->db->rollback();
310 public function delete(
User $user, $notrigger =
false)
331 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
332 $sql .=
' WHERE id = '.((int) $this->
id);
334 $resql = $this->db->query($sql);
337 $this->errors[] =
'Error '.$this->db->lasterror();
338 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
344 $this->db->rollback();
371 $object->fetch($fromid);
379 $this->context[
'createfromclone'] =
'createfromclone';
380 $result = $object->create($user);
385 $this->errors = $object->errors;
386 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
389 unset($this->context[
'createfromclone']);
397 $this->db->rollback();
414 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
416 global $langs, $conf, $db;
417 global $dolibarr_main_authentication, $dolibarr_main_demo;
424 $label =
'<u>'.$langs->trans(
"MyModule").
'</u>';
425 $label .=
'<div width="100%">';
426 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
428 $link =
'<a href="'.DOL_URL_ROOT.
'/tax/card.php?id='.$this->
id.
'"';
429 $link .= ($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
434 $result .= ($link.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
435 if ($withpicto != 2) {
439 $result .= $link.$this->ref.$linkend;
451 return $this->
LibStatut($this->status, $mode);
469 return $langs->trans(
'Enabled');
470 } elseif ($status == 0) {
471 return $langs->trans(
'Disabled');
473 } elseif ($mode == 1) {
475 return $langs->trans(
'Enabled');
476 } elseif ($status == 0) {
477 return $langs->trans(
'Disabled');
479 } elseif ($mode == 2) {
481 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
482 } elseif ($status == 0) {
483 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
485 } elseif ($mode == 3) {
487 return img_picto($langs->trans(
'Enabled'),
'statut4');
488 } elseif ($status == 0) {
489 return img_picto($langs->trans(
'Disabled'),
'statut5');
491 } elseif ($mode == 4) {
493 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
494 } elseif ($status == 0) {
495 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
497 } elseif ($mode == 5) {
499 return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
500 } elseif ($status == 0) {
501 return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
520 $this->deductible =
'';
525 $this->accountancy_code =
'';
536 foreach ($parameters as $parameter) {
537 if (isset($this->$parameter)) {
538 $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.
getLibStatut($mode=0)
Return the label of the status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link to the user card (with optionaly the picto) Use this->id,this->lastname,...
LibStatut($status, $mode=0)
Return the label of a given status.
createFromClone(User $user, $fromid)
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.