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