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