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