26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $element =
'chargesociales';
40 public $table =
'chargesociales';
45 public $table_element =
'chargesociales';
50 public $picto =
'bill';
73 public $date_creation;
78 public $date_modification;
83 public $date_validation;
103 public $paiementtype;
111 const STATUS_UNPAID = 0;
112 const STATUS_PAID = 1;
132 public function fetch($id, $ref =
'')
134 $sql =
"SELECT cs.rowid, cs.date_ech";
135 $sql .=
", cs.libelle as label, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode, cs.import_key";
136 $sql .=
", cs.fk_account, cs.fk_mode_reglement";
137 $sql .=
", c.libelle";
138 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
139 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as cs";
140 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_chargesociales as c ON cs.fk_type = c.id";
141 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON cs.fk_mode_reglement = p.id';
142 $sql .=
' WHERE cs.entity IN ('.getEntity(
'tax').
')';
143 if ($ref) $sql .=
" AND cs.rowid = ".$ref;
144 else $sql .=
" AND cs.rowid = ".$id;
146 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
152 $obj = $this->
db->fetch_object(
$resql);
154 $this->
id = $obj->rowid;
155 $this->ref = $obj->rowid;
156 $this->date_ech = $this->
db->jdate($obj->date_ech);
157 $this->lib = $obj->label;
158 $this->label = $obj->label;
159 $this->
type = $obj->fk_type;
160 $this->type_label = $obj->libelle;
161 $this->fk_account = $obj->fk_account;
162 $this->mode_reglement_id = $obj->fk_mode_reglement;
163 $this->mode_reglement_code = $obj->mode_reglement_code;
164 $this->mode_reglement = $obj->mode_reglement_libelle;
165 $this->amount = $obj->amount;
166 $this->fk_project = $obj->fk_project;
167 $this->paye = $obj->paye;
168 $this->periode = $this->
db->jdate($obj->periode);
169 $this->import_key = $this->import_key;
178 $this->error = $this->
db->lasterror();
190 $newamount =
price2num($this->amount,
'MT');
193 if (!$newamount > 0 || empty($this->date_ech) || empty($this->periode))
216 $newamount =
price2num($this->amount,
'MT');
218 if (!$this->
check()) {
219 $this->error =
"ErrorBadParameter";
225 $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, date_creation)";
226 $sql .=
" VALUES (".$this->type;
227 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
228 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
"NULL");
229 $sql .=
", '".$this->db->escape($this->label ? $this->label : $this->lib).
"'";
230 $sql .=
", '".$this->db->idate($this->date_ech).
"'";
231 $sql .=
", '".$this->db->idate($this->periode).
"'";
232 $sql .=
", '".price2num($newamount).
"'";
233 $sql .=
", ".($this->fk_project > 0 ? $this->fk_project :
'NULL');
234 $sql .=
", ".$conf->entity;
235 $sql .=
", ".$user->id;
236 $sql .=
", '".$this->db->idate($now).
"'";
239 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
242 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"chargesociales");
245 $result = $this->
call_trigger(
'SOCIALCONTRIBUTION_CREATE', $user);
246 if ($result < 0) $error++;
252 $this->
db->rollback();
256 $this->error = $this->
db->error();
257 $this->
db->rollback();
269 public function delete($user)
276 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
278 $lines_url = $account->get_url(
'', $this->
id,
'sc');
281 foreach ($lines_url as $line_url)
286 $accountline->fetch($line_url[
'fk_bank']);
287 $result = $accountline->delete_urls($user);
298 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge WHERE fk_charge=".$this->id;
299 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
304 $this->error = $this->
db->lasterror();
310 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"chargesociales WHERE rowid=".$this->id;
311 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
316 $this->error = $this->
db->lasterror();
325 $this->
db->rollback();
338 public function update($user, $notrigger = 0)
343 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales";
344 $sql .=
" SET libelle='".$this->db->escape($this->label ? $this->label : $this->lib).
"'";
345 $sql .=
", date_ech='".$this->db->idate($this->date_ech).
"'";
346 $sql .=
", periode='".$this->db->idate($this->periode).
"'";
347 $sql .=
", amount='".price2num($this->amount,
'MT').
"'";
348 $sql .=
", fk_projet=".($this->fk_project > 0 ? $this->
db->escape($this->fk_project) :
"NULL");
349 $sql .=
", fk_user_modif=".$user->id;
350 $sql .=
" WHERE rowid=".$this->id;
352 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
356 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
364 $result = $this->
call_trigger(
'SOCIALCHARGES_MODIFY', $user);
365 if ($result < 0) $error++;
373 foreach ($this->errors as $errmsg)
375 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
376 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
378 $this->
db->rollback();
396 $sql =
"SELECT SUM(f.amount) as amount";
397 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as f";
398 $sql .=
" WHERE f.entity = ".$conf->entity;
399 $sql .=
" AND paye = 0";
402 $sql .=
" AND f.datev >= '".((int) $year).
"-01-01' AND f.datev <= '".((int) $year).
"-12-31' ";
405 $result = $this->
db->query($sql);
408 if ($this->
db->num_rows($result))
410 $obj = $this->
db->fetch_object($result);
411 $this->
db->free($result);
432 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
434 $sql .=
" WHERE rowid = ".$this->id;
435 $return = $this->
db->query($sql);
436 if ($return)
return 1;
450 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"chargesociales SET";
452 $sql .=
" WHERE rowid = ".$this->id;
453 $return = $this->
db->query($sql);
454 if ($return)
return 1;
467 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
479 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
485 $langs->loadLangs(array(
"customers",
"bills"));
488 $this->labelStatus = array();
489 $this->labelStatusShort = array();
491 if (empty($this->labelStatus) || empty($this->labelStatusShort))
495 $this->labelStatus[self::STATUS_UNPAID] = $langs->trans(
'Unpaid');
496 $this->labelStatus[self::STATUS_PAID] = $langs->trans(
'Paid');
497 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) $this->labelStatus[self::STATUS_UNPAID] = $langs->trans(
"BillStatusStarted");
498 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans(
'Unpaid');
499 $this->labelStatusShort[self::STATUS_PAID] = $langs->trans(
'Paid');
500 if ($status == self::STATUS_UNPAID && $alreadypaid > 0) $this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans(
"BillStatusStarted");
503 $statusType =
'status1';
504 if ($status == 0 && $alreadypaid > 0) $statusType =
'status3';
505 if ($status == 1) $statusType =
'status6';
507 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
521 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $short = 0, $save_lastsearch_value = -1)
523 global $langs, $conf, $user, $form;
525 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
529 $url = DOL_URL_ROOT.
'/compta/sociales/card.php?id='.$this->id;
531 if ($short)
return $url;
533 if ($option !==
'nolink')
536 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
537 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
538 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
541 if (empty($this->ref)) $this->ref = $this->label;
543 $label =
img_picto(
'',
'tax').
'<u class="paddingrightonly">'.$langs->trans(
"SocialContribution").
'</u>';
544 if (isset($this->paye)) {
545 $label .=
' '.$this->getLibStatut(5);
547 if (!empty($this->ref))
548 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
549 if (!empty($this->label))
550 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
551 if (!empty($this->type_label))
552 $label .=
'<br><b>'.$langs->trans(
'Type').
':</b> '.$this->type_label;
555 if (empty($notooltip) && $user->rights->facture->lire)
557 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
559 $label = $langs->trans(
"SocialContribution");
560 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
562 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
563 $linkclose .=
' class="classfortooltip"';
566 $linkstart =
'<a href="'.$url.
'"';
567 $linkstart .= $linkclose.
'>';
570 $result .= $linkstart;
571 if ($withpicto) $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);
572 if ($withpicto != 2) $result .= $this->ref;
585 $table =
'paiementcharge';
586 $field =
'fk_charge';
588 $sql =
'SELECT sum(amount) as amount';
589 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
590 $sql .=
' WHERE '.$field.
' = '.$this->id;
592 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
597 $obj = $this->
db->fetch_object(
$resql);
598 if ($obj) $amount = $obj->amount ? $obj->amount : 0;
615 $sql =
"SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,";
616 $sql .=
" e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
617 $sql .=
" FROM ".MAIN_DB_PREFIX.
"chargesociales as e";
618 $sql .=
" WHERE e.rowid = ".$id;
620 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
621 $result = $this->
db->query($sql);
624 if ($this->
db->num_rows($result))
626 $obj = $this->
db->fetch_object($result);
628 $this->
id = $obj->rowid;
630 if ($obj->fk_user_author) {
631 $cuser =
new User($this->
db);
632 $cuser->fetch($obj->fk_user_author);
633 $this->user_creation = $cuser;
636 if ($obj->fk_user_modif) {
637 $muser =
new User($this->
db);
638 $muser->fetch($obj->fk_user_modif);
639 $this->user_modification = $muser;
642 if ($obj->fk_user_valid) {
643 $vuser =
new User($this->
db);
644 $vuser->fetch($obj->fk_user_valid);
645 $this->user_validation = $vuser;
648 $this->date_creation = $this->
db->jdate($obj->datec);
649 $this->date_modification = $this->
db->jdate($obj->datem);
650 $this->date_validation = $this->
db->jdate($obj->datev);
651 $this->import_key = $obj->import_key;
654 $this->
db->free($result);
671 $this->ref =
'SPECIMEN';
675 $this->date_ech = $this->date + 3600 * 24 * 30;
676 $this->periode = $this->date + 3600 * 24 * 30;
678 $this->label =
'Social contribution label';
680 $this->type_label =
'Type of social contribution';
check()
Check if a social contribution can be created into database.
getSommePaiement()
Return amount of payments already done.
create($user)
Create a social contribution into database.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
set_paid($user)
Tag social contribution as paid completely.
Class to manage bank transaction lines.
solde($year=0)
Calculate amount remaining to pay by year.
$conf db
API class for accounts.
Class to manage bank accounts.
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.
initAsSpecimen()
Initialise an instance with random values.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
getLibStatut($mode=0, $alreadypaid=-1)
Retourne le libelle du statut d'une charge (impaye, payee)
set_unpaid($user)
Remove tag paid on social contribution.
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.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
LibStatut($status, $mode=0, $alreadypaid=-1)
Renvoi le libelle d'un statut donne.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
call_trigger($triggerName, $user)
Call trigger based on this instance.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
update($user, $notrigger=0)
Update social or fiscal contribution.
fetch($id, $ref= '')
Retrouve et charge une charge sociale.
__construct($db)
Constructor.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)