pay.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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. return true;
  267. }
  268. function reset()
  269. {
  270. received=0;
  271. $('.change1').html(pricejs(received, 'MT'));
  272. $('.change1').val(price2numjs(received));
  273. $('.change2').html(pricejs(received, 'MT'));
  274. $('.change2').val(price2numjs(received));
  275. $('.change1').removeClass('colorgreen');
  276. $('.change1').addClass('colorred');
  277. $('.change2').removeClass('colorred');
  278. $('.change2').addClass('colorwhite');
  279. }
  280. function Validate(payment)
  281. {
  282. var invoiceid = <?php echo ($invoiceid > 0 ? $invoiceid : 0); ?>;
  283. var accountid = $("#selectaccountid").val();
  284. var amountpayed = $("#change1").val();
  285. var excess = $("#change2").val();
  286. if (amountpayed > <?php echo $invoice->total_ttc; ?>) {
  287. amountpayed = <?php echo $invoice->total_ttc; ?>;
  288. }
  289. console.log("We click on the payment mode to pay amount = "+amountpayed);
  290. 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() {
  291. if (amountpayed > <?php echo $remaintopay; ?> || amountpayed == <?php echo $remaintopay; ?> || amountpayed==0 ) {
  292. console.log("Close popup");
  293. parent.$.colorbox.close();
  294. }
  295. else {
  296. console.log("Amount is not comple, so we do NOT close popup and reload it.");
  297. location.reload();
  298. }
  299. });
  300. return true;
  301. }
  302. function fetchPaymentIntentClientSecret(amount, invoiceid) {
  303. const bodyContent = JSON.stringify({ amount : amount, invoiceid : invoiceid });
  304. <?php
  305. $urlpaymentintent = DOL_URL_ROOT.'/stripe/ajax/ajax.php?action=createPaymentIntent&token='.newToken().'&servicestatus='.$servicestatus;
  306. if (!empty($stripeacc)) $urlpaymentintent .= '&stripeacc='.$stripeacc;
  307. ?>
  308. return fetch('<?php echo $urlpaymentintent; ?>', {
  309. method: "POST",
  310. headers: {
  311. 'Content-Type': 'application/json'
  312. },
  313. body: bodyContent
  314. })
  315. .then(function(response) {
  316. return response.json();
  317. })
  318. .then(function(data) {
  319. return data.client_secret;
  320. });
  321. }
  322. function capturePaymentIntent(paymentIntentId) {
  323. const bodyContent = JSON.stringify({"id": paymentIntentId})
  324. <?php
  325. $urlpaymentintent = DOL_URL_ROOT.'/stripe/ajax/ajax.php?action=capturePaymentIntent&token='.newToken().'&servicestatus='.urlencode($servicestatus);
  326. if (!empty($stripeacc)) {
  327. $urlpaymentintent .= '&stripeacc='.urlencode($stripeacc);
  328. }
  329. ?>
  330. return fetch('<?php echo $urlpaymentintent; ?>', {
  331. method: "POST",
  332. headers: {
  333. 'Content-Type': 'application/json'
  334. },
  335. body: bodyContent
  336. })
  337. .then(function(response) {
  338. return response.json();
  339. })
  340. .then(function(data) {
  341. return data.client_secret;
  342. });
  343. }
  344. function ValidateStripeTerminal() {
  345. console.log("Launch ValidateStripeTerminal");
  346. var invoiceid = <?php echo($invoiceid > 0 ? $invoiceid : 0); ?>;
  347. var accountid = $("#selectaccountid").val();
  348. var amountpayed = $("#change1").val();
  349. var excess = $("#change2").val();
  350. if (amountpayed > <?php echo $invoice->getRemainToPay(); ?>) {
  351. amountpayed = <?php echo $invoice->getRemainToPay(); ?>;
  352. }
  353. if (amountpayed == 0) {
  354. amountpayed = <?php echo $invoice->getRemainToPay(); ?>;
  355. }
  356. console.log("Pay with terminal ", amountpayed);
  357. fetchPaymentIntentClientSecret(amountpayed, invoiceid).then(function(client_secret) {
  358. <?php if (empty($servicestatus) && !empty($conf->global->STRIPE_TERMINAL_SIMULATED)) { ?>
  359. terminal.setSimulatorConfiguration({testCardNumber: '<?php echo $conf->global->STRIPE_TERMINAL_SIMULATED; ?>'});
  360. <?php } ?>
  361. document.getElementById("card-present-alert").innerHTML = '<div class="warning clearboth"><?php echo $langs->trans('PaymentSendToStripeTerminal'); ?></div>';
  362. terminal.collectPaymentMethod(client_secret).then(function(result) {
  363. if (result.error) {
  364. // Placeholder for handling result.error
  365. document.getElementById("card-present-alert").innerHTML = '<div class="error clearboth">'+result.error.message+'</div>';
  366. } else {
  367. document.getElementById("card-present-alert").innerHTML = '<div class="warning clearboth"><?php echo $langs->trans('PaymentBeingProcessed'); ?></div>';
  368. console.log('terminal.collectPaymentMethod', result.paymentIntent);
  369. terminal.processPayment(result.paymentIntent).then(function(result) {
  370. if (result.error) {
  371. document.getElementById("card-present-alert").innerHTML = '<div class="error clearboth">'+result.error.message+'</div>';
  372. console.log(result.error)
  373. } else if (result.paymentIntent) {
  374. paymentIntentId = result.paymentIntent.id;
  375. console.log('terminal.processPayment', result.paymentIntent);
  376. capturePaymentIntent(paymentIntentId).then(function(client_secret) {
  377. if (result.error) {
  378. // Placeholder for handling result.error
  379. document.getElementById("card-present-alert").innerHTML = '<div class="error clearboth">'+result.error.message+'</div>';
  380. console.log("error when capturing paymentIntent", result.error);
  381. } else {
  382. document.getElementById("card-present-alert").innerHTML = '<div class="warning clearboth"><?php echo $langs->trans('PaymentValidated'); ?></div>';
  383. console.log("Capture paymentIntent successfull "+paymentIntentId);
  384. 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() {
  385. if (amountpayed > <?php echo $remaintopay; ?> || amountpayed == <?php echo $remaintopay; ?> || amountpayed==0 ) {
  386. console.log("Close popup");
  387. parent.$.colorbox.close();
  388. }
  389. else {
  390. console.log("Amount is not comple, so we do NOT close popup and reload it.");
  391. location.reload();
  392. }
  393. });
  394. }
  395. });
  396. }
  397. });
  398. }
  399. });
  400. });
  401. }
  402. function ValidateSumup() {
  403. console.log("Launch ValidateSumup");
  404. <?php $_SESSION['SMP_CURRENT_PAYMENT'] = "NEW" ?>
  405. var invoiceid = <?php echo($invoiceid > 0 ? $invoiceid : 0); ?>;
  406. var amountpayed = $("#change1").val();
  407. if (amountpayed > <?php echo $invoice->total_ttc; ?>) {
  408. amountpayed = <?php echo $invoice->total_ttc; ?>;
  409. }
  410. // Starting sumup app
  411. 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');
  412. var loop = window.setInterval(function () {
  413. $.ajax({
  414. method: 'POST',
  415. data: { token: '<?php echo currentToken(); ?>' },
  416. url: '<?php echo DOL_URL_ROOT ?>/takepos/smpcb.php?status' }).done(function (data) {
  417. console.log(data);
  418. if (data === "SUCCESS") {
  419. parent.$("#poslines").load("invoice.php?place=<?php echo $place; ?>&action=valid&token=<?php echo newToken(); ?>&pay=CB&amount=" + amountpayed + "&invoiceid=" + invoiceid, function () {
  420. //parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
  421. parent.$.colorbox.close();
  422. //parent.setFocusOnSearchField(); // This does not have effect
  423. });
  424. clearInterval(loop);
  425. } else if (data === "FAILED") {
  426. parent.$.colorbox.close();
  427. clearInterval(loop);
  428. }
  429. });
  430. }, 2500);
  431. }
  432. <?php
  433. if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) {
  434. echo "var line1='".$langs->trans('TotalTTC')."'.substring(0,20);";
  435. echo "line1=line1.padEnd(20);";
  436. echo "var line2='".price($invoice->total_ttc, 1, '', 1, -1, -1)."'.substring(0,20);";
  437. echo "line2=line2.padEnd(20);";
  438. echo "$.ajax({
  439. type: 'GET',
  440. data: { text: line1+line2 },
  441. url: '".getDolGlobalString('TAKEPOS_PRINT_SERVER')."/display/index.php',
  442. });";
  443. }
  444. ?>
  445. </script>
  446. <div style="position:relative; padding-top: 20px; left:5%; height:140px; width:90%;">
  447. <div class="paymentbordline paymentbordlinetotal center">
  448. <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>
  449. </div>
  450. <?php if ($remaintopay != $invoice->total_ttc) { ?>
  451. <div class="paymentbordline paymentbordlineremain center">
  452. <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>
  453. </div>
  454. <?php } ?>
  455. <div class="paymentbordline paymentbordlinereceived center">
  456. <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>
  457. </div>
  458. <div class="paymentbordline paymentbordlinechange center">
  459. <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>
  460. </div>
  461. <?php
  462. if (!empty($conf->global->TAKEPOS_CAN_FORCE_BANK_ACCOUNT_DURING_PAYMENT)) {
  463. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  464. print '<div class="paymentbordline paddingtop paddingbottom center">';
  465. $filter = '';
  466. $form = new Form($db);
  467. print '<span class="takepospay colorwhite">'.$langs->trans("BankAccount").': </span>';
  468. $form->select_comptes(0, 'accountid', 0, $filter, 1, '');
  469. print ajax_combobox('selectaccountid');
  470. print '</div>';
  471. }
  472. ?>
  473. </div>
  474. <div style="position:absolute; left:5%; height:52%; width:90%;">
  475. <?php
  476. $action_buttons = array(
  477. array(
  478. "function" =>"reset()",
  479. "span" => "style='font-size: 150%;'",
  480. "text" => "C",
  481. "class" => "poscolorblue"
  482. ),
  483. array(
  484. "function" => "parent.$.colorbox.close();",
  485. "span" => "id='printtext' style='font-weight: bold; font-size: 18pt;'",
  486. "text" => "X",
  487. "class" => "poscolordelete"
  488. ),
  489. );
  490. $numpad = $conf->global->TAKEPOS_NUMPAD;
  491. if (isModEnabled('stripe') && isset($keyforstripeterminalbank) && !empty($conf->global->STRIPE_CARD_PRESENT)) {
  492. print '<span id="card-present-alert">';
  493. dol_htmloutput_mesg($langs->trans('ConnectingToStripeTerminal', 'Stripe'), '', 'warning', 1);
  494. print '</span>';
  495. }
  496. print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '7' : '10').')">'.($numpad == 0 ? '7' : '10').'</button>';
  497. print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '8' : '20').')">'.($numpad == 0 ? '8' : '20').'</button>';
  498. print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '9' : '50').')">'.($numpad == 0 ? '9' : '50').'</button>';
  499. ?>
  500. <?php if (count($arrayOfValidPaymentModes) > 0) {
  501. $paycode = $arrayOfValidPaymentModes[0]->code;
  502. $payIcon = '';
  503. if ($paycode == 'LIQ') {
  504. if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
  505. $payIcon = 'coins';
  506. }
  507. } elseif ($paycode == 'CB') {
  508. if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
  509. $payIcon = 'credit-card';
  510. }
  511. } elseif ($paycode == 'CHQ') {
  512. if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
  513. $payIcon = 'money-check';
  514. }
  515. }
  516. 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>';
  517. } else {
  518. print '<button type="button" class="calcbutton2">'.$langs->trans("NoPaimementModesDefined").'</button>';
  519. }
  520. print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '4' : '1').')">'.($numpad == 0 ? '4' : '1').'</button>';
  521. print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '5' : '2').')">'.($numpad == 0 ? '5' : '2').'</button>';
  522. print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '6' : '5').')">'.($numpad == 0 ? '6' : '5').'</button>';
  523. ?>
  524. <?php if (count($arrayOfValidPaymentModes) > 1) {
  525. $paycode = $arrayOfValidPaymentModes[1]->code;
  526. $payIcon = '';
  527. if ($paycode == 'LIQ') {
  528. if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
  529. $payIcon = 'coins';
  530. }
  531. } elseif ($paycode == 'CB') {
  532. if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
  533. $payIcon = 'credit-card';
  534. }
  535. } elseif ($paycode == 'CHQ') {
  536. if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
  537. $payIcon = 'money-check';
  538. }
  539. }
  540. 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>';
  541. } else {
  542. $button = array_pop($action_buttons);
  543. print '<button type="button" class="calcbutton2" onclick="'.$button["function"].'"><span '.$button["span"].'>'.$button["text"].'</span></button>';
  544. }
  545. print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '1' : '0.10').')">'.($numpad == 0 ? '1' : '0.10').'</button>';
  546. print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '2' : '0.20').')">'.($numpad == 0 ? '2' : '0.20').'</button>';
  547. print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '3' : '0.50').')">'.($numpad == 0 ? '3' : '0.50').'</button>';
  548. ?>
  549. <?php if (count($arrayOfValidPaymentModes) > 2) {
  550. $paycode = $arrayOfValidPaymentModes[2]->code;
  551. $payIcon = '';
  552. if ($paycode == 'LIQ') {
  553. if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
  554. $payIcon = 'coins';
  555. }
  556. } elseif ($paycode == 'CB') {
  557. if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
  558. $payIcon = 'credit-card';
  559. }
  560. } elseif ($paycode == 'CHQ') {
  561. if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
  562. $payIcon = 'money-check';
  563. }
  564. }
  565. 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>';
  566. } else {
  567. $button = array_pop($action_buttons);
  568. print '<button type="button" class="calcbutton2" onclick="'.$button["function"].'"><span '.$button["span"].'>'.$button["text"].'</span></button>';
  569. }
  570. print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '0' : '0.01').')">'.($numpad == 0 ? '0' : '0.01').'</button>';
  571. print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '\'000\'' : '0.02').')">'.($numpad == 0 ? '000' : '0.02').'</button>';
  572. print '<button type="button" class="calcbutton" onclick="addreceived('.($numpad == 0 ? '\'.\'' : '0.05').')">'.($numpad == 0 ? '.' : '0.05').'</button>';
  573. $i = 3;
  574. while ($i < count($arrayOfValidPaymentModes)) {
  575. $paycode = $arrayOfValidPaymentModes[$i]->code;
  576. $payIcon = '';
  577. if ($paycode == 'LIQ') {
  578. if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
  579. $payIcon = 'coins';
  580. }
  581. } elseif ($paycode == 'CB') {
  582. if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
  583. $payIcon = 'credit-card';
  584. }
  585. } elseif ($paycode == 'CHQ') {
  586. if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON)) {
  587. $payIcon = 'money-check';
  588. }
  589. }
  590. 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>';
  591. $i = $i + 1;
  592. }
  593. if (isModEnabled('stripe') && isset($keyforstripeterminalbank) && !empty($conf->global->STRIPE_CARD_PRESENT)) {
  594. $keyforstripeterminalbank = "CASHDESK_ID_BANKACCOUNT_STRIPETERMINAL".$_SESSION["takeposterminal"];
  595. print '<span id="StripeTerminal"></span>';
  596. if (!empty($conf->global->$keyforstripeterminalbank)) {
  597. } else {
  598. $langs->loadLangs(array("errors", "admin"));
  599. //print '<button type="button" class="calcbutton2 disabled" title="'.$langs->trans("SetupNotComplete").'">TerminalOff</button>';
  600. }
  601. }
  602. $keyforsumupbank = "CASHDESK_ID_BANKACCOUNT_SUMUP".$_SESSION["takeposterminal"];
  603. if (getDolGlobalInt('TAKEPOS_ENABLE_SUMUP')) {
  604. if (!empty($conf->global->$keyforsumupbank)) {
  605. print '<button type="button" class="calcbutton2" onclick="ValidateSumup();">Sumup</button>';
  606. } else {
  607. $langs->loadLangs(array("errors", "admin"));
  608. print '<button type="button" class="calcbutton2 disabled" title="'.$langs->trans("SetupNotComplete").'">Sumup</button>';
  609. }
  610. }
  611. $parameters = array();
  612. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $invoice, $action); // Note that $action and $object may have been modified by hook
  613. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  614. $class = ($i == 3) ? "calcbutton3" : "calcbutton2";
  615. foreach ($action_buttons as $button) {
  616. $newclass = $class.($button["class"] ? " ".$button["class"] : "");
  617. print '<button type="button" class="'.$newclass.'" onclick="'.$button["function"].'"><span '.$button["span"].'>'.$button["text"].'</span></button>';
  618. }
  619. if (getDolGlobalString('TAKEPOS_DELAYED_PAYMENT')) {
  620. print '<button type="button" class="calcbutton2" onclick="Validate(\'delayed\')">'.$langs->trans("Reported").'</button>';
  621. }
  622. ?>
  623. <?php
  624. // Add code from hooks
  625. $parameters=array();
  626. $hookmanager->executeHooks('completePayment', $parameters, $invoice);
  627. print $hookmanager->resPrint;
  628. ?>
  629. </div>
  630. </body>
  631. </html>