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