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