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