dolibarr  17.0.3
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 
311  function reset()
312  {
313  received=0;
314  $('.change1').html(pricejs(received, 'MT'));
315  $('.change1').val(price2numjs(received));
316  $('.change2').html(pricejs(received, 'MT'));
317  $('.change2').val(price2numjs(received));
318  $('.change1').removeClass('colorgreen');
319  $('.change1').addClass('colorred');
320  $('.change2').removeClass('colorred');
321  $('.change2').addClass('colorwhite');
322  }
323 
324  function Validate(payment)
325  {
326  var invoiceid = <?php echo ($invoiceid > 0 ? $invoiceid : 0); ?>;
327  var accountid = $("#selectaccountid").val();
328  var amountpayed = $("#change1").val();
329  var excess = $("#change2").val();
330  if (amountpayed > <?php echo $invoice->total_ttc; ?>) {
331  amountpayed = <?php echo $invoice->total_ttc; ?>;
332  }
333  console.log("We click on the payment mode to pay amount = "+amountpayed);
334  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() {
335  if (amountpayed > <?php echo $remaintopay; ?> || amountpayed == <?php echo $remaintopay; ?> || amountpayed==0 ) {
336  console.log("Close popup");
337  parent.$.colorbox.close();
338  }
339  else {
340  console.log("Amount is not comple, so we do NOT close popup and reload it.");
341  location.reload();
342  }
343  });
344  }
345 
346  function fetchPaymentIntentClientSecret(amount, invoiceid) {
347  const bodyContent = JSON.stringify({ amount : amount, invoiceid : invoiceid });
348  <?php
349  $urlpaymentintent = DOL_URL_ROOT.'/stripe/ajax/ajax.php?action=createPaymentIntent&token='.newToken().'&servicestatus='.$servicestatus;
350  if (!empty($stripeacc)) $urlpaymentintent .= '&stripeacc='.$stripeacc;
351  ?>
352  return fetch('<?php echo $urlpaymentintent; ?>', {
353  method: "POST",
354  headers: {
355  'Content-Type': 'application/json'
356  },
357  body: bodyContent
358  })
359  .then(function(response) {
360  return response.json();
361  })
362  .then(function(data) {
363  return data.client_secret;
364  });
365  }
366 
367 
368  function capturePaymentIntent(paymentIntentId) {
369  const bodyContent = JSON.stringify({"id": paymentIntentId})
370  <?php
371  $urlpaymentintent = DOL_URL_ROOT.'/stripe/ajax/ajax.php?action=capturePaymentIntent&token='.newToken().'&servicestatus='.urlencode($servicestatus);
372  if (!empty($stripeacc)) {
373  $urlpaymentintent .= '&stripeacc='.urlencode($stripeacc);
374  }
375  ?>
376  return fetch('<?php echo $urlpaymentintent; ?>', {
377  method: "POST",
378  headers: {
379  'Content-Type': 'application/json'
380  },
381  body: bodyContent
382  })
383  .then(function(response) {
384  return response.json();
385  })
386  .then(function(data) {
387  return data.client_secret;
388  });
389  }
390 
391 
392  function ValidateStripeTerminal() {
393  console.log("Launch ValidateStripeTerminal");
394  var invoiceid = <?php echo($invoiceid > 0 ? $invoiceid : 0); ?>;
395  var accountid = $("#selectaccountid").val();
396  var amountpayed = $("#change1").val();
397  var excess = $("#change2").val();
398  if (amountpayed > <?php echo $invoice->getRemainToPay(); ?>) {
399  amountpayed = <?php echo $invoice->getRemainToPay(); ?>;
400  }
401  if (amountpayed == 0) {
402  amountpayed = <?php echo $invoice->getRemainToPay(); ?>;
403  }
404 
405  console.log("Pay with terminal ", amountpayed);
406 
407  fetchPaymentIntentClientSecret(amountpayed, invoiceid).then(function(client_secret) {
408  <?php if (empty($servicestatus) && !empty($conf->global->STRIPE_TERMINAL_SIMULATED)) { ?>
409  terminal.setSimulatorConfiguration({testCardNumber: '<?php echo $conf->global->STRIPE_TERMINAL_SIMULATED; ?>'});
410  <?php } ?>
411  document.getElementById("card-present-alert").innerHTML = '<div class="warning clearboth"><?php echo $langs->trans('PaymentSendToStripeTerminal'); ?></div>';
412  terminal.collectPaymentMethod(client_secret).then(function(result) {
413  if (result.error) {
414  // Placeholder for handling result.error
415  document.getElementById("card-present-alert").innerHTML = '<div class="error clearboth">'+result.error.message+'</div>';
416  } else {
417  document.getElementById("card-present-alert").innerHTML = '<div class="warning clearboth"><?php echo $langs->trans('PaymentBeingProcessed'); ?></div>';
418  console.log('terminal.collectPaymentMethod', result.paymentIntent);
419  terminal.processPayment(result.paymentIntent).then(function(result) {
420  if (result.error) {
421  document.getElementById("card-present-alert").innerHTML = '<div class="error clearboth">'+result.error.message+'</div>';
422  console.log(result.error)
423  } else if (result.paymentIntent) {
424  paymentIntentId = result.paymentIntent.id;
425  console.log('terminal.processPayment', result.paymentIntent);
426  capturePaymentIntent(paymentIntentId).then(function(client_secret) {
427  if (result.error) {
428  // Placeholder for handling result.error
429  document.getElementById("card-present-alert").innerHTML = '<div class="error clearboth">'+result.error.message+'</div>';
430  console.log("error when capturing paymentIntent", result.error);
431  } else {
432  document.getElementById("card-present-alert").innerHTML = '<div class="warning clearboth"><?php echo $langs->trans('PaymentValidated'); ?></div>';
433  console.log("Capture paymentIntent successfull "+paymentIntentId);
434  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() {
435  if (amountpayed > <?php echo $remaintopay; ?> || amountpayed == <?php echo $remaintopay; ?> || amountpayed==0 ) {
436  console.log("Close popup");
437  parent.$.colorbox.close();
438  }
439  else {
440  console.log("Amount is not comple, so we do NOT close popup and reload it.");
441  location.reload();
442  }
443  });
444 
445  }
446  });
447  }
448  });
449  }
450  });
451  });
452  }
453 
454  function ValidateSumup() {
455  console.log("Launch ValidateSumup");
456  <?php $_SESSION['SMP_CURRENT_PAYMENT'] = "NEW" ?>
457  var invoiceid = <?php echo($invoiceid > 0 ? $invoiceid : 0); ?>;
458  var amountpayed = $("#change1").val();
459  if (amountpayed > <?php echo $invoice->total_ttc; ?>) {
460  amountpayed = <?php echo $invoice->total_ttc; ?>;
461  }
462 
463  // Starting sumup app
464  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');
465 
466  var loop = window.setInterval(function () {
467  $.ajax({
468  method: 'POST',
469  data: { token: '<?php echo currentToken(); ?>' },
470  url: '<?php echo DOL_URL_ROOT ?>/takepos/smpcb.php?status' }).done(function (data) {
471  console.log(data);
472  if (data === "SUCCESS") {
473  parent.$("#poslines").load("invoice.php?place=<?php echo $place; ?>&action=valid&token=<?php echo newToken(); ?>&pay=CB&amount=" + amountpayed + "&invoiceid=" + invoiceid, function () {
474  //parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
475  parent.$.colorbox.close();
476  //parent.setFocusOnSearchField(); // This does not have effect
477  });
478  clearInterval(loop);
479  } else if (data === "FAILED") {
480  parent.$.colorbox.close();
481  clearInterval(loop);
482  }
483  });
484  }, 2500);
485  }
486 
487 <?php
488 if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) {
489  echo "var line1='".$langs->trans('TotalTTC')."'.substring(0,20);";
490  echo "line1=line1.padEnd(20);";
491  echo "var line2='".price($invoice->total_ttc, 1, '', 1, -1, -1)."'.substring(0,20);";
492  echo "line2=line2.padEnd(20);";
493  echo "$.ajax({
494  type: 'GET',
495  data: { text: line1+line2 },
496  url: '".getDolGlobalString('TAKEPOS_PRINT_SERVER')."/display/index.php',
497  });";
498 }
499 ?>
500 </script>
501 
502 <div style="position:relative; padding-top: 20px; left:5%; height:140px; width:90%;">
503  <div class="paymentbordline paymentbordlinetotal center">
504  <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>
505  </div>
506  <?php if ($remaintopay != $invoice->total_ttc) { ?>
507  <div class="paymentbordline paymentbordlineremain center">
508  <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>
509  </div>
510  <?php } ?>
511  <div class="paymentbordline paymentbordlinereceived center">
512  <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>
513  </div>
514  <div class="paymentbordline paymentbordlinechange center">
515  <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>
516  </div>
517  <?php
518  if (!empty($conf->global->TAKEPOS_CAN_FORCE_BANK_ACCOUNT_DURING_PAYMENT)) {
519  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
520  print '<div class="paymentbordline paddingtop paddingbottom center">';
521  $filter = '';
522  $form = new Form($db);
523  print '<span class="takepospay colorwhite">'.$langs->trans("BankAccount").': </span>';
524  $form->select_comptes(0, 'accountid', 0, $filter, 1, '');
525  print ajax_combobox('selectaccountid');
526  print '</div>';
527  }
528  ?>
529 </div>
530 <div style="position:absolute; left:5%; height:52%; width:90%;">
531 <?php
532 $action_buttons = array(
533  array(
534  "function" =>"reset()",
535  "span" => "style='font-size: 150%;'",
536  "text" => "C",
537  "class" => "poscolorblue"
538  ),
539  array(
540  "function" => "parent.$.colorbox.close();",
541  "span" => "id='printtext' style='font-weight: bold; font-size: 18pt;'",
542  "text" => "X",
543  "class" => "poscolordelete"
544  ),
545 );
546 $numpad = $conf->global->TAKEPOS_NUMPAD;
547 if (isModEnabled('stripe') && isset($keyforstripeterminalbank) && !empty($conf->global->STRIPE_CARD_PRESENT)) {
548  print '<span id="card-present-alert">';
549  dol_htmloutput_mesg($langs->trans('ConnectingToStripeTerminal', 'Stripe'), '', 'warning', 1);
550  print '</span>';
551 }
552 print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '7' : '10').');">'.($numpad == 0 ? '7' : '10').'</button>';
553 print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '8' : '20').');">'.($numpad == 0 ? '8' : '20').'</button>';
554 print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '9' : '50').');">'.($numpad == 0 ? '9' : '50').'</button>';
555 ?>
556 <?php if (count($arrayOfValidPaymentModes) > 0) {
557  $paycode = $arrayOfValidPaymentModes[0]->code;
558  $payIcon = '';
559  if ($paycode == 'LIQ') {
560  if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
561  $payIcon = 'coins';
562  }
563  } elseif ($paycode == 'CB') {
564  if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
565  $payIcon = 'credit-card';
566  }
567  } elseif ($paycode == 'CHQ') {
568  if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
569  $payIcon = 'money-check';
570  }
571  }
572 
573  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>';
574 } else {
575  print '<button type="button" class="calcbutton2">'.$langs->trans("NoPaimementModesDefined").'</button>';
576 }
577 
578 print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '4' : '1').');">'.($numpad == 0 ? '4' : '1').'</button>';
579 print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '5' : '2').');">'.($numpad == 0 ? '5' : '2').'</button>';
580 print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '6' : '5').');">'.($numpad == 0 ? '6' : '5').'</button>';
581 ?>
582 <?php if (count($arrayOfValidPaymentModes) > 1) {
583  $paycode = $arrayOfValidPaymentModes[1]->code;
584  $payIcon = '';
585  if ($paycode == 'LIQ') {
586  if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
587  $payIcon = 'coins';
588  }
589  } elseif ($paycode == 'CB') {
590  if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
591  $payIcon = 'credit-card';
592  }
593  } elseif ($paycode == 'CHQ') {
594  if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
595  $payIcon = 'money-check';
596  }
597  }
598 
599  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>';
600 } else {
601  $button = array_pop($action_buttons);
602  print '<button type="button" class="calcbutton2" onclick="'.$button["function"].'"><span '.$button["span"].'>'.$button["text"].'</span></button>';
603 }
604 
605 print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '1' : '0.10').');">'.($numpad == 0 ? '1' : '0.10').'</button>';
606 print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '2' : '0.20').');">'.($numpad == 0 ? '2' : '0.20').'</button>';
607 print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '3' : '0.50').');">'.($numpad == 0 ? '3' : '0.50').'</button>';
608 ?>
609 <?php if (count($arrayOfValidPaymentModes) > 2) {
610  $paycode = $arrayOfValidPaymentModes[2]->code;
611  $payIcon = '';
612  if ($paycode == 'LIQ') {
613  if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
614  $payIcon = 'coins';
615  }
616  } elseif ($paycode == 'CB') {
617  if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
618  $payIcon = 'credit-card';
619  }
620  } elseif ($paycode == 'CHQ') {
621  if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
622  $payIcon = 'money-check';
623  }
624  }
625 
626  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>';
627 } else {
628  $button = array_pop($action_buttons);
629  print '<button type="button" class="calcbutton2" onclick="'.$button["function"].'"><span '.$button["span"].'>'.$button["text"].'</span></button>';
630 }
631 
632 print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '0' : '0.01').');">'.($numpad == 0 ? '0' : '0.01').'</button>';
633 print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '\'000\'' : '0.02').');">'.($numpad == 0 ? '000' : '0.02').'</button>';
634 print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '\'.\'' : '0.05').');">'.($numpad == 0 ? '.' : '0.05').'</button>';
635 
636 $i = 3;
637 while ($i < count($arrayOfValidPaymentModes)) {
638  $paycode = $arrayOfValidPaymentModes[$i]->code;
639  $payIcon = '';
640  if ($paycode == 'LIQ') {
641  if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
642  $payIcon = 'coins';
643  }
644  } elseif ($paycode == 'CB') {
645  if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
646  $payIcon = 'credit-card';
647  }
648  } elseif ($paycode == 'CHQ') {
649  if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
650  $payIcon = 'money-check';
651  }
652  }
653 
654  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>';
655  $i = $i + 1;
656 }
657 
658 if (isModEnabled('stripe') && isset($keyforstripeterminalbank) && !empty($conf->global->STRIPE_CARD_PRESENT)) {
659  $keyforstripeterminalbank = "CASHDESK_ID_BANKACCOUNT_STRIPETERMINAL".$_SESSION["takeposterminal"];
660  print '<span id="StripeTerminal"></span>';
661  if (!empty($conf->global->$keyforstripeterminalbank)) {
662  } else {
663  $langs->loadLangs(array("errors", "admin"));
664  //print '<button type="button" class="calcbutton2 disabled" title="'.$langs->trans("SetupNotComplete").'">TerminalOff</button>';
665  }
666 }
667 
668 $keyforsumupbank = "CASHDESK_ID_BANKACCOUNT_SUMUP".$_SESSION["takeposterminal"];
669 if (getDolGlobalInt('TAKEPOS_ENABLE_SUMUP')) {
670  if (!empty($conf->global->$keyforsumupbank)) {
671  print '<button type="button" class="calcbutton2" onclick="ValidateSumup();">Sumup</button>';
672  } else {
673  $langs->loadLangs(array("errors", "admin"));
674  print '<button type="button" class="calcbutton2 disabled" title="'.$langs->trans("SetupNotComplete").'">Sumup</button>';
675  }
676 }
677 
678 $parameters = array();
679 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $invoice, $action); // Note that $action and $object may have been modified by hook
680 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
681 
682 $class = ($i == 3) ? "calcbutton3" : "calcbutton2";
683 foreach ($action_buttons as $button) {
684  $newclass = $class.($button["class"] ? " ".$button["class"] : "");
685  print '<button type="button" class="'.$newclass.'" onclick="'.$button["function"].'"><span '.$button["span"].'>'.$button["text"].'</span></button>';
686 }
687 
688 if ($conf->global->TAKEPOS_DELAYED_PAYMENT) {
689  print '<button type="button" class="calcbutton2" onclick="Validate(\'delayed\');">'.$langs->trans("Reported").'</button>';
690 }
691 ?>
692 
693 <?php
694 // Add code from hooks
695 $parameters=array();
696 $hookmanager->executeHooks('completePayment', $parameters, $invoice);
697 print $hookmanager->resPrint;
698 ?>
699 
700 </div>
701 
702 </body>
703 </html>
pricejs
pricejs(amount, mode='MT', currency_code='', force_locale='')
Function similar to PHP price()
Definition: lib_head.js.php:1149
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:520
button
table tableforfield button
Definition: style.css.php:843
top_htmlhead
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
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
Facture
Class to manage invoices.
Definition: facture.class.php:60
price2numjs
price2numjs(amount)
Function similar to PHP price2num()
Definition: lib_head.js.php:1222
dol_escape_js
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
Definition: functions.lib.php:1444
Validate
Class toolbox to validate values.
Definition: validate.class.php:28
$resql
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
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11295
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
dol_htmloutput_mesg
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
Definition: functions.lib.php:8628
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
Stripe
Stripe class.
Definition: stripe.class.php:29
price
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.
Definition: functions.lib.php:5697
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1125
ajax_combobox
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
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25