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());
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) {
287 $label =
'(CustomerInvoicePayment)';
289 $label =
'(CustomerInvoicePaymentBack)';
291 $result = $paiement->addPaymentToBank($user,
'payment', $label,
GETPOSTINT(
'accountid'),
GETPOST(
'chqemetteur'),
GETPOST(
'chqbank'));
303 foreach ($paiement->amounts as $key => $amount) {
305 if (is_numeric($amount) && $amount != 0) {
306 if ($invoiceid != 0) {
313 if ($invoiceid > 0) {
314 $loc = DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$invoiceid;
316 $loc = DOL_URL_ROOT.
'/compta/paiement/card.php?id='.$paiement_id;
318 header(
'Location: '.$loc);
331$form =
new Form($db);
338if ($action ==
'create' || $action ==
'confirm_paiement' || $action ==
'add_paiement') {
340 $result = $facture->fetch($facid);
343 $facture->fetch_thirdparty();
347 $title .= $langs->trans(
"EnterPaymentReceivedFromCustomer");
350 $title .= $langs->trans(
"EnterPaymentDueToCustomer");
355 if ($action ==
'add_paiement') {
358 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'facid',
'value' => $facture->id);
359 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'socid',
'value' => $facture->socid);
360 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'type',
'value' => $facture->type);
365 if (isModEnabled(
'paypalplus') &&
getDolGlobalString(
'PAYPAL_ENABLE_TRANSACTION_MANAGEMENT') && !empty($facture->ref_ext)) {
369 $paymentnum = $facture->ref_ext;
373 if (!empty($conf->use_javascript_ajax)) {
374 print
"\n".
'<script type="text/javascript">';
375 print
'$(document).ready(function () {
378 $("#selectpaiementcode").change(function() {
382 function setPaiementCode()
384 var code = $("#selectpaiementcode option:selected").val();
385 console.log("setPaiementCode code="+code);
387 if (code == \'CHQ\' || code == \'VIR\')
391 $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
393 if ($(\'#fieldchqemetteur\').val() == \'\')
396 $(\'#fieldchqemetteur\').val(emetteur);
401 $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
402 $(\'#fieldchqemetteur\').val(\'\');
406 function _elemToJson(selector)
409 $.map(selector.serializeArray(), function(n,i)
411 subJson[n["name"]] = n["value"];
416 function callForResult(imgId)
419 var form = $("#payment_form");
421 json["invoice_type"] = $("#invoice_type").val();
422 json["amountPayment"] = $("#amountpayment").attr("value");
423 json["amounts"] = _elemToJson(form.find("input.amount"));
424 json["remains"] = _elemToJson(form.find("input.remain"));
427 json["imgClicked"] = imgId;
430 $.post("'.DOL_URL_ROOT.
'/compta/ajaxpayment.php", json, function(data)
432 json = $.parseJSON(data);
436 for (var key in json)
438 if (key == "result") {
439 if (json["makeRed"]) {
440 $("#"+key).addClass("error");
442 $("#"+key).removeClass("error");
444 json[key]=json["label"]+" "+json[key];
445 $("#"+key).text(json[key]);
446 } else {console.log(key);
447 form.find("input[name*=\""+key+"\"]").each(function() {
448 $(this).attr("value", json[key]);
454 $("#payment_form").find("input.amount").change(function() {
457 $("#payment_form").find("input.amount").keyup(function() {
465 print
' $(document).ready(function () {';
466 print
' $(".AutoFillAmount").on(\'click touchstart\', function(){
467 $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
471 print
' </script>'.
"\n";
474 print
'<form id="payment_form" name="add_paiement" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
475 print
'<input type="hidden" name="token" value="'.newToken().
'">';
476 print
'<input type="hidden" name="action" value="add_paiement">';
477 print
'<input type="hidden" name="facid" value="'.$facture->id.
'">';
478 print
'<input type="hidden" name="socid" value="'.$facture->socid.
'">';
479 print
'<input type="hidden" name="type" id="invoice_type" value="'.$facture->type.
'">';
480 print
'<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($facture->thirdparty->name).
'">';
481 print
'<input type="hidden" name="page_y" value="">';
485 print
'<table class="border centpercent">';
488 print
'<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans(
'Company').
'</span></td><td>'.$facture->thirdparty->getNomUrl(4).
"</td></tr>\n";
491 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
'Date').
'</span></td><td>';
493 $datepayment = ($datepayment ==
'' ? (!
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ? -1 :
'') : $datepayment);
494 print $form->selectDate($datepayment,
'', 0, 0, 0,
"add_paiement", 1, 1, 0,
'',
'', $facture->date);
498 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
'PaymentMode').
'</span></td><td>';
499 $form->select_types_paiements((
GETPOST(
'paiementcode') ?
GETPOST(
'paiementcode') : $facture->mode_reglement_code),
'paiementcode',
'', 2);
505 if (isModEnabled(
"bank")) {
506 if ($facture->type != 2) {
507 print
'<td><span class="fieldrequired">'.$langs->trans(
'AccountToCredit').
'</span></td>';
509 if ($facture->type == 2) {
510 print
'<td><span class="fieldrequired">'.$langs->trans(
'AccountToDebit').
'</span></td>';
514 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
515 print $form->select_comptes($accountid,
'accountid', 0,
'', 2,
'', 0,
'widthcentpercentminusx maxwidth500', 1);
518 print
'<td> </td>';
523 print
'<tr><td>'.$langs->trans(
'Numero');
524 print
' <em class="opacitymedium">('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
526 print
'<td><input name="num_paiement" type="text" class="maxwidth200" value="'.$paymentnum.
'"></td></tr>';
529 print
'<tr><td class="'.(GETPOST(
'paiementcode') ==
'CHQ' ?
'fieldrequired ' :
'').
'fieldrequireddyn">'.$langs->trans(
'CheckTransmitter');
530 print
' <em class="opacitymedium">('.$langs->trans(
"ChequeMaker").
')</em>';
532 print
'<td><input id="fieldchqemetteur" class="maxwidth300" name="chqemetteur" type="text" value="'.GETPOST(
'chqemetteur',
'alphanohtml').
'"></td></tr>';
535 print
'<tr><td>'.$langs->trans(
'Bank');
536 print
' <em class="opacitymedium">('.$langs->trans(
"ChequeBank").
')</em>';
538 print
'<td><input name="chqbank" class="maxwidth300" type="text" value="'.GETPOST(
'chqbank',
'alphanohtml').
'"></td></tr>';
541 print
'<tr><td>'.$langs->trans(
'Comments').
'</td>';
542 print
'<td class="tdtop">';
543 print
'<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.
'">'.
GETPOST(
'comment',
'restricthtml').
'</textarea>';
547 if ($action !=
'add_paiement' &&
getDolGlobalString(
'FACTURE_PAYMENTS_SHOW_LINK_TO_INPUT_ORIGIN_IS_MORE_THAN')) {
548 print
'<tr><td></td>';
549 print
'<td class="tdtop right">';
550 print
'<a class="right" href="#amount_'.$facid.
'">'.$langs->trans(
"GoSourceInvoice").
'</a>';
563 $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,';
564 $sql .=
' f.datef as df, f.fk_soc as socid, f.date_lim_reglement as dlr';
565 $sql .=
' FROM '.MAIN_DB_PREFIX.
'facture as f';
566 $sql .=
' WHERE f.entity IN ('.getEntity(
'facture').
')';
567 $sql .=
' AND (f.fk_soc = '.((int) $facture->socid);
569 if (
getDolGlobalString(
'FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS') && !empty($facture->thirdparty->parent)) {
570 $sql .=
' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe WHERE parent = '.((int) $facture->thirdparty->parent).
')';
574 $sql .=
' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'societe WHERE parent = '.((int) $facture->thirdparty->id).
')';
576 $sql .=
') AND f.paye = 0';
577 $sql .=
' AND f.fk_statut = 1';
579 $sql .=
' AND type IN (0,1,3,5)';
581 $sql .=
' AND type = 2';
584 $sql .=
' ORDER BY f.datef ASC, f.ref ASC';
586 $resql = $db->query($sql);
588 $num = $db->num_rows($resql);
590 $arraytitle = $langs->trans(
'Invoice');
591 if ($facture->type == 2) {
592 $arraytitle = $langs->trans(
"CreditNotes");
594 $alreadypayedlabel = $langs->trans(
'Received');
595 $multicurrencyalreadypayedlabel = $langs->trans(
'MulticurrencyReceived');
596 if ($facture->type == 2) {
597 $alreadypayedlabel = $langs->trans(
"PaidBack");
598 $multicurrencyalreadypayedlabel = $langs->trans(
"MulticurrencyPaidBack");
600 $remaindertopay = $langs->trans(
'RemainderToTake');
601 $multicurrencyremaindertopay = $langs->trans(
'MulticurrencyRemainderToTake');
602 if ($facture->type == 2) {
603 $remaindertopay = $langs->trans(
"RemainderToPayBack");
604 $multicurrencyremaindertopay = $langs->trans(
"MulticurrencyRemainderToPayBack");
611 print
'<div class="div-table-responsive-no-min">';
612 print
'<table class="noborder centpercent">';
614 print
'<tr class="liste_titre">';
615 print
'<td>'.$arraytitle.
'</td>';
616 print
'<td class="center">'.$langs->trans(
'Date').
'</td>';
617 print
'<td class="center">'.$langs->trans(
'DateMaxPayment').
'</td>';
618 if (isModEnabled(
'multicurrency')) {
619 print
'<td>'.$langs->trans(
'Currency').
'</td>';
620 print
'<td class="right">'.$langs->trans(
'MulticurrencyAmountTTC').
'</td>';
621 print
'<td class="right">'.$multicurrencyalreadypayedlabel.
'</td>';
622 print
'<td class="right">'.$multicurrencyremaindertopay.
'</td>';
623 print
'<td class="right">'.$langs->trans(
'MulticurrencyPaymentAmount').
'</td>';
625 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
626 print
'<td class="right">'.$alreadypayedlabel.
'</td>';
627 print
'<td class="right">'.$remaindertopay.
'</td>';
628 print
'<td class="right">'.$langs->trans(
'PaymentAmount').
'</td>';
630 $parameters = array();
631 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $facture, $action);
633 print
'<td align="right"> </td>';
638 $totalrecucreditnote = 0;
639 $totalrecudeposits = 0;
642 $objp = $db->fetch_object($resql);
650 $soc->fetch($objp->socid);
653 $invoice->fetch($objp->facid);
654 $paiement = $invoice->getSommePaiement();
655 $creditnotes = $invoice->getSumCreditNotesUsed();
656 $deposits = $invoice->getSumDepositsUsed();
657 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
658 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
661 if (isModEnabled(
'multicurrency')) {
662 $multicurrency_payment = $invoice->getSommePaiement(1);
663 $multicurrency_creditnotes = $invoice->getSumCreditNotesUsed(1);
664 $multicurrency_deposits = $invoice->getSumDepositsUsed(1);
665 $multicurrency_alreadypayed =
price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,
'MT');
666 $multicurrency_remaintopay =
price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,
'MT');
668 $tootltiponmulticurrencyfullamount = $langs->trans(
'AmountHT') .
": " .
price($objp->multicurrency_total_ht, 0, $langs, 0, -1, -1, $objp->multicurrency_code) .
"<br>";
669 $tootltiponmulticurrencyfullamount .= $langs->trans(
'AmountVAT') .
": " .
price($objp->multicurrency_total_tva, 0, $langs, 0, -1, -1, $objp->multicurrency_code) .
"<br>";
670 $tootltiponmulticurrencyfullamount .= $langs->trans(
'AmountTTC') .
": " .
price($objp->multicurrency_total_ttc, 0, $langs, 0, -1, -1, $objp->multicurrency_code) .
"<br>";
674 $tootltiponfullamount = $langs->trans(
'AmountHT') .
": " .
price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
"<br>";
675 $tootltiponfullamount .= $langs->trans(
'AmountVAT') .
": " .
price($objp->total_tva, 0, $langs, 0, -1, -1, $conf->currency) .
"<br>";
676 $tootltiponfullamount .= $langs->trans(
'AmountTTC') .
": " .
price($objp->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) .
"<br>";
678 print
'<tr class="oddeven'.(($invoice->id == $facid) ?
' highlight' :
'').
'">';
680 print
'<td class="nowraponall">';
681 print $invoice->getNomUrl(1,
'');
682 if ($objp->socid != $facture->thirdparty->id) {
683 print
' - '.$soc->getNomUrl(1).
' ';
688 print
'<td class="center">'.dol_print_date($db->jdate($objp->df),
'day').
"</td>\n";
691 if ($objp->dlr > 0) {
692 print
'<td class="nowraponall center">';
695 if ($invoice->hasDelay()) {
701 print
'<td align="center"></td>';
705 if (isModEnabled(
'multicurrency')) {
706 print
'<td class="center">'.$objp->multicurrency_code.
"</td>\n";
710 if (isModEnabled(
'multicurrency')) {
711 print
'<td class="right">';
712 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
713 print
'<span class="amount classfortooltip" title="'.$tootltiponmulticurrencyfullamount.
'">' .
price($sign * $objp->multicurrency_total_ttc);
715 print
'</span></td>';
718 print
'<td class="right">';
719 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
720 print
price($sign * $multicurrency_payment);
721 if ($multicurrency_creditnotes) {
722 print
'+'.price($multicurrency_creditnotes);
724 if ($multicurrency_deposits) {
725 print
'+'.price($multicurrency_deposits);
731 print
'<td class="right">';
732 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
733 print
price($sign * (
float) $multicurrency_remaintopay);
737 print
'<td class="right nowraponall">';
740 $namef =
'multicurrency_amount_'.$objp->facid;
741 $nameRemain =
'multicurrency_remain_'.$objp->facid;
743 if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
744 if ($action !=
'add_paiement') {
745 if (!empty($conf->use_javascript_ajax)) {
746 print
img_picto(
"Auto fill",
'rightarrow',
"class='AutoFillAmount' data-rowname='".$namef.
"' data-value='".($sign * (
float) $multicurrency_remaintopay).
"'");
748 print
'<input type="text" class="maxwidth75 multicurrency_amount" name="'.$namef.
'" value="'.
GETPOST($namef).
'">';
749 print
'<input type="hidden" class="multicurrency_remain" name="'.$nameRemain.
'" value="'.$multicurrency_remaintopay.
'">';
751 print
'<input type="text" class="maxwidth75" name="'.$namef.
'_disabled" value="'.
GETPOST($namef).
'" disabled>';
752 print
'<input type="hidden" name="'.$namef.
'" value="'.
GETPOST($namef).
'">';
759 print
'<td class="right"><span class="amount classfortooltip" title="'.$tootltiponfullamount.
'">'.
price($sign * $objp->total_ttc).
'</span></td>';
762 print
'<td class="right"><span class="amount">'.price($sign * $paiement);
764 print
'<span class="opacitymedium">+'.price($creditnotes).
'</span>';
767 print
'<span class="opacitymedium">+'.price($deposits).
'</span>';
769 print
'</span></td>';
772 print
'<td class="right">';
773 print
price($sign * (
float) $remaintopay);
774 if (isModEnabled(
'prelevement')) {
775 $numdirectdebitopen = 0;
776 $totaldirectdebit = 0;
777 $sql =
"SELECT COUNT(pfd.rowid) as nb, SUM(pfd.amount) as amount";
778 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
779 $sql .=
" WHERE fk_facture = ".((int) $objp->facid);
780 $sql .=
" AND pfd.traite = 0";
781 $sql .=
" AND pfd.ext_payment_id IS NULL";
783 $result_sql = $db->query($sql);
785 $obj = $db->fetch_object($result_sql);
786 $numdirectdebitopen = $obj->nb;
787 $totaldirectdebit = $obj->amount;
791 if ($numdirectdebitopen) {
792 $langs->load(
"withdrawals");
793 print
img_warning($langs->trans(
"WarningSomeDirectDebitOrdersAlreadyExists", $numdirectdebitopen,
price(
price2num($totaldirectdebit,
'MT'), 0, $langs, 1, -1, -1, $conf->currency)),
'',
'classfortooltip');
800 print
'<td class="right nowraponall">';
803 $namef =
'amount_'.$objp->facid;
804 $nameRemain =
'remain_'.$objp->facid;
806 if ($action !=
'add_paiement') {
807 if (!empty($conf->use_javascript_ajax)) {
808 print
img_picto(
"Auto fill",
'rightarrow',
"class='AutoFillAmount' data-rowname='".$namef.
"' data-value='".($sign * (
float) $remaintopay).
"'");
810 print
'<input type="text" class="maxwidth75 amount" id="'.$namef.
'" name="'.$namef.
'" value="'.
dol_escape_htmltag(
GETPOST($namef)).
'">';
811 print
'<input type="hidden" class="remain" name="'.$nameRemain.
'" value="'.$remaintopay.
'">';
813 print
'<input type="text" class="maxwidth75" name="'.$namef.
'_disabled" value="'.
dol_escape_htmltag(
GETPOST($namef)).
'" disabled>';
818 $parameters = array();
819 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $objp, $action);
822 print
'<td align="center" width="16">';
824 if (!empty($amounts[$invoice->id]) && (abs((
float) $amounts[$invoice->id]) > abs((
float) $amountsresttopay[$invoice->id]))
825 || !empty($multicurrency_amounts[$invoice->id]) && (abs((
float) $multicurrency_amounts[$invoice->id]) > abs((
float) $multicurrency_amountsresttopay[$invoice->id]))) {
826 print
' '.img_warning($langs->trans(
"PaymentHigherThanReminderToPay"));
832 $total_ttc += $objp->total_ttc;
833 $totalrecu += $paiement;
834 $totalrecucreditnote += $creditnotes;
835 $totalrecudeposits += $deposits;
841 print
'<tr class="liste_total">';
842 print
'<td colspan="3" class="left">'.$langs->trans(
'TotalTTC').
'</td>';
843 if (isModEnabled(
'multicurrency')) {
848 print
'<td class="right" id="multicurrency_result" style="font-weight: bold;"></td>';
850 print
'<td class="right"><b>'.price($sign * $total_ttc).
'</b></td>';
851 print
'<td class="right"><b>'.price($sign * $totalrecu);
852 if ($totalrecucreditnote) {
853 print
'+'.price($totalrecucreditnote);
855 if ($totalrecudeposits) {
856 print
'+'.price($totalrecudeposits);
859 print
'<td class="right"><b>'.price($sign * (
float)
price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,
'MT')).
'</b></td>';
860 print
'<td class="right" id="result" style="font-weight: bold;"></td>';
861 print
'<td align="center"> </td>';
875 if ($action !=
'add_paiement') {
876 $checkboxlabel = $langs->trans(
"ClosePaidInvoicesAutomatically");
878 $checkboxlabel = $langs->trans(
"ClosePaidCreditNotesAutomatically");
880 $buttontitle = $langs->trans(
'ToMakePayment');
882 $buttontitle = $langs->trans(
'ToMakePaymentBack');
885 print
'<br><div class="center">';
886 print
'<input type="checkbox" checked name="closepaidinvoices" id="closepaidinvoices"><label for="closepaidinvoices"> '.$checkboxlabel.
'</label>';
891 print
'<br><input type="submit" class="button reposition" value="'.dol_escape_htmltag($buttontitle).
'"><br><br>';
896 if ($action ==
'add_paiement') {
897 $preselectedchoice = $addwarning ?
'no' :
'yes';
900 if (!empty($totalpayment)) {
901 $text = $langs->trans(
'ConfirmCustomerPayment', $totalpayment, $langs->transnoentitiesnoconv(
"Currency".$conf->currency));
903 if (!empty($multicurrency_totalpayment)) {
904 $text .=
'<br>'.$langs->trans(
'ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->transnoentitiesnoconv(
"paymentInInvoiceCurrency"));
906 if (
GETPOST(
'closepaidinvoices')) {
907 $text .=
'<br>'.$langs->trans(
"AllCompletelyPayedInvoiceWillBeClosed");
908 print
'<input type="hidden" name="closepaidinvoices" value="'.GETPOST(
'closepaidinvoices').
'">';
910 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$facture->id.
'&socid='.$facture->socid.
'&type='.$facture->type, $langs->trans(
'ReceivedCustomersPayments'), $text,
'confirm_paiement', $formquestion, $preselectedchoice);
914 $parameters = array(
'formConfirm' => $formconfirm);
915 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
916 if (empty($reshook)) {
917 $formconfirm .= $hookmanager->resPrint;
918 } elseif ($reshook > 0) {
919 $formconfirm = $hookmanager->resPrint;
933if (!
GETPOST(
'action',
'aZ09')) {
934 if (empty($page) || $page == -1) {
938 $offset = $limit * $page;
944 $sortfield =
'p.datep';
947 $sql =
'SELECT p.datep as dp, p.amount, f.total_ttc as fa_amount, f.ref';
948 $sql .=
', f.rowid as facid, c.libelle as paiement_type, p.num_paiement as num_payment';
949 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as c ON p.fk_paiement = c.id';
950 $sql .=
', '.MAIN_DB_PREFIX.
'facture as f';
951 $sql .=
' WHERE p.fk_facture = f.rowid';
952 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
954 $sql .=
' AND f.fk_soc = '.((int) $socid);
957 $sql .= $db->order($sortfield, $sortorder);
958 $sql .= $db->plimit($limit + 1, $offset);
959 $resql = $db->query($sql);
962 $num = $db->num_rows($resql);
965 print_barre_liste($langs->trans(
'Payments'), $page, $_SERVER[
"PHP_SELF"],
'', $sortfield, $sortorder,
'', $num);
966 print
'<table class="noborder centpercent">';
967 print
'<tr class="liste_titre">';
971 print_liste_field_titre(
'Amount', $_SERVER[
"PHP_SELF"],
'p.amount',
'',
'',
'', $sortfield, $sortorder,
'right ');
975 while ($i < min($num, $limit)) {
976 $objp = $db->fetch_object($resql);
978 print
'<tr class="oddeven">';
979 print
'<td><a href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$objp->facid.
'">'.$objp->ref.
"</a></td>\n";
980 print
'<td>'.dol_print_date($db->jdate($objp->dp)).
"</td>\n";
981 print
'<td>'.$objp->paiement_type.
' '.$objp->num_payment.
"</td>\n";
982 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
983 print
'<td> </td>';
986 $parameters = array();
987 $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()
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.
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.
print_barre_liste($title, $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.
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.
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 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.