28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'chargesociales';
42 public $table =
'chargesociales';
47 public $table_element =
'chargesociales';
52 public $picto =
'bill';
69 public $type_accountancy_code;
99 public $mode_reglement_id;
100 public $mode_reglement_code;
101 public $mode_reglement;
121 const STATUS_UNPAID = 0;
122 const STATUS_PAID = 1;
142 public function fetch($id, $ref =
'')
144 $sql =
"SELECT cs.rowid, cs.date_ech";
145 $sql .=
", cs.libelle as label, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode as period, cs.import_key";
146 $sql .=
", cs.fk_account, cs.fk_mode_reglement, cs.fk_user, note_public, note_private";
147 $sql .=
", c.libelle as type_label, c.code as type_code, c.accountancy_code as type_accountancy_code";
148 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
149 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as cs";
150 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_chargesociales as c ON cs.fk_type = c.id";
151 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON cs.fk_mode_reglement = p.id';
152 $sql .=
' WHERE cs.entity IN ('.getEntity(
'tax').
')';
154 $sql .=
" AND cs.ref = '".$this->db->escape($ref).
"'";
156 $sql .=
" AND cs.rowid = ".((int) $id);
159 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
160 $resql = $this->db->query($sql);
162 if ($this->db->num_rows($resql)) {
163 $obj = $this->db->fetch_object($resql);
165 $this->
id = $obj->rowid;
166 $this->
ref = $obj->rowid;
167 $this->date_ech = $this->db->jdate($obj->date_ech);
168 $this->lib = $obj->label;
169 $this->label = $obj->label;
170 $this->
type = $obj->fk_type;
171 $this->type_label = $obj->type_label;
172 $this->type_code = $obj->type_code;
173 $this->type_accountancy_code = $obj->type_accountancy_code;
174 $this->fk_account = $obj->fk_account;
175 $this->mode_reglement_id = $obj->fk_mode_reglement;
176 $this->mode_reglement_code = $obj->mode_reglement_code;
177 $this->mode_reglement = $obj->mode_reglement_libelle;
178 $this->amount = $obj->amount;
179 $this->fk_project = $obj->fk_project;
180 $this->fk_user = $obj->fk_user;
181 $this->note_public = $obj->note_public;
182 $this->note_private = $obj->note_private;
183 $this->paye = $obj->paye;
184 $this->periode = $this->db->jdate($obj->period);
185 $this->period = $this->db->jdate($obj->period);
186 $this->import_key = $obj->import_key;
188 $this->db->free($resql);
195 $this->error = $this->db->lasterror();
207 $newamount =
price2num($this->amount,
'MT');
210 if ($newamount == 0 || empty($this->date_ech) || (empty($this->period) && empty($this->periode))) {
231 $newamount =
price2num($this->amount,
'MT');
233 if (!$this->
check()) {
234 $this->error =
"ErrorBadParameter";
240 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, fk_projet, entity, fk_user_author, fk_user, date_creation)";
241 $sql .=
" VALUES (".((int) $this->
type);
242 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
243 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"NULL");
244 $sql .=
", '".$this->db->escape($this->label ? $this->label :
$this->lib).
"'";
245 $sql .=
", '".$this->db->idate($this->date_ech).
"'";
246 $sql .=
", '".$this->db->idate($this->periode).
"'";
247 $sql .=
", '".price2num($newamount).
"'";
248 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
'NULL');
249 $sql .=
", ".((int) $conf->entity);
250 $sql .=
", ".((int) $user->id);
251 $sql .=
", ".($this->fk_user > 0 ? ((int) $this->fk_user) :
'NULL');
252 $sql .=
", '".$this->db->idate($now).
"'";
255 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
256 $resql = $this->db->query($sql);
258 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"chargesociales");
261 $result = $this->
call_trigger(
'SOCIALCONTRIBUTION_CREATE', $user);
270 $this->db->rollback();
274 $this->error = $this->db->error();
275 $this->db->rollback();
287 public function delete($user)
294 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
295 $account =
new Account($this->db);
296 $lines_url = $account->get_url(
'', $this->
id,
'sc');
299 foreach ($lines_url as $line_url) {
302 $accountline->fetch($line_url[
'fk_bank']);
303 $result = $accountline->delete_urls($user);
312 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge WHERE fk_charge=".((int) $this->
id);
313 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
314 $resql = $this->db->query($sql);
317 $this->error = $this->db->lasterror();
322 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"chargesociales WHERE rowid=".((int) $this->
id);
323 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
324 $resql = $this->db->query($sql);
327 $this->error = $this->db->lasterror();
335 $this->db->rollback();
348 public function update($user, $notrigger = 0)
353 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales";
354 $sql .=
" SET libelle='".$this->db->escape($this->label ? $this->label :
$this->lib).
"'";
355 $sql .=
", date_ech='".$this->db->idate($this->date_ech).
"'";
356 $sql .=
", periode='".$this->db->idate($this->periode).
"'";
357 $sql .=
", amount='".price2num($this->amount,
'MT').
"'";
358 $sql .=
", fk_projet=".($this->fk_project > 0 ? $this->db->escape($this->fk_project) :
"NULL");
359 $sql .=
", fk_user=".($this->fk_user > 0 ? $this->db->escape($this->fk_user) :
"NULL");
360 $sql .=
", fk_user_modif=".$user->id;
361 $sql .=
" WHERE rowid=".((int) $this->
id);
363 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
364 $resql = $this->db->query($sql);
368 $this->errors[] =
"Error ".$this->db->lasterror();
374 $result = $this->
call_trigger(
'SOCIALCONTRIBUTION_MODIFY', $user);
384 foreach ($this->errors as $errmsg) {
385 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
386 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
388 $this->db->rollback();
406 $sql =
"SELECT SUM(f.amount) as amount";
407 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as f";
408 $sql .=
" WHERE f.entity = ".$conf->entity;
409 $sql .=
" AND paye = 0";
412 $sql .=
" AND f.datev >= '".((int) $year).
"-01-01' AND f.datev <= '".((int) $year).
"-12-31' ";
415 $result = $this->db->query($sql);
417 if ($this->db->num_rows($result)) {
418 $obj = $this->db->fetch_object($result);
419 $this->db->free($result);
425 print $this->db->error();
442 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
454 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
456 $sql .=
" WHERE rowid = ".((int) $this->
id);
458 $return = $this->db->query($sql);
481 dol_syslog(get_class($this).
"::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE);
493 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
495 $sql .=
" WHERE rowid = ".((int) $this->
id);
497 $return = $this->db->query($sql);
517 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
529 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
535 $langs->loadLangs(array(
"customers",
"bills"));
538 $this->labelStatus = array();
539 $this->labelStatusShort = array();
541 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
544 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'Unpaid');
545 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'Paid');
546 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) {
547 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
549 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'Unpaid');
550 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'Paid');
551 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) {
552 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
556 $statusType =
'status1';
557 if ($status == 0 && $alreadypaid > 0) {
558 $statusType =
'status3';
561 $statusType =
'status6';
564 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
578 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $short = 0, $save_lastsearch_value = -1)
580 global $langs, $conf, $user, $hookmanager;
582 if (!empty($conf->dol_no_mouse_hover)) {
588 $url = DOL_URL_ROOT.
'/compta/sociales/card.php?id='.$this->id;
594 if ($option !==
'nolink') {
596 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
597 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
598 $add_save_lastsearch_values = 1;
600 if ($add_save_lastsearch_values) {
601 $url .=
'&save_lastsearch_values=1';
605 if (empty($this->
ref)) {
606 $this->
ref = $this->label;
609 $label =
img_picto(
'', $this->picto,
'class="pictofixedwidth"').
'<u class="paddingrightonly">'.$langs->trans(
"SocialContribution").
'</u>';
610 if (isset($this->paye)) {
611 $label .=
' '.$this->getLibStatut(5);
613 if (!empty($this->
ref)) {
614 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
616 if (!empty($this->label)) {
617 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
619 if (!empty($this->type_label)) {
620 $label .=
'<br><b>'.$langs->trans(
'Type').
':</b> '.$this->type_label;
621 if (!empty($this->type_accountancy_code)) {
622 $label .=
' <span class="opacitymedium">('.$langs->trans(
'AccountancyCode').
': '.$this->type_accountancy_code.
')</span>';
627 if (empty($notooltip) && $user->hasRight(
"facture",
"read")) {
629 $label = $langs->trans(
"SocialContribution");
630 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
632 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
633 $linkclose .=
' class="classfortooltip"';
636 $linkstart =
'<a href="'.$url.
'"';
637 $linkstart .= $linkclose.
'>';
640 $result .= $linkstart;
642 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
644 if ($withpicto != 2) {
645 $result .= $this->ref;
650 $hookmanager->initHooks(array($this->element .
'dao'));
651 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
652 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
654 $result = $hookmanager->resPrint;
656 $result .= $hookmanager->resPrint;
669 $table =
'paiementcharge';
670 $field =
'fk_charge';
672 $sql =
'SELECT sum(amount) as amount';
673 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
674 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
676 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
677 $resql = $this->db->query($sql);
681 $obj = $this->db->fetch_object($resql);
683 $amount = $obj->amount ? $obj->amount : 0;
686 $this->db->free($resql);
701 $sql =
"SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,";
702 $sql .=
" e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
703 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as e";
704 $sql .=
" WHERE e.rowid = ".((int) $id);
706 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
707 $result = $this->db->query($sql);
709 if ($this->db->num_rows($result)) {
710 $obj = $this->db->fetch_object($result);
712 $this->
id = $obj->rowid;
714 $this->user_creation_id = $obj->fk_user_author;
715 $this->user_modification_id = $obj->fk_user_modif;
716 $this->user_validation_id = $obj->fk_user_valid;
717 $this->date_creation = $this->db->jdate($obj->datec);
718 $this->date_modification = $this->db->jdate($obj->datem);
719 $this->date_validation = $this->db->jdate($obj->datev);
720 $this->import_key = $obj->import_key;
723 $this->db->free($result);
742 $this->
ref =
'SPECIMEN';
745 $this->date_creation =
dol_now();
746 $this->date_ech = $this->date_creation + 3600 * 24 * 30;
747 $this->periode = $this->date_creation + 3600 * 24 * 30;
748 $this->period = $this->date_creation + 3600 * 24 * 30;
750 $this->label =
'Social contribution label';
752 $this->type_label =
'Type of social contribution';
766 global $conf, $langs;
768 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
770 $return =
'<div class="box-flex-item box-flex-grow-zero">';
771 $return .=
'<div class="info-box info-box-sm">';
772 $return .=
'<span class="info-box-icon bg-infobox-action">';
774 $return .=
'</span>';
775 $return .=
'<div class="info-box-content">';
776 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0) : $this->ref).
'</span>';
777 if ($selected >= 0) {
778 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
780 if (property_exists($this,
'label')) {
781 $return .=
' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.
'</div>';
783 if (!empty($arraydata[
'project']) && $arraydata[
'project']->
id > 0) {
784 $return .=
'<br><span class="info-box-label">'.$arraydata[
'project']->getNomUrl(1).
'</span>';
786 if (property_exists($this,
'date_ech')) {
787 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label">'.
dol_print_date($this->date_ech,
'day').
'</span>';
789 if (property_exists($this,
'amount')) {
791 $return .=
'<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).
'</span>';
793 if (method_exists($this,
'LibStatut')) {
794 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3, $this->alreadypaid).
'</div>';
Class to manage bank accounts.
Class to manage bank transaction lines.
Class for managing the social charges.
LibStatut($status, $mode=0, $alreadypaid=-1)
Renvoi le libelle d'un statut donne.
__construct(DoliDB $db)
Constructor.
setUnpaid($user)
Remove tag paid on social contribution.
initAsSpecimen()
Initialise an instance with random values.
check()
Check if a social contribution can be created into database.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
getSommePaiement()
Return amount of payments already done.
solde($year=0)
Calculate amount remaining to pay by year.
fetch($id, $ref='')
Retrouve et charge une charge sociale.
update($user, $notrigger=0)
Update social or fiscal contribution.
set_unpaid($user)
Remove tag paid on social contribution.
set_paid($user)
Tag social contribution as paid completely.
getNomUrl($withpicto=0, $option='', $notooltip=0, $short=0, $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
info($id)
Charge l'information d'ordre info dans l'objet entrepot.
create($user)
Create a social contribution into database.
getLibStatut($mode=0, $alreadypaid=-1)
Retourne le libelle du statut d'une charge (impaye, payee)
setPaid($user)
Tag social contribution as paid completely.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type