39require
'../main.inc.php';
47require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
53$langs->loadLangs(array(
'companies',
'bills',
'banks',
'multicurrency'));
55$action =
GETPOST(
'action',
'alpha');
56$confirm =
GETPOST(
'confirm',
'alpha');
60$paymentnum =
GETPOST(
'num_paiement',
'alpha');
63$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
64$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
67$displayAllInvoices =
getDolGlobalInt(
'MAIN_PAIMENTS_SHOW_ALL_INVOICE_TYPES', 0);
69 $displayAllInvoices =
GETPOSTINT(
'display-all-invoices');
74$amountsresttopay = array();
77$multicurrency_amounts = array();
78$multicurrency_amountsresttopay = array();
81if ($user->socid > 0) {
82 $socid = $user->socid;
93$hookmanager->initHooks(array(
'paiementcard',
'globalcard'));
95$formquestion = array();
97$usercanissuepayment = $user->hasRight(
'facture',
'paiement');
109$parameters = array(
'socid' => $socid);
110$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
112 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
116if (empty($reshook)) {
117 if (($action ==
'add_paiement' || ($action ==
'confirm_paiement' && $confirm ==
'yes')) && $usercanissuepayment) {
120 $multicurrency_totalpayment = 0;
121 $atleastonepaymentnotnull = 0;
122 $formquestion = array();
126 $tmpinvoice =
new Facture($db);
128 foreach (array_merge($_GET, $_POST) as $key => $value) {
129 if (substr($key, 0, 7) ==
'amount_' &&
GETPOST($key) !=
'') {
130 $cursorfacid = (int) substr($key, 7);
132 if (!empty($amounts[$cursorfacid])) {
133 $totalpayment += (float) $amounts[$cursorfacid];
134 $atleastonepaymentnotnull++;
136 $result = $tmpinvoice->fetch($cursorfacid);
138 dol_print_error($db);
143 $amountsresttopay[$cursorfacid] =
price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement(0));
144 if ($amounts[$cursorfacid]) {
146 if ($amounts[$cursorfacid] && (abs((
float) $amounts[$cursorfacid]) > abs((
float) $amountsresttopay[$cursorfacid]))) {
148 $formquestion[
'text'] = img_warning($langs->trans(
"PaymentHigherThanReminderToPay")).
' '.$langs->trans(
"HelpPaymentHigherThanReminderToPay");
151 if ($datepaye && ($datepaye < $tmpinvoice->
date)) {
152 $langs->load(
"errors");
154 setEventMessages($langs->transnoentities(
"WarningPaymentDateLowerThanInvoiceDate",
dol_print_date($datepaye,
'day'),
dol_print_date($tmpinvoice->date,
'day'), $tmpinvoice->ref),
null,
'warnings');
158 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' => $key,
'value' =>
GETPOST($key));
159 } elseif (substr($key, 0, 21) ==
'multicurrency_amount_') {
160 $cursorfacid = (int) substr($key, 21);
162 $multicurrency_totalpayment += (float) $multicurrency_amounts[$cursorfacid];
163 if (!empty($multicurrency_amounts[$cursorfacid])) {
164 $atleastonepaymentnotnull++;
166 $result = $tmpinvoice->fetch($cursorfacid);
168 dol_print_error($db);
173 $multicurrency_amountsresttopay[$cursorfacid] =
price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1));
174 if ($multicurrency_amounts[$cursorfacid]) {
176 if ($multicurrency_amounts[$cursorfacid] && (abs((
float) $multicurrency_amounts[$cursorfacid]) > abs((
float) $multicurrency_amountsresttopay[$cursorfacid]))) {
178 $formquestion[
'text'] = img_warning($langs->trans(
"PaymentHigherThanReminderToPay")).
' '.$langs->trans(
"HelpPaymentHigherThanReminderToPay");
181 if ($datepaye && ($datepaye < $tmpinvoice->
date)) {
182 $langs->load(
"errors");
184 setEventMessages($langs->transnoentities(
"WarningPaymentDateLowerThanInvoiceDate",
dol_print_date($datepaye,
'day'),
dol_print_date($tmpinvoice->date,
'day'), $tmpinvoice->ref),
null,
'warnings');
188 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' => $key,
'value' =>
GETPOST($key));
193 if (!
GETPOST(
'paiementcode')) {
194 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'PaymentMode')),
null,
'errors');
200 if (
GETPOST(
'accountid') <= 0) {
201 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'AccountToCredit')),
null,
'errors');
206 if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) {
207 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->trans(
'PaymentAmount')),
null,
'errors');
211 if (empty($datepaye)) {
212 setEventMessages($langs->transnoentities(
'ErrorFieldRequired', $langs->transnoentities(
'Date')),
null,
'errors');
217 if ($totalpayment > 0 && $multicurrency_totalpayment > 0) {
218 $langs->load(
"errors");
219 setEventMessages($langs->transnoentities(
'ErrorPaymentInBothCurrency'),
null,
'errors');
227 if ($action ==
'add_paiement') {
237 if ($action ==
'confirm_paiement' && $confirm ==
'yes' && $usercanissuepayment) {
242 $thirdparty =
new Societe($db);
244 $thirdparty->fetch($socid);
247 $multicurrency_code = array();
248 $multicurrency_tx = array();
251 foreach ($amounts as $key => $value) {
252 $tmpinvoice =
new Facture($db);
253 $tmpinvoice->fetch($key);
256 $amounts[$key] = - abs((
float) $newvalue);
258 $multicurrency_code[$key] = $tmpinvoice->multicurrency_code;
259 $multicurrency_tx[$key] = $tmpinvoice->multicurrency_tx;
262 foreach ($multicurrency_amounts as $key => $value) {
263 $tmpinvoice =
new Facture($db);
264 $tmpinvoice->fetch((
int) $key);
267 $multicurrency_amounts[$key] = - abs((
float) $newvalue);
269 $multicurrency_code[$key] = $tmpinvoice->multicurrency_code;
270 $multicurrency_tx[$key] = $tmpinvoice->multicurrency_tx;
276 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'AccountToCredit')),
null,
'errors');
283 $paiement->datepaye = $datepaye;
284 $paiement->amounts = $amounts;
285 $paiement->multicurrency_amounts = $multicurrency_amounts;
286 $paiement->multicurrency_code = $multicurrency_code;
287 $paiement->multicurrency_tx = $multicurrency_tx;
288 $paiement->paiementcode =
GETPOST(
'paiementcode',
'alpha');
289 $paiement->paiementid =
dol_getIdFromCode($db, $paiement->paiementcode,
'c_paiement',
'code',
'id', 1);
290 $paiement->num_payment =
GETPOST(
'num_paiement',
'alpha');
291 $paiement->note_private =
GETPOST(
'comment',
'alpha');
292 $paiement->fk_account =
GETPOSTINT(
'accountid');
299 $paiement_id = $paiement->create($user, (
GETPOST(
'closepaidinvoices') ==
'on' ? 1 : 0), $thirdparty);
300 if ($paiement_id < 0) {
301 setEventMessages($paiement->error, $paiement->errors,
'errors');
312 $label =
'(CustomerInvoicePayment)';
314 $label =
'(CustomerInvoicePaymentBack)';
317 $result = $paiement->addPaymentToBank($user,
'payment', $label,
GETPOSTINT(
'accountid'),
GETPOST(
'chqemetteur'),
GETPOST(
'chqbank'));
319 setEventMessages($paiement->error, $paiement->errors,
'errors');
329 foreach ($paiement->amounts as $key => $amount) {
331 if (is_numeric($amount) && $amount != 0) {
332 if ($invoiceid != 0) {
339 if ($invoiceid > 0) {
340 $loc = DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$invoiceid;
342 $loc = DOL_URL_ROOT.
'/compta/paiement/card.php?id='.$paiement_id;
344 header(
'Location: '.$loc);
357$form =
new Form($db);
363$useajaxconfirm = (!empty(
$conf->use_javascript_ajax) && empty(
$conf->dol_use_jmobile)) ? 1 : 0;
367$result = $facture->fetch($facid);
370 $facture->fetch_thirdparty();
374 $title .= $langs->trans(
"EnterPaymentReceivedFromCustomer");
377 $title .= $langs->trans(
"EnterPaymentDueToCustomer");
382 if ($action ==
'add_paiement') {
383 $i = count($formquestion);
385 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'facid',
'value' => $facture->id);
386 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'socid',
'value' => $facture->socid);
387 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'type',
'value' => $facture->type);
389 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'paiementcode',
'value' => (
GETPOST(
'paiementcode',
'alpha') ?
GETPOST(
'paiementcode',
'alpha') : $facture->mode_reglement_code));
390 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'accountid',
'value' => $accountid);
391 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'reday',
'value' =>
GETPOSTINT(
'reday'));
392 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'remonth',
'value' =>
GETPOSTINT(
'remonth'));
393 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'reyear',
'value' =>
GETPOSTINT(
'reyear'));
394 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'num_paiement',
'value' => $paymentnum);
395 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'chqemetteur',
'value' =>
GETPOST(
'chqemetteur',
'alphanohtml'));
396 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'chqbank',
'value' =>
GETPOST(
'chqbank',
'alphanohtml'));
397 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'comment',
'value' =>
GETPOST(
'comment',
'restricthtml'));
398 $formquestion[$i++] = array(
'type' =>
'hidden',
'name' =>
'closepaidinvoices',
'value' =>
GETPOST(
'closepaidinvoices'));
407 $paymentnum = $facture->ref_ext;
411 if (!empty(
$conf->use_javascript_ajax)) {
412 print
"\n".
'<script type="text/javascript">';
413 print
'$(document).ready(function () {
416 $("#selectpaiementcode").change(function() {
420 function setPaiementCode()
422 var code = $("#selectpaiementcode option:selected").val();
423 console.log("setPaiementCode code="+code);
425 if (code == \'CHQ\' || code == \'VIR\')
429 $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
431 if ($(\'#fieldchqemetteur\').val() == \'\')
434 $(\'#fieldchqemetteur\').val(emetteur);
439 $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
440 $(\'#fieldchqemetteur\').val(\'\');
444 function _elemToJson(selector)
447 $.map(selector.serializeArray(), function(n,i)
449 subJson[n["name"]] = n["value"];
454 function callForResult(imgId, multicurrency = 0)
457 var form = $("#payment_form");
458 var keyresult = "result";
460 json["invoice_type"] = $("#invoice_type").val();
462 keyresult = "multicurrency_result";
463 json["multicurrency"] = 1;
464 json["multicurrency_amountPayment"] = $("#multicurrency_amountpayment").attr("value");
465 json["multicurrency_amounts"] = _elemToJson(form.find("input.multicurrency_amount"));
466 json["multicurrency_remains"] = _elemToJson(form.find("input.multicurrency_remain"));
468 json["amountPayment"] = $("#amountpayment").attr("value");
469 json["amounts"] = _elemToJson(form.find("input.amount"));
470 json["remains"] = _elemToJson(form.find("input.remain"));
474 json["imgClicked"] = imgId;
477 $.post("'.DOL_URL_ROOT.
'/compta/ajaxpayment.php", json, function(data)
479 json = $.parseJSON(data);
483 for (var key in json)
485 if (key == keyresult) {
486 if (json["makeRed"]) {
487 $("#"+key).addClass("error");
489 $("#"+key).removeClass("error");
491 json[key]=json["label"]+" "+json[key];
492 $("#"+key).text(json[key]);
493 } else {console.log(key);
494 form.find("input[name*=\""+key+"\"]").each(function() {
495 $(this).attr("value", json[key]);
501 $("#payment_form").find("input.amount").change(function() {
504 $("#payment_form").find("input.amount").keyup(function() {
508 $("#payment_form").find("input.multicurrency_amount").change(function() {
509 callForResult(null, 1);
511 $("#payment_form").find("input.multicurrency_amount").keyup(function() {
512 callForResult(null, 1);
519 print
' $(document).ready(function () {';
520 print
' $(".AutoFillAmount").on(\'click touchstart\', function(e){
522 $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
526 print
' </script>'.
"\n";
529 print
'<form id="payment_form" name="add_paiement" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
530 print
'<input type="hidden" name="token" value="'.newToken().
'">';
531 print
'<input type="hidden" name="action" value="add_paiement">';
532 print
'<input type="hidden" name="display-all-invoices" value="'.(int) $displayAllInvoices.
'">';
533 print
'<input type="hidden" name="facid" value="'.$facture->id.
'">';
534 print
'<input type="hidden" name="socid" value="'.$facture->socid.
'">';
535 print
'<input type="hidden" name="type" id="invoice_type" value="'.$facture->type.
'">';
536 print
'<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($facture->thirdparty->name).
'">';
537 print
'<input type="hidden" name="page_y" value="">';
541 print
'<table class="border centpercent">';
544 print
'<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans(
'Company').
'</span></td><td>'.$facture->thirdparty->getNomUrl(4).
"</td></tr>\n";
547 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
'Date').
'</span></td><td>';
549 $datepayment = ($datepayment ==
'' ? (
getDolGlobalString(
'MAIN_AUTOFILL_DATE') ?
'' : -1) : $datepayment);
550 $adddateof = array(array(
'adddateof'=>$facture->date));
551 $adddateof[] = array(
'adddateof'=>$facture->date_lim_reglement,
'labeladddateof'=>$langs->transnoentities(
'DateDue'));
552 print $form->selectDate($datepayment,
'', 0, 0, 0,
"add_paiement", 1, 1, 0,
'',
'', $adddateof);
556 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
'PaymentMode').
'</span></td><td>';
557 print img_picto(
'',
'bank',
'class="pictofixedwidth"');
558 $form->select_types_paiements((
GETPOST(
'paiementcode') ?
GETPOST(
'paiementcode') : $facture->mode_reglement_code),
'paiementcode',
'', 2);
565 if ($facture->type != 2) {
566 print
'<td><span class="fieldrequired">'.$langs->trans(
'AccountToCredit').
'</span></td>';
568 if ($facture->type == 2) {
569 print
'<td><span class="fieldrequired">'.$langs->trans(
'AccountToDebit').
'</span></td>';
573 print img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
574 print $form->select_comptes($accountid,
'accountid', 0,
'', 2,
'', (
isModEnabled(
'multicurrency') ? 1 : 0),
'widthcentpercentminusx maxwidth500', 1);
577 print
'<td> </td>';
582 print
'<tr><td>'.$langs->trans(
'Numero');
583 print
' <em class="opacitymedium small">('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
585 print
'<td><input name="num_paiement" type="text" class="maxwidth200" value="'.$paymentnum.
'" spellcheck="false"></td></tr>';
588 print
'<tr><td><span class="'.(GETPOST(
'paiementcode') ==
'CHQ' ?
'fieldrequired ' :
'').
'fieldrequireddyn">'.$langs->trans(
'CheckTransmitter').
'</span>';
589 print
' <em class="opacitymedium small">('.$langs->trans(
"ChequeMaker").
')</em>';
591 print
'<td><input id="fieldchqemetteur" class="maxwidth300" name="chqemetteur" type="text" value="'.GETPOST(
'chqemetteur',
'alphanohtml').
'" spellcheck="false"></td></tr>';
594 print
'<tr><td>'.$langs->trans(
'Bank');
595 print
' <em class="opacitymedium small">('.$langs->trans(
"ChequeBank").
')</em>';
597 print
'<td><input name="chqbank" class="maxwidth300" type="text" value="'.GETPOST(
'chqbank',
'alphanohtml').
'" spellcheck="false"></td></tr>';
600 print
'<tr><td class="tdtop">'.$langs->trans(
'Comments').
'</td>';
602 print
'<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_2.
'">'.
GETPOST(
'comment',
'restricthtml').
'</textarea>';
606 if ($action !=
'add_paiement' &&
getDolGlobalString(
'FACTURE_PAYMENTS_SHOW_LINK_TO_INPUT_ORIGIN_IS_MORE_THAN')) {
607 print
'<tr><td></td>';
608 print
'<td class="tdtop right">';
609 print
'<a class="right" href="#amount_'.$facid.
'">'.$langs->trans(
"GoSourceInvoice").
'</a>';
622 $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,";
623 $sql .=
" f.datef as df, f.fk_soc as socid, f.date_lim_reglement as dlr";
624 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
625 $sql .=
" WHERE f.entity IN (".getEntity(
'facture').
")";
626 $sql .=
" AND (f.fk_soc = ".((int) $facture->socid);
628 if (
getDolGlobalString(
'FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS') && !empty($facture->thirdparty->parent)) {
629 $sql .=
" OR f.fk_soc IN (SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe WHERE parent = ".((int) $facture->thirdparty->parent).
")";
633 $sql .=
" OR f.fk_soc IN (SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe WHERE parent = ".((int) $facture->thirdparty->id).
")";
635 $sql .=
") AND f.paye = 0";
636 $sql .=
" AND f.fk_statut = 1";
638 if (!$displayAllInvoices) {
640 $sql .=
" AND type IN (0,1,3,5)";
642 $sql .=
" AND type = 2";
645 if (!
getDolGlobalInt(
'FACTURE_PAYMENTS_INVOICE_REQUESTED_SORT_FIRST')) {
647 $sql .=
" ORDER BY f.datef ASC, f.ref ASC";
650 $sql .=
" ORDER BY f.rowid = ".((int) $facid).
" DESC, f.datef ASC, f.ref ASC";
653 $resql = $db->query($sql);
655 $num = $db->num_rows($resql);
656 $totalnboflines = $num = $db->num_rows($resql);
658 $arraytitle = $langs->trans(
'Invoice');
660 $arraytitle = $langs->trans(
"CreditNotes");
662 $alreadypayedlabel = $langs->trans(
'Received');
663 $multicurrencyalreadypayedlabel = $langs->trans(
'Received');
665 $alreadypayedlabel = $langs->trans(
"PaidBack");
666 $multicurrencyalreadypayedlabel = $langs->trans(
"PaidBack");
668 $remaindertopay = $langs->trans(
'RemainderToTake');
669 $multicurrencyremaindertopay = $langs->trans(
'RemainderToTake');
671 $remaindertopay = $langs->trans(
"RemainderToPayBack");
672 $multicurrencyremaindertopay = $langs->trans(
"RemainderToPayBack");
679 if ($action==
'create') {
680 $urlToggleDisplayMod = $_SERVER[
"PHP_SELF"].
'?facid='.$facid.
'&action='.$action.
'&accountid='.$accountid.
'&display-all-invoices=' . (intval(!$displayAllInvoices));
682 if (empty($displayAllInvoices)) {
683 $btnTitle = $langs->trans(
'DisplayOtherInvoicesToo');
685 $btnTitle = $langs->trans(
'DisplayCreditNotesToo');
688 $btnTitle = $langs->trans(
'HideOtherInvoices');
690 $btnTitle = $langs->trans(
'HideCreditNotes');
695 $btnCssGray = empty($displayAllInvoices) ?
' opacitymediumbycolor' :
'';
696 $moreHtmlRight .=
'<a class="btnTitle" title="'.dolPrintHTMLForAttribute($btnTitle).
'" href="'.
dol_escape_htmltag($urlToggleDisplayMod).
'">';
697 $moreHtmlRight .=
'<span class="fa '.(empty($displayAllInvoices) ?
'fa-plus' :
'fa-minus').
' btnTitle-icon inline-blockimp valignmiddle'.$btnCssGray.
'" style="font-size:1.6em"></span>';
698 $moreHtmlRight .= img_picto(
'', empty($displayAllInvoices) ?
'billa_nocolor' :
'billa',
'style="font-size:1.6em"', 0, 0, 1,
'',
'inline-blockimp valignmiddle marginleftonlyshort'.$btnCssGray);
699 $moreHtmlRight .=
'</a>';
702 print_barre_liste($langs->trans(
'Invoices'), 0, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', $num, $totalnboflines,
'bill', 0, $moreHtmlRight,
'', 0, 0, 0, 1);
704 print
'<div class="div-table-responsive-no-min">';
705 print
'<table id="customer-invoices-paiments-list" class="noborder centpercent" data-display-all-invoices="' . (int) $displayAllInvoices .
'" >';
708 print
'<tr class="liste_titre">';
709 print
'<td>'.$arraytitle.
'</td>';
710 if ($displayAllInvoices) {
711 print
'<td>' . $langs->trans(
'Type') .
'</td>';
713 print
'<td class="center">'.$langs->trans(
'Date').
'</td>';
714 print
'<td class="center">'.$langs->trans(
'DateDue').
'</td>';
716 $langs->load(
"multicurrency");
717 $labeltoshow = $langs->trans(
"MulticurrencyOriginalCurrency");
718 print
'<td>'.$langs->trans(
'Currency').
'</th>';
719 print
'<td class="right">'.$langs->trans(
'AmountTTC').
' <span class="opacitymedium small nowraponall">('.$labeltoshow.
')</span></td>';
720 print
'<td class="right">'.$multicurrencyalreadypayedlabel.
' <span class="opacitymedium small nowraponall">('.$labeltoshow.
')</span></td>';
721 print
'<td class="right">'.$multicurrencyremaindertopay.
' <span class="opacitymedium small nowraponall">('.$labeltoshow.
')</span></td>';
722 print
'<td class="center">'.$langs->trans(
'PaymentAmount').
' <span class="opacitymedium small nowraponall">('.$labeltoshow.
')</span></td>';
724 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
725 print
'<td class="right">'.$alreadypayedlabel.
'</td>';
726 print
'<td class="right">'.$remaindertopay.
'</td>';
727 print
'<td class="right">'.$langs->trans(
'PaymentAmount').
'</td>';
729 $parameters = array();
730 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $facture, $action);
732 print
'<td align="right"> </td>';
737 $totalrecucreditnote = 0;
738 $totalrecudeposits = 0;
739 $multicurrency_total_ttc = 0;
740 $multicurrency_totalrecu = 0;
741 $multicurrency_totalrecucreditnote = 0;
742 $multicurrency_totalrecudeposits = 0;
743 $multicurrencycodetotal =
'';
744 $showtotalmulticurrency =
true;
749 $objp = $db->fetch_object($resql);
757 $soc->fetch($objp->socid);
760 $invoice->fetch($objp->facid);
761 $paiement = $invoice->getSommePaiement();
762 $creditnotes = $invoice->getSumCreditNotesUsed();
763 $deposits = $invoice->getSumDepositsUsed();
764 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
765 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
768 $tooltiponmulticurrencyfullamount =
'';
769 $multicurrency_remaintopay =
'';
770 $multicurrency_payment = 0;
771 $multicurrency_creditnotes = 0;
772 $multicurrency_deposits = 0;
774 $multicurrency_payment = $invoice->getSommePaiement(1);
775 $multicurrency_creditnotes = $invoice->getSumCreditNotesUsed(1);
776 $multicurrency_deposits = $invoice->getSumDepositsUsed(1);
777 $multicurrency_alreadypayed = (float)
price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,
'MT');
778 $multicurrency_remaintopay = (float)
price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,
'MT');
780 $tooltiponmulticurrencyfullamount = $langs->trans(
'AmountHT') .
": " .
price($objp->multicurrency_total_ht, 0, $langs, 0, -1, -1, $objp->multicurrency_code) .
"<br>";
781 $tooltiponmulticurrencyfullamount .= $langs->trans(
'AmountVAT') .
": " .
price($objp->multicurrency_total_tva, 0, $langs, 0, -1, -1, $objp->multicurrency_code) .
"<br>";
782 $tooltiponmulticurrencyfullamount .= $langs->trans(
'AmountTTC') .
": " .
price($objp->multicurrency_total_ttc, 0, $langs, 0, -1, -1, $objp->multicurrency_code) .
"<br>";
786 $tooltiponfullamount = $langs->trans(
'AmountHT') .
": " .
price($objp->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
"<br>";
787 $tooltiponfullamount .= $langs->trans(
'AmountVAT') .
": " .
price($objp->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
"<br>";
788 $tooltiponfullamount .= $langs->trans(
'AmountTTC') .
": " .
price($objp->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) .
"<br>";
790 print
'<tr data-row-type="'.$objp->type.
'" class="oddeven'.(($invoice->id == $facid) ?
' highlight' :
'').
'">';
792 print
'<td class="nowraponall">';
793 print $invoice->getNomUrl(1,
'');
794 if ($objp->socid != $facture->thirdparty->id) {
795 print
' - '.$soc->getNomUrl(1).
' ';
800 if ($displayAllInvoices) {
808 print
'<td class="center nowraponall">' . $typearray[$objp->type] .
'</td>';
812 print
'<td class="center">'.dol_print_date($db->jdate($objp->df),
'day').
"</td>\n";
815 if ($objp->dlr > 0) {
816 print
'<td class="nowraponall center">';
819 if ($invoice->hasDelay()) {
820 print img_warning($langs->trans(
'Late'));
825 print
'<td align="center"></td>';
830 print
'<td class="center">'.$objp->multicurrency_code.
"</td>\n";
835 print
'<td class="right">';
836 if ($objp->multicurrency_code && $objp->multicurrency_code !=
$conf->currency) {
837 print
'<span class="amount classfortooltip" title="'.$tooltiponmulticurrencyfullamount.
'">' .
price($sign * $objp->multicurrency_total_ttc, 0, $langs, 0, -1, -1, $objp->multicurrency_code);
839 print
'</span></td>';
842 print
'<td class="right">';
843 print
'<span class="amount">';
844 if ($objp->multicurrency_code && $objp->multicurrency_code !=
$conf->currency) {
845 print
price($sign * $multicurrency_payment, 0, $langs, 0, -1, -1, $objp->multicurrency_code);
846 if ($multicurrency_creditnotes) {
847 print
'+'.price($multicurrency_creditnotes, 0, $langs, 0, -1, -1, $objp->multicurrency_code);
849 if ($multicurrency_deposits) {
850 print
'+'.price($multicurrency_deposits, 0, $langs, 0, -1, -1, $objp->multicurrency_code);
857 print
'<td class="right">';
858 if ($objp->multicurrency_code && $objp->multicurrency_code !=
$conf->currency) {
859 print
'<span class="amount">'.price($sign * (
float) $multicurrency_remaintopay, 0, $langs, 0, -1, -1, $objp->multicurrency_code).
'</span>';
863 print
'<td class="right nowraponall">';
866 $namef =
'multicurrency_amount_'.$objp->facid;
867 $nameRemain =
'multicurrency_remain_'.$objp->facid;
869 if ($displayAllInvoices) {
877 if ($objp->multicurrency_code && $objp->multicurrency_code !=
$conf->currency) {
878 if ($action !=
'add_paiement' || $useajaxconfirm) {
879 if (!empty(
$conf->use_javascript_ajax)) {
880 print
'<button type="button" class="btn-low-emphasis --btn-icon AutoFillAmount" data-rowname="'.$namef.
'" data-value="'.($sign * (float) $multicurrency_remaintopay).
'">';
881 print img_picto(
"Auto fill",
'rightarrow.png');
884 print
'<input '.$min.
' '.$max.
' type="text" class="multicurrency_amount right maxwidth100" name="'.$namef.
'" placeholder="'.
dol_escape_htmltag($langs->getCurrencySymbol($objp->multicurrency_code)).
'" value="'.
GETPOST($namef).
'">';
885 print
'<input type="hidden" class="multicurrency_remain" name="'.$nameRemain.
'" value="'.$multicurrency_remaintopay.
'">';
887 print
'<input type="text" class="maxwidth75" name="'.$namef.
'_disabled" placeholder="'.
dol_escape_htmltag($langs->getCurrencySymbol($objp->multicurrency_code)).
'" value="'.(
GETPOST($namef) !=
'0' ?
GETPOST($namef) :
'').
'" disabled>';
888 print
'<input type="hidden" name="'.$namef.
'" value="'.
GETPOST($namef).
'">';
895 print
'<td class="right"><span class="amount classfortooltip" title="'.$tooltiponfullamount.
'">'.
price($sign * $objp->total_ttc).
'</span></td>';
898 print
'<td class="right"><span class="amount">'.price($sign * $paiement);
900 print
'<span class="opacitymedium">+'.price($creditnotes).
'</span>';
903 print
'<span class="opacitymedium">+'.price($deposits).
'</span>';
905 print
'</span></td>';
908 print
'<td class="right">';
909 print
'<span class="amount">'.price($sign * (
float) $remaintopay).
'</span>';
911 $numdirectdebitopen = 0;
912 $totaldirectdebit = 0;
913 $sql =
"SELECT COUNT(pfd.rowid) as nb, SUM(pfd.amount) as amount";
914 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
915 $sql .=
" WHERE fk_facture = ".((int) $objp->facid);
916 $sql .=
" AND pfd.traite = 0";
917 $sql .=
" AND pfd.ext_payment_id IS NULL";
919 $result_sql = $db->query($sql);
921 $obj = $db->fetch_object($result_sql);
922 $numdirectdebitopen = $obj->nb;
923 $totaldirectdebit = $obj->amount;
925 dol_print_error($db);
927 if ($numdirectdebitopen) {
928 $langs->load(
"withdrawals");
929 print img_warning($langs->trans(
"WarningSomeDirectDebitOrdersAlreadyExists", $numdirectdebitopen,
price(
price2num($totaldirectdebit,
'MT'), 0, $langs, 1, -1, -1,
$conf->currency)),
'',
'classfortooltip');
936 print
'<td class="right nowraponall">';
939 $namef =
'amount_'.$objp->facid;
940 $nameRemain =
'remain_'.$objp->facid;
943 if ($displayAllInvoices) {
951 if ($action !=
'add_paiement' || $useajaxconfirm) {
952 if (!empty(
$conf->use_javascript_ajax)) {
953 print
'<button type="button" class="btn-low-emphasis --btn-icon AutoFillAmount" data-rowname="'.$namef.
'" data-value="'.($sign * (float) $remaintopay).
'">';
954 print img_picto(
"Auto fill",
'rightarrow.png');
957 print
'<input '.$max.
' '.$min.
' type="text" class="amount right maxwidth100" name="'.$namef.
'" value="'.
dol_escape_htmltag(
GETPOST($namef)).
'">';
958 print
'<input type="hidden" class="remain" name="'.$nameRemain.
'" value="'.$remaintopay.
'">';
960 print
'<input type="text" class="maxwidth75" name="'.$namef.
'_disabled" value="'.
dol_escape_htmltag(
GETPOST($namef)).
'" disabled>';
965 $parameters = array();
966 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $objp, $action);
969 print
'<td align="center" width="16">';
971 if (!empty($amounts[$invoice->id]) && (abs((
float) $amounts[$invoice->id]) > abs((
float) $amountsresttopay[$invoice->id]))
972 || !empty($multicurrency_amounts[$invoice->id]) && (abs((
float) $multicurrency_amounts[$invoice->id]) > abs((
float) $multicurrency_amountsresttopay[$invoice->id]))) {
973 print
' '.img_warning($langs->trans(
"PaymentHigherThanReminderToPay"));
979 $total_ttc += $objp->total_ttc;
980 $totalrecu += $paiement;
981 $totalrecucreditnote += $creditnotes;
982 $totalrecudeposits += $deposits;
985 if (empty($objp->multicurrency_code) || $objp->multicurrency_code ==
getDolCurrency()) {
986 $showtotalmulticurrency =
false;
988 if (empty($multicurrencycodetotal)) {
989 $multicurrencycodetotal = $objp->multicurrency_code;
991 $multicurrency_total_ttc += $objp->multicurrency_total_ttc;
992 $multicurrency_totalrecu += $multicurrency_payment;
993 $multicurrency_totalrecucreditnote += $multicurrency_creditnotes;
994 $multicurrency_totalrecudeposits += $multicurrency_deposits;
1004 if ($displayAllInvoices) {
1010 print
'<tr class="liste_total">';
1011 print
'<td colspan="'.$colspan.
'" class="left">'.$langs->trans(
'TotalTTC').
'</td>';
1014 if ($showtotalmulticurrency) {
1015 print
'<td class="right"><b>'.price($sign * $multicurrency_total_ttc, 0, $langs, 0, -1, -1, $multicurrencycodetotal).
'</b></td>';
1016 print
'<td class="right"><b>'.price($sign * $multicurrency_totalrecu, 0, $langs, 0, -1, -1, $multicurrencycodetotal);
1017 if ($multicurrency_totalrecucreditnote) {
1018 print
'+'.price($multicurrency_totalrecucreditnote, 0, $langs, 0, -1, -1, $multicurrencycodetotal);
1020 if ($multicurrency_totalrecudeposits) {
1021 print
'+'.price($multicurrency_totalrecudeposits, 0, $langs, 0, -1, -1, $multicurrencycodetotal);
1024 print
'<td class="right"><b>'.price($sign * (
float)
price2num($multicurrency_total_ttc - $multicurrency_totalrecu - $multicurrency_totalrecucreditnote - $multicurrency_totalrecudeposits,
'MT'), 0, $langs, 0, -1, -1, $multicurrencycodetotal).
'</b></td>';
1025 print
'<td class="right" id="multicurrency_result" style="font-weight: bold;"></td>';
1033 print
'<td class="right"><b>'.price($sign * $total_ttc).
'</b></td>';
1034 print
'<td class="right"><b>'.price($sign * $totalrecu);
1035 if ($totalrecucreditnote) {
1036 print
'+'.price($totalrecucreditnote);
1038 if ($totalrecudeposits) {
1039 print
'+'.price($totalrecudeposits);
1042 print
'<td class="right"><b>'.price($sign * (
float)
price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,
'MT')).
'</b></td>';
1043 print
'<td class="right" id="result" style="font-weight: bold;"></td>';
1044 print
'<td align="center"> </td>';
1055 dol_print_error($db);
1063 if ($action !=
'add_paiement' || $useajaxconfirm) {
1064 $checkboxlabel = $langs->trans(
"ClosePaidInvoicesAutomatically");
1066 $checkboxlabel = $langs->trans(
"ClosePaidCreditNotesAutomatically");
1068 $buttontitle = $langs->trans(
'ToMakePayment');
1070 $buttontitle = $langs->trans(
'ToMakePaymentBack');
1073 $closepaidinvoiceschecked = (($action ==
'add_paiement' && !
GETPOST(
'closepaidinvoices')) ?
'' :
' checked');
1075 print
'<br><div class="center">';
1076 print
'<input type="checkbox"'.$closepaidinvoiceschecked.
' name="closepaidinvoices" id="closepaidinvoices" class="marginrightonly"><label for="closepaidinvoices" class="opacitymedium">'.$checkboxlabel.
'</label>';
1077 print
'<br><input type="submit" class="button reposition" value="'.dol_escape_htmltag($buttontitle).
'"><br><br>';
1082 if ($action ==
'add_paiement') {
1083 $preselectedchoice = $addwarning ?
'no' :
'yes';
1087 if (!empty($totalpayment)) {
1088 $text = $langs->trans(
'ConfirmCustomerPayment', (
string) $totalpayment, $langs->transnoentitiesnoconv(
"Currency".$conf->currency));
1090 if (!empty($multicurrency_totalpayment)) {
1091 $text .=
'<br>'.$langs->trans(
'ConfirmCustomerPayment', (
string) $multicurrency_totalpayment, $langs->transnoentitiesnoconv(
"paymentInInvoiceCurrency"));
1093 if (
GETPOST(
'closepaidinvoices')) {
1094 $text .=
'<br>'.$langs->trans(
"AllCompletelyPayedInvoiceWillBeClosed");
1095 if (empty($useajaxconfirm)) {
1098 print
'<input type="hidden" name="closepaidinvoices" value="'.GETPOST(
'closepaidinvoices').
'">';
1101 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?facid='.$facture->id.
'&socid='.$facture->socid.
'&type='.$facture->type, $langs->trans(
'ReceivedCustomersPayments'), $text,
'confirm_paiement', $formquestion, $preselectedchoice, $useajaxconfirm);
1105 $parameters = array(
'formConfirm' => $formconfirm);
1106 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
1107 if (empty($reshook)) {
1108 $formconfirm .= $hookmanager->resPrint;
1109 } elseif ($reshook > 0) {
1110 $formconfirm = $hookmanager->resPrint;
1118 print
'<div class="error">'.$langs->trans(
"ErrorRecordNotFound").
'</div>';
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_DRAFT
Draft status.
const TYPE_STANDARD
Standard invoice.
const TYPE_DEPOSIT
Deposit invoice.
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
price2num($amount, $rounding='', $option=0, $currencycode='')
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'.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.