pay.php 31 KB

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