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