27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 public $element =
'chargesociales';
41 public $table =
'chargesociales';
46 public $table_element =
'chargesociales';
51 public $picto =
'bill';
78 public $date_creation;
83 public $date_modification;
88 public $date_validation;
108 public $paiementtype;
110 public $mode_reglement_id;
111 public $mode_reglement_code;
112 public $mode_reglement;
132 const STATUS_UNPAID = 0;
133 const STATUS_PAID = 1;
153 public function fetch($id, $ref =
'')
155 $sql =
"SELECT cs.rowid, cs.date_ech";
156 $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";
157 $sql .=
", cs.fk_account, cs.fk_mode_reglement, cs.fk_user, note_public, note_private";
158 $sql .=
", c.libelle as type_label";
159 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
160 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as cs";
161 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_chargesociales as c ON cs.fk_type = c.id";
162 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON cs.fk_mode_reglement = p.id';
163 $sql .=
' WHERE cs.entity IN ('.getEntity(
'tax').
')';
165 $sql .=
" AND cs.ref = '".$this->db->escape($ref).
"'";
167 $sql .=
" AND cs.rowid = ".((int) $id);
170 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
171 $resql = $this->db->query($sql);
173 if ($this->db->num_rows($resql)) {
174 $obj = $this->db->fetch_object($resql);
176 $this->
id = $obj->rowid;
177 $this->
ref = $obj->rowid;
178 $this->date_ech = $this->db->jdate($obj->date_ech);
179 $this->lib = $obj->label;
180 $this->label = $obj->label;
181 $this->
type = $obj->fk_type;
182 $this->type_label = $obj->type_label;
183 $this->fk_account = $obj->fk_account;
184 $this->mode_reglement_id = $obj->fk_mode_reglement;
185 $this->mode_reglement_code = $obj->mode_reglement_code;
186 $this->mode_reglement = $obj->mode_reglement_libelle;
187 $this->amount = $obj->amount;
188 $this->fk_project = $obj->fk_project;
189 $this->fk_user = $obj->fk_user;
190 $this->note_public = $obj->note_public;
191 $this->note_private = $obj->note_private;
192 $this->paye = $obj->paye;
193 $this->periode = $this->db->jdate($obj->period);
194 $this->period = $this->db->jdate($obj->period);
195 $this->import_key = $this->import_key;
197 $this->db->free($resql);
204 $this->error = $this->db->lasterror();
216 $newamount =
price2num($this->amount,
'MT');
219 if ($newamount == 0 || empty($this->date_ech) || (empty($this->period) && empty($this->periode))) {
240 $newamount =
price2num($this->amount,
'MT');
242 if (!$this->
check()) {
243 $this->error =
"ErrorBadParameter";
249 $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)";
250 $sql .=
" VALUES (".((int) $this->
type);
251 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
252 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"NULL");
253 $sql .=
", '".$this->db->escape($this->label ? $this->label :
$this->lib).
"'";
254 $sql .=
", '".$this->db->idate($this->date_ech).
"'";
255 $sql .=
", '".$this->db->idate($this->periode).
"'";
256 $sql .=
", '".price2num($newamount).
"'";
257 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
'NULL');
258 $sql .=
", ".((int) $conf->entity);
259 $sql .=
", ".((int) $user->id);
260 $sql .=
", ".($this->fk_user > 0 ? ((int) $this->fk_user) :
'NULL');
261 $sql .=
", '".$this->db->idate($now).
"'";
264 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
265 $resql = $this->db->query($sql);
267 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"chargesociales");
270 $result = $this->
call_trigger(
'SOCIALCONTRIBUTION_CREATE', $user);
279 $this->db->rollback();
283 $this->error = $this->db->error();
284 $this->db->rollback();
296 public function delete($user)
303 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
304 $account =
new Account($this->db);
305 $lines_url = $account->get_url(
'', $this->
id,
'sc');
308 foreach ($lines_url as $line_url) {
311 $accountline->fetch($line_url[
'fk_bank']);
312 $result = $accountline->delete_urls($user);
321 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge WHERE fk_charge=".((int) $this->
id);
322 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
323 $resql = $this->db->query($sql);
326 $this->error = $this->db->lasterror();
331 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"chargesociales WHERE rowid=".((int) $this->
id);
332 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
333 $resql = $this->db->query($sql);
336 $this->error = $this->db->lasterror();
344 $this->db->rollback();
357 public function update($user, $notrigger = 0)
362 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales";
363 $sql .=
" SET libelle='".$this->db->escape($this->label ? $this->label :
$this->lib).
"'";
364 $sql .=
", date_ech='".$this->db->idate($this->date_ech).
"'";
365 $sql .=
", periode='".$this->db->idate($this->periode).
"'";
366 $sql .=
", amount='".price2num($this->amount,
'MT').
"'";
367 $sql .=
", fk_projet=".($this->fk_project > 0 ? $this->db->escape($this->fk_project) :
"NULL");
368 $sql .=
", fk_user=".($this->fk_user > 0 ? $this->db->escape($this->fk_user) :
"NULL");
369 $sql .=
", fk_user_modif=".$user->id;
370 $sql .=
" WHERE rowid=".((int) $this->
id);
372 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
373 $resql = $this->db->query($sql);
377 $this->errors[] =
"Error ".$this->db->lasterror();
383 $result = $this->
call_trigger(
'SOCIALCONTRIBUTION_MODIFY', $user);
393 foreach ($this->errors as $errmsg) {
394 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
395 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
397 $this->db->rollback();
415 $sql =
"SELECT SUM(f.amount) as amount";
416 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as f";
417 $sql .=
" WHERE f.entity = ".$conf->entity;
418 $sql .=
" AND paye = 0";
421 $sql .=
" AND f.datev >= '".((int) $year).
"-01-01' AND f.datev <= '".((int) $year).
"-12-31' ";
424 $result = $this->db->query($sql);
426 if ($this->db->num_rows($result)) {
427 $obj = $this->db->fetch_object($result);
428 $this->db->free($result);
434 print $this->db->error();
451 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
463 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
465 $sql .=
" WHERE rowid = ".((int) $this->
id);
467 $return = $this->db->query($sql);
490 dol_syslog(get_class($this).
"::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE);
502 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
504 $sql .=
" WHERE rowid = ".((int) $this->
id);
506 $return = $this->db->query($sql);
526 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
538 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
544 $langs->loadLangs(array(
"customers",
"bills"));
547 $this->labelStatus = array();
548 $this->labelStatusShort = array();
550 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
553 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'Unpaid');
554 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'Paid');
555 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) {
556 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
558 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'Unpaid');
559 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'Paid');
560 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) {
561 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
565 $statusType =
'status1';
566 if ($status == 0 && $alreadypaid > 0) {
567 $statusType =
'status3';
570 $statusType =
'status6';
573 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
587 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $short = 0, $save_lastsearch_value = -1)
589 global $langs, $conf, $user, $form, $hookmanager;
591 if (!empty($conf->dol_no_mouse_hover)) {
597 $url = DOL_URL_ROOT.
'/compta/sociales/card.php?id='.$this->id;
603 if ($option !==
'nolink') {
605 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
606 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
607 $add_save_lastsearch_values = 1;
609 if ($add_save_lastsearch_values) {
610 $url .=
'&save_lastsearch_values=1';
614 if (empty($this->
ref)) {
615 $this->
ref = $this->label;
618 $label =
img_picto(
'', $this->picto,
'class="pictofixedwidth"').
'<u class="paddingrightonly">'.$langs->trans(
"SocialContribution").
'</u>';
619 if (isset($this->paye)) {
620 $label .=
' '.$this->getLibStatut(5);
622 if (!empty($this->
ref)) {
623 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
625 if (!empty($this->label)) {
626 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
628 if (!empty($this->type_label)) {
629 $label .=
'<br><b>'.$langs->trans(
'Type').
':</b> '.$this->type_label;
633 if (empty($notooltip) && $user->hasRight(
"facture",
"read")) {
635 $label = $langs->trans(
"SocialContribution");
636 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
638 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
639 $linkclose .=
' class="classfortooltip"';
642 $linkstart =
'<a href="'.$url.
'"';
643 $linkstart .= $linkclose.
'>';
646 $result .= $linkstart;
648 $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);
650 if ($withpicto != 2) {
651 $result .= $this->ref;
655 $hookmanager->initHooks(array($this->element .
'dao'));
656 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
657 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
659 $result = $hookmanager->resPrint;
661 $result .= $hookmanager->resPrint;
673 $table =
'paiementcharge';
674 $field =
'fk_charge';
676 $sql =
'SELECT sum(amount) as amount';
677 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
678 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
680 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
681 $resql = $this->db->query($sql);
685 $obj = $this->db->fetch_object($resql);
687 $amount = $obj->amount ? $obj->amount : 0;
690 $this->db->free($resql);
705 $sql =
"SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,";
706 $sql .=
" e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
707 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as e";
708 $sql .=
" WHERE e.rowid = ".((int) $id);
710 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
711 $result = $this->db->query($sql);
713 if ($this->db->num_rows($result)) {
714 $obj = $this->db->fetch_object($result);
716 $this->
id = $obj->rowid;
718 $this->user_creation_id = $obj->fk_user_author;
719 $this->user_modification_id = $obj->fk_user_modif;
720 $this->user_validation_id = $obj->fk_user_valid;
721 $this->date_creation = $this->db->jdate($obj->datec);
722 $this->date_modification = $this->db->jdate($obj->datem);
723 $this->date_validation = $this->db->jdate($obj->datev);
724 $this->import_key = $obj->import_key;
727 $this->db->free($result);
746 $this->
ref =
'SPECIMEN';
749 $this->date_creation =
dol_now();
750 $this->date_ech = $this->date_creation + 3600 * 24 * 30;
751 $this->periode = $this->date_creation + 3600 * 24 * 30;
752 $this->period = $this->date_creation + 3600 * 24 * 30;
754 $this->label =
'Social contribution label';
756 $this->type_label =
'Type of social contribution';
768 global $conf, $langs;
770 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
772 $return =
'<div class="box-flex-item box-flex-grow-zero">';
773 $return .=
'<div class="info-box info-box-sm">';
774 $return .=
'<span class="info-box-icon bg-infobox-action">';
776 $return .=
'</span>';
777 $return .=
'<div class="info-box-content">';
778 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0) : $this->ref).
'</span>';
779 if ($selected >= 0) {
780 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
782 if (property_exists($this,
'label')) {
783 $return .=
' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.
'</div>';
785 if (!empty($arraydata[
'project']) && $arraydata[
'project']->
id > 0) {
786 $return .=
'<br><span class="info-box-label">'.$arraydata[
'project']->getNomUrl(1).
'</span>';
788 if (property_exists($this,
'date_ech')) {
789 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label">'.
dol_print_date($this->date_ech,
'day').
'</span>';
791 if (property_exists($this,
'amount')) {
793 $return .=
'<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).
'</span>';
795 if (method_exists($this,
'LibStatut')) {
796 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3, $this->alreadypaid).
'</div>';
Class to manage bank accounts.
Class to manage bank transaction lines.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
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 optionaly the picto)
info($id)
Charge les informations 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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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