pay.php 31 KB

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