dolibarr 25.0.0-alpha
pay.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
3 * Copyright (C) 2021-2022 Thibault FOUCART <support@ptibogxiv.net>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
28// if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
29// if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
30// if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
31
32if (!defined('NOTOKENRENEWAL')) {
33 define('NOTOKENRENEWAL', '1');
34}
35if (!defined('NOREQUIREMENU')) {
36 define('NOREQUIREMENU', '1');
37}
38if (!defined('NOREQUIREHTML')) {
39 define('NOREQUIREHTML', '1');
40}
41
42// Load Dolibarr environment
43require '../main.inc.php'; // Load $user and permissions
52require_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php';
53require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
54require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
55require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
56
57// Load translation files required by the page
58$langs->loadLangs(array("main", "bills", "cashdesk", "banks"));
59
60$action = GETPOST('action', 'aZ09');
61
62$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : '0'); // $place is id of table for Bar or Restaurant
63
64$invoiceid = GETPOSTINT('invoiceid');
65
66$hookmanager->initHooks(array('takepospay'));
67
68if (!$user->hasRight('takepos', 'run')) {
70}
71
72
73/*
74 * View
75 */
76
77$arrayofcss = array('/takepos/css/pos.css.php');
78$arrayofjs = array();
79
80$head = '';
81$title = '';
82$disablejs = 0;
83$disablehead = 0;
84
85$head = '<link rel="stylesheet" href="css/pos.css.php">';
86if (getDolGlobalInt('TAKEPOS_COLOR_THEME') == 1) {
87 $head .= '<link rel="stylesheet" href="css/colorful.css">';
88}
89
90top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
91
92?>
93<body>
94<?php
95
96$usestripeterminals = 0;
97$keyforstripeterminalbank = '';
98$stripe = null;
99$servicestatus = 0;
100$stripeacc = null;
101
102if (isModEnabled('stripe')) {
103 $service = 'StripeTest';
104
105 if (getDolGlobalString('STRIPE_LIVE')/* && !GETPOST('forcesandbox', 'alpha') */) {
106 $service = 'StripeLive';
107 $servicestatus = 1;
108 }
109
110 // Force to use the correct API key
111 global $stripearrayofkeysbyenv;
112 $site_account = $stripearrayofkeysbyenv[$servicestatus]['publishable_key'];
113
114 $stripe = new Stripe($db);
115 $stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account (no remote access to Stripe here)
116
117 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
118 $invoicetmp = new Facture($db);
119 $invoicetmp->fetch($invoiceid);
120 $stripecu = $stripe->getStripeCustomerAccount($invoicetmp->socid, $servicestatus, $site_account); // Get remote Stripe customer 'cus_...' (no remote access to Stripe here)
121 $keyforstripeterminalbank = "CASHDESK_ID_BANKACCOUNT_STRIPETERMINAL".(empty($_SESSION['takeposterminal']) ? '' : $_SESSION['takeposterminal']);
122
123 $usestripeterminals = getDolGlobalString('STRIPE_LOCATION');
124
125 if ($usestripeterminals) {
126 ?>
127<script src="https://js.stripe.com/terminal/v1/"></script>
128<script>
129var terminal = StripeTerminal.create({
130 onFetchConnectionToken: fetchConnectionToken,
131 onUnexpectedReaderDisconnect: unexpectedDisconnect,
132});
133
134function unexpectedDisconnect() {
135 // In this function, your app should notify the user that the reader disconnected.
136 // You can also include a way to attempt to reconnect to a reader.
137 console.log("Disconnected from reader")
138}
139
140function fetchConnectionToken() {
141 <?php
142 $urlconnexiontoken = DOL_URL_ROOT.'/stripe/ajax/ajax.php?action=getConnexionToken&token='.currentToken().'&servicestatus='.urlencode((string) ($servicestatus));
143 if (getDolGlobalString('STRIPE_LOCATION')) {
144 $urlconnexiontoken .= '&location='.urlencode(getDolGlobalString('STRIPE_LOCATION'));
145 }
146 if (!empty($stripeacc)) {
147 $urlconnexiontoken .= '&stripeacc='.urlencode($stripeacc);
148 } ?>
149 // Do not cache or hardcode the ConnectionToken. The SDK manages the ConnectionToken's lifecycle.
150 return fetch('<?php echo $urlconnexiontoken; ?>', { method: "POST" })
151 .then(function(response) {
152 return response.json();
153 })
154 .then(function(data) {
155 return data.secret;
156 });
157}
158
159</script>
160 <?php
161 }
162}
163
164if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE')/* || GETPOST('forcesandbox', 'alpha') */)) {
165 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), [], 'warning', 1);
166}
167
168$invoice = new Facture($db);
169if ($invoiceid > 0) {
170 $invoice->fetch($invoiceid);
171} else {
172 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture";
173 $sql .= " WHERE entity IN (".getEntity('invoice').")";
174 $sql .= " AND ref = '(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
175 $resql = $db->query($sql);
176 $obj = $db->fetch_object($resql);
177 if ($obj) {
178 $invoiceid = $obj->rowid;
179 }
180 if (!$invoiceid) {
181 $invoiceid = 0; // Invoice does not exist yet
182 } else {
183 $invoice->fetch($invoiceid);
184 }
185}
186
187?>
188<script>
189<?php
190if ($usestripeterminals && $invoice->type != $invoice::TYPE_CREDIT_NOTE) {
191 if (!getDolGlobalString((string) $keyforstripeterminalbank) || $stripeacc === null) { ?>
192 const config = {
193 simulated: <?php if (empty($servicestatus) && getDolGlobalString('STRIPE_TERMINAL_SIMULATED')) { ?> true <?php } else { ?> false <?php } ?>
194 <?php if (getDolGlobalString('STRIPE_LOCATION')) { ?>, location: <?php echo "'".dol_escape_js(getDolGlobalString('STRIPE_LOCATION'))."'"; ?><?php } ?>
195 }
196 terminal.discoverReaders(config).then(function(discoverResult) {
197 if (discoverResult.error) {
198 console.log('Failed to discover: ', discoverResult.error);
199 } else if (discoverResult.discoveredReaders.length === 0) {
200 console.log('No available readers.');
201 } else {
202 // You should show the list of discoveredReaders to the
203 // cashier here and let them select which to connect to (see below).
204 selectedReader = discoverResult.discoveredReaders[0];
205 //console.log('terminal.discoverReaders', selectedReader); // only active for development
206
207 terminal.connectReader(selectedReader).then(function(connectResult) {
208 if (connectResult.error) {
209 document.getElementById("card-present-alert").innerHTML = '<div class="error">'+connectResult.error.message+'</div>';
210 console.log('Failed to connect: ', connectResult.error);
211 } else {
212 document.getElementById("card-present-alert").innerHTML = '';
213 console.log('Connected to reader: ', connectResult.reader.label);
214 if (document.getElementById("StripeTerminal")) {
215 document.getElementById("StripeTerminal").innerHTML = '<button type="button" class="calcbutton2" onclick="ValidateStripeTerminal();"><span class="fa fa-2x fa-credit-card iconwithlabel"></span><br>'+connectResult.reader.label+'</button>';
216 }
217 }
218 });
219 }
220 });
221 <?php } else { ?>
222 terminal.connectReader(<?php echo json_encode($stripe->getSelectedReader(getDolGlobalString((string) $keyforstripeterminalbank), $stripeacc, $servicestatus)); ?>).then(function(connectResult) {
223 if (connectResult.error) {
224 document.getElementById("card-present-alert").innerHTML = '<div class="error clearboth">'+connectResult.error.message+'</div>';
225 console.log('Failed to connect: ', connectResult.error);
226 } else {
227 document.getElementById("card-present-alert").innerHTML = '';
228 console.log('Connected to reader: ', connectResult.reader.label);
229 if (document.getElementById("StripeTerminal")) {
230 document.getElementById("StripeTerminal").innerHTML = '<button type="button" class="calcbutton2" onclick="ValidateStripeTerminal();"><span class="fa fa-2x fa-credit-card iconwithlabel"></span><br>'+connectResult.reader.label+'</button>';
231 }
232 }
233 });
234
235 <?php }
236} ?>
237</script>
238<?php
239
240// Define list of possible payments
241$arrayOfValidPaymentModes = array();
242$arrayOfValidBankAccount = array();
243
244$sql = "SELECT code, libelle as label FROM ".MAIN_DB_PREFIX."c_paiement";
245$sql .= " WHERE entity IN (".getEntity('c_paiement').")";
246$sql .= " AND active = 1";
247if (isALNERunningVersion() && $mysoc->country_code == 'FR') {
248 // In certified version, we can use only 3 payments modes in POS because
249 // the cash control feature support only this 3 payment modes
250 $sql .= " AND code IN ('LIQ', 'CB', 'CHQ')";
251}
252$sql .= " ORDER BY libelle";
253$resql = $db->query($sql);
254
255if ($resql) {
256 while ($obj = $db->fetch_object($resql)) {
257 $paycode = $obj->code;
258 if ($paycode == 'LIQ') {
259 $paycode = 'CASH';
260 }
261 if ($paycode == 'CB') {
262 $paycode = 'CB';
263 }
264 if ($paycode == 'CHQ') {
265 $paycode = 'CHEQUE';
266 }
267
268 $accountname = "CASHDESK_ID_BANKACCOUNT_".$paycode.$_SESSION["takeposterminal"];
269 if (getDolGlobalInt($accountname) > 0) {
270 $arrayOfValidBankAccount[getDolGlobalInt($accountname)] = getDolGlobalInt($accountname);
271 $arrayOfValidPaymentModes[] = $obj;
272 }
273 if (!isModEnabled('bank')) {
274 if ($paycode == 'CASH' || $paycode == 'CB') {
275 $arrayOfValidPaymentModes[] = $obj;
276 }
277 }
278 }
279}
280
281?>
282
283<script>
284<?php
285$remaintopay = 0;
286if ($invoice->id > 0) {
287 $remaintopay = $invoice->getRemainToPay();
288}
289$alreadypayed = (is_object($invoice) ? ($invoice->total_ttc - $remaintopay) : 0);
290
291$parameters = array();
292$reshook = $hookmanager->executeHooks('takeposPayActions', $parameters, $invoice, $action);
293
294
295if (!getDolGlobalInt("TAKEPOS_NUMPAD")) {
296 print "var received='';";
297} else {
298 print "var received=0;";
299}
300
301?>
302 var alreadypayed = <?php echo $alreadypayed ?>;
303 var invoicetype = <?php echo $invoice->type ?>;
304
305 function addreceived(price)
306 {
307 <?php
308 if (!getDolGlobalInt("TAKEPOS_NUMPAD")) {
309 print 'received+=String(price);'."\n";
310 } else {
311 print 'received+=parseFloat(price);'."\n";
312 }
313 ?>
314 $('.change1').html(pricejs(parseFloat(received), 'MT'));
315 $('.change1').val(parseFloat(received));
316 console.log("invoicetype="+invoicetype);
317 console.log("alreadyreceived="+alreadypayed);
318 console.log("received="+received);
319 if (invoicetype == 2) {
320 alreadypaydplusreceived = price2numjs(alreadypayed - parseFloat(received));
321 } else {
322 alreadypaydplusreceived = price2numjs(alreadypayed + parseFloat(received));
323 }
324 console.log("already+received = "+alreadypaydplusreceived);
325 //console.log("total_ttc = "+<?php echo (float) $invoice->total_ttc; ?>);
326 if (Math.abs(alreadypaydplusreceived) > Math.abs(<?php echo ((float) $invoice->total_ttc); ?>)) {
327 if (invoicetype == 2) {
328 var change = parseFloat(alreadypayed + parseFloat(received) + <?php echo (float) $invoice->total_ttc; ?>);
329 } else {
330 var change = parseFloat(alreadypayed + parseFloat(received) - <?php echo (float) $invoice->total_ttc; ?>);
331 }
332 $('.change2').html(pricejs(change, 'MT'));
333 $('.change2').val(change);
334 $('.change1').removeClass('colorred');
335 $('.change1').addClass('colorgreen');
336 $('.change2').removeClass('colorwhite');
337 $('.change2').addClass('colorred');
338 } else {
339 $('.change2').html(pricejs(0, 'MT'));
340 $('.change2').val(0);
341 if (alreadypaydplusreceived == <?php echo (float) $invoice->total_ttc; ?>) {
342 $('.change1').removeClass('colorred');
343 $('.change1').addClass('colorgreen');
344 $('.change2').removeClass('colorred');
345 $('.change2').addClass('colorwhite');
346 } else {
347 $('.change1').removeClass('colorgreen');
348 $('.change1').addClass('colorred');
349 $('.change2').removeClass('colorred');
350 $('.change2').addClass('colorwhite');
351 }
352 }
353
354 return true;
355 }
356
357 function reset()
358 {
359 received=0;
360 $('.change1').html(pricejs(received, 'MT'));
361 $('.change1').val(price2numjs(received));
362 $('.change2').html(pricejs(received, 'MT'));
363 $('.change2').val(price2numjs(received));
364 $('.change1').removeClass('colorgreen');
365 $('.change1').addClass('colorred');
366 $('.change2').removeClass('colorred');
367 $('.change2').addClass('colorwhite');
368 }
369
370 function Validate(payment)
371 {
372 console.log("Launch Validate");
373
374 var invoiceid = <?php echo($invoiceid > 0 ? $invoiceid : 0); ?>;
375 var accountid = $("#selectaccountid").val();
376 var amountpayed = $("#change1").val();
377 var excess = $("#change2").val();
378 if (amountpayed > <?php echo (float) $invoice->total_ttc; ?>) {
379 amountpayed = <?php echo (float) $invoice->total_ttc; ?>;
380 }
381 console.log("We click on the payment mode to pay amount = "+amountpayed);
382 parent.$("#poslines").load("invoice.php?place=<?php echo $place; ?>&action=valid&token=<?php echo currentToken(); ?>&pay="+payment+"&amount="+amountpayed+"&excess="+excess+"&invoiceid="+invoiceid+"&accountid="+accountid, function() {
383 if (amountpayed > <?php echo (float) $remaintopay; ?> || amountpayed == <?php echo (float) $remaintopay; ?> || amountpayed == 0 ) {
384 console.log("Close popup");
385 parent.$('#invoiceid').val("");
386 parent.$.colorbox.close();
387 } else {
388 console.log("Amount is not complete, so we do NOT close popup and reload it.");
389 location.reload();
390 }
391 });
392
393 return true;
394 }
395
396 // Open the credit apply page in a colorbox (parent window's colorbox)
397 function OpenCreditApply() {
398 parent.$.colorbox({
399 href: "creditnote_apply.php?invoiceid=<?php echo $invoiceid; ?>&place=" + <?php echo "'".dol_escape_js($place)."'"; ?> + "&token=<?php echo currentToken(); ?>",
400 width: "70%",
401 height: "80%",
402 transition: "none",
403 iframe: "true",
404 title: <?php echo "'".dol_escape_js($langs->trans('TakeposApplyAvailableCredit'))."'"; ?>
405 });
406 }
407
408 function fetchPaymentIntentClientSecret(amount, invoiceid) {
409 const bodyContent = JSON.stringify({ amount : amount, invoiceid : invoiceid });
410 <?php
411 $urlpaymentintent = DOL_URL_ROOT.'/stripe/ajax/ajax.php?action=createPaymentIntent&token='.currentToken().'&servicestatus='.urlencode((string) $servicestatus);
412 if (!empty($stripeacc)) {
413 $urlpaymentintent .= '&stripeacc='.$stripeacc;
414 }
415 ?>
416 return fetch('<?php echo $urlpaymentintent; ?>', {
417 method: "POST",
418 headers: {
419 'Content-Type': 'application/json'
420 },
421 body: bodyContent
422 })
423 .then(function(response) {
424 return response.json();
425 })
426 .then(function(data) {
427 return data.client_secret;
428 });
429 }
430
431
432 function capturePaymentIntent(paymentIntentId) {
433 const bodyContent = JSON.stringify({"id": paymentIntentId})
434 <?php
435 $urlpaymentintent = DOL_URL_ROOT.'/stripe/ajax/ajax.php?action=capturePaymentIntent&token='.currentToken().'&servicestatus='.urlencode((string) ($servicestatus));
436 if (!empty($stripeacc)) {
437 $urlpaymentintent .= '&stripeacc='.urlencode($stripeacc);
438 }
439 ?>
440 return fetch('<?php echo $urlpaymentintent; ?>', {
441 method: "POST",
442 headers: {
443 'Content-Type': 'application/json'
444 },
445 body: bodyContent
446 })
447 .then(function(response) {
448 return response.json();
449 })
450 .then(function(data) {
451 return data.client_secret;
452 });
453 }
454
455
456 function ValidateStripeTerminal() {
457 console.log("Launch ValidateStripeTerminal");
458 var invoiceid = <?php echo($invoiceid > 0 ? $invoiceid : 0); ?>;
459 var accountid = $("#selectaccountid").val();
460 var amountpayed = $("#change1").val();
461 var excess = $("#change2").val();
462 if (amountpayed > <?php echo (float) $invoice->getRemainToPay(); ?>) {
463 amountpayed = <?php echo (float) $invoice->getRemainToPay(); ?>;
464 }
465 if (amountpayed == 0) {
466 amountpayed = <?php echo (float) $invoice->getRemainToPay(); ?>;
467 }
468
469 console.log("Pay with terminal ", amountpayed);
470
471 fetchPaymentIntentClientSecret(amountpayed, invoiceid).then(function(client_secret) {
472 <?php if (empty($servicestatus) && getDolGlobalString('STRIPE_TERMINAL_SIMULATED')) { ?>
473 terminal.setSimulatorConfiguration({testCardNumber: <?php echo "'".dol_escape_js(getDolGlobalString('STRIPE_TERMINAL_SIMULATED'))."'" ; ?>});
474 <?php } ?>
475 document.getElementById("card-present-alert").innerHTML = '<div class="warning clearboth"><?php echo $langs->trans('PaymentSendToStripeTerminal'); ?></div>';
476 terminal.collectPaymentMethod(client_secret).then(function(result) {
477 if (result.error) {
478 // Placeholder for handling result.error
479 document.getElementById("card-present-alert").innerHTML = '<div class="error clearboth">'+result.error.message+'</div>';
480 } else {
481 document.getElementById("card-present-alert").innerHTML = '<div class="warning clearboth"><?php echo $langs->trans('PaymentBeingProcessed'); ?></div>';
482 console.log('terminal.collectPaymentMethod', result.paymentIntent);
483 terminal.processPayment(result.paymentIntent).then(function(result) {
484 if (result.error) {
485 document.getElementById("card-present-alert").innerHTML = '<div class="error clearboth">'+result.error.message+'</div>';
486 console.log(result.error)
487 } else if (result.paymentIntent) {
488 paymentIntentId = result.paymentIntent.id;
489 console.log('terminal.processPayment', result.paymentIntent);
490 capturePaymentIntent(paymentIntentId).then(function(client_secret) {
491 if (result.error) {
492 // Placeholder for handling result.error
493 document.getElementById("card-present-alert").innerHTML = '<div class="error clearboth">'+result.error.message+'</div>';
494 console.log("error when capturing paymentIntent", result.error);
495 } else {
496 document.getElementById("card-present-alert").innerHTML = '<div class="warning clearboth"><?php echo $langs->trans('PaymentValidated'); ?></div>';
497 console.log("Capture paymentIntent successful "+paymentIntentId);
498 parent.$("#poslines").load("invoice.php?place=<?php echo $place; ?>&action=valid&token=<?php echo newToken(); ?>&pay=CB&amount="+amountpayed+"&excess="+excess+"&invoiceid="+invoiceid+"&accountid="+accountid, function() {
499 if (amountpayed > <?php echo (float) $remaintopay; ?> || amountpayed == <?php echo (float) $remaintopay; ?> || amountpayed == 0 ) {
500 console.log("Close popup");
501 parent.$.colorbox.close();
502 }
503 else {
504 console.log("Amount is not comple, so we do NOT close popup and reload it.");
505 location.reload();
506 }
507 });
508
509 }
510 });
511 }
512 });
513 }
514 });
515 });
516 }
517
518 function ValidateSumup() {
519 console.log("Launch ValidateSumup");
520 <?php $_SESSION['SMP_CURRENT_PAYMENT'] = "NEW" ?>
521 var invoiceid = <?php echo ($invoiceid > 0 ? $invoiceid : 0); ?>;
522 var amountpayed = $("#change1").val();
523 if (amountpayed > <?php echo (float) $invoice->total_ttc; ?>) {
524 amountpayed = <?php echo (float) $invoice->total_ttc; ?>;
525 }
526 if (amountpayed == 0) {
527 amountpayed = <?php echo (float) $invoice->total_ttc; ?>;
528 }
529 var currencycode = "<?php echo $invoice->multicurrency_code; ?>";
530
531 // Starting sumup app
532 window.open('sumupmerchant://pay/1.0?affiliate-key=<?php echo urlencode(getDolGlobalString('TAKEPOS_SUMUP_AFFILIATE')) ?>&app-id=<?php echo urlencode(getDolGlobalString('TAKEPOS_SUMUP_APPID')) ?>&amount=' + amountpayed + '&currency=' + currencycode + '&title=' + invoiceid + '&callback=<?php echo DOL_MAIN_URL_ROOT ?>/takepos/smpcb.php');
533
534 var loop = window.setInterval(function () {
535 $.ajax({
536 method: 'POST',
537 data: { token: '<?php echo currentToken(); ?>' },
538 url: '<?php echo DOL_URL_ROOT ?>/takepos/smpcb.php?status' }).done(function (data) {
539 console.log(data);
540 if (data === "SUCCESS") {
541 parent.$("#poslines").load("invoice.php?place=<?php echo urlencode($place); ?>&action=valid&token=<?php echo newToken(); ?>&pay=CB&amount=" + amountpayed + "&invoiceid=" + invoiceid, function () {
542 //parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
543 parent.$.colorbox.close();
544 //parent.setFocusOnSearchField(); // This does not have effect
545 });
546 clearInterval(loop);
547 } else if (data === "FAILED") {
548 parent.$.colorbox.close();
549 clearInterval(loop);
550 }
551 });
552 }, 2500);
553 }
554
555<?php
556if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
557 echo "var line1='".$langs->trans('TotalTTC')."'.substring(0,20);";
558 echo "line1=line1.padEnd(20);";
559 echo "var line2='".price($invoice->total_ttc, 1, '', 1, -1, -1)."'.substring(0,20);";
560 echo "line2=line2.padEnd(20);";
561 if (getDolGlobalString('TAKEPOS_CONNECTOR_TO_WHB_CUSTOMER_DISPLAY')) {
562 echo 'webSocketCustomerDisplay.onOpen(function() {';
563 echo ' webSocketCustomerDisplay.send(line1);';
564 echo ' webSocketCustomerDisplay.send(line2);';
565 echo '});';
566 } else {
567 echo "$.ajax({
568 type: 'GET',
569 data: { text: line1+line2 },
570 url: '".getDolGlobalString('TAKEPOS_PRINT_SERVER')."/display/index.php',
571 });";
572 }
573}
574?>
575</script>
576
577<?php
578$sessioncurrency = $_SESSION["takeposcustomercurrency"] ?? '';
579print '<!-- conf->currency = '.$conf->currency.' - sessioncurrency = '.$sessioncurrency.' -->'."\n";
580$multicurrency = null;
581if (isModEnabled('multicurrency') && $sessioncurrency != "" && $conf->currency != $sessioncurrency) {
582 // Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
583 include_once DOL_DOCUMENT_ROOT . '/multicurrency/class/multicurrency.class.php';
584 $multicurrency = new MultiCurrency($db);
585 $multicurrency->fetch(0, $sessioncurrency);
586}
587?>
588
589<div style="position:relative; padding-top: 20px; left:5%; height:140px; width:90%;">
590 <div class="paymentbordline paymentbordlinetotal center">
591 <span class="takepospay colorwhite"><?php echo $langs->trans('TotalTTC'); ?>: <span id="totaldisplay" class="colorwhite"><?php
592 echo price($invoice->total_ttc, 1, '', 1, -1, -1, $conf->currency);
593 if ($multicurrency !== null) {
594 print ' &nbsp; <span id="linecolht-span-total opacitymedium" style="font-size:0.9em; font-style:italic;">(' . price($invoice->total_ht * $multicurrency->rate->rate) . ' ' . $sessioncurrency . ')</span>';
595 }
596 ?></span></span>
597 </div>
598 <?php if ($remaintopay != $invoice->total_ttc) { ?>
599 <div class="paymentbordline paymentbordlineremain center">
600 <span class="takepospay colorwhite"><?php echo $langs->trans('RemainToPay'); ?>: <span id="remaintopaydisplay" class="colorwhite"><?php
601 echo price($remaintopay, 1, '', 1, -1, -1, $conf->currency);
602 if ($multicurrency !== null) {
603 print ' &nbsp; <span id="linecolht-span-total opacitymedium" style="font-size:0.9em; font-style:italic;">(' . price($remaintopay * $multicurrency->rate->rate) . ' ' . $sessioncurrency . ')</span>';
604 }
605 ?></span></span>
606 </div>
607 <?php } ?>
608 <div class="paymentbordline paymentbordlinereceived center">
609 <span class="takepospay colorwhite"><?php echo $invoice->type == $invoice::TYPE_CREDIT_NOTE ? $langs->trans("Refunded") : $langs->trans("Received"); ?>: <span class="change1 colorred"><?php
610 echo price(0, 1, '', 1, -1, -1, $conf->currency);
611 if ($multicurrency !== null) {
612 print ' &nbsp; <span id="linecolht-span-total opacitymedium" style="font-size:0.9em; font-style:italic;">(' . price(0 * $multicurrency->rate->rate) . ' ' . $sessioncurrency . ')</span>';
613 }
614 ?></span><input type="hidden" id="change1" class="change1" value="0"></span>
615 </div>
616 <div class="paymentbordline paymentbordlinechange center">
617 <span class="takepospay colorwhite"><?php echo $langs->trans("Change"); ?>: <span class="change2 colorwhite"><?php
618 echo price(0, 1, '', 1, -1, -1, $conf->currency);
619 if ($multicurrency !== null) {
620 print ' &nbsp; <span id="linecolht-span-total opacitymedium" style="font-size:0.9em; font-style:italic;">(' . price(0 * $multicurrency->rate->rate) . ' ' . $sessioncurrency . ')</span>';
621 }
622 ?></span><input type="hidden" id="change2" class="change2" value="0"></span>
623 </div>
624 <?php
625 if (getDolGlobalString('TAKEPOS_CAN_FORCE_BANK_ACCOUNT_DURING_PAYMENT')) {
626 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
627 print '<div class="paymentbordline paddingtop paddingbottom center">';
628 $filter = '';
629 $form = new Form($db);
630 print '<span class="takepospay colorwhite">'.$langs->trans("BankAccount").': </span>';
631 $form->select_comptes(0, 'accountid', 0, $filter, 1, '');
632 print ajax_combobox('selectaccountid');
633 print '</div>';
634 }
635 ?>
636</div>
637<div style="position:absolute; left:5%; height:52%; width:90%;">
638<?php
639$action_buttons = array(
640array(
641"function" => "reset()",
642"span" => "style='font-size: 150%;'",
643"text" => "C",
644"class" => "poscolorblue"
645),
646array(
647"function" => "parent.$.colorbox.close();",
648"span" => "id='printtext' style='font-weight: bold; font-size: 18pt;'",
649"text" => "X",
650"class" => "poscolordelete"
651),
652);
653$numpad = getDolGlobalInt('TAKEPOS_NUMPAD');
654if (isModEnabled('stripe') && getDolGlobalString('STRIPE_CARD_PRESENT')) {
655 print '<span id="card-present-alert">';
656 dol_htmloutput_mesg($langs->trans('ConnectingToStripeTerminal', 'Stripe'), [], 'warning', 1);
657 print '</span>';
658}
659print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '7' : '10').')">'.($numpad == 0 ? '7' : '10').'</button>';
660print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '8' : '20').')">'.($numpad == 0 ? '8' : '20').'</button>';
661print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '9' : '50').')">'.($numpad == 0 ? '9' : '50').'</button>';
662?>
663<?php if (count($arrayOfValidPaymentModes) > 0) {
664 $paycode = $arrayOfValidPaymentModes[0]->code;
665 $payIcon = '';
666 if ($paycode == 'LIQ') {
667 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
668 $payIcon = 'coins';
669 }
670 } elseif ($paycode == 'CB') {
671 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
672 $payIcon = 'credit-card';
673 }
674 } elseif ($paycode == 'CHQ') {
675 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
676 $payIcon = 'money-check';
677 }
678 }
679
680 print '<button type="button" class="calcbutton2" onclick="Validate(\''.dol_escape_js($paycode).'\')">'.(!empty($payIcon) ? '<span class="fa fa-2x fa-'.$payIcon.' iconwithlabel"></span><span class="hideonsmartphone"><br>'.$langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[0]->code) : $langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[0]->code)).'</span></button>';
681} else {
682 print '<button type="button" class="calcbutton2">'.$langs->trans("NoPaimementModesDefined").'</button>';
683}
684
685print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '4' : '1').')">'.($numpad == 0 ? '4' : '1').'</button>';
686print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '5' : '2').')">'.($numpad == 0 ? '5' : '2').'</button>';
687print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '6' : '5').')">'.($numpad == 0 ? '6' : '5').'</button>';
688?>
689<?php if (count($arrayOfValidPaymentModes) > 1) {
690 $paycode = $arrayOfValidPaymentModes[1]->code;
691 $payIcon = '';
692 if ($paycode == 'LIQ') {
693 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
694 $payIcon = 'coins';
695 }
696 } elseif ($paycode == 'CB') {
697 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
698 $payIcon = 'credit-card';
699 }
700 } elseif ($paycode == 'CHQ') {
701 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
702 $payIcon = 'money-check';
703 }
704 }
705
706 print '<button type="button" class="calcbutton2" onclick="Validate(\''.dol_escape_js($paycode).'\')">'.(!empty($payIcon) ? '<span class="fa fa-2x fa-'.$payIcon.' iconwithlabel"></span><br> '.$langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[1]->code) : $langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[1]->code)).'</button>';
707} else {
708 $button = array_pop($action_buttons);
709 print '<button type="button" class="calcbutton2" onclick="'.$button["function"].'"><span '.$button["span"].'>'.$button["text"].'</span></button>';
710}
711
712print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '1' : '0.10').')">'.($numpad == 0 ? '1' : '0.10').'</button>';
713print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '2' : '0.20').')">'.($numpad == 0 ? '2' : '0.20').'</button>';
714print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '3' : '0.50').')">'.($numpad == 0 ? '3' : '0.50').'</button>';
715?>
716<?php if (count($arrayOfValidPaymentModes) > 2) {
717 $paycode = $arrayOfValidPaymentModes[2]->code;
718 $payIcon = '';
719 if ($paycode == 'LIQ') {
720 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
721 $payIcon = 'coins';
722 }
723 } elseif ($paycode == 'CB') {
724 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
725 $payIcon = 'credit-card';
726 }
727 } elseif ($paycode == 'CHQ') {
728 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
729 $payIcon = 'money-check';
730 }
731 }
732
733 print '<button type="button" class="calcbutton2" onclick="Validate(\''.dol_escape_js($paycode).'\')">'.(!empty($payIcon) ? '<span class="fa fa-2x fa-'.$payIcon.' iconwithlabel"></span><br>'.$langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[2]->code) : $langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[2]->code)).'</button>';
734} else {
735 $button = array_pop($action_buttons);
736 print '<button type="button" class="calcbutton2" onclick="'.$button["function"].'"><span '.$button["span"].'>'.$button["text"].'</span></button>';
737}
738
739print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '0' : '0.01').')">'.($numpad == 0 ? '0' : '0.01').'</button>';
740print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '\'000\'' : '0.02').')">'.($numpad == 0 ? '000' : '0.02').'</button>';
741print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '\'.\'' : '0.05').')">'.($numpad == 0 ? '.' : '0.05').'</button>';
742
743$i = 3;
744while ($i < count($arrayOfValidPaymentModes)) {
745 $paycode = $arrayOfValidPaymentModes[$i]->code;
746 $payIcon = '';
747 if ($paycode == 'LIQ') {
748 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
749 $payIcon = 'coins';
750 }
751 } elseif ($paycode == 'CB') {
752 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
753 $payIcon = 'credit-card';
754 }
755 } elseif ($paycode == 'CHQ') {
756 if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || getDolGlobalString('TAKEPOS_NUMPAD_USE_PAYMENT_ICON')) {
757 $payIcon = 'money-check';
758 }
759 }
760
761 print '<button type="button" class="calcbutton2" onclick="Validate(\''.dol_escape_js($paycode).'\')">'.(!empty($payIcon) ? '<span class="fa fa-2x fa-'.$payIcon.' iconwithlabel"></span><br>'.$langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[$i]->code) : $langs->trans("PaymentTypeShort".$arrayOfValidPaymentModes[$i]->code)).'</button>';
762 $i += 1;
763}
764
765// Show "Available credit" button when the customer has credits and this is not a credit note
766if ($invoice->socid > 0 && $invoice->type != Facture::TYPE_CREDIT_NOTE) {
767 $invoice->fetch_thirdparty();
768 if (is_object($invoice->thirdparty)) {
769 $discountCheck = new DiscountAbsolute($db);
770 $availableCredit = $discountCheck->getAvailableDiscounts($invoice->thirdparty, null, '', 0, 0, 0);
771 if ($availableCredit > 0) {
772 print '<button type="button" class="calcbutton2" onclick="OpenCreditApply()">';
773 print '<span class="fa fa-2x fa-wallet iconwithlabel"></span><br>';
774 print $langs->trans('TakeposAvailableCredit').'<br>';
775 print '<span style="font-size:0.85em;">'.price($availableCredit, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
776 print '</button>';
777 }
778 }
779}
780
781if (isModEnabled('stripe') && getDolGlobalString('STRIPE_CARD_PRESENT')) {
782 $keyforstripeterminalbank = "CASHDESK_ID_BANKACCOUNT_STRIPETERMINAL".$_SESSION["takeposterminal"];
783 print '<span id="StripeTerminal"></span>';
784 if (getDolGlobalString((string) $keyforstripeterminalbank)) {
785 // Nothing
786 } else {
787 $langs->loadLangs(array("errors", "admin"));
788 //print '<button type="button" class="calcbutton2 disabled" title="'.$langs->trans("SetupNotComplete").'">TerminalOff</button>';
789 }
790}
791
792$keyforsumupbank = "CASHDESK_ID_BANKACCOUNT_SUMUP".$_SESSION["takeposterminal"];
793if (getDolGlobalInt("TAKEPOS_ENABLE_SUMUP")) {
794 if (getDolGlobalString($keyforsumupbank)) {
795 print '<button type="button" class="calcbutton2" onclick="ValidateSumup();">Sumup</button>';
796 } else {
797 $langs->loadLangs(array("errors", "admin"));
798 print '<button type="button" class="calcbutton2 disabled" title="'.$langs->trans("SetupNotComplete").'">Sumup</button>';
799 }
800}
801
802$parameters = array('action_buttons' => $action_buttons);
803$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $invoice, $action); // Note that $action and $invoice may have been modified by hook
804if ($reshook < 0) {
805 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
806} elseif ($reshook == 0) {
807 $action_buttons = array_merge($action_buttons, $hookmanager->resArray);
808} elseif ($reshook > 0) {
809 $action_buttons = $hookmanager->resArray;
810}
811
812$class = ($i == 3) ? "calcbutton3" : "calcbutton2";
813foreach ($action_buttons as $button) {
814 $newclass = $class.($button["class"] ? " ".$button["class"] : "");
815 print '<button type="button" class="'.$newclass.'" onclick="'.$button["function"].'"><span '.$button["span"].'>'.$button["text"].'</span></button>';
816}
817
818if (getDolGlobalString('TAKEPOS_DELAYED_PAYMENT')) {
819 print '<button type="button" class="calcbutton2" onclick="Validate(\'delayed\')">'.$langs->trans("Reported").'</button>';
820}
821?>
822
823<?php
824// Add code from hooks
825$parameters = array();
826$hookmanager->executeHooks('completePayment', $parameters, $invoice);
827print $hookmanager->resPrint;
828?>
829
830</div>
831
832</body>
833</html>
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:488
isALNERunningVersion($blockedlogusagealreadychecked=0, $blockedlogmoduleonalreadychecked=0)
Return if the application is executed with the LNE requirements on.
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.
Class to manage generation of HTML components Only common components must be here.
Class Currency.
Stripe class @TODO No reason to extend CommonObject.
Class toolbox to validate values.
global $mysoc
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Build the customer statement lines (invoices and payments) with running balance.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
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 p p num_paiement as f pf amount as amount
Definition receipt.php:494
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
a disabled