36require
'../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
43$langs->loadLangs(array(
'companies',
'bills',
'banks',
'multicurrency'));
45$action =
GETPOST(
'action',
'alpha');
46$confirm =
GETPOST(
'confirm',
'alpha');
48$facid =
GETPOST(
'facid',
'int');
49$accountid =
GETPOST(
'accountid',
'int');
50$paymentnum =
GETPOST(
'num_paiement',
'alpha');
51$socid =
GETPOST(
'socid',
'int');
53$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
54$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
55$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
58$amountsresttopay = array();
61$multicurrency_amounts = array();
62$multicurrency_amountsresttopay = array();
65if ($user->socid > 0) {
66 $socid = $user->socid;
73 $ret = $object->fetch($facid);
77$hookmanager->initHooks(array(
'paiementcard',
'globalcard'));
79$formquestion = array();
81$usercanissuepayment = $user->hasRight(
'facture',
'paiement');
85$result =
restrictedArea($user,
'facture', $object->id,
'',
'',
'fk_soc', $fieldid, $isdraft);
92$parameters = array(
'socid'=>$socid);
93$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
99 if (($action ==
'add_paiement' || ($action ==
'confirm_paiement' && $confirm ==
'yes')) && $usercanissuepayment) {
105 $multicurrency_totalpayment = 0;
106 $atleastonepaymentnotnull = 0;
107 $formquestion = array();
111 $tmpinvoice =
new Facture($db);
112 foreach ($_POST as $key => $value) {
113 if (substr($key, 0, 7) ==
'amount_' &&
GETPOST($key) !=
'') {
114 $cursorfacid = substr($key, 7);
116 $totalpayment = $totalpayment + $amounts[$cursorfacid];
117 if (!empty($amounts[$cursorfacid])) {
118 $atleastonepaymentnotnull++;
120 $result = $tmpinvoice->fetch($cursorfacid);
124 $amountsresttopay[$cursorfacid] =
price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
125 if ($amounts[$cursorfacid]) {
127 if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) {
129 $formquestion[
'text'] =
img_warning($langs->trans(
"PaymentHigherThanReminderToPay")).
' '.$langs->trans(
"HelpPaymentHigherThanReminderToPay");
132 if ($datepaye && ($datepaye < $tmpinvoice->date)) {
133 $langs->load(
"errors");
139 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' => $key,
'value' =>
GETPOST($key));
140 } elseif (substr($key, 0, 21) ==
'multicurrency_amount_') {
141 $cursorfacid = substr($key, 21);
143 $multicurrency_totalpayment += floatval($multicurrency_amounts[$cursorfacid]);
144 if (!empty($multicurrency_amounts[$cursorfacid])) {
145 $atleastonepaymentnotnull++;
147 $result = $tmpinvoice->fetch($cursorfacid);
151 $multicurrency_amountsresttopay[$cursorfacid] =
price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1));
152 if ($multicurrency_amounts[$cursorfacid]) {
154 if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid]))) {
156 $formquestion[
'text'] =
img_warning($langs->trans(
"PaymentHigherThanReminderToPay")).
' '.$langs->trans(
"HelpPaymentHigherThanReminderToPay");
159 if ($datepaye && ($datepaye < $tmpinvoice->date)) {
160 $langs->load(
"errors");
166 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' => $key,
'value' =>
GETPOST($key,
'int'));
171 if (!
GETPOST(
'paiementcode')) {
172 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'PaymentMode')),
null,
'errors');
176 if (isModEnabled(
"banque")) {
178 if (
GETPOST(
'accountid') <= 0) {
179 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'AccountToCredit')),
null,
'errors');
184 if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) {
185 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->trans(
'PaymentAmount')),
null,
'errors');
189 if (empty($datepaye)) {
190 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'Date')),
null,
'errors');
195 if ($totalpayment > 0 && $multicurrency_totalpayment > 0) {
196 $langs->load(
"errors");
197 setEventMessages($langs->transnoentities(
'ErrorPaymentInBothCurrency'),
null,
'errors');
205 if ($action ==
'add_paiement') {
215 if ($action ==
'confirm_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
222 $thirdparty =
new Societe($db);
224 $thirdparty->fetch($socid);
227 $multicurrency_code = array();
228 $multicurrency_tx = array();
231 foreach ($amounts as $key => $value) {
232 $tmpinvoice =
new Facture($db);
233 $tmpinvoice->fetch($key);
236 $amounts[$key] = - abs($newvalue);
238 $multicurrency_code[$key] = $tmpinvoice->multicurrency_code;
239 $multicurrency_tx[$key] = $tmpinvoice->multicurrency_tx;
242 foreach ($multicurrency_amounts as $key => $value) {
243 $tmpinvoice =
new Facture($db);
244 $tmpinvoice->fetch($key);
247 $multicurrency_amounts[$key] = - abs($newvalue);
249 $multicurrency_code[$key] = $tmpinvoice->multicurrency_code;
250 $multicurrency_tx[$key] = $tmpinvoice->multicurrency_tx;
253 if (isModEnabled(
"banque")) {
255 if (
GETPOST(
'accountid',
'int') <= 0) {
256 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'AccountToCredit')),
null,
'errors');
263 $paiement->datepaye = $datepaye;
264 $paiement->amounts = $amounts;
265 $paiement->multicurrency_amounts = $multicurrency_amounts;
266 $paiement->multicurrency_code = $multicurrency_code;
267 $paiement->multicurrency_tx = $multicurrency_tx;
269 $paiement->num_payment =
GETPOST(
'num_paiement',
'alpha');
270 $paiement->note_private =
GETPOST(
'comment',
'alpha');
271 $paiement->fk_account =
GETPOST(
'accountid',
'int');
277 $paiement_id = $paiement->create($user, (
GETPOST(
'closepaidinvoices') ==
'on' ? 1 : 0), $thirdparty);
278 if ($paiement_id < 0) {
285 $label =
'(CustomerInvoicePayment)';
287 $label =
'(CustomerInvoicePaymentBack)';
289 $result = $paiement->addPaymentToBank($user,
'payment', $label,
GETPOST(
'accountid',
'int'),
GETPOST(
'chqemetteur'),
GETPOST(
'chqbank'));
301 foreach ($paiement->amounts as $key => $amount) {
303 if (is_numeric($amount) && $amount <> 0) {
304 if ($invoiceid != 0) {
311 if ($invoiceid > 0) {
312 $loc = DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$invoiceid;
314 $loc = DOL_URL_ROOT.
'/compta/paiement/card.php?id='.$paiement_id;
316 header(
'Location: '.$loc);
329$form =
new Form($db);
336if ($action ==
'create' || $action ==
'confirm_paiement' || $action ==
'add_paiement') {
338 $result = $facture->fetch($facid);
341 $facture->fetch_thirdparty();
345 $title .= $langs->trans(
"EnterPaymentReceivedFromCustomer");
348 $title .= $langs->trans(
"EnterPaymentDueToCustomer");
353 if ($action ==
'add_paiement') {
356 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'facid',
'value' => $facture->id);
357 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'socid',
'value' => $facture->socid);
358 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'type',
'value' => $facture->type);
363 if (isModEnabled(
'paypalplus') && $conf->global->PAYPAL_ENABLE_TRANSACTION_MANAGEMENT && !empty($facture->ref_ext)) {
364 if (!empty($conf->global->PAYPAL_BANK_ACCOUNT)) {
365 $accountid = $conf->global->PAYPAL_BANK_ACCOUNT;
367 $paymentnum = $facture->ref_ext;
371 if (!empty($conf->use_javascript_ajax)) {
372 print
"\n".
'<script type="text/javascript">';
373 print
'$(document).ready(function () {
376 $("#selectpaiementcode").change(function() {
380 function setPaiementCode()
382 var code = $("#selectpaiementcode option:selected").val();
383 console.log("setPaiementCode code="+code);
385 if (code == \'CHQ\' || code == \'VIR\')
389 $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
391 if ($(\'#fieldchqemetteur\').val() == \'\')
394 $(\'#fieldchqemetteur\').val(emetteur);
399 $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
400 $(\'#fieldchqemetteur\').val(\'\');
404 function _elemToJson(selector)
407 $.map(selector.serializeArray(), function(n,i)
409 subJson[n["name"]] = n["value"];
414 function callForResult(imgId)
417 var form = $("#payment_form");
419 json["invoice_type"] = $("#invoice_type").val();
420 json["amountPayment"] = $("#amountpayment").attr("value");
421 json["amounts"] = _elemToJson(form.find("input.amount"));
422 json["remains"] = _elemToJson(form.find("input.remain"));
425 json["imgClicked"] = imgId;
428 $.post("'.DOL_URL_ROOT.
'/compta/ajaxpayment.php", json, function(data)
430 json = $.parseJSON(data);
434 for (var key in json)
436 if (key == "result") {
437 if (json["makeRed"]) {
438 $("#"+key).addClass("error");
440 $("#"+key).removeClass("error");
442 json[key]=json["label"]+" "+json[key];
443 $("#"+key).text(json[key]);
444 } else {console.log(key);
445 form.find("input[name*=\""+key+"\"]").each(function() {
446 $(this).attr("value", json[key]);
452 $("#payment_form").find("input.amount").change(function() {
455 $("#payment_form").find("input.amount").keyup(function() {
463 print
' $(document).ready(function () {';
464 print
' $(".AutoFillAmout").on(\'click touchstart\', function(){
465 $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
469 print
' </script>'.
"\n";
472 print
'<form id="payment_form" name="add_paiement" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
473 print
'<input type="hidden" name="token" value="'.newToken().
'">';
474 print
'<input type="hidden" name="action" value="add_paiement">';
475 print
'<input type="hidden" name="facid" value="'.$facture->id.
'">';
476 print
'<input type="hidden" name="socid" value="'.$facture->socid.
'">';
477 print
'<input type="hidden" name="type" id="invoice_type" value="'.$facture->type.
'">';
478 print
'<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($facture->thirdparty->name).
'">';
479 print
'<input type="hidden" name="page_y" value="">';
483 print
'<table class="border centpercent">';
486 print
'<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans(
'Company').
'</span></td><td>'.$facture->thirdparty->getNomUrl(4).
"</td></tr>\n";
489 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
'Date').
'</span></td><td>';
491 $datepayment = ($datepayment ==
'' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'') : $datepayment);
492 print $form->selectDate($datepayment,
'',
'',
'', 0,
"add_paiement", 1, 1, 0,
'',
'', $facture->date);
496 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
'PaymentMode').
'</span></td><td>';
497 $form->select_types_paiements((
GETPOST(
'paiementcode') ?
GETPOST(
'paiementcode') : $facture->mode_reglement_code),
'paiementcode',
'', 2);
503 if (isModEnabled(
"banque")) {
504 if ($facture->type != 2) {
505 print
'<td><span class="fieldrequired">'.$langs->trans(
'AccountToCredit').
'</span></td>';
507 if ($facture->type == 2) {
508 print
'<td><span class="fieldrequired">'.$langs->trans(
'AccountToDebit').
'</span></td>';
513 print $form->select_comptes($accountid,
'accountid', 0,
'', 2,
'', 0,
'widthcentpercentminusx maxwidth500', 1);
516 print
'<td> </td>';
521 print
'<tr><td>'.$langs->trans(
'Numero');
522 print
' <em class="opacitymedium">('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
524 print
'<td><input name="num_paiement" type="text" class="maxwidth200" value="'.$paymentnum.
'"></td></tr>';
527 print
'<tr><td class="'.(GETPOST(
'paiementcode') ==
'CHQ' ?
'fieldrequired ' :
'').
'fieldrequireddyn">'.$langs->trans(
'CheckTransmitter');
528 print
' <em class="opacitymedium">('.$langs->trans(
"ChequeMaker").
')</em>';
530 print
'<td><input id="fieldchqemetteur" class="maxwidth300" name="chqemetteur" type="text" value="'.GETPOST(
'chqemetteur',
'alphanohtml').
'"></td></tr>';
533 print
'<tr><td>'.$langs->trans(
'Bank');
534 print
' <em class="opacitymedium">('.$langs->trans(
"ChequeBank").
')</em>';
536 print
'<td><input name="chqbank" class="maxwidth300" type="text" value="'.GETPOST(
'chqbank',
'alphanohtml').
'"></td></tr>';
539 print
'<tr><td>'.$langs->trans(
'Comments').
'</td>';
540 print
'<td class="tdtop">';
541 print
'<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.
'">'.
GETPOST(
'comment',
'restricthtml').
'</textarea>';
545 if ($action !=
'add_paiement' && !empty($conf->global->FACTURE_PAYMENTS_SHOW_LINK_TO_INPUT_ORIGIN_IS_MORE_THAN)) {
546 print
'<tr><td></td>';
547 print
'<td class="tdtop right">';
548 print
'<a class="right" href="#amount_'.$facid.
'">'.$langs->trans(
"GoSourceInvoice").
'</a>';
561 $sql =
'SELECT f.rowid as facid, f.ref, f.total_ttc, f.multicurrency_code, f.multicurrency_total_ttc, f.type,';
562 $sql .=
' f.datef as df, f.fk_soc as socid, f.date_lim_reglement as dlr';
563 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture as f';
564 $sql .=
' WHERE f.entity IN ('.getEntity(
'facture').
')';
565 $sql .=
' AND (f.fk_soc = '.((int) $facture->socid);
567 if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) {
568 $sql .=
' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe WHERE parent = '.((int) $facture->thirdparty->parent).
')';
571 if (!empty($conf->global->FACTURE_PAYMENTS_ON_SUBSIDIARY_COMPANIES)) {
572 $sql .=
' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe WHERE parent = '.((int) $facture->thirdparty->id).
')';
574 $sql .=
') AND f.paye = 0';
575 $sql .=
' AND f.fk_statut = 1';
577 $sql .=
' AND type IN (0,1,3,5)';
579 $sql .=
' AND type = 2';
582 $sql .=
' ORDER BY f.datef ASC, f.ref ASC';
584 $resql = $db->query($sql);
586 $num = $db->num_rows($resql);
588 $arraytitle = $langs->trans(
'Invoice');
589 if ($facture->type == 2) {
590 $arraytitle = $langs->trans(
"CreditNotes");
592 $alreadypayedlabel = $langs->trans(
'Received');
593 $multicurrencyalreadypayedlabel = $langs->trans(
'MulticurrencyReceived');
594 if ($facture->type == 2) {
595 $alreadypayedlabel = $langs->trans(
"PaidBack");
596 $multicurrencyalreadypayedlabel = $langs->trans(
"MulticurrencyPaidBack");
598 $remaindertopay = $langs->trans(
'RemainderToTake');
599 $multicurrencyremaindertopay = $langs->trans(
'MulticurrencyRemainderToTake');
600 if ($facture->type == 2) {
601 $remaindertopay = $langs->trans(
"RemainderToPayBack");
602 $multicurrencyremaindertopay = $langs->trans(
"MulticurrencyRemainderToPayBack");
609 print
'<div class="div-table-responsive-no-min">';
610 print
'<table class="noborder centpercent">';
612 print
'<tr class="liste_titre">';
613 print
'<td>'.$arraytitle.
'</td>';
614 print
'<td class="center">'.$langs->trans(
'Date').
'</td>';
615 print
'<td class="center">'.$langs->trans(
'DateMaxPayment').
'</td>';
616 if (isModEnabled(
'multicurrency')) {
617 print
'<td>'.$langs->trans(
'Currency').
'</td>';
618 print
'<td class="right">'.$langs->trans(
'MulticurrencyAmountTTC').
'</td>';
619 print
'<td class="right">'.$multicurrencyalreadypayedlabel.
'</td>';
620 print
'<td class="right">'.$multicurrencyremaindertopay.
'</td>';
621 print
'<td class="right">'.$langs->trans(
'MulticurrencyPaymentAmount').
'</td>';
623 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
624 print
'<td class="right">'.$alreadypayedlabel.
'</td>';
625 print
'<td class="right">'.$remaindertopay.
'</td>';
626 print
'<td class="right">'.$langs->trans(
'PaymentAmount').
'</td>';
628 $parameters = array();
629 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $facture, $action);
631 print
'<td align="right"> </td>';
636 $totalrecucreditnote = 0;
637 $totalrecudeposits = 0;
640 $objp = $db->fetch_object($resql);
648 $soc->fetch($objp->socid);
651 $invoice->fetch($objp->facid);
652 $paiement = $invoice->getSommePaiement();
653 $creditnotes = $invoice->getSumCreditNotesUsed();
654 $deposits = $invoice->getSumDepositsUsed();
655 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
656 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
659 if (isModEnabled(
'multicurrency')) {
660 $multicurrency_payment = $invoice->getSommePaiement(1);
661 $multicurrency_creditnotes = $invoice->getSumCreditNotesUsed(1);
662 $multicurrency_deposits = $invoice->getSumDepositsUsed(1);
663 $multicurrency_alreadypayed =
price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,
'MT');
664 $multicurrency_remaintopay =
price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,
'MT');
668 print
'<tr class="oddeven'.(($invoice->id == $facid) ?
' highlight' :
'').
'">';
670 print
'<td class="nowraponall">';
671 print $invoice->getNomUrl(1,
'');
672 if ($objp->socid != $facture->thirdparty->id) {
673 print
' - '.$soc->getNomUrl(1).
' ';
678 print
'<td class="center">'.dol_print_date($db->jdate($objp->df),
'day').
"</td>\n";
681 if ($objp->dlr > 0) {
682 print
'<td class="nowraponall center">';
685 if ($invoice->hasDelay()) {
691 print
'<td align="center"></td>';
695 if (isModEnabled(
'multicurrency')) {
696 print
'<td class="center">'.$objp->multicurrency_code.
"</td>\n";
700 if (isModEnabled(
'multicurrency')) {
701 print
'<td class="right">';
702 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
703 print
price($sign * $objp->multicurrency_total_ttc);
708 print
'<td class="right">';
709 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
710 print
price($sign * $multicurrency_payment);
711 if ($multicurrency_creditnotes) {
712 print
'+'.price($multicurrency_creditnotes);
714 if ($multicurrency_deposits) {
715 print
'+'.price($multicurrency_deposits);
721 print
'<td class="right">';
722 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
723 print
price($sign * $multicurrency_remaintopay);
727 print
'<td class="right nowraponall">';
730 $namef =
'multicurrency_amount_'.$objp->facid;
731 $nameRemain =
'multicurrency_remain_'.$objp->facid;
733 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
734 if ($action !=
'add_paiement') {
735 if (!empty($conf->use_javascript_ajax)) {
736 print
img_picto(
"Auto fill",
'rightarrow',
"class='AutoFillAmout' data-rowname='".$namef.
"' data-value='".($sign * $multicurrency_remaintopay).
"'");
738 print
'<input type="text" class="maxwidth75 multicurrency_amount" name="'.$namef.
'" value="'.
GETPOST($namef).
'">';
739 print
'<input type="hidden" class="multicurrency_remain" name="'.$nameRemain.
'" value="'.$multicurrency_remaintopay.
'">';
741 print
'<input type="text" class="maxwidth75" name="'.$namef.
'_disabled" value="'.
GETPOST($namef).
'" disabled>';
742 print
'<input type="hidden" name="'.$namef.
'" value="'.
GETPOST($namef).
'">';
749 print
'<td class="right"><span class="amount">'.price($sign * $objp->total_ttc).
'</span></td>';
752 print
'<td class="right"><span class="amount">'.price($sign * $paiement);
754 print
'<span class="opacitymedium">+'.price($creditnotes).
'</span>';
757 print
'<span class="opacitymedium">+'.price($deposits).
'</span>';
759 print
'</span></td>';
762 print
'<td class="right">';
763 print
price($sign * $remaintopay);
764 if (isModEnabled(
'prelevement')) {
765 $numdirectdebitopen = 0;
766 $totaldirectdebit = 0;
767 $sql =
"SELECT COUNT(pfd.rowid) as nb, SUM(pfd.amount) as amount";
768 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
769 $sql .=
" WHERE fk_facture = ".((int) $objp->facid);
770 $sql .=
" AND pfd.traite = 0";
771 $sql .=
" AND pfd.ext_payment_id IS NULL";
773 $result_sql = $db->query($sql);
775 $obj = $db->fetch_object($result_sql);
776 $numdirectdebitopen = $obj->nb;
777 $totaldirectdebit = $obj->amount;
781 if ($numdirectdebitopen) {
782 $langs->load(
"withdrawals");
783 print
img_warning($langs->trans(
"WarningSomeDirectDebitOrdersAlreadyExists", $numdirectdebitopen,
price(
price2num($totaldirectdebit,
'MT'), 0, $langs, 1, -1, -1, $conf->currency)),
'',
'classfortooltip');
790 print
'<td class="right nowraponall">';
793 $namef =
'amount_'.$objp->facid;
794 $nameRemain =
'remain_'.$objp->facid;
796 if ($action !=
'add_paiement') {
797 if (!empty($conf->use_javascript_ajax)) {
798 print
img_picto(
"Auto fill",
'rightarrow',
"class='AutoFillAmout' data-rowname='".$namef.
"' data-value='".($sign * $remaintopay).
"'");
800 print
'<input type="text" class="maxwidth75 amount" id="'.$namef.
'" name="'.$namef.
'" value="'.
dol_escape_htmltag(
GETPOST($namef)).
'">';
801 print
'<input type="hidden" class="remain" name="'.$nameRemain.
'" value="'.$remaintopay.
'">';
803 print
'<input type="text" class="maxwidth75" name="'.$namef.
'_disabled" value="'.
dol_escape_htmltag(
GETPOST($namef)).
'" disabled>';
808 $parameters = array();
809 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $objp, $action);
812 print
'<td align="center" width="16">';
814 if (!empty($amounts[$invoice->id]) && (abs($amounts[$invoice->id]) > abs($amountsresttopay[$invoice->id]))
815 || !empty($multicurrency_amounts[$invoice->id]) && (abs($multicurrency_amounts[$invoice->id]) > abs($multicurrency_amountsresttopay[$invoice->id]))) {
816 print
' '.img_warning($langs->trans(
"PaymentHigherThanReminderToPay"));
822 $total_ttc += $objp->total_ttc;
823 $totalrecu += $paiement;
824 $totalrecucreditnote += $creditnotes;
825 $totalrecudeposits += $deposits;
831 print
'<tr class="liste_total">';
832 print
'<td colspan="3" class="left">'.$langs->trans(
'TotalTTC').
'</td>';
833 if (isModEnabled(
'multicurrency')) {
838 print
'<td class="right" id="multicurrency_result" style="font-weight: bold;"></td>';
840 print
'<td class="right"><b>'.price($sign * $total_ttc).
'</b></td>';
841 print
'<td class="right"><b>'.price($sign * $totalrecu);
842 if ($totalrecucreditnote) {
843 print
'+'.price($totalrecucreditnote);
845 if ($totalrecudeposits) {
846 print
'+'.price($totalrecudeposits);
849 print
'<td class="right"><b>'.price($sign *
price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,
'MT')).
'</b></td>';
850 print
'<td class="right" id="result" style="font-weight: bold;"></td>';
851 print
'<td align="center"> </td>';
865 if ($action !=
'add_paiement') {
866 $checkboxlabel = $langs->trans(
"ClosePaidInvoicesAutomatically");
868 $checkboxlabel = $langs->trans(
"ClosePaidCreditNotesAutomatically");
870 $buttontitle = $langs->trans(
'ToMakePayment');
872 $buttontitle = $langs->trans(
'ToMakePaymentBack');
875 print
'<br><div class="center">';
876 print
'<input type="checkbox" checked name="closepaidinvoices"> '.$checkboxlabel;
881 print
'<br><input type="submit" class="button reposition" value="'.dol_escape_htmltag($buttontitle).
'"><br><br>';
886 if ($action ==
'add_paiement') {
887 $preselectedchoice = $addwarning ?
'no' :
'yes';
890 if (!empty($totalpayment)) {
891 $text = $langs->trans(
'ConfirmCustomerPayment', $totalpayment, $langs->transnoentitiesnoconv(
"Currency".$conf->currency));
893 if (!empty($multicurrency_totalpayment)) {
894 $text .=
'<br>'.$langs->trans(
'ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->transnoentitiesnoconv(
"paymentInInvoiceCurrency"));
896 if (
GETPOST(
'closepaidinvoices')) {
897 $text .=
'<br>'.$langs->trans(
"AllCompletelyPayedInvoiceWillBeClosed");
898 print
'<input type="hidden" name="closepaidinvoices" value="'.GETPOST(
'closepaidinvoices').
'">';
900 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$facture->id.
'&socid='.$facture->socid.
'&type='.$facture->type, $langs->trans(
'ReceivedCustomersPayments'), $text,
'confirm_paiement', $formquestion, $preselectedchoice);
904 $parameters = array(
'formConfirm' => $formconfirm);
905 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
906 if (empty($reshook)) {
907 $formconfirm .= $hookmanager->resPrint;
908 } elseif ($reshook > 0) {
909 $formconfirm = $hookmanager->resPrint;
923if (!
GETPOST(
'action',
'aZ09')) {
924 if (empty($page) || $page == -1) {
927 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
928 $offset = $limit * $page;
934 $sortfield =
'p.datep';
937 $sql =
'SELECT p.datep as dp, p.amount, f.total_ttc as fa_amount, f.ref';
938 $sql .=
', f.rowid as facid, c.libelle as paiement_type, p.num_paiement as num_payment';
939 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
940 $sql .=
', '.MAIN_DB_PREFIX.
'facture as f';
941 $sql .=
' WHERE p.fk_facture = f.rowid';
942 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
944 $sql .=
' AND f.fk_soc = '.((int) $socid);
947 $sql .= $db->order($sortfield, $sortorder);
948 $sql .= $db->plimit($limit + 1, $offset);
949 $resql = $db->query($sql);
952 $num = $db->num_rows($resql);
955 print_barre_liste($langs->trans(
'Payments'), $page, $_SERVER[
"PHP_SELF"],
'', $sortfield, $sortorder,
'', $num);
956 print
'<table class="noborder centpercent">';
957 print
'<tr class="liste_titre">';
961 print_liste_field_titre(
'Amount', $_SERVER[
"PHP_SELF"],
'p.amount',
'',
'',
'', $sortfield, $sortorder,
'right ');
965 while ($i < min($num, $limit)) {
966 $objp = $db->fetch_object($resql);
968 print
'<tr class="oddeven">';
969 print
'<td><a href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$objp->facid.
'">'.$objp->ref.
"</a></td>\n";
970 print
'<td>'.dol_print_date($db->jdate($objp->dp)).
"</td>\n";
971 print
'<td>'.$objp->paiement_type.
' '.$objp->num_payment.
"</td>\n";
972 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
973 print
'<td> </td>';
976 $parameters = array();
977 $reshook = $hookmanager->executeHooks(
'printObjectLine', $parameters, $objp, $action);
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
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 informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
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 '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.