index.php 60 KB

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