pay.php 29 KB

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