26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
27require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
38 public $element =
'paiementcharge';
43 public $table_element =
'paiementcharge';
48 public $picto =
'payment';
91 public $amounts = array();
96 public $fk_typepaiement;
102 public $num_paiement;
117 public $fk_user_creat;
122 public $fk_user_modif;
137 public $paiementtype;
158 public function create($user, $closepaidcontrib = 0)
160 global $conf, $langs;
166 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
169 if (!$this->datepaye) {
170 $this->error =
'ErrorBadValueForParameterCreatePaymentSocialContrib';
175 if (isset($this->fk_charge)) {
176 $this->fk_charge = (int) $this->fk_charge;
178 if (isset($this->amount)) {
179 $this->amount = trim($this->amount);
181 if (isset($this->fk_typepaiement)) {
182 $this->fk_typepaiement = (int) $this->fk_typepaiement;
184 if (isset($this->num_payment)) {
185 $this->num_payment = trim($this->num_payment);
187 if (isset($this->note_private)) {
188 $this->note_private = trim($this->note_private);
190 if (isset($this->fk_bank)) {
191 $this->fk_bank = (int) $this->fk_bank;
193 if (isset($this->fk_user_creat)) {
194 $this->fk_user_creat = (int) $this->fk_user_creat;
196 if (isset($this->fk_user_modif)) {
197 $this->fk_user_modif = (int) $this->fk_user_modif;
201 foreach ($this->amounts as $key => $value) {
203 $this->amounts[$key] = $newvalue;
204 $totalamount += $newvalue;
209 if ($totalamount == 0) {
216 if ($totalamount != 0) {
217 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiementcharge (fk_charge, datec, datep, amount,";
218 $sql .=
" fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
219 $sql .=
" VALUES ($this->chid, '".$this->db->idate($now).
"',";
220 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
221 $sql .=
" ".((float) $totalamount).
",";
222 $sql .=
" ".((int) $this->paiementtype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note).
"', ".$user->id.
",";
225 $resql = $this->db->query($sql);
227 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"paiementcharge");
230 foreach ($this->amounts as $key => $amount) {
232 if (is_numeric($amount) && $amount != 0) {
236 if ($closepaidcontrib) {
238 $contrib->fetch($contribid);
239 $paiement = $contrib->getSommePaiement();
244 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
245 $remaintopay =
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
246 if ($remaintopay == 0) {
247 $result = $contrib->setPaid($user);
249 dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
259 $result = $this->
call_trigger(
'PAYMENTSOCIALCONTRIBUTION_CREATE', $user);
264 if ($totalamount != 0 && !$error) {
265 $this->amount = $totalamount;
266 $this->total = $totalamount;
270 $this->error = $this->db->error();
271 $this->db->rollback();
287 $sql .=
" t.fk_charge,";
291 $sql .=
" t.amount,";
292 $sql .=
" t.fk_typepaiement,";
293 $sql .=
" t.num_paiement as num_payment,";
295 $sql .=
" t.fk_bank,";
296 $sql .=
" t.fk_user_creat,";
297 $sql .=
" t.fk_user_modif,";
298 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
299 $sql .=
' b.fk_account';
300 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepaiement = pt.id";
301 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
302 $sql .=
" WHERE t.rowid = ".((int) $id);
305 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
306 $resql = $this->db->query($sql);
308 if ($this->db->num_rows($resql)) {
309 $obj = $this->db->fetch_object($resql);
311 $this->
id = $obj->rowid;
312 $this->
ref = $obj->rowid;
314 $this->fk_charge = $obj->fk_charge;
315 $this->datec = $this->db->jdate($obj->datec);
316 $this->tms = $this->db->jdate($obj->tms);
317 $this->datep = $this->db->jdate($obj->datep);
318 $this->amount = $obj->amount;
319 $this->fk_typepaiement = $obj->fk_typepaiement;
320 $this->num_payment = $obj->num_payment;
321 $this->note_private = $obj->note;
322 $this->fk_bank = $obj->fk_bank;
323 $this->fk_user_creat = $obj->fk_user_creat;
324 $this->fk_user_modif = $obj->fk_user_modif;
326 $this->type_code = $obj->type_code;
327 $this->type_label = $obj->type_label;
329 $this->bank_account = $obj->fk_account;
330 $this->bank_line = $obj->fk_bank;
332 $this->db->free($resql);
336 $this->error =
"Error ".$this->db->lasterror();
349 public function update($user =
null, $notrigger = 0)
351 global $conf, $langs;
356 if (isset($this->fk_charge)) {
357 $this->fk_charge = (int) $this->fk_charge;
359 if (isset($this->amount)) {
360 $this->amount = trim($this->amount);
362 if (isset($this->fk_typepaiement)) {
363 $this->fk_typepaiement = (int) $this->fk_typepaiement;
365 if (isset($this->num_payment)) {
366 $this->num_payment = trim($this->num_payment);
368 if (isset($this->note_private)) {
369 $this->note_private = trim($this->note_private);
371 if (isset($this->fk_bank)) {
372 $this->fk_bank = (int) $this->fk_bank;
374 if (isset($this->fk_user_creat)) {
375 $this->fk_user_creat = (int) $this->fk_user_creat;
377 if (isset($this->fk_user_modif)) {
378 $this->fk_user_modif = (int) $this->fk_user_modif;
387 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET";
388 $sql .=
" fk_charge=".(isset($this->fk_charge) ? ((int) $this->fk_charge) :
"null").
",";
389 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
390 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
391 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
392 $sql .=
" amount=".(isset($this->amount) ?
price2num($this->amount) :
"null").
",";
393 $sql .=
" fk_typepaiement=".(isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) :
"null").
",";
394 $sql .=
" num_paiement=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
395 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
396 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
397 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null").
",";
398 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
399 $sql .=
" WHERE rowid=".((int) $this->
id);
403 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
404 $resql = $this->db->query($sql);
407 $this->errors[] =
"Error ".$this->db->lasterror();
412 foreach ($this->errors as $errmsg) {
413 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
414 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
416 $this->db->rollback();
432 public function delete($user, $notrigger = 0)
440 if ($this->bank_line > 0) {
442 $accline->fetch($this->bank_line);
443 $result = $accline->delete($user);
445 $this->errors[] = $accline->error;
451 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge";
452 $sql .=
" WHERE rowid=".((int) $this->
id);
454 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
455 $resql = $this->db->query($sql);
458 $this->errors[] =
"Error ".$this->db->lasterror();
464 foreach ($this->errors as $errmsg) {
465 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
466 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
468 $this->db->rollback();
494 $object->fetch($fromid);
502 $object->context[
'createfromclone'] =
'createfromclone';
503 $result = $object->create($user);
507 $this->error = $object->error;
511 unset($object->context[
'createfromclone']);
518 $this->db->rollback();
535 $this->fk_charge =
'';
540 $this->fk_typepaiement =
'';
541 $this->num_payment =
'';
542 $this->note_private =
'';
543 $this->note_public =
'';
545 $this->fk_user_creat =
'';
546 $this->fk_user_modif =
'';
562 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
564 global $conf, $langs;
567 $this->num_payment = trim($this->num_payment);
571 if (isModEnabled(
"banque")) {
572 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
575 $acc->fetch($accountid);
578 if ($mode ==
'payment_sc') {
583 $bank_line_id = $acc->addline(
597 if ($bank_line_id > 0) {
606 if ($mode ==
'payment_sc') {
607 $url = DOL_URL_ROOT.
'/compta/payment_sc/card.php?id=';
610 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
618 $linkaddedforthirdparty = array();
619 foreach ($this->amounts as $key => $value) {
620 if ($mode ==
'payment_sc') {
622 $socialcontrib->fetch($key);
623 $result = $acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.
'/compta/charges.php?id=', $socialcontrib->type_label.(($socialcontrib->lib && $socialcontrib->lib != $socialcontrib->type_label) ?
' ('.$socialcontrib->lib.
')' :
''),
'sc');
628 if ($socialcontrib->fk_user) {
629 $fuser =
new User($this->db);
630 $fuser->fetch($socialcontrib->fk_user);
633 $result = $acc->add_url_line(
635 $socialcontrib->fk_user,
636 DOL_URL_ROOT.
'/user/card.php?id=',
637 $fuser->getFullName($langs),
642 $this->error = $acc->error;
649 $this->error = $acc->error;
672 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
674 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
675 $result = $this->db->query($sql);
679 $this->error = $this->db->error();
709 $langs->load(
'compta');
761 if (empty($this->
ref)) {
762 $this->
ref = $this->label;
765 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SocialContributionPayment").
'</u>';
766 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
767 if (!empty($this->label)) {
768 $labeltoshow = $this->label;
770 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
772 if ($reg[1] ==
'paiement') {
775 $labeltoshow = $langs->trans($reg[1]);
777 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
780 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
783 if (!empty($this->
id)) {
784 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_sc/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
788 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
790 if ($withpicto && $withpicto != 2) {
793 if ($withpicto != 2) {
794 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
809 $alreadydispatched = 0;
813 $sql =
" SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type).
"' AND ab.fk_doc = ".((int) $this->bank_line);
814 $resql = $this->db->query($sql);
816 $obj = $this->db->fetch_object($resql);
818 $alreadydispatched = $obj->nb;
821 $this->error = $this->db->lasterror();
825 if ($alreadydispatched) {
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...
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 payments of social contributions.
getLibStatut($mode=0)
Return the label of the status.
__construct(DoliDB $db)
Constructor.
fetch($id)
Load object in memory from database.
getNomUrl($withpicto=0, $maxlen=0)
Return clicable name (with picto eventually)
getVentilExportCompta()
Return if object was dispatched into bookkeeping.
create($user, $closepaidcontrib=0)
Create payment of social contribution into database.
addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
Add record into bank for payment with links between this bank record and invoices of payment.
LibStatut($status, $mode=0)
Return the label of a given status.
update($user=null, $notrigger=0)
Update database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
update_fk_bank($id_bank)
Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee.
initAsSpecimen()
Initialise an instance with random values.
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...
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_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut