38require
'../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
45$langs->loadLangs(array(
'companies',
'bills',
'banks',
'multicurrency'));
47$action =
GETPOST(
'action',
'alpha');
48$confirm =
GETPOST(
'confirm',
'alpha');
52$paymentnum =
GETPOST(
'num_paiement',
'alpha');
55$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
56$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
60$amountsresttopay = array();
63$multicurrency_amounts = array();
64$multicurrency_amountsresttopay = array();
67if ($user->socid > 0) {
68 $socid = $user->socid;
79$hookmanager->initHooks(array(
'paiementcard',
'globalcard'));
81$formquestion = array();
83$usercanissuepayment = $user->hasRight(
'facture',
'paiement');
94$parameters = array(
'socid' => $socid);
95$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
100if (empty($reshook)) {
101 if (($action ==
'add_paiement' || ($action ==
'confirm_paiement' && $confirm ==
'yes')) && $usercanissuepayment) {
107 $multicurrency_totalpayment = 0;
108 $atleastonepaymentnotnull = 0;
109 $formquestion = array();
113 $tmpinvoice =
new Facture($db);
114 foreach ($_POST as $key => $value) {
115 if (substr($key, 0, 7) ==
'amount_' &&
GETPOST($key) !=
'') {
116 $cursorfacid = substr($key, 7);
118 if (!empty($amounts[$cursorfacid])) {
119 $totalpayment += (float) $amounts[$cursorfacid];
120 $atleastonepaymentnotnull++;
122 $result = $tmpinvoice->fetch($cursorfacid);
126 $amountsresttopay[$cursorfacid] =
price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement(0));
127 if ($amounts[$cursorfacid]) {
129 if ($amounts[$cursorfacid] && (abs((
float) $amounts[$cursorfacid]) > abs((
float) $amountsresttopay[$cursorfacid]))) {
131 $formquestion[
'text'] =
img_warning($langs->trans(
"PaymentHigherThanReminderToPay")).
' '.$langs->trans(
"HelpPaymentHigherThanReminderToPay");
134 if ($datepaye && ($datepaye < $tmpinvoice->date)) {
135 $langs->load(
"errors");
141 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' => $key,
'value' =>
GETPOST($key));
142 } elseif (substr($key, 0, 21) ==
'multicurrency_amount_') {
143 $cursorfacid = substr($key, 21);
145 $multicurrency_totalpayment += (float) $multicurrency_amounts[$cursorfacid];
146 if (!empty($multicurrency_amounts[$cursorfacid])) {
147 $atleastonepaymentnotnull++;
149 $result = $tmpinvoice->fetch($cursorfacid);
153 $multicurrency_amountsresttopay[$cursorfacid] =
price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1));
154 if ($multicurrency_amounts[$cursorfacid]) {
156 if ($multicurrency_amounts[$cursorfacid] && (abs((
float) $multicurrency_amounts[$cursorfacid]) > abs((
float) $multicurrency_amountsresttopay[$cursorfacid]))) {
158 $formquestion[
'text'] =
img_warning($langs->trans(
"PaymentHigherThanReminderToPay")).
' '.$langs->trans(
"HelpPaymentHigherThanReminderToPay");
161 if ($datepaye && ($datepaye < $tmpinvoice->date)) {
162 $langs->load(
"errors");
168 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' => $key,
'value' =>
GETPOSTINT($key));
173 if (!
GETPOST(
'paiementcode')) {
174 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'PaymentMode')),
null,
'errors');
178 if (isModEnabled(
"bank")) {
180 if (
GETPOST(
'accountid') <= 0) {
181 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'AccountToCredit')),
null,
'errors');
186 if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) {
187 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->trans(
'PaymentAmount')),
null,
'errors');
191 if (empty($datepaye)) {
192 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'Date')),
null,
'errors');
197 if ($totalpayment > 0 && $multicurrency_totalpayment > 0) {
198 $langs->load(
"errors");
199 setEventMessages($langs->transnoentities(
'ErrorPaymentInBothCurrency'),
null,
'errors');
207 if ($action ==
'add_paiement') {
217 if ($action ==
'confirm_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
224 $thirdparty =
new Societe($db);
226 $thirdparty->fetch($socid);
229 $multicurrency_code = array();
230 $multicurrency_tx = array();
233 foreach ($amounts as $key => $value) {
234 $tmpinvoice =
new Facture($db);
235 $tmpinvoice->fetch($key);
238 $amounts[$key] = - abs((
float) $newvalue);
240 $multicurrency_code[$key] = $tmpinvoice->multicurrency_code;
241 $multicurrency_tx[$key] = $tmpinvoice->multicurrency_tx;
244 foreach ($multicurrency_amounts as $key => $value) {
245 $tmpinvoice =
new Facture($db);
246 $tmpinvoice->fetch($key);
249 $multicurrency_amounts[$key] = - abs((
float) $newvalue);
251 $multicurrency_code[$key] = $tmpinvoice->multicurrency_code;
252 $multicurrency_tx[$key] = $tmpinvoice->multicurrency_tx;
255 if (isModEnabled(
"bank")) {
258 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'AccountToCredit')),
null,
'errors');
265 $paiement->datepaye = $datepaye;
266 $paiement->amounts = $amounts;
267 $paiement->multicurrency_amounts = $multicurrency_amounts;
268 $paiement->multicurrency_code = $multicurrency_code;
269 $paiement->multicurrency_tx = $multicurrency_tx;
271 $paiement->num_payment =
GETPOST(
'num_paiement',
'alpha');
272 $paiement->note_private =
GETPOST(
'comment',
'alpha');
273 $paiement->fk_account =
GETPOSTINT(
'accountid');
279 $paiement_id = $paiement->create($user, (
GETPOST(
'closepaidinvoices') ==
'on' ? 1 : 0), $thirdparty);
280 if ($paiement_id < 0) {
292 $label =
'(CustomerInvoicePayment)';
294 $label =
'(CustomerInvoicePaymentBack)';
297 $result = $paiement->addPaymentToBank($user,
'payment', $label,
GETPOSTINT(
'accountid'),
GETPOST(
'chqemetteur'),
GETPOST(
'chqbank'));
309 foreach ($paiement->amounts as $key => $amount) {
311 if (is_numeric($amount) && $amount != 0) {
312 if ($invoiceid != 0) {
319 if ($invoiceid > 0) {
320 $loc = DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$invoiceid;
322 $loc = DOL_URL_ROOT.
'/compta/paiement/card.php?id='.$paiement_id;
324 header(
'Location: '.$loc);
337$form =
new Form($db);
344if ($action ==
'create' || $action ==
'confirm_paiement' || $action ==
'add_paiement') {
346 $result = $facture->fetch($facid);
349 $facture->fetch_thirdparty();
353 $title .= $langs->trans(
"EnterPaymentReceivedFromCustomer");
356 $title .= $langs->trans(
"EnterPaymentDueToCustomer");
361 if ($action ==
'add_paiement') {
364 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'facid',
'value' => $facture->id);
365 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'socid',
'value' => $facture->socid);
366 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'type',
'value' => $facture->type);
371 if (isModEnabled(
'paypalplus') &&
getDolGlobalString(
'PAYPAL_ENABLE_TRANSACTION_MANAGEMENT') && !empty($facture->ref_ext)) {
375 $paymentnum = $facture->ref_ext;
379 if (!empty($conf->use_javascript_ajax)) {
380 print
"\n".
'<script type="text/javascript">';
381 print
'$(document).ready(function () {
384 $("#selectpaiementcode").change(function() {
388 function setPaiementCode()
390 var code = $("#selectpaiementcode option:selected").val();
391 console.log("setPaiementCode code="+code);
393 if (code == \'CHQ\' || code == \'VIR\')
397 $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
399 if ($(\'#fieldchqemetteur\').val() == \'\')
402 $(\'#fieldchqemetteur\').val(emetteur);
407 $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
408 $(\'#fieldchqemetteur\').val(\'\');
412 function _elemToJson(selector)
415 $.map(selector.serializeArray(), function(n,i)
417 subJson[n["name"]] = n["value"];
422 function callForResult(imgId)
425 var form = $("#payment_form");
427 json["invoice_type"] = $("#invoice_type").val();
428 json["amountPayment"] = $("#amountpayment").attr("value");
429 json["amounts"] = _elemToJson(form.find("input.amount"));
430 json["remains"] = _elemToJson(form.find("input.remain"));
433 json["imgClicked"] = imgId;
436 $.post("'.DOL_URL_ROOT.
'/compta/ajaxpayment.php", json, function(data)
438 json = $.parseJSON(data);
442 for (var key in json)
444 if (key == "result") {
445 if (json["makeRed"]) {
446 $("#"+key).addClass("error");
448 $("#"+key).removeClass("error");
450 json[key]=json["label"]+" "+json[key];
451 $("#"+key).text(json[key]);
452 } else {console.log(key);
453 form.find("input[name*=\""+key+"\"]").each(function() {
454 $(this).attr("value", json[key]);
460 $("#payment_form").find("input.amount").change(function() {
463 $("#payment_form").find("input.amount").keyup(function() {
471 print
' $(document).ready(function () {';
472 print
' $(".AutoFillAmount").on(\'click touchstart\', function(){
473 $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
477 print
' </script>'.
"\n";
480 print
'<form id="payment_form" name="add_paiement" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
481 print
'<input type="hidden" name="token" value="'.newToken().
'">';
482 print
'<input type="hidden" name="action" value="add_paiement">';
483 print
'<input type="hidden" name="facid" value="'.$facture->id.
'">';
484 print
'<input type="hidden" name="socid" value="'.$facture->socid.
'">';
485 print
'<input type="hidden" name="type" id="invoice_type" value="'.$facture->type.
'">';
486 print
'<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($facture->thirdparty->name).
'">';
487 print
'<input type="hidden" name="page_y" value="">';
491 print
'<table class="border centpercent">';
494 print
'<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans(
'Company').
'</span></td><td>'.$facture->thirdparty->getNomUrl(4).
"</td></tr>\n";
497 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
'Date').
'</span></td><td>';
499 $datepayment = ($datepayment ==
'' ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $datepayment);
500 print $form->selectDate($datepayment,
'', 0, 0, 0,
"add_paiement", 1, 1, 0,
'',
'', $facture->date);
504 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
'PaymentMode').
'</span></td><td>';
505 $form->select_types_paiements((
GETPOST(
'paiementcode') ?
GETPOST(
'paiementcode') : $facture->mode_reglement_code),
'paiementcode',
'', 2);
511 if (isModEnabled(
"bank")) {
512 if ($facture->type != 2) {
513 print
'<td><span class="fieldrequired">'.$langs->trans(
'AccountToCredit').
'</span></td>';
515 if ($facture->type == 2) {
516 print
'<td><span class="fieldrequired">'.$langs->trans(
'AccountToDebit').
'</span></td>';
520 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
521 print $form->select_comptes($accountid,
'accountid', 0,
'', 2,
'', (isModEnabled(
'multicurrency') ? 1 : 0),
'widthcentpercentminusx maxwidth500', 1);
524 print
'<td> </td>';
529 print
'<tr><td>'.$langs->trans(
'Numero');
530 print
' <em class="opacitymedium">('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
532 print
'<td><input name="num_paiement" type="text" class="maxwidth200" value="'.$paymentnum.
'"></td></tr>';
535 print
'<tr><td class="'.(GETPOST(
'paiementcode') ==
'CHQ' ?
'fieldrequired ' :
'').
'fieldrequireddyn">'.$langs->trans(
'CheckTransmitter');
536 print
' <em class="opacitymedium">('.$langs->trans(
"ChequeMaker").
')</em>';
538 print
'<td><input id="fieldchqemetteur" class="maxwidth300" name="chqemetteur" type="text" value="'.GETPOST(
'chqemetteur',
'alphanohtml').
'"></td></tr>';
541 print
'<tr><td>'.$langs->trans(
'Bank');
542 print
' <em class="opacitymedium">('.$langs->trans(
"ChequeBank").
')</em>';
544 print
'<td><input name="chqbank" class="maxwidth300" type="text" value="'.GETPOST(
'chqbank',
'alphanohtml').
'"></td></tr>';
547 print
'<tr><td>'.$langs->trans(
'Comments').
'</td>';
548 print
'<td class="tdtop">';
549 print
'<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.
'">'.
GETPOST(
'comment',
'restricthtml').
'</textarea>';
553 if ($action !=
'add_paiement' &&
getDolGlobalString(
'FACTURE_PAYMENTS_SHOW_LINK_TO_INPUT_ORIGIN_IS_MORE_THAN')) {
554 print
'<tr><td></td>';
555 print
'<td class="tdtop right">';
556 print
'<a class="right" href="#amount_'.$facid.
'">'.$langs->trans(
"GoSourceInvoice").
'</a>';
569 $sql =
'SELECT f.rowid as facid, f.ref, f.total_ht, f.total_tva, f.total_ttc, f.multicurrency_code, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc, f.type,';
570 $sql .=
' f.datef as df, f.fk_soc as socid, f.date_lim_reglement as dlr';
571 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture as f';
572 $sql .=
' WHERE f.entity IN ('.getEntity(
'facture').
')';
573 $sql .=
' AND (f.fk_soc = '.((int) $facture->socid);
575 if (
getDolGlobalString(
'FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS') && !empty($facture->thirdparty->parent)) {
576 $sql .=
' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe WHERE parent = '.((int) $facture->thirdparty->parent).
')';
580 $sql .=
' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe WHERE parent = '.((int) $facture->thirdparty->id).
')';
582 $sql .=
') AND f.paye = 0';
583 $sql .=
' AND f.fk_statut = 1';
585 $sql .=
' AND type IN (0,1,3,5)';
587 $sql .=
' AND type = 2';
590 $sql .=
' ORDER BY f.datef ASC, f.ref ASC';
592 $resql = $db->query($sql);
594 $num = $db->num_rows($resql);
596 $arraytitle = $langs->trans(
'Invoice');
597 if ($facture->type == 2) {
598 $arraytitle = $langs->trans(
"CreditNotes");
600 $alreadypayedlabel = $langs->trans(
'Received');
601 $multicurrencyalreadypayedlabel = $langs->trans(
'MulticurrencyReceived');
602 if ($facture->type == 2) {
603 $alreadypayedlabel = $langs->trans(
"PaidBack");
604 $multicurrencyalreadypayedlabel = $langs->trans(
"MulticurrencyPaidBack");
606 $remaindertopay = $langs->trans(
'RemainderToTake');
607 $multicurrencyremaindertopay = $langs->trans(
'MulticurrencyRemainderToTake');
608 if ($facture->type == 2) {
609 $remaindertopay = $langs->trans(
"RemainderToPayBack");
610 $multicurrencyremaindertopay = $langs->trans(
"MulticurrencyRemainderToPayBack");
617 print
'<div class="div-table-responsive-no-min">';
618 print
'<table class="noborder centpercent">';
620 print
'<tr class="liste_titre">';
621 print
'<td>'.$arraytitle.
'</td>';
622 print
'<td class="center">'.$langs->trans(
'Date').
'</td>';
623 print
'<td class="center">'.$langs->trans(
'DateMaxPayment').
'</td>';
624 if (isModEnabled(
'multicurrency')) {
625 print
'<td>'.$langs->trans(
'Currency').
'</td>';
626 print
'<td class="right">'.$langs->trans(
'MulticurrencyAmountTTC').
'</td>';
627 print
'<td class="right">'.$multicurrencyalreadypayedlabel.
'</td>';
628 print
'<td class="right">'.$multicurrencyremaindertopay.
'</td>';
629 print
'<td class="right">'.$langs->trans(
'MulticurrencyPaymentAmount').
'</td>';
631 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
632 print
'<td class="right">'.$alreadypayedlabel.
'</td>';
633 print
'<td class="right">'.$remaindertopay.
'</td>';
634 print
'<td class="right">'.$langs->trans(
'PaymentAmount').
'</td>';
636 $parameters = array();
637 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $facture, $action);
639 print
'<td align="right"> </td>';
644 $totalrecucreditnote = 0;
645 $totalrecudeposits = 0;
648 $objp = $db->fetch_object($resql);
656 $soc->fetch($objp->socid);
659 $invoice->fetch($objp->facid);
660 $paiement = $invoice->getSommePaiement();
661 $creditnotes = $invoice->getSumCreditNotesUsed();
662 $deposits = $invoice->getSumDepositsUsed();
663 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
664 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
667 if (isModEnabled(
'multicurrency')) {
668 $multicurrency_payment = $invoice->getSommePaiement(1);
669 $multicurrency_creditnotes = $invoice->getSumCreditNotesUsed(1);
670 $multicurrency_deposits = $invoice->getSumDepositsUsed(1);
671 $multicurrency_alreadypayed =
price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,
'MT');
672 $multicurrency_remaintopay =
price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,
'MT');
674 $tootltiponmulticurrencyfullamount = $langs->trans(
'AmountHT') .
": " .
price($objp->multicurrency_total_ht, 0, $langs, 0, -1, -1, $objp->multicurrency_code) .
"<br>";
675 $tootltiponmulticurrencyfullamount .= $langs->trans(
'AmountVAT') .
": " .
price($objp->multicurrency_total_tva, 0, $langs, 0, -1, -1, $objp->multicurrency_code) .
"<br>";
676 $tootltiponmulticurrencyfullamount .= $langs->trans(
'AmountTTC') .
": " .
price($objp->multicurrency_total_ttc, 0, $langs, 0, -1, -1, $objp->multicurrency_code) .
"<br>";
680 $tootltiponfullamount = $langs->trans(
'AmountHT') .
": " .
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
"<br>";
681 $tootltiponfullamount .= $langs->trans(
'AmountVAT') .
": " .
price($objp->total_tva, 0, $langs, 0, -1, -1, $conf->currency) .
"<br>";
682 $tootltiponfullamount .= $langs->trans(
'AmountTTC') .
": " .
price($objp->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) .
"<br>";
684 print
'<tr class="oddeven'.(($invoice->id == $facid) ?
' highlight' :
'').
'">';
686 print
'<td class="nowraponall">';
687 print $invoice->getNomUrl(1,
'');
688 if ($objp->socid != $facture->thirdparty->id) {
689 print
' - '.$soc->getNomUrl(1).
' ';
694 print
'<td class="center">'.dol_print_date($db->jdate($objp->df),
'day').
"</td>\n";
697 if ($objp->dlr > 0) {
698 print
'<td class="nowraponall center">';
701 if ($invoice->hasDelay()) {
707 print
'<td align="center"></td>';
711 if (isModEnabled(
'multicurrency')) {
712 print
'<td class="center">'.$objp->multicurrency_code.
"</td>\n";
716 if (isModEnabled(
'multicurrency')) {
717 print
'<td class="right">';
718 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
719 print
'<span class="amount classfortooltip" title="'.$tootltiponmulticurrencyfullamount.
'">' .
price($sign * $objp->multicurrency_total_ttc);
721 print
'</span></td>';
724 print
'<td class="right">';
725 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
726 print
price($sign * $multicurrency_payment);
727 if ($multicurrency_creditnotes) {
728 print
'+'.price($multicurrency_creditnotes);
730 if ($multicurrency_deposits) {
731 print
'+'.price($multicurrency_deposits);
737 print
'<td class="right">';
738 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
739 print
price($sign * (
float) $multicurrency_remaintopay);
743 print
'<td class="right nowraponall">';
746 $namef =
'multicurrency_amount_'.$objp->facid;
747 $nameRemain =
'multicurrency_remain_'.$objp->facid;
749 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
750 if ($action !=
'add_paiement') {
751 if (!empty($conf->use_javascript_ajax)) {
752 print
img_picto(
"Auto fill",
'rightarrow',
"class='AutoFillAmount' data-rowname='".$namef.
"' data-value='".($sign * (
float) $multicurrency_remaintopay).
"'");
754 print
'<input type="text" class="maxwidth75 multicurrency_amount" name="'.$namef.
'" value="'.(
GETPOST($namef) !=
'0' ?
GETPOST($namef) :
'').
'">';
755 print
'<input type="hidden" class="multicurrency_remain" name="'.$nameRemain.
'" value="'.$multicurrency_remaintopay.
'">';
757 print
'<input type="text" class="maxwidth75" name="'.$namef.
'_disabled" value="'.(
GETPOST($namef) !=
'0' ?
GETPOST($namef) :
'').
'" disabled>';
758 print
'<input type="hidden" name="'.$namef.
'" value="'.
GETPOST($namef).
'">';
765 print
'<td class="right"><span class="amount classfortooltip" title="'.$tootltiponfullamount.
'">'.
price($sign * $objp->total_ttc).
'</span></td>';
768 print
'<td class="right"><span class="amount">'.price($sign * $paiement);
770 print
'<span class="opacitymedium">+'.price($creditnotes).
'</span>';
773 print
'<span class="opacitymedium">+'.price($deposits).
'</span>';
775 print
'</span></td>';
778 print
'<td class="right">';
779 print
price($sign * (
float) $remaintopay);
780 if (isModEnabled(
'prelevement')) {
781 $numdirectdebitopen = 0;
782 $totaldirectdebit = 0;
783 $sql =
"SELECT COUNT(pfd.rowid) as nb, SUM(pfd.amount) as amount";
784 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
785 $sql .=
" WHERE fk_facture = ".((int) $objp->facid);
786 $sql .=
" AND pfd.traite = 0";
787 $sql .=
" AND pfd.ext_payment_id IS NULL";
789 $result_sql = $db->query($sql);
791 $obj = $db->fetch_object($result_sql);
792 $numdirectdebitopen = $obj->nb;
793 $totaldirectdebit = $obj->amount;
797 if ($numdirectdebitopen) {
798 $langs->load(
"withdrawals");
799 print
img_warning($langs->trans(
"WarningSomeDirectDebitOrdersAlreadyExists", $numdirectdebitopen,
price(
price2num($totaldirectdebit,
'MT'), 0, $langs, 1, -1, -1, $conf->currency)),
'',
'classfortooltip');
806 print
'<td class="right nowraponall">';
809 $namef =
'amount_'.$objp->facid;
810 $nameRemain =
'remain_'.$objp->facid;
812 if ($action !=
'add_paiement') {
813 if (!empty($conf->use_javascript_ajax)) {
814 print
img_picto(
"Auto fill",
'rightarrow',
"class='AutoFillAmount' data-rowname='".$namef.
"' data-value='".($sign * (
float) $remaintopay).
"'");
816 print
'<input type="text" class="maxwidth75 amount" id="'.$namef.
'" name="'.$namef.
'" value="'.
dol_escape_htmltag(
GETPOST($namef)).
'">';
817 print
'<input type="hidden" class="remain" name="'.$nameRemain.
'" value="'.$remaintopay.
'">';
819 print
'<input type="text" class="maxwidth75" name="'.$namef.
'_disabled" value="'.
dol_escape_htmltag(
GETPOST($namef)).
'" disabled>';
824 $parameters = array();
825 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $objp, $action);
828 print
'<td align="center" width="16">';
830 if (!empty($amounts[$invoice->id]) && (abs((
float) $amounts[$invoice->id]) > abs((
float) $amountsresttopay[$invoice->id]))
831 || !empty($multicurrency_amounts[$invoice->id]) && (abs((
float) $multicurrency_amounts[$invoice->id]) > abs((
float) $multicurrency_amountsresttopay[$invoice->id]))) {
832 print
' '.img_warning($langs->trans(
"PaymentHigherThanReminderToPay"));
838 $total_ttc += $objp->total_ttc;
839 $totalrecu += $paiement;
840 $totalrecucreditnote += $creditnotes;
841 $totalrecudeposits += $deposits;
847 print
'<tr class="liste_total">';
848 print
'<td colspan="3" class="left">'.$langs->trans(
'TotalTTC').
'</td>';
849 if (isModEnabled(
'multicurrency')) {
854 print
'<td class="right" id="multicurrency_result" style="font-weight: bold;"></td>';
856 print
'<td class="right"><b>'.price($sign * $total_ttc).
'</b></td>';
857 print
'<td class="right"><b>'.price($sign * $totalrecu);
858 if ($totalrecucreditnote) {
859 print
'+'.price($totalrecucreditnote);
861 if ($totalrecudeposits) {
862 print
'+'.price($totalrecudeposits);
865 print
'<td class="right"><b>'.price($sign * (
float)
price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,
'MT')).
'</b></td>';
866 print
'<td class="right" id="result" style="font-weight: bold;"></td>';
867 print
'<td align="center"> </td>';
881 if ($action !=
'add_paiement') {
882 $checkboxlabel = $langs->trans(
"ClosePaidInvoicesAutomatically");
884 $checkboxlabel = $langs->trans(
"ClosePaidCreditNotesAutomatically");
886 $buttontitle = $langs->trans(
'ToMakePayment');
888 $buttontitle = $langs->trans(
'ToMakePaymentBack');
891 print
'<br><div class="center">';
892 print
'<input type="checkbox" checked name="closepaidinvoices" id="closepaidinvoices"><label for="closepaidinvoices"> '.$checkboxlabel.
'</label>';
897 print
'<br><input type="submit" class="button reposition" value="'.dol_escape_htmltag($buttontitle).
'"><br><br>';
902 if ($action ==
'add_paiement') {
903 $preselectedchoice = $addwarning ?
'no' :
'yes';
906 if (!empty($totalpayment)) {
907 $text = $langs->trans(
'ConfirmCustomerPayment', $totalpayment, $langs->transnoentitiesnoconv(
"Currency".$conf->currency));
909 if (!empty($multicurrency_totalpayment)) {
910 $text .=
'<br>'.$langs->trans(
'ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->transnoentitiesnoconv(
"paymentInInvoiceCurrency"));
912 if (
GETPOST(
'closepaidinvoices')) {
913 $text .=
'<br>'.$langs->trans(
"AllCompletelyPayedInvoiceWillBeClosed");
914 print
'<input type="hidden" name="closepaidinvoices" value="'.GETPOST(
'closepaidinvoices').
'">';
916 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$facture->id.
'&socid='.$facture->socid.
'&type='.$facture->type, $langs->trans(
'ReceivedCustomersPayments'), $text,
'confirm_paiement', $formquestion, $preselectedchoice);
920 $parameters = array(
'formConfirm' => $formconfirm);
921 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
922 if (empty($reshook)) {
923 $formconfirm .= $hookmanager->resPrint;
924 } elseif ($reshook > 0) {
925 $formconfirm = $hookmanager->resPrint;
939if (!
GETPOST(
'action',
'aZ09')) {
940 if (empty($page) || $page == -1) {
944 $offset = $limit * $page;
950 $sortfield =
'p.datep';
953 $sql =
'SELECT p.datep as dp, p.amount, f.total_ttc as fa_amount, f.ref';
954 $sql .=
', f.rowid as facid, c.libelle as paiement_type, p.num_paiement as num_payment';
955 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
956 $sql .=
', '.MAIN_DB_PREFIX.
'facture as f';
957 $sql .=
' WHERE p.fk_facture = f.rowid';
958 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
960 $sql .=
' AND f.fk_soc = '.((int) $socid);
963 $sql .= $db->order($sortfield, $sortorder);
964 $sql .= $db->plimit($limit + 1, $offset);
965 $resql = $db->query($sql);
968 $num = $db->num_rows($resql);
971 print_barre_liste($langs->trans(
'Payments'), $page, $_SERVER[
"PHP_SELF"],
'', $sortfield, $sortorder,
'', $num);
972 print
'<table class="noborder centpercent">';
973 print
'<tr class="liste_titre">';
977 print_liste_field_titre(
'Amount', $_SERVER[
"PHP_SELF"],
'p.amount',
'',
'',
'', $sortfield, $sortorder,
'right ');
981 while ($i < min($num, $limit)) {
982 $objp = $db->fetch_object($resql);
984 print
'<tr class="oddeven">';
985 print
'<td><a href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$objp->facid.
'">'.$objp->ref.
"</a></td>\n";
986 print
'<td>'.dol_print_date($db->jdate($objp->dp)).
"</td>\n";
987 print
'<td>'.$objp->paiement_type.
' '.$objp->num_payment.
"</td>\n";
988 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
989 print
'<td> </td>';
992 $parameters = array();
993 $reshook = $hookmanager->executeHooks(
'printObjectLine', $parameters, $objp, $action);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage payments of customer invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
currentToken()
Return the value of token currently saved into session with name 'token'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.