forked from altairisfr/takepos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
1532 lines (1398 loc) · 59.4 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* Copyright (C) 2018 Andreu Bisquerra <[email protected]>
* Copyright (C) 2019 Josep Lluís Amador <[email protected]>
* Copyright (C) 2020 Thibault FOUCART <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/takepos/index.php
* \ingroup takepos
* \brief Main TakePOS screen
*/
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
if (!defined('NOCSRFCHECK')) {
define('NOCSRFCHECK', '1');
}
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1');
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
require '../main.inc.php'; // Load $user and permissions
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
$hookmanager->initHooks(array('takeposfrontend'));
$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant or multiple sales
$action = GETPOST('action', 'aZ09');
$setterminal = GETPOST('setterminal', 'int');
$setcurrency = GETPOST('setcurrency', 'aZ09');
if ($_SESSION["takeposterminal"] == "") {
if ($conf->global->TAKEPOS_NUM_TERMINALS == "1") {
$_SESSION["takeposterminal"] = 1; // Use terminal 1 if there is only 1 terminal
} elseif (!empty($_COOKIE["takeposterminal"])) {
$_SESSION["takeposterminal"] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE["takeposterminal"]); // Restore takeposterminal from previous session
}
}
if ($setterminal > 0) {
$_SESSION["takeposterminal"] = $setterminal;
setcookie("takeposterminal", $setterminal, (time() + (86400 * 354)), '/', null, false, true); // Permanent takeposterminal var in a cookie
}
if ($setcurrency != "") {
$_SESSION["takeposcustomercurrency"] = $setcurrency;
// We will recalculate amount for foreign currency at next call of invoice.php when $_SESSION["takeposcustomercurrency"] differs from invoice->multicurrency_code.
}
$_SESSION["urlfrom"] = '/takepos/index.php';
$langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter", "banks", "takepos@takepos"));
$categorie = new Categorie($db);
$maxcategbydefaultforthisdevice = 12;
$maxproductbydefaultforthisdevice = 24;
if ($conf->browser->layout == 'phone') {
$maxcategbydefaultforthisdevice = 8;
$maxproductbydefaultforthisdevice = 16;
//REDIRECT TO BASIC LAYOUT IF TERMINAL SELECTED AND BASIC MOBILE LAYOUT ENABLED
if ($_SESSION["takeposterminal"] != "" && $conf->global->TAKEPOS_PHONE_BASIC_LAYOUT == 1) {
$_SESSION["basiclayout"] = 1;
header("Location: phone.php?mobilepage=invoice");
exit;
}
}
$MAXCATEG = (empty($conf->global->TAKEPOS_NB_MAXCATEG) ? $maxcategbydefaultforthisdevice : $conf->global->TAKEPOS_NB_MAXCATEG);
$MAXPRODUCT = (empty($conf->global->TAKEPOS_NB_MAXPRODUCT) ? $maxproductbydefaultforthisdevice : $conf->global->TAKEPOS_NB_MAXPRODUCT);
/*
$constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
$soc = new Societe($db);
if ($invoice->socid > 0) $soc->fetch($invoice->socid);
else $soc->fetch($conf->global->$constforcompanyid);
*/
// Security check
$result = restrictedArea($user, 'takepos', 0, '');
/*
* View
*/
$form = new Form($db);
// Title
$title = 'TakePOS - Dolibarr '.DOL_VERSION;
if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
$title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
}
$head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
?>
<link rel="stylesheet" href="css/pos.css.php">
<link rel="stylesheet" href="css/colorbox.css" type="text/css" media="screen" />
<?php
if ($conf->global->TAKEPOS_COLOR_THEME == 1) {
print '<link rel="stylesheet" href="css/colorful.css">';
}
?>
<script type="text/javascript" src="js/jquery.colorbox-min.js"></script> <!-- TODO It seems we don't need this -->
<script language="javascript">
<?php
$categories = $categorie->get_full_arbo('product', (($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) ? $conf->global->TAKEPOS_ROOT_CATEGORY_ID : 0), 1);
// Search root category to know its level
//$conf->global->TAKEPOS_ROOT_CATEGORY_ID=0;
$levelofrootcategory = 0;
if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) {
foreach ($categories as $key => $categorycursor) {
if ($categorycursor['id'] == $conf->global->TAKEPOS_ROOT_CATEGORY_ID) {
$levelofrootcategory = $categorycursor['level'];
break;
}
}
}
$levelofmaincategories = $levelofrootcategory + 1;
$maincategories = array();
$subcategories = array();
foreach ($categories as $key => $categorycursor) {
if ($categorycursor['level'] == $levelofmaincategories) {
$maincategories[$key] = $categorycursor;
} else {
$subcategories[$key] = $categorycursor;
}
}
$maincategories = dol_sort_array($maincategories, 'label');
$subcategories = dol_sort_array($subcategories, 'label');
?>
var categories = <?php echo json_encode($maincategories); ?>;
var subcategories = <?php echo json_encode($subcategories); ?>;
var currentcat;
var pageproducts=0;
var pagecategories=0;
var pageactions=0;
var place="<?php echo $place; ?>";
var editaction="qty";
var editnumber="";
var invoiceid=0;
var search2_timer=null;
/*
var app = this;
app.hasKeyboard = false;
this.keyboardPress = function() {
app.hasKeyboard = true;
$(window).unbind("keyup", app.keyboardPress);
localStorage.hasKeyboard = true;
console.log("has keyboard!")
}
$(window).on("keyup", app.keyboardPress)
if(localStorage.hasKeyboard) {
app.hasKeyboard = true;
$(window).unbind("keyup", app.keyboardPress);
console.log("has keyboard from localStorage")
}
*/
function closeTerminal(modal) {
$.post("<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=closeTerminal", function(data) { if (modal) ModalBox('ModalTerminal'); });
}
function ClearSearch(clearSearchResults) {
console.log("ClearSearch");
$("#search").val('');
<?php if ($conf->browser->layout == 'classic') { ?>
setFocusOnSearchField();
<?php } ?>
if (typeof clearSearchResults != "undefined") $("#search").trigger('keyup');
}
// 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
function setFocusOnSearchField() {
console.log("Call setFocusOnSearchField in page index.php");
<?php if ($conf->browser->layout == 'classic') { ?>
console.log("has keyboard from localStorage, so we can force focus on search field");
$("#search").focus();
<?php } ?>
}
function PrintCategories(first) {
console.log("PrintCategories");
for (i = 0; i < <?php echo ($MAXCATEG - 2); ?>; i++) {
if (typeof (categories[parseInt(i)+parseInt(first)]) == "undefined")
{
$("#catdivdesc"+i).hide();
$("#catdesc"+i).text("");
$("#catimg"+i).attr("src","genimg/empty.png");
$("#catwatermark"+i).hide();
$("#catdiv"+i).attr('class', 'wrapper divempty');
continue;
}
$("#catdivdesc"+i).show();
<?php
if ($conf->global->TAKEPOS_SHOW_CATEGORY_DESCRIPTION == 1) { ?>
$("#catdesc"+i).html(categories[parseInt(i)+parseInt(first)]['label'].bold() + ' - ' + categories[parseInt(i)+parseInt(first)]['description']);
<?php } else { ?>
$("#catdesc"+i).text(categories[parseInt(i)+parseInt(first)]['label']);
<?php } ?>
$("#catimg"+i).attr("src","genimg/index.php?query=cat&id="+categories[parseInt(i)+parseInt(first)]['rowid']);
$("#catdiv"+i).data("rowid",categories[parseInt(i)+parseInt(first)]['rowid']);
$("#catdiv"+i).attr('class', 'wrapper');
$("#catwatermark"+i).show();
}
}
function MoreCategories(moreorless) {
console.log("MoreCategories moreorless="+moreorless+" pagecategories="+pagecategories);
if (moreorless=="more") {
$('#catimg15').animate({opacity: '0.5'}, 1);
$('#catimg15').animate({opacity: '1'}, 100);
pagecategories=pagecategories+1;
}
if (moreorless=="less") {
$('#catimg14').animate({opacity: '0.5'}, 1);
$('#catimg14').animate({opacity: '1'}, 100);
if (pagecategories==0) return; //Return if no less pages
pagecategories=pagecategories-1;
}
if (typeof (categories[<?php echo ($MAXCATEG - 2); ?> * pagecategories] && moreorless=="more") == "undefined"){ // Return if no more pages
pagecategories=pagecategories-1;
return;
}
for (i = 0; i < <?php echo ($MAXCATEG - 2); ?>; i++) {
if (typeof (categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]) == "undefined") {
$("#catdivdesc"+i).hide();
$("#catdesc"+i).text("");
$("#catimg"+i).attr("src","genimg/empty.png");
$("#catwatermark"+i).hide();
continue;
}
$("#catdivdesc"+i).show();
<?php
if ($conf->global->TAKEPOS_SHOW_CATEGORY_DESCRIPTION == 1) { ?>
$("#catdesc"+i).html(categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['label'].bold() + ' - ' + categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['description']);
<?php } else { ?>
$("#catdesc"+i).text(categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['label']);
<?php } ?>
$("#catimg"+i).attr("src","genimg/index.php?query=cat&id="+categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['rowid']);
$("#catdiv"+i).data("rowid",categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['rowid']);
$("#catwatermark"+i).show();
}
ClearSearch();
}
// LoadProducts
function LoadProducts(position, issubcat) {
console.log("LoadProducts");
var maxproduct = <?php echo ($MAXPRODUCT - 2); ?>;
if (position=="supplements") currentcat="supplements";
else
{
$('#catimg'+position).animate({opacity: '0.5'}, 1);
$('#catimg'+position).animate({opacity: '1'}, 100);
if (issubcat==true) currentcat=$('#prodiv'+position).data('rowid');
else currentcat=$('#catdiv'+position).data('rowid');
}
if (currentcat == undefined) return;
pageproducts=0;
ishow=0; //product to show counter
jQuery.each(subcategories, function(i, val) {
if (currentcat==val.fk_parent) {
$("#prodivdesc"+ishow).show();
<?php if ($conf->global->TAKEPOS_SHOW_CATEGORY_DESCRIPTION == 1) { ?>
$("#prodesc"+ishow).html(val.label.bold() + ' - ' + val.description);
<?php } else { ?>
$("#prodesc"+ishow).text(val.label);
<?php } ?>
$("#probutton"+ishow).text(val.label);
$("#probutton"+ishow).show();
$("#proprice"+ishow).attr("class", "hidden");
$("#proprice"+ishow).html("");
$("#proimg"+ishow).attr("src","genimg/index.php?query=cat&id="+val.rowid);
$("#prodiv"+ishow).data("rowid",val.rowid);
$("#prodiv"+ishow).data("iscat",1);
$("#prowatermark"+ishow).val("...").show();
ishow++;
}
});
idata=0; //product data counter
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&category='+currentcat, function(data) {
console.log("Call ajax.php (in LoadProducts) to get Products of category "+currentcat+" then loop on result to fill image thumbs");
console.log(data);
while (ishow < maxproduct) {
//console.log("ishow"+ishow+" idata="+idata);
console.log(data[idata]);
if (typeof (data[idata]) == "undefined") {
<?php if (!$conf->global->TAKEPOS_HIDE_PRODUCT_IMAGES) {
echo '$("#prodivdesc"+ishow).hide();';
echo '$("#prodesc"+ishow).text("");';
echo '$("#proimg"+ishow).attr("title","");';
echo '$("#proimg"+ishow).attr("src","genimg/empty.png");';
} else {
echo '$("#probutton"+ishow).hide();';
echo '$("#probutton"+ishow).text("");';
}?>
$("#proprice"+ishow).attr("class", "hidden");
$("#proprice"+ishow).html("");
$("#prodiv"+ishow).data("rowid","");
$("#prodiv"+ishow).attr("class","wrapper2 divempty");
$("#prowatermark"+ishow).hide();
ishow++; //Next product to show after print data product
}
else if ((data[idata]['status']) == "1") { // Only show products with status=1 (for sell)
<?php
$titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[idata]['ref']";
$titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[idata]['barcode']";
?>
var titlestring = <?php echo $titlestring; ?>;
<?php if (!$conf->global->TAKEPOS_HIDE_PRODUCT_IMAGES) {
echo '$("#prodivdesc"+ishow).show();';
if ($conf->global->TAKEPOS_SHOW_PRODUCT_REFERENCE == 1) {
echo '$("#prodesc"+ishow).html(data[parseInt(idata)][\'ref\'].bold() + \' - \' + data[parseInt(idata)][\'label\']);';
} else {
echo '$("#prodesc"+ishow).text(data[parseInt(idata)][\'label\']);';
}
echo '$("#proimg"+ishow).attr("title", titlestring);';
echo '$("#proimg"+ishow).attr("src", "genimg/index.php?query=pro&id="+data[idata][\'id\']);';
} else {
echo '$("#probutton"+ishow).show();';
echo '$("#probutton"+ishow).text(data[parseInt(idata)][\'label\']);';
}
?>
if (data[parseInt(idata)]['price_formated']) {
$("#proprice"+ishow).attr("class", "productprice");
$("#proprice"+ishow).html(data[parseInt(idata)]['price_formated']);
}
$("#prodiv"+ishow).data("rowid", data[idata]['id']);
$("#prodiv"+ishow).data("iscat", 0);
$("#prodiv"+ishow).attr("class","wrapper2");
$("#prowatermark"+ishow).hide();
<?php
// Add js from hooks
$parameters=array();
$parameters['caller'] = 'loadProducts';
$hookmanager->executeHooks('completeJSProductDisplay', $parameters);
print $hookmanager->resPrint;
?>
ishow++; //Next product to show after print data product
}
//console.log("Hide the prowatermark for ishow="+ishow);
idata++; //Next data everytime
}
});
ClearSearch();
}
function MoreProducts(moreorless) {
console.log("MoreProducts");
var maxproduct = <?php echo ($MAXPRODUCT - 2); ?>;
if ($('#search_pagination').val() != '') return Search2('<?php echo $keyCodeForEnter; ?>', moreorless);
if (moreorless=="more"){
$('#proimg31').animate({opacity: '0.5'}, 1);
$('#proimg31').animate({opacity: '1'}, 100);
pageproducts=pageproducts+1;
}
if (moreorless=="less"){
$('#proimg30').animate({opacity: '0.5'}, 1);
$('#proimg30').animate({opacity: '1'}, 100);
if (pageproducts==0) return; //Return if no less pages
pageproducts=pageproducts-1;
}
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&category='+currentcat, function(data) {
console.log("Call ajax.php (in MoreProducts) to get Products of category "+currentcat);
if (typeof (data[(maxproduct * pageproducts)]) == "undefined" && moreorless=="more"){ // Return if no more pages
pageproducts=pageproducts-1;
return;
}
idata=<?php echo ($MAXPRODUCT - 2); ?> * pageproducts; //product data counter
ishow=0; //product to show counter
while (ishow < maxproduct) {
if (typeof (data[idata]) == "undefined") {
$("#prodivdesc"+ishow).hide();
$("#prodesc"+ishow).text("");
$("#probutton"+ishow).text("");
$("#probutton"+ishow).hide();
$("#proprice"+ishow).attr("class", "");
$("#proprice"+ishow).html("");
$("#proimg"+ishow).attr("src","genimg/empty.png");
$("#prodiv"+ishow).data("rowid","");
ishow++; //Next product to show after print data product
}
else if ((data[idata]['status']) == "1") {
//Only show products with status=1 (for sell)
$("#prodivdesc"+ishow).show();
<?php
if ($conf->global->TAKEPOS_SHOW_PRODUCT_REFERENCE == 1) { ?>
$("#prodesc"+ishow).html(data[parseInt(idata)]['ref'].bold() + ' - ' + data[parseInt(idata)]['label']);
<?php } else { ?>
$("#prodesc"+ishow).text(data[parseInt(idata)]['label']);
<?php } ?>
$("#probutton"+ishow).text(data[parseInt(idata)]['label']);
$("#probutton"+ishow).show();
if (data[parseInt(idata)]['price_formated']) {
$("#proprice"+ishow).attr("class", "productprice");
$("#proprice"+ishow).html(data[parseInt(idata)]['price_formated']);
}
$("#proimg"+ishow).attr("src","genimg/index.php?query=pro&id="+data[idata]['id']);
$("#prodiv"+ishow).data("rowid",data[idata]['id']);
$("#prodiv"+ishow).data("iscat",0);
ishow++; //Next product to show after print data product
}
$("#prowatermark"+ishow).hide();
idata++; //Next data everytime
}
});
ClearSearch();
}
function ClickProduct(position) {
console.log("ClickProduct");
$('#proimg'+position).animate({opacity: '0.5'}, 1);
$('#proimg'+position).animate({opacity: '1'}, 100);
if ($('#prodiv'+position).data('iscat')==1){
console.log("Click on a category at position "+position);
LoadProducts(position, true);
}
else{
idproduct=$('#prodiv'+position).data('rowid');
console.log("Click on product at position "+position+" for idproduct "+idproduct);
if (idproduct=="") return;
// Call page invoice.php to generate the section with product lines
$("#poslines").load("invoice.php?action=addline&place="+place+"&idproduct="+idproduct+"&selectedline="+selectedline, function() {
//$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
});
}
ClearSearch();
}
function ChangeThirdparty(idcustomer) {
console.log("ChangeThirdparty");
// Call page list.php to change customer
$("#poslines").load("../societe/list.php?action=change&type=t&contextpage=poslist&idcustomer="+idcustomer+"&place="+place+"", function() {
});
ClearSearch();
}
function deleteline() {
console.log("Delete line");
$("#poslines").load("invoice.php?action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
//$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
});
ClearSearch();
}
function Customer(numterm) {
console.log("Open box to select the thirdparty place="+place);
$.colorbox({href:"../societe/list.php?type=t&contextpage=poslist&nomassaction=1&place="+place, width:"90%", height:"80%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Customer"); ?>", onClosed : function() { if (numterm) $.post("<?php echo DOL_URL_ROOT ; ?>/takepos/ajax/ajax.php?action=lockTerminal&term=" + numterm);}});
}
function Contact(numterm) {
console.log("Open box to select the contact place="+place);
$.colorbox({href:"../contact/list.php?type=c&contextpage=poslist&nomassaction=1&place="+place, width:"90%", height:"80%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("TakePOSContact"); ?>", onClosed : function() { if (numterm) $.post("<?php echo DOL_URL_ROOT ; ?>/takepos/ajax/ajax.php?action=lockTerminal&term=" + numterm);}});
}
function History()
{
console.log("Open box to select the history");
$.colorbox({href:"../compta/facture/list.php?contextpage=poslist", width:"90%", height:"80%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("History"); ?>"});
}
function Reduction() {
invoiceid = $("#invoiceid").val();
console.log("Open popup to enter reduction on invoiceid="+invoiceid);
$.colorbox({href:"reduction.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
}
function CloseBill() {
<?php if ($conf->global->TAKEPOS_NO_GENERIC_THIRDPARTY) { ?>
if ($("#idcustomer").val() == "") {
alert("<?php echo $langs->trans('TakePosCustomerMandatory'); ?>");
<?php if ($conf->global->TAKEPOS_CHOOSE_CONTACT) { ?>
Contact();
<?php } else { ?>
Customer();
<?php } ?>
return;
}
<?php }
if ($conf->global->TAKEPOS_USE_NEW_PAYMENT_SCREEN) {
$payurl = "pay2.php";
} else {
$payurl = "pay.php";
}
?>
invoiceid = $("#invoiceid").val();
console.log("Open popup to enter payment on invoiceid="+invoiceid);
<?php if ($conf->global->TAKEPOS_USE_NEW_PAYMENT_SCREEN) { ?>
var originalClose = $.colorbox.close;
$.colorbox.close = function() {
if ( ! $.colorbox.paymentok) {
var response;
response = confirm("<?php echo $langs->trans('ConfirmClosePayment'); ?>");
if(!response){
return; // Do nothing.
}
}
originalClose();
$.colorbox.close = originalClose;
};
<?php } ?>
$.colorbox({href:"<?php echo $payurl; ?>?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:"" });
}
function Floors() {
console.log("Open box to select floor place="+place);
$.colorbox({href:"floors.php?place="+place, width:"90%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Floors"); ?>"});
}
function FreeZone() {
console.log("Open box to enter a free product");
$.colorbox({href:"freezone.php?action=freezone&place="+place, width:"80%", height:"200px", transition:"none", iframe:"true", title:"<?php echo $langs->trans("FreeZone"); ?>"});
}
function TakeposOrderNotes() {
console.log("Open box to order notes");
ModalBox('ModalNote');
$("#textinput").focus();
}
function Refresh() {
console.log("Refresh by reloading place="+place+" invoiceid="+invoiceid);
$("#poslines").load("invoice.php?place="+place+"&invoiceid="+invoiceid, function() {
//$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
});
}
function New() {
// If we go here,it means $conf->global->TAKEPOS_BAR_RESTAURANT is not defined
invoiceid = $("#invoiceid").val();
console.log("New with place = <?php echo $place; ?>, js place="+place+", invoiceid="+invoiceid);
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getInvoice&id='+invoiceid, function(data) {
var r;
if (parseInt(data['paye']) === 1) {
r = true;
} else {
r = confirm('<?php echo ($place > 0 ? $langs->transnoentitiesnoconv("ConfirmDeletionOfThisPOSSale") : $langs->transnoentitiesnoconv("ConfirmDiscardOfThisPOSSale")); ?>');
}
if (r == true) {
// Reload section with invoice lines
$("#poslines").load("invoice.php?action=delete&token=<?php echo newToken(); ?>&place=" + place, function () {
//$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
});
ClearSearch();
$("#idcustomer").val("");
<?php if ( ! getDolGlobalString('TAKEPOS_CHOOSE_CONTACT')) { ?>
Customer();
<?php } else { ?>
Contact();
<?php } ?>
}
});
}
/**
* Search products
*
* @param {int} keyCodeForEnter Key code for "enter"
* return {void}
*/
function Search2(keyCodeForEnter, moreorless) {
console.log("Search2 Call ajax search to replace products keyCodeForEnter="+keyCodeForEnter);
var search_term = $('#search').val();
var search_start = 0;
var search_limit = <?php echo $MAXPRODUCT - 2; ?>;
if (moreorless != null) {
search_term = $('#search_pagination').val();
search_start = $('#search_start_'+moreorless).val();
}
if (search_term == '') {
$("[id^=prowatermark]").html("");
$("[id^=prodesc]").text("");
$("[id^=probutton]").text("");
$("[id^=probutton]").hide();
$("[id^=proprice]").attr("class", "hidden");
$("[id^=proprice]").html("");
$("[id^=proimg]").attr("src", "genimg/empty.png");
$("[id^=prodiv]").data("rowid", "");
return;
}
var search = false;
var eventKeyCode = window.event.keyCode;
if (keyCodeForEnter == '' || eventKeyCode == keyCodeForEnter) {
search = true;
}
if (search === true) {
// temporization time to give time to type
if (search2_timer) {
clearTimeout(search2_timer);
}
search2_timer = setTimeout(function(){
pageproducts = 0;
jQuery(".wrapper2 .catwatermark").hide();
var nbsearchresults = 0;
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&term=' + search_term + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) {
for (i = 0; i < <?php echo ($MAXPRODUCT - 2) ?>; i++) {
if (typeof (data[i]) == "undefined") {
$("#prowatermark" + i).html("");
$("#prodesc" + i).text("");
$("#probutton" + i).text("");
$("#probutton" + i).hide();
$("#proprice" + i).attr("class", "hidden");
$("#proprice" + i).html("");
$("#proimg" + i).attr("src", "genimg/empty.png");
$("#prodiv" + i).data("rowid", "");
continue;
}
<?php
$titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[i]['ref']";
$titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[i]['barcode']";
?>
var titlestring = <?php echo $titlestring; ?>;
<?php
if ($conf->global->TAKEPOS_SHOW_PRODUCT_REFERENCE == 1) { ?>
$("#prodesc" + i).html(data[i]['ref'].bold() + ' - ' + data[i]['label']);
<?php } else { ?>
$("#prodesc" + i).text(data[i]['label']);
<?php } ?>
$("#prodivdesc" + i).show();
$("#probutton" + i).text(data[i]['label']);
$("#probutton" + i).show();
if (data[i]['price_formated']) {
$("#proprice" + i).attr("class", "productprice");
$("#proprice" + i).html(data[i]['price_formated']);
}
$("#proimg" + i).attr("title", titlestring);
$("#proimg" + i).attr("src", "genimg/index.php?query=pro&id=" + data[i]['rowid']);
$("#prodiv" + i).data("rowid", data[i]['rowid']);
$("#prodiv" + i).data("iscat", 0);
<?php
// Add js from hooks
$parameters=array();
$parameters['caller'] = 'search2';
$hookmanager->executeHooks('completeJSProductDisplay', $parameters);
print $hookmanager->resPrint;
?>
nbsearchresults++;
}
searching = false;
}).always(function (data) {
// If there is only 1 answer
if ($('#search').val().length > 0 && data.length == 1) {
console.log($('#search').val()+' - '+data[0]['barcode']);
if ($('#search').val() == data[0]['barcode'] && 'thirdparty' == data[0]['object']) {
console.log("There is only 1 answer with barcode matching the search, so we change the thirdparty "+data[0]['rowid']);
ChangeThirdparty(data[0]['rowid']);
}
else if ($('#search').val() == data[0]['barcode'] && 'product' == data[0]['object']) {
console.log("There is only 1 answer with barcode matching the search, so we add the product in basket");
ClickProduct(0);
}
}
if (eventKeyCode == keyCodeForEnter){
if (data.length == 0) {
$('#search').val('<?php
$langs->load('errors');
echo dol_escape_js($langs->trans("ErrorRecordNotFound"));
?>');
$('#search').select();
}
else ClearSearch();
}
// memorize search_term and start for pagination
$("#search_pagination").val($("#search").val());
if (search_start == 0) {
$("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").hide();
}
else {
$("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").show();
var search_start_less = Math.max(0, parseInt(search_start) - parseInt(<?php echo $MAXPRODUCT - 2;?>));
$("#search_start_less").val(search_start_less);
}
if (nbsearchresults != <?php echo $MAXPRODUCT - 2; ?>) {
$("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").hide();
}
else {
$("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").show();
var search_start_more = parseInt(search_start) + parseInt(<?php echo $MAXPRODUCT - 2;?>);
$("#search_start_more").val(search_start_more);
}
});
}, 500); // 500ms delay
}
}
/**
* Search category
*
* @param {int} keyCodeForEnter Key code for "enter"
* return {void}
*/
function searchCategory(keyCodeForEnter) {
console.log("searchCategory Call ajax search to replace products keyCodeForEnter="+keyCodeForEnter);
var search = false;
var eventKeyCode = window.event.keyCode;
if (typeof keyCodeForEnter === 'undefined' || eventKeyCode == keyCodeForEnter) {
search = true;
}
if (search === true) {
pageproducts = 0;
jQuery(".wrapper2 .catwatermark").hide();
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search_category&term=' + $('#search_category').val(), function (data) {
for (i = 0; i < <?php echo $MAXCATEG ?>; i++) {
if (typeof (data[i]) == "undefined") {
$("#catdesc" + i).text("");
$("#catimg" + i).attr("src", "genimg/empty.png");
$("#catdiv" + i).data("rowid", "");
continue;
}
<?php
$titlestring = "'".dol_escape_js($langs->transnoentities('Label').': ')."' + data[i]['label']";
$titlestring .= " + ' - ".dol_escape_js($langs->trans("Description").': ')."' + data[i]['description']";
?>
var titlestring = <?php echo $titlestring; ?>;
<?php if ($conf->global->TAKEPOS_SHOW_CATEGORY_DESCRIPTION == 1) { ?>
$("#catdesc" + i).html(data[i]['label'].bold() + ' - ' + data[i]['description']);
<?php } else { ?>
$("#catdesc" + i).text(data[i]['label']);
<?php } ?>
$("#catdivdesc" + i).show();
$("#catimg" + i).attr("title", titlestring);
$("#catimg" + i).attr("src", "genimg/index.php?query=cat&id=" + data[i]['rowid']);
$("#catdiv" + i).data("rowid", data[i]['rowid']);
}
}).always(function (data) {
if (eventKeyCode == keyCodeForEnter){
if (data.length == 0) {
$('#search_category').val('<?php
$langs->load('errors');
echo dol_escape_js($langs->trans("ErrorRecordNotFound"));
?>');
$('#search_category').select();
}
else ClearSearch();
}
});
}
}
function Edit(number) {
if (typeof(selectedtext) == "undefined") return; // We click on an action on the number pad but there is no line selected
var text=selectedtext+"<br> ";
if (number=='c'){
editnumber="";
Refresh();
return;
}
else if (number=='qty'){
console.log("Edit "+number);
if (editaction=='qty' && editnumber!=""){
$("#poslines").load("invoice.php?action=updateqty&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
editnumber="";
//$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
$("#qty").html("<?php echo $langs->trans("Qty"); ?>");
});
setFocusOnSearchField();
return;
}
else {
editaction="qty";
}
}
else if (number=='p'){
console.log("Edit "+number);
if (editaction=='p' && editnumber!=""){
$("#poslines").load("invoice.php?action=updateprice&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
editnumber="";
//$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
$("#price").html("<?php echo $langs->trans("Price"); ?>");
});
ClearSearch();
return;
}
else {
editaction="p";
}
}
else if (number=='r'){
console.log("Edit "+number);
if (editaction=='r' && editnumber!=""){
$("#poslines").load("invoice.php?action=updatereduction&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
editnumber="";
//$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
$("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>");
});
ClearSearch();
return;
}
else {
editaction="r";
}
}
else {
editnumber=editnumber+number;
}
if (editaction=='qty'){
text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Qty").": "; ?>";
$("#qty").html("OK");
$("#price").html("<?php echo $langs->trans("Price"); ?>");
$("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>");
}
if (editaction=='p'){
text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Price").": "; ?>";
$("#qty").html("<?php echo $langs->trans("Qty"); ?>");
$("#price").html("OK");
$("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>");
}
if (editaction=='r'){
text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("ReductionShort").": "; ?>";
$("#qty").html("<?php echo $langs->trans("Qty"); ?>");
$("#price").html("<?php echo $langs->trans("Price"); ?>");
$("#reduction").html("OK");
}
$('#'+selectedline).find("td:first").html(text+editnumber);
}
function TakeposPrintingOrder(){
console.log("TakeposPrintingOrder");
$("#poslines").load("invoice.php?action=order&place="+place, function() {
//$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
});
}
function TakeposPrintingTemp(){
console.log("TakeposPrintingTemp");
$("#poslines").load("invoice.php?action=temp&place="+place, function() {
//$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
});
}
function OpenDrawer(){
console.log("OpenDrawer call ajax url http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>:8111/print");
$.ajax({
type: "POST",
data: { token: 'notrequired' },
<?php
if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
echo "url: '".$conf->global->TAKEPOS_PRINT_SERVER."/printer/drawer.php',";
} else {
echo "url: 'http://".$conf->global->TAKEPOS_PRINT_SERVER.":8111/print',";
}
?>
data: "opendrawer"
});
}
function DolibarrOpenDrawer() {
console.log("DolibarrOpenDrawer call ajax url /takepos/ajax/ajax.php?action=opendrawer&term=<?php print urlencode($_SESSION["takeposterminal"]); ?>");
$.ajax({
type: "GET",
data: { token: '<?php echo currentToken(); ?>' },
url: "<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=opendrawer&term='.urlencode($_SESSION["takeposterminal"]); ?>",
});
}
function MoreActions(totalactions){
if (pageactions==0){
pageactions=1;
for (i = 0; i <= totalactions; i++){
if (i<12) $("#action"+i).hide();
else $("#action"+i).show();
}
}
else if (pageactions==1){
pageactions=0;
for (i = 0; i <= totalactions; i++){
if (i<12) $("#action"+i).show();
else $("#action"+i).hide();
}
}
}
function ControlCashOpening()
{
$.colorbox({href:"../compta/cashcontrol/cashcontrol_card.php?action=create&contextpage=takepos", width:"90%", height:"60%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("NewCashFence"); ?>"});
}
function CloseCashFence(rowid)
{
$.colorbox({href:"../compta/cashcontrol/cashcontrol_card.php?id="+rowid+"&contextpage=takepos", width:"90%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("NewCashFence"); ?>"});
}
function CashReport(rowid)
{
$.colorbox({href:"../compta/cashcontrol/report.php?id="+rowid+"&contextpage=takepos", width:"60%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("CashReport"); ?>"});
}
// TakePOS Popup
function ModalBox(ModalID)
{
var modal = document.getElementById(ModalID);
modal.style.display = "block";
}
function DirectPayment(){
console.log("DirectPayment");
$("#poslines").load("invoice.php?place="+place+"&action=valid&pay=LIQ", function() {
});
}
function FullScreen() {
document.documentElement.requestFullscreen();
}
function WeighingScale(){
console.log("Weighing Scale");
$.ajax({
type: "POST",
data: { token: 'notrequired' },
url: '<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>/scale/index.php',
})
.done(function( editnumber ) {
$("#poslines").load("invoice.php?action=updateqty&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
editnumber="";
});
});
}
$( document ).ready(function() {
<?php
// get user authorized terminals
$nb_auth_terms = 0;