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