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