pay.php 29 KB

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