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