dolibarr 23.0.4
index.php
Go to the documentation of this file.
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 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
29// if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
30// if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
31// if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
32
33if (!defined('NOREQUIREMENU')) {
34 define('NOREQUIREMENU', '1');
35}
36if (!defined('NOREQUIREHTML')) {
37 define('NOREQUIREHTML', '1');
38}
39if (!defined('NOREQUIREAJAX')) {
40 define('NOREQUIREAJAX', '1');
41}
42
43// Load Dolibarr environment
44require '../main.inc.php'; // Load $user and permissions
53require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
54require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
55require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
56require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
57require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
58require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
59require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
60
61
62$langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter", "banks"));
63
64$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant or multiple sales
65$action = GETPOST('action', 'aZ09');
66$setterminal = GETPOSTINT('setterminal');
67$setcurrency = GETPOST('setcurrency', 'aZ09');
68
69$hookmanager->initHooks(array('takeposfrontend'));
70if (empty($_SESSION["takeposterminal"])) {
71 if (getDolGlobalInt('TAKEPOS_NUM_TERMINALS') == 1) {
72 $_SESSION["takeposterminal"] = 1; // Use terminal 1 if there is only 1 terminal
73 } elseif (!empty($_COOKIE["takeposterminal"])) {
74 $_SESSION["takeposterminal"] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE["takeposterminal"]); // Restore takeposterminal from previous session
75 }
76}
77
78if ($setterminal > 0) {
79 $_SESSION["takeposterminal"] = $setterminal;
80 dolSetCookie("takeposterminal", (string) $setterminal, -1); // takeposterminal var in a 1 year cookie
81}
82
83if ($setcurrency != "") {
84 $_SESSION["takeposcustomercurrency"] = $setcurrency;
85 // We will recalculate amount for foreign currency at next call of invoice.php when $_SESSION["takeposcustomercurrency"] differs from invoice->multicurrency_code.
86}
87
88
89$categorie = new Categorie($db);
90
91$maxcategbydefaultforthisdevice = 12;
92$maxproductbydefaultforthisdevice = 24;
93
94$MAXCATEG = getDolGlobalInt('TAKEPOS_NB_MAXCATEG', $maxcategbydefaultforthisdevice);
95$MAXPRODUCT = getDolGlobalInt('TAKEPOS_NB_MAXPRODUCT', $maxproductbydefaultforthisdevice);
96
97$term = empty($_SESSION['takeposterminal']) ? 1 : $_SESSION['takeposterminal'];
98
99$socid = getDolGlobalInt('CASHDESK_ID_THIRDPARTY' . $term);
100
101
102/*
103 $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
104 $soc = new Societe($db);
105 if ($invoice->socid > 0) $soc->fetch($invoice->socid);
106 else $soc->fetch(getDolGlobalInt($constforcompanyid));
107 */
108
109// Security check
110$result = restrictedArea($user, 'takepos', 0, '');
111
112
113
114/*
115 * View
116 */
117
118$form = new Form($db);
119
120$disablejs = 0;
121$disablehead = 0;
122$arrayofjs = array('/takepos/js/jquery.colorbox-min.js'); // TODO It seems we don't need this
123$arrayofcss = array('/takepos/css/pos.css.php', '/takepos/css/colorbox.css');
124
125if (getDolGlobalInt('TAKEPOS_COLOR_THEME') == 1) {
126 $arrayofcss[] = '/takepos/css/colorful.css';
127}
128
129
130// Title
131$title = 'TakePOS - Dolibarr '.DOL_VERSION;
132if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
133 $title = 'TakePOS - ' . getDolGlobalString('MAIN_APPLICATION_TITLE');
134}
135$head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
136<meta name="apple-mobile-web-app-capable" content="yes">
137<meta name="mobile-web-app-capable" content="yes">
138<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
139
140top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
141
142
143$categories = $categorie->get_full_arbo('product', getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID'), 1);
144
145
146// Search root category to know its level
147//$conf->global->TAKEPOS_ROOT_CATEGORY_ID=0;
148$levelofrootcategory = 0;
149if (getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') > 0) {
150 foreach ($categories as $key => $categorycursor) {
151 // @phan-suppress-next-line PhanTypeInvalidDimOffset
152 if ($categorycursor['id'] == getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID')) {
153 $levelofrootcategory = $categorycursor['level'];
154 break;
155 }
156 }
157}
158
159$levelofmaincategories = $levelofrootcategory + 1; // Main categories are categories just under the root categorie of POS products.
160
161$maincategories = array();
162$subcategories = array();
163foreach ($categories as $key => $categorycursor) {
164 if ($categorycursor['level'] == $levelofmaincategories) {
165 $maincategories[$key] = $categorycursor;
166 } elseif ($categorycursor['level'] > $levelofmaincategories) {
167 $subcategories[$key] = $categorycursor; // If category level 2 or 3 or ...
168 }
169}
170
171$maincategories = dol_sort_array($maincategories, 'label');
172$subcategories = dol_sort_array($subcategories, 'label');
173?>
174<?php
175$keyCodeForEnter = '';
176if (!empty($_SESSION['takeposterminal'])) {
177 $keyCodeForEnter = getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) > 0 ? getDolGlobalString('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) : '';
178}
179?>
180
181<body class="bodytakepos" style="overflow: hidden;">
182
183<script>
184var categories = <?php echo json_encode($maincategories); ?>;
185var subcategories = <?php echo json_encode($subcategories); ?>;
186
187var currentcat;
188var pageproducts=0;
189var currentsubcategories=[]; // Subcategories of currentcat, shown before its products in the product grid
190var pagecategories=0;
191var pageactions=0;
192var place="<?php echo $place; ?>";
193var editaction="qty";
194var editnumber="";
195var invoiceid=0;
196var search2_timer=null;
197
198/*
199var app = this;
200app.hasKeyboard = false;
201this.keyboardPress = function() {
202 app.hasKeyboard = true;
203 $(window).unbind("keyup", app.keyboardPress);
204 localStorage.hasKeyboard = true;
205 console.log("has keyboard!")
206}
207$(window).on("keyup", app.keyboardPress)
208if(localStorage.hasKeyboard) {
209 app.hasKeyboard = true;
210 $(window).unbind("keyup", app.keyboardPress);
211 console.log("has keyboard from localStorage")
212}
213*/
214
215function ClearSearch(clearSearchResults) {
216 console.log("ClearSearch");
217 $("#search").val('');
218 $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
219 $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
220 $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
221 <?php if ($conf->browser->layout == 'classic') { ?>
222 setFocusOnSearchField();
223 <?php } ?>
224 if (clearSearchResults) {
225 $("#search").trigger('keyup');
226 }
227}
228
229// 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
230function setFocusOnSearchField() {
231 console.log("Call setFocusOnSearchField in page index.php");
232 <?php if ($conf->browser->layout == 'classic') { ?>
233 console.log("has keyboard from localStorage, so we can force focus on search field");
234 $("#search").focus();
235 <?php } ?>
236}
237
238function PrintCategories(first) {
239 console.log("PrintCategories");
240 for (i = 0; i < <?php echo($MAXCATEG - 2); ?>; i++) {
241 if (typeof (categories[parseInt(i)+parseInt(first)]) == "undefined")
242 {
243 $("#catdivdesc"+i).hide();
244 $("#catdesc"+i).text("");
245 $("#catimg"+i).attr("src","genimg/empty.png");
246 $("#catwatermark"+i).hide();
247 $("#catdiv"+i).attr('class', 'wrapper divempty');
248 continue;
249 }
250 $("#catdivdesc"+i).show();
251 <?php
252 if (getDolGlobalString('TAKEPOS_SHOW_CATEGORY_DESCRIPTION') == 1) { ?>
253 $("#catdesc"+i).html(categories[parseInt(i)+parseInt(first)]['label'].bold() + ' - ' + categories[parseInt(i)+parseInt(first)]['description']);
254 <?php } else { ?>
255 $("#catdesc"+i).text(categories[parseInt(i)+parseInt(first)]['label']);
256 <?php } ?>
257 $("#catimg"+i).attr("src","genimg/index.php?query=cat&id="+categories[parseInt(i)+parseInt(first)]['rowid']);
258 $("#catdiv"+i).data("rowid",categories[parseInt(i)+parseInt(first)]['rowid']);
259 $("#catdiv"+i).attr("data-rowid",categories[parseInt(i)+parseInt(first)]['rowid']);
260 $("#catdiv"+i).attr('class', 'wrapper');
261 $("#catwatermark"+i).show();
262 }
263}
264
265function MoreCategories(moreorless) {
266 console.log("MoreCategories moreorless="+moreorless+" pagecategories="+pagecategories);
267 if (moreorless == "more") {
268 $('#catimg15').animate({opacity: '0.5'}, 1);
269 $('#catimg15').animate({opacity: '1'}, 100);
270 pagecategories=pagecategories+1;
271 }
272 if (moreorless == "less") {
273 $('#catimg14').animate({opacity: '0.5'}, 1);
274 $('#catimg14').animate({opacity: '1'}, 100);
275 if (pagecategories==0) return; //Return if no less pages
276 pagecategories=pagecategories-1;
277 }
278 if (typeof (categories[<?php echo($MAXCATEG - 2); ?> * pagecategories] && moreorless == "more") == "undefined") { // Return if no more pages
279 pagecategories=pagecategories-1;
280 return;
281 }
282
283 for (i = 0; i < <?php echo($MAXCATEG - 2); ?>; i++) {
284 if (typeof (categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]) == "undefined") {
285 // complete with empty record
286 console.log("complete with empty record");
287 $("#catdivdesc"+i).hide();
288 $("#catdesc"+i).text("");
289 $("#catimg"+i).attr("src","genimg/empty.png");
290 $("#catwatermark"+i).hide();
291 continue;
292 }
293 $("#catdivdesc"+i).show();
294 <?php
295 if (getDolGlobalString('TAKEPOS_SHOW_CATEGORY_DESCRIPTION') == 1) { ?>
296 $("#catdesc"+i).html(categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]['label'].bold() + ' - ' + categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]['description']);
297 <?php } else { ?>
298 $("#catdesc"+i).text(categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]['label']);
299 <?php } ?>
300 $("#catimg"+i).attr("src","genimg/index.php?query=cat&id="+categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]['rowid']);
301 $("#catdiv"+i).data("rowid",categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]['rowid']);
302 $("#catdiv"+i).attr("data-rowid",categories[i+(<?php echo($MAXCATEG - 2); ?> * pagecategories)]['rowid']);
303 $("#catwatermark"+i).show();
304 }
305
306 ClearSearch(false);
307}
308
309// Show a subcategory into the tile ishow of the product grid
310function PrintSubCategory(ishow, val) {
311 $("#prodivdesc"+ishow).show();
312 <?php if (getDolGlobalString('TAKEPOS_SHOW_CATEGORY_DESCRIPTION') == 1) { ?>
313 $("#prodesc"+ishow).html(val.label.bold() + ' - ' + val.description);
314 $("#probutton"+ishow).html(val.label);
315 <?php } else { ?>
316 $("#prodesc"+ishow).text(val.label);
317 $("#probutton"+ishow).text(val.label);
318 <?php } ?>
319 $("#probutton"+ishow).show();
320 $("#proprice"+ishow).attr("class", "hidden");
321 $("#proprice"+ishow).html("");
322 $("#proimg"+ishow).attr("src","genimg/index.php?query=cat&id="+val.rowid);
323 $("#prodiv"+ishow).data("rowid",val.rowid);
324 $("#prodiv"+ishow).attr("data-rowid",val.rowid);
325 $("#prodiv"+ishow).data("iscat", 1);
326 $("#prodiv"+ishow).attr("data-iscat", 1);
327 $("#prodiv"+ishow).removeClass("divempty");
328 $("#prowatermark"+ishow).show();
329}
330
331// LoadProducts
332function LoadProducts(position, issubcat) {
333 console.log("LoadProducts position="+position+" issubcat="+issubcat);
334 var maxproduct = <?php echo (int) ($MAXPRODUCT - 2); ?>;
335
336 if (position == "supplements") {
337 currentcat = "supplements";
338
339 if (subcategories.count == 0) {
340 alert("No product found into categories level 2 or more");
341 }
342 } else {
343 $('#catimg'+position).animate({opacity: '0.5'}, 1);
344 $('#catimg'+position).animate({opacity: '1'}, 100);
345 if (issubcat == true) {
346 currentcat = $('#prodiv'+position).data('rowid');
347 } else {
348 console.log('#catdiv'+position);
349 currentcat = $('#catdiv'+position).data('rowid');
350 console.log("currentcat="+currentcat);
351 }
352 }
353 if (currentcat == undefined) {
354 return;
355 }
356 pageproducts=0;
357 ishow=0; //product to show counter
358
359 currentsubcategories = [];
360 if (currentcat != "supplements") {
361 console.log("Loop on each category level 2 or more");
362 jQuery.each(subcategories, function(i, val) {
363 if (currentcat == val.fk_parent) {
364 currentsubcategories.push(val);
365 }
366 });
367 }
368 // Show the first subcategories, the next ones are shown by MoreProducts()
369 while (ishow < currentsubcategories.length && ishow < maxproduct) {
370 PrintSubCategory(ishow, currentsubcategories[ishow]);
371 ishow++;
372 }
373
374 idata=0; //product data counter
375 var limit = 0;
376 if (maxproduct >= 1) {
377 limit = maxproduct - 1;
378 }
379
380 // Get socid
381 let socid = jQuery('#thirdpartyid').val();
382 if ((socid === undefined || socid === "") && parseInt("<?php echo dol_escape_js($socid) ?>") > 0) {
383 socid = parseInt("<?php echo dol_escape_js($socid); ?>");
384 }
385
386 // Only show products for sale (tosell=1)
387 $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&token=<?php echo newToken();?>&thirdpartyid=' + socid + '&category='+currentcat+'&tosell=1&limit='+limit+'&offset=0', function(data) {
388 /* Fill thumbs from ishow to end max of products with products loaded into data array */
389 console.log("Call ajax.php (in LoadProducts) to get Products of category "+currentcat+" then loop on result to fill image thumbs");
390 console.log("Found "+data.length+" record");
391
392 if (data.length == 0 && currentcat == "supplements") {
393 alert("No supplements found into the supplement category. Check the module setup and your product categories.");
394 }
395
396 while (ishow < maxproduct) {
397 console.log("ishow"+ishow+" idata="+idata);
398 console.log(data[idata]);
399
400 if (typeof (data[idata]) == "undefined") {
401 <?php if (!getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
402 echo '$("#prodivdesc"+ishow).hide();';
403 echo '$("#prodesc"+ishow).text("");';
404 echo '$("#proimg"+ishow).attr("title","");';
405 echo '$("#proimg"+ishow).attr("src","genimg/empty.png");';
406 } else {
407 echo '$("#probutton"+ishow).hide();';
408 echo '$("#probutton"+ishow).text("");';
409 }?>
410 $("#proprice"+ishow).attr("class", "hidden");
411 $("#proprice"+ishow).html("");
412
413 $("#prodiv"+ishow).data("rowid","");
414 $("#prodiv"+ishow).attr("data-rowid","");
415
416 $("#prodiv"+ishow).data("iscat","0");
417 $("#prodiv"+ishow).attr("data-iscat","0");
418
419 $("#prodiv"+ishow).attr("class","wrapper2 divempty");
420 } else {
421 <?php
422 $titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[idata]['ref']";
423 $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[idata]['barcode']";
424 ?>
425 var titlestring = <?php echo $titlestring; ?>;
426 <?php if (!getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
427 echo '$("#prodivdesc"+ishow).show();';
428 if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) {
429 echo '$("#prodesc"+ishow).html(data[parseInt(idata)][\'ref\'].bold() + \' - \' + data[parseInt(idata)][\'label\']);';
430 } elseif (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 2) {
431 echo '$("#prodesc"+ishow).html(data[parseInt(idata)][\'ref\'].bold());';
432 } else {
433 echo '$("#prodesc"+ishow).html(data[parseInt(idata)][\'label\']);';
434 }
435 echo '$("#proimg"+ishow).attr("title", titlestring);';
436 echo '$("#proimg"+ishow).attr("src", "genimg/index.php?query=pro&id="+data[idata][\'id\']);';
437 } else {
438 echo '$("#probutton"+ishow).show();';
439 echo '$("#probutton"+ishow).html(data[parseInt(idata)][\'label\']);';
440 }
441 ?>
442 if (data[parseInt(idata)]['price_formated']) {
443 $("#proprice" + ishow).attr("class", "productprice");
444 <?php
445 if (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT')) {
446 ?>
447 $("#proprice" + ishow).html(data[parseInt(idata)]['price_formated']);
448 <?php
449 } else {
450 ?>
451 $("#proprice" + ishow).html(data[parseInt(idata)]['price_ttc_formated']);
452 <?php
453 }
454 ?>
455 }
456 console.log("#prodiv"+ishow+".data(rowid)="+data[idata]['id']);
457
458 $("#prodiv"+ishow).data("rowid", data[idata]['id']);
459 $("#prodiv"+ishow).attr("data-rowid", data[idata]['id']);
460 console.log($('#prodiv4').data('rowid'));
461
462 $("#prodiv"+ishow).data("iscat", 0);
463 $("#prodiv"+ishow).attr("data-iscat", 0);
464
465 $("#prodiv"+ishow).attr("class","wrapper2");
466
467 <?php
468 // Add js from hooks
469 $parameters = array();
470 $parameters['caller'] = 'loadProducts';
471 $hookmanager->executeHooks('completeJSProductDisplay', $parameters);
472 print $hookmanager->resPrint;
473 ?>
474 }
475 $("#prowatermark"+ishow).hide();
476 ishow++; //Next product to show after print data product
477 idata++; //Next data every time
478 }
479 });
480
481 ClearSearch(false);
482}
483
484function MoreProducts(moreorless) {
485 console.log("MoreProducts");
486
487 if ($('#search_pagination').val() != '') {
488 return Search2('<?php echo(isset($keyCodeForEnter) ? $keyCodeForEnter : ''); ?>', moreorless);
489 }
490
491 var maxproduct = <?php echo($MAXPRODUCT - 2); ?>;
492
493 if (moreorless=="more"){
494 $('#proimg31').animate({opacity: '0.5'}, 1);
495 $('#proimg31').animate({opacity: '1'}, 100);
496 pageproducts=pageproducts+1;
497 }
498 if (moreorless=="less"){
499 $('#proimg30').animate({opacity: '0.5'}, 1);
500 $('#proimg30').animate({opacity: '1'}, 100);
501 if (pageproducts==0) return; //Return if no less pages
502 pageproducts=pageproducts-1;
503 }
504
505 ishow=0; //product to show counter
506 idata=0; //product data counter
507 var limit = 0;
508 if (maxproduct >= 1) {
509 limit = maxproduct-1;
510 }
511
512 // The grid shows the subcategories of currentcat first, then its products
513 var first = maxproduct * pageproducts; // Rank of the first tile of the page into the list of subcategories then products
514 var offset = Math.max(0, first - currentsubcategories.length);
515
516 // Get socid
517 let socid = jQuery('#thirdpartyid').val();
518 if ((socid === undefined || socid === "") && parseInt("<?php echo dol_escape_js($socid) ?>") > 0) {
519 socid = parseInt("<?php echo dol_escape_js($socid); ?>");
520 }
521
522 // Only show products for sale (tosell=1)
523 $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&token=<?php echo newToken();?>&thirdpartyid=' + socid + '&category='+currentcat+'&tosell=1&limit='+limit+'&offset='+offset, function(data) {
524 console.log("Call ajax.php (in MoreProducts) to get Products of category "+currentcat);
525
526 if (typeof (data[0]) == "undefined" && first >= currentsubcategories.length && moreorless=="more"){ // Return if no more pages
527 pageproducts=pageproducts-1;
528 return;
529 }
530
531 while (ishow < maxproduct && first + ishow < currentsubcategories.length) {
532 PrintSubCategory(ishow, currentsubcategories[first + ishow]);
533 ishow++;
534 }
535
536 while (ishow < maxproduct) {
537 if (typeof (data[idata]) == "undefined") {
538 $("#prodivdesc"+ishow).hide();
539 $("#prodesc"+ishow).text("");
540 $("#probutton"+ishow).text("");
541 $("#probutton"+ishow).hide();
542 $("#proprice"+ishow).attr("class", "");
543 $("#proprice"+ishow).html("");
544 $("#proimg"+ishow).attr("src","genimg/empty.png");
545 $("#prodiv"+ishow).data("rowid","");
546 $("#prodiv"+ishow).attr("data-rowid","");
547 $("#prodiv"+ishow).data("iscat",0);
548 $("#prodiv"+ishow).attr("data-iscat",0);
549 } else {
550 $("#prodivdesc"+ishow).show();
551 <?php if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) { ?>
552 $("#prodesc"+ishow).html(data[parseInt(idata)]['ref'].bold() + ' - ' + data[parseInt(idata)]['label']);
553 <?php } elseif (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 2) { ?>
554 $("#prodesc"+ishow).html(data[parseInt(idata)]['ref'].bold());
555 <?php } else { ?>
556 $("#prodesc"+ishow).html(data[parseInt(idata)]['label']);
557 <?php } ?>
558 $("#probutton"+ishow).html(data[parseInt(idata)]['label']);
559 $("#probutton"+ishow).show();
560 if (data[parseInt(idata)]['price_formated']) {
561 $("#proprice" + ishow).attr("class", "productprice");
562 <?php
563 if (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT')) {
564 ?>
565 $("#proprice" + ishow).html(data[parseInt(idata)]['price_formated']);
566 <?php
567 } else {
568 ?>
569 $("#proprice" + ishow).html(data[parseInt(idata)]['price_ttc_formated']);
570 <?php
571 }
572 ?>
573 }
574 $("#proimg"+ishow).attr("src","genimg/index.php?query=pro&id="+data[idata]['id']);
575 $("#prodiv"+ishow).data("rowid",data[idata]['id']);
576 $("#prodiv"+ishow).attr("data-rowid",data[idata]['id']);
577 $("#prodiv"+ishow).data("iscat",0);
578 $("#prodiv"+ishow).attr("data-iscat",0);
579 }
580 $("#prowatermark"+ishow).hide();
581 ishow++; //Next product to show after print data product
582 idata++; //Next data every time
583 }
584 });
585
586 ClearSearch(false);
587}
588
589function ClickProduct(position, qty = 1) {
590 console.log("ClickProduct at position"+position);
591 if ($('#invoiceid').val() == "") {
592 invoiceid = $('#invoiceid').val();
593 Refresh();
594 }
595 $('#proimg'+position).animate({opacity: '0.5'}, 1);
596 $('#proimg'+position).animate({opacity: '1'}, 100);
597 if ($('#prodiv'+position).data('iscat') == 1){
598 console.log("Click on a category at position "+position);
599 LoadProducts(position, true);
600 }
601 else{
602 console.log($('#prodiv4').data('rowid'));
603 invoiceid = $("#invoiceid").val();
604 idproduct=$('#prodiv'+position).data('rowid');
605 console.log("Click on product at position "+position+" for idproduct "+idproduct+", qty="+qty+" invoiceid="+invoiceid);
606 if (idproduct == "") {
607 return;
608 }
609 // Call page invoice.php to generate the section with product lines
610 $("#poslines").load("invoice.php?action=addline&token=<?php echo newToken(); ?>&place="+place+"&idproduct="+idproduct+"&selectedline="+selectedline+"&qty="+qty+"&invoiceid="+invoiceid, function() {
611 <?php if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
612 echo "CustomerDisplay();";
613 }?>
614 });
615 }
616
617 ClearSearch(false);
618}
619
620function ChangeThirdparty(idcustomer) {
621 console.log("ChangeThirdparty");
622 // Call page list.php to change customer
623 $("#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() {
624 });
625
626 ClearSearch(false);
627}
628
629function deleteline() {
630 invoiceid = $("#invoiceid").val();
631 console.log("Delete line invoiceid="+invoiceid);
632 $("#poslines").load("invoice.php?action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&invoiceid="+invoiceid, function() {
633 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
634 });
635 ClearSearch(false);
636}
637
638function Customer() {
639 console.log("Open box to select the thirdparty place="+place);
640 $.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"); ?>"});
641}
642
643function Contact() {
644 console.log("Open box to select the contact place="+place);
645 $.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"); ?>"});
646}
647
648function History()
649{
650 console.log("Open box to select the history");
651 $.colorbox({href:"../compta/facture/list.php?contextpage=poslist&search_module_source=takepos", width:"90%", height:"80%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("History"); ?>"});
652}
653
654function Reduction() {
655 invoiceid = $("#invoiceid").val();
656 console.log("Open popup to enter reduction on invoiceid="+invoiceid);
657 $.colorbox({href:"reduction.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
658}
659
660var closeBillParams="";
661function CloseBill() {
662 <?php
663 $parameters = array();
664 $reshook = $hookmanager->executeHooks('paramsForCloseBill', $parameters, $obj, $action);
665 if (getDolGlobalString('TAKEPOS_FORBID_SALES_TO_DEFAULT_CUSTOMER')) {
666 echo "customerAnchorTag = document.querySelector('a[id=\"customer\"]'); ";
667 echo "if (customerAnchorTag && customerAnchorTag.innerText.trim() === '".dol_escape_js($langs->transnoentitiesnoconv("Customer"))."') { ";
668 echo "alert('".dol_escape_js($langs->transnoentitiesnoconv("NoClientErrorMessage"))."'); ";
669 echo "return; } \n";
670 }
671 ?>
672 invoiceid = $("#invoiceid").val();
673 console.log("Open popup to enter payment on invoiceid="+invoiceid);
674 <?php if (getDolGlobalInt("TAKEPOS_NO_GENERIC_THIRDPARTY")) { ?>
675 if ($("#idcustomer").val() == "") {
676 alert("<?php echo dol_escape_js($langs->transnoentitiesnoconv('TakePosCustomerMandatory'), 2); ?>");
677 <?php if (getDolGlobalString('TAKEPOS_CHOOSE_CONTACT')) { ?>
678 Contact();
679 <?php } else { ?>
680 Customer();
681 <?php } ?>
682 return;
683 }
684 <?php } ?>
685 <?php
686 $alternative_payurl = getDolGlobalString('TAKEPOS_ALTERNATIVE_PAYMENT_SCREEN');
687 if (empty($alternative_payurl)) {
688 $payurl = "pay.php";
689 } else {
690 $payurl = dol_buildpath($alternative_payurl, 1);
691 }
692 ?>
693 $.colorbox({href:"<?php echo $payurl; ?>?place="+place+"&invoiceid="+invoiceid+closeBillParams, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
694}
695
696function Split() {
697 invoiceid = $("#invoiceid").val();
698 console.log("Open popup to split on invoiceid="+invoiceid);
699 $.colorbox({href:"split.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
700}
701
702function Floors() {
703 console.log("Open box to select floor place="+place);
704 $.colorbox({href:"floors.php?place="+place, width:"90%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Floors"); ?>"});
705}
706
707function FreeZone() {
708 invoiceid = $("#invoiceid").val();
709 console.log("Open box to enter a free product on invoiceid="+invoiceid);
710 $.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"); ?>"});
711}
712
713function TakeposOrderNotes() {
714 console.log("Open box to order notes");
715 ModalBox('ModalNote');
716 $("#textinput").focus();
717}
718
719function Refresh() {
720 console.log("Refresh by reloading place="+place+" invoiceid="+invoiceid);
721 $("#poslines").load("invoice.php?place="+place+"&invoiceid="+invoiceid, function() {
722 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
723 });
724}
725
726function New() {
727 // If we go here,it means $conf->global->TAKEPOS_BAR_RESTAURANT is not defined
728 invoiceid = $("#invoiceid").val(); // This is a hidden field added by invoice.php
729
730 console.log("New with place = <?php echo $place; ?>, js place="+place+", invoiceid="+invoiceid);
731
732 $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getInvoice&token=<?php echo newToken();?>&id='+invoiceid, function(data) {
733 var r;
734
735 if (parseInt(data['paye']) === 1) {
736 r = true;
737 } else {
738 r = confirm('<?php echo($place > 0 ? $langs->transnoentitiesnoconv("ConfirmDeletionOfThisPOSSale") : $langs->transnoentitiesnoconv("ConfirmDiscardOfThisPOSSale")); ?>');
739 }
740
741 if (r == true) {
742 // Reload section with invoice lines
743 $("#poslines").load("invoice.php?action=delete&token=<?php echo newToken(); ?>&place=" + place, function () {
744 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
745 });
746
747 ClearSearch(false);
748 $("#idcustomer").val("");
749 }
750 });
751}
752
760function Search2(keyCodeForEnter, moreorless) {
761 var eventKeyCode = null;
762
763 if (window.event && window.event.keyCode) {
764 eventKeyCode = window.event.keyCode;
765 }
766 if (eventKeyCode === null && keyCodeForEnter !== '') {
767 // No key code available, exit early if a key code is required
768 return;
769 }
770
771 console.log("Search2 Call ajax search to replace products keyCodeForEnter="+keyCodeForEnter+", eventKeyCode="+eventKeyCode);
772
773 var search_term = $('#search').val();
774 var search_start = 0;
775 var search_limit = <?php echo $MAXPRODUCT - 2; ?>;
776 if (moreorless != null) {
777 search_term = $('#search_pagination').val();
778 search_start = $('#search_start_'+moreorless).val();
779 }
780
781 console.log("search_term="+search_term);
782
783 if (search_term == '') {
784 $("[id^=prowatermark]").html("");
785 $("[id^=prodesc]").text("");
786 $("[id^=probutton]").text("");
787 $("[id^=probutton]").hide();
788 $("[id^=proprice]").attr("class", "hidden");
789 $("[id^=proprice]").html("");
790 $("[id^=proimg]").attr("src", "genimg/empty.png");
791 $("[id^=prodiv]").data("rowid", "");
792 $("[id^=prodiv]").attr("data-rowid", "");
793 return;
794 }
795
796 var search = false;
797 if (keyCodeForEnter == '' || eventKeyCode == keyCodeForEnter) {
798 search = true;
799 }
800
801 if (search === true) {
802 // if a timer has been already started (search2_timer is a global js variable), we cancel it now
803 // we click onto another key, we will restart another timer just after
804 if (search2_timer) {
805 clearTimeout(search2_timer);
806 }
807
808 // temporization time to give time to type
809 search2_timer = setTimeout(function(){
810 pageproducts = 0;
811 jQuery(".wrapper2 .catwatermark").hide();
812 var nbsearchresults = 0;
813
814 // Only show products for sale (tosell=1)
815 let socid = jQuery('#thirdpartyid').val();
816 if ((socid === undefined || socid === "") && parseInt("<?php echo dol_escape_js($socid) ?>") > 0) {
817 socid = parseInt("<?php echo dol_escape_js($socid); ?>");
818 }
819
820 $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&token=<?php echo newToken();?>&search_term=' + search_term + '&thirdpartyid=' + socid + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) {
821 for (i = 0; i < <?php echo($MAXPRODUCT - 2); ?>; i++) { // the last 2 slots are the pager arrows, not product slots
822 if (typeof (data[i]) == "undefined") {
823 $("#prowatermark" + i).html("");
824 $("#prodesc" + i).text("");
825 $("#probutton" + i).text("");
826 $("#probutton" + i).hide();
827 $("#proprice" + i).attr("class", "hidden");
828 $("#proprice" + i).html("");
829 $("#proimg" + i).attr("src", "genimg/empty.png");
830 $("#prodiv" + i).data("rowid", "");
831 $("#prodiv" + i).attr("data-rowid", "");
832 continue;
833 }
834 <?php
835 $titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[i]['ref']";
836 $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[i]['barcode']";
837 ?>
838 var titlestring = <?php echo $titlestring; ?>;
839 <?php if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) { ?>
840 $("#prodesc" + i).html(data[i]['ref'].bold() + ' - ' + data[i]['label']);
841 <?php } elseif (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 2) { ?>
842 $("#prodesc" + i).html(data[i]['ref'].bold());
843 <?php } else { ?>
844 $("#prodesc" + i).html(data[i]['label']);
845 <?php } ?>
846 $("#prodivdesc" + i).show();
847 $("#probutton" + i).html(data[i]['label']);
848 $("#probutton" + i).show();
849 if (data[i]['price_formated']) {
850 $("#proprice" + i).attr("class", "productprice");
851 <?php
852 if (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT')) {
853 ?>
854 $("#proprice" + i).html(data[i]['price_formated']);
855 <?php
856 } else {
857 ?>
858 $("#proprice" + i).html(data[i]['price_ttc_formated']);
859 <?php
860 }
861 ?>
862 }
863 $("#proimg" + i).attr("title", titlestring);
864 if( undefined !== data[i]['img']) {
865 $("#proimg" + i).attr("src", data[i]['img']);
866 }
867 else {
868 $("#proimg" + i).attr("src", "genimg/index.php?query=pro&id=" + data[i]['rowid']);
869 }
870 $("#prodiv" + i).data("rowid", data[i]['rowid']);
871 $("#prodiv" + i).attr("data-rowid", data[i]['rowid']);
872 $("#prodiv" + i).data("iscat", 0);
873 $("#prodiv" + i).attr("data-iscat", 0);
874
875 <?php
876 // Add js from hooks
877 $parameters = array();
878 $parameters['caller'] = 'search2';
879 $hookmanager->executeHooks('completeJSProductDisplay', $parameters);
880 print $hookmanager->resPrint;
881 ?>
882
883 nbsearchresults++;
884 }
885 }).always(function (data) {
886 // If there is only 1 answer
887 if ($('#search').val().length > 0 && data.length == 1) {
888 console.log($('#search').val()+' - '+data[0]['barcode']);
889 if ($('#search').val() == data[0]['barcode'] && 'thirdparty' == data[0]['object']) {
890 console.log("There is only 1 answer with barcode matching the search, so we change the thirdparty "+data[0]['rowid']);
891 ChangeThirdparty(data[0]['rowid']);
892 }
893 else if ('product' == data[0]['object'] && $('#search').val() == data[0]['barcode']) {
894 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']);
895 ClickProduct(0, data[0]['qty']);
896 }
897 }
898 if (eventKeyCode == keyCodeForEnter){
899 if (data.length == 0) {
900 $('#search').val('<?php
901 $langs->load('errors');
902 echo dol_escape_js($langs->transnoentitiesnoconv("ErrorRecordNotFoundShort"));
903 ?> ('+search_term+')');
904 $('#search').select();
905 }
906 else ClearSearch(false);
907 }
908 // memorize search_term and start for pagination
909 $("#search_pagination").val($("#search").val());
910 if (search_start == 0) {
911 $("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").hide();
912 }
913 else {
914 $("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").show();
915 var search_start_less = Math.max(0, parseInt(search_start) - parseInt(<?php echo $MAXPRODUCT - 2;?>));
916 $("#search_start_less").val(search_start_less);
917 }
918 if (nbsearchresults != <?php echo $MAXPRODUCT - 2; ?>) {
919 $("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").hide();
920 }
921 else {
922 $("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").show();
923 var search_start_more = parseInt(search_start) + parseInt(<?php echo $MAXPRODUCT - 2;?>);
924 $("#search_start_more").val(search_start_more);
925 }
926 });
927 }, 500); // 500ms delay
928 }
929
930}
931
932/* Function called on an action into the PAD */
933function Edit(number) {
934 console.log("We click on PAD on key="+number);
935
936 if (typeof(selectedtext) == "undefined") {
937 return; // We click on an action on the number pad but there is no line selected
938 }
939
940 var text=selectedtext+"<br> ";
941
942
943 if (number=='c') {
944 editnumber='';
945 Refresh();
946 $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
947 $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
948 $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
949 return;
950 } else if (number=='qty') {
951 if (editaction=='qty' && editnumber != '') {
952 $("#poslines").load("invoice.php?action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
953 editnumber="";
954 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
955 $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
956 });
957
958 setFocusOnSearchField();
959 return;
960 }
961 else {
962 editaction="qty";
963 }
964 } else if (number=='p') {
965 if (editaction=='p' && editnumber!="") {
966 $("#poslines").load("invoice.php?action=updateprice&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
967 editnumber="";
968 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
969 $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
970 });
971
972 ClearSearch(false);
973 return;
974 }
975 else {
976 editaction="p";
977 }
978 } else if (number=='r') {
979 if (editaction=='r' && editnumber!="") {
980 $("#poslines").load("invoice.php?action=updatereduction&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
981 editnumber="";
982 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
983 $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
984 });
985
986 ClearSearch(false);
987 return;
988 }
989 else {
990 editaction="r";
991 }
992 }
993 else {
994 editnumber=editnumber+number;
995 }
996 if (editaction=='qty'){
997 text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Qty").": "; ?>";
998 $("#qty").html("OK").addClass("clicked");
999 $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
1000 $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
1001 }
1002 if (editaction=='p'){
1003 text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Price").": "; ?>";
1004 $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
1005 $("#price").html("OK").addClass("clicked");
1006 $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
1007 }
1008 if (editaction=='r'){
1009 text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("LineDiscountShort").": "; ?>";
1010 $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
1011 $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
1012 $("#reduction").html("OK").addClass("clicked");
1013 }
1014 $('#'+selectedline).find("td:first").html(text+editnumber);
1015}
1016
1017
1018function TakeposPrintingOrder(){
1019 console.log("TakeposPrintingOrder output invoice to print order");
1020 $("#poslines").load("invoice.php?action=order&token=<?php echo newToken();?>&place="+place, function() {
1021 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
1022 });
1023}
1024
1025function TakeposPrintingTemp(){
1026 console.log("TakeposPrintingTemp");
1027 $("#poslines").load("invoice.php?action=temp&token=<?php echo newToken();?>&place="+place, function() {
1028 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
1029 });
1030}
1031
1032function OpenDrawer(){
1033 console.log("OpenDrawer call ajax url http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>:8111/print");
1034 $.ajax({
1035 type: "POST",
1036 data: { token: 'notrequired' },
1037 <?php
1038 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1039 echo "url: '".getDolGlobalString('TAKEPOS_PRINT_SERVER', 'localhost')."/printer/drawer.php',";
1040 } else {
1041 echo "url: 'http://".getDolGlobalString('TAKEPOS_PRINT_SERVER', 'localhost').":8111/print',";
1042 }
1043 ?>
1044 data: "opendrawer"
1045 });
1046}
1047
1048/* Click on button to open drawer */
1049function DolibarrOpenDrawer() {
1050 console.log("DolibarrOpenDrawer call ajax url /takepos/ajax/ajax.php?action=opendrawer&token=<?php echo newToken();?>&term=<?php print urlencode(empty($_SESSION["takeposterminal"]) ? '' : $_SESSION["takeposterminal"]); ?>");
1051 $.ajax({
1052 type: "GET",
1053 data: { token: '<?php echo currentToken(); ?>' },
1054 url: "<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=opendrawer&token='.newToken().'&term='.urlencode(empty($_SESSION["takeposterminal"]) ? '' : $_SESSION["takeposterminal"]); ?>",
1055 });
1056}
1057
1058function MoreActions(totalactions) {
1059 for (i = 0; i <= totalactions; i++) {
1060 $("#action" + i).toggle();
1061 }
1062 $("#actionnext").toggle();
1063 $("#actionprevious").toggle();
1064}
1065
1066function ControlCashOpening()
1067{
1068 $.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"); ?>"});
1069}
1070
1071function CloseCashFence(rowid)
1072{
1073 $.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"); ?>"});
1074}
1075
1076function CashReport(rowid)
1077{
1078 $.colorbox({href:"../compta/cashcontrol/report.php?id="+rowid+"&contextpage=takepos", width:"60%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("CashReport"); ?>"});
1079}
1080
1081// TakePOS Popup
1082function ModalBox(ModalID)
1083{
1084 var modal = document.getElementById(ModalID);
1085 modal.style.display = "block";
1086}
1087
1088function DirectPayment(){
1089 console.log("DirectPayment");
1090 $("#poslines").load("invoice.php?place="+place+"&action=valid&token=<?php echo newToken(); ?>&pay=LIQ", function() {
1091 $('#invoiceid').val("");
1092 });
1093}
1094
1095function FullScreen() {
1096 document.documentElement.requestFullscreen();
1097}
1098
1099function WeighingScale(){
1100 console.log("Weighing Scale");
1101 $.ajax({
1102 type: "POST",
1103 data: { token: 'notrequired' },
1104 url: '<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>/scale/index.php',
1105 })
1106 .done(function( editnumber ) {
1107 $("#poslines").load("invoice.php?token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
1108 editnumber="";
1109 });
1110 });
1111}
1112
1113$( document ).ready(function() {
1114 PrintCategories(0);
1115 LoadProducts(0);
1116 Refresh();
1117 <?php
1118 // IF NO TERMINAL SELECTED
1119 if (empty($_SESSION["takeposterminal"]) || $_SESSION["takeposterminal"] == "") {
1120 print "ModalBox('ModalTerminal');";
1121 }
1122
1123 if (getDolGlobalString('TAKEPOS_CONTROL_CASH_OPENING')) {
1124 // Look for any cash control fence created today on this terminal, regardless of its status,
1125 // so the auto-open popup only fires on the first cash control of a calendar day. Without this,
1126 // refreshing the browser the same day after closing a fence used to immediately re-fire the
1127 // popup because the closed fences were filtered out by the status check (#38597).
1128 $sql = "SELECT rowid, status FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE";
1129 $sql .= " entity = ".((int) $conf->entity)." AND ";
1130 $sql .= " posnumber = ".((int) $_SESSION["takeposterminal"])." AND ";
1131 $sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'";
1132 $resql = $db->query($sql);
1133 if ($resql) {
1134 $obj = $db->fetch_object($resql);
1135 // If there is no cash control from today open it
1136 if (!isset($obj->rowid) || is_null($obj->rowid)) {
1137 print "ControlCashOpening();";
1138 }
1139 }
1140 }
1141 ?>
1142
1143 /* For Header Scroll */
1144 var elem1 = $("#topnav-left")[0];
1145 var elem2 = $("#topnav-right")[0];
1146 var checkOverflow = function() {
1147 if (scrollBars().horizontal) $("#topnav").addClass("overflow");
1148 else $("#topnav").removeClass("overflow");
1149 }
1150
1151 var scrollBars = function(){
1152 var container= $('#topnav')[0];
1153 return {
1154 vertical:container.scrollHeight > container.clientHeight,
1155 horizontal:container.scrollWidth > container.clientWidth
1156 }
1157 }
1158
1159 $(window).resize(function(){
1160 checkOverflow();
1161 });
1162
1163 let resizeObserver = new ResizeObserver(() => {
1164 checkOverflow();
1165 });
1166 resizeObserver.observe(elem1);
1167 resizeObserver.observe(elem2);
1168 checkOverflow();
1169
1170 var pressTimer = [];
1171 var direction = 1;
1172 var step = 200;
1173
1174 $(".indicator").mousedown(function(){
1175 direction = $(this).hasClass("left") ? -1 : 1;
1176 scrollTo();
1177 pressTimer.push(setInterval(scrollTo, 100));
1178 });
1179
1180 $(".indicator").mouseup(function(){
1181 pressTimer.forEach(clearInterval);
1182 });
1183
1184 $("body").mouseup(function(){
1185 pressTimer.forEach(clearInterval);
1186 console.log("body mouseup");
1187 });
1188
1189 function scrollTo(){
1190 console.log("here");
1191 var pos = $("#topnav").scrollLeft();
1192 document.getElementById("topnav").scrollTo({ left: $("#topnav").scrollLeft() + direction * step, behavior: 'smooth' })
1193 }
1194
1195 $("#topnav").scroll(function(){
1196 if (($("#topnav").offsetWidth + $("#topnav").scrollLeft >= $("#topnav").scrollWidth)) {
1197 console.log("end");
1198 }
1199 });
1200 /* End Header Scroll */
1201});
1202</script>
1203
1204<div class="container">
1205
1206<?php
1207if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
1208 ?>
1209 <div class="header">
1210 <div id="topnav" class="topnav">
1211 <div id="topnav-left" class="topnav-left">
1212 <div class="inline-block valignmiddle">
1213 <a class="topnav-terminalhour" onclick="ModalBox('ModalTerminal')">
1214 <span class="fa fa-cash-register"></span>
1215 <span class="hideonsmartphone">
1216 <?php
1217 if (!empty($_SESSION["takeposterminal"])) {
1218 echo getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$_SESSION["takeposterminal"], $langs->trans("TerminalName", $_SESSION["takeposterminal"]));
1219 }
1220 ?>
1221 </span>
1222 <?php
1223 echo '<span class="hideonsmartphone"> - '.dol_print_date(dol_now(), "day").'</span>'; ?>
1224 </a>
1225 <?php
1226 if (isModEnabled('multicurrency')) {
1227 print '<a class="valignmiddle tdoverflowmax100" id="multicurrency" onclick="ModalBox(\'ModalCurrency\')" title=""><span class="fas fa-coins paddingrightonly"></span>';
1228 print '<span class="hideonsmartphone">'.$langs->trans("Currency").'</span>';
1229 print '</a>';
1230 } ?>
1231 </div>
1232 <!-- section for customer -->
1233 <div class="inline-block valignmiddle" id="customerandsales"></div>
1234 <input type="hidden" id="idcustomer" value="">
1235 <!-- section for shopping carts -->
1236 <div class="inline-block valignmiddle" id="shoppingcart"></div>
1237 <!-- More info about customer -->
1238 <div class="inline-block valignmiddle tdoverflowmax150onsmartphone" id="moreinfo"></div>
1239 <?php
1240 if (isModEnabled('stock')) {
1241 ?>
1242 <!-- More info about warehouse -->
1243 <div class="inline-block valignmiddle tdoverflowmax150onsmartphone" id="infowarehouse"></div>
1244 <?php
1245 } ?>
1246 </div>
1247 <div id="topnav-right" class="topnav-right">
1248 <?php
1249 $reshook = $hookmanager->executeHooks('takepos_login_block_other');
1250 if ($reshook == 0) { //Search method
1251 ?>
1252 <div class="login_block_other takepos">
1253 <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>
1254 <a onclick="ClearSearch(false);" class="nohover"><span class="fa fa-backspace"></span></a>
1255 <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 -->
1256 <span class="fas fa-home"></span></a>
1257 <?php if (empty($conf->dol_use_jmobile)) { ?>
1258 <a class="hideonsmartphone" onclick="FullScreen();" title="<?php echo dol_escape_htmltag($langs->trans("ClickFullScreenEscapeToLeave")); ?>"><span class="fa fa-expand-arrows-alt"></span></a>
1259 <?php } ?>
1260 </div>
1261 <?php
1262 }
1263 ?>
1264 <div class="login_block_user">
1265 <?php
1266 print top_menu_user(1, DOL_URL_ROOT.'/user/logout.php?token='.newToken().'&urlfrom='.urlencode('/takepos/?setterminal='.((int) $term)));
1267 ?>
1268 </div>
1269 </div>
1270 <div class="arrows">
1271 <span class="indicator left"><i class="fa fa-arrow-left"></i></span>
1272 <span class="indicator right"><i class="fa fa-arrow-right"></i></span>
1273 </div>
1274 </div>
1275 </div>
1276 <?php
1277}
1278?>
1279
1280<!-- Modal terminal box -->
1281<div id="ModalTerminal" class="modal">
1282 <div class="modal-content">
1283 <div class="modal-header">
1284 <?php
1285 if (!getDolGlobalString('TAKEPOS_FORCE_TERMINAL_SELECT')) {
1286 ?>
1287 <span class="close" href="#" onclick="document.getElementById('ModalTerminal').style.display = 'none';">&times;</span>
1288 <?php
1289 } ?>
1290 <h3><?php print $langs->trans("TerminalSelect"); ?></h3>
1291 </div>
1292 <div class="modal-body">
1293 <button type="button" class="block" onclick="location.href='index.php?setterminal=1'"><?php print getDolGlobalString("TAKEPOS_TERMINAL_NAME_1", $langs->trans("TerminalName", 1)); ?></button>
1294 <?php
1295 $nbloop = getDolGlobalInt('TAKEPOS_NUM_TERMINALS');
1296 for ($i = 2; $i <= $nbloop; $i++) {
1297 print '<button type="button" class="block" onclick="location.href=\'index.php?setterminal='.$i.'\'">'.getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$i, $langs->trans("TerminalName", $i)).'</button>';
1298 }
1299 ?>
1300 </div>
1301</div>
1302</div>
1303
1304<!-- Modal multicurrency box -->
1305<?php if (isModEnabled('multicurrency')) { ?>
1306<div id="ModalCurrency" class="modal">
1307 <div class="modal-content">
1308 <div class="modal-header">
1309 <span class="close" href="#" onclick="document.getElementById('ModalCurrency').style.display = 'none';">&times;</span>
1310 <h3><?php print $langs->trans("SetMultiCurrencyCode"); ?></h3>
1311 </div>
1312 <div class="modal-body">
1313 <?php
1314 $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'multicurrency';
1315 $sql .= " WHERE entity IN ('".getEntity('multicurrency')."')";
1316 $resql = $db->query($sql);
1317 if ($resql) {
1318 while ($obj = $db->fetch_object($resql)) {
1319 print '<button type="button" class="block" onclick="location.href=\'index.php?setcurrency='.$obj->code.'\'">'.$obj->code.'</button>';
1320 }
1321 }
1322 ?>
1323 </div>
1324 </div>
1325</div>
1326<?php } ?>
1327
1328<!-- Modal terminal Credit Note -->
1329<div id="ModalCreditNote" class="modal">
1330 <div class="modal-content">
1331 <div class="modal-header">
1332 <span class="close" href="#" onclick="document.getElementById('ModalCreditNote').style.display = 'none';">&times;</span>
1333 <h3><?php print $langs->trans("invoiceAvoirWithLines"); ?></h3>
1334 </div>
1335 <div class="modal-body">
1336 <button type="button" class="block" onclick="CreditNote(); document.getElementById('ModalCreditNote').style.display = 'none';"><?php print $langs->trans("Yes"); ?></button>
1337 <button type="button" class="block" onclick="document.getElementById('ModalCreditNote').style.display = 'none';"><?php print $langs->trans("No"); ?></button>
1338 </div>
1339</div>
1340</div>
1341
1342<!-- Modal Note -->
1343<div id="ModalNote" class="modal">
1344 <div class="modal-content">
1345 <div class="modal-header">
1346 <span class="close" href="#" onclick="document.getElementById('ModalNote').style.display = 'none';">&times;</span>
1347 <h3><?php print $langs->trans("Note"); ?></h3>
1348 </div>
1349 <div class="modal-body">
1350 <input type="text" class="block" id="textinput">
1351 <button type="button" class="block" onclick="SetNote(); document.getElementById('ModalNote').style.display = 'none';">OK</button>
1352 </div>
1353</div>
1354</div>
1355
1356 <div class="row1<?php if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
1357 print 'withhead';
1358 } ?>">
1359
1360 <div id="poslines" class="div1">
1361 </div>
1362
1363 <div class="div2">
1364 <button type="button" class="calcbutton" onclick="Edit(7);">7</button>
1365 <button type="button" class="calcbutton" onclick="Edit(8);">8</button>
1366 <button type="button" class="calcbutton" onclick="Edit(9);">9</button>
1367 <button type="button" id="qty" class="calcbutton2" onclick="Edit('qty')"><?php echo $langs->trans("Qty"); ?></button>
1368 <button type="button" class="calcbutton" onclick="Edit(4);">4</button>
1369 <button type="button" class="calcbutton" onclick="Edit(5);">5</button>
1370 <button type="button" class="calcbutton" onclick="Edit(6);">6</button>
1371 <button type="button" id="price" class="calcbutton2" onclick="Edit('p')"><?php echo $langs->trans("Price"); ?></button>
1372 <button type="button" class="calcbutton" onclick="Edit(1);">1</button>
1373 <button type="button" class="calcbutton" onclick="Edit(2);">2</button>
1374 <button type="button" class="calcbutton" onclick="Edit(3);">3</button>
1375 <button type="button" id="reduction" class="calcbutton2" onclick="Edit('r')"><?php echo $langs->trans("LineDiscountShort"); ?></button>
1376 <button type="button" class="calcbutton" onclick="Edit(0);">0</button>
1377 <button type="button" class="calcbutton" onclick="Edit('.')">.</button>
1378 <button type="button" class="calcbutton poscolorblue" onclick="Edit('c')">C</button>
1379 <?php if ($user->hasRight('takepos', 'editlines')) { ?>
1380 <button type="button" class="calcbutton2 poscolordelete" id="delete" onclick="deleteline()"><span class="fa fa-trash"></span></button>
1381 <?php } ?>
1382 </div>
1383
1384<?php
1385
1386// Dependency modulecheck
1387if (!isModEnabled('invoice')) {
1388 setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Invoice")), null, 'errors');
1389}
1390
1391// TakePOS setup check
1392if (isset($_SESSION["takeposterminal"]) && $_SESSION["takeposterminal"]) {
1393 $sql = "SELECT code, libelle FROM " . MAIN_DB_PREFIX . "c_paiement";
1394 $sql .= " WHERE entity IN (" . getEntity('c_paiement') . ")";
1395 $sql .= " AND active = 1";
1396 $sql .= " ORDER BY libelle";
1397
1398 $resql = $db->query($sql);
1399 $paiementsModes = array();
1400 if ($resql) {
1401 while ($obj = $db->fetch_object($resql)) {
1402 $paycode = $obj->code;
1403 if ($paycode == 'LIQ') {
1404 $paycode = 'CASH';
1405 }
1406 if ($paycode == 'CHQ') {
1407 $paycode = 'CHEQUE';
1408 }
1409
1410 $constantforkey = "CASHDESK_ID_BANKACCOUNT_" . $paycode . $_SESSION["takeposterminal"];
1411 //var_dump($constantforkey.' '.getDolGlobalInt($constantforkey));
1412 if (getDolGlobalInt($constantforkey) > 0) {
1413 array_push($paiementsModes, $obj);
1414 }
1415 }
1416 }
1417
1418 if (empty($paiementsModes) && isModEnabled("bank")) {
1419 $langs->load('errors');
1420 setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("TakePOS")), null, 'errors');
1421 setEventMessages($langs->trans("ProblemIsInSetupOfTerminal", $_SESSION["takeposterminal"]), null, 'errors');
1422 }
1423}
1424
1425if (count($maincategories) == 0) {
1426 if (getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') > 0) {
1427 $tmpcategory = new Categorie($db);
1428 $tmpcategory->fetch(getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID'));
1429 setEventMessages($langs->trans("TakeposNeedsAtLeastOnSubCategoryIntoParentCategory", $tmpcategory->label), null, 'errors');
1430 } else {
1431 setEventMessages($langs->trans("TakeposNeedsCategories"), null, 'errors');
1432 }
1433}
1434// User menu and external TakePOS modules
1435$menus = array();
1436$r = 0;
1437
1438if (! getDolGlobalString('TAKEPOS_HIDE_HISTORY')) {
1439 $menus[$r++] = array('title' => '<span class="fa fa-history paddingrightonly"></span><div class="trunc">'.$langs->trans("History").'</div>', 'action' => 'History();');
1440}
1441
1442if (getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
1443 if (getDolGlobalString('TAKEPOS_CHOOSE_CONTACT')) {
1444 $menus[$r++] = array('title' => '<span class="far fa-building paddingrightonly"></span><div class="trunc">'.$langs->trans("Contact").'</div>', 'action' => 'Contact();');
1445 } else {
1446 $menus[$r++] = array('title' => '<span class="far fa-building paddingrightonly"></span><div class="trunc">'.$langs->trans("Customer").'</div>', 'action' => 'Customer();');
1447 }
1448}
1449
1450if (!getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
1451 $menus[$r++] = array('title' => '<span class="fa fa-layer-group paddingrightonly"></span><div class="trunc">'.$langs->trans("New").'</div>', 'action' => 'New();');
1452} else {
1453 // BAR RESTAURANT specific menu
1454 $menus[$r++] = array('title' => '<span class="fa fa-layer-group paddingrightonly"></span><div class="trunc">'.$langs->trans("Place").'</div>', 'action' => 'Floors();');
1455}
1456
1457// Add a non predefined product
1458$menus[$r++] = array('title' => '<span class="fa fa-cube paddingrightonly"></span><div class="trunc">'.$langs->trans("FreeZone").'</div>', 'action' => 'FreeZone();');
1459
1460// BAR RESTAURANT specific menu "Print on kitchen/order printer"
1461if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
1462 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
1463 $menus[$r++] = array('title' => '<span class="fa fa-cube paddingrightonly"></span><div class="trunc">'.$langs->trans("ProductSupplements").'</div>', 'action' => 'LoadProducts(\'supplements\');');
1464 }
1465
1466 if (getDolGlobalString('TAKEPOS_ORDER_PRINTERS')) {
1467 $menus[$r++] = array('title' => '<span class="fa fa-blender-phone paddingrightonly"></span><div class="trunc">'.$langs->trans("SentOrderToKitchen").'</span>', 'action' => 'TakeposPrintingOrder();');
1468 }
1469}
1470
1471// Add a discount
1472$menus[$r++] = array('title' => '<span class="fa fa-percent paddingrightonly"></span><div class="trunc">'.$langs->trans("InvoiceDiscountShort").'</div>', 'action' => 'Reduction();');
1473
1474if (!getDolGlobalString('TAKEPOS_NO_SPLIT_SALE')) {
1475 $menus[$r++] = array('title' => '<span class="fas fa-cut paddingrightonly"></span><div class="trunc">'.$langs->trans("SplitSale").'</div>', 'action' => 'Split();');
1476}
1477
1478// Last action that close the sell (payments)
1479$menus[$r++] = array('title' => '<span class="far fa-money-bill-alt paddingrightonly"></span><div class="trunc">'.$langs->trans("Payment").'</div>', 'action' => 'CloseBill();');
1480if (getDolGlobalString('TAKEPOS_DIRECT_PAYMENT')) {
1481 $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();');
1482}
1483
1484$customprinterallowed = false;
1485
1486// BAR RESTAURANT specific menu
1487if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
1488 // Button to print receipt before payment
1489 $customprinterallowed = true;
1490 $customprinttemplateallowed = true;
1491 include_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php';
1492 if (isALNERunningVersion()) { // No need to show this option because it has no effect when isALNERunningVersion is true.
1493 $customprinttemplateallowed = false; // Custom printer may be allowed if mandatory information in template are guaranteed. For the moment, we prefer not allow this.
1494 }
1495}
1496
1497// Button to print receipt
1498if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") { // deprecated method
1499 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var(getDolGlobalString('TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) == true) {
1500 $menus[$r++] = array('title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("PrintTicket").'</div>', 'action' => 'TakeposConnector(placeid);');
1501 } else {
1502 $menus[$r++] = array('title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("PrintTicket").'</div>', 'action' => 'TakeposPrinting(placeid);');
1503 }
1504} elseif ($customprinterallowed && (isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") { // @phpstan-ignore-line
1505 // Button Print Receipt on special printer
1506 $nameOfPrinter = dol_getIdFromCode($db, getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term), 'printer_receipt', 'rowid', 'name', 1);
1507 $menus[$r++] = array('title' => '<div title="'.dolPrintHTMLForAttribute($langs->trans("PrintOn", $nameOfPrinter)).'"><span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("PrintTicket").'</div></div>', 'action' => 'DolibarrTakeposPrinting(placeid);');
1508} else {
1509 // Button Print Receipt on browser
1510 $menus[$r++] = array('title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("PrintTicket").'</div>', 'action' => 'Print(placeid);');
1511}
1512
1513if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector" && getDolGlobalString('TAKEPOS_ORDER_NOTES') == 1) {
1514 $menus[$r++] = array('title' => '<span class="fa fa-sticky-note paddingrightonly"></span><div class="trunc">'.$langs->trans("OrderNotes").'</div>', 'action' => 'TakeposOrderNotes();');
1515}
1516
1517
1518if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") {
1519 $menus[$r++] = array('title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("DOL_OPEN_DRAWER").'</div>', 'action' => 'OpenDrawer();');
1520}
1521if (getDolGlobalInt('TAKEPOS_ADD_BUTTON_OPEN_DRAWER'.$term) > 0) {
1522 $menus[$r++] = array(
1523 'title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("DOL_OPEN_DRAWER").'</div>',
1524 'action' => 'DolibarrOpenDrawer();',
1525 );
1526}
1527
1528$sql = "SELECT rowid, status, entity FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE";
1529$sql .= " entity = ".((int) $conf->entity)." AND ";
1530$sql .= " posnumber = ".((int) empty($_SESSION["takeposterminal"]) ? 0 : $_SESSION["takeposterminal"])." AND ";
1531$sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'";
1532$sql .= " AND status = 0";
1533
1534$resql = $db->query($sql);
1535if ($resql) {
1536 $num = $db->num_rows($resql);
1537 if ($num) {
1538 $obj = $db->fetch_object($resql);
1539 $menus[$r++] = array('title' => '<span class="fas fa-file-invoice-dollar paddingrightonly"></span><div class="trunc">'.$langs->trans("CashReport").'</div>', 'action' => 'CashReport('.$obj->rowid.');');
1540 if ($obj->status == 0) {
1541 $menus[$r++] = array('title' => '<span class="fas fa-cash-register paddingrightonly"></span><div class="trunc">'.$langs->trans("CloseCashFence").'</div>', 'action' => 'CloseCashFence('.$obj->rowid.');');
1542 }
1543 }
1544}
1545
1546if (getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
1547 $menus[$r++] = array('title' => '<span class="fa fa-sign-out-alt pictofixedwidth"></span><div class="trunc">'.$langs->trans("Logout").'</div>', 'action' => 'window.location.href=\''.DOL_URL_ROOT.'/user/logout.php?token='.newToken().'\';');
1548}
1549
1550if (getDolGlobalString('TAKEPOS_WEIGHING_SCALE')) {
1551 $menus[$r++] = array('title' => '<span class="fa fa-balance-scale pictofixedwidth"></span><div class="trunc">'.$langs->trans("WeighingScale").'</div>', 'action' => 'WeighingScale();');
1552}
1553
1554$parameters = array('menus' => $menus);
1555$reshook = $hookmanager->executeHooks('ActionButtons', $parameters);
1556if ($reshook == 0) { //add buttons
1557 if (is_array($hookmanager->resArray)) {
1558 foreach ($hookmanager->resArray as $resArray) {
1559 foreach ($resArray as $butmenu) {
1560 $menus[$r++] = $butmenu;
1561 }
1562 }
1563 }
1564} elseif ($reshook == 1) {
1565 $r = 0; //replace buttons
1566 if (is_array($hookmanager->resArray) ) {
1567 foreach ($hookmanager->resArray as $resArray) {
1568 foreach ($resArray as $butmenu) {
1569 $menus[$r++] = $butmenu;
1570 }
1571 }
1572 }
1573}
1574
1575?>
1576 <!-- Show buttons -->
1577 <div id="dialogforpopuptakepos"></div>
1578 <style>
1579 /* Style de la popup */
1580 #dialogforpopuptakepos {
1581 display: none;
1582 position: fixed;
1583 top: 20px;
1584 right: 20px;
1585 background: #333;
1586 color: #fff;
1587 padding: 15px 20px;
1588 border-radius: 8px;
1589 box-shadow: 0 0 10px rgba(0,0,0,0.3);
1590 z-index: 1000;
1591 font-family: sans-serif;
1592 }
1593 </style>
1594
1595 <div class="div3">
1596 <?php
1597 $i = 0;
1598 foreach ($menus as $menu) {
1599 $i++;
1600 if (count($menus) > 12 and $i == 12) {
1601 echo '<button style="'.(empty($menu['style']) ? '' : $menu['style']).'" type="button" id="actionnext" class="actionbutton" onclick="MoreActions('.count($menus).')">'.$langs->trans("Next").'</button>';
1602 echo '<button style="display: none;" type="button" id="actionprevious" class="actionbutton" onclick="MoreActions('.count($menus).')">'.$langs->trans("Previous").'</button>';
1603 echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
1604 } elseif ($i > 12) {
1605 echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
1606 // TODO keep style but hide button
1607 } else {
1608 echo '<button style="'.(empty($menu['style']) ? '' : $menu['style']).'" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
1609 }
1610 }
1611
1612 if (getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR') && !getDolGlobalString('TAKEPOS_HIDE_SEARCH')) {
1613 print '<!-- Show the search input text -->'."\n";
1614 print '<div class="margintoponly">';
1615 print '<input type="text" id="search" class="input-search-takepos 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> ';
1616 print '<a class="marginleftonly hideonsmartphone" onclick="ClearSearch(false);">'.img_picto('', 'searchclear.png').'</a>';
1617 print '</div>';
1618 }
1619 ?>
1620 </div>
1621 </div>
1622
1623 <div class="row2<?php if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
1624 print 'withhead';
1625 } ?>">
1626
1627 <!-- Show categories -->
1628 <?php
1629 if (getDolGlobalInt('TAKEPOS_HIDE_CATEGORIES') == 1) {
1630 print '<div class="div4" style= "display: none;">';
1631 } else {
1632 print '<div class="div4">';
1633 }
1634
1635 $count = 0;
1636 while ($count < $MAXCATEG) {
1637 ?>
1638 <div class="wrapper" <?php if ($count == ($MAXCATEG - 2)) {
1639 echo 'onclick="MoreCategories(\'less\')"';
1640 } elseif ($count == ($MAXCATEG - 1)) {
1641 echo 'onclick="MoreCategories(\'more\')"';
1642 } else {
1643 echo 'onclick="LoadProducts('.$count.')"';
1644 } ?> id="catdiv<?php echo $count; ?>">
1645 <?php
1646 if ($count == ($MAXCATEG - 2)) {
1647 //echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="catimg'.$count.'" />';
1648 echo '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1649 } elseif ($count == ($MAXCATEG - 1)) {
1650 //echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="catimg'.$count.'" />';
1651 echo '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1652 } else {
1653 if (!getDolGlobalString('TAKEPOS_HIDE_CATEGORY_IMAGES')) {
1654 echo '<img class="imgwrapper" id="catimg'.$count.'" />';
1655 }
1656 } ?>
1657 <?php if ($count != $MAXCATEG - 2 && $count != $MAXCATEG - 1) { ?>
1658 <div class="description" id="catdivdesc<?php echo $count; ?>">
1659 <div class="description_content" id="catdesc<?php echo $count; ?>"></div>
1660 </div>
1661 <?php } ?>
1662 <div class="catwatermark" id='catwatermark<?php echo $count; ?>'>...</div>
1663 </div>
1664 <?php
1665 $count++;
1666 }
1667 ?>
1668 </div>
1669
1670 <!-- Show product -->
1671 <div class="div5<?php if (getDolGlobalInt('TAKEPOS_HIDE_CATEGORIES') == 1) {
1672 print ' centpercent';
1673 } ?>">
1674 <?php
1675 $count = 0;
1676
1677 while ($count < $MAXPRODUCT) {
1678 print '<div class="wrapper2'.(($count >= ($MAXPRODUCT - 2)) ? ' arrow' : '').'" id="prodiv'.$count.'" '; ?>
1679 <?php if ($count == ($MAXPRODUCT - 2)) {
1680 ?> onclick="MoreProducts('less')" <?php
1681 }
1682 if ($count == ($MAXPRODUCT - 1)) {
1683 ?> onclick="MoreProducts('more')" <?php
1684 } else {
1685 echo 'onclick="ClickProduct('.((int) $count).')"';
1686 } ?>>
1687 <?php
1688 if ($count == ($MAXPRODUCT - 2)) {
1689 //echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="proimg'.$count.'" />';
1690 print '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1691 } elseif ($count == ($MAXPRODUCT - 1)) {
1692 //echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="proimg'.$count.'" />';
1693 print '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1694 } else {
1695 if (!getDolGlobalString('TAKEPOS_HIDE_PRODUCT_PRICES')) {
1696 print '<div class="" id="proprice'.$count.'"></div>';
1697 }
1698 if (getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
1699 print '<button type="button" id="probutton'.$count.'" class="productbutton" style="display: none;"></button>';
1700 } else {
1701 print '<img class="imgwrapper" title="" id="proimg'.$count.'">';
1702 }
1703 } ?>
1704 <?php if ($count != $MAXPRODUCT - 2 && $count != $MAXPRODUCT - 1 && !getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) { ?>
1705 <div class="description" id="prodivdesc<?php echo $count; ?>">
1706 <div class="description_content" id="prodesc<?php echo $count; ?>"></div>
1707 </div>
1708 <?php } ?>
1709 <div class="catwatermark" id='prowatermark<?php echo $count; ?>'>...</div>
1710 </div>
1711 <?php
1712 $count++;
1713 }
1714 ?>
1715 <input type="hidden" id="search_start_less" value="0">
1716 <input type="hidden" id="search_start_more" value="0">
1717 <input type="hidden" id="search_pagination" value="">
1718 </div>
1719 </div>
1720</div>
1721</body>
1722<?php
1723
1724llxFooter();
1725
1726$db->close();
while( $i< min( $num, $limit))
The main.inc.php has been included so the following variable are now defined:
Definition export.php:1222
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
print $object position
Definition edit.php:207
Class to manage categories.
Class to manage contact/addresses.
Class to manage generation of HTML components Only common components must be here.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
Definition date.lib.php:678
dol_now($mode='gmt')
Return date for now.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolSetCookie(string $cookiename, string $cookievalue, int $expire=-1)
Set a cookie.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
editval_textarea active
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
top_menu_user($hideloginname=0, $urllogout='')
Build the tooltip on user login.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:132
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:135
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.