pay.php 29 KB

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