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