27 require_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);
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;
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);
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';
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);
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);
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);
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);
456 $return = $this->
db->query($sql);
476 dol_syslog(get_class($this).
"::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE);
488 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
490 $sql .=
" WHERE rowid = ".((int) $this->
id);
491 $return = $this->
db->query($sql);
508 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
520 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
526 $langs->loadLangs(array(
"customers",
"bills"));
529 $this->labelStatus = array();
530 $this->labelStatusShort = array();
532 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
535 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'Unpaid');
536 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'Paid');
537 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) {
538 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
540 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'Unpaid');
541 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'Paid');
542 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) {
543 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
547 $statusType =
'status1';
548 if ($status == 0 && $alreadypaid > 0) {
549 $statusType =
'status3';
552 $statusType =
'status6';
555 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
569 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $short = 0, $save_lastsearch_value = -1)
571 global $langs, $conf, $user,
$form, $hookmanager;
573 if (!empty($conf->dol_no_mouse_hover)) {
579 $url = DOL_URL_ROOT.
'/compta/sociales/card.php?id='.$this->id;
585 if ($option !==
'nolink') {
587 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
588 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
589 $add_save_lastsearch_values = 1;
591 if ($add_save_lastsearch_values) {
592 $url .=
'&save_lastsearch_values=1';
596 if (empty($this->
ref)) {
597 $this->
ref = $this->label;
600 $label =
img_picto(
'',
'tax').
'<u class="paddingrightonly">'.$langs->trans(
"SocialContribution").
'</u>';
601 if (isset($this->paye)) {
602 $label .=
' '.$this->getLibStatut(5);
604 if (!empty($this->
ref)) {
605 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
607 if (!empty($this->label)) {
608 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
610 if (!empty($this->type_label)) {
611 $label .=
'<br><b>'.$langs->trans(
'Type').
':</b> '.$this->type_label;
615 if (empty($notooltip) && $user->hasRight(
"facture",
"read")) {
616 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
617 $label = $langs->trans(
"SocialContribution");
618 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
620 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
621 $linkclose .=
' class="classfortooltip"';
624 $linkstart =
'<a href="'.$url.
'"';
625 $linkstart .= $linkclose.
'>';
628 $result .= $linkstart;
630 $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);
632 if ($withpicto != 2) {
633 $result .= $this->ref;
637 $hookmanager->initHooks(array($this->element .
'dao'));
638 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
639 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
641 $result = $hookmanager->resPrint;
643 $result .= $hookmanager->resPrint;
655 $table =
'paiementcharge';
656 $field =
'fk_charge';
658 $sql =
'SELECT sum(amount) as amount';
659 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
660 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
662 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
667 $obj = $this->
db->fetch_object(
$resql);
669 $amount = $obj->amount ? $obj->amount : 0;
687 $sql =
"SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,";
688 $sql .=
" e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
689 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as e";
690 $sql .=
" WHERE e.rowid = ".((int) $id);
692 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
693 $result = $this->
db->query($sql);
695 if ($this->
db->num_rows($result)) {
696 $obj = $this->
db->fetch_object($result);
698 $this->
id = $obj->rowid;
700 if ($obj->fk_user_author) {
701 $cuser =
new User($this->
db);
702 $cuser->fetch($obj->fk_user_author);
703 $this->user_creation = $cuser;
706 if ($obj->fk_user_modif) {
707 $muser =
new User($this->
db);
708 $muser->fetch($obj->fk_user_modif);
709 $this->user_modification = $muser;
712 if ($obj->fk_user_valid) {
713 $vuser =
new User($this->
db);
714 $vuser->fetch($obj->fk_user_valid);
715 $this->user_validation = $vuser;
718 $this->date_creation = $this->
db->jdate($obj->datec);
719 $this->date_modification = $this->
db->jdate($obj->datem);
720 $this->date_validation = $this->
db->jdate($obj->datev);
721 $this->import_key = $obj->import_key;
724 $this->
db->free($result);
741 $this->
ref =
'SPECIMEN';
745 $this->date_ech = $this->date + 3600 * 24 * 30;
746 $this->periode = $this->date + 3600 * 24 * 30;
748 $this->label =
'Social contribution label';
750 $this->type_label =
'Type of social contribution';
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.
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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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_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)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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
$conf db
API class for accounts.