33 require
'../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
40 $langs->loadLangs(array(
'companies',
'bills',
'banks',
'multicurrency'));
42 $action =
GETPOST(
'action',
'alpha');
43 $confirm =
GETPOST(
'confirm',
'alpha');
45 $facid =
GETPOST(
'facid',
'int');
46 $accountid =
GETPOST(
'accountid',
'int');
47 $paymentnum =
GETPOST(
'num_paiement',
'alpha');
48 $socid =
GETPOST(
'socid',
'int');
50 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
51 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
55 $amountsresttopay = array();
58 $multicurrency_amounts = array();
59 $multicurrency_amountsresttopay = array();
62 if ($user->socid > 0) {
63 $socid = $user->socid;
70 $ret = $object->fetch($facid);
74 $hookmanager->initHooks(array(
'paiementcard',
'globalcard'));
76 $formquestion = array();
78 $usercanissuepayment = !empty($user->rights->facture->paiement);
82 $result =
restrictedArea($user,
'facture', $object->id,
'',
'',
'fk_soc', $fieldid, $isdraft);
89 $parameters = array(
'socid'=>$socid);
90 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
95 if (empty($reshook)) {
96 if (($action ==
'add_paiement' || ($action ==
'confirm_paiement' && $confirm ==
'yes')) && $usercanissuepayment) {
102 $multicurrency_totalpayment = 0;
103 $atleastonepaymentnotnull = 0;
104 $formquestion = array();
108 $tmpinvoice =
new Facture($db);
109 foreach ($_POST as $key => $value) {
110 if (substr($key, 0, 7) ==
'amount_' &&
GETPOST($key) !=
'') {
111 $cursorfacid = substr($key, 7);
113 $totalpayment = $totalpayment + $amounts[$cursorfacid];
114 if (!empty($amounts[$cursorfacid])) {
115 $atleastonepaymentnotnull++;
117 $result = $tmpinvoice->fetch($cursorfacid);
121 $amountsresttopay[$cursorfacid] =
price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
122 if ($amounts[$cursorfacid]) {
124 if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) {
126 $formquestion[
'text'] =
img_warning($langs->trans(
"PaymentHigherThanReminderToPay")).
' '.$langs->trans(
"HelpPaymentHigherThanReminderToPay");
129 if ($datepaye && ($datepaye < $tmpinvoice->date)) {
130 $langs->load(
"errors");
136 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' => $key,
'value' =>
GETPOST($key));
137 } elseif (substr($key, 0, 21) ==
'multicurrency_amount_') {
138 $cursorfacid = substr($key, 21);
140 $multicurrency_totalpayment += floatval($multicurrency_amounts[$cursorfacid]);
141 if (!empty($multicurrency_amounts[$cursorfacid])) {
142 $atleastonepaymentnotnull++;
144 $result = $tmpinvoice->fetch($cursorfacid);
148 $multicurrency_amountsresttopay[$cursorfacid] =
price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1));
149 if ($multicurrency_amounts[$cursorfacid]) {
151 if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid]))) {
153 $formquestion[
'text'] =
img_warning($langs->trans(
"PaymentHigherThanReminderToPay")).
' '.$langs->trans(
"HelpPaymentHigherThanReminderToPay");
156 if ($datepaye && ($datepaye < $tmpinvoice->date)) {
157 $langs->load(
"errors");
163 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' => $key,
'value' =>
GETPOST($key,
'int'));
168 if (!
GETPOST(
'paiementcode')) {
169 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'PaymentMode')),
null,
'errors');
175 if (
GETPOST(
'accountid') <= 0) {
176 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'AccountToCredit')),
null,
'errors');
181 if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) {
182 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->trans(
'PaymentAmount')),
null,
'errors');
186 if (empty($datepaye)) {
187 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'Date')),
null,
'errors');
192 if ($totalpayment > 0 && $multicurrency_totalpayment > 0) {
193 $langs->load(
"errors");
194 setEventMessages($langs->transnoentities(
'ErrorPaymentInBothCurrency'),
null,
'errors');
202 if ($action ==
'add_paiement') {
212 if ($action ==
'confirm_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
219 $thirdparty =
new Societe($db);
221 $thirdparty->fetch($socid);
224 $multicurrency_code = array();
227 foreach ($amounts as $key => $value) {
228 $tmpinvoice =
new Facture($db);
229 $tmpinvoice->fetch($key);
232 $amounts[$key] = - abs($newvalue);
234 $multicurrency_code[$key] = $tmpinvoice->multicurrency_code;
237 foreach ($multicurrency_amounts as $key => $value) {
238 $tmpinvoice =
new Facture($db);
239 $tmpinvoice->fetch($key);
242 $multicurrency_amounts[$key] = - abs($newvalue);
244 $multicurrency_code[$key] = $tmpinvoice->multicurrency_code;
249 if (
GETPOST(
'accountid',
'int') <= 0) {
250 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'AccountToCredit')),
null,
'errors');
257 $paiement->datepaye = $datepaye;
258 $paiement->amounts = $amounts;
259 $paiement->multicurrency_amounts = $multicurrency_amounts;
260 $paiement->multicurrency_code = $multicurrency_code;
262 $paiement->num_payment =
GETPOST(
'num_paiement',
'alpha');
263 $paiement->note_private =
GETPOST(
'comment',
'alpha');
264 $paiement->fk_account =
GETPOST(
'accountid',
'int');
270 $paiement_id = $paiement->create($user, (
GETPOST(
'closepaidinvoices') ==
'on' ? 1 : 0), $thirdparty);
271 if ($paiement_id < 0) {
278 $label =
'(CustomerInvoicePayment)';
280 $label =
'(CustomerInvoicePaymentBack)';
282 $result = $paiement->addPaymentToBank($user,
'payment', $label,
GETPOST(
'accountid',
'int'),
GETPOST(
'chqemetteur'),
GETPOST(
'chqbank'));
294 foreach ($paiement->amounts as $key => $amount) {
296 if (is_numeric($amount) && $amount <> 0) {
297 if ($invoiceid != 0) {
304 if ($invoiceid > 0) {
305 $loc = DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$invoiceid;
307 $loc = DOL_URL_ROOT.
'/compta/paiement/card.php?id='.$paiement_id;
309 header(
'Location: '.$loc);
329 if ($action ==
'create' || $action ==
'confirm_paiement' || $action ==
'add_paiement') {
331 $result = $facture->fetch($facid);
334 $facture->fetch_thirdparty();
338 $title .= $langs->trans(
"EnterPaymentReceivedFromCustomer");
341 $title .= $langs->trans(
"EnterPaymentDueToCustomer");
346 if ($action ==
'add_paiement') {
349 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'facid',
'value' => $facture->id);
350 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'socid',
'value' => $facture->socid);
351 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'type',
'value' => $facture->type);
356 if (!empty($conf->paypalplus->enabled) && $conf->global->PAYPAL_ENABLE_TRANSACTION_MANAGEMENT && !empty($facture->ref_ext)) {
357 if (!empty($conf->global->PAYPAL_BANK_ACCOUNT)) {
358 $accountid = $conf->global->PAYPAL_BANK_ACCOUNT;
360 $paymentnum = $facture->ref_ext;
364 if (!empty($conf->use_javascript_ajax)) {
365 print
"\n".
'<script type="text/javascript">';
366 print
'$(document).ready(function () {
369 $("#selectpaiementcode").change(function() {
373 function setPaiementCode()
375 var code = $("#selectpaiementcode option:selected").val();
376 console.log("setPaiementCode code="+code);
378 if (code == \'CHQ\' || code == \'VIR\')
382 $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
384 if ($(\'#fieldchqemetteur\').val() == \'\')
387 $(\'#fieldchqemetteur\').val(emetteur);
392 $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
393 $(\'#fieldchqemetteur\').val(\'\');
397 function _elemToJson(selector)
400 $.map(selector.serializeArray(), function(n,i)
402 subJson[n["name"]] = n["value"];
407 function callForResult(imgId)
410 var form = $("#payment_form");
412 json["invoice_type"] = $("#invoice_type").val();
413 json["amountPayment"] = $("#amountpayment").attr("value");
414 json["amounts"] = _elemToJson(form.find("input.amount"));
415 json["remains"] = _elemToJson(form.find("input.remain"));
418 json["imgClicked"] = imgId;
421 $.post("'.DOL_URL_ROOT.
'/compta/ajaxpayment.php", json, function(data)
423 json = $.parseJSON(data);
427 for (var key in json)
429 if (key == "result") {
430 if (json["makeRed"]) {
431 $("#"+key).addClass("error");
433 $("#"+key).removeClass("error");
435 json[key]=json["label"]+" "+json[key];
436 $("#"+key).text(json[key]);
437 } else {console.log(key);
438 form.find("input[name*=\""+key+"\"]").each(function() {
439 $(this).attr("value", json[key]);
445 $("#payment_form").find("input.amount").change(function() {
448 $("#payment_form").find("input.amount").keyup(function() {
456 print
' $(document).ready(function () {';
457 print
' $(".AutoFillAmout").on(\'click touchstart\', function(){
458 $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
462 print
' </script>'.
"\n";
465 print
'<form id="payment_form" name="add_paiement" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
466 print
'<input type="hidden" name="token" value="'.newToken().
'">';
467 print
'<input type="hidden" name="action" value="add_paiement">';
468 print
'<input type="hidden" name="facid" value="'.$facture->id.
'">';
469 print
'<input type="hidden" name="socid" value="'.$facture->socid.
'">';
470 print
'<input type="hidden" name="type" id="invoice_type" value="'.$facture->type.
'">';
471 print
'<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($facture->thirdparty->name).
'">';
475 print
'<table class="border centpercent">';
478 print
'<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans(
'Company').
'</span></td><td>'.$facture->thirdparty->getNomUrl(4).
"</td></tr>\n";
481 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
'Date').
'</span></td><td>';
483 $datepayment = ($datepayment ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $datepayment);
484 print
$form->selectDate($datepayment,
'',
'',
'', 0,
"add_paiement", 1, 1, 0,
'',
'', $facture->date);
488 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
'PaymentMode').
'</span></td><td>';
489 $form->select_types_paiements((
GETPOST(
'paiementcode') ?
GETPOST(
'paiementcode') : $facture->mode_reglement_code),
'paiementcode',
'', 2);
496 if ($facture->type != 2) {
497 print
'<td><span class="fieldrequired">'.$langs->trans(
'AccountToCredit').
'</span></td>';
499 if ($facture->type == 2) {
500 print
'<td><span class="fieldrequired">'.$langs->trans(
'AccountToDebit').
'</span></td>';
505 print
$form->select_comptes($accountid,
'accountid', 0,
'', 2,
'', 0,
'widthcentpercentminusx maxwidth500', 1);
508 print
'<td> </td>';
513 print
'<tr><td>'.$langs->trans(
'Numero');
514 print
' <em class="opacitymedium">('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
516 print
'<td><input name="num_paiement" type="text" class="maxwidth200" value="'.$paymentnum.
'"></td></tr>';
519 print
'<tr><td class="'.(GETPOST(
'paiementcode') ==
'CHQ' ?
'fieldrequired ' :
'').
'fieldrequireddyn">'.$langs->trans(
'CheckTransmitter');
520 print
' <em class="opacitymedium">('.$langs->trans(
"ChequeMaker").
')</em>';
522 print
'<td><input id="fieldchqemetteur" class="maxwidth300" name="chqemetteur" type="text" value="'.GETPOST(
'chqemetteur',
'alphanohtml').
'"></td></tr>';
525 print
'<tr><td>'.$langs->trans(
'Bank');
526 print
' <em class="opacitymedium">('.$langs->trans(
"ChequeBank").
')</em>';
528 print
'<td><input name="chqbank" class="maxwidth300" type="text" value="'.GETPOST(
'chqbank',
'alphanohtml').
'"></td></tr>';
531 print
'<tr><td>'.$langs->trans(
'Comments').
'</td>';
532 print
'<td class="tdtop">';
533 print
'<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.
'">'.
GETPOST(
'comment',
'restricthtml').
'</textarea>';
545 $sql =
'SELECT f.rowid as facid, f.ref, f.total_ttc, f.multicurrency_code, f.multicurrency_total_ttc, f.type,';
546 $sql .=
' f.datef as df, f.fk_soc as socid, f.date_lim_reglement as dlr';
547 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture as f';
548 $sql .=
' WHERE f.entity IN ('.getEntity(
'facture').
')';
549 $sql .=
' AND (f.fk_soc = '.((int) $facture->socid);
551 if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) {
552 $sql .=
' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe WHERE parent = '.((int) $facture->thirdparty->parent).
')';
555 if (!empty($conf->global->FACTURE_PAYMENTS_ON_SUBSIDIARY_COMPANIES)) {
556 $sql .=
' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe WHERE parent = '.((int) $facture->thirdparty->id).
')';
558 $sql .=
') AND f.paye = 0';
559 $sql .=
' AND f.fk_statut = 1';
561 $sql .=
' AND type IN (0,1,3,5)';
563 $sql .=
' AND type = 2';
566 $sql .=
' ORDER BY f.datef ASC, f.ref ASC';
568 $resql = $db->query($sql);
570 $num = $db->num_rows(
$resql);
572 $arraytitle = $langs->trans(
'Invoice');
573 if ($facture->type == 2) {
574 $arraytitle = $langs->trans(
"CreditNotes");
576 $alreadypayedlabel = $langs->trans(
'Received');
577 $multicurrencyalreadypayedlabel = $langs->trans(
'MulticurrencyReceived');
578 if ($facture->type == 2) {
579 $alreadypayedlabel = $langs->trans(
"PaidBack");
580 $multicurrencyalreadypayedlabel = $langs->trans(
"MulticurrencyPaidBack");
582 $remaindertopay = $langs->trans(
'RemainderToTake');
583 $multicurrencyremaindertopay = $langs->trans(
'MulticurrencyRemainderToTake');
584 if ($facture->type == 2) {
585 $remaindertopay = $langs->trans(
"RemainderToPayBack");
586 $multicurrencyremaindertopay = $langs->trans(
"MulticurrencyRemainderToPayBack");
593 print
'<div class="div-table-responsive-no-min">';
594 print
'<table class="noborder centpercent">';
596 print
'<tr class="liste_titre">';
597 print
'<td>'.$arraytitle.
'</td>';
598 print
'<td class="center">'.$langs->trans(
'Date').
'</td>';
599 print
'<td class="center">'.$langs->trans(
'DateMaxPayment').
'</td>';
601 print
'<td>'.$langs->trans(
'Currency').
'</td>';
602 print
'<td class="right">'.$langs->trans(
'MulticurrencyAmountTTC').
'</td>';
603 print
'<td class="right">'.$multicurrencyalreadypayedlabel.
'</td>';
604 print
'<td class="right">'.$multicurrencyremaindertopay.
'</td>';
605 print
'<td class="right">'.$langs->trans(
'MulticurrencyPaymentAmount').
'</td>';
607 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
608 print
'<td class="right">'.$alreadypayedlabel.
'</td>';
609 print
'<td class="right">'.$remaindertopay.
'</td>';
610 print
'<td class="right">'.$langs->trans(
'PaymentAmount').
'</td>';
612 $parameters = array();
613 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $facture, $action);
615 print
'<td align="right"> </td>';
620 $totalrecucreditnote = 0;
621 $totalrecudeposits = 0;
624 $objp = $db->fetch_object(
$resql);
632 $soc->fetch($objp->socid);
635 $invoice->fetch($objp->facid);
636 $paiement = $invoice->getSommePaiement();
637 $creditnotes = $invoice->getSumCreditNotesUsed();
638 $deposits = $invoice->getSumDepositsUsed();
639 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
640 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
644 $multicurrency_payment = $invoice->getSommePaiement(1);
645 $multicurrency_creditnotes = $invoice->getSumCreditNotesUsed(1);
646 $multicurrency_deposits = $invoice->getSumDepositsUsed(1);
647 $multicurrency_alreadypayed =
price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,
'MT');
648 $multicurrency_remaintopay =
price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,
'MT');
652 print
'<tr class="oddeven'.(($invoice->id == $facid) ?
' highlight' :
'').
'">';
654 print
'<td class="nowraponall">';
655 print $invoice->getNomUrl(1,
'');
656 if ($objp->socid != $facture->thirdparty->id) {
657 print
' - '.$soc->getNomUrl(1).
' ';
662 print
'<td class="center">'.dol_print_date($db->jdate($objp->df),
'day').
"</td>\n";
665 if ($objp->dlr > 0) {
666 print
'<td class="nowraponall center">';
669 if ($invoice->hasDelay()) {
675 print
'<td align="center"></td>';
680 print
'<td class="center">'.$objp->multicurrency_code.
"</td>\n";
685 print
'<td class="right">';
686 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
687 print
price($sign * $objp->multicurrency_total_ttc);
692 print
'<td class="right">';
693 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
694 print
price($sign * $multicurrency_payment);
695 if ($multicurrency_creditnotes) {
696 print
'+'.price($multicurrency_creditnotes);
698 if ($multicurrency_deposits) {
699 print
'+'.price($multicurrency_deposits);
705 print
'<td class="right">';
706 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
707 print
price($sign * $multicurrency_remaintopay);
711 print
'<td class="right nowraponall">';
714 $namef =
'multicurrency_amount_'.$objp->facid;
715 $nameRemain =
'multicurrency_remain_'.$objp->facid;
717 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
718 if ($action !=
'add_paiement') {
719 if (!empty($conf->use_javascript_ajax)) {
720 print
img_picto(
"Auto fill",
'rightarrow',
"class='AutoFillAmout' data-rowname='".$namef.
"' data-value='".($sign * $multicurrency_remaintopay).
"'");
722 print
'<input type="text" class="maxwidth75 multicurrency_amount" name="'.$namef.
'" value="'.
GETPOST($namef).
'">';
723 print
'<input type="hidden" class="multicurrency_remain" name="'.$nameRemain.
'" value="'.$multicurrency_remaintopay.
'">';
725 print
'<input type="text" class="maxwidth75" name="'.$namef.
'_disabled" value="'.
GETPOST($namef).
'" disabled>';
726 print
'<input type="hidden" name="'.$namef.
'" value="'.
GETPOST($namef).
'">';
733 print
'<td class="right"><span class="amount">'.price($sign * $objp->total_ttc).
'</span></td>';
736 print
'<td class="right"><span class="amount">'.price($sign * $paiement);
738 print
'<span class="opacitymedium">+'.price($creditnotes).
'</span>';
741 print
'<span class="opacitymedium">+'.price($deposits).
'</span>';
743 print
'</span></td>';
746 print
'<td class="right">';
747 print
price($sign * $remaintopay);
748 if (!empty($conf->prelevement->enabled)) {
749 $numdirectdebitopen = 0;
750 $totaldirectdebit = 0;
751 $sql =
"SELECT COUNT(pfd.rowid) as nb, SUM(pfd.amount) as amount";
752 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_facture_demande as pfd";
753 $sql .=
" WHERE fk_facture = ".((int) $objp->facid);
754 $sql .=
" AND pfd.traite = 0";
755 $sql .=
" AND pfd.ext_payment_id IS NULL";
757 $result_sql = $db->query($sql);
759 $obj = $db->fetch_object($result_sql);
760 $numdirectdebitopen = $obj->nb;
761 $totaldirectdebit = $obj->amount;
765 if ($numdirectdebitopen) {
766 $langs->load(
"withdrawals");
767 print
img_warning($langs->trans(
"WarningSomeDirectDebitOrdersAlreadyExists", $numdirectdebitopen,
price(
price2num($totaldirectdebit,
'MT'), 0, $langs, 1, -1, -1, $conf->currency)),
'',
'classfortooltip');
774 print
'<td class="right nowraponall">';
777 $namef =
'amount_'.$objp->facid;
778 $nameRemain =
'remain_'.$objp->facid;
780 if ($action !=
'add_paiement') {
781 if (!empty($conf->use_javascript_ajax)) {
782 print
img_picto(
"Auto fill",
'rightarrow',
"class='AutoFillAmout' data-rowname='".$namef.
"' data-value='".($sign * $remaintopay).
"'");
785 print
'<input type="hidden" class="remain" name="'.$nameRemain.
'" value="'.$remaintopay.
'">';
787 print
'<input type="text" class="maxwidth75" name="'.$namef.
'_disabled" value="'.
dol_escape_htmltag(
GETPOST($namef)).
'" disabled>';
792 $parameters = array();
793 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $objp, $action);
796 print
'<td align="center" width="16">';
798 if (!empty($amounts[$invoice->id]) && (abs($amounts[$invoice->id]) > abs($amountsresttopay[$invoice->id]))
799 || !empty($multicurrency_amounts[$invoice->id]) && (abs($multicurrency_amounts[$invoice->id]) > abs($multicurrency_amountsresttopay[$invoice->id]))) {
800 print
' '.img_warning($langs->trans(
"PaymentHigherThanReminderToPay"));
806 $total_ttc += $objp->total_ttc;
807 $totalrecu += $paiement;
808 $totalrecucreditnote += $creditnotes;
809 $totalrecudeposits += $deposits;
815 print
'<tr class="liste_total">';
816 print
'<td colspan="3" class="left">'.$langs->trans(
'TotalTTC').
'</td>';
822 print
'<td class="right" id="multicurrency_result" style="font-weight: bold;"></td>';
824 print
'<td class="right"><b>'.price($sign * $total_ttc).
'</b></td>';
825 print
'<td class="right"><b>'.price($sign * $totalrecu);
826 if ($totalrecucreditnote) {
827 print
'+'.price($totalrecucreditnote);
829 if ($totalrecudeposits) {
830 print
'+'.price($totalrecudeposits);
833 print
'<td class="right"><b>'.price($sign *
price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,
'MT')).
'</b></td>';
834 print
'<td class="right" id="result" style="font-weight: bold;"></td>';
835 print
'<td align="center"> </td>';
849 if ($action !=
'add_paiement') {
850 $checkboxlabel = $langs->trans(
"ClosePaidInvoicesAutomatically");
852 $checkboxlabel = $langs->trans(
"ClosePaidCreditNotesAutomatically");
854 $buttontitle = $langs->trans(
'ToMakePayment');
856 $buttontitle = $langs->trans(
'ToMakePaymentBack');
859 print
'<br><div class="center">';
860 print
'<input type="checkbox" checked name="closepaidinvoices"> '.$checkboxlabel;
866 print
'<br><input type="submit" class="button" value="'.dol_escape_htmltag($buttontitle).
'"><br><br>';
871 if ($action ==
'add_paiement') {
872 $preselectedchoice = $addwarning ?
'no' :
'yes';
875 if (!empty($totalpayment)) {
876 $text = $langs->trans(
'ConfirmCustomerPayment', $totalpayment, $langs->trans(
"Currency".$conf->currency));
878 if (!empty($multicurrency_totalpayment)) {
879 $text .=
'<br>'.$langs->trans(
'ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->trans(
"paymentInInvoiceCurrency"));
881 if (
GETPOST(
'closepaidinvoices')) {
882 $text .=
'<br>'.$langs->trans(
"AllCompletelyPayedInvoiceWillBeClosed");
883 print
'<input type="hidden" name="closepaidinvoices" value="'.GETPOST(
'closepaidinvoices').
'">';
885 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$facture->id.
'&socid='.$facture->socid.
'&type='.$facture->type, $langs->trans(
'ReceivedCustomersPayments'), $text,
'confirm_paiement', $formquestion, $preselectedchoice);
890 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
891 if (empty($reshook)) {
893 } elseif ($reshook > 0) {
908 if (!
GETPOST(
'action',
'aZ09')) {
909 if (empty($page) || $page == -1) {
912 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
913 $offset = $limit * $page;
919 $sortfield =
'p.datep';
922 $sql =
'SELECT p.datep as dp, p.amount, f.total_ttc as fa_amount, f.ref';
923 $sql .=
', f.rowid as facid, c.libelle as paiement_type, p.num_paiement as num_payment';
924 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
925 $sql .=
', '.MAIN_DB_PREFIX.
'facture as f';
926 $sql .=
' WHERE p.fk_facture = f.rowid';
927 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
929 $sql .=
' AND f.fk_soc = '.((int) $socid);
932 $sql .= $db->order($sortfield, $sortorder);
933 $sql .= $db->plimit($limit + 1, $offset);
934 $resql = $db->query($sql);
937 $num = $db->num_rows(
$resql);
940 print_barre_liste($langs->trans(
'Payments'), $page, $_SERVER[
"PHP_SELF"],
'', $sortfield, $sortorder,
'', $num);
941 print
'<table class="noborder centpercent">';
942 print
'<tr class="liste_titre">';
946 print_liste_field_titre(
'Amount', $_SERVER[
"PHP_SELF"],
'p.amount',
'',
'',
'', $sortfield, $sortorder,
'right ');
950 while ($i < min($num, $limit)) {
951 $objp = $db->fetch_object(
$resql);
953 print
'<tr class="oddeven">';
954 print
'<td><a href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$objp->facid.
'">'.$objp->ref.
"</a></td>\n";
955 print
'<td>'.dol_print_date($db->jdate($objp->dp)).
"</td>\n";
956 print
'<td>'.$objp->paiement_type.
' '.$objp->num_payment.
"</td>\n";
957 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
958 print
'<td> </td>';
961 $parameters = array();
962 $reshook = $hookmanager->executeHooks(
'printObjectLine', $parameters, $objp, $action);