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