28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'chargesociales';
47 public $table =
'chargesociales';
52 public $table_element =
'chargesociales';
57 public $picto =
'bill';
92 public $type_accountancy_code;
134 public $paiementtype;
139 public $mode_reglement_id;
144 public $mode_reglement_code;
149 public $mode_reglement;
174 const STATUS_UNPAID = 0;
179 const STATUS_PAID = 1;
199 public function fetch($id, $ref =
'')
201 $sql =
"SELECT cs.rowid, cs.date_ech";
202 $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";
203 $sql .=
", cs.fk_account, cs.fk_mode_reglement, cs.fk_user, note_public, note_private";
204 $sql .=
", c.libelle as type_label, c.code as type_code, c.accountancy_code as type_accountancy_code";
205 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
206 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as cs";
207 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_chargesociales as c ON cs.fk_type = c.id";
208 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON cs.fk_mode_reglement = p.id';
209 $sql .=
' WHERE cs.entity IN ('.getEntity(
'tax').
')';
211 $sql .=
" AND cs.ref = '".$this->db->escape($ref).
"'";
213 $sql .=
" AND cs.rowid = ".((int) $id);
216 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
217 $resql = $this->db->query($sql);
219 if ($this->db->num_rows($resql)) {
220 $obj = $this->db->fetch_object($resql);
222 $this->
id = $obj->rowid;
223 $this->
ref = $obj->rowid;
224 $this->date_ech = $this->db->jdate($obj->date_ech);
225 $this->lib = $obj->label;
226 $this->label = $obj->label;
227 $this->
type = $obj->fk_type;
228 $this->type_label = $obj->type_label;
229 $this->type_code = $obj->type_code;
230 $this->type_accountancy_code = $obj->type_accountancy_code;
231 $this->fk_account = $obj->fk_account;
232 $this->mode_reglement_id = $obj->fk_mode_reglement;
233 $this->mode_reglement_code = $obj->mode_reglement_code;
234 $this->mode_reglement = $obj->mode_reglement_libelle;
235 $this->amount = $obj->amount;
236 $this->fk_project = $obj->fk_project;
237 $this->fk_user = $obj->fk_user;
238 $this->note_public = $obj->note_public;
239 $this->note_private = $obj->note_private;
240 $this->paye = $obj->paye;
241 $this->periode = $this->db->jdate($obj->period);
242 $this->period = $this->db->jdate($obj->period);
243 $this->import_key = $obj->import_key;
245 $this->db->free($resql);
252 $this->error = $this->db->lasterror();
264 $newamount =
price2num($this->amount,
'MT');
267 if ($newamount == 0 || empty($this->date_ech) || (empty($this->period) && empty($this->periode))) {
288 $newamount =
price2num($this->amount,
'MT');
290 if (!$this->
check()) {
291 $this->error =
"ErrorBadParameter";
297 $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)";
298 $sql .=
" VALUES (".((int) $this->
type);
299 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
300 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"NULL");
301 $sql .=
", '".$this->db->escape($this->label ? $this->label : $this->lib).
"'";
302 $sql .=
", '".$this->db->idate($this->date_ech).
"'";
303 $sql .=
", '".$this->db->idate($this->periode).
"'";
304 $sql .=
", '".price2num($newamount).
"'";
305 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
'NULL');
306 $sql .=
", ".((int) $conf->entity);
307 $sql .=
", ".((int) $user->id);
308 $sql .=
", ".($this->fk_user > 0 ? ((int) $this->fk_user) :
'NULL');
309 $sql .=
", '".$this->db->idate($now).
"'";
312 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
313 $resql = $this->db->query($sql);
315 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"chargesociales");
318 $result = $this->
call_trigger(
'SOCIALCONTRIBUTION_CREATE', $user);
327 $this->db->rollback();
331 $this->error = $this->db->error();
332 $this->db->rollback();
344 public function delete($user)
351 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
352 $account =
new Account($this->db);
353 $lines_url = $account->get_url(0, $this->
id,
'sc');
356 foreach ($lines_url as $line_url) {
359 $accountline->fetch($line_url[
'fk_bank']);
360 $result = $accountline->delete_urls($user);
369 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge WHERE fk_charge=".((int) $this->
id);
370 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
371 $resql = $this->db->query($sql);
374 $this->error = $this->db->lasterror();
379 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"chargesociales WHERE rowid=".((int) $this->
id);
380 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
381 $resql = $this->db->query($sql);
384 $this->error = $this->db->lasterror();
392 $this->db->rollback();
405 public function update($user, $notrigger = 0)
410 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales";
411 $sql .=
" SET libelle = '".$this->db->escape($this->label ? $this->label : $this->lib).
"'";
412 $sql .=
", date_ech = '".$this->db->idate($this->date_ech).
"'";
413 $sql .=
", periode = '".$this->db->idate($this->period ? $this->period : $this->periode).
"'";
414 $sql .=
", amount = ".((float)
price2num($this->amount,
'MT'));
415 $sql .=
", fk_projet=".($this->fk_project > 0 ? ((int) $this->fk_project) :
"NULL");
416 $sql .=
", fk_user=".($this->fk_user > 0 ? ((int) $this->fk_user) :
"NULL");
417 $sql .=
", fk_user_modif=".((int) $user->id);
418 if ($this->
type > 0) {
419 $sql .=
", fk_type = ".((int) $this->
type);
421 $sql .=
", fk_user_modif=".((int) $user->id);
422 $sql .=
" WHERE rowid=".((int) $this->
id);
424 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
425 $resql = $this->db->query($sql);
429 $this->errors[] =
"Error ".$this->db->lasterror();
435 $result = $this->
call_trigger(
'SOCIALCONTRIBUTION_MODIFY', $user);
445 foreach ($this->errors as $errmsg) {
446 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
447 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
449 $this->db->rollback();
467 $sql =
"SELECT SUM(f.amount) as amount";
468 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as f";
469 $sql .=
" WHERE f.entity = ".((int) $conf->entity);
470 $sql .=
" AND paye = 0";
473 $sql .=
" AND f.datev >= '".((int) $year).
"-01-01' AND f.datev <= '".((int) $year).
"-12-31' ";
476 $result = $this->db->query($sql);
478 if ($this->db->num_rows($result)) {
479 $obj = $this->db->fetch_object($result);
480 $this->db->free($result);
486 print $this->db->error();
503 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
515 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
517 $sql .=
" WHERE rowid = ".((int) $this->
id);
519 $return = $this->db->query($sql);
542 dol_syslog(get_class($this).
"::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE);
554 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
556 $sql .=
" WHERE rowid = ".((int) $this->
id);
558 $return = $this->db->query($sql);
578 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
590 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
596 $langs->loadLangs(array(
"customers",
"bills"));
599 $this->labelStatus = array();
600 $this->labelStatusShort = array();
602 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
605 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'Unpaid');
606 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'Paid');
607 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) {
608 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
610 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'Unpaid');
611 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'Paid');
612 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) {
613 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
617 $statusType =
'status1';
618 if ($status == 0 && $alreadypaid > 0) {
619 $statusType =
'status3';
622 $statusType =
'status6';
625 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
639 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $short = 0, $save_lastsearch_value = -1)
641 global $langs, $conf, $user, $hookmanager;
643 if (!empty($conf->dol_no_mouse_hover)) {
649 $url = DOL_URL_ROOT.
'/compta/sociales/card.php?id='.$this->id;
655 if ($option !==
'nolink') {
657 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
658 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
659 $add_save_lastsearch_values = 1;
661 if ($add_save_lastsearch_values) {
662 $url .=
'&save_lastsearch_values=1';
666 if (empty($this->
ref)) {
667 $this->
ref = $this->label;
670 $label =
img_picto(
'', $this->picto,
'class="pictofixedwidth"').
'<u class="paddingrightonly">'.$langs->trans(
"SocialContribution").
'</u>';
671 if (isset($this->paye)) {
672 $label .=
' '.$this->getLibStatut(5);
674 if (!empty($this->
ref)) {
675 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
677 if (!empty($this->label)) {
678 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
680 if (!empty($this->type_label)) {
681 $label .=
'<br><b>'.$langs->trans(
'Type').
':</b> '.$this->type_label;
682 if (!empty($this->type_accountancy_code)) {
683 $label .=
' <span class="opacitymedium">('.$langs->trans(
'AccountancyCode').
': '.$this->type_accountancy_code.
')</span>';
688 if (empty($notooltip) && $user->hasRight(
"facture",
"read")) {
690 $label = $langs->trans(
"SocialContribution");
691 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
693 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
694 $linkclose .=
' class="classfortooltip"';
697 $linkstart =
'<a href="'.$url.
'"';
698 $linkstart .= $linkclose.
'>';
701 $result .= $linkstart;
703 $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);
705 if ($withpicto != 2) {
706 $result .= $this->ref;
711 $hookmanager->initHooks(array($this->element .
'dao'));
712 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
713 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
715 $result = $hookmanager->resPrint;
717 $result .= $hookmanager->resPrint;
730 $table =
'paiementcharge';
731 $field =
'fk_charge';
733 $sql =
'SELECT sum(amount) as amount';
734 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
735 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
737 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
738 $resql = $this->db->query($sql);
742 $obj = $this->db->fetch_object($resql);
744 $amount = $obj->amount ? $obj->amount : 0;
747 $this->db->free($resql);
762 $sql =
"SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,";
763 $sql .=
" e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
764 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as e";
765 $sql .=
" WHERE e.rowid = ".((int) $id);
767 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
768 $result = $this->db->query($sql);
770 if ($this->db->num_rows($result)) {
771 $obj = $this->db->fetch_object($result);
773 $this->
id = $obj->rowid;
775 $this->user_creation_id = $obj->fk_user_author;
776 $this->user_modification_id = $obj->fk_user_modif;
777 $this->user_validation_id = $obj->fk_user_valid;
778 $this->date_creation = $this->db->jdate($obj->datec);
779 $this->date_modification = $this->db->jdate($obj->datem);
780 $this->date_validation = $this->db->jdate($obj->datev);
781 $this->import_key = $obj->import_key;
784 $this->db->free($result);
803 $this->
ref =
'SPECIMEN';
806 $this->date_creation =
dol_now();
807 $this->date_ech = $this->date_creation + 3600 * 24 * 30;
808 $this->periode = $this->date_creation + 3600 * 24 * 30;
809 $this->period = $this->date_creation + 3600 * 24 * 30;
811 $this->label =
'Social contribution label';
813 $this->type_label =
'Type of social contribution';
827 global $conf, $langs;
829 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
831 $return =
'<div class="box-flex-item box-flex-grow-zero">';
832 $return .=
'<div class="info-box info-box-sm">';
833 $return .=
'<span class="info-box-icon bg-infobox-action">';
835 $return .=
'</span>';
836 $return .=
'<div class="info-box-content">';
837 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0) : $this->ref).
'</span>';
838 if ($selected >= 0) {
839 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
841 if (property_exists($this,
'label')) {
842 $return .=
' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.
'</div>';
844 if (!empty($arraydata[
'project']) && $arraydata[
'project'] instanceof
Project && $arraydata[
'project']->
id > 0) {
845 $return .=
'<br><span class="info-box-label">'.$arraydata[
'project']->getNomUrl(1).
'</span>';
847 if (property_exists($this,
'date_ech')) {
848 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label">'.
dol_print_date($this->date_ech,
'day').
'</span>';
850 if (property_exists($this,
'amount')) {
852 $return .=
'<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).
'</span>';
854 if (method_exists($this,
'LibStatut')) {
855 $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 clickable 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.
Class to manage projects.
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 a 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