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';
80 public $date_creation;
85 public $date_modification;
90 public $date_validation;
110 public $paiementtype;
112 public $mode_reglement_id;
113 public $mode_reglement_code;
114 public $mode_reglement;
134 const STATUS_UNPAID = 0;
135 const STATUS_PAID = 1;
155 public function fetch($id, $ref =
'')
157 $sql =
"SELECT cs.rowid, cs.date_ech";
158 $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";
159 $sql .=
", cs.fk_account, cs.fk_mode_reglement, cs.fk_user, note_public, note_private";
160 $sql .=
", c.libelle as type_label";
161 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
162 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as cs";
163 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_chargesociales as c ON cs.fk_type = c.id";
164 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON cs.fk_mode_reglement = p.id';
165 $sql .=
' WHERE cs.entity IN ('.getEntity(
'tax').
')';
167 $sql .=
" AND cs.ref = '".$this->db->escape($ref).
"'";
169 $sql .=
" AND cs.rowid = ".((int) $id);
172 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
173 $resql = $this->db->query($sql);
175 if ($this->db->num_rows($resql)) {
176 $obj = $this->db->fetch_object($resql);
178 $this->
id = $obj->rowid;
179 $this->
ref = $obj->rowid;
180 $this->date_ech = $this->db->jdate($obj->date_ech);
181 $this->lib = $obj->label;
182 $this->label = $obj->label;
183 $this->
type = $obj->fk_type;
184 $this->type_label = $obj->type_label;
185 $this->fk_account = $obj->fk_account;
186 $this->mode_reglement_id = $obj->fk_mode_reglement;
187 $this->mode_reglement_code = $obj->mode_reglement_code;
188 $this->mode_reglement = $obj->mode_reglement_libelle;
189 $this->amount = $obj->amount;
190 $this->fk_project = $obj->fk_project;
191 $this->fk_user = $obj->fk_user;
192 $this->note_public = $obj->note_public;
193 $this->note_private = $obj->note_private;
194 $this->paye = $obj->paye;
195 $this->periode = $this->db->jdate($obj->period);
196 $this->period = $this->db->jdate($obj->period);
197 $this->import_key = $obj->import_key;
199 $this->db->free($resql);
206 $this->error = $this->db->lasterror();
218 $newamount =
price2num($this->amount,
'MT');
221 if ($newamount == 0 || empty($this->date_ech) || (empty($this->period) && empty($this->periode))) {
242 $newamount =
price2num($this->amount,
'MT');
244 if (!$this->
check()) {
245 $this->error =
"ErrorBadParameter";
251 $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)";
252 $sql .=
" VALUES (".((int) $this->
type);
253 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
254 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"NULL");
255 $sql .=
", '".$this->db->escape($this->label ? $this->label :
$this->lib).
"'";
256 $sql .=
", '".$this->db->idate($this->date_ech).
"'";
257 $sql .=
", '".$this->db->idate($this->periode).
"'";
258 $sql .=
", '".price2num($newamount).
"'";
259 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
'NULL');
260 $sql .=
", ".((int) $conf->entity);
261 $sql .=
", ".((int) $user->id);
262 $sql .=
", ".($this->fk_user > 0 ? ((int) $this->fk_user) :
'NULL');
263 $sql .=
", '".$this->db->idate($now).
"'";
266 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
267 $resql = $this->db->query($sql);
269 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"chargesociales");
272 $result = $this->
call_trigger(
'SOCIALCONTRIBUTION_CREATE', $user);
281 $this->db->rollback();
285 $this->error = $this->db->error();
286 $this->db->rollback();
298 public function delete($user)
305 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
306 $account =
new Account($this->db);
307 $lines_url = $account->get_url(
'', $this->
id,
'sc');
310 foreach ($lines_url as $line_url) {
313 $accountline->fetch($line_url[
'fk_bank']);
314 $result = $accountline->delete_urls($user);
323 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge WHERE fk_charge=".((int) $this->
id);
324 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
325 $resql = $this->db->query($sql);
328 $this->error = $this->db->lasterror();
333 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"chargesociales WHERE rowid=".((int) $this->
id);
334 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
335 $resql = $this->db->query($sql);
338 $this->error = $this->db->lasterror();
346 $this->db->rollback();
359 public function update($user, $notrigger = 0)
364 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales";
365 $sql .=
" SET libelle='".$this->db->escape($this->label ? $this->label :
$this->lib).
"'";
366 $sql .=
", date_ech='".$this->db->idate($this->date_ech).
"'";
367 $sql .=
", periode='".$this->db->idate($this->periode).
"'";
368 $sql .=
", amount='".price2num($this->amount,
'MT').
"'";
369 $sql .=
", fk_projet=".($this->fk_project > 0 ? $this->db->escape($this->fk_project) :
"NULL");
370 $sql .=
", fk_user=".($this->fk_user > 0 ? $this->db->escape($this->fk_user) :
"NULL");
371 $sql .=
", fk_user_modif=".$user->id;
372 $sql .=
" WHERE rowid=".((int) $this->
id);
374 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
375 $resql = $this->db->query($sql);
379 $this->errors[] =
"Error ".$this->db->lasterror();
385 $result = $this->
call_trigger(
'SOCIALCONTRIBUTION_MODIFY', $user);
395 foreach ($this->errors as $errmsg) {
396 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
397 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
399 $this->db->rollback();
417 $sql =
"SELECT SUM(f.amount) as amount";
418 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as f";
419 $sql .=
" WHERE f.entity = ".$conf->entity;
420 $sql .=
" AND paye = 0";
423 $sql .=
" AND f.datev >= '".((int) $year).
"-01-01' AND f.datev <= '".((int) $year).
"-12-31' ";
426 $result = $this->db->query($sql);
428 if ($this->db->num_rows($result)) {
429 $obj = $this->db->fetch_object($result);
430 $this->db->free($result);
436 print $this->db->error();
453 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
465 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
467 $sql .=
" WHERE rowid = ".((int) $this->
id);
469 $return = $this->db->query($sql);
492 dol_syslog(get_class($this).
"::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE);
504 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
506 $sql .=
" WHERE rowid = ".((int) $this->
id);
508 $return = $this->db->query($sql);
528 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
540 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
546 $langs->loadLangs(array(
"customers",
"bills"));
549 $this->labelStatus = array();
550 $this->labelStatusShort = array();
552 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
555 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'Unpaid');
556 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'Paid');
557 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) {
558 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
560 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'Unpaid');
561 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'Paid');
562 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) {
563 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
567 $statusType =
'status1';
568 if ($status == 0 && $alreadypaid > 0) {
569 $statusType =
'status3';
572 $statusType =
'status6';
575 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
589 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $short = 0, $save_lastsearch_value = -1)
591 global $langs, $conf, $user, $form, $hookmanager;
593 if (!empty($conf->dol_no_mouse_hover)) {
599 $url = DOL_URL_ROOT.
'/compta/sociales/card.php?id='.$this->id;
605 if ($option !==
'nolink') {
607 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
608 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
609 $add_save_lastsearch_values = 1;
611 if ($add_save_lastsearch_values) {
612 $url .=
'&save_lastsearch_values=1';
616 if (empty($this->
ref)) {
617 $this->
ref = $this->label;
620 $label =
img_picto(
'', $this->picto,
'class="pictofixedwidth"').
'<u class="paddingrightonly">'.$langs->trans(
"SocialContribution").
'</u>';
621 if (isset($this->paye)) {
622 $label .=
' '.$this->getLibStatut(5);
624 if (!empty($this->
ref)) {
625 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
627 if (!empty($this->label)) {
628 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
630 if (!empty($this->type_label)) {
631 $label .=
'<br><b>'.$langs->trans(
'Type').
':</b> '.$this->type_label;
635 if (empty($notooltip) && $user->hasRight(
"facture",
"read")) {
637 $label = $langs->trans(
"SocialContribution");
638 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
640 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
641 $linkclose .=
' class="classfortooltip"';
644 $linkstart =
'<a href="'.$url.
'"';
645 $linkstart .= $linkclose.
'>';
648 $result .= $linkstart;
650 $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);
652 if ($withpicto != 2) {
653 $result .= $this->ref;
657 $hookmanager->initHooks(array($this->element .
'dao'));
658 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
659 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
661 $result = $hookmanager->resPrint;
663 $result .= $hookmanager->resPrint;
675 $table =
'paiementcharge';
676 $field =
'fk_charge';
678 $sql =
'SELECT sum(amount) as amount';
679 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
680 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
682 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
683 $resql = $this->db->query($sql);
687 $obj = $this->db->fetch_object($resql);
689 $amount = $obj->amount ? $obj->amount : 0;
692 $this->db->free($resql);
707 $sql =
"SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,";
708 $sql .=
" e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
709 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as e";
710 $sql .=
" WHERE e.rowid = ".((int) $id);
712 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
713 $result = $this->db->query($sql);
715 if ($this->db->num_rows($result)) {
716 $obj = $this->db->fetch_object($result);
718 $this->
id = $obj->rowid;
720 $this->user_creation_id = $obj->fk_user_author;
721 $this->user_modification_id = $obj->fk_user_modif;
722 $this->user_validation_id = $obj->fk_user_valid;
723 $this->date_creation = $this->db->jdate($obj->datec);
724 $this->date_modification = $this->db->jdate($obj->datem);
725 $this->date_validation = $this->db->jdate($obj->datev);
726 $this->import_key = $obj->import_key;
729 $this->db->free($result);
748 $this->
ref =
'SPECIMEN';
751 $this->date_creation =
dol_now();
752 $this->date_ech = $this->date_creation + 3600 * 24 * 30;
753 $this->periode = $this->date_creation + 3600 * 24 * 30;
754 $this->period = $this->date_creation + 3600 * 24 * 30;
756 $this->label =
'Social contribution label';
758 $this->type_label =
'Type of social contribution';
772 global $conf, $langs;
774 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
776 $return =
'<div class="box-flex-item box-flex-grow-zero">';
777 $return .=
'<div class="info-box info-box-sm">';
778 $return .=
'<span class="info-box-icon bg-infobox-action">';
780 $return .=
'</span>';
781 $return .=
'<div class="info-box-content">';
782 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0) : $this->ref).
'</span>';
783 if ($selected >= 0) {
784 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
786 if (property_exists($this,
'label')) {
787 $return .=
' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.
'</div>';
789 if (!empty($arraydata[
'project']) && $arraydata[
'project']->
id > 0) {
790 $return .=
'<br><span class="info-box-label">'.$arraydata[
'project']->getNomUrl(1).
'</span>';
792 if (property_exists($this,
'date_ech')) {
793 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label">'.
dol_print_date($this->date_ech,
'day').
'</span>';
795 if (property_exists($this,
'amount')) {
797 $return .=
'<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).
'</span>';
799 if (method_exists($this,
'LibStatut')) {
800 $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