dolibarr 25.0.0-alpha
paiement.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
7 * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
8 * Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
9 * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com>
10 * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
11 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2023-2026 Lenin Rivas <lenin.rivas777@gmail.com>
13 * Copyright (C) 2023 Sylvain Legrand <technique@infras.fr>
14 * Copyright (C) 2023 William Mead <william.mead@manchenumerique.fr>
15 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
16 * Copyright (C) 2025 Josep Lluís Amador <joseplluis@lliuretic.cat>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 */
31
38// Load Dolibarr environment
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';
51
52// Load translation files required by the page
53$langs->loadLangs(array('companies', 'bills', 'banks', 'multicurrency'));
54
55$action = GETPOST('action', 'alpha');
56$confirm = GETPOST('confirm', 'alpha');
57
58$facid = GETPOSTINT('facid');
59$accountid = GETPOSTINT('accountid');
60$paymentnum = GETPOST('num_paiement', 'alpha');
61$socid = GETPOSTINT('socid');
62
63$sortfield = GETPOST('sortfield', 'aZ09comma');
64$sortorder = GETPOST('sortorder', 'aZ09comma');
65$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
66
67$displayAllInvoices = getDolGlobalInt('MAIN_PAIMENTS_SHOW_ALL_INVOICE_TYPES', 0);
68if (GETPOSTISSET('display-all-invoices')) {
69 $displayAllInvoices = GETPOSTINT('display-all-invoices');
70}
71
72
73$amounts = array();
74$amountsresttopay = array();
75$addwarning = 0;
76
77$multicurrency_amounts = array();
78$multicurrency_amountsresttopay = array();
79
80// Security check
81if ($user->socid > 0) {
82 $socid = $user->socid;
83}
84
85$object = new Facture($db);
86
87// Load object
88if ($facid > 0) {
89 $ret = $object->fetch($facid);
90}
91
92// Initialize a technical object to manage hooks of paiements. Note that conf->hooks_modules contains array array
93$hookmanager->initHooks(array('paiementcard', 'globalcard'));
94
95$formquestion = array();
96
97$usercanissuepayment = $user->hasRight('facture', 'paiement');
98
99$fieldid = 'rowid';
100$isdraft = (($object->status == Facture::STATUS_DRAFT) ? 1 : 0);
101$result = restrictedArea($user, 'facture', $object->id, '', '', 'fk_soc', $fieldid, $isdraft);
102
103
104/*
105 * Actions
106 */
107$error = 0;
108
109$parameters = array('socid' => $socid);
110$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
111if ($reshook < 0) {
112 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
113}
114
115$paiement_id = 0;
116if (empty($reshook)) {
117 if (($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes')) && $usercanissuepayment) {
118 $datepaye = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
119 $totalpayment = 0;
120 $multicurrency_totalpayment = 0;
121 $atleastonepaymentnotnull = 0;
122 $formquestion = array();
123 $i = 0;
124
125 // Generate payment array and check if there is payment higher than invoice and payment date before invoice date
126 $tmpinvoice = new Facture($db);
127 // Can be into POST or GET (GET when the payment is confirmed from the ajax dialog box)
128 foreach (array_merge($_GET, $_POST) as $key => $value) {
129 if (substr($key, 0, 7) == 'amount_' && GETPOST($key) != '') {
130 $cursorfacid = (int) substr($key, 7);
131 $amounts[$cursorfacid] = price2num(GETPOST($key));
132 if (!empty($amounts[$cursorfacid])) {
133 $totalpayment += (float) $amounts[$cursorfacid];
134 $atleastonepaymentnotnull++;
135 }
136 $result = $tmpinvoice->fetch($cursorfacid);
137 if ($result <= 0) {
138 dol_print_error($db);
139 }
140 // The id comes from the name of a POST field, so it can name an invoice other than the
141 // one restrictedArea() was called on above. Check the user is allowed on that one too.
142 restrictedArea($user, 'facture', $tmpinvoice->id, '', '', 'fk_soc', 'rowid', (($tmpinvoice->status == Facture::STATUS_DRAFT) ? 1 : 0));
143 $amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement(0));
144 if ($amounts[$cursorfacid]) {
145 // Check amount
146 if ($amounts[$cursorfacid] && (abs((float) $amounts[$cursorfacid]) > abs((float) $amountsresttopay[$cursorfacid]))) {
147 $addwarning = 1;
148 $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
149 }
150 // Check date
151 if ($datepaye && ($datepaye < $tmpinvoice->date)) {
152 $langs->load("errors");
153 //$error++;
154 setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
155 }
156 }
157
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);
161 $multicurrency_amounts[$cursorfacid] = price2num(GETPOST($key));
162 $multicurrency_totalpayment += (float) $multicurrency_amounts[$cursorfacid];
163 if (!empty($multicurrency_amounts[$cursorfacid])) {
164 $atleastonepaymentnotnull++;
165 }
166 $result = $tmpinvoice->fetch($cursorfacid);
167 if ($result <= 0) {
168 dol_print_error($db);
169 }
170 // The id comes from the name of a POST field, so it can name an invoice other than the
171 // one restrictedArea() was called on above. Check the user is allowed on that one too.
172 restrictedArea($user, 'facture', $tmpinvoice->id, '', '', 'fk_soc', 'rowid', (($tmpinvoice->status == Facture::STATUS_DRAFT) ? 1 : 0));
173 $multicurrency_amountsresttopay[$cursorfacid] = price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1));
174 if ($multicurrency_amounts[$cursorfacid]) {
175 // Check amount
176 if ($multicurrency_amounts[$cursorfacid] && (abs((float) $multicurrency_amounts[$cursorfacid]) > abs((float) $multicurrency_amountsresttopay[$cursorfacid]))) {
177 $addwarning = 1;
178 $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
179 }
180 // Check date
181 if ($datepaye && ($datepaye < $tmpinvoice->date)) {
182 $langs->load("errors");
183 //$error++;
184 setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
185 }
186 }
187
188 $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => GETPOST($key));
189 }
190 }
191
192 // Check parameters
193 if (!GETPOST('paiementcode')) {
194 setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('PaymentMode')), null, 'errors');
195 $error++;
196 }
197
198 if (isModEnabled("bank")) {
199 // If bank module is on, account is required to enter a payment
200 if (GETPOST('accountid') <= 0) {
201 setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors');
202 $error++;
203 }
204 }
205
206 if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) {
207 setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->trans('PaymentAmount')), null, 'errors');
208 $error++;
209 }
210
211 if (empty($datepaye)) {
212 setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('Date')), null, 'errors');
213 $error++;
214 }
215
216 // Check if payments in both currency
217 if ($totalpayment > 0 && $multicurrency_totalpayment > 0) {
218 $langs->load("errors");
219 setEventMessages($langs->transnoentities('ErrorPaymentInBothCurrency'), null, 'errors');
220 $error++;
221 }
222 }
223
224 /*
225 * Action add_paiement
226 */
227 if ($action == 'add_paiement') { // Test on permission not required
228 if ($error) {
229 $action = 'create';
230 }
231 // The next of this action is displayed at the page's bottom.
232 }
233
234 /*
235 * Action confirm_paiement
236 */
237 if ($action == 'confirm_paiement' && $confirm == 'yes' && $usercanissuepayment) {
238 $datepaye = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'), 'tzuser');
239
240 $db->begin();
241
242 $thirdparty = new Societe($db);
243 if ($socid > 0) {
244 $thirdparty->fetch($socid);
245 }
246
247 $multicurrency_code = array();
248 $multicurrency_tx = array();
249
250 // Clean parameters amount if payment is for a credit note
251 foreach ($amounts as $key => $value) { // How payment is dispatched
252 $tmpinvoice = new Facture($db);
253 $tmpinvoice->fetch($key);
254 if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE) {
255 $newvalue = price2num($value, 'MT');
256 $amounts[$key] = - abs((float) $newvalue);
257 }
258 $multicurrency_code[$key] = $tmpinvoice->multicurrency_code;
259 $multicurrency_tx[$key] = $tmpinvoice->multicurrency_tx;
260 }
261
262 foreach ($multicurrency_amounts as $key => $value) { // How payment is dispatched
263 $tmpinvoice = new Facture($db);
264 $tmpinvoice->fetch((int) $key);
265 if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE) {
266 $newvalue = price2num($value, 'MT');
267 $multicurrency_amounts[$key] = - abs((float) $newvalue);
268 }
269 $multicurrency_code[$key] = $tmpinvoice->multicurrency_code;
270 $multicurrency_tx[$key] = $tmpinvoice->multicurrency_tx;
271 }
272
273 if (isModEnabled("bank")) {
274 // If the bank module is active, an account is required to input a payment
275 if (GETPOSTINT('accountid') <= 0) {
276 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors');
277 $error++;
278 }
279 }
280
281 // Creation of payment line
282 $paiement = new Paiement($db);
283 $paiement->datepaye = $datepaye;
284 $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id
285 $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching
286 $paiement->multicurrency_code = $multicurrency_code; // Array with all currency of payments dispatching
287 $paiement->multicurrency_tx = $multicurrency_tx; // Array with all currency tx of payments dispatching
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');
293
294 $paiement_id = 0;
295 if (!$error) {
296 // Create payment and update this->multicurrency_amounts if this->amounts filled or
297 // this->amounts if this->multicurrency_amounts filled.
298 // This also set ->amount and ->multicurrency_amount
299 $paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices') == 'on' ? 1 : 0), $thirdparty); // This include closing invoices and regenerating documents
300 if ($paiement_id < 0) {
301 setEventMessages($paiement->error, $paiement->errors, 'errors');
302 $error++;
303 }
304 }
305 /*
306 var_dump($paiement->amount);
307 var_dump($paiement->multicurrency_amount);
308 var_dump($paiement->multicurrency_currency);
309 */
310
311 if (!$error) {
312 $label = '(CustomerInvoicePayment)';
313 if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) {
314 $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
315 }
316
317 $result = $paiement->addPaymentToBank($user, 'payment', $label, GETPOSTINT('accountid'), GETPOST('chqemetteur'), GETPOST('chqbank'));
318 if ($result < 0) {
319 setEventMessages($paiement->error, $paiement->errors, 'errors');
320 $error++;
321 }
322 }
323
324 if (!$error) {
325 $db->commit();
326
327 // If payment dispatching on more than one invoice, we stay on summary page, otherwise jump on invoice card
328 $invoiceid = 0;
329 foreach ($paiement->amounts as $key => $amount) {
330 $facid = $key;
331 if (is_numeric($amount) && $amount != 0) {
332 if ($invoiceid != 0) {
333 $invoiceid = -1; // There is more than one invoice paid by this payment
334 } else {
335 $invoiceid = $facid;
336 }
337 }
338 }
339 if ($invoiceid > 0) {
340 $loc = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$invoiceid;
341 } else {
342 $loc = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id;
343 }
344 header('Location: '.$loc);
345 exit;
346 } else {
347 $db->rollback();
348 }
349 }
350}
351
352
353/*
354 * View
355 */
356
357$form = new Form($db);
358
359
360llxHeader('', $langs->trans("Payment"));
361
362// Does the confirm use the dialog box mode (must match the conditions into the formconfirm() method)
363$useajaxconfirm = (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) ? 1 : 0;
364
365
366$facture = new Facture($db);
367$result = $facture->fetch($facid);
368
369if ($result > 0) {
370 $facture->fetch_thirdparty();
371
372 $title = '';
373 if ($facture->type != Facture::TYPE_CREDIT_NOTE) {
374 $title .= $langs->trans("EnterPaymentReceivedFromCustomer");
375 }
376 if ($facture->type == Facture::TYPE_CREDIT_NOTE) {
377 $title .= $langs->trans("EnterPaymentDueToCustomer");
378 }
379 print load_fiche_titre($title);
380
381 // Initialize data for confirmation (this is used because data can be change during confirmation)
382 if ($action == 'add_paiement') {
383 $i = count($formquestion);
384
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);
388 // Fields of the payment form, so the ajax confirm dialog can propagate them to the confirm action
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'));
399 }
400
401 // Invoice with Paypal transaction
402 // @TODO add hook here
403 if (isModEnabled('paypalplus') && getDolGlobalString('PAYPAL_ENABLE_TRANSACTION_MANAGEMENT') && !empty($facture->ref_ext)) {
404 if (getDolGlobalString('PAYPAL_BANK_ACCOUNT')) {
405 $accountid = getDolGlobalString('PAYPAL_BANK_ACCOUNT');
406 }
407 $paymentnum = $facture->ref_ext;
408 }
409
410 // Add realtime total information
411 if (!empty($conf->use_javascript_ajax)) {
412 print "\n".'<script type="text/javascript">';
413 print '$(document).ready(function () {
414 setPaiementCode();
415
416 $("#selectpaiementcode").change(function() {
417 setPaiementCode();
418 });
419
420 function setPaiementCode()
421 {
422 var code = $("#selectpaiementcode option:selected").val();
423 console.log("setPaiementCode code="+code);
424
425 if (code == \'CHQ\' || code == \'VIR\')
426 {
427 if (code == \'CHQ\')
428 {
429 $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
430 }
431 if ($(\'#fieldchqemetteur\').val() == \'\')
432 {
433 var emetteur = ('.$facture->type.' == '.Facture::TYPE_CREDIT_NOTE.') ? \''.dol_escape_js(dol_escape_htmltag(getDolGlobalString('MAIN_INFO_SOCIETE_NOM'))).'\' : jQuery(\'#thirdpartylabel\').val();
434 $(\'#fieldchqemetteur\').val(emetteur);
435 }
436 }
437 else
438 {
439 $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
440 $(\'#fieldchqemetteur\').val(\'\');
441 }
442 }
443
444 function _elemToJson(selector)
445 {
446 var subJson = {};
447 $.map(selector.serializeArray(), function(n,i)
448 {
449 subJson[n["name"]] = n["value"];
450 });
451
452 return subJson;
453 }
454 function callForResult(imgId, multicurrency = 0)
455 {
456 var json = {};
457 var form = $("#payment_form");
458 var keyresult = "result";
459
460 json["invoice_type"] = $("#invoice_type").val();
461 if (multicurrency) {
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"));
467 } else {
468 json["amountPayment"] = $("#amountpayment").attr("value");
469 json["amounts"] = _elemToJson(form.find("input.amount"));
470 json["remains"] = _elemToJson(form.find("input.remain"));
471 }
472 json["token"] = "'.currentToken().'";
473 if (imgId != null) {
474 json["imgClicked"] = imgId;
475 }
476
477 $.post("'.DOL_URL_ROOT.'/compta/ajaxpayment.php", json, function(data)
478 {
479 json = $.parseJSON(data);
480
481 form.data(json);
482
483 for (var key in json)
484 {
485 if (key == keyresult) {
486 if (json["makeRed"]) {
487 $("#"+key).addClass("error");
488 } else {
489 $("#"+key).removeClass("error");
490 }
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]);
496 });
497 }
498 }
499 });
500 }
501 $("#payment_form").find("input.amount").change(function() {
502 callForResult();
503 });
504 $("#payment_form").find("input.amount").keyup(function() {
505 callForResult();
506 });
507 // Multicurrency LRR
508 $("#payment_form").find("input.multicurrency_amount").change(function() {
509 callForResult(null, 1);
510 });
511 $("#payment_form").find("input.multicurrency_amount").keyup(function() {
512 callForResult(null, 1);
513 });
514 ';
515
516 print ' });'."\n";
517
518 //Add js for AutoFill
519 print ' $(document).ready(function () {';
520 print ' $(".AutoFillAmount").on(\'click touchstart\', function(e){
521 e.preventDefault();
522 $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
523 });';
524 print ' });'."\n";
525
526 print ' </script>'."\n";
527 }
528
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="">';
538
539 print dol_get_fiche_head();
540
541 print '<table class="border centpercent">';
542
543 // Third party
544 print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans('Company').'</span></td><td>'.$facture->thirdparty->getNomUrl(4)."</td></tr>\n";
545
546 // Date payment
547 print '<tr><td><span class="fieldrequired">'.$langs->trans('Date').'</span></td><td>';
548 $datepayment = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
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);
553 print '</td></tr>';
554
555 // Payment mode
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);
559 print "</td>\n";
560 print '</tr>';
561
562 // Bank account
563 print '<tr>';
564 if (isModEnabled("bank")) {
565 if ($facture->type != 2) {
566 print '<td><span class="fieldrequired">'.$langs->trans('AccountToCredit').'</span></td>';
567 }
568 if ($facture->type == 2) {
569 print '<td><span class="fieldrequired">'.$langs->trans('AccountToDebit').'</span></td>';
570 }
571
572 print '<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);
575 print '</td>';
576 } else {
577 print '<td>&nbsp;</td>';
578 }
579 print "</tr>\n";
580
581 // Bank check number
582 print '<tr><td>'.$langs->trans('Numero');
583 print ' <em class="opacitymedium small">('.$langs->trans("ChequeOrTransferNumber").')</em>';
584 print '</td>';
585 print '<td><input name="num_paiement" type="text" class="maxwidth200" value="'.$paymentnum.'" spellcheck="false"></td></tr>';
586
587 // Check transmitter
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>';
590 print '</td>';
591 print '<td><input id="fieldchqemetteur" class="maxwidth300" name="chqemetteur" type="text" value="'.GETPOST('chqemetteur', 'alphanohtml').'" spellcheck="false"></td></tr>';
592
593 // Bank name
594 print '<tr><td>'.$langs->trans('Bank');
595 print ' <em class="opacitymedium small">('.$langs->trans("ChequeBank").')</em>';
596 print '</td>';
597 print '<td><input name="chqbank" class="maxwidth300" type="text" value="'.GETPOST('chqbank', 'alphanohtml').'" spellcheck="false"></td></tr>';
598
599 // Comments
600 print '<tr><td class="tdtop">'.$langs->trans('Comments').'</td>';
601 print '<td>';
602 print '<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_2.'">'.GETPOST('comment', 'restricthtml').'</textarea>';
603 print '</td></tr>';
604
605 // Go Source Invoice (useful when there are many invoices)
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>';
610 print '</td></tr>';
611 }
612
613 print '</table>';
614
615 print dol_get_fiche_end();
616
617
618 /*
619 * List of unpaid invoices
620 */
621
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);
627 // Can pay invoices of all child of parent company
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).")";
630 }
631 // Can pay invoices of all child of myself
632 if (getDolGlobalString('FACTURE_PAYMENTS_ON_SUBSIDIARY_COMPANIES')) {
633 $sql .= " OR f.fk_soc IN (SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE parent = ".((int) $facture->thirdparty->id).")";
634 }
635 $sql .= ") AND f.paye = 0";
636 $sql .= " AND f.fk_statut = 1"; // Statut=0 => not validated, Statut=2 => canceled
637
638 if (!$displayAllInvoices) {
639 if ($facture->type != Facture::TYPE_CREDIT_NOTE) {
640 $sql .= " AND type IN (0,1,3,5)"; // Standard invoice, replacement, deposit, situation
641 } else {
642 $sql .= " AND type = 2"; // If paying back a credit note, we show all credit notes
643 }
644 }
645 if (!getDolGlobalInt('FACTURE_PAYMENTS_INVOICE_REQUESTED_SORT_FIRST')) {
646 // Sort invoices by date and serial number: the older one comes first
647 $sql .= " ORDER BY f.datef ASC, f.ref ASC";
648 } else {
649 // The requested invoice sort first
650 $sql .= " ORDER BY f.rowid = ".((int) $facid)." DESC, f.datef ASC, f.ref ASC";
651 }
652
653 $resql = $db->query($sql);
654 if ($resql) {
655 $num = $db->num_rows($resql);
656 $totalnboflines = $num = $db->num_rows($resql);
657 if ($num > 0) {
658 $arraytitle = $langs->trans('Invoice');
659 if ($facture->type == Facture::TYPE_CREDIT_NOTE) {
660 $arraytitle = $langs->trans("CreditNotes");
661 }
662 $alreadypayedlabel = $langs->trans('Received');
663 $multicurrencyalreadypayedlabel = $langs->trans('Received');
664 if ($facture->type == Facture::TYPE_CREDIT_NOTE) {
665 $alreadypayedlabel = $langs->trans("PaidBack");
666 $multicurrencyalreadypayedlabel = $langs->trans("PaidBack");
667 }
668 $remaindertopay = $langs->trans('RemainderToTake');
669 $multicurrencyremaindertopay = $langs->trans('RemainderToTake');
670 if ($facture->type == Facture::TYPE_CREDIT_NOTE) {
671 $remaindertopay = $langs->trans("RemainderToPayBack");
672 $multicurrencyremaindertopay = $langs->trans("RemainderToPayBack");
673 }
674
675 $i = 0;
676 //print '<tr><td colspan="3">';
677
678 $moreHtmlRight = '';
679 if ($action=='create') {
680 $urlToggleDisplayMod = $_SERVER["PHP_SELF"].'?facid='.$facid.'&action='.$action.'&accountid='.$accountid.'&display-all-invoices=' . (intval(!$displayAllInvoices));
681
682 if (empty($displayAllInvoices)) {
683 $btnTitle = $langs->trans('DisplayOtherInvoicesToo');
684 if ($object->type != Facture::TYPE_CREDIT_NOTE) {
685 $btnTitle = $langs->trans('DisplayCreditNotesToo');
686 }
687 } else {
688 $btnTitle = $langs->trans('HideOtherInvoices');
689 if ($object->type != Facture::TYPE_CREDIT_NOTE) {
690 $btnTitle = $langs->trans('HideCreditNotes');
691 }
692 }
693
694 // Show a +/- sign to toggle the visibility of credit notes with the credit note picto (grey when not active, colored when active)
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>';
700 }
701
702 print_barre_liste($langs->trans('Invoices'), 0, $_SERVER["PHP_SELF"], '', '', '', '', $num, $totalnboflines, 'bill', 0, $moreHtmlRight, '', 0, 0, 0, 1);
703
704 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
705 print '<table id="customer-invoices-paiments-list" class="noborder centpercent" data-display-all-invoices="' . (int) $displayAllInvoices . '" >';
706 print '<thead>';
707
708 print '<tr class="liste_titre">';
709 print '<td>'.$arraytitle.'</td>';
710 if ($displayAllInvoices) {
711 print '<td>' . $langs->trans('Type') . '</td>';
712 }
713 print '<td class="center">'.$langs->trans('Date').'</td>';
714 print '<td class="center">'.$langs->trans('DateDue').'</td>';
715 if (isModEnabled("multicurrency")) {
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>';
723 }
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>';
728
729 $parameters = array();
730 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $facture, $action); // Note that $action and $object may have been modified by hook
731
732 print '<td align="right">&nbsp;</td>';
733 print "</tr>\n";
734 print '</thead>';
735 $total_ttc = 0;
736 $totalrecu = 0;
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;
745 $sign = 1;
746
747 print '<tbody>';
748 while ($i < $num) {
749 $objp = $db->fetch_object($resql);
750
751 $sign = 1;
752 if ($facture->type == Facture::TYPE_CREDIT_NOTE && !$displayAllInvoices) {
753 $sign = -1;
754 }
755
756 $soc = new Societe($db);
757 $soc->fetch($objp->socid);
758
759 $invoice = new Facture($db);
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');
766
767 // Multicurrency Price
768 $tooltiponmulticurrencyfullamount = '';
769 $multicurrency_remaintopay = '';
770 $multicurrency_payment = 0;
771 $multicurrency_creditnotes = 0;
772 $multicurrency_deposits = 0;
773 if (isModEnabled('multicurrency')) {
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');
779 // Multicurrency full amount tooltip
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>";
783 }
784
785 // Full amount tooltip
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>";
789
790 print '<tr data-row-type="'.$objp->type.'" class="oddeven'.(($invoice->id == $facid) ? ' highlight' : '').'">';
791
792 print '<td class="nowraponall">';
793 print $invoice->getNomUrl(1, '');
794 if ($objp->socid != $facture->thirdparty->id) {
795 print ' - '.$soc->getNomUrl(1).' ';
796 }
797 print "</td>\n";
798
799 // type
800 if ($displayAllInvoices) {
801 $typearray = [
802 Facture::TYPE_STANDARD => $langs->trans("InvoiceStandard"),
803 Facture::TYPE_REPLACEMENT => $langs->trans("InvoiceReplacement"),
804 Facture::TYPE_CREDIT_NOTE => $langs->trans("InvoiceAvoir"),
805 Facture::TYPE_DEPOSIT => $langs->trans("InvoiceDeposit"),
806 ];
807 // Primary Secondary Success Danger Warning Info Light Dark status0 status1 status2 status3 status4 status5 status6 status7 status8 status9
808 print '<td class="center nowraponall">' . $typearray[$objp->type] . '</td>';
809 }
810
811 // Date
812 print '<td class="center">'.dol_print_date($db->jdate($objp->df), 'day')."</td>\n";
813
814 // Due date
815 if ($objp->dlr > 0) {
816 print '<td class="nowraponall center">';
817 print dol_print_date($db->jdate($objp->dlr), 'day');
818
819 if ($invoice->hasDelay()) {
820 print img_warning($langs->trans('Late'));
821 }
822
823 print '</td>';
824 } else {
825 print '<td align="center"></td>';
826 }
827
828 // Currency
829 if (isModEnabled('multicurrency')) {
830 print '<td class="center">'.$objp->multicurrency_code."</td>\n";
831 }
832
833 // Multicurrency full amount
834 if (isModEnabled('multicurrency')) {
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);
838 }
839 print '</span></td>';
840
841 // Multicurrency Price
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);
848 }
849 if ($multicurrency_deposits) {
850 print '+'.price($multicurrency_deposits, 0, $langs, 0, -1, -1, $objp->multicurrency_code);
851 }
852 }
853 print '</span>';
854 print '</td>';
855
856 // Multicurrency remain to pay
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>';
860 }
861 print '</td>';
862
863 print '<td class="right nowraponall">';
864
865 // Add remind multicurrency amount
866 $namef = 'multicurrency_amount_'.$objp->facid;
867 $nameRemain = 'multicurrency_remain_'.$objp->facid;
868 $min = $max = '';
869 if ($displayAllInvoices) {
870 if ($objp->type == Facture::TYPE_CREDIT_NOTE) {
871 $max = ' max="0" ';
872 } else {
873 $min = ' min="0" ';
874 }
875 }
876
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');
882 print '</button>';
883 }
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.'">';
886 } else {
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).'">';
889 }
890 }
891 print "</td>";
892 }
893
894 // Full amount
895 print '<td class="right"><span class="amount classfortooltip" title="'.$tooltiponfullamount.'">'.price($sign * $objp->total_ttc).'</span></td>';
896
897 // Received + already paid
898 print '<td class="right"><span class="amount">'.price($sign * $paiement);
899 if ($creditnotes) {
900 print '<span class="opacitymedium">+'.price($creditnotes).'</span>';
901 }
902 if ($deposits) {
903 print '<span class="opacitymedium">+'.price($deposits).'</span>';
904 }
905 print '</span></td>';
906
907 // Remain to take or to pay back
908 print '<td class="right">';
909 print '<span class="amount">'.price($sign * (float) $remaintopay).'</span>';
910 if (isModEnabled('prelevement')) {
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";
918
919 $result_sql = $db->query($sql);
920 if ($result_sql) {
921 $obj = $db->fetch_object($result_sql);
922 $numdirectdebitopen = $obj->nb;
923 $totaldirectdebit = $obj->amount;
924 } else {
925 dol_print_error($db);
926 }
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');
930 }
931 }
932 print '</td>';
933 //$test= price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits));
934
935 // Amount
936 print '<td class="right nowraponall">';
937
938 // Add remind amount
939 $namef = 'amount_'.$objp->facid;
940 $nameRemain = 'remain_'.$objp->facid;
941
942 $min = $max = '';
943 if ($displayAllInvoices) {
944 if ($objp->type == Facture::TYPE_CREDIT_NOTE) {
945 $max = ' max="0" ';
946 } else {
947 $min = ' min="0" ';
948 }
949 }
950
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');
955 print '</button>';
956 }
957 print '<input '.$max.' '.$min.' type="text" class="amount right maxwidth100" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">'; // class is required to be used by javascript callForResult();
958 print '<input type="hidden" class="remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
959 } else {
960 print '<input type="text" class="maxwidth75" name="'.$namef.'_disabled" value="'.dol_escape_htmltag(GETPOST($namef)).'" disabled>';
961 print '<input type="hidden" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
962 }
963 print "</td>";
964
965 $parameters = array();
966 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objp, $action); // Note that $action and $object may have been modified by hook
967
968 // Warning
969 print '<td align="center" width="16">';
970 //print "xx".$amounts[$invoice->id]."-".$amountsresttopay[$invoice->id]."<br>";
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"));
974 }
975 print '</td>';
976
977 print "</tr>\n";
978
979 $total_ttc += $objp->total_ttc;
980 $totalrecu += $paiement;
981 $totalrecucreditnote += $creditnotes;
982 $totalrecudeposits += $deposits;
983
984 if (isModEnabled('multicurrency')) {
985 if (empty($objp->multicurrency_code) || $objp->multicurrency_code == getDolCurrency()) {
986 $showtotalmulticurrency = false;
987 }
988 if (empty($multicurrencycodetotal)) {
989 $multicurrencycodetotal = $objp->multicurrency_code;
990 }
991 $multicurrency_total_ttc += $objp->multicurrency_total_ttc;
992 $multicurrency_totalrecu += $multicurrency_payment;
993 $multicurrency_totalrecucreditnote += $multicurrency_creditnotes;
994 $multicurrency_totalrecudeposits += $multicurrency_deposits;
995 }
996
997 $i++;
998 }
999
1000 if ($i > 1) {
1001 $colspan = 3;
1002
1003 // type
1004 if ($displayAllInvoices) {
1005 $colspan++;
1006 }
1007
1008 // Print total
1009
1010 print '<tr class="liste_total">';
1011 print '<td colspan="'.$colspan.'" class="left">'.$langs->trans('TotalTTC').'</td>';
1012 if (isModEnabled('multicurrency')) {
1013 print '<td></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);
1019 }
1020 if ($multicurrency_totalrecudeposits) {
1021 print '+'.price($multicurrency_totalrecudeposits, 0, $langs, 0, -1, -1, $multicurrencycodetotal);
1022 }
1023 print '</b></td>';
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>';
1026 } else {
1027 print '<td></td>';
1028 print '<td></td>';
1029 print '<td></td>';
1030 print '<td></td>';
1031 }
1032 }
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);
1037 }
1038 if ($totalrecudeposits) {
1039 print '+'.price($totalrecudeposits);
1040 }
1041 print '</b></td>';
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>'; // Autofilled
1044 print '<td align="center">&nbsp;</td>';
1045 print "</tr>\n";
1046 }
1047
1048 print '</tbody>';
1049
1050 print "</table>";
1051 print "</div>\n";
1052 }
1053 $db->free($resql);
1054 } else {
1055 dol_print_error($db);
1056 }
1057
1058 $formconfirm = '';
1059
1060 // Save button
1061 // When the confirm is a dialog box, the save button is kept so user can close the dialog,
1062 // change data and submit the payment form again
1063 if ($action != 'add_paiement' || $useajaxconfirm) {
1064 $checkboxlabel = $langs->trans("ClosePaidInvoicesAutomatically");
1065 if ($facture->type == Facture::TYPE_CREDIT_NOTE) {
1066 $checkboxlabel = $langs->trans("ClosePaidCreditNotesAutomatically");
1067 }
1068 $buttontitle = $langs->trans('ToMakePayment');
1069 if ($facture->type == Facture::TYPE_CREDIT_NOTE) {
1070 $buttontitle = $langs->trans('ToMakePaymentBack');
1071 }
1072 // Keep the checkbox state entered by the user when the page is rendered again after a submit
1073 $closepaidinvoiceschecked = (($action == 'add_paiement' && !GETPOST('closepaidinvoices')) ? '' : ' checked');
1074
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>';
1078 print '</div>';
1079 }
1080
1081 // Form to confirm payment
1082 if ($action == 'add_paiement') {
1083 $preselectedchoice = $addwarning ? 'no' : 'yes';
1084
1085 print '<br>';
1086 $text = '';
1087 if (!empty($totalpayment)) {
1088 $text = $langs->trans('ConfirmCustomerPayment', (string) $totalpayment, $langs->transnoentitiesnoconv("Currency".$conf->currency));
1089 }
1090 if (!empty($multicurrency_totalpayment)) {
1091 $text .= '<br>'.$langs->trans('ConfirmCustomerPayment', (string) $multicurrency_totalpayment, $langs->transnoentitiesnoconv("paymentInInvoiceCurrency"));
1092 }
1093 if (GETPOST('closepaidinvoices')) {
1094 $text .= '<br>'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed");
1095 if (empty($useajaxconfirm)) {
1096 // In dialog mode, the value is read from the checkbox by the dialog box itself.
1097 // In inline mode, we must carry it into the confirm form.
1098 print '<input type="hidden" name="closepaidinvoices" value="'.GETPOST('closepaidinvoices').'">';
1099 }
1100 }
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);
1102 }
1103
1104 // Call Hook formConfirm
1105 $parameters = array('formConfirm' => $formconfirm);
1106 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1107 if (empty($reshook)) {
1108 $formconfirm .= $hookmanager->resPrint;
1109 } elseif ($reshook > 0) {
1110 $formconfirm = $hookmanager->resPrint;
1111 }
1112
1113 // Print form confirm
1114 print $formconfirm;
1115
1116 print "</form>\n";
1117} else {
1118 print '<div class="error">'.$langs->trans("ErrorRecordNotFound").'</div>';
1119}
1120
1121
1122llxFooter();
1123
1124$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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.
Definition wrapper.php:73
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 generation of HTML components Only common components must be here.
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.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
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)
Definition html.lib.php:183
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
Definition receipt.php:492
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.