dolibarr 24.0.3
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-2026 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"] = (int) $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 currentToken();?>&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 currentToken();?>&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, qty_std = 0) {
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 invoiceid = $("#invoiceid").val();
603 idproduct=$('#prodiv'+position).data('rowid');
604 console.log("Click on product at position "+position+" for idproduct "+idproduct+", qty="+qty+" invoiceid="+invoiceid);
605 if (idproduct == "") {
606 return;
607 }
608
609 addInvoiceLine = function(qty, qty_std_inner = 0) {
610 // Call page invoice.php to generate the section with product lines
611 $("#poslines").load("invoice.php?action=addline&token=<?php echo currentToken(); ?>&place="+place+"&idproduct="+idproduct+"&selectedline="+selectedline+"&qty="+qty+"&invoiceid="+invoiceid+(qty_std_inner ? '&qty_std=1' : ''), function() {
612 idproduct = "";
613 <?php if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
614 echo "CustomerDisplay();";
615 }?>
616 });
617 };
618
619 // call WeighingScale() if product is a product that need to measure weight
620 <?php if (getDolGlobalString('TAKEPOS_WEIGHING_SCALE')) { ?>
621 if ($('#prodiv'+position).data('unit') == 2) {
622 WeighingScale(addInvoiceLine);
623 } else {
624 addInvoiceLine(qty, qty_std);
625 }
626 <?php } else { ?>
627 addInvoiceLine(qty, qty_std);
628 <?php } ?>
629 }
630
631 ClearSearch(false);
632}
633
634function ChangeThirdparty(idcustomer) {
635 console.log("ChangeThirdparty");
636 // Call page list.php to change customer
637 $("#poslines").load("<?php echo DOL_URL_ROOT ?>/societe/list.php?action=change&token=<?php echo currentToken();?>&type=t&contextpage=poslist&idcustomer="+idcustomer+"&place="+place+"", function() {
638 });
639
640 ClearSearch(false);
641}
642
643function deleteline() {
644 invoiceid = $("#invoiceid").val();
645 console.log("Delete line invoiceid="+invoiceid);
646 $("#poslines").load("invoice.php?action=deleteline&token=<?php echo currentToken(); ?>&place="+place+"&idline="+selectedline+"&invoiceid="+invoiceid, function() {
647 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
648 });
649 ClearSearch(false);
650}
651
652function Customer() {
653 console.log("Open box to select the thirdparty place="+place);
654 $.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"); ?>"});
655}
656
657function Contact() {
658 console.log("Open box to select the contact place="+place);
659 $.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"); ?>"});
660}
661
662function History()
663{
664 console.log("Open box to select the history");
665 $.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"); ?>"});
666}
667
668function Reduction() {
669 invoiceid = $("#invoiceid").val();
670 console.log("Open popup to enter reduction on invoiceid="+invoiceid);
671 $.colorbox({href:"reduction.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
672}
673
674var closeBillParams="";
675function CloseBill() {
676 <?php
677 $parameters = array();
678 $reshook = $hookmanager->executeHooks('paramsForCloseBill', $parameters, $obj, $action);
679 if (getDolGlobalString('TAKEPOS_FORBID_SALES_TO_DEFAULT_CUSTOMER')) {
680 echo "customerAnchorTag = document.querySelector('a[id=\"customer\"]'); ";
681 echo "if (customerAnchorTag && customerAnchorTag.innerText.trim() === '".dol_escape_js($langs->transnoentitiesnoconv("Customer"))."') { ";
682 echo "alert('".dol_escape_js($langs->transnoentitiesnoconv("NoClientErrorMessage"))."'); ";
683 echo "return; } \n";
684 }
685 ?>
686 invoiceid = $("#invoiceid").val();
687 console.log("Open popup to enter payment on invoiceid="+invoiceid);
688 <?php if (getDolGlobalInt("TAKEPOS_NO_GENERIC_THIRDPARTY")) { ?>
689 if ($("#idcustomer").val() == "") {
690 alert("<?php echo dol_escape_js($langs->transnoentitiesnoconv('TakePosCustomerMandatory'), 2); ?>");
691 <?php if (getDolGlobalString('TAKEPOS_CHOOSE_CONTACT')) { ?>
692 Contact();
693 <?php } else { ?>
694 Customer();
695 <?php } ?>
696 return;
697 }
698 <?php } ?>
699 <?php
700 $alternative_payurl = getDolGlobalString('TAKEPOS_ALTERNATIVE_PAYMENT_SCREEN');
701 if (empty($alternative_payurl)) {
702 $payurl = "pay.php";
703 } else {
704 $payurl = dol_buildpath($alternative_payurl, 1);
705 }
706 ?>
707 $.colorbox({href:"<?php echo $payurl; ?>?place="+place+"&invoiceid="+invoiceid+closeBillParams, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
708}
709
710function Split() {
711 invoiceid = $("#invoiceid").val();
712 console.log("Open popup to split on invoiceid="+invoiceid);
713 $.colorbox({href:"split.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
714}
715
716function Floors() {
717 console.log("Open box to select floor place="+place);
718 $.colorbox({href:"floors.php?place="+place, width:"90%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Floors"); ?>"});
719}
720
721function FreeZone() {
722 invoiceid = $("#invoiceid").val();
723 console.log("Open box to enter a free product on invoiceid="+invoiceid);
724 $.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"); ?>"});
725}
726
727function TakeposOrderNotes() {
728 console.log("Open box to order notes");
729 ModalBox('ModalNote');
730 $("#textinput").focus();
731}
732
733function Refresh() {
734 console.log("Refresh by reloading place="+place+" invoiceid="+invoiceid);
735 $("#poslines").load("invoice.php?place="+place+"&invoiceid="+invoiceid, function() {
736 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
737 });
738}
739
740function New() {
741 // If we go here,it means $conf->global->TAKEPOS_BAR_RESTAURANT is not defined
742 invoiceid = $("#invoiceid").val(); // This is a hidden field added by invoice.php
743
744 console.log("New with place = <?php echo $place; ?>, js place="+place+", invoiceid="+invoiceid);
745
746 if (invoiceid == '') {
747 $("#poslines").load("invoice.php?action=delete&token=<?php echo currentToken(); ?>&place=" + place, function () {
748 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
749 });
750
751 ClearSearch(false);
752 $("#idcustomer").val("");
753 return;
754 }
755
756 $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getInvoice&token=<?php echo currentToken();?>&id='+invoiceid, function(data) {
757 var r;
758
759 if (parseInt(data['paye']) === 1) {
760 r = true;
761 } else {
762 r = confirm('<?php echo($place > 0 ? $langs->transnoentitiesnoconv("ConfirmDeletionOfThisPOSSale") : $langs->transnoentitiesnoconv("ConfirmDiscardOfThisPOSSale")); ?>');
763 }
764
765 if (r == true) {
766 // Reload section with invoice lines
767 $("#poslines").load("invoice.php?action=delete&token=<?php echo currentToken(); ?>&place=" + place, function () {
768 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
769 });
770
771 ClearSearch(false);
772 $("#idcustomer").val("");
773 }
774 });
775}
783function Search2(keyCodeForEnter, moreorless) {
784 var eventKeyCode = null;
785
786 if (window.event && window.event.keyCode) {
787 eventKeyCode = window.event.keyCode;
788 }
789 if (eventKeyCode === null && keyCodeForEnter !== '') {
790 // No key code available, exit early if a key code is required
791 return;
792 }
793
794 console.log("Search2 Call ajax search to replace products keyCodeForEnter="+keyCodeForEnter+", eventKeyCode="+eventKeyCode);
795
796 var search_term = $('#search').val();
797 var search_start = 0;
798 var search_limit = <?php echo $MAXPRODUCT - 2; ?>;
799 if (moreorless != null) {
800 search_term = $('#search_pagination').val();
801 search_start = $('#search_start_'+moreorless).val();
802 }
803
804 console.log("search_term="+search_term);
805
806 if (search_term == '') {
807 $("[id^=prowatermark]").html("");
808 $("[id^=prodesc]").text("");
809 $("[id^=probutton]").text("");
810 $("[id^=probutton]").hide();
811 $("[id^=proprice]").attr("class", "hidden");
812 $("[id^=proprice]").html("");
813 $("[id^=proimg]").attr("src", "genimg/empty.png");
814 $("[id^=prodiv]").data("rowid", "");
815 $("[id^=prodiv]").attr("data-rowid", "");
816 return;
817 }
818
819 var search = false;
820 if (keyCodeForEnter == '' || eventKeyCode == keyCodeForEnter) {
821 search = true;
822 }
823
824 if (search === true) {
825 // if a timer has been already started (search2_timer is a global js variable), we cancel it now
826 // we click onto another key, we will restart another timer just after
827 if (search2_timer) {
828 clearTimeout(search2_timer);
829 }
830
831 // temporization time to give time to type
832 search2_timer = setTimeout(function(){
833 pageproducts = 0;
834 jQuery(".wrapper2 .catwatermark").hide();
835 var nbsearchresults = 0;
836
837 // Only show products for sale (tosell=1)
838 let socid = jQuery('#thirdpartyid').val();
839 if ((socid === undefined || socid === "") && parseInt("<?php echo dol_escape_js($socid) ?>") > 0) {
840 socid = parseInt("<?php echo dol_escape_js($socid); ?>");
841 }
842
843 $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&token=<?php echo currentToken();?>&search_term=' + search_term + '&thirdpartyid=' + socid + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) {
844 for (i = 0; i < <?php echo($MAXPRODUCT - 2); ?>; i++) { // the last 2 slots are the pager arrows, not product slots
845 if (typeof (data[i]) == "undefined") {
846 $("#prowatermark" + i).html("");
847 $("#prodesc" + i).text("");
848 $("#probutton" + i).text("");
849 $("#probutton" + i).hide();
850 $("#proprice" + i).attr("class", "hidden");
851 $("#proprice" + i).html("");
852 $("#proimg" + i).attr("src", "genimg/empty.png");
853 $("#prodiv" + i).data("rowid", "");
854 $("#prodiv" + i).attr("data-rowid", "");
855 continue;
856 }
857 <?php
858 $titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[i]['ref']";
859 $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[i]['barcode']";
860 ?>
861 var titlestring = <?php echo $titlestring; ?>;
862 <?php if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) { ?>
863 $("#prodesc" + i).html(data[i]['ref'].bold() + ' - ' + data[i]['label']);
864 <?php } elseif (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 2) { ?>
865 $("#prodesc" + i).html(data[i]['ref'].bold());
866 <?php } else { ?>
867 $("#prodesc" + i).html(data[i]['label']);
868 <?php } ?>
869 $("#prodivdesc" + i).show();
870 $("#probutton" + i).html(data[i]['label']);
871 $("#probutton" + i).show();
872 if (data[i]['price_formated']) {
873 $("#proprice" + i).attr("class", "productprice");
874 <?php
875 if (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT')) {
876 ?>
877 $("#proprice" + i).html(data[i]['price_formated']);
878 <?php
879 } else {
880 ?>
881 $("#proprice" + i).html(data[i]['price_ttc_formated']);
882 <?php
883 }
884 ?>
885 }
886 $("#proimg" + i).attr("title", titlestring);
887 if( undefined !== data[i]['img']) {
888 $("#proimg" + i).attr("src", data[i]['img']);
889 }
890 else {
891 $("#proimg" + i).attr("src", "genimg/index.php?query=pro&id=" + data[i]['rowid']);
892 }
893 $("#prodiv" + i).data("rowid", data[i]['rowid']);
894 $("#prodiv" + i).attr("data-rowid", data[i]['rowid']);
895 $("#prodiv" + i).data("iscat", 0);
896 $("#prodiv" + i).attr("data-iscat", 0);
897
898 <?php
899 // Add js from hooks
900 $parameters = array();
901 $parameters['caller'] = 'search2';
902 $hookmanager->executeHooks('completeJSProductDisplay', $parameters);
903 print $hookmanager->resPrint;
904 ?>
905
906 nbsearchresults++;
907 }
908 }).always(function (data) {
909 // If there is only 1 answer
910 if ($('#search').val().length > 0 && data.length == 1) {
911 console.log($('#search').val()+' - '+data[0]['barcode']);
912 if ($('#search').val() == data[0]['barcode'] && 'thirdparty' == data[0]['object']) {
913 console.log("There is only 1 answer with barcode matching the search, so we change the thirdparty "+data[0]['rowid']);
914 ChangeThirdparty(data[0]['rowid']);
915 }
916 else if ('product' == data[0]['object'] && $('#search').val() == data[0]['barcode']) {
917 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']);
918 ClickProduct(0, data[0]['qty'], 1);
919 }
920 }
921 if (eventKeyCode == keyCodeForEnter){
922 if (data.length == 0) {
923 $('#search').val('<?php
924 $langs->load('errors');
925 echo dol_escape_js($langs->transnoentitiesnoconv("ErrorRecordNotFoundShort"));
926 ?> ('+search_term+')');
927 $('#search').select();
928 }
929 else ClearSearch(false);
930 }
931 // memorize search_term and start for pagination
932 $("#search_pagination").val($("#search").val());
933 if (search_start == 0) {
934 $("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").hide();
935 }
936 else {
937 $("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").show();
938 var search_start_less = Math.max(0, parseInt(search_start) - parseInt(<?php echo $MAXPRODUCT - 2;?>));
939 $("#search_start_less").val(search_start_less);
940 }
941 if (nbsearchresults != <?php echo $MAXPRODUCT - 2; ?>) {
942 $("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").hide();
943 }
944 else {
945 $("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").show();
946 var search_start_more = parseInt(search_start) + parseInt(<?php echo $MAXPRODUCT - 2;?>);
947 $("#search_start_more").val(search_start_more);
948 }
949 });
950 }, 500); // 500ms delay
951 }
952
953}
954
955/* Function called on an action into the PAD */
956function Edit(number) {
957 console.log("We click on PAD on key="+number);
958
959 if (typeof(selectedtext) == "undefined") {
960 return; // We click on an action on the number pad but there is no line selected
961 }
962
963 var text=selectedtext+"<br> ";
964
965
966 if (number=='c') {
967 editnumber='';
968 Refresh();
969 $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
970 $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
971 $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
972 return;
973 } else if (number=='qty') {
974 if (editaction=='qty' && editnumber != '') {
975 $("#poslines").load("invoice.php?action=updateqty&token=<?php echo currentToken(); ?>&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
976 editnumber="";
977 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
978 $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
979 });
980
981 setFocusOnSearchField();
982 return;
983 }
984 else {
985 editaction="qty";
986 }
987 } else if (number=='p') {
988 if (editaction=='p' && editnumber!="") {
989 $("#poslines").load("invoice.php?action=updateprice&token=<?php echo currentToken(); ?>&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
990 editnumber="";
991 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
992 $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
993 });
994
995 ClearSearch(false);
996 return;
997 }
998 else {
999 editaction="p";
1000 }
1001 } else if (number=='r') {
1002 if (editaction=='r' && editnumber!="") {
1003 $("#poslines").load("invoice.php?action=updatereduction&token=<?php echo currentToken(); ?>&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
1004 editnumber="";
1005 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
1006 $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
1007 });
1008
1009 ClearSearch(false);
1010 return;
1011 }
1012 else {
1013 editaction="r";
1014 }
1015 }
1016 else {
1017 editnumber=editnumber+number;
1018 }
1019 if (editaction=='qty'){
1020 text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Qty").": "; ?>";
1021 $("#qty").html("OK").addClass("clicked");
1022 $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
1023 $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
1024 }
1025 if (editaction=='p'){
1026 text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Price").": "; ?>";
1027 $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
1028 $("#price").html("OK").addClass("clicked");
1029 $("#reduction").html("<?php echo $langs->trans("LineDiscountShort"); ?>").removeClass('clicked');
1030 }
1031 if (editaction=='r'){
1032 text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("LineDiscountShort").": "; ?>";
1033 $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
1034 $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
1035 $("#reduction").html("OK").addClass("clicked");
1036 }
1037 $('#'+selectedline).find("td:first").html(text+editnumber);
1038}
1039
1040
1041function TakeposPrintingOrder(){
1042 console.log("TakeposPrintingOrder output invoice to print order");
1043 $("#poslines").load("invoice.php?action=order&token=<?php echo currentToken();?>&place="+place, function() {
1044 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
1045 });
1046}
1047
1048function TakeposPrintingTemp(){
1049 console.log("TakeposPrintingTemp");
1050 $("#poslines").load("invoice.php?action=temp&token=<?php echo currentToken();?>&place="+place, function() {
1051 //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
1052 });
1053}
1054
1055function OpenDrawer(){
1056 console.log("OpenDrawer call ajax url http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>:8111/print");
1057 $.ajax({
1058 type: "POST",
1059 data: { token: 'notrequired' },
1060 <?php
1061 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1062 echo "url: '".getDolGlobalString('TAKEPOS_PRINT_SERVER', 'localhost')."/printer/drawer.php',";
1063 } else {
1064 echo "url: 'http://".getDolGlobalString('TAKEPOS_PRINT_SERVER', 'localhost').":8111/print',";
1065 }
1066 ?>
1067 data: "opendrawer"
1068 });
1069}
1070
1071/* Click on button to open drawer */
1072function DolibarrOpenDrawer() {
1073 console.log("DolibarrOpenDrawer call ajax url /takepos/ajax/ajax.php?action=opendrawer&token=<?php echo currentToken();?>&term=<?php print urlencode(empty($_SESSION["takeposterminal"]) ? '' : $_SESSION["takeposterminal"]); ?>");
1074 $.ajax({
1075 type: "GET",
1076 data: { token: '<?php echo currentToken(); ?>' },
1077 url: "<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=opendrawer&token='.currentToken().'&term='.urlencode(empty($_SESSION["takeposterminal"]) ? '' : $_SESSION["takeposterminal"]); ?>",
1078 });
1079}
1080
1081function MoreActions(totalactions) {
1082 for (i = 0; i <= totalactions; i++) {
1083 $("#action" + i).toggle();
1084 }
1085 $("#actionnext").toggle();
1086 $("#actionprevious").toggle();
1087}
1088
1089function ControlCashOpening()
1090{
1091 $.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"); ?>"});
1092}
1093
1094function CloseCashFence(rowid)
1095{
1096 $.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"); ?>"});
1097}
1098
1099function CashReport(rowid)
1100{
1101 $.colorbox({href:"../compta/cashcontrol/report.php?id="+rowid+"&contextpage=takepos", width:"60%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("CashReport"); ?>"});
1102}
1103
1104/*
1105 * TakePOS Popup
1106 * Open the <div id='ModalID'>in a popup. Example with ModalID='ModalCreditNote'
1107 */
1108function ModalBox(ModalID)
1109{
1110 var modal = document.getElementById(ModalID);
1111 modal.style.display = "block";
1112}
1113
1114function DirectPayment(){
1115 console.log("DirectPayment");
1116 $("#poslines").load("invoice.php?place="+place+"&action=valid&token=<?php echo currentToken(); ?>&pay=LIQ", function() {
1117 $('#invoiceid').val("");
1118 });
1119}
1120
1121function FullScreen() {
1122 document.documentElement.requestFullscreen();
1123}
1124
1125function WeighingScale(callback) {
1126 console.log("Weighing Scale: invoiceid = " + placeid + ", lineid = " + selectedline);
1127 <?php if (getDolGlobalString('TAKEPOS_CONNECTOR_TO_WHB_SCALE')) {?>
1128 <?php if (getDolGlobalString('WEIGHINGSCALE_PROTOCOL') == "diag06") { ?>
1129 // Protocole Dialog-06, il a besoin du prix unitaire, le demander s'il manque
1130 var urlProduct;
1131 if (idproduct == "" && selectedline > 0) {
1132 urlProduct = "<?php echo DOL_URL_ROOT; ?>/api/index.php/takeposconnector/invoices/" + placeid + "/lines/" + selectedline + "/product";
1133 } else {
1134 urlProduct = "<?php echo DOL_URL_ROOT; ?>/api/index.php/products/" + idproduct;
1135 }
1136 $.ajax({
1137 type: "GET",
1138 headers: { "DOLAPIKEY": '<?php echo $user->api_key; ?>' },
1139 url: urlProduct,
1140 })
1141 .done(function(product) {
1142 if (callback === undefined) {
1143 callback = function(qty) {
1144 $("#poslines").load("invoice.php?token=<?php echo currentToken(); ?>&action=updateqty&place="+place+"&idline="+selectedline+"&number="+qty);
1145 };
1146 }
1147 if (product.fk_unit == "2") {
1148 askForWeight(product.multiprices_ttc[1], callback, function (errorMessage) {
1149 console.log("Erreur: " + errorMessage);
1150 });
1151 }
1152 });
1153 <?php } else { ?>
1154 // Protocole par défaut de takeposconnector: réception continue du poids/stabilité
1155 editnumber = globalWeight;
1156 $("#poslines").load("invoice.php?token=<?php echo currentToken(); ?>&action=updateqty&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
1157 editnumber="";
1158 });
1159 <?php } ?>
1160 <?php } else { ?> // utilisation du new TakePOS-Connector PHP: envoie "$" à la balance pour avoir le poids
1161 $.ajax({
1162 type: "POST",
1163 data: { token: 'notrequired' },
1164 url: '<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>/scale/index.php',
1165 })
1166 .done(function( editnumber ) {
1167 $("#poslines").load("invoice.php?token=<?php echo currentToken(); ?>&action=updateqty&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
1168 editnumber="";
1169 });
1170 });
1171 <?php } ?>
1172}
1173
1174$( document ).ready(function() {
1175 PrintCategories(0);
1176 LoadProducts(0);
1177 Refresh();
1178 <?php
1179 // IF NO TERMINAL SELECTED
1180 if (empty($_SESSION["takeposterminal"]) || $_SESSION["takeposterminal"] == "") {
1181 print "ModalBox('ModalTerminal');";
1182 }
1183
1184 if (getDolGlobalString('TAKEPOS_CONTROL_CASH_OPENING') && !empty($_SESSION["takeposterminal"])) {
1185 // Look for any cash control fence created today on this terminal, regardless of its status,
1186 // so the auto-open popup only fires on the first cash control of a calendar day. Without this,
1187 // refreshing the browser the same day after closing a fence used to immediately re-fire the
1188 // popup because the closed fences were filtered out by the status check (#38597).
1189 $sql = "SELECT rowid, status FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE";
1190 $sql .= " entity = ".((int) $conf->entity)." AND ";
1191 $sql .= " posnumber = ".((int) $_SESSION["takeposterminal"])." AND ";
1192 $sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'";
1193 $resql = $db->query($sql);
1194 if ($resql) {
1195 $obj = $db->fetch_object($resql);
1196 // If there is no cash control from today open it
1197 if (!isset($obj->rowid) || is_null($obj->rowid)) {
1198 print "ControlCashOpening();";
1199 }
1200 }
1201 }
1202 ?>
1203
1204 /* For Header Scroll */
1205 var elem1 = $("#topnav-left")[0];
1206 var elem2 = $("#topnav-right")[0];
1207 var checkOverflow = function() {
1208 if (scrollBars().horizontal) $("#topnav").addClass("overflow");
1209 else $("#topnav").removeClass("overflow");
1210 }
1211
1212 var scrollBars = function(){
1213 var container= $('#topnav')[0];
1214 return {
1215 vertical:container.scrollHeight > container.clientHeight,
1216 horizontal:container.scrollWidth > container.clientWidth
1217 }
1218 }
1219
1220 $(window).resize(function(){
1221 checkOverflow();
1222 });
1223
1224 let resizeObserver = new ResizeObserver(() => {
1225 checkOverflow();
1226 });
1227 resizeObserver.observe(elem1);
1228 resizeObserver.observe(elem2);
1229 checkOverflow();
1230
1231 var pressTimer = [];
1232 var direction = 1;
1233 var step = 200;
1234
1235 $(".indicator").mousedown(function(){
1236 direction = $(this).hasClass("left") ? -1 : 1;
1237 scrollTo();
1238 pressTimer.push(setInterval(scrollTo, 100));
1239 });
1240
1241 $(".indicator").mouseup(function(){
1242 pressTimer.forEach(clearInterval);
1243 });
1244
1245 $("body").mouseup(function(){
1246 pressTimer.forEach(clearInterval);
1247 console.log("body mouseup");
1248 });
1249
1250 function scrollTo(){
1251 console.log("here");
1252 var pos = $("#topnav").scrollLeft();
1253 document.getElementById("topnav").scrollTo({ left: $("#topnav").scrollLeft() + direction * step, behavior: 'smooth' })
1254 }
1255
1256 $("#topnav").scroll(function(){
1257 if (($("#topnav").offsetWidth + $("#topnav").scrollLeft >= $("#topnav").scrollWidth)) {
1258 console.log("end");
1259 }
1260 });
1261 /* End Header Scroll */
1262});
1263</script>
1264
1265<div class="container">
1266
1267<?php
1268if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
1269 ?>
1270 <div class="header">
1271 <div id="topnav" class="topnav">
1272 <div id="topnav-left" class="topnav-left">
1273 <div class="inline-block valignmiddle">
1274 <a class="topnav-terminalhour" onclick="ModalBox('ModalTerminal')">
1275 <span class="fa fa-cash-register"></span>
1276 <span class="hideonsmartphone">
1277 <?php
1278 if (!empty($_SESSION["takeposterminal"])) {
1279 echo getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$_SESSION["takeposterminal"], $langs->trans("TerminalName", $_SESSION["takeposterminal"]));
1280 }
1281 ?>
1282 </span>
1283 <?php
1284 echo '<span class="hideonsmartphone"> - '.dol_print_date(dol_now(), "day").'</span>'; ?>
1285 </a>
1286 <?php
1287 if (isModEnabled('multicurrency')) {
1288 print '<a class="valignmiddle tdoverflowmax100" id="multicurrency" onclick="ModalBox(\'ModalCurrency\')" title=""><span class="fas fa-coins paddingrightonly"></span>';
1289 print '<span class="hideonsmartphone">'.$langs->trans("Currency").'</span>';
1290 print '</a>';
1291 } ?>
1292 </div>
1293 <!-- section for customer -->
1294 <div class="inline-block valignmiddle" id="customerandsales"></div>
1295 <input type="hidden" id="idcustomer" value="">
1296 <!-- section for shopping carts -->
1297 <div class="inline-block valignmiddle" id="shoppingcart"></div>
1298 <!-- More info about customer -->
1299 <div class="inline-block valignmiddle tdoverflowmax150onsmartphone" id="moreinfo"></div>
1300 <?php
1301 if (isModEnabled('stock')) {
1302 ?>
1303 <!-- More info about warehouse -->
1304 <div class="inline-block valignmiddle tdoverflowmax150onsmartphone" id="infowarehouse"></div>
1305 <?php
1306 } ?>
1307 </div>
1308 <div id="topnav-right" class="topnav-right">
1309 <?php
1310 $reshook = $hookmanager->executeHooks('takepos_login_block_other');
1311 if ($reshook == 0) { //Search method
1312 ?>
1313 <div class="login_block_other takepos">
1314 <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>
1315 <a onclick="ClearSearch(false);" class="nohover"><span class="fa fa-backspace"></span></a>
1316 <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 -->
1317 <span class="fas fa-home"></span></a>
1318 <?php if (empty($conf->dol_use_jmobile)) { ?>
1319 <a class="hideonsmartphone" onclick="FullScreen();" title="<?php echo dol_escape_htmltag($langs->trans("ClickFullScreenEscapeToLeave")); ?>"><span class="fa fa-expand-arrows-alt"></span></a>
1320 <?php } ?>
1321 </div>
1322 <?php
1323 }
1324 ?>
1325 <div class="login_block_user">
1326 <?php
1327 print top_menu_user(1, DOL_URL_ROOT.'/user/logout.php?token='.newToken().'&urlfrom='.urlencode('/takepos/?setterminal='.((int) $term)));
1328 ?>
1329 </div>
1330 </div>
1331 <div class="arrows">
1332 <span class="indicator left"><i class="fa fa-arrow-left"></i></span>
1333 <span class="indicator right"><i class="fa fa-arrow-right"></i></span>
1334 </div>
1335 </div>
1336 </div>
1337 <?php
1338}
1339?>
1340
1341<!-- Modal terminal box -->
1342<div id="ModalTerminal" class="modal">
1343 <div class="modal-content">
1344 <div class="modal-header">
1345 <?php
1346 if (!getDolGlobalString('TAKEPOS_FORCE_TERMINAL_SELECT')) {
1347 ?>
1348 <span class="close" href="#" onclick="document.getElementById('ModalTerminal').style.display = 'none';">&times;</span>
1349 <?php
1350 } ?>
1351 <h3><?php print $langs->trans("TerminalSelect"); ?></h3>
1352 </div>
1353 <div class="modal-body">
1354 <button type="button" class="block" onclick="location.href='index.php?setterminal=1'"><?php print getDolGlobalString("TAKEPOS_TERMINAL_NAME_1", $langs->trans("TerminalName", 1)); ?></button>
1355 <?php
1356 $nbloop = getDolGlobalInt('TAKEPOS_NUM_TERMINALS');
1357 for ($i = 2; $i <= $nbloop; $i++) {
1358 print '<button type="button" class="block" onclick="location.href=\'index.php?setterminal='.$i.'\'">'.getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$i, $langs->trans("TerminalName", $i)).'</button>';
1359 }
1360 ?>
1361 </div>
1362</div>
1363</div>
1364
1365<!-- Modal multicurrency box -->
1366<?php if (isModEnabled('multicurrency')) { ?>
1367<div id="ModalCurrency" class="modal">
1368 <div class="modal-content">
1369 <div class="modal-header">
1370 <span class="close" href="#" onclick="document.getElementById('ModalCurrency').style.display = 'none';">&times;</span>
1371 <h3><?php print $langs->trans("SetMultiCurrencyCode"); ?></h3>
1372 </div>
1373 <div class="modal-body">
1374 <?php
1375 $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'multicurrency';
1376 $sql .= " WHERE entity IN ('".getEntity('multicurrency')."')";
1377 $resql = $db->query($sql);
1378 if ($resql) {
1379 while ($obj = $db->fetch_object($resql)) {
1380 print '<button type="button" class="block" onclick="location.href=\'index.php?setcurrency='.urlencode($obj->code).'\'">'.$obj->code.'</button>';
1381 }
1382 }
1383 ?>
1384 </div>
1385 </div>
1386</div>
1387<?php } ?>
1388
1389<!-- Modal popup to create a Credit Note -->
1390<div id="ModalCreditNote" class="modal">
1391 <div class="modal-content">
1392 <div class="modal-header">
1393 <span class="close" href="#" onclick="document.getElementById('ModalCreditNote').style.display = 'none';">&times;</span>
1394 <h3><?php print $langs->trans("invoiceAvoirWithLines"); ?></h3>
1395 </div>
1396 <div class="modal-body">
1397 <button type="button" class="block" onclick="CreditNote(); document.getElementById('ModalCreditNote').style.display = 'none';"><?php print $langs->trans("Yes"); ?></button>
1398 <button type="button" class="block" onclick="document.getElementById('ModalCreditNote').style.display = 'none';"><?php print $langs->trans("No"); ?></button>
1399 </div>
1400</div>
1401</div>
1402
1403<!-- Modal Note -->
1404<div id="ModalNote" class="modal">
1405 <div class="modal-content">
1406 <div class="modal-header">
1407 <span class="close" href="#" onclick="document.getElementById('ModalNote').style.display = 'none';">&times;</span>
1408 <h3><?php print $langs->trans("Note"); ?></h3>
1409 </div>
1410 <div class="modal-body">
1411 <input type="text" class="block" id="textinput">
1412 <button type="button" class="block" onclick="SetNote(); document.getElementById('ModalNote').style.display = 'none';">OK</button>
1413 </div>
1414</div>
1415</div>
1416
1417 <div class="row1<?php if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
1418 print 'withhead';
1419 } ?>">
1420
1421 <div id="poslines" class="div1">
1422 </div>
1423
1424 <div class="div2">
1425 <button type="button" class="calcbutton" onclick="Edit(7);">7</button>
1426 <button type="button" class="calcbutton" onclick="Edit(8);">8</button>
1427 <button type="button" class="calcbutton" onclick="Edit(9);">9</button>
1428 <button type="button" id="qty" class="calcbutton2" onclick="Edit('qty')"><?php echo $langs->trans("Qty"); ?></button>
1429 <button type="button" class="calcbutton" onclick="Edit(4);">4</button>
1430 <button type="button" class="calcbutton" onclick="Edit(5);">5</button>
1431 <button type="button" class="calcbutton" onclick="Edit(6);">6</button>
1432 <button type="button" id="price" class="calcbutton2" onclick="Edit('p')"><?php echo $langs->trans("Price"); ?></button>
1433 <button type="button" class="calcbutton" onclick="Edit(1);">1</button>
1434 <button type="button" class="calcbutton" onclick="Edit(2);">2</button>
1435 <button type="button" class="calcbutton" onclick="Edit(3);">3</button>
1436 <button type="button" id="reduction" class="calcbutton2" onclick="Edit('r')"><?php echo $langs->trans("LineDiscountShort"); ?></button>
1437 <button type="button" class="calcbutton" onclick="Edit(0);">0</button>
1438 <button type="button" class="calcbutton" onclick="Edit('.')">.</button>
1439 <button type="button" class="calcbutton poscolorblue" onclick="Edit('c')">C</button>
1440 <?php if ($user->hasRight('takepos', 'editlines')) { ?>
1441 <button type="button" class="calcbutton2 poscolordelete" id="delete" onclick="deleteline()"><span class="fa fa-trash"></span></button>
1442 <?php } ?>
1443 </div>
1444
1445<?php
1446
1447// Dependency modulecheck
1448if (!isModEnabled('invoice')) {
1449 setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Invoice")), null, 'errors');
1450}
1451
1452// TakePOS setup check
1453if (isset($_SESSION["takeposterminal"]) && $_SESSION["takeposterminal"]) {
1454 $sql = "SELECT code, libelle FROM " . MAIN_DB_PREFIX . "c_paiement";
1455 $sql .= " WHERE entity IN (" . getEntity('c_paiement') . ")";
1456 $sql .= " AND active = 1";
1457 $sql .= " ORDER BY libelle";
1458
1459 $resql = $db->query($sql);
1460 $paiementsModes = array();
1461 if ($resql) {
1462 while ($obj = $db->fetch_object($resql)) {
1463 $paycode = $obj->code;
1464 if ($paycode == 'LIQ') {
1465 $paycode = 'CASH';
1466 }
1467 if ($paycode == 'CHQ') {
1468 $paycode = 'CHEQUE';
1469 }
1470
1471 $constantforkey = "CASHDESK_ID_BANKACCOUNT_" . $paycode . $_SESSION["takeposterminal"];
1472 //var_dump($constantforkey.' '.getDolGlobalInt($constantforkey));
1473 if (getDolGlobalInt($constantforkey) > 0) {
1474 array_push($paiementsModes, $obj);
1475 }
1476 }
1477 }
1478
1479 if (empty($paiementsModes) && isModEnabled("bank")) {
1480 $langs->load('errors');
1481 setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("TakePOS")), null, 'errors');
1482 setEventMessages($langs->trans("ProblemIsInSetupOfTerminal", $_SESSION["takeposterminal"]), null, 'errors');
1483 }
1484}
1485
1486if (count($maincategories) == 0) {
1487 if (getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') > 0) {
1488 $tmpcategory = new Categorie($db);
1489 $tmpcategory->fetch(getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID'));
1490 setEventMessages($langs->trans("TakeposNeedsAtLeastOnSubCategoryIntoParentCategory", $tmpcategory->label), null, 'errors');
1491 } else {
1492 setEventMessages($langs->trans("TakeposNeedsCategories"), null, 'errors');
1493 }
1494}
1495// User menu and external TakePOS modules
1496$menus = array();
1497$r = 0;
1498
1499if (! getDolGlobalString('TAKEPOS_HIDE_HISTORY')) {
1500 $menus[$r++] = array('title' => '<span class="fa fa-history paddingrightonly"></span><div class="trunc">'.$langs->trans("History").'</div>', 'action' => 'History();');
1501}
1502
1503if (getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
1504 if (getDolGlobalString('TAKEPOS_CHOOSE_CONTACT')) {
1505 $menus[$r++] = array('title' => '<span class="far fa-building paddingrightonly"></span><div class="trunc">'.$langs->trans("Contact").'</div>', 'action' => 'Contact();');
1506 } else {
1507 $menus[$r++] = array('title' => '<span class="far fa-building paddingrightonly"></span><div class="trunc">'.$langs->trans("Customer").'</div>', 'action' => 'Customer();');
1508 }
1509}
1510
1511if (!getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
1512 $menus[$r++] = array('title' => '<span class="fa fa-layer-group paddingrightonly"></span><div class="trunc">'.$langs->trans("New").'</div>', 'action' => 'New();');
1513} else {
1514 // BAR RESTAURANT specific menu
1515 $menus[$r++] = array('title' => '<span class="fa fa-layer-group paddingrightonly"></span><div class="trunc">'.$langs->trans("Place").'</div>', 'action' => 'Floors();');
1516}
1517
1518// Add a non predefined product
1519if (!getDolGlobalString('TAKEPOS_NO_FREE_ZONE_PRODUCT')) {
1520 $menus[$r++] = array('title' => '<span class="fa fa-cube paddingrightonly"></span><div class="trunc">'.$langs->trans("FreeZone").'</div>', 'action' => 'FreeZone();');
1521}
1522
1523// BAR RESTAURANT specific menu "Print on kitchen/order printer"
1524if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
1525 if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
1526 $menus[$r++] = array('title' => '<span class="fa fa-cube paddingrightonly"></span><div class="trunc">'.$langs->trans("ProductSupplements").'</div>', 'action' => 'LoadProducts(\'supplements\');');
1527 }
1528
1529 if (getDolGlobalString('TAKEPOS_ORDER_PRINTERS')) {
1530 $menus[$r++] = array('title' => '<span class="fa fa-blender-phone paddingrightonly"></span><div class="trunc">'.$langs->trans("SentOrderToKitchen").'</span>', 'action' => 'TakeposPrintingOrder();');
1531 }
1532}
1533
1534// Add a discount
1535$menus[$r++] = array('title' => '<span class="fa fa-percent paddingrightonly"></span><div class="trunc">'.$langs->trans("InvoiceDiscountShort").'</div>', 'action' => 'Reduction();');
1536
1537if (!getDolGlobalString('TAKEPOS_NO_SPLIT_SALE')) {
1538 $menus[$r++] = array('title' => '<span class="fas fa-cut paddingrightonly"></span><div class="trunc">'.$langs->trans("SplitSale").'</div>', 'action' => 'Split();');
1539}
1540
1541// Last action that close the sell (payments)
1542$menus[$r++] = array('title' => '<span class="far fa-money-bill-alt paddingrightonly"></span><div class="trunc">'.$langs->trans("Payment").'</div>', 'action' => 'CloseBill();');
1543if (getDolGlobalString('TAKEPOS_DIRECT_PAYMENT')) {
1544 $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();');
1545}
1546
1547$customprinterallowed = false;
1548$customprinttemplateallowed = true;
1549
1550// BAR RESTAURANT specific menu
1551if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
1552 // Button to print receipt before payment
1553 $customprinterallowed = true;
1554 $customprinttemplateallowed = true;
1555}
1556
1557include_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php';
1558if (isALNERunningVersion()) {
1559 // Custom printer may be allowed if mandatory information in template are guaranteed. For the moment, we prefer not allow this.
1560 $customprinttemplateallowed = false;
1561}
1562
1563// Button to print receipt
1564// This section should be same than into invoice.php
1565if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") { // deprecated method
1566 if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var(getDolGlobalString('TAKEPOS_PRINT_SERVER'), FILTER_VALIDATE_URL) == true) {
1567 // If TAKEPOS_PRINT_SERVER is an URL
1568 $menus[$r++] = array('title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("PrintTicket").'</div>', 'action' => 'PrintByESCPOSOld(placeid);');
1569 } else {
1570 // If TAKEPOS_PRINT_SERVER is an IP
1571 // Print by calling the receipt.php to get HTML content and send the HTML content to TAKEPOS_PRINT_SERVER:8111/print
1572 $menus[$r++] = array('title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("PrintTicket").'</div>', 'action' => 'PrintHTMLToSlashPrint(placeid);');
1573 }
1574} elseif ($customprinterallowed && $customprinttemplateallowed && (isModEnabled('receiptprinter') && getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term) > 0) || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") { // @phpstan-ignore-line
1575 // Button Print Receipt on special custom printer using custom template
1576 $nameOfPrinter = dol_getIdFromCode($db, getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$term), 'printer_receipt', 'rowid', 'name', 1);
1577 $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' => 'PrintByESCPOS(placeid);');
1578} else {
1579 // Button Print Receipt on browser
1580 $menus[$r++] = array('title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("PrintTicket").'</div>', 'action' => 'PrintByBrowser(placeid);');
1581}
1582
1583if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector" && getDolGlobalString('TAKEPOS_ORDER_NOTES') == 1) {
1584 $menus[$r++] = array('title' => '<span class="fa fa-sticky-note paddingrightonly"></span><div class="trunc">'.$langs->trans("OrderNotes").'</div>', 'action' => 'TakeposOrderNotes();');
1585}
1586
1587
1588if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") {
1589 $menus[$r++] = array('title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("DOL_OPEN_DRAWER").'</div>', 'action' => 'OpenDrawer();');
1590}
1591if (getDolGlobalInt('TAKEPOS_ADD_BUTTON_OPEN_DRAWER'.$term) > 0) {
1592 $menus[$r++] = array(
1593 'title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("DOL_OPEN_DRAWER").'</div>',
1594 'action' => 'DolibarrOpenDrawer();',
1595 );
1596}
1597
1598// If there is an open cash control started
1599$sql = "SELECT rowid, status, entity FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE";
1600$sql .= " entity = ".((int) $conf->entity)." AND ";
1601$sql .= " posnumber = ".((int) empty($_SESSION["takeposterminal"]) ? 0 : $_SESSION["takeposterminal"])." AND ";
1602$sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'";
1603$sql .= " AND status = 0";
1604
1605$resql = $db->query($sql);
1606if ($resql) {
1607 $num = $db->num_rows($resql);
1608 if ($num) {
1609 $obj = $db->fetch_object($resql);
1610 $menus[$r++] = array('title' => '<span class="fas fa-file-invoice-dollar paddingrightonly"></span><div class="trunc">'.$langs->trans("CashReport").'</div>', 'action' => 'CashReport('.$obj->rowid.');');
1611 if ($obj->status == 0) {
1612 $menus[$r++] = array('title' => '<span class="fas fa-cash-register paddingrightonly"></span><div class="trunc">'.$langs->trans("CloseCashFence").'</div>', 'action' => 'CloseCashFence('.$obj->rowid.');');
1613 }
1614 }
1615}
1616
1617if (getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
1618 $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().'\';');
1619}
1620
1621if (getDolGlobalString('TAKEPOS_WEIGHING_SCALE')) {
1622 $menus[$r++] = array('title' => '<span class="fa fa-balance-scale pictofixedwidth"></span><div class="trunc">'.$langs->trans("WeighingScale").'</div>', 'action' => 'WeighingScale();');
1623}
1624
1625$parameters = array('menus' => $menus);
1626$reshook = $hookmanager->executeHooks('ActionButtons', $parameters);
1627if ($reshook == 0) { //add buttons
1628 if (is_array($hookmanager->resArray)) {
1629 foreach ($hookmanager->resArray as $resArray) {
1630 foreach ($resArray as $butmenu) {
1631 $menus[$r++] = $butmenu;
1632 }
1633 }
1634 }
1635} elseif ($reshook == 1) {
1636 $r = 0; //replace buttons
1637 if (is_array($hookmanager->resArray)) {
1638 foreach ($hookmanager->resArray as $resArray) {
1639 foreach ($resArray as $butmenu) {
1640 $menus[$r++] = $butmenu;
1641 }
1642 }
1643 }
1644}
1645
1646?>
1647 <!-- Show buttons -->
1648 <div id="dialogforpopuptakepos"></div>
1649 <style>
1650 /* Style de la popup */
1651 #dialogforpopuptakepos {
1652 display: none;
1653 position: fixed;
1654 top: 20px;
1655 right: 20px;
1656 background: #333;
1657 color: #fff;
1658 padding: 15px 20px;
1659 border-radius: 8px;
1660 box-shadow: 0 0 10px rgba(0,0,0,0.3);
1661 z-index: 1000;
1662 font-family: sans-serif;
1663 }
1664 </style>
1665
1666 <div class="div3">
1667 <?php
1668 $i = 0;
1669 foreach ($menus as $menu) {
1670 $i++;
1671 if (count($menus) > 12 and $i == 12) {
1672 echo '<button style="'.(empty($menu['style']) ? '' : $menu['style']).'" type="button" id="actionnext" class="actionbutton" onclick="MoreActions('.count($menus).')">'.$langs->trans("Next").'</button>';
1673 echo '<button style="display: none;" type="button" id="actionprevious" class="actionbutton" onclick="MoreActions('.count($menus).')">'.$langs->trans("Previous").'</button>';
1674 echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
1675 } elseif ($i > 12) {
1676 echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
1677 // TODO keep style but hide button
1678 } else {
1679 echo '<button style="'.(empty($menu['style']) ? '' : $menu['style']).'" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
1680 }
1681 }
1682
1683 if (getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR') && !getDolGlobalString('TAKEPOS_HIDE_SEARCH')) {
1684 print '<!-- Show the search input text -->'."\n";
1685 print '<div class="margintoponly">';
1686 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> ';
1687 print '<a class="marginleftonly hideonsmartphone" onclick="ClearSearch(false);">'.img_picto('', 'searchclear.png').'</a>';
1688 print '</div>';
1689 }
1690 ?>
1691 </div>
1692 </div>
1693
1694 <div class="row2<?php if (!getDolGlobalString('TAKEPOS_HIDE_HEAD_BAR')) {
1695 print 'withhead';
1696 } ?>">
1697
1698 <!-- Show categories -->
1699 <?php
1700 if (getDolGlobalInt('TAKEPOS_HIDE_CATEGORIES') == 1) {
1701 print '<div class="div4" style= "display: none;">';
1702 } else {
1703 print '<div class="div4">';
1704 }
1705
1706 $count = 0;
1707 while ($count < $MAXCATEG) {
1708 ?>
1709 <div class="wrapper" <?php if ($count == ($MAXCATEG - 2)) {
1710 echo 'onclick="MoreCategories(\'less\')"';
1711 } elseif ($count == ($MAXCATEG - 1)) {
1712 echo 'onclick="MoreCategories(\'more\')"';
1713 } else {
1714 echo 'onclick="LoadProducts('.$count.')"';
1715 } ?> id="catdiv<?php echo $count; ?>">
1716 <?php
1717 if ($count == ($MAXCATEG - 2)) {
1718 //echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="catimg'.$count.'" />';
1719 echo '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1720 } elseif ($count == ($MAXCATEG - 1)) {
1721 //echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="catimg'.$count.'" />';
1722 echo '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1723 } else {
1724 if (!getDolGlobalString('TAKEPOS_HIDE_CATEGORY_IMAGES')) {
1725 echo '<img class="imgwrapper" id="catimg'.$count.'" />';
1726 }
1727 } ?>
1728 <?php if ($count != $MAXCATEG - 2 && $count != $MAXCATEG - 1) { ?>
1729 <div class="description" id="catdivdesc<?php echo $count; ?>">
1730 <div class="description_content" id="catdesc<?php echo $count; ?>"></div>
1731 </div>
1732 <?php } ?>
1733 <div class="catwatermark" id='catwatermark<?php echo $count; ?>'>...</div>
1734 </div>
1735 <?php
1736 $count++;
1737 }
1738 ?>
1739 </div>
1740
1741 <!-- Show product -->
1742 <div class="div5<?php if (getDolGlobalInt('TAKEPOS_HIDE_CATEGORIES') == 1) {
1743 print ' centpercent';
1744 } ?>">
1745 <?php
1746 $count = 0;
1747
1748 while ($count < $MAXPRODUCT) {
1749 print '<div class="wrapper2'.(($count >= ($MAXPRODUCT - 2)) ? ' arrow' : '').'" id="prodiv'.$count.'" '; ?>
1750 <?php if ($count == ($MAXPRODUCT - 2)) {
1751 ?> onclick="MoreProducts('less')" <?php
1752 }
1753 if ($count == ($MAXPRODUCT - 1)) {
1754 ?> onclick="MoreProducts('more')" <?php
1755 } else {
1756 echo 'onclick="ClickProduct('.((int) $count).')"';
1757 } ?>>
1758 <?php
1759 if ($count == ($MAXPRODUCT - 2)) {
1760 //echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="proimg'.$count.'" />';
1761 print '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1762 } elseif ($count == ($MAXPRODUCT - 1)) {
1763 //echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="proimg'.$count.'" />';
1764 print '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1765 } else {
1766 if (!getDolGlobalString('TAKEPOS_HIDE_PRODUCT_PRICES')) {
1767 print '<div class="" id="proprice'.$count.'"></div>';
1768 }
1769 if (getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
1770 print '<button type="button" id="probutton'.$count.'" class="productbutton" style="display: none;"></button>';
1771 } else {
1772 print '<img class="imgwrapper" title="" id="proimg'.$count.'">';
1773 }
1774 } ?>
1775 <?php if ($count != $MAXPRODUCT - 2 && $count != $MAXPRODUCT - 1 && !getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) { ?>
1776 <div class="description" id="prodivdesc<?php echo $count; ?>">
1777 <div class="description_content" id="prodesc<?php echo $count; ?>"></div>
1778 </div>
1779 <?php } ?>
1780 <div class="catwatermark" id='prowatermark<?php echo $count; ?>'>...</div>
1781 </div>
1782 <?php
1783 $count++;
1784 }
1785 ?>
1786 <input type="hidden" id="search_start_less" value="0">
1787 <input type="hidden" id="search_start_more" value="0">
1788 <input type="hidden" id="search_pagination" value="">
1789 </div>
1790 </div>
1791</div>
1792</body>
1793<?php
1794
1795llxFooter();
1796
1797$db->close();
while( $i< $imaxinloop)
The main.inc.php has been included so the following variable are now defined:
Definition list.php:552
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
print $object position
Definition edit.php:206
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:169
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:680
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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:137
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.