index.php 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  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('NOREQUIREMENU')) {
  29. define('NOREQUIREMENU', '1');
  30. }
  31. if (!defined('NOREQUIREHTML')) {
  32. define('NOREQUIREHTML', '1');
  33. }
  34. if (!defined('NOREQUIREAJAX')) {
  35. define('NOREQUIREAJAX', '1');
  36. }
  37. // Load Dolibarr environment
  38. require '../main.inc.php'; // Load $user and permissions
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  43. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  46. $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant or multiple sales
  47. $action = GETPOST('action', 'aZ09');
  48. $setterminal = GETPOST('setterminal', 'int');
  49. $setcurrency = GETPOST('setcurrency', 'aZ09');
  50. $hookmanager->initHooks(array('takeposfrontend'));
  51. if (empty($_SESSION["takeposterminal"])) {
  52. if (getDolGlobalInt('TAKEPOS_NUM_TERMINALS') == 1) {
  53. $_SESSION["takeposterminal"] = 1; // Use terminal 1 if there is only 1 terminal
  54. } elseif (!empty($_COOKIE["takeposterminal"])) {
  55. $_SESSION["takeposterminal"] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE["takeposterminal"]); // Restore takeposterminal from previous session
  56. }
  57. }
  58. if ($setterminal > 0) {
  59. $_SESSION["takeposterminal"] = $setterminal;
  60. setcookie("takeposterminal", $setterminal, (time() + (86400 * 354)), '/', null, (empty($dolibarr_main_force_https) ? false : true), true); // Permanent takeposterminal var in a cookie
  61. }
  62. if ($setcurrency != "") {
  63. $_SESSION["takeposcustomercurrency"] = $setcurrency;
  64. // We will recalculate amount for foreign currency at next call of invoice.php when $_SESSION["takeposcustomercurrency"] differs from invoice->multicurrency_code.
  65. }
  66. $_SESSION["urlfrom"] = '/takepos/index.php';
  67. $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter", "banks"));
  68. $categorie = new Categorie($db);
  69. $maxcategbydefaultforthisdevice = 12;
  70. $maxproductbydefaultforthisdevice = 24;
  71. if ($conf->browser->layout == 'phone') {
  72. $maxcategbydefaultforthisdevice = 8;
  73. $maxproductbydefaultforthisdevice = 16;
  74. //REDIRECT TO BASIC LAYOUT IF TERMINAL SELECTED AND BASIC MOBILE LAYOUT FORCED
  75. if (!empty($_SESSION["takeposterminal"]) && getDolGlobalString('TAKEPOS_BAR_RESTAURANT') && getDolGlobalInt('TAKEPOS_PHONE_BASIC_LAYOUT') == 1) {
  76. $_SESSION["basiclayout"] = 1;
  77. header("Location: phone.php?mobilepage=invoice");
  78. exit;
  79. }
  80. } else {
  81. unset($_SESSION["basiclayout"]);
  82. }
  83. $MAXCATEG = (!getDolGlobalString('TAKEPOS_NB_MAXCATEG') ? $maxcategbydefaultforthisdevice : $conf->global->TAKEPOS_NB_MAXCATEG);
  84. $MAXPRODUCT = (!getDolGlobalString('TAKEPOS_NB_MAXPRODUCT') ? $maxproductbydefaultforthisdevice : $conf->global->TAKEPOS_NB_MAXPRODUCT);
  85. $term = empty($_SESSION['takeposterminal']) ? 1: $_SESSION['takeposterminal'];
  86. /*
  87. $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
  88. $soc = new Societe($db);
  89. if ($invoice->socid > 0) $soc->fetch($invoice->socid);
  90. else $soc->fetch(getDolGlobalInt($constforcompanyid));
  91. */
  92. // Security check
  93. $result = restrictedArea($user, 'takepos', 0, '');
  94. /*
  95. * View
  96. */
  97. $form = new Form($db);
  98. $disablejs = 0;
  99. $disablehead = 0;
  100. $arrayofjs = array('/takepos/js/jquery.colorbox-min.js'); // TODO It seems we don't need this
  101. $arrayofcss = array('/takepos/css/pos.css.php', '/takepos/css/colorbox.css');
  102. if (getDolGlobalInt('TAKEPOS_COLOR_THEME') == 1) {
  103. $arrayofcss[] = '/takepos/css/colorful.css';
  104. }
  105. // Title
  106. $title = 'TakePOS - Dolibarr '.DOL_VERSION;
  107. if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
  108. $title = 'TakePOS - ' . getDolGlobalString('MAIN_APPLICATION_TITLE');
  109. }
  110. $head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
  111. <meta name="apple-mobile-web-app-capable" content="yes">
  112. <meta name="mobile-web-app-capable" content="yes">
  113. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
  114. top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
  115. $categories = $categorie->get_full_arbo('product', ((getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') > 0) ? getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') : 0), 1);
  116. // Search root category to know its level
  117. //$conf->global->TAKEPOS_ROOT_CATEGORY_ID=0;
  118. $levelofrootcategory = 0;
  119. if (getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') > 0) {
  120. foreach ($categories as $key => $categorycursor) {
  121. if ($categorycursor['id'] == getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID')) {
  122. $levelofrootcategory = $categorycursor['level'];
  123. break;
  124. }
  125. }
  126. }
  127. $levelofmaincategories = $levelofrootcategory + 1;
  128. $maincategories = array();
  129. $subcategories = array();
  130. foreach ($categories as $key => $categorycursor) {
  131. if ($categorycursor['level'] == $levelofmaincategories) {
  132. $maincategories[$key] = $categorycursor;
  133. } else {
  134. $subcategories[$key] = $categorycursor;
  135. }
  136. }
  137. $maincategories = dol_sort_array($maincategories, 'label');
  138. $subcategories = dol_sort_array($subcategories, 'label');
  139. ?>
  140. <body class="bodytakepos" style="overflow: hidden;">
  141. <script>
  142. var categories = <?php echo json_encode($maincategories); ?>;
  143. var subcategories = <?php echo json_encode($subcategories); ?>;
  144. var currentcat;
  145. var pageproducts=0;
  146. var pagecategories=0;
  147. var pageactions=0;
  148. var place="<?php echo $place; ?>";
  149. var editaction="qty";
  150. var editnumber="";
  151. var invoiceid=0;
  152. var search2_timer=null;
  153. /*
  154. var app = this;
  155. app.hasKeyboard = false;
  156. this.keyboardPress = function() {
  157. app.hasKeyboard = true;
  158. $(window).unbind("keyup", app.keyboardPress);
  159. localStorage.hasKeyboard = true;
  160. console.log("has keyboard!")
  161. }
  162. $(window).on("keyup", app.keyboardPress)
  163. if(localStorage.hasKeyboard) {
  164. app.hasKeyboard = true;
  165. $(window).unbind("keyup", app.keyboardPress);
  166. console.log("has keyboard from localStorage")
  167. }
  168. */
  169. function ClearSearch() {
  170. console.log("ClearSearch");
  171. $("#search").val('');
  172. $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
  173. $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
  174. $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
  175. <?php if ($conf->browser->layout == 'classic') { ?>
  176. setFocusOnSearchField();
  177. <?php } ?>
  178. }
  179. // 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
  180. function setFocusOnSearchField() {
  181. console.log("Call setFocusOnSearchField in page index.php");
  182. <?php if ($conf->browser->layout == 'classic') { ?>
  183. console.log("has keyboard from localStorage, so we can force focus on search field");
  184. $("#search").focus();
  185. <?php } ?>
  186. }
  187. function PrintCategories(first) {
  188. console.log("PrintCategories");
  189. for (i = 0; i < <?php echo($MAXCATEG - 2); ?>; i++) {
  190. if (typeof (categories[parseInt(i)+parseInt(first)]) == "undefined")
  191. {
  192. $("#catdivdesc"+i).hide();
  193. $("#catdesc"+i).text("");
  194. $("#catimg"+i).attr("src","genimg/empty.png");
  195. $("#catwatermark"+i).hide();
  196. $("#catdiv"+i).attr('class', 'wrapper divempty');
  197. continue;
  198. }
  199. $("#catdivdesc"+i).show();
  200. <?php
  201. if (getDolGlobalString('TAKEPOS_SHOW_CATEGORY_DESCRIPTION') == 1) { ?>
  202. $("#catdesc"+i).html(categories[parseInt(i)+parseInt(first)]['label'].bold() + ' - ' + categories[parseInt(i)+parseInt(first)]['description']);
  203. <?php } else { ?>
  204. $("#catdesc"+i).text(categories[parseInt(i)+parseInt(first)]['label']);
  205. <?php } ?>
  206. $("#catimg"+i).attr("src","genimg/index.php?query=cat&id="+categories[parseInt(i)+parseInt(first)]['rowid']);
  207. $("#catdiv"+i).data("rowid",categories[parseInt(i)+parseInt(first)]['rowid']);
  208. $("#catdiv"+i).attr("data-rowid",categories[parseInt(i)+parseInt(first)]['rowid']);
  209. $("#catdiv"+i).attr('class', 'wrapper');
  210. $("#catwatermark"+i).show();
  211. }
  212. }
  213. function MoreCategories(moreorless) {
  214. console.log("MoreCategories moreorless="+moreorless+" pagecategories="+pagecategories);
  215. if (moreorless == "more") {
  216. $('#catimg15').animate({opacity: '0.5'}, 1);
  217. $('#catimg15').animate({opacity: '1'}, 100);
  218. pagecategories=pagecategories+1;
  219. }
  220. if (moreorless == "less") {
  221. $('#catimg14').animate({opacity: '0.5'}, 1);
  222. $('#catimg14').animate({opacity: '1'}, 100);
  223. if (pagecategories==0) return; //Return if no less pages
  224. pagecategories=pagecategories-1;
  225. }
  226. if (typeof (categories[<?php echo($MAXCATEG - 2); ?> * pagecategories] && moreorless == "more") == "undefined") { // Return if no more pages
  227. pagecategories=pagecategories-1;
  228. return;
  229. }
  230. for (i = 0; i < <?php echo($MAXCATEG - 2); ?>; i++) {
  231. if (typeof (categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]) == "undefined") {
  232. // complete with empty record
  233. console.log("complete with empty record");
  234. $("#catdivdesc"+i).hide();
  235. $("#catdesc"+i).text("");
  236. $("#catimg"+i).attr("src","genimg/empty.png");
  237. $("#catwatermark"+i).hide();
  238. continue;
  239. }
  240. $("#catdivdesc"+i).show();
  241. <?php
  242. if (getDolGlobalString('TAKEPOS_SHOW_CATEGORY_DESCRIPTION') == 1) { ?>
  243. $("#catdesc"+i).html(categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]['label'].bold() + ' - ' + categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]['description']);
  244. <?php } else { ?>
  245. $("#catdesc"+i).text(categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]['label']);
  246. <?php } ?>
  247. $("#catimg"+i).attr("src","genimg/index.php?query=cat&id="+categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]['rowid']);
  248. $("#catdiv"+i).data("rowid",categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]['rowid']);
  249. $("#catdiv"+i).attr("data-rowid",categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]['rowid']);
  250. $("#catwatermark"+i).show();
  251. }
  252. ClearSearch();
  253. }
  254. // LoadProducts
  255. function LoadProducts(position, issubcat) {
  256. console.log("LoadProducts position="+position+" issubcat="+issubcat);
  257. var maxproduct = <?php echo($MAXPRODUCT - 2); ?>;
  258. if (position=="supplements") {
  259. currentcat="supplements";
  260. } else {
  261. $('#catimg'+position).animate({opacity: '0.5'}, 1);
  262. $('#catimg'+position).animate({opacity: '1'}, 100);
  263. if (issubcat == true) {
  264. currentcat=$('#prodiv'+position).data('rowid');
  265. } else {
  266. console.log('#catdiv'+position);
  267. currentcat=$('#catdiv'+position).data('rowid');
  268. console.log("currentcat="+currentcat);
  269. }
  270. }
  271. if (currentcat == undefined) {
  272. return;
  273. }
  274. pageproducts=0;
  275. ishow=0; //product to show counter
  276. jQuery.each(subcategories, function(i, val) {
  277. if (currentcat==val.fk_parent) {
  278. $("#prodivdesc"+ishow).show();
  279. <?php if (getDolGlobalString('TAKEPOS_SHOW_CATEGORY_DESCRIPTION') == 1) { ?>
  280. $("#prodesc"+ishow).html(val.label.bold() + ' - ' + val.description);
  281. $("#probutton"+ishow).html(val.label);
  282. <?php } else { ?>
  283. $("#prodesc"+ishow).text(val.label);
  284. $("#probutton"+ishow).text(val.label);
  285. <?php } ?>
  286. $("#probutton"+ishow).show();
  287. $("#proprice"+ishow).attr("class", "hidden");
  288. $("#proprice"+ishow).html("");
  289. $("#proimg"+ishow).attr("src","genimg/index.php?query=cat&id="+val.rowid);
  290. $("#prodiv"+ishow).data("rowid",val.rowid);
  291. $("#prodiv"+ishow).attr("data-rowid",val.rowid);
  292. $("#prodiv"+ishow).data("iscat",1);
  293. $("#prodiv"+ishow).attr("data-iscat",1);
  294. $("#prowatermark"+ishow).show();
  295. ishow++;
  296. }
  297. });
  298. idata=0; //product data counter
  299. var limit = 0;
  300. if (maxproduct >= 1) {
  301. limit = maxproduct-1;
  302. }
  303. // Only show products for sale (tosell=1)
  304. $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&token=<?php echo newToken();?>&thirdpartyid=' + jQuery('#thirdpartyid').val() + '&category='+currentcat+'&tosell=1&limit='+limit+'&offset=0', function(data) {
  305. console.log("Call ajax.php (in LoadProducts) to get Products of category "+currentcat+" then loop on result to fill image thumbs");
  306. console.log(data);
  307. while (ishow < maxproduct) {
  308. console.log("ishow"+ishow+" idata="+idata);
  309. //console.log(data[idata]);
  310. if (typeof (data[idata]) == "undefined") {
  311. <?php if (!getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
  312. echo '$("#prodivdesc"+ishow).hide();';
  313. echo '$("#prodesc"+ishow).text("");';
  314. echo '$("#proimg"+ishow).attr("title","");';
  315. echo '$("#proimg"+ishow).attr("src","genimg/empty.png");';
  316. } else {
  317. echo '$("#probutton"+ishow).hide();';
  318. echo '$("#probutton"+ishow).text("");';
  319. }?>
  320. $("#proprice"+ishow).attr("class", "hidden");
  321. $("#proprice"+ishow).html("");
  322. $("#prodiv"+ishow).data("rowid","");
  323. $("#prodiv"+ishow).attr("data-rowid","");
  324. $("#prodiv"+ishow).attr("class","wrapper2 divempty");
  325. } else {
  326. <?php
  327. $titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[idata]['ref']";
  328. $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[idata]['barcode']";
  329. ?>
  330. var titlestring = <?php echo $titlestring; ?>;
  331. <?php if (!getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
  332. echo '$("#prodivdesc"+ishow).show();';
  333. if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) {
  334. echo '$("#prodesc"+ishow).html(data[parseInt(idata)][\'ref\'].bold() + \' - \' + data[parseInt(idata)][\'label\']);';
  335. } elseif (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 2) {
  336. echo '$("#prodesc"+ishow).html(data[parseInt(idata)][\'ref\'].bold());';
  337. } else {
  338. echo '$("#prodesc"+ishow).html(data[parseInt(idata)][\'label\']);';
  339. }
  340. echo '$("#proimg"+ishow).attr("title", titlestring);';
  341. echo '$("#proimg"+ishow).attr("src", "genimg/index.php?query=pro&id="+data[idata][\'id\']);';
  342. } else {
  343. echo '$("#probutton"+ishow).show();';
  344. echo '$("#probutton"+ishow).html(data[parseInt(idata)][\'label\']);';
  345. }
  346. ?>
  347. if (data[parseInt(idata)]['price_formated']) {
  348. $("#proprice" + ishow).attr("class", "productprice");
  349. <?php
  350. if (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT')) {
  351. ?>
  352. $("#proprice" + ishow).html(data[parseInt(idata)]['price_formated']);
  353. <?php
  354. } else {
  355. ?>
  356. $("#proprice" + ishow).html(data[parseInt(idata)]['price_ttc_formated']);
  357. <?php
  358. }
  359. ?>
  360. }
  361. console.log("#prodiv"+ishow+".data(rowid)="+data[idata]['id']);
  362. $("#prodiv"+ishow).data("rowid", data[idata]['id']);
  363. $("#prodiv"+ishow).attr("data-rowid", data[idata]['id']);
  364. console.log($('#prodiv4').data('rowid'));
  365. $("#prodiv"+ishow).data("iscat", 0);
  366. $("#prodiv"+ishow).attr("data-iscat", 0);
  367. $("#prodiv"+ishow).attr("class","wrapper2");
  368. <?php
  369. // Add js from hooks
  370. $parameters=array();
  371. $parameters['caller'] = 'loadProducts';
  372. $hookmanager->executeHooks('completeJSProductDisplay', $parameters);
  373. print $hookmanager->resPrint;
  374. ?>
  375. }
  376. $("#prowatermark"+ishow).hide();
  377. ishow++; //Next product to show after print data product
  378. idata++; //Next data everytime
  379. }
  380. });
  381. ClearSearch();
  382. }
  383. function MoreProducts(moreorless) {
  384. console.log("MoreProducts");
  385. if ($('#search_pagination').val() != '') {
  386. return Search2('<?php echo(isset($keyCodeForEnter) ? $keyCodeForEnter : ''); ?>', moreorless);
  387. }
  388. var maxproduct = <?php echo($MAXPRODUCT - 2); ?>;
  389. if (moreorless=="more"){
  390. $('#proimg31').animate({opacity: '0.5'}, 1);
  391. $('#proimg31').animate({opacity: '1'}, 100);
  392. pageproducts=pageproducts+1;
  393. }
  394. if (moreorless=="less"){
  395. $('#proimg30').animate({opacity: '0.5'}, 1);
  396. $('#proimg30').animate({opacity: '1'}, 100);
  397. if (pageproducts==0) return; //Return if no less pages
  398. pageproducts=pageproducts-1;
  399. }
  400. ishow=0; //product to show counter
  401. idata=0; //product data counter
  402. var limit = 0;
  403. if (maxproduct >= 1) {
  404. limit = maxproduct-1;
  405. }
  406. var offset = <?php echo($MAXPRODUCT - 2); ?> * pageproducts;
  407. // Only show products for sale (tosell=1)
  408. $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&token=<?php echo newToken();?>&category='+currentcat+'&tosell=1&limit='+limit+'&offset='+offset, function(data) {
  409. console.log("Call ajax.php (in MoreProducts) to get Products of category "+currentcat);
  410. if (typeof (data[0]) == "undefined" && moreorless=="more"){ // Return if no more pages
  411. pageproducts=pageproducts-1;
  412. return;
  413. }
  414. while (ishow < maxproduct) {
  415. if (typeof (data[idata]) == "undefined") {
  416. $("#prodivdesc"+ishow).hide();
  417. $("#prodesc"+ishow).text("");
  418. $("#probutton"+ishow).text("");
  419. $("#probutton"+ishow).hide();
  420. $("#proprice"+ishow).attr("class", "");
  421. $("#proprice"+ishow).html("");
  422. $("#proimg"+ishow).attr("src","genimg/empty.png");
  423. $("#prodiv"+ishow).data("rowid","");
  424. $("#prodiv"+ishow).attr("data-rowid","");
  425. } else {
  426. $("#prodivdesc"+ishow).show();
  427. <?php if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) { ?>
  428. $("#prodesc"+ishow).html(data[parseInt(idata)]['ref'].bold() + ' - ' + data[parseInt(idata)]['label']);
  429. <?php } elseif (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 2) { ?>
  430. $("#prodesc"+ishow).html(data[parseInt(idata)]['ref'].bold());
  431. <?php } else { ?>
  432. $("#prodesc"+ishow).html(data[parseInt(idata)]['label']);
  433. <?php } ?>
  434. $("#probutton"+ishow).html(data[parseInt(idata)]['label']);
  435. $("#probutton"+ishow).show();
  436. if (data[parseInt(idata)]['price_formated']) {
  437. $("#proprice" + ishow).attr("class", "productprice");
  438. <?php
  439. if (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT')) {
  440. ?>
  441. $("#proprice" + ishow).html(data[parseInt(idata)]['price_formated']);
  442. <?php
  443. } else {
  444. ?>
  445. $("#proprice" + ishow).html(data[parseInt(idata)]['price_ttc_formated']);
  446. <?php
  447. }
  448. ?>
  449. }
  450. $("#proimg"+ishow).attr("src","genimg/index.php?query=pro&id="+data[idata]['id']);
  451. $("#prodiv"+ishow).data("rowid",data[idata]['id']);
  452. $("#prodiv"+ishow).attr("data-rowid",data[idata]['id']);
  453. $("#prodiv"+ishow).data("iscat",0);
  454. }
  455. $("#prowatermark"+ishow).hide();
  456. ishow++; //Next product to show after print data product
  457. idata++; //Next data everytime
  458. }
  459. });
  460. ClearSearch();
  461. }
  462. function ClickProduct(position, qty = 1) {
  463. console.log("ClickProduct at position"+position);
  464. $('#proimg'+position).animate({opacity: '0.5'}, 1);
  465. $('#proimg'+position).animate({opacity: '1'}, 100);
  466. if ($('#prodiv'+position).data('iscat')==1){
  467. console.log("Click on a category at position "+position);
  468. LoadProducts(position, true);
  469. }
  470. else{
  471. console.log($('#prodiv4').data('rowid'));
  472. idproduct=$('#prodiv'+position).data('rowid');
  473. console.log("Click on product at position "+position+" for idproduct "+idproduct+", qty="+qty);
  474. if (idproduct=="") return;
  475. // Call page invoice.php to generate the section with product lines
  476. $("#poslines").load("invoice.php?action=addline&token=<?php echo newToken() ?>&place="+place+"&idproduct="+idproduct+"&qty="+qty, function() {
  477. <?php if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
  478. echo "CustomerDisplay();";
  479. }?>
  480. });
  481. }
  482. ClearSearch();
  483. }
  484. function ChangeThirdparty(idcustomer) {
  485. console.log("ChangeThirdparty");
  486. // Call page list.php to change customer
  487. $("#poslines").load("<?php echo DOL_URL_ROOT ?>/societe/list.php?action=change&token=<?php echo newToken();?>&type=t&contextpage=poslist&idcustomer="+idcustomer+"&place="+place+"", function() {
  488. });
  489. ClearSearch();
  490. }
  491. function deleteline() {
  492. console.log("Delete line");
  493. $("#poslines").load("invoice.php?action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
  494. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  495. });
  496. ClearSearch();
  497. }
  498. function Customer() {
  499. console.log("Open box to select the thirdparty place="+place);
  500. $.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"); ?>"});
  501. }
  502. function Contact() {
  503. console.log("Open box to select the contact place="+place);
  504. $.colorbox({href:"../contact/list.php?type=c&contextpage=poslist&nomassaction=1&place="+place, width:"90%", height:"80%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Contact"); ?>"});
  505. }
  506. function History()
  507. {
  508. console.log("Open box to select the history");
  509. $.colorbox({href:"../compta/facture/list.php?contextpage=poslist", width:"90%", height:"80%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("History"); ?>"});
  510. }
  511. function Reduction() {
  512. invoiceid = $("#invoiceid").val();
  513. console.log("Open popup to enter reduction on invoiceid="+invoiceid);
  514. $.colorbox({href:"reduction.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
  515. }
  516. function CloseBill() {
  517. invoiceid = $("#invoiceid").val();
  518. console.log("Open popup to enter payment on invoiceid="+invoiceid);
  519. $.colorbox({href:"pay.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
  520. }
  521. function Split() {
  522. invoiceid = $("#invoiceid").val();
  523. console.log("Open popup to split on invoiceid="+invoiceid);
  524. $.colorbox({href:"split.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
  525. }
  526. function Floors() {
  527. console.log("Open box to select floor place="+place);
  528. $.colorbox({href:"floors.php?place="+place, width:"90%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Floors"); ?>"});
  529. }
  530. function FreeZone() {
  531. console.log("Open box to enter a free product");
  532. $.colorbox({href:"freezone.php?action=freezone&token=<?php echo newToken(); ?>&place="+place, width:"80%", height:"40%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("FreeZone"); ?>"});
  533. }
  534. function TakeposOrderNotes() {
  535. console.log("Open box to order notes");
  536. ModalBox('ModalNote');
  537. $("#textinput").focus();
  538. }
  539. function Refresh() {
  540. console.log("Refresh by reloading place="+place+" invoiceid="+invoiceid);
  541. $("#poslines").load("invoice.php?place="+place+"&invoiceid="+invoiceid, function() {
  542. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  543. });
  544. }
  545. function New() {
  546. // If we go here,it means $conf->global->TAKEPOS_BAR_RESTAURANT is not defined
  547. invoiceid = $("#invoiceid").val(); // This is a hidden field added by invoice.php
  548. console.log("New with place = <?php echo $place; ?>, js place="+place+", invoiceid="+invoiceid);
  549. $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getInvoice&token=<?php echo newToken();?>&id='+invoiceid, function(data) {
  550. var r;
  551. if (parseInt(data['paye']) === 1) {
  552. r = true;
  553. } else {
  554. r = confirm('<?php echo($place > 0 ? $langs->transnoentitiesnoconv("ConfirmDeletionOfThisPOSSale") : $langs->transnoentitiesnoconv("ConfirmDiscardOfThisPOSSale")); ?>');
  555. }
  556. if (r == true) {
  557. // Reload section with invoice lines
  558. $("#poslines").load("invoice.php?action=delete&token=<?php echo newToken(); ?>&place=" + place, function () {
  559. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  560. });
  561. ClearSearch();
  562. }
  563. });
  564. }
  565. /**
  566. * Search products
  567. *
  568. * @param keyCodeForEnter Key code for "enter" or '' if not
  569. * @param moreorless "more" or "less"
  570. * return void
  571. */
  572. function Search2(keyCodeForEnter, moreorless) {
  573. var eventKeyCode = window.event.keyCode;
  574. console.log("Search2 Call ajax search to replace products keyCodeForEnter="+keyCodeForEnter+", eventKeyCode="+eventKeyCode);
  575. var search_term = $('#search').val();
  576. var search_start = 0;
  577. var search_limit = <?php echo $MAXPRODUCT - 2; ?>;
  578. if (moreorless != null) {
  579. search_term = $('#search_pagination').val();
  580. search_start = $('#search_start_'+moreorless).val();
  581. }
  582. console.log("search_term="+search_term);
  583. if (search_term == '') {
  584. $("[id^=prowatermark]").html("");
  585. $("[id^=prodesc]").text("");
  586. $("[id^=probutton]").text("");
  587. $("[id^=probutton]").hide();
  588. $("[id^=proprice]").attr("class", "hidden");
  589. $("[id^=proprice]").html("");
  590. $("[id^=proimg]").attr("src", "genimg/empty.png");
  591. $("[id^=prodiv]").data("rowid", "");
  592. $("[id^=prodiv]").attr("data-rowid", "");
  593. return;
  594. }
  595. var search = false;
  596. if (keyCodeForEnter == '' || eventKeyCode == keyCodeForEnter) {
  597. search = true;
  598. }
  599. if (search === true) {
  600. // if a timer has been already started (search2_timer is a global js variable), we cancel it now
  601. // we click onto another key, we will restart another timer just after
  602. if (search2_timer) {
  603. clearTimeout(search2_timer);
  604. }
  605. // temporization time to give time to type
  606. search2_timer = setTimeout(function(){
  607. pageproducts = 0;
  608. jQuery(".wrapper2 .catwatermark").hide();
  609. var nbsearchresults = 0;
  610. $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&token=<?php echo newToken();?>&term=' + search_term + '&thirdpartyid=' + jQuery('#thirdpartyid').val() + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) {
  611. for (i = 0; i < <?php echo $MAXPRODUCT ?>; i++) {
  612. if (typeof (data[i]) == "undefined") {
  613. $("#prowatermark" + i).html("");
  614. $("#prodesc" + i).text("");
  615. $("#probutton" + i).text("");
  616. $("#probutton" + i).hide();
  617. $("#proprice" + i).attr("class", "hidden");
  618. $("#proprice" + i).html("");
  619. $("#proimg" + i).attr("src", "genimg/empty.png");
  620. $("#prodiv" + i).data("rowid", "");
  621. $("#prodiv" + i).attr("data-rowid", "");
  622. continue;
  623. }
  624. <?php
  625. $titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[i]['ref']";
  626. $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[i]['barcode']";
  627. ?>
  628. var titlestring = <?php echo $titlestring; ?>;
  629. <?php if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) { ?>
  630. $("#prodesc" + i).html(data[i]['ref'].bold() + ' - ' + data[i]['label']);
  631. <?php } elseif (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 2) { ?>
  632. $("#prodesc" + i).html(data[i]['ref'].bold());
  633. <?php } else { ?>
  634. $("#prodesc" + i).html(data[i]['label']);
  635. <?php } ?>
  636. $("#prodivdesc" + i).show();
  637. $("#probutton" + i).html(data[i]['label']);
  638. $("#probutton" + i).show();
  639. if (data[i]['price_formated']) {
  640. $("#proprice" + i).attr("class", "productprice");
  641. <?php
  642. if (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT')) {
  643. ?>
  644. $("#proprice" + i).html(data[i]['price_formated']);
  645. <?php
  646. } else {
  647. ?>
  648. $("#proprice" + i).html(data[i]['price_ttc_formated']);
  649. <?php
  650. }
  651. ?>
  652. }
  653. $("#proimg" + i).attr("title", titlestring);
  654. if( undefined !== data[i]['img']) {
  655. $("#proimg" + i).attr("src", data[i]['img']);
  656. }
  657. else {
  658. $("#proimg" + i).attr("src", "genimg/index.php?query=pro&id=" + data[i]['rowid']);
  659. }
  660. $("#prodiv" + i).data("rowid", data[i]['rowid']);
  661. $("#prodiv" + i).attr("data-rowid", data[i]['rowid']);
  662. $("#prodiv" + i).data("iscat", 0);
  663. $("#prodiv" + i).attr("data-iscat", 0);
  664. <?php
  665. // Add js from hooks
  666. $parameters=array();
  667. $parameters['caller'] = 'search2';
  668. $hookmanager->executeHooks('completeJSProductDisplay', $parameters);
  669. print $hookmanager->resPrint;
  670. ?>
  671. nbsearchresults++;
  672. }
  673. }).always(function (data) {
  674. // If there is only 1 answer
  675. if ($('#search').val().length > 0 && data.length == 1) {
  676. console.log($('#search').val()+' - '+data[0]['barcode']);
  677. if ($('#search').val() == data[0]['barcode'] && 'thirdparty' == data[0]['object']) {
  678. console.log("There is only 1 answer with barcode matching the search, so we change the thirdparty "+data[0]['rowid']);
  679. ChangeThirdparty(data[0]['rowid']);
  680. }
  681. else if ($('#search').val() == data[0]['barcode'] && 'product' == data[0]['object']) {
  682. console.log("There is only 1 answer and we found search on a barcode, so we add the product in basket, qty="+data[0]['qty']);
  683. ClickProduct(0, data[0]['qty']);
  684. }
  685. }
  686. if (eventKeyCode == keyCodeForEnter){
  687. if (data.length == 0) {
  688. $('#search').val('<?php
  689. $langs->load('errors');
  690. echo dol_escape_js($langs->transnoentitiesnoconv("ErrorRecordNotFoundShort"));
  691. ?> ('+search_term+')');
  692. $('#search').select();
  693. }
  694. else ClearSearch();
  695. }
  696. // memorize search_term and start for pagination
  697. $("#search_pagination").val($("#search").val());
  698. if (search_start == 0) {
  699. $("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").hide();
  700. }
  701. else {
  702. $("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").show();
  703. var search_start_less = Math.max(0, parseInt(search_start) - parseInt(<?php echo $MAXPRODUCT - 2;?>));
  704. $("#search_start_less").val(search_start_less);
  705. }
  706. if (nbsearchresults != <?php echo $MAXPRODUCT - 2; ?>) {
  707. $("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").hide();
  708. }
  709. else {
  710. $("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").show();
  711. var search_start_more = parseInt(search_start) + parseInt(<?php echo $MAXPRODUCT - 2;?>);
  712. $("#search_start_more").val(search_start_more);
  713. }
  714. });
  715. }, 500); // 500ms delay
  716. }
  717. }
  718. /* Function called on an action into the PAD */
  719. function Edit(number) {
  720. console.log("We click on PAD on key="+number);
  721. if (typeof(selectedtext) == "undefined") {
  722. return; // We click on an action on the number pad but there is no line selected
  723. }
  724. var text=selectedtext+"<br> ";
  725. if (number=='c') {
  726. editnumber='';
  727. Refresh();
  728. $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
  729. $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
  730. $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
  731. return;
  732. } else if (number=='qty') {
  733. if (editaction=='qty' && editnumber != '') {
  734. $("#poslines").load("invoice.php?action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  735. editnumber="";
  736. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  737. $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
  738. });
  739. setFocusOnSearchField();
  740. return;
  741. }
  742. else {
  743. editaction="qty";
  744. }
  745. } else if (number=='p') {
  746. if (editaction=='p' && editnumber!="") {
  747. $("#poslines").load("invoice.php?action=updateprice&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  748. editnumber="";
  749. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  750. $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
  751. });
  752. ClearSearch();
  753. return;
  754. }
  755. else {
  756. editaction="p";
  757. }
  758. } else if (number=='r') {
  759. if (editaction=='r' && editnumber!="") {
  760. $("#poslines").load("invoice.php?action=updatereduction&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  761. editnumber="";
  762. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  763. $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
  764. });
  765. ClearSearch();
  766. return;
  767. }
  768. else {
  769. editaction="r";
  770. }
  771. }
  772. else {
  773. editnumber=editnumber+number;
  774. }
  775. if (editaction=='qty'){
  776. text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Qty").": "; ?>";
  777. $("#qty").html("OK").addClass("clicked");
  778. $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
  779. $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
  780. }
  781. if (editaction=='p'){
  782. text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Price").": "; ?>";
  783. $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
  784. $("#price").html("OK").addClass("clicked");
  785. $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
  786. }
  787. if (editaction=='r'){
  788. text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("LineDiscountShort").": "; ?>";
  789. $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
  790. $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
  791. $("#reduction").html("OK").addClass("clicked");
  792. }
  793. $('#'+selectedline).find("td:first").html(text+editnumber);
  794. }
  795. function TakeposPrintingOrder(){
  796. console.log("TakeposPrintingOrder");
  797. $("#poslines").load("invoice.php?action=order&token=<?php echo newToken();?>&place="+place, function() {
  798. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  799. });
  800. }
  801. function TakeposPrintingTemp(){
  802. console.log("TakeposPrintingTemp");
  803. $("#poslines").load("invoice.php?action=temp&token=<?php echo newToken();?>&place="+place, function() {
  804. //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
  805. });
  806. }
  807. function OpenDrawer(){
  808. console.log("OpenDrawer call ajax url http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>:8111/print");
  809. $.ajax({
  810. type: "POST",
  811. data: { token: 'notrequired' },
  812. <?php
  813. if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
  814. echo "url: '".getDolGlobalString('TAKEPOS_PRINT_SERVER', 'localhost')."/printer/drawer.php',";
  815. } else {
  816. echo "url: 'http://".getDolGlobalString('TAKEPOS_PRINT_SERVER', 'localhost').":8111/print',";
  817. }
  818. ?>
  819. data: "opendrawer"
  820. });
  821. }
  822. function DolibarrOpenDrawer() {
  823. console.log("DolibarrOpenDrawer call ajax url /takepos/ajax/ajax.php?action=opendrawer&token=<?php echo newToken();?>&term=<?php print urlencode($_SESSION["takeposterminal"]); ?>");
  824. $.ajax({
  825. type: "GET",
  826. data: { token: '<?php echo currentToken(); ?>' },
  827. url: "<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=opendrawer&token='.newToken().'&term='.urlencode($_SESSION["takeposterminal"]); ?>",
  828. });
  829. }
  830. function MoreActions(totalactions){
  831. if (pageactions==0){
  832. pageactions=1;
  833. for (i = 0; i <= totalactions; i++){
  834. if (i<12) $("#action"+i).hide();
  835. else $("#action"+i).show();
  836. }
  837. }
  838. else if (pageactions==1){
  839. pageactions=0;
  840. for (i = 0; i <= totalactions; i++){
  841. if (i<12) $("#action"+i).show();
  842. else $("#action"+i).hide();
  843. }
  844. }
  845. return true;
  846. }
  847. function ControlCashOpening()
  848. {
  849. $.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"); ?>"});
  850. }
  851. function CloseCashFence(rowid)
  852. {
  853. $.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"); ?>"});
  854. }
  855. function CashReport(rowid)
  856. {
  857. $.colorbox({href:"../compta/cashcontrol/report.php?id="+rowid+"&contextpage=takepos", width:"60%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("CashReport"); ?>"});
  858. }
  859. // TakePOS Popup
  860. function ModalBox(ModalID)
  861. {
  862. var modal = document.getElementById(ModalID);
  863. modal.style.display = "block";
  864. }
  865. function DirectPayment(){
  866. console.log("DirectPayment");
  867. $("#poslines").load("invoice.php?place="+place+"&action=valid&token=<?php echo newToken(); ?>&pay=LIQ", function() {
  868. });
  869. }
  870. function FullScreen() {
  871. document.documentElement.requestFullscreen();
  872. }
  873. function WeighingScale(){
  874. console.log("Weighing Scale");
  875. $.ajax({
  876. type: "POST",
  877. data: { token: 'notrequired' },
  878. url: '<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>/scale/index.php',
  879. })
  880. .done(function( editnumber ) {
  881. $("#poslines").load("invoice.php?token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
  882. editnumber="";
  883. });
  884. });
  885. }
  886. $( document ).ready(function() {
  887. PrintCategories(0);
  888. LoadProducts(0);
  889. Refresh();
  890. <?php
  891. //IF NO TERMINAL SELECTED
  892. if ($_SESSION["takeposterminal"] == "") {
  893. print "ModalBox('ModalTerminal');";
  894. }
  895. if (getDolGlobalString('TAKEPOS_CONTROL_CASH_OPENING')) {
  896. $sql = "SELECT rowid, status FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE";
  897. $sql .= " entity = ".((int) $conf->entity)." AND ";
  898. $sql .= " posnumber = ".((int) $_SESSION["takeposterminal"])." AND ";
  899. $sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'";
  900. $resql = $db->query($sql);
  901. if ($resql) {
  902. $obj = $db->fetch_object($resql);
  903. // If there is no cash control from today open it
  904. if (!isset($obj->rowid) || is_null($obj->rowid)) {
  905. print "ControlCashOpening();";
  906. }
  907. }
  908. }
  909. ?>
  910. /* For Header Scroll */
  911. var elem1 = $("#topnav-left")[0];
  912. var elem2 = $("#topnav-right")[0];
  913. var checkOverflow = function() {
  914. if (scrollBars().horizontal) $("#topnav").addClass("overflow");
  915. else $("#topnav").removeClass("overflow");
  916. }
  917. var scrollBars = function(){
  918. var container= $('#topnav')[0];
  919. return {
  920. vertical:container.scrollHeight > container.clientHeight,
  921. horizontal:container.scrollWidth > container.clientWidth
  922. }
  923. }
  924. $(window).resize(function(){
  925. checkOverflow();
  926. });
  927. let resizeObserver = new ResizeObserver(() => {
  928. checkOverflow();
  929. });
  930. resizeObserver.observe(elem1);
  931. resizeObserver.observe(elem2);
  932. checkOverflow();
  933. var pressTimer = [];
  934. var direction = 1;
  935. var step = 200;
  936. $(".indicator").mousedown(function(){
  937. direction = $(this).hasClass("left") ? -1 : 1;
  938. scrollTo();
  939. pressTimer.push(setInterval(scrollTo, 100));
  940. });
  941. $(".indicator").mouseup(function(){
  942. pressTimer.forEach(clearInterval);
  943. });
  944. $("body").mouseup(function(){
  945. pressTimer.forEach(clearInterval);
  946. console.log("body");
  947. });
  948. function scrollTo(){
  949. console.log("here");
  950. var pos = $("#topnav").scrollLeft();
  951. document.getElementById("topnav").scrollTo({ left: $("#topnav").scrollLeft() + direction * step, behavior: 'smooth' })
  952. }
  953. $("#topnav").scroll(function(){
  954. if (($("#topnav").offsetWidth + $("#topnav").scrollLeft >= $("#topnav").scrollWidth)) {
  955. console.log("end");
  956. }
  957. });
  958. /* End Header Scroll */
  959. });
  960. </script>
  961. <?php
  962. $keyCodeForEnter = getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) > 0 ? getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) : '';
  963. ?>
  964. <div class="container">
  965. <?php
  966. if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
  967. ?>
  968. <div class="header">
  969. <div id="topnav" class="topnav">
  970. <div id="topnav-left" class="topnav-left">
  971. <div class="inline-block valignmiddle">
  972. <a class="topnav-terminalhour" onclick="ModalBox('ModalTerminal')">
  973. <span class="fa fa-cash-register"></span>
  974. <span class="hideonsmartphone">
  975. <?php echo getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$_SESSION["takeposterminal"], $langs->trans("TerminalName", $_SESSION["takeposterminal"])); ?>
  976. </span>
  977. <?php
  978. echo '<span class="hideonsmartphone"> - '.dol_print_date(dol_now(), "day").'</span>'; ?>
  979. </a>
  980. <?php
  981. if (isModEnabled('multicurrency')) {
  982. print '<a class="valignmiddle tdoverflowmax100" id="multicurrency" onclick="ModalBox(\'ModalCurrency\')" title=""><span class="fas fa-coins paddingrightonly"></span>';
  983. print '<span class="hideonsmartphone">'.$langs->trans("Currency").'</span>';
  984. print '</a>';
  985. } ?>
  986. </div>
  987. <!-- section for customer -->
  988. <div class="inline-block valignmiddle" id="customerandsales"></div>
  989. <!-- section for shopping carts -->
  990. <div class="inline-block valignmiddle" id="shoppingcart"></div>
  991. <!-- More info about customer -->
  992. <div class="inline-block valignmiddle tdoverflowmax150onsmartphone" id="moreinfo"></div>
  993. <?php
  994. if (isModEnabled('stock')) {
  995. ?>
  996. <!-- More info about warehouse -->
  997. <div class="inline-block valignmiddle tdoverflowmax150onsmartphone" id="infowarehouse"></div>
  998. <?php
  999. } ?>
  1000. </div>
  1001. <div id="topnav-right" class="topnav-right">
  1002. <?php
  1003. $reshook = $hookmanager->executeHooks('takepos_login_block_other');
  1004. if ($reshook == 0) { //Search method
  1005. ?>
  1006. <div class="login_block_other">
  1007. <input type="text" id="search" name="search" class="input-nobottom" onkeyup="Search2('<?php echo dol_escape_js($keyCodeForEnter); ?>', null);" placeholder="<?php echo dol_escape_htmltag($langs->trans("Search")); ?>" autofocus>
  1008. <a onclick="ClearSearch();" class="nohover"><span class="fa fa-backspace"></span></a>
  1009. <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 -->
  1010. <span class="fas fa-home"></span></a>
  1011. <?php if (empty($conf->dol_use_jmobile)) { ?>
  1012. <a class="hideonsmartphone" onclick="FullScreen();" title="<?php echo dol_escape_htmltag($langs->trans("ClickFullScreenEscapeToLeave")); ?>"><span class="fa fa-expand-arrows-alt"></span></a>
  1013. <?php } ?>
  1014. </div>
  1015. <?php
  1016. }
  1017. ?>
  1018. <div class="login_block_user">
  1019. <?php
  1020. print top_menu_user(1);
  1021. ?>
  1022. </div>
  1023. </div>
  1024. <div class="arrows">
  1025. <span class="indicator left"><i class="fa fa-arrow-left"></i></span>
  1026. <span class="indicator right"><i class="fa fa-arrow-right"></i></span>
  1027. </div>
  1028. </div>
  1029. </div>
  1030. <?php
  1031. }
  1032. ?>
  1033. <!-- Modal terminal box -->
  1034. <div id="ModalTerminal" class="modal">
  1035. <div class="modal-content">
  1036. <div class="modal-header">
  1037. <?php
  1038. if (!getDolGlobalString('TAKEPOS_FORCE_TERMINAL_SELECT')) {
  1039. ?>
  1040. <span class="close" href="#" onclick="document.getElementById('ModalTerminal').style.display = 'none';">&times;</span>
  1041. <?php
  1042. } ?>
  1043. <h3><?php print $langs->trans("TerminalSelect"); ?></h3>
  1044. </div>
  1045. <div class="modal-body">
  1046. <button type="button" class="block" onclick="location.href='index.php?setterminal=1'"><?php print getDolGlobalString("TAKEPOS_TERMINAL_NAME_1", $langs->trans("TerminalName", 1)); ?></button>
  1047. <?php
  1048. $nbloop = getDolGlobalInt('TAKEPOS_NUM_TERMINALS');
  1049. for ($i = 2; $i <= $nbloop; $i++) {
  1050. print '<button type="button" class="block" onclick="location.href=\'index.php?setterminal='.$i.'\'">'.getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$i, $langs->trans("TerminalName", $i)).'</button>';
  1051. }
  1052. ?>
  1053. </div>
  1054. </div>
  1055. </div>
  1056. <!-- Modal multicurrency box -->
  1057. <?php if (isModEnabled('multicurrency')) { ?>
  1058. <div id="ModalCurrency" class="modal">
  1059. <div class="modal-content">
  1060. <div class="modal-header">
  1061. <span class="close" href="#" onclick="document.getElementById('ModalCurrency').style.display = 'none';">&times;</span>
  1062. <h3><?php print $langs->trans("SetMultiCurrencyCode"); ?></h3>
  1063. </div>
  1064. <div class="modal-body">
  1065. <?php
  1066. $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'multicurrency';
  1067. $sql .= " WHERE entity IN ('".getEntity('multicurrency')."')";
  1068. $resql = $db->query($sql);
  1069. if ($resql) {
  1070. while ($obj = $db->fetch_object($resql)) {
  1071. print '<button type="button" class="block" onclick="location.href=\'index.php?setcurrency='.$obj->code.'\'">'.$obj->code.'</button>';
  1072. }
  1073. }
  1074. ?>
  1075. </div>
  1076. </div>
  1077. </div>
  1078. <?php } ?>
  1079. <!-- Modal terminal Credit Note -->
  1080. <div id="ModalCreditNote" class="modal">
  1081. <div class="modal-content">
  1082. <div class="modal-header">
  1083. <span class="close" href="#" onclick="document.getElementById('ModalCreditNote').style.display = 'none';">&times;</span>
  1084. <h3><?php print $langs->trans("invoiceAvoirWithLines"); ?></h3>
  1085. </div>
  1086. <div class="modal-body">
  1087. <button type="button" class="block" onclick="CreditNote(); document.getElementById('ModalCreditNote').style.display = 'none';"><?php print $langs->trans("Yes"); ?></button>
  1088. <button type="button" class="block" onclick="document.getElementById('ModalCreditNote').style.display = 'none';"><?php print $langs->trans("No"); ?></button>
  1089. </div>
  1090. </div>
  1091. </div>
  1092. <!-- Modal Note -->
  1093. <div id="ModalNote" class="modal">
  1094. <div class="modal-content">
  1095. <div class="modal-header">
  1096. <span class="close" href="#" onclick="document.getElementById('ModalNote').style.display = 'none';">&times;</span>
  1097. <h3><?php print $langs->trans("Note"); ?></h3>
  1098. </div>
  1099. <div class="modal-body">
  1100. <input type="text" class="block" id="textinput">
  1101. <button type="button" class="block" onclick="SetNote(); document.getElementById('ModalNote').style.display = 'none';">OK</button>
  1102. </div>
  1103. </div>
  1104. </div>
  1105. <div class="row1<?php if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
  1106. print 'withhead';
  1107. } ?>">
  1108. <div id="poslines" class="div1">
  1109. </div>
  1110. <div class="div2">
  1111. <button type="button" class="calcbutton" onclick="Edit(7);">7</button>
  1112. <button type="button" class="calcbutton" onclick="Edit(8);">8</button>
  1113. <button type="button" class="calcbutton" onclick="Edit(9);">9</button>
  1114. <button type="button" id="qty" class="calcbutton2" onclick="Edit('qty')"><?php echo $langs->trans("Qty"); ?></button>
  1115. <button type="button" class="calcbutton" onclick="Edit(4);">4</button>
  1116. <button type="button" class="calcbutton" onclick="Edit(5);">5</button>
  1117. <button type="button" class="calcbutton" onclick="Edit(6);">6</button>
  1118. <button type="button" id="price" class="calcbutton2" onclick="Edit('p')"><?php echo $langs->trans("Price"); ?></button>
  1119. <button type="button" class="calcbutton" onclick="Edit(1);">1</button>
  1120. <button type="button" class="calcbutton" onclick="Edit(2);">2</button>
  1121. <button type="button" class="calcbutton" onclick="Edit(3);">3</button>
  1122. <button type="button" id="reduction" class="calcbutton2" onclick="Edit('r')"><?php echo $langs->trans("LineDiscountShort"); ?></button>
  1123. <button type="button" class="calcbutton" onclick="Edit(0);">0</button>
  1124. <button type="button" class="calcbutton" onclick="Edit('.')">.</button>
  1125. <button type="button" class="calcbutton poscolorblue" onclick="Edit('c')">C</button>
  1126. <button type="button" class="calcbutton2 poscolordelete" id="delete" onclick="deleteline()"><span class="fa fa-trash"></span></button>
  1127. </div>
  1128. <?php
  1129. // TakePOS setup check
  1130. if (isset($_SESSION["takeposterminal"]) && $_SESSION["takeposterminal"]) {
  1131. $sql = "SELECT code, libelle FROM " . MAIN_DB_PREFIX . "c_paiement";
  1132. $sql .= " WHERE entity IN (" . getEntity('c_paiement') . ")";
  1133. $sql .= " AND active = 1";
  1134. $sql .= " ORDER BY libelle";
  1135. $resql = $db->query($sql);
  1136. $paiementsModes = array();
  1137. if ($resql) {
  1138. while ($obj = $db->fetch_object($resql)) {
  1139. $paycode = $obj->code;
  1140. if ($paycode == 'LIQ') {
  1141. $paycode = 'CASH';
  1142. }
  1143. if ($paycode == 'CHQ') {
  1144. $paycode = 'CHEQUE';
  1145. }
  1146. $constantforkey = "CASHDESK_ID_BANKACCOUNT_" . $paycode . $_SESSION["takeposterminal"];
  1147. //var_dump($constantforkey.' '.getDolGlobalInt($constantforkey));
  1148. if (getDolGlobalInt($constantforkey) > 0) {
  1149. array_push($paiementsModes, $obj);
  1150. }
  1151. }
  1152. }
  1153. if (empty($paiementsModes) && isModEnabled("banque")) {
  1154. $langs->load('errors');
  1155. setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("TakePOS")), null, 'errors');
  1156. setEventMessages($langs->trans("ProblemIsInSetupOfTerminal", $_SESSION["takeposterminal"]), null, 'errors');
  1157. }
  1158. }
  1159. if (count($maincategories) == 0) {
  1160. if (getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') > 0) {
  1161. $tmpcategory = new Categorie($db);
  1162. $tmpcategory->fetch($conf->global->TAKEPOS_ROOT_CATEGORY_ID);
  1163. setEventMessages($langs->trans("TakeposNeedsAtLeastOnSubCategoryIntoParentCategory", $tmpcategory->label), null, 'errors');
  1164. } else {
  1165. setEventMessages($langs->trans("TakeposNeedsCategories"), null, 'errors');
  1166. }
  1167. }
  1168. // User menu and external TakePOS modules
  1169. $menus = array();
  1170. $r = 0;
  1171. if (!getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
  1172. $menus[$r++] = array('title'=>'<span class="fa fa-layer-group paddingrightonly"></span><div class="trunc">'.$langs->trans("New").'</div>', 'action'=>'New();');
  1173. } else {
  1174. // BAR RESTAURANT specific menu
  1175. $menus[$r++] = array('title'=>'<span class="fa fa-layer-group paddingrightonly"></span><div class="trunc">'.$langs->trans("Place").'</div>', 'action'=>'Floors();');
  1176. }
  1177. if (getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
  1178. if (getDolGlobalString('TAKEPOS_CHOOSE_CONTACT')) {
  1179. $menus[$r++] = array('title'=>'<span class="far fa-building paddingrightonly"></span><div class="trunc">'.$langs->trans("Contact").'</div>', 'action'=>'Contact();');
  1180. } else {
  1181. $menus[$r++] = array('title'=>'<span class="far fa-building paddingrightonly"></span><div class="trunc">'.$langs->trans("Customer").'</div>', 'action'=>'Customer();');
  1182. }
  1183. }
  1184. if (! getDolGlobalString('TAKEPOS_HIDE_HISTORY')) {
  1185. $menus[$r++] = array('title'=>'<span class="fa fa-history paddingrightonly"></span><div class="trunc">'.$langs->trans("History").'</div>', 'action'=>'History();');
  1186. }
  1187. $menus[$r++] = array('title'=>'<span class="fa fa-cube paddingrightonly"></span><div class="trunc">'.$langs->trans("FreeZone").'</div>', 'action'=>'FreeZone();');
  1188. $menus[$r++] = array('title'=>'<span class="fa fa-percent paddingrightonly"></span><div class="trunc">'.$langs->trans("InvoiceDiscountShort").'</div>', 'action'=>'Reduction();');
  1189. $menus[$r++] = array('title'=>'<span class="far fa-money-bill-alt paddingrightonly"></span><div class="trunc">'.$langs->trans("Payment").'</div>', 'action'=>'CloseBill();');
  1190. if (getDolGlobalString('TAKEPOS_DIRECT_PAYMENT')) {
  1191. $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();');
  1192. }
  1193. $menus[$r++] = array('title'=>'<span class="fas fa-cut paddingrightonly"></span><div class="trunc">'.$langs->trans("SplitSale").'</div>', 'action'=>'Split();');
  1194. // BAR RESTAURANT specific menu
  1195. if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
  1196. if (getDolGlobalString('TAKEPOS_ORDER_PRINTERS')) {
  1197. $menus[$r++] = array('title'=>'<span class="fa fa-blender-phone paddingrightonly"></span><div class="trunc">'.$langs->trans("Order").'</span>', 'action'=>'TakeposPrintingOrder();');
  1198. }
  1199. //Button to print receipt before payment
  1200. if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
  1201. if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") {
  1202. if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
  1203. $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'TakeposConnector(placeid);');
  1204. } else {
  1205. $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'TakeposPrinting(placeid);');
  1206. }
  1207. } elseif ((isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") {
  1208. $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'DolibarrTakeposPrinting(placeid);');
  1209. } else {
  1210. $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'Print(placeid);');
  1211. }
  1212. }
  1213. if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector" && getDolGlobalString('TAKEPOS_ORDER_NOTES') == 1) {
  1214. $menus[$r++] = array('title'=>'<span class="fa fa-sticky-note paddingrightonly"></span><div class="trunc">'.$langs->trans("OrderNotes").'</div>', 'action'=>'TakeposOrderNotes();');
  1215. }
  1216. if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
  1217. $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("ProductSupplements").'</div>', 'action'=>'LoadProducts(\'supplements\');');
  1218. }
  1219. }
  1220. if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") {
  1221. $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("DOL_OPEN_DRAWER").'</div>', 'action'=>'OpenDrawer();');
  1222. }
  1223. if (getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0 || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") {
  1224. $menus[$r++] = array(
  1225. 'title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("DOL_OPEN_DRAWER").'</div>',
  1226. 'action' => 'DolibarrOpenDrawer();',
  1227. );
  1228. }
  1229. $sql = "SELECT rowid, status, entity FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE";
  1230. $sql .= " entity = ".((int) $conf->entity)." AND ";
  1231. $sql .= " posnumber = ".((int) $_SESSION["takeposterminal"])." AND ";
  1232. $sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'";
  1233. $resql = $db->query($sql);
  1234. if ($resql) {
  1235. $num = $db->num_rows($resql);
  1236. if ($num) {
  1237. $obj = $db->fetch_object($resql);
  1238. $menus[$r++] = array('title'=>'<span class="fas fa-file-invoice-dollar paddingrightonly"></span><div class="trunc">'.$langs->trans("CashReport").'</div>', 'action'=>'CashReport('.$obj->rowid.');');
  1239. if ($obj->status == 0) {
  1240. $menus[$r++] = array('title'=>'<span class="fas fa-cash-register paddingrightonly"></span><div class="trunc">'.$langs->trans("CloseCashFence").'</div>', 'action'=>'CloseCashFence('.$obj->rowid.');');
  1241. }
  1242. }
  1243. }
  1244. $parameters = array('menus'=>$menus);
  1245. $reshook = $hookmanager->executeHooks('ActionButtons', $parameters);
  1246. if ($reshook == 0) { //add buttons
  1247. if (is_array($hookmanager->resArray)) {
  1248. foreach ($hookmanager->resArray as $resArray) {
  1249. foreach ($resArray as $butmenu) {
  1250. $menus[$r++] = $butmenu;
  1251. }
  1252. }
  1253. } elseif ($reshook == 1) {
  1254. $r = 0; //replace buttons
  1255. if (is_array($hookmanager->resArray)) {
  1256. foreach ($hookmanager->resArray as $resArray) {
  1257. foreach ($resArray as $butmenu) {
  1258. $menus[$r++] = $butmenu;
  1259. }
  1260. }
  1261. }
  1262. }
  1263. }
  1264. if ($r % 3 == 2) {
  1265. $menus[$r++] = array('title'=>'', 'style'=>'visibility: hidden;');
  1266. }
  1267. if (getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
  1268. $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?token='.newToken().'\';');
  1269. }
  1270. if (getDolGlobalString('TAKEPOS_WEIGHING_SCALE')) {
  1271. $menus[$r++] = array('title'=>'<span class="fa fa-balance-scale paddingrightonly"></span><div class="trunc">'.$langs->trans("WeighingScale").'</div>', 'action'=>'WeighingScale();');
  1272. }
  1273. ?>
  1274. <!-- Show buttons -->
  1275. <div class="div3">
  1276. <?php
  1277. $i = 0;
  1278. foreach ($menus as $menu) {
  1279. $i++;
  1280. if (count($menus) > 12 and $i == 12) {
  1281. echo '<button style="'.(empty($menu['style']) ? '' : $menu['style']).'" type="button" id="actionnext" class="actionbutton" onclick="MoreActions('.count($menus).')">'.$langs->trans("Next").'</button>';
  1282. echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
  1283. } elseif ($i > 12) {
  1284. echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
  1285. } else {
  1286. echo '<button style="'.(empty($menu['style']) ? '' : $menu['style']).'" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
  1287. }
  1288. }
  1289. if (getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
  1290. print '<!-- Show the search input text -->'."\n";
  1291. print '<div class="margintoponly">';
  1292. print '<input type="text" id="search" class="input-nobottom" name="search" onkeyup="Search2(\''.dol_escape_js($keyCodeForEnter).'\', null);" style="width: 80%; width:calc(100% - 51px); font-size: 150%;" placeholder="'.dol_escape_htmltag($langs->trans("Search")).'" autofocus> ';
  1293. print '<a class="marginleftonly hideonsmartphone" onclick="ClearSearch();">'.img_picto('', 'searchclear').'</a>';
  1294. print '</div>';
  1295. }
  1296. ?>
  1297. </div>
  1298. </div>
  1299. <div class="row2<?php if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
  1300. print 'withhead';
  1301. } ?>">
  1302. <!-- Show categories -->
  1303. <?php
  1304. if (getDolGlobalInt('TAKEPOS_HIDE_CATEGORIES') == 1) {
  1305. print '<div class="div4" style= "display: none;">';
  1306. } else {
  1307. print '<div class="div4">';
  1308. }
  1309. $count = 0;
  1310. while ($count < $MAXCATEG) {
  1311. ?>
  1312. <div class="wrapper" <?php if ($count == ($MAXCATEG - 2)) {
  1313. echo 'onclick="MoreCategories(\'less\')"';
  1314. } elseif ($count == ($MAXCATEG - 1)) {
  1315. echo 'onclick="MoreCategories(\'more\')"';
  1316. } else {
  1317. echo 'onclick="LoadProducts('.$count.')"';
  1318. } ?> id="catdiv<?php echo $count; ?>">
  1319. <?php
  1320. if ($count == ($MAXCATEG - 2)) {
  1321. //echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="catimg'.$count.'" />';
  1322. echo '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
  1323. } elseif ($count == ($MAXCATEG - 1)) {
  1324. //echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="catimg'.$count.'" />';
  1325. echo '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
  1326. } else {
  1327. if (!getDolGlobalString('TAKEPOS_HIDE_CATEGORY_IMAGES')) {
  1328. echo '<img class="imgwrapper" id="catimg'.$count.'" />';
  1329. }
  1330. } ?>
  1331. <?php if ($count != $MAXCATEG - 2 && $count != $MAXCATEG - 1) { ?>
  1332. <div class="description" id="catdivdesc<?php echo $count; ?>">
  1333. <div class="description_content" id="catdesc<?php echo $count; ?>"></div>
  1334. </div>
  1335. <?php } ?>
  1336. <div class="catwatermark" id='catwatermark<?php echo $count; ?>'>...</div>
  1337. </div>
  1338. <?php
  1339. $count++;
  1340. }
  1341. ?>
  1342. </div>
  1343. <!-- Show product -->
  1344. <div class="div5<?php if (getDolGlobalInt('TAKEPOS_HIDE_CATEGORIES') == 1) {
  1345. print ' centpercent';
  1346. } ?>">
  1347. <?php
  1348. $count = 0;
  1349. while ($count < $MAXPRODUCT) {
  1350. print '<div class="wrapper2 arrow" id="prodiv'.$count.'" '; ?>
  1351. <?php if ($count == ($MAXPRODUCT - 2)) {
  1352. ?> onclick="MoreProducts('less')" <?php
  1353. }
  1354. if ($count == ($MAXPRODUCT - 1)) {
  1355. ?> onclick="MoreProducts('more')" <?php
  1356. } else {
  1357. echo 'onclick="ClickProduct('.$count.')"';
  1358. } ?>>
  1359. <?php
  1360. if ($count == ($MAXPRODUCT - 2)) {
  1361. //echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="proimg'.$count.'" />';
  1362. print '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
  1363. } elseif ($count == ($MAXPRODUCT - 1)) {
  1364. //echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="proimg'.$count.'" />';
  1365. print '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
  1366. } else {
  1367. if (!getDolGlobalString('TAKEPOS_HIDE_PRODUCT_PRICES')) {
  1368. print '<div class="" id="proprice'.$count.'"></div>';
  1369. }
  1370. if (getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
  1371. print '<button type="button" id="probutton'.$count.'" class="productbutton" style="display: none;"></button>';
  1372. } else {
  1373. print '<img class="imgwrapper" title="" id="proimg'.$count.'">';
  1374. }
  1375. } ?>
  1376. <?php if ($count != $MAXPRODUCT - 2 && $count != $MAXPRODUCT - 1 && !getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) { ?>
  1377. <div class="description" id="prodivdesc<?php echo $count; ?>">
  1378. <div class="description_content" id="prodesc<?php echo $count; ?>"></div>
  1379. </div>
  1380. <?php } ?>
  1381. <div class="catwatermark" id='prowatermark<?php echo $count; ?>'>...</div>
  1382. </div>
  1383. <?php
  1384. $count++;
  1385. }
  1386. ?>
  1387. <input type="hidden" id="search_start_less" value="0">
  1388. <input type="hidden" id="search_start_more" value="0">
  1389. <input type="hidden" id="search_pagination" value="">
  1390. </div>
  1391. </div>
  1392. </div>
  1393. </body>
  1394. <?php
  1395. llxFooter();
  1396. $db->close();