Issues (2811)

public/htdocs/takepos/index.php (2 issues)

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