index.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. <?php
  2. /* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
  3. * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
  4. * Copyright (C) 2020 Thibault FOUCART <support@ptibogxiv.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/takepos/index.php
  21. * \ingroup takepos
  22. * \brief Main TakePOS screen
  23. */
  24. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  25. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
  26. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  27. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  28. if (!defined('NOCSRFCHECK')) {
  29. define('NOCSRFCHECK', '1');
  30. }
  31. if (!defined('NOTOKENRENEWAL')) {
  32. define('NOTOKENRENEWAL', '1');
  33. }
  34. if (!defined('NOREQUIREMENU')) {
  35. define('NOREQUIREMENU', '1');
  36. }
  37. if (!defined('NOREQUIREHTML')) {
  38. define('NOREQUIREHTML', '1');
  39. }
  40. if (!defined('NOREQUIREAJAX')) {
  41. define('NOREQUIREAJAX', '1');
  42. }
  43. require '../main.inc.php'; // Load $user and permissions
  44. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  48. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  49. require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  50. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  51. $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant or multiple sales
  52. $action = GETPOST('action', 'aZ09');
  53. $setterminal = GETPOST('setterminal', 'int');
  54. $setcurrency = GETPOST('setcurrency', 'aZ09');
  55. if ($_SESSION["takeposterminal"] == "") {
  56. if ($conf->global->TAKEPOS_NUM_TERMINALS == "1") {
  57. $_SESSION["takeposterminal"] = 1; // Use terminal 1 if there is only 1 terminal
  58. } elseif (!empty($_COOKIE["takeposterminal"])) {
  59. $_SESSION["takeposterminal"] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE["takeposterminal"]); // Restore takeposterminal from previous session
  60. }
  61. }
  62. if ($setterminal > 0) {
  63. $_SESSION["takeposterminal"] = $setterminal;
  64. setcookie("takeposterminal", $setterminal, (time() + (86400 * 354)), '/', null, false, true); // Permanent takeposterminal var in a cookie
  65. }
  66. if ($setcurrency != "") {
  67. $_SESSION["takeposcustomercurrency"] = $setcurrency;
  68. // We will recalculate amount for foreign currency at next call of invoice.php when $_SESSION["takeposcustomercurrency"] differs from invoice->multicurrency_code.
  69. }
  70. $_SESSION["urlfrom"] = '/takepos/index.php';
  71. $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter", "banks"));
  72. $categorie = new Categorie($db);
  73. $maxcategbydefaultforthisdevice = 12;
  74. $maxproductbydefaultforthisdevice = 24;
  75. if ($conf->browser->layout == 'phone') {
  76. $maxcategbydefaultforthisdevice = 8;
  77. $maxproductbydefaultforthisdevice = 16;
  78. //REDIRECT TO BASIC LAYOUT IF TERMINAL SELECTED AND BASIC MOBILE LAYOUT ENABLED
  79. if ($_SESSION["takeposterminal"] != "" && $conf->global->TAKEPOS_PHONE_BASIC_LAYOUT == 1) {
  80. $_SESSION["basiclayout"] = 1;
  81. header("Location: phone.php?mobilepage=invoice");
  82. exit;
  83. }
  84. }
  85. $MAXCATEG = (empty($conf->global->TAKEPOS_NB_MAXCATEG) ? $maxcategbydefaultforthisdevice : $conf->global->TAKEPOS_NB_MAXCATEG);
  86. $MAXPRODUCT = (empty($conf->global->TAKEPOS_NB_MAXPRODUCT) ? $maxproductbydefaultforthisdevice : $conf->global->TAKEPOS_NB_MAXPRODUCT);
  87. /*
  88. $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
  89. $soc = new Societe($db);
  90. if ($invoice->socid > 0) $soc->fetch($invoice->socid);
  91. else $soc->fetch($conf->global->$constforcompanyid);
  92. */
  93. // Security check
  94. $result = restrictedArea($user, 'takepos', 0, '');
  95. /*
  96. * View
  97. */
  98. $form = new Form($db);
  99. // Title
  100. $title = 'TakePOS - Dolibarr '.DOL_VERSION;
  101. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  102. $title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
  103. }
  104. $head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
  105. <meta name="apple-mobile-web-app-capable" content="yes">
  106. <meta name="mobile-web-app-capable" content="yes">
  107. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
  108. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  109. ?>
  110. <link rel="stylesheet" href="css/pos.css.php">
  111. <link rel="stylesheet" href="css/colorbox.css" type="text/css" media="screen" />
  112. <?php
  113. if ($conf->global->TAKEPOS_COLOR_THEME == 1) {
  114. print '<link rel="stylesheet" href="css/colorful.css">';
  115. }
  116. ?>
  117. <script type="text/javascript" src="js/jquery.colorbox-min.js"></script> <!-- TODO It seems we don't need this -->
  118. <script language="javascript">
  119. <?php
  120. $categories = $categorie->get_full_arbo('product', (($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) ? $conf->global->TAKEPOS_ROOT_CATEGORY_ID : 0), 1);
  121. // Search root category to know its level
  122. //$conf->global->TAKEPOS_ROOT_CATEGORY_ID=0;
  123. $levelofrootcategory = 0;
  124. if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) {
  125. foreach ($categories as $key => $categorycursor) {
  126. if ($categorycursor['id'] == $conf->global->TAKEPOS_ROOT_CATEGORY_ID) {
  127. $levelofrootcategory = $categorycursor['level'];
  128. break;
  129. }
  130. }
  131. }
  132. $levelofmaincategories = $levelofrootcategory + 1;
  133. $maincategories = array();
  134. $subcategories = array();
  135. foreach ($categories as $key => $categorycursor) {
  136. if ($categorycursor['level'] == $levelofmaincategories) {
  137. $maincategories[$key] = $categorycursor;
  138. } else {
  139. $subcategories[$key] = $categorycursor;
  140. }
  141. }
  142. $maincategories = dol_sort_array($maincategories, 'label');
  143. $subcategories = dol_sort_array($subcategories, 'label');
  144. ?>
  145. var categories = <?php echo json_encode($maincategories); ?>;
  146. var subcategories = <?php echo json_encode($subcategories); ?>;
  147. var currentcat;
  148. var pageproducts=0;
  149. var pagecategories=0;
  150. var pageactions=0;
  151. var place="<?php echo $place; ?>";
  152. var editaction="qty";
  153. var editnumber="";
  154. var invoiceid=0;
  155. /*
  156. var app = this;
  157. app.hasKeyboard = false;
  158. this.keyboardPress = function() {
  159. app.hasKeyboard = true;
  160. $(window).unbind("keyup", app.keyboardPress);
  161. localStorage.hasKeyboard = true;
  162. console.log("has keyboard!")
  163. }
  164. $(window).on("keyup", app.keyboardPress)
  165. if(localStorage.hasKeyboard) {
  166. app.hasKeyboard = true;
  167. $(window).unbind("keyup", app.keyboardPress);
  168. console.log("has keyboard from localStorage")
  169. }
  170. */
  171. function ClearSearch() {
  172. console.log("ClearSearch");
  173. $("#search").val('');
  174. <?php if ($conf->browser->layout == 'classic') { ?>
  175. setFocusOnSearchField();
  176. <?php } ?>
  177. }
  178. // Set the focus on search field but only on desktop. On tablet or smartphone, we don't to avoid to have the keyboard open automatically
  179. function setFocusOnSearchField() {
  180. console.log("Call setFocusOnSearchField in page index.php");
  181. <?php if ($conf->browser->layout == 'classic') { ?>
  182. console.log("has keyboard from localStorage, so we can force focus on search field");
  183. $("#search").focus();
  184. <?php } ?>
  185. }
  186. function PrintCategories(first) {
  187. console.log("PrintCategories");
  188. for (i = 0; i < <?php echo ($MAXCATEG - 2); ?>; i++) {
  189. if (typeof (categories[parseInt(i)+parseInt(first)]) == "undefined")
  190. {
  191. $("#catdivdesc"+i).hide();
  192. $("#catdesc"+i).text("");
  193. $("#catimg"+i).attr("src","genimg/empty.png");
  194. $("#catwatermark"+i).hide();
  195. $("#catdiv"+i).attr('class', 'wrapper divempty');
  196. continue;
  197. }
  198. $("#catdivdesc"+i).show();
  199. $("#catdesc"+i).text(categories[parseInt(i)+parseInt(first)]['label']);
  200. $("#catimg"+i).attr("src","genimg/index.php?query=cat&id="+categories[parseInt(i)+parseInt(first)]['rowid']);
  201. $("#catdiv"+i).data("rowid",categories[parseInt(i)+parseInt(first)]['rowid']);
  202. $("#catdiv"+i).attr('class', 'wrapper');
  203. $("#catwatermark"+i).show();
  204. }
  205. }
  206. function MoreCategories(moreorless) {
  207. console.log("MoreCategories moreorless="+moreorless+" pagecategories="+pagecategories);
  208. if (moreorless=="more") {
  209. $('#catimg15').animate({opacity: '0.5'}, 1);
  210. $('#catimg15').animate({opacity: '1'}, 100);
  211. pagecategories=pagecategories+1;
  212. }
  213. if (moreorless=="less") {
  214. $('#catimg14').animate({opacity: '0.5'}, 1);
  215. $('#catimg14').animate({opacity: '1'}, 100);
  216. if (pagecategories==0) return; //Return if no less pages
  217. pagecategories=pagecategories-1;
  218. }
  219. if (typeof (categories[<?php echo ($MAXCATEG - 2); ?> * pagecategories] && moreorless=="more") == "undefined"){ // Return if no more pages
  220. pagecategories=pagecategories-1;
  221. return;
  222. }
  223. for (i = 0; i < <?php echo ($MAXCATEG - 2); ?>; i++) {
  224. if (typeof (categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]) == "undefined") {
  225. $("#catdivdesc"+i).hide();
  226. $("#catdesc"+i).text("");
  227. $("#catimg"+i).attr("src","genimg/empty.png");
  228. $("#catwatermark"+i).hide();
  229. continue;
  230. }
  231. $("#catdivdesc"+i).show();
  232. $("#catdesc"+i).text(categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['label']);
  233. $("#catimg"+i).attr("src","genimg/index.php?query=cat&id="+categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['rowid']);
  234. $("#catdiv"+i).data("rowid",categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['rowid']);
  235. $("#catwatermark"+i).show();
  236. }
  237. ClearSearch();
  238. }
  239. // LoadProducts
  240. function LoadProducts(position, issubcat) {
  241. console.log("LoadProducts");
  242. var maxproduct = <?php echo ($MAXPRODUCT - 2); ?>;
  243. if (position=="supplements") currentcat="supplements";
  244. else
  245. {
  246. $('#catimg'+position).animate({opacity: '0.5'}, 1);
  247. $('#catimg'+position).animate({opacity: '1'}, 100);
  248. if (issubcat==true) currentcat=$('#prodiv'+position).data('rowid');
  249. else currentcat=$('#catdiv'+position).data('rowid');
  250. }
  251. if (currentcat == undefined) return;
  252. pageproducts=0;
  253. ishow=0; //product to show counter
  254. jQuery.each(subcategories, function(i, val) {
  255. if (currentcat==val.fk_parent) {
  256. $("#prodivdesc"+ishow).show();
  257. $("#prodesc"+ishow).text(val.label);
  258. $("#probutton"+ishow).text(val.label);
  259. $("#probutton"+ishow).show();
  260. $("#proprice"+ishow).attr("class", "hidden");
  261. $("#proprice"+ishow).html("");
  262. $("#proimg"+ishow).attr("src","genimg/index.php?query=cat&id="+val.rowid);
  263. $("#prodiv"+ishow).data("rowid",val.rowid);
  264. $("#prodiv"+ishow).data("iscat",1);
  265. $("#prowatermark"+ishow).show();
  266. ishow++;
  267. }
  268. });
  269. idata=0; //product data counter
  270. $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&category='+currentcat, function(data) {
  271. console.log("Call ajax.php (in LoadProducts) to get Products of category "+currentcat+" then loop on result to fill image thumbs");
  272. console.log(data);
  273. while (ishow < maxproduct) {
  274. //console.log("ishow"+ishow+" idata="+idata);
  275. console.log(data[idata]);
  276. if (typeof (data[idata]) == "undefined") {
  277. <?php if (!$conf->global->TAKEPOS_HIDE_PRODUCT_IMAGES) {
  278. echo '$("#prodivdesc"+ishow).hide();';
  279. echo '$("#prodesc"+ishow).text("");';
  280. echo '$("#proimg"+ishow).attr("title","");';
  281. echo '$("#proimg"+ishow).attr("src","genimg/empty.png");';
  282. } else {
  283. echo '$("#probutton"+ishow).hide();';
  284. echo '$("#probutton"+ishow).text("");';
  285. }?>
  286. $("#proprice"+ishow).attr("class", "hidden");
  287. $("#proprice"+ishow).html("");
  288. $("#prodiv"+ishow).data("rowid","");
  289. $("#prodiv"+ishow).attr("class","wrapper2 divempty");
  290. $("#prowatermark"+ishow).hide();
  291. ishow++; //Next product to show after print data product
  292. }
  293. else if ((data[idata]['status']) == "1") { // Only show products with status=1 (for sell)
  294. <?php
  295. $titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[idata]['ref']";
  296. $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[idata]['barcode']";
  297. ?>
  298. var titlestring = <?php echo $titlestring; ?>;
  299. <?php if (!$conf->global->TAKEPOS_HIDE_PRODUCT_IMAGES) {
  300. echo '$("#prodivdesc"+ishow).show();';
  301. echo '$("#prodesc"+ishow).text(data[parseInt(idata)][\'label\']);';
  302. echo '$("#proimg"+ishow).attr("title", titlestring);';
  303. echo '$("#proimg"+ishow).attr("src", "genimg/index.php?query=pro&id="+data[idata][\'id\']);';
  304. } else {
  305. echo '$("#probutton"+ishow).show();';
  306. echo '$("#probutton"+ishow).text(data[parseInt(idata)][\'label\']);';
  307. }
  308. ?>
  309. if (data[parseInt(idata)]['price_formated']) {
  310. $("#proprice"+ishow).attr("class", "productprice");
  311. $("#proprice"+ishow).html(data[parseInt(idata)]['price_formated']);
  312. }
  313. $("#prodiv"+ishow).data("rowid", data[idata]['id']);
  314. $("#prodiv"+ishow).data("iscat", 0);
  315. $("#prodiv"+ishow).attr("class","wrapper2");
  316. $("#prowatermark"+ishow).hide();
  317. ishow++; //Next product to show after print data product
  318. }
  319. //console.log("Hide the prowatermark for ishow="+ishow);
  320. idata++; //Next data everytime
  321. }
  322. });
  323. ClearSearch();
  324. }
  325. function MoreProducts(moreorless) {
  326. console.log("MoreProducts");
  327. var maxproduct = <?php echo ($MAXPRODUCT - 2); ?>;
  328. if (moreorless=="more"){
  329. $('#proimg31').animate({opacity: '0.5'}, 1);
  330. $('#proimg31').animate({opacity: '1'}, 100);
  331. pageproducts=pageproducts+1;
  332. }
  333. if (moreorless=="less"){
  334. $('#proimg30').animate({opacity: '0.5'}, 1);
  335. $('#proimg30').animate({opacity: '1'}, 100);
  336. if (pageproducts==0) return; //Return if no less pages
  337. pageproducts=pageproducts-1;
  338. }
  339. $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&category='+currentcat, function(data) {
  340. console.log("Call ajax.php (in MoreProducts) to get Products of category "+currentcat);
  341. if (typeof (data[(maxproduct * pageproducts)]) == "undefined" && moreorless=="more"){ // Return if no more pages
  342. pageproducts=pageproducts-1;
  343. return;
  344. }
  345. idata=<?php echo ($MAXPRODUCT - 2); ?> * pageproducts; //product data counter
  346. ishow=0; //product to show counter
  347. while (ishow < maxproduct) {
  348. if (typeof (data[idata]) == "undefined") {
  349. $("#prodivdesc"+ishow).hide();
  350. $("#prodesc"+ishow).text("");
  351. $("#probutton"+ishow).text("");
  352. $("#probutton"+ishow).hide();
  353. $("#proprice"+ishow).attr("class", "");
  354. $("#proprice"+ishow).html("");
  355. $("#proimg"+ishow).attr("src","genimg/empty.png");
  356. $("#prodiv"+ishow).data("rowid","");
  357. ishow++; //Next product to show after print data product
  358. }
  359. else if ((data[idata]['status']) == "1") {
  360. //Only show products with status=1 (for sell)
  361. $("#prodivdesc"+ishow).show();
  362. $("#prodesc"+ishow).text(data[parseInt(idata)]['label']);
  363. $("#probutton"+ishow).text(data[parseInt(idata)]['label']);
  364. $("#probutton"+ishow).show();
  365. if (data[parseInt(idata)]['price_formated']) {
  366. $("#proprice"+ishow).attr("class", "productprice");
  367. $("#proprice"+ishow).html(data[parseInt(idata)]['price_formated']);
  368. }
  369. $("#proimg"+ishow).attr("src","genimg/index.php?query=pro&id="+data[idata]['id']);
  370. $("#prodiv"+ishow).data("rowid",data[idata]['id']);
  371. $("#prodiv"+ishow).data("iscat",0);
  372. ishow++; //Next product to show after print data product
  373. }
  374. $("#prowatermark"+ishow).hide();
  375. idata++; //Next data everytime
  376. }
  377. });
  378. ClearSearch();
  379. }
  380. function ClickProduct(position) {
  381. console.log("ClickProduct");
  382. $('#proimg'+position).animate({opacity: '0.5'}, 1);
  383. $('#proimg'+position).animate({opacity: '1'}, 100);
  384. if ($('#prodiv'+position).data('iscat')==1){
  385. console.log("Click on a category at position "+position);
  386. LoadProducts(position, true);
  387. }
  388. else{
  389. idproduct=$('#prodiv'+position).data('rowid');
  390. console.log("Click on product at position "+position+" for idproduct "+idproduct);
  391. if (idproduct=="") return;
  392. // Call page invoice.php to generate the section with product lines
  393. $("#poslines").load("invoice.php?action=addline&place="+place+"&idproduct="+idproduct+"&selectedline="+selectedline, function() {
  394. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  395. });
  396. }
  397. ClearSearch();
  398. }
  399. function ChangeThirdparty(idcustomer) {
  400. console.log("ChangeThirdparty");
  401. // Call page list.php to change customer
  402. $("#poslines").load("../societe/list.php?action=change&type=t&contextpage=poslist&idcustomer="+idcustomer+"&place="+place+"", function() {
  403. });
  404. ClearSearch();
  405. }
  406. function deleteline() {
  407. console.log("Delete line");
  408. $("#poslines").load("invoice.php?action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
  409. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  410. });
  411. ClearSearch();
  412. }
  413. function Customer() {
  414. console.log("Open box to select the thirdparty place="+place);
  415. $.colorbox({href:"../societe/list.php?type=t&contextpage=poslist&nomassaction=1&place="+place, width:"90%", height:"80%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Customer"); ?>"});
  416. }
  417. function History()
  418. {
  419. console.log("Open box to select the history");
  420. $.colorbox({href:"../compta/facture/list.php?contextpage=poslist", width:"90%", height:"80%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("History"); ?>"});
  421. }
  422. function Reduction() {
  423. invoiceid = $("#invoiceid").val();
  424. console.log("Open popup to enter reduction on invoiceid="+invoiceid);
  425. $.colorbox({href:"reduction.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
  426. }
  427. function CloseBill() {
  428. invoiceid = $("#invoiceid").val();
  429. console.log("Open popup to enter payment on invoiceid="+invoiceid);
  430. $.colorbox({href:"pay.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
  431. }
  432. function Floors() {
  433. console.log("Open box to select floor place="+place);
  434. $.colorbox({href:"floors.php?place="+place, width:"90%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Floors"); ?>"});
  435. }
  436. function FreeZone() {
  437. console.log("Open box to enter a free product");
  438. $.colorbox({href:"freezone.php?action=freezone&place="+place, width:"80%", height:"200px", transition:"none", iframe:"true", title:"<?php echo $langs->trans("FreeZone"); ?>"});
  439. }
  440. function TakeposOrderNotes() {
  441. console.log("Open box to order notes");
  442. ModalBox('ModalNote');
  443. $("#textinput").focus();
  444. }
  445. function Refresh() {
  446. console.log("Refresh by reloading place="+place+" invoiceid="+invoiceid);
  447. $("#poslines").load("invoice.php?place="+place+"&invoiceid="+invoiceid, function() {
  448. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  449. });
  450. }
  451. function New() {
  452. // If we go here,it means $conf->global->TAKEPOS_BAR_RESTAURANT is not defined
  453. invoiceid = $("#invoiceid").val();
  454. console.log("New with place = <?php echo $place; ?>, js place="+place+", invoiceid="+invoiceid);
  455. $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getInvoice&id='+invoiceid, function(data) {
  456. var r;
  457. if (parseInt(data['paye']) === 1) {
  458. r = true;
  459. } else {
  460. r = confirm('<?php echo ($place > 0 ? $langs->transnoentitiesnoconv("ConfirmDeletionOfThisPOSSale") : $langs->transnoentitiesnoconv("ConfirmDiscardOfThisPOSSale")); ?>');
  461. }
  462. if (r == true) {
  463. // Reload section with invoice lines
  464. $("#poslines").load("invoice.php?action=delete&token=<?php echo newToken(); ?>&place=" + place, function () {
  465. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  466. });
  467. ClearSearch();
  468. }
  469. });
  470. }
  471. /**
  472. * Search products
  473. *
  474. * @param {int} keyCodeForEnter Key code for "enter"
  475. * return {void}
  476. */
  477. function Search2(keyCodeForEnter) {
  478. console.log("Search2 Call ajax search to replace products keyCodeForEnter="+keyCodeForEnter);
  479. var search = false;
  480. var eventKeyCode = window.event.keyCode;
  481. if (typeof keyCodeForEnter === 'undefined' || eventKeyCode == keyCodeForEnter) {
  482. search = true;
  483. }
  484. if (search === true) {
  485. pageproducts = 0;
  486. jQuery(".wrapper2 .catwatermark").hide();
  487. $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&term=' + $('#search').val(), function (data) {
  488. for (i = 0; i < <?php echo $MAXPRODUCT ?>; i++) {
  489. if (typeof (data[i]) == "undefined") {
  490. $("#prodesc" + i).text("");
  491. $("#probutton" + i).text("");
  492. $("#probutton" + i).hide();
  493. $("#proprice" + i).attr("class", "hidden");
  494. $("#proprice" + i).html("");
  495. $("#proimg" + i).attr("src", "genimg/empty.png");
  496. $("#prodiv" + i).data("rowid", "");
  497. continue;
  498. }
  499. <?php
  500. $titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[i]['ref']";
  501. $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[i]['barcode']";
  502. ?>
  503. var titlestring = <?php echo $titlestring; ?>;
  504. $("#prodesc" + i).text(data[i]['label']);
  505. $("#prodivdesc" + i).show();
  506. $("#probutton" + i).text(data[i]['label']);
  507. $("#probutton" + i).show();
  508. if (data[i]['price_formated']) {
  509. $("#proprice" + i).attr("class", "productprice");
  510. $("#proprice" + i).html(data[i]['price_formated']);
  511. }
  512. $("#proimg" + i).attr("title", titlestring);
  513. $("#proimg" + i).attr("src", "genimg/index.php?query=pro&id=" + data[i]['rowid']);
  514. $("#prodiv" + i).data("rowid", data[i]['rowid']);
  515. $("#prodiv" + i).data("iscat", 0);
  516. }
  517. }).always(function (data) {
  518. // If there is only 1 answer
  519. if ($('#search').val().length > 0 && data.length == 1) {
  520. console.log($('#search').val()+' - '+data[0]['barcode']);
  521. if ($('#search').val() == data[0]['barcode'] && 'thirdparty' == data[0]['object']) {
  522. console.log("There is only 1 answer with barcode matching the search, so we change the thirdparty "+data[0]['rowid']);
  523. ChangeThirdparty(data[0]['rowid']);
  524. }
  525. else if ($('#search').val() == data[0]['barcode'] && 'product' == data[0]['object']) {
  526. console.log("There is only 1 answer with barcode matching the search, so we add the product in basket");
  527. ClickProduct(0);
  528. }
  529. }
  530. if (eventKeyCode == keyCodeForEnter){
  531. if (data.length == 0) {
  532. $('#search').val('<?php
  533. $langs->load('errors');
  534. echo dol_escape_js($langs->trans("ErrorRecordNotFound"));
  535. ?>');
  536. $('#search').select();
  537. }
  538. else ClearSearch();
  539. }
  540. });
  541. }
  542. }
  543. function Edit(number) {
  544. if (typeof(selectedtext) == "undefined") return; // We click on an action on the number pad but there is no line selected
  545. var text=selectedtext+"<br> ";
  546. if (number=='c'){
  547. editnumber="";
  548. Refresh();
  549. return;
  550. }
  551. else if (number=='qty'){
  552. console.log("Edit "+number);
  553. if (editaction=='qty' && editnumber!=""){
  554. $("#poslines").load("invoice.php?action=updateqty&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  555. editnumber="";
  556. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  557. $("#qty").html("<?php echo $langs->trans("Qty"); ?>");
  558. });
  559. setFocusOnSearchField();
  560. return;
  561. }
  562. else {
  563. editaction="qty";
  564. }
  565. }
  566. else if (number=='p'){
  567. console.log("Edit "+number);
  568. if (editaction=='p' && editnumber!=""){
  569. $("#poslines").load("invoice.php?action=updateprice&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  570. editnumber="";
  571. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  572. $("#price").html("<?php echo $langs->trans("Price"); ?>");
  573. });
  574. ClearSearch();
  575. return;
  576. }
  577. else {
  578. editaction="p";
  579. }
  580. }
  581. else if (number=='r'){
  582. console.log("Edit "+number);
  583. if (editaction=='r' && editnumber!=""){
  584. $("#poslines").load("invoice.php?action=updatereduction&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  585. editnumber="";
  586. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  587. $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>");
  588. });
  589. ClearSearch();
  590. return;
  591. }
  592. else {
  593. editaction="r";
  594. }
  595. }
  596. else {
  597. editnumber=editnumber+number;
  598. }
  599. if (editaction=='qty'){
  600. text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Qty").": "; ?>";
  601. $("#qty").html("OK");
  602. $("#price").html("<?php echo $langs->trans("Price"); ?>");
  603. $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>");
  604. }
  605. if (editaction=='p'){
  606. text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Price").": "; ?>";
  607. $("#qty").html("<?php echo $langs->trans("Qty"); ?>");
  608. $("#price").html("OK");
  609. $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>");
  610. }
  611. if (editaction=='r'){
  612. text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("ReductionShort").": "; ?>";
  613. $("#qty").html("<?php echo $langs->trans("Qty"); ?>");
  614. $("#price").html("<?php echo $langs->trans("Price"); ?>");
  615. $("#reduction").html("OK");
  616. }
  617. $('#'+selectedline).find("td:first").html(text+editnumber);
  618. }
  619. function TakeposPrintingOrder(){
  620. console.log("TakeposPrintingOrder");
  621. $("#poslines").load("invoice.php?action=order&place="+place, function() {
  622. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  623. });
  624. }
  625. function TakeposPrintingTemp(){
  626. console.log("TakeposPrintingTemp");
  627. $("#poslines").load("invoice.php?action=temp&place="+place, function() {
  628. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  629. });
  630. }
  631. function OpenDrawer(){
  632. console.log("OpenDrawer call ajax url http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>:8111/print");
  633. $.ajax({
  634. type: "POST",
  635. data: { token: 'notrequired' },
  636. <?php
  637. if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
  638. echo "url: '".$conf->global->TAKEPOS_PRINT_SERVER."/printer/drawer.php',";
  639. } else {
  640. echo "url: 'http://".$conf->global->TAKEPOS_PRINT_SERVER.":8111/print',";
  641. }
  642. ?>
  643. data: "opendrawer"
  644. });
  645. }
  646. function DolibarrOpenDrawer() {
  647. console.log("DolibarrOpenDrawer call ajax url /takepos/ajax/ajax.php?action=opendrawer&term=<?php print urlencode($_SESSION["takeposterminal"]); ?>");
  648. $.ajax({
  649. type: "GET",
  650. data: { token: '<?php echo currentToken(); ?>' },
  651. url: "<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=opendrawer&term='.urlencode($_SESSION["takeposterminal"]); ?>",
  652. });
  653. }
  654. function MoreActions(totalactions){
  655. if (pageactions==0){
  656. pageactions=1;
  657. for (i = 0; i <= totalactions; i++){
  658. if (i<12) $("#action"+i).hide();
  659. else $("#action"+i).show();
  660. }
  661. }
  662. else if (pageactions==1){
  663. pageactions=0;
  664. for (i = 0; i <= totalactions; i++){
  665. if (i<12) $("#action"+i).show();
  666. else $("#action"+i).hide();
  667. }
  668. }
  669. }
  670. function ControlCashOpening()
  671. {
  672. $.colorbox({href:"../compta/cashcontrol/cashcontrol_card.php?action=create&contextpage=takepos", width:"90%", height:"60%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("NewCashFence"); ?>"});
  673. }
  674. function CloseCashFence(rowid)
  675. {
  676. $.colorbox({href:"../compta/cashcontrol/cashcontrol_card.php?id="+rowid+"&contextpage=takepos", width:"90%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("NewCashFence"); ?>"});
  677. }
  678. function CashReport(rowid)
  679. {
  680. $.colorbox({href:"../compta/cashcontrol/report.php?id="+rowid+"&contextpage=takepos", width:"60%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("CashReport"); ?>"});
  681. }
  682. // TakePOS Popup
  683. function ModalBox(ModalID)
  684. {
  685. var modal = document.getElementById(ModalID);
  686. modal.style.display = "block";
  687. }
  688. function DirectPayment(){
  689. console.log("DirectPayment");
  690. $("#poslines").load("invoice.php?place="+place+"&action=valid&pay=LIQ", function() {
  691. });
  692. }
  693. function FullScreen() {
  694. document.documentElement.requestFullscreen();
  695. }
  696. function WeighingScale(){
  697. console.log("Weighing Scale");
  698. $.ajax({
  699. type: "POST",
  700. data: { token: 'notrequired' },
  701. url: '<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>/scale/index.php',
  702. })
  703. .done(function( editnumber ) {
  704. $("#poslines").load("invoice.php?action=updateqty&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  705. editnumber="";
  706. });
  707. });
  708. }
  709. $( document ).ready(function() {
  710. PrintCategories(0);
  711. LoadProducts(0);
  712. Refresh();
  713. <?php
  714. //IF NO TERMINAL SELECTED
  715. if ($_SESSION["takeposterminal"] == "") {
  716. print "ModalBox('ModalTerminal');";
  717. }
  718. if (getDolGlobalString('TAKEPOS_CONTROL_CASH_OPENING')) {
  719. $sql = "SELECT rowid, status FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE";
  720. $sql .= " entity = ".((int) $conf->entity)." AND ";
  721. $sql .= " posnumber = ".((int) $_SESSION["takeposterminal"])." AND ";
  722. $sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'";
  723. $resql = $db->query($sql);
  724. if ($resql) {
  725. $obj = $db->fetch_object($resql);
  726. // If there is no cash control from today open it
  727. if ($obj->rowid == null) {
  728. print "ControlCashOpening();";
  729. }
  730. }
  731. }
  732. ?>
  733. });
  734. </script>
  735. <body class="bodytakepos" style="overflow: hidden;">
  736. <?php
  737. $keyCodeForEnter = getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) > 0 ? getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) : '';
  738. ?>
  739. <div class="container">
  740. <?php
  741. if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
  742. ?>
  743. <div class="header">
  744. <div class="topnav">
  745. <div class="topnav-left">
  746. <div class="inline-block valignmiddle">
  747. <a class="topnav-terminalhour" onclick="ModalBox('ModalTerminal');">
  748. <span class="fa fa-cash-register"></span>
  749. <span class="hideonsmartphone">
  750. <?php echo $langs->trans("Terminal"); ?>
  751. </span>
  752. <?php echo " ";
  753. if ($_SESSION["takeposterminal"] == "") {
  754. echo "1";
  755. } else {
  756. echo $_SESSION["takeposterminal"];
  757. }
  758. echo '<span class="hideonsmartphone"> - '.dol_print_date(dol_now(), "day").'</span>';
  759. ?>
  760. </a>
  761. <?php
  762. if (!empty($conf->multicurrency->enabled)) {
  763. print '<a class="valignmiddle tdoverflowmax100" id="multicurrency" onclick="ModalBox(\'ModalCurrency\');" title=""><span class="fas fa-coins paddingrightonly"></span>';
  764. print '<span class="hideonsmartphone">'.$langs->trans("Currency").'</span>';
  765. print '</a>';
  766. }
  767. ?>
  768. </div>
  769. <!-- section for customer and open sales -->
  770. <div class="inline-block valignmiddle" id="customerandsales">
  771. </div>
  772. <!-- More info about customer -->
  773. <div class="inline-block valignmiddle tdoverflowmax150onsmartphone" id="moreinfo"></div>
  774. <div class="inline-block valignmiddle tdoverflowmax150onsmartphone" id="infowarehouse"></div>
  775. </div>
  776. <div class="topnav-right">
  777. <div class="login_block_other">
  778. <input type="text" id="search" name="search" onkeyup="Search2(<?php echo $keyCodeForEnter; ?>);" placeholder="<?php echo $langs->trans("Search"); ?>" autofocus>
  779. <a onclick="ClearSearch();"><span class="fa fa-backspace"></span></a>
  780. <a href="<?php echo DOL_URL_ROOT.'/'; ?>" target="backoffice" rel="opener"><!-- we need rel="opener" here, we are on same domain and we need to be able to reuse this tab several times -->
  781. <span class="fas fa-home"></span></a>
  782. <?php if (empty($conf->dol_use_jmobile)) { ?>
  783. <a class="hideonsmartphone" onclick="FullScreen();"><span class="fa fa-expand-arrows-alt"></span></a>
  784. <?php } ?>
  785. </div>
  786. <div class="login_block_user">
  787. <?php
  788. print top_menu_user(1, DOL_URL_ROOT.'/user/logout.php');
  789. ?>
  790. </div>
  791. </div>
  792. </div>
  793. </div>
  794. <?php
  795. }
  796. ?>
  797. <!-- Modal terminal box -->
  798. <div id="ModalTerminal" class="modal">
  799. <div class="modal-content">
  800. <div class="modal-header">
  801. <span class="close" href="#" onclick="document.getElementById('ModalTerminal').style.display = 'none';">&times;</span>
  802. <h3><?php print $langs->trans("TerminalSelect"); ?></h3>
  803. </div>
  804. <div class="modal-body">
  805. <button type="button" class="block" onclick="location.href='index.php?setterminal=1'"><?php print $langs->trans("Terminal"); ?> 1</button>
  806. <?php
  807. for ($i = 2; $i <= $conf->global->TAKEPOS_NUM_TERMINALS; $i++) {
  808. print '<button type="button" class="block" onclick="location.href=\'index.php?setterminal='.$i.'\'">'.$langs->trans("Terminal").' '.$i.'</button>';
  809. }
  810. ?>
  811. </div>
  812. </div>
  813. </div>
  814. <!-- Modal multicurrency box -->
  815. <?php if (!empty($conf->multicurrency->enabled)) { ?>
  816. <div id="ModalCurrency" class="modal">
  817. <div class="modal-content">
  818. <div class="modal-header">
  819. <span class="close" href="#" onclick="document.getElementById('ModalCurrency').style.display = 'none';">&times;</span>
  820. <h3><?php print $langs->trans("SetMultiCurrencyCode"); ?></h3>
  821. </div>
  822. <div class="modal-body">
  823. <?php
  824. $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'multicurrency';
  825. $sql .= " WHERE entity IN ('".getEntity('multicurrency')."')";
  826. $resql = $db->query($sql);
  827. if ($resql) {
  828. while ($obj = $db->fetch_object($resql)) {
  829. print '<button type="button" class="block" onclick="location.href=\'index.php?setcurrency='.$obj->code.'\'">'.$obj->code.'</button>';
  830. }
  831. }
  832. ?>
  833. </div>
  834. </div>
  835. </div>
  836. <?php } ?>
  837. <!-- Modal terminal Credit Note -->
  838. <div id="ModalCreditNote" class="modal">
  839. <div class="modal-content">
  840. <div class="modal-header">
  841. <span class="close" href="#" onclick="document.getElementById('ModalCreditNote').style.display = 'none';">&times;</span>
  842. <h3><?php print $langs->trans("invoiceAvoirWithLines"); ?></h3>
  843. </div>
  844. <div class="modal-body">
  845. <button type="button" class="block" onclick="CreditNote(); document.getElementById('ModalCreditNote').style.display = 'none';"><?php print $langs->trans("Yes"); ?></button>
  846. <button type="button" class="block" onclick="document.getElementById('ModalCreditNote').style.display = 'none';"><?php print $langs->trans("No"); ?></button>
  847. </div>
  848. </div>
  849. </div>
  850. <!-- Modal Note -->
  851. <div id="ModalNote" class="modal">
  852. <div class="modal-content">
  853. <div class="modal-header">
  854. <span class="close" href="#" onclick="document.getElementById('ModalNote').style.display = 'none';">&times;</span>
  855. <h3><?php print $langs->trans("Note"); ?></h3>
  856. </div>
  857. <div class="modal-body">
  858. <input type="text" class="block" id="textinput">
  859. <button type="button" class="block" onclick="SetNote(); document.getElementById('ModalNote').style.display = 'none';">OK</button>
  860. </div>
  861. </div>
  862. </div>
  863. <div class="row1<?php if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
  864. print 'withhead';
  865. } ?>">
  866. <div id="poslines" class="div1">
  867. </div>
  868. <div class="div2">
  869. <button type="button" class="calcbutton" onclick="Edit(7);">7</button>
  870. <button type="button" class="calcbutton" onclick="Edit(8);">8</button>
  871. <button type="button" class="calcbutton" onclick="Edit(9);">9</button>
  872. <button type="button" id="qty" class="calcbutton2" onclick="Edit('qty');"><?php echo $langs->trans("Qty"); ?></button>
  873. <button type="button" class="calcbutton" onclick="Edit(4);">4</button>
  874. <button type="button" class="calcbutton" onclick="Edit(5);">5</button>
  875. <button type="button" class="calcbutton" onclick="Edit(6);">6</button>
  876. <button type="button" id="price" class="calcbutton2" onclick="Edit('p');"><?php echo $langs->trans("Price"); ?></button>
  877. <button type="button" class="calcbutton" onclick="Edit(1);">1</button>
  878. <button type="button" class="calcbutton" onclick="Edit(2);">2</button>
  879. <button type="button" class="calcbutton" onclick="Edit(3);">3</button>
  880. <button type="button" id="reduction" class="calcbutton2" onclick="Edit('r');"><?php echo $langs->trans("ReductionShort"); ?></button>
  881. <button type="button" class="calcbutton" onclick="Edit(0);">0</button>
  882. <button type="button" class="calcbutton" onclick="Edit('.');">.</button>
  883. <button type="button" class="calcbutton poscolorblue" onclick="Edit('c');">C</button>
  884. <button type="button" class="calcbutton2 poscolordelete" id="delete" onclick="deleteline();"><span class="fa fa-trash"></span></button>
  885. </div>
  886. <?php
  887. // TakePOS setup check
  888. if (isset($_SESSION["takeposterminal"]) && $_SESSION["takeposterminal"]) {
  889. $sql = "SELECT code, libelle FROM " . MAIN_DB_PREFIX . "c_paiement";
  890. $sql .= " WHERE entity IN (" . getEntity('c_paiement') . ")";
  891. $sql .= " AND active = 1";
  892. $sql .= " ORDER BY libelle";
  893. $resql = $db->query($sql);
  894. $paiementsModes = array();
  895. if ($resql) {
  896. while ( $obj = $db->fetch_object($resql) ) {
  897. $paycode = $obj->code;
  898. if ($paycode == 'LIQ') {
  899. $paycode = 'CASH';
  900. }
  901. if ($paycode == 'CHQ') {
  902. $paycode = 'CHEQUE';
  903. }
  904. $constantforkey = "CASHDESK_ID_BANKACCOUNT_" . $paycode . $_SESSION["takeposterminal"];
  905. //var_dump($constantforkey.' '.$conf->global->$constantforkey);
  906. if ( ! empty($conf->global->$constantforkey) && $conf->global->$constantforkey > 0) {
  907. array_push($paiementsModes, $obj);
  908. }
  909. }
  910. }
  911. if (empty($paiementsModes)) {
  912. $langs->load('errors');
  913. setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("TakePOS")), null, 'errors');
  914. setEventMessages($langs->trans("ProblemIsInSetupOfTerminal", $_SESSION["takeposterminal"]), null, 'errors');
  915. }
  916. }
  917. if (count($maincategories) == 0) {
  918. if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) {
  919. $tmpcategory = new Categorie($db);
  920. $tmpcategory->fetch($conf->global->TAKEPOS_ROOT_CATEGORY_ID);
  921. setEventMessages($langs->trans("TakeposNeedsAtLeastOnSubCategoryIntoParentCategory", $tmpcategory->label), null, 'errors');
  922. } else {
  923. setEventMessages($langs->trans("TakeposNeedsCategories"), null, 'errors');
  924. }
  925. }
  926. // User menu and external TakePOS modules
  927. $menus = array();
  928. $r = 0;
  929. if (empty($conf->global->TAKEPOS_BAR_RESTAURANT)) {
  930. $menus[$r++] = array('title'=>'<span class="fa fa-layer-group paddingrightonly"></span><div class="trunc">'.$langs->trans("New").'</div>', 'action'=>'New();');
  931. } else {
  932. // BAR RESTAURANT specific menu
  933. $menus[$r++] = array('title'=>'<span class="fa fa-layer-group paddingrightonly"></span><div class="trunc">'.$langs->trans("Place").'</div>', 'action'=>'Floors();');
  934. }
  935. if (!empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
  936. $menus[$r++] = array('title'=>'<span class="far fa-building paddingrightonly"></span><div class="trunc">'.$langs->trans("Customer").'</div>', 'action'=>'Customer();');
  937. }
  938. $menus[$r++] = array('title'=>'<span class="fa fa-history paddingrightonly"></span><div class="trunc">'.$langs->trans("History").'</div>', 'action'=>'History();');
  939. $menus[$r++] = array('title'=>'<span class="fa fa-cube paddingrightonly"></span><div class="trunc">'.$langs->trans("FreeZone").'</div>', 'action'=>'FreeZone();');
  940. $menus[$r++] = array('title'=>'<span class="fa fa-percent paddingrightonly"></span><div class="trunc">'.$langs->trans("Reduction").'</div>', 'action'=>'Reduction();');
  941. $menus[$r++] = array('title'=>'<span class="far fa-money-bill-alt paddingrightonly"></span><div class="trunc">'.$langs->trans("Payment").'</div>', 'action'=>'CloseBill();');
  942. if (getDolGlobalString('TAKEPOS_DIRECT_PAYMENT')) {
  943. $menus[$r++] = array('title'=>'<span class="far fa-money-bill-alt paddingrightonly"></span><div class="trunc">'.$langs->trans("DirectPayment").' <span class="opacitymedium">('.$langs->trans("Cash").')</span></div>', 'action'=>'DirectPayment();');
  944. }
  945. // BAR RESTAURANT specific menu
  946. if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
  947. if ($conf->global->TAKEPOS_ORDER_PRINTERS) {
  948. $menus[$r++] = array('title'=>'<span class="fa fa-blender-phone paddingrightonly"></span><div class="trunc">'.$langs->trans("Order").'</span>', 'action'=>'TakeposPrintingOrder();');
  949. }
  950. //Button to print receipt before payment
  951. if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
  952. if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") {
  953. if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
  954. $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'TakeposConnector(placeid);');
  955. } else {
  956. $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'TakeposPrinting(placeid);');
  957. }
  958. } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") {
  959. $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'DolibarrTakeposPrinting(placeid);');
  960. } else {
  961. $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'Print(placeid);');
  962. }
  963. }
  964. if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector" && getDolGlobalString('TAKEPOS_ORDER_NOTES') == 1) {
  965. $menus[$r++] = array('title'=>'<span class="fa fa-sticky-note paddingrightonly"></span><div class="trunc">'.$langs->trans("OrderNotes").'</div>', 'action'=>'TakeposOrderNotes();');
  966. }
  967. if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
  968. $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("ProductSupplements").'</div>', 'action'=>'LoadProducts(\'supplements\');');
  969. }
  970. }
  971. if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") {
  972. $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("DOL_OPEN_DRAWER").'</div>', 'action'=>'OpenDrawer();');
  973. }
  974. if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") {
  975. $menus[$r++] = array(
  976. 'title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("DOL_OPEN_DRAWER").'</div>',
  977. 'action' => 'DolibarrOpenDrawer();',
  978. );
  979. }
  980. $sql = "SELECT rowid, status, entity FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE";
  981. $sql .= " entity = ".((int) $conf->entity)." AND ";
  982. $sql .= " posnumber = ".((int) $_SESSION["takeposterminal"])." AND ";
  983. $sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'";
  984. $resql = $db->query($sql);
  985. if ($resql) {
  986. $num = $db->num_rows($resql);
  987. if ($num) {
  988. $obj = $db->fetch_object($resql);
  989. $menus[$r++] = array('title'=>'<span class="fas fa-file-invoice-dollar paddingrightonly"></span><div class="trunc">'.$langs->trans("CashReport").'</div>', 'action'=>'CashReport('.$obj->rowid.');');
  990. if ($obj->status == 0) {
  991. $menus[$r++] = array('title'=>'<span class="fas fa-cash-register paddingrightonly"></span><div class="trunc">'.$langs->trans("CloseCashFence").'</div>', 'action'=>'CloseCashFence('.$obj->rowid.');');
  992. }
  993. }
  994. }
  995. $hookmanager->initHooks(array('takeposfrontend'));
  996. $reshook = $hookmanager->executeHooks('ActionButtons');
  997. if (!empty($reshook)) {
  998. if (is_array($reshook) && !isset($reshook['title'])) {
  999. foreach ($reshook as $reshook) {
  1000. $menus[$r++] = $reshook;
  1001. }
  1002. } else {
  1003. $menus[$r++] = $reshook;
  1004. }
  1005. }
  1006. if ($r % 3 == 2) {
  1007. $menus[$r++] = array('title'=>'', 'style'=>'visibility: hidden;');
  1008. }
  1009. if (!empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
  1010. $menus[$r++] = array('title'=>'<span class="fa fa-sign-out-alt paddingrightonly"></span><div class="trunc">'.$langs->trans("Logout").'</div>', 'action'=>'window.location.href=\''.DOL_URL_ROOT.'/user/logout.php\';');
  1011. }
  1012. if (!empty($conf->global->TAKEPOS_WEIGHING_SCALE)) {
  1013. $menus[$r++] = array('title'=>'<span class="fa fa-balance-scale paddingrightonly"></span><div class="trunc">'.$langs->trans("WeighingScale").'</div>', 'action'=>'WeighingScale();');
  1014. }
  1015. ?>
  1016. <!-- Show buttons -->
  1017. <div class="div3">
  1018. <?php
  1019. $i = 0;
  1020. foreach ($menus as $menu) {
  1021. $i++;
  1022. if (count($menus) > 12 and $i == 12) {
  1023. echo '<button style="'.(empty($menu['style']) ? '' : $menu['style']).'" type="button" id="actionnext" class="actionbutton" onclick="MoreActions('.count($menus).');">'.$langs->trans("Next").'</button>';
  1024. echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
  1025. } elseif ($i > 12) {
  1026. echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
  1027. } else {
  1028. echo '<button style="'.(empty($menu['style']) ? '' : $menu['style']).'" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
  1029. }
  1030. }
  1031. if (!empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
  1032. print '<!-- Show the search input text -->'."\n";
  1033. print '<div class="margintoponly">';
  1034. print '<input type="text" id="search" name="search" onkeyup="Search2('.$keyCodeForEnter.');" style="width:80%;width:calc(100% - 51px);font-size: 150%;" placeholder="'.$langs->trans("Search").'" autofocus> ';
  1035. print '<a class="marginleftonly hideonsmartphone" onclick="ClearSearch();">'.img_picto('', 'searchclear').'</a>';
  1036. print '</div>';
  1037. }
  1038. ?>
  1039. </div>
  1040. </div>
  1041. <div class="row2<?php if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
  1042. print 'withhead';
  1043. } ?>">
  1044. <!-- Show categories -->
  1045. <div class="div4">
  1046. <?php
  1047. $count = 0;
  1048. while ($count < $MAXCATEG) {
  1049. ?>
  1050. <div class="wrapper" <?php if ($count == ($MAXCATEG - 2)) {
  1051. echo 'onclick="MoreCategories(\'less\');"';
  1052. } elseif ($count == ($MAXCATEG - 1)) {
  1053. echo 'onclick="MoreCategories(\'more\');"';
  1054. } else {
  1055. echo 'onclick="LoadProducts('.$count.');"';
  1056. } ?> id="catdiv<?php echo $count; ?>">
  1057. <?php
  1058. if ($count == ($MAXCATEG - 2)) {
  1059. //echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="catimg'.$count.'" />';
  1060. echo '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em;"></span>';
  1061. } elseif ($count == ($MAXCATEG - 1)) {
  1062. //echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="catimg'.$count.'" />';
  1063. echo '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em;"></span>';
  1064. } else {
  1065. if (!getDolGlobalString('TAKEPOS_HIDE_CATEGORY_IMAGES')) {
  1066. echo '<img class="imgwrapper" height="100%" id="catimg'.$count.'" />';
  1067. }
  1068. }
  1069. ?>
  1070. <?php if ($count != ($MAXCATEG - 2) && $count != ($MAXCATEG - 1)) { ?>
  1071. <div class="description" id="catdivdesc<?php echo $count; ?>">
  1072. <div class="description_content" id="catdesc<?php echo $count; ?>"></div>
  1073. </div>
  1074. <?php } ?>
  1075. <div class="catwatermark" id='catwatermark<?php echo $count; ?>'>...</div>
  1076. </div>
  1077. <?php
  1078. $count++;
  1079. }
  1080. ?>
  1081. </div>
  1082. <!-- Show product -->
  1083. <div class="div5">
  1084. <?php
  1085. $count = 0;
  1086. while ($count < $MAXPRODUCT) {
  1087. ?>
  1088. <div class="wrapper2" id='prodiv<?php echo $count; ?>' <?php if ($count == ($MAXPRODUCT - 2)) {
  1089. ?> onclick="MoreProducts('less');" <?php
  1090. } if ($count == ($MAXPRODUCT - 1)) {
  1091. ?> onclick="MoreProducts('more');" <?php
  1092. } else {
  1093. echo 'onclick="ClickProduct('.$count.');"';
  1094. } ?>>
  1095. <?php
  1096. if ($count == ($MAXPRODUCT - 2)) {
  1097. //echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="proimg'.$count.'" />';
  1098. print '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em;"></span>';
  1099. } elseif ($count == ($MAXPRODUCT - 1)) {
  1100. //echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="proimg'.$count.'" />';
  1101. print '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em;"></span>';
  1102. } else {
  1103. if (getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
  1104. echo '<button type="button" id="probutton'.$count.'" class="productbutton" style="display: none;"></button>';
  1105. } else {
  1106. print '<div class="" id="proprice'.$count.'"></div>';
  1107. print '<img class="imgwrapper" height="100%" title="" id="proimg'.$count.'">';
  1108. }
  1109. }
  1110. ?>
  1111. <?php if ($count != ($MAXPRODUCT - 2) && $count != ($MAXPRODUCT - 1) && !getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) { ?>
  1112. <div class="description" id="prodivdesc<?php echo $count; ?>">
  1113. <div class="description_content" id="prodesc<?php echo $count; ?>"></div>
  1114. </div>
  1115. <?php } ?>
  1116. <div class="catwatermark" id='prowatermark<?php echo $count; ?>'>...</div>
  1117. </div>
  1118. <?php
  1119. $count++;
  1120. }
  1121. ?>
  1122. </div>
  1123. </div>
  1124. </div>
  1125. </body>
  1126. <?php
  1127. llxFooter();
  1128. $db->close();