pay.php 28 KB

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