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';
74 public $date_creation;
79 public $date_modification;
84 public $date_validation;
104 public $paiementtype;
123 const STATUS_UNPAID = 0;
124 const STATUS_PAID = 1;
144 public function fetch($id, $ref =
'')
146 $sql =
"SELECT cs.rowid, cs.date_ech";
147 $sql .=
", cs.libelle as label, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode, cs.import_key";
148 $sql .=
", cs.fk_account, cs.fk_mode_reglement, cs.fk_user, note_public, note_private";
149 $sql .=
", c.libelle as type_label";
150 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
151 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as cs";
152 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_chargesociales as c ON cs.fk_type = c.id";
153 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON cs.fk_mode_reglement = p.id';
154 $sql .=
' WHERE cs.entity IN ('.getEntity(
'tax').
')';
156 $sql .=
" AND cs.ref = '".$this->db->escape($ref).
"'";
158 $sql .=
" AND cs.rowid = ".((int) $id);
161 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
162 $resql = $this->db->query($sql);
164 if ($this->db->num_rows($resql)) {
165 $obj = $this->db->fetch_object($resql);
167 $this->
id = $obj->rowid;
168 $this->
ref = $obj->rowid;
169 $this->date_ech = $this->db->jdate($obj->date_ech);
170 $this->lib = $obj->label;
171 $this->label = $obj->label;
172 $this->
type = $obj->fk_type;
173 $this->type_label = $obj->type_label;
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->periode);
185 $this->import_key = $this->import_key;
187 $this->db->free($resql);
194 $this->error = $this->db->lasterror();
206 $newamount =
price2num($this->amount,
'MT');
209 if ($newamount == 0 || empty($this->date_ech) || empty($this->periode)) {
230 $newamount =
price2num($this->amount,
'MT');
232 if (!$this->
check()) {
233 $this->error =
"ErrorBadParameter";
239 $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)";
240 $sql .=
" VALUES (".((int) $this->
type);
241 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
242 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"NULL");
243 $sql .=
", '".$this->db->escape($this->label ? $this->label :
$this->lib).
"'";
244 $sql .=
", '".$this->db->idate($this->date_ech).
"'";
245 $sql .=
", '".$this->db->idate($this->periode).
"'";
246 $sql .=
", '".price2num($newamount).
"'";
247 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
'NULL');
248 $sql .=
", ".((int) $conf->entity);
249 $sql .=
", ".((int) $user->id);
250 $sql .=
", ".($this->fk_user > 0 ? ((int) $this->fk_user) :
'NULL');
251 $sql .=
", '".$this->db->idate($now).
"'";
254 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
255 $resql = $this->db->query($sql);
257 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"chargesociales");
260 $result = $this->
call_trigger(
'SOCIALCONTRIBUTION_CREATE', $user);
269 $this->db->rollback();
273 $this->error = $this->db->error();
274 $this->db->rollback();
286 public function delete($user)
293 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
294 $account =
new Account($this->db);
295 $lines_url = $account->get_url(
'', $this->
id,
'sc');
298 foreach ($lines_url as $line_url) {
301 $accountline->fetch($line_url[
'fk_bank']);
302 $result = $accountline->delete_urls($user);
311 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge WHERE fk_charge=".((int) $this->
id);
312 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
313 $resql = $this->db->query($sql);
316 $this->error = $this->db->lasterror();
321 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"chargesociales WHERE rowid=".((int) $this->
id);
322 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
323 $resql = $this->db->query($sql);
326 $this->error = $this->db->lasterror();
334 $this->db->rollback();
347 public function update($user, $notrigger = 0)
352 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales";
353 $sql .=
" SET libelle='".$this->db->escape($this->label ? $this->label :
$this->lib).
"'";
354 $sql .=
", date_ech='".$this->db->idate($this->date_ech).
"'";
355 $sql .=
", periode='".$this->db->idate($this->periode).
"'";
356 $sql .=
", amount='".price2num($this->amount,
'MT').
"'";
357 $sql .=
", fk_projet=".($this->fk_project > 0 ? $this->db->escape($this->fk_project) :
"NULL");
358 $sql .=
", fk_user=".($this->fk_user > 0 ? $this->db->escape($this->fk_user) :
"NULL");
359 $sql .=
", fk_user_modif=".$user->id;
360 $sql .=
" WHERE rowid=".((int) $this->
id);
362 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
363 $resql = $this->db->query($sql);
367 $this->errors[] =
"Error ".$this->db->lasterror();
373 $result = $this->
call_trigger(
'SOCIALCONTRIBUTION_MODIFY', $user);
383 foreach ($this->errors as $errmsg) {
384 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
385 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
387 $this->db->rollback();
405 $sql =
"SELECT SUM(f.amount) as amount";
406 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as f";
407 $sql .=
" WHERE f.entity = ".$conf->entity;
408 $sql .=
" AND paye = 0";
411 $sql .=
" AND f.datev >= '".((int) $year).
"-01-01' AND f.datev <= '".((int) $year).
"-12-31' ";
414 $result = $this->db->query($sql);
416 if ($this->db->num_rows($result)) {
417 $obj = $this->db->fetch_object($result);
418 $this->db->free($result);
424 print $this->db->error();
441 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
453 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
455 $sql .=
" WHERE rowid = ".((int) $this->
id);
457 $return = $this->db->query($sql);
480 dol_syslog(get_class($this).
"::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE);
492 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
494 $sql .=
" WHERE rowid = ".((int) $this->
id);
496 $return = $this->db->query($sql);
516 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
528 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
534 $langs->loadLangs(array(
"customers",
"bills"));
537 $this->labelStatus = array();
538 $this->labelStatusShort = array();
540 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
543 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'Unpaid');
544 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'Paid');
545 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) {
546 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
548 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'Unpaid');
549 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'Paid');
550 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) {
551 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
555 $statusType =
'status1';
556 if ($status == 0 && $alreadypaid > 0) {
557 $statusType =
'status3';
560 $statusType =
'status6';
563 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
577 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $short = 0, $save_lastsearch_value = -1)
579 global $langs, $conf, $user, $form, $hookmanager;
581 if (!empty($conf->dol_no_mouse_hover)) {
587 $url = DOL_URL_ROOT.
'/compta/sociales/card.php?id='.$this->id;
593 if ($option !==
'nolink') {
595 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
596 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
597 $add_save_lastsearch_values = 1;
599 if ($add_save_lastsearch_values) {
600 $url .=
'&save_lastsearch_values=1';
604 if (empty($this->
ref)) {
605 $this->
ref = $this->label;
608 $label =
img_picto(
'', $this->picto,
'class="pictofixedwidth"').
'<u class="paddingrightonly">'.$langs->trans(
"SocialContribution").
'</u>';
609 if (isset($this->paye)) {
610 $label .=
' '.$this->getLibStatut(5);
612 if (!empty($this->
ref)) {
613 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
615 if (!empty($this->label)) {
616 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
618 if (!empty($this->type_label)) {
619 $label .=
'<br><b>'.$langs->trans(
'Type').
':</b> '.$this->type_label;
623 if (empty($notooltip) && $user->hasRight(
"facture",
"read")) {
624 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
625 $label = $langs->trans(
"SocialContribution");
626 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
628 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
629 $linkclose .=
' class="classfortooltip"';
632 $linkstart =
'<a href="'.$url.
'"';
633 $linkstart .= $linkclose.
'>';
636 $result .= $linkstart;
638 $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);
640 if ($withpicto != 2) {
641 $result .= $this->ref;
645 $hookmanager->initHooks(array($this->element .
'dao'));
646 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
647 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
649 $result = $hookmanager->resPrint;
651 $result .= $hookmanager->resPrint;
663 $table =
'paiementcharge';
664 $field =
'fk_charge';
666 $sql =
'SELECT sum(amount) as amount';
667 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
668 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
670 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
671 $resql = $this->db->query($sql);
675 $obj = $this->db->fetch_object($resql);
677 $amount = $obj->amount ? $obj->amount : 0;
680 $this->db->free($resql);
695 $sql =
"SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,";
696 $sql .=
" e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
697 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as e";
698 $sql .=
" WHERE e.rowid = ".((int) $id);
700 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
701 $result = $this->db->query($sql);
703 if ($this->db->num_rows($result)) {
704 $obj = $this->db->fetch_object($result);
706 $this->
id = $obj->rowid;
708 if ($obj->fk_user_author) {
709 $cuser =
new User($this->db);
710 $cuser->fetch($obj->fk_user_author);
711 $this->user_creation = $cuser;
714 if ($obj->fk_user_modif) {
715 $muser =
new User($this->db);
716 $muser->fetch($obj->fk_user_modif);
717 $this->user_modification = $muser;
720 if ($obj->fk_user_valid) {
721 $vuser =
new User($this->db);
722 $vuser->fetch($obj->fk_user_valid);
723 $this->user_validation = $vuser;
726 $this->date_creation = $this->db->jdate($obj->datec);
727 $this->date_modification = $this->db->jdate($obj->datem);
728 $this->date_validation = $this->db->jdate($obj->datev);
729 $this->import_key = $obj->import_key;
732 $this->db->free($result);
751 $this->
ref =
'SPECIMEN';
755 $this->date_ech = $this->date + 3600 * 24 * 30;
756 $this->periode = $this->date + 3600 * 24 * 30;
758 $this->label =
'Social contribution label';
760 $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 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
784 if (property_exists($this,
'label')) {
785 $return .=
' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.
'</div>';
787 if (!empty($arraydata[
'project']) && $arraydata[
'project']->
id > 0) {
788 $return .=
'<br><span class="info-box-label">'.$arraydata[
'project']->getNomUrl(1).
'</span>';
790 if (property_exists($this,
'date_ech')) {
791 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label">'.
dol_print_date($this->date_ech,
'day').
'</span>';
793 if (property_exists($this,
'amount')) {
795 $return .=
'<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).
'</span>';
797 if (method_exists($this,
'LibStatut')) {
798 $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.
Class to manage Dolibarr users.
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)
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