dolibarr  16.0.1
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
3  * Copyright (C) 2019 Josep LluĂ­s Amador <joseplluis@lliuretic.cat>
4  * Copyright (C) 2020 Thibault FOUCART <support@ptibogxiv.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
27 //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
28 //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
29 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
30 if (!defined('NOCSRFCHECK')) {
31  define('NOCSRFCHECK', '1');
32 }
33 if (!defined('NOTOKENRENEWAL')) {
34  define('NOTOKENRENEWAL', '1');
35 }
36 if (!defined('NOREQUIREMENU')) {
37  define('NOREQUIREMENU', '1');
38 }
39 if (!defined('NOREQUIREHTML')) {
40  define('NOREQUIREHTML', '1');
41 }
42 if (!defined('NOREQUIREAJAX')) {
43  define('NOREQUIREAJAX', '1');
44 }
45 
46 require '../main.inc.php'; // Load $user and permissions
47 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
48 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
49 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
50 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
51 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
52 require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
53 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
54 
55 $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant or multiple sales
56 $action = GETPOST('action', 'aZ09');
57 $setterminal = GETPOST('setterminal', 'int');
58 $setcurrency = GETPOST('setcurrency', 'aZ09');
59 
60 if (empty($_SESSION["takeposterminal"])) {
61  if (getDolGlobalInt('TAKEPOS_NUM_TERMINALS') == 1) {
62  $_SESSION["takeposterminal"] = 1; // Use terminal 1 if there is only 1 terminal
63  } elseif (!empty($_COOKIE["takeposterminal"])) {
64  $_SESSION["takeposterminal"] = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE["takeposterminal"]); // Restore takeposterminal from previous session
65  }
66 }
67 
68 if ($setterminal > 0) {
69  $_SESSION["takeposterminal"] = $setterminal;
70  setcookie("takeposterminal", $setterminal, (time() + (86400 * 354)), '/', null, (empty($dolibarr_main_force_https) ? false : true), true); // Permanent takeposterminal var in a cookie
71 }
72 
73 if ($setcurrency != "") {
74  $_SESSION["takeposcustomercurrency"] = $setcurrency;
75  // We will recalculate amount for foreign currency at next call of invoice.php when $_SESSION["takeposcustomercurrency"] differs from invoice->multicurrency_code.
76 }
77 
78 $_SESSION["urlfrom"] = '/takepos/index.php';
79 
80 $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter", "banks"));
81 
82 $categorie = new Categorie($db);
83 
84 $maxcategbydefaultforthisdevice = 12;
85 $maxproductbydefaultforthisdevice = 24;
86 if ($conf->browser->layout == 'phone') {
87  $maxcategbydefaultforthisdevice = 8;
88  $maxproductbydefaultforthisdevice = 16;
89  //REDIRECT TO BASIC LAYOUT IF TERMINAL SELECTED AND BASIC MOBILE LAYOUT ENABLED
90  if ($_SESSION["takeposterminal"] != "" && $conf->global->TAKEPOS_PHONE_BASIC_LAYOUT == 1) {
91  $_SESSION["basiclayout"] = 1;
92  header("Location: phone.php?mobilepage=invoice");
93  exit;
94  }
95 }
96 $MAXCATEG = (empty($conf->global->TAKEPOS_NB_MAXCATEG) ? $maxcategbydefaultforthisdevice : $conf->global->TAKEPOS_NB_MAXCATEG);
97 $MAXPRODUCT = (empty($conf->global->TAKEPOS_NB_MAXPRODUCT) ? $maxproductbydefaultforthisdevice : $conf->global->TAKEPOS_NB_MAXPRODUCT);
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($conf->global->$constforcompanyid);
104 */
105 
106 // Security check
107 $result = restrictedArea($user, 'takepos', 0, '');
108 
109 
110 
111 /*
112  * View
113  */
114 
115 $form = new Form($db);
116 
117 $disablejs = 0;
118 $disablehead = 0;
119 $arrayofjs = array();
120 $arrayofcss = array();
121 
122 // Title
123 $title = 'TakePOS - Dolibarr '.DOL_VERSION;
124 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
125  $title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
126 }
127 $head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
128 <meta name="apple-mobile-web-app-capable" content="yes">
129 <meta name="mobile-web-app-capable" content="yes">
130 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
131 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
132 
133 ?>
134 <link rel="stylesheet" href="css/pos.css.php">
135 <link rel="stylesheet" href="css/colorbox.css" type="text/css" media="screen" />
136 <?php
137 if (getDolGlobalInt('TAKEPOS_COLOR_THEME') == 1) {
138  print '<link rel="stylesheet" href="css/colorful.css">';
139 }
140 ?>
141 <script type="text/javascript" src="js/jquery.colorbox-min.js"></script> <!-- TODO It seems we don't need this -->
142 <script type="text/javascript">
143 <?php
144 $categories = $categorie->get_full_arbo('product', ((getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') > 0) ? getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') : 0), 1);
145 
146 
147 // Search root category to know its level
148 //$conf->global->TAKEPOS_ROOT_CATEGORY_ID=0;
149 $levelofrootcategory = 0;
150 if (getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') > 0) {
151  foreach ($categories as $key => $categorycursor) {
152  if ($categorycursor['id'] == getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID')) {
153  $levelofrootcategory = $categorycursor['level'];
154  break;
155  }
156  }
157 }
158 
159 $levelofmaincategories = $levelofrootcategory + 1;
160 
161 $maincategories = array();
162 $subcategories = array();
163 foreach ($categories as $key => $categorycursor) {
164  if ($categorycursor['level'] == $levelofmaincategories) {
165  $maincategories[$key] = $categorycursor;
166  } else {
167  $subcategories[$key] = $categorycursor;
168  }
169 }
170 
171 $maincategories = dol_sort_array($maincategories, 'label');
172 $subcategories = dol_sort_array($subcategories, 'label');
173 ?>
174 
175 var categories = <?php echo json_encode($maincategories); ?>;
176 var subcategories = <?php echo json_encode($subcategories); ?>;
177 
178 var currentcat;
179 var pageproducts=0;
180 var pagecategories=0;
181 var pageactions=0;
182 var place="<?php echo $place; ?>";
183 var editaction="qty";
184 var editnumber="";
185 var invoiceid=0;
186 var search2_timer=null;
187 
188 /*
189 var app = this;
190 app.hasKeyboard = false;
191 this.keyboardPress = function() {
192  app.hasKeyboard = true;
193  $(window).unbind("keyup", app.keyboardPress);
194  localStorage.hasKeyboard = true;
195  console.log("has keyboard!")
196 }
197 $(window).on("keyup", app.keyboardPress)
198 if(localStorage.hasKeyboard) {
199  app.hasKeyboard = true;
200  $(window).unbind("keyup", app.keyboardPress);
201  console.log("has keyboard from localStorage")
202 }
203 */
204 
205 function ClearSearch() {
206  console.log("ClearSearch");
207  $("#search").val('');
208  $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
209  $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
210  $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>").removeClass('clicked');
211  <?php if ($conf->browser->layout == 'classic') { ?>
212  setFocusOnSearchField();
213  <?php } ?>
214 }
215 
216 // 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
217 function setFocusOnSearchField() {
218  console.log("Call setFocusOnSearchField in page index.php");
219  <?php if ($conf->browser->layout == 'classic') { ?>
220  console.log("has keyboard from localStorage, so we can force focus on search field");
221  $("#search").focus();
222  <?php } ?>
223 }
224 
225 function PrintCategories(first) {
226  console.log("PrintCategories");
227  for (i = 0; i < <?php echo ($MAXCATEG - 2); ?>; i++) {
228  if (typeof (categories[parseInt(i)+parseInt(first)]) == "undefined")
229  {
230  $("#catdivdesc"+i).hide();
231  $("#catdesc"+i).text("");
232  $("#catimg"+i).attr("src","genimg/empty.png");
233  $("#catwatermark"+i).hide();
234  $("#catdiv"+i).attr('class', 'wrapper divempty');
235  continue;
236  }
237  $("#catdivdesc"+i).show();
238  <?php
239  if (getDolGlobalString('TAKEPOS_SHOW_CATEGORY_DESCRIPTION') == 1) { ?>
240  $("#catdesc"+i).html(categories[parseInt(i)+parseInt(first)]['label'].bold() + ' - ' + categories[parseInt(i)+parseInt(first)]['description']);
241  <?php } else { ?>
242  $("#catdesc"+i).text(categories[parseInt(i)+parseInt(first)]['label']);
243  <?php } ?>
244  $("#catimg"+i).attr("src","genimg/index.php?query=cat&id="+categories[parseInt(i)+parseInt(first)]['rowid']);
245  $("#catdiv"+i).data("rowid",categories[parseInt(i)+parseInt(first)]['rowid']);
246  $("#catdiv"+i).attr('class', 'wrapper');
247  $("#catwatermark"+i).show();
248  }
249 }
250 
251 function MoreCategories(moreorless) {
252  console.log("MoreCategories moreorless="+moreorless+" pagecategories="+pagecategories);
253  if (moreorless=="more") {
254  $('#catimg15').animate({opacity: '0.5'}, 1);
255  $('#catimg15').animate({opacity: '1'}, 100);
256  pagecategories=pagecategories+1;
257  }
258  if (moreorless=="less") {
259  $('#catimg14').animate({opacity: '0.5'}, 1);
260  $('#catimg14').animate({opacity: '1'}, 100);
261  if (pagecategories==0) return; //Return if no less pages
262  pagecategories=pagecategories-1;
263  }
264  if (typeof (categories[<?php echo ($MAXCATEG - 2); ?> * pagecategories] && moreorless=="more") == "undefined"){ // Return if no more pages
265  pagecategories=pagecategories-1;
266  return;
267  }
268  for (i = 0; i < <?php echo ($MAXCATEG - 2); ?>; i++) {
269  if (typeof (categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]) == "undefined") {
270  $("#catdivdesc"+i).hide();
271  $("#catdesc"+i).text("");
272  $("#catimg"+i).attr("src","genimg/empty.png");
273  $("#catwatermark"+i).hide();
274  continue;
275  }
276  $("#catdivdesc"+i).show();
277  <?php
278  if (getDolGlobalString('TAKEPOS_SHOW_CATEGORY_DESCRIPTION') == 1) { ?>
279  $("#catdesc"+i).html(categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['label'].bold() + ' - ' + categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['description']);
280  <?php } else { ?>
281  $("#catdesc"+i).text(categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['label']);
282  <?php } ?>
283  $("#catimg"+i).attr("src","genimg/index.php?query=cat&id="+categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['rowid']);
284  $("#catdiv"+i).data("rowid",categories[i+(<?php echo ($MAXCATEG - 2); ?> * pagecategories)]['rowid']);
285  $("#catwatermark"+i).show();
286  }
287 
288  ClearSearch();
289 }
290 
291 // LoadProducts
292 function LoadProducts(position, issubcat) {
293  console.log("LoadProducts");
294  var maxproduct = <?php echo ($MAXPRODUCT - 2); ?>;
295 
296  if (position=="supplements") currentcat="supplements";
297  else
298  {
299  $('#catimg'+position).animate({opacity: '0.5'}, 1);
300  $('#catimg'+position).animate({opacity: '1'}, 100);
301  if (issubcat==true) currentcat=$('#prodiv'+position).data('rowid');
302  else currentcat=$('#catdiv'+position).data('rowid');
303  }
304  if (currentcat == undefined) return;
305  pageproducts=0;
306  ishow=0; //product to show counter
307 
308  jQuery.each(subcategories, function(i, val) {
309  if (currentcat==val.fk_parent) {
310  $("#prodivdesc"+ishow).show();
311  <?php if (getDolGlobalString('TAKEPOS_SHOW_CATEGORY_DESCRIPTION') == 1) { ?>
312  $("#prodesc"+ishow).html(val.label.bold() + ' - ' + val.description);
313  $("#probutton"+ishow).html(val.label);
314  <?php } else { ?>
315  $("#prodesc"+ishow).text(val.label);
316  $("#probutton"+ishow).text(val.label);
317  <?php } ?>
318  $("#probutton"+ishow).show();
319  $("#proprice"+ishow).attr("class", "hidden");
320  $("#proprice"+ishow).html("");
321  $("#proimg"+ishow).attr("src","genimg/index.php?query=cat&id="+val.rowid);
322  $("#prodiv"+ishow).data("rowid",val.rowid);
323  $("#prodiv"+ishow).data("iscat",1);
324  $("#prowatermark"+ishow).show();
325  ishow++;
326  }
327  });
328 
329  idata=0; //product data counter
330  $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&category='+currentcat, function(data) {
331  console.log("Call ajax.php (in LoadProducts) to get Products of category "+currentcat+" then loop on result to fill image thumbs");
332  console.log(data);
333  while (ishow < maxproduct) {
334  //console.log("ishow"+ishow+" idata="+idata);
335  console.log(data[idata]);
336  if (typeof (data[idata]) == "undefined") {
337  <?php if (!getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
338  echo '$("#prodivdesc"+ishow).hide();';
339  echo '$("#prodesc"+ishow).text("");';
340  echo '$("#proimg"+ishow).attr("title","");';
341  echo '$("#proimg"+ishow).attr("src","genimg/empty.png");';
342  } else {
343  echo '$("#probutton"+ishow).hide();';
344  echo '$("#probutton"+ishow).text("");';
345  }?>
346  $("#proprice"+ishow).attr("class", "hidden");
347  $("#proprice"+ishow).html("");
348  $("#prodiv"+ishow).data("rowid","");
349  $("#prodiv"+ishow).attr("class","wrapper2 divempty");
350  $("#prowatermark"+ishow).hide();
351  ishow++; //Next product to show after print data product
352  }
353  else if ((data[idata]['status']) == "1") { // Only show products with status=1 (for sell)
354  <?php
355  $titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[idata]['ref']";
356  $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[idata]['barcode']";
357  ?>
358  var titlestring = <?php echo $titlestring; ?>;
359  <?php if (!getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
360  echo '$("#prodivdesc"+ishow).show();';
361  if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) {
362  echo '$("#prodesc"+ishow).html(data[parseInt(idata)][\'ref\'].bold() + \' - \' + data[parseInt(idata)][\'label\']);';
363  } else {
364  echo '$("#prodesc"+ishow).html(data[parseInt(idata)][\'label\']);';
365  }
366  echo '$("#proimg"+ishow).attr("title", titlestring);';
367  echo '$("#proimg"+ishow).attr("src", "genimg/index.php?query=pro&id="+data[idata][\'id\']);';
368  } else {
369  echo '$("#probutton"+ishow).show();';
370  echo '$("#probutton"+ishow).html(data[parseInt(idata)][\'label\']);';
371  }
372  ?>
373  if (data[parseInt(idata)]['price_formated']) {
374  $("#proprice"+ishow).attr("class", "productprice");
375  $("#proprice"+ishow).html(data[parseInt(idata)]['price_formated']);
376  }
377  $("#prodiv"+ishow).data("rowid", data[idata]['id']);
378  $("#prodiv"+ishow).data("iscat", 0);
379  $("#prodiv"+ishow).attr("class","wrapper2");
380  $("#prowatermark"+ishow).hide();
381  ishow++; //Next product to show after print data product
382  <?php
383  // Add js from hooks
384  $parameters=array();
385  $parameters['caller'] = 'loadProducts';
386  $hookmanager->executeHooks('completeJSProductDisplay', $parameters);
387  print $hookmanager->resPrint;
388  ?>
389  }
390  //console.log("Hide the prowatermark for ishow="+ishow);
391  idata++; //Next data everytime
392  }
393  });
394 
395  ClearSearch();
396 }
397 
398 function MoreProducts(moreorless) {
399  console.log("MoreProducts");
400 
401  if ($('#search_pagination').val() != '') return Search2('<?php echo $keyCodeForEnter; ?>', moreorless);
402 
403  var maxproduct = <?php echo ($MAXPRODUCT - 2); ?>;
404 
405  if (moreorless=="more"){
406  $('#proimg31').animate({opacity: '0.5'}, 1);
407  $('#proimg31').animate({opacity: '1'}, 100);
408  pageproducts=pageproducts+1;
409  }
410  if (moreorless=="less"){
411  $('#proimg30').animate({opacity: '0.5'}, 1);
412  $('#proimg30').animate({opacity: '1'}, 100);
413  if (pageproducts==0) return; //Return if no less pages
414  pageproducts=pageproducts-1;
415  }
416  $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getProducts&category='+currentcat, function(data) {
417  console.log("Call ajax.php (in MoreProducts) to get Products of category "+currentcat);
418 
419  if (typeof (data[(maxproduct * pageproducts)]) == "undefined" && moreorless=="more"){ // Return if no more pages
420  pageproducts=pageproducts-1;
421  return;
422  }
423  idata=<?php echo ($MAXPRODUCT - 2); ?> * pageproducts; //product data counter
424  ishow=0; //product to show counter
425 
426  while (ishow < maxproduct) {
427  if (typeof (data[idata]) == "undefined") {
428  $("#prodivdesc"+ishow).hide();
429  $("#prodesc"+ishow).text("");
430  $("#probutton"+ishow).text("");
431  $("#probutton"+ishow).hide();
432  $("#proprice"+ishow).attr("class", "");
433  $("#proprice"+ishow).html("");
434  $("#proimg"+ishow).attr("src","genimg/empty.png");
435  $("#prodiv"+ishow).data("rowid","");
436  ishow++; //Next product to show after print data product
437  }
438  else if ((data[idata]['status']) == "1") {
439  //Only show products with status=1 (for sell)
440  $("#prodivdesc"+ishow).show();
441  <?php
442  if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) { ?>
443  $("#prodesc"+ishow).html(data[parseInt(idata)]['ref'].bold() + ' - ' + data[parseInt(idata)]['label']);
444  <?php } else { ?>
445  $("#prodesc"+ishow).html(data[parseInt(idata)]['label']);
446  <?php } ?>
447  $("#probutton"+ishow).html(data[parseInt(idata)]['label']);
448  $("#probutton"+ishow).show();
449  if (data[parseInt(idata)]['price_formated']) {
450  $("#proprice"+ishow).attr("class", "productprice");
451  $("#proprice"+ishow).html(data[parseInt(idata)]['price_formated']);
452  }
453  $("#proimg"+ishow).attr("src","genimg/index.php?query=pro&id="+data[idata]['id']);
454  $("#prodiv"+ishow).data("rowid",data[idata]['id']);
455  $("#prodiv"+ishow).data("iscat",0);
456  ishow++; //Next product to show after print data product
457  }
458  $("#prowatermark"+ishow).hide();
459  idata++; //Next data everytime
460  }
461  });
462 
463  ClearSearch();
464 }
465 
466 function ClickProduct(position, qty = 1) {
467  console.log("ClickProduct");
468  $('#proimg'+position).animate({opacity: '0.5'}, 1);
469  $('#proimg'+position).animate({opacity: '1'}, 100);
470  if ($('#prodiv'+position).data('iscat')==1){
471  console.log("Click on a category at position "+position);
472  LoadProducts(position, true);
473  }
474  else{
475  idproduct=$('#prodiv'+position).data('rowid');
476  console.log("Click on product at position "+position+" for idproduct "+idproduct+", qty="+qty);
477  if (idproduct=="") return;
478  // Call page invoice.php to generate the section with product lines
479  $("#poslines").load("invoice.php?action=addline&token=<?php echo newToken() ?>&place="+place+"&idproduct="+idproduct+"&selectedline="+selectedline+"&qty="+qty, function() {
480  <?php if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) echo "CustomerDisplay();";?>
481  });
482  }
483 
484  ClearSearch();
485 }
486 
487 function ChangeThirdparty(idcustomer) {
488  console.log("ChangeThirdparty");
489  // Call page list.php to change customer
490  $("#poslines").load("../societe/list.php?action=change&type=t&contextpage=poslist&idcustomer="+idcustomer+"&place="+place+"", function() {
491  });
492 
493  ClearSearch();
494 }
495 
496 function deleteline() {
497  console.log("Delete line");
498  $("#poslines").load("invoice.php?action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
499  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
500  });
501  ClearSearch();
502 }
503 
504 function Customer() {
505  console.log("Open box to select the thirdparty place="+place);
506  $.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"); ?>"});
507 }
508 
509 function History()
510 {
511  console.log("Open box to select the history");
512  $.colorbox({href:"../compta/facture/list.php?contextpage=poslist", width:"90%", height:"80%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("History"); ?>"});
513 }
514 
515 function Reduction() {
516  invoiceid = $("#invoiceid").val();
517  console.log("Open popup to enter reduction on invoiceid="+invoiceid);
518  $.colorbox({href:"reduction.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
519 }
520 
521 function CloseBill() {
522  invoiceid = $("#invoiceid").val();
523  console.log("Open popup to enter payment on invoiceid="+invoiceid);
524  $.colorbox({href:"pay.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
525 }
526 
527 function Split() {
528  invoiceid = $("#invoiceid").val();
529  console.log("Open popup to split on invoiceid="+invoiceid);
530  $.colorbox({href:"split.php?place="+place+"&invoiceid="+invoiceid, width:"80%", height:"90%", transition:"none", iframe:"true", title:""});
531 }
532 
533 function Floors() {
534  console.log("Open box to select floor place="+place);
535  $.colorbox({href:"floors.php?place="+place, width:"90%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("Floors"); ?>"});
536 }
537 
538 function FreeZone() {
539  console.log("Open box to enter a free product");
540  $.colorbox({href:"freezone.php?action=freezone&place="+place, width:"80%", height:"200px", transition:"none", iframe:"true", title:"<?php echo $langs->trans("FreeZone"); ?>"});
541 }
542 
543 function TakeposOrderNotes() {
544  console.log("Open box to order notes");
545  ModalBox('ModalNote');
546  $("#textinput").focus();
547 }
548 
549 function Refresh() {
550  console.log("Refresh by reloading place="+place+" invoiceid="+invoiceid);
551  $("#poslines").load("invoice.php?place="+place+"&invoiceid="+invoiceid, function() {
552  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
553  });
554 }
555 
556 function New() {
557  // If we go here,it means $conf->global->TAKEPOS_BAR_RESTAURANT is not defined
558  invoiceid = $("#invoiceid").val();
559 
560  console.log("New with place = <?php echo $place; ?>, js place="+place+", invoiceid="+invoiceid);
561 
562  $.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getInvoice&id='+invoiceid, function(data) {
563  var r;
564 
565  if (parseInt(data['paye']) === 1) {
566  r = true;
567  } else {
568  r = confirm('<?php echo ($place > 0 ? $langs->transnoentitiesnoconv("ConfirmDeletionOfThisPOSSale") : $langs->transnoentitiesnoconv("ConfirmDiscardOfThisPOSSale")); ?>');
569  }
570 
571  if (r == true) {
572  // Reload section with invoice lines
573  $("#poslines").load("invoice.php?action=delete&token=<?php echo newToken(); ?>&place=" + place, function () {
574  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
575  });
576  ClearSearch();
577  }
578  });
579 }
580 
587 function Search2(keyCodeForEnter, moreorless) {
588  console.log("Search2 Call ajax search to replace products keyCodeForEnter="+keyCodeForEnter);
589 
590  var search_term = $('#search').val();
591  var search_start = 0;
592  var search_limit = <?php echo $MAXPRODUCT - 2; ?>;
593  if (moreorless != null) {
594  search_term = $('#search_pagination').val();
595  search_start = $('#search_start_'+moreorless).val();
596  }
597 
598  if (search_term == '') {
599  $("[id^=prowatermark]").html("");
600  $("[id^=prodesc]").text("");
601  $("[id^=probutton]").text("");
602  $("[id^=probutton]").hide();
603  $("[id^=proprice]").attr("class", "hidden");
604  $("[id^=proprice]").html("");
605  $("[id^=proimg]").attr("src", "genimg/empty.png");
606  $("[id^=prodiv]").data("rowid", "");
607  return;
608  }
609 
610  var search = false;
611  var eventKeyCode = window.event.keyCode;
612  if (keyCodeForEnter == '' || eventKeyCode == keyCodeForEnter) {
613  search = true;
614  }
615 
616  if (search === true) {
617 
618  // temporization time to give time to type
619  if (search2_timer) {
620  clearTimeout(search2_timer);
621  }
622 
623  search2_timer = setTimeout(function(){
624 
625  pageproducts = 0;
626  jQuery(".wrapper2 .catwatermark").hide();
627  var nbsearchresults = 0;
628  $.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) {
629  for (i = 0; i < <?php echo $MAXPRODUCT ?>; i++) {
630  if (typeof (data[i]) == "undefined") {
631  $("#prowatermark" + i).html("");
632  $("#prodesc" + i).text("");
633  $("#probutton" + i).text("");
634  $("#probutton" + i).hide();
635  $("#proprice" + i).attr("class", "hidden");
636  $("#proprice" + i).html("");
637  $("#proimg" + i).attr("src", "genimg/empty.png");
638  $("#prodiv" + i).data("rowid", "");
639  continue;
640  }
641  <?php
642  $titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[i]['ref']";
643  $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[i]['barcode']";
644  ?>
645  var titlestring = <?php echo $titlestring; ?>;
646  <?php
647  if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) { ?>
648  $("#prodesc" + i).html(data[i]['ref'].bold() + ' - ' + data[i]['label']);
649  <?php } else { ?>
650  $("#prodesc" + i).html(data[i]['label']);
651  <?php } ?>
652  $("#prodivdesc" + i).show();
653  $("#probutton" + i).html(data[i]['label']);
654  $("#probutton" + i).show();
655  if (data[i]['price_formated']) {
656  $("#proprice" + i).attr("class", "productprice");
657  $("#proprice" + i).html(data[i]['price_formated']);
658  }
659  $("#proimg" + i).attr("title", titlestring);
660  if( undefined !== data[i]['img']) {
661  $("#proimg" + i).attr("src", data[i]['img']);
662  }
663  else {
664  $("#proimg" + i).attr("src", "genimg/index.php?query=pro&id=" + data[i]['rowid']);
665  }
666  $("#prodiv" + i).data("rowid", data[i]['rowid']);
667  $("#prodiv" + i).data("iscat", 0);
668 
669  <?php
670  // Add js from hooks
671  $parameters=array();
672  $parameters['caller'] = 'search2';
673  $hookmanager->executeHooks('completeJSProductDisplay', $parameters);
674  print $hookmanager->resPrint;
675  ?>
676 
677  nbsearchresults++;
678  }
679  }).always(function (data) {
680  // If there is only 1 answer
681  if ($('#search').val().length > 0 && data.length == 1) {
682  console.log($('#search').val()+' - '+data[0]['barcode']);
683  if ($('#search').val() == data[0]['barcode'] && 'thirdparty' == data[0]['object']) {
684  console.log("There is only 1 answer with barcode matching the search, so we change the thirdparty "+data[0]['rowid']);
685  ChangeThirdparty(data[0]['rowid']);
686  }
687  else if ($('#search').val() == data[0]['barcode'] && 'product' == data[0]['object']) {
688  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']);
689  ClickProduct(0, data[0]['qty']);
690  }
691  }
692  if (eventKeyCode == keyCodeForEnter){
693  if (data.length == 0) {
694  $('#search').val('<?php
695  $langs->load('errors');
696  echo dol_escape_js($langs->trans("ErrorRecordNotFound"));
697  ?>');
698  $('#search').select();
699  }
700  else ClearSearch();
701  }
702  // memorize search_term and start for pagination
703  $("#search_pagination").val($("#search").val());
704  if (search_start == 0) {
705  $("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").hide();
706  }
707  else {
708  $("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").show();
709  var search_start_less = Math.max(0, parseInt(search_start) - parseInt(<?php echo $MAXPRODUCT - 2;?>));
710  $("#search_start_less").val(search_start_less);
711  }
712  if (nbsearchresults != <?php echo $MAXPRODUCT - 2; ?>) {
713  $("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").hide();
714  }
715  else {
716  $("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").show();
717  var search_start_more = parseInt(search_start) + parseInt(<?php echo $MAXPRODUCT - 2;?>);
718  $("#search_start_more").val(search_start_more);
719  }
720  });
721  }, 500); // 500ms delay
722  }
723 
724 }
725 
726 /* Function called on an action into the PAD */
727 function Edit(number) {
728  console.log("We click on PAD on key="+number);
729 
730  if (typeof(selectedtext) == "undefined") {
731  return; // We click on an action on the number pad but there is no line selected
732  }
733 
734  var text=selectedtext+"<br> ";
735 
736 
737  if (number=='c') {
738  editnumber='';
739  Refresh();
740  $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
741  $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
742  $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>").removeClass('clicked');
743  return;
744  } else if (number=='qty') {
745  if (editaction=='qty' && editnumber != '') {
746  $("#poslines").load("invoice.php?action=updateqty&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
747  editnumber="";
748  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
749  $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
750  });
751 
752  setFocusOnSearchField();
753  return;
754  }
755  else {
756  editaction="qty";
757  }
758  } else if (number=='p') {
759  if (editaction=='p' && editnumber!="") {
760  $("#poslines").load("invoice.php?action=updateprice&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
761  editnumber="";
762  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
763  $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
764  });
765 
766  ClearSearch();
767  return;
768  }
769  else {
770  editaction="p";
771  }
772  } else if (number=='r') {
773  if (editaction=='r' && editnumber!="") {
774  $("#poslines").load("invoice.php?action=updatereduction&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
775  editnumber="";
776  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
777  $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>").removeClass('clicked');
778  });
779 
780  ClearSearch();
781  return;
782  }
783  else {
784  editaction="r";
785  }
786  }
787  else {
788  editnumber=editnumber+number;
789  }
790  if (editaction=='qty'){
791  text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Qty").": "; ?>";
792  $("#qty").html("OK").addClass("clicked");
793  $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
794  $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>").removeClass('clicked');
795  }
796  if (editaction=='p'){
797  text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Price").": "; ?>";
798  $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
799  $("#price").html("OK").addClass("clicked");
800  $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>").removeClass('clicked');
801  }
802  if (editaction=='r'){
803  text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("ReductionShort").": "; ?>";
804  $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
805  $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
806  $("#reduction").html("OK").addClass("clicked");
807  }
808  $('#'+selectedline).find("td:first").html(text+editnumber);
809 }
810 
811 
812 function TakeposPrintingOrder(){
813  console.log("TakeposPrintingOrder");
814  $("#poslines").load("invoice.php?action=order&place="+place, function() {
815  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
816  });
817 }
818 
819 function TakeposPrintingTemp(){
820  console.log("TakeposPrintingTemp");
821  $("#poslines").load("invoice.php?action=temp&place="+place, function() {
822  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
823  });
824 }
825 
826 function OpenDrawer(){
827  console.log("OpenDrawer call ajax url http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>:8111/print");
828  $.ajax({
829  type: "POST",
830  data: { token: 'notrequired' },
831  <?php
832  if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
833  echo "url: '".getDolGlobalString('TAKEPOS_PRINT_SERVER', 'localhost')."/printer/drawer.php',";
834  } else {
835  echo "url: 'http://".getDolGlobalString('TAKEPOS_PRINT_SERVER', 'localhost').":8111/print',";
836  }
837  ?>
838  data: "opendrawer"
839  });
840 }
841 
842 function DolibarrOpenDrawer() {
843  console.log("DolibarrOpenDrawer call ajax url /takepos/ajax/ajax.php?action=opendrawer&term=<?php print urlencode($_SESSION["takeposterminal"]); ?>");
844  $.ajax({
845  type: "GET",
846  data: { token: '<?php echo currentToken(); ?>' },
847  url: "<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=opendrawer&term='.urlencode($_SESSION["takeposterminal"]); ?>",
848  });
849 }
850 
851 function MoreActions(totalactions){
852  if (pageactions==0){
853  pageactions=1;
854  for (i = 0; i <= totalactions; i++){
855  if (i<12) $("#action"+i).hide();
856  else $("#action"+i).show();
857  }
858  }
859  else if (pageactions==1){
860  pageactions=0;
861  for (i = 0; i <= totalactions; i++){
862  if (i<12) $("#action"+i).show();
863  else $("#action"+i).hide();
864  }
865  }
866 }
867 
868 function ControlCashOpening()
869 {
870  $.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"); ?>"});
871 }
872 
873 function CloseCashFence(rowid)
874 {
875  $.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"); ?>"});
876 }
877 
878 function CashReport(rowid)
879 {
880  $.colorbox({href:"../compta/cashcontrol/report.php?id="+rowid+"&contextpage=takepos", width:"60%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("CashReport"); ?>"});
881 }
882 
883 // TakePOS Popup
884 function ModalBox(ModalID)
885 {
886  var modal = document.getElementById(ModalID);
887  modal.style.display = "block";
888 }
889 
890 function DirectPayment(){
891  console.log("DirectPayment");
892  $("#poslines").load("invoice.php?place="+place+"&action=valid&pay=LIQ", function() {
893  });
894 }
895 
896 function FullScreen() {
897  document.documentElement.requestFullscreen();
898 }
899 
900 function WeighingScale(){
901  console.log("Weighing Scale");
902  $.ajax({
903  type: "POST",
904  data: { token: 'notrequired' },
905  url: '<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>/scale/index.php',
906  })
907  .done(function( editnumber ) {
908  $("#poslines").load("invoice.php?action=updateqty&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
909  editnumber="";
910  });
911  });
912 }
913 
914 $( document ).ready(function() {
915  PrintCategories(0);
916  LoadProducts(0);
917  Refresh();
918  <?php
919  //IF NO TERMINAL SELECTED
920  if ($_SESSION["takeposterminal"] == "") {
921  print "ModalBox('ModalTerminal');";
922  }
923 
924  if (getDolGlobalString('TAKEPOS_CONTROL_CASH_OPENING')) {
925  $sql = "SELECT rowid, status FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE";
926  $sql .= " entity = ".((int) $conf->entity)." AND ";
927  $sql .= " posnumber = ".((int) $_SESSION["takeposterminal"])." AND ";
928  $sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'";
929  $resql = $db->query($sql);
930  if ($resql) {
931  $obj = $db->fetch_object($resql);
932  // If there is no cash control from today open it
933  if ($obj->rowid == null) {
934  print "ControlCashOpening();";
935  }
936  }
937  }
938  ?>
939 });
940 </script>
941 
942 <body class="bodytakepos" style="overflow: hidden;">
943 <?php
944 $keyCodeForEnter = getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) > 0 ? getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) : '';
945 ?>
946 <div class="container">
947 
948 <?php
949 if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
950  ?>
951  <div class="header">
952  <div class="topnav">
953  <div class="topnav-left">
954  <div class="inline-block valignmiddle">
955  <a class="topnav-terminalhour" onclick="ModalBox('ModalTerminal');">
956  <span class="fa fa-cash-register"></span>
957  <span class="hideonsmartphone">
958  <?php echo $langs->trans("Terminal"); ?>
959  </span>
960  <?php echo " ";
961  if ($_SESSION["takeposterminal"] == "") {
962  echo "1";
963  } else {
964  echo $_SESSION["takeposterminal"];
965  }
966  echo '<span class="hideonsmartphone"> - '.dol_print_date(dol_now(), "day").'</span>';
967  ?>
968  </a>
969  <?php
970  if (isModEnabled('multicurrency')) {
971  print '<a class="valignmiddle tdoverflowmax100" id="multicurrency" onclick="ModalBox(\'ModalCurrency\');" title=""><span class="fas fa-coins paddingrightonly"></span>';
972  print '<span class="hideonsmartphone">'.$langs->trans("Currency").'</span>';
973  print '</a>';
974  }
975  ?>
976  </div>
977  <!-- section for customer -->
978  <div class="inline-block valignmiddle" id="customerandsales"></div>
979  <!-- section for shopping carts -->
980  <div class="inline-block valignmiddle" id="shoppingcart"></div>
981  <!-- More info about customer -->
982  <div class="inline-block valignmiddle tdoverflowmax150onsmartphone" id="moreinfo"></div>
983  <?php
984  if (isModEnabled('stock')) {
985  ?>
986  <!-- More info about warehouse -->
987  <div class="inline-block valignmiddle tdoverflowmax150onsmartphone" id="infowarehouse"></div>
988  <?php
989  }
990  ?>
991  </div>
992  <div class="topnav-right">
993  <div class="login_block_other">
994  <input type="text" id="search" name="search" class="input-search-takepos" onkeyup="Search2('<?php echo dol_escape_js($keyCodeForEnter); ?>', null);" placeholder="<?php echo dol_escape_htmltag($langs->trans("Search")); ?>" autofocus>
995  <a onclick="ClearSearch();"><span class="fa fa-backspace"></span></a>
996  <a href="<?php echo DOL_URL_ROOT.'/'; ?>" target="backoffice" rel="opener"><!-- we need rel="opener" here, we are on same domain and we need to be able to reuse this tab several times -->
997  <span class="fas fa-home"></span></a>
998  <?php if (empty($conf->dol_use_jmobile)) { ?>
999  <a class="hideonsmartphone" onclick="FullScreen();"><span class="fa fa-expand-arrows-alt"></span></a>
1000  <?php } ?>
1001  </div>
1002  <div class="login_block_user">
1003  <?php
1004  print top_menu_user(1);
1005  ?>
1006  </div>
1007  </div>
1008  </div>
1009  </div>
1010  <?php
1011 }
1012 ?>
1013 
1014 <!-- Modal terminal box -->
1015 <div id="ModalTerminal" class="modal">
1016  <div class="modal-content">
1017  <div class="modal-header">
1018  <span class="close" href="#" onclick="document.getElementById('ModalTerminal').style.display = 'none';">&times;</span>
1019  <h3><?php print $langs->trans("TerminalSelect"); ?></h3>
1020  </div>
1021  <div class="modal-body">
1022  <button type="button" class="block" onclick="location.href='index.php?setterminal=1'"><?php print $langs->trans("Terminal"); ?> 1</button>
1023  <?php
1024  $nbloop = getDolGlobalInt('TAKEPOS_NUM_TERMINALS');
1025  for ($i = 2; $i <= $nbloop; $i++) {
1026  print '<button type="button" class="block" onclick="location.href=\'index.php?setterminal='.$i.'\'">'.$langs->trans("Terminal").' '.$i.'</button>';
1027  }
1028  ?>
1029  </div>
1030 </div>
1031 </div>
1032 
1033 <!-- Modal multicurrency box -->
1034 <?php if (isModEnabled('multicurrency')) { ?>
1035 <div id="ModalCurrency" class="modal">
1036  <div class="modal-content">
1037  <div class="modal-header">
1038  <span class="close" href="#" onclick="document.getElementById('ModalCurrency').style.display = 'none';">&times;</span>
1039  <h3><?php print $langs->trans("SetMultiCurrencyCode"); ?></h3>
1040  </div>
1041  <div class="modal-body">
1042  <?php
1043  $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'multicurrency';
1044  $sql .= " WHERE entity IN ('".getEntity('multicurrency')."')";
1045  $resql = $db->query($sql);
1046  if ($resql) {
1047  while ($obj = $db->fetch_object($resql)) {
1048  print '<button type="button" class="block" onclick="location.href=\'index.php?setcurrency='.$obj->code.'\'">'.$obj->code.'</button>';
1049  }
1050  }
1051  ?>
1052  </div>
1053  </div>
1054 </div>
1055 <?php } ?>
1056 
1057 <!-- Modal terminal Credit Note -->
1058 <div id="ModalCreditNote" class="modal">
1059  <div class="modal-content">
1060  <div class="modal-header">
1061  <span class="close" href="#" onclick="document.getElementById('ModalCreditNote').style.display = 'none';">&times;</span>
1062  <h3><?php print $langs->trans("invoiceAvoirWithLines"); ?></h3>
1063  </div>
1064  <div class="modal-body">
1065  <button type="button" class="block" onclick="CreditNote(); document.getElementById('ModalCreditNote').style.display = 'none';"><?php print $langs->trans("Yes"); ?></button>
1066  <button type="button" class="block" onclick="document.getElementById('ModalCreditNote').style.display = 'none';"><?php print $langs->trans("No"); ?></button>
1067  </div>
1068 </div>
1069 </div>
1070 
1071 <!-- Modal Note -->
1072 <div id="ModalNote" class="modal">
1073  <div class="modal-content">
1074  <div class="modal-header">
1075  <span class="close" href="#" onclick="document.getElementById('ModalNote').style.display = 'none';">&times;</span>
1076  <h3><?php print $langs->trans("Note"); ?></h3>
1077  </div>
1078  <div class="modal-body">
1079  <input type="text" class="block" id="textinput">
1080  <button type="button" class="block" onclick="SetNote(); document.getElementById('ModalNote').style.display = 'none';">OK</button>
1081  </div>
1082 </div>
1083 </div>
1084 
1085  <div class="row1<?php if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
1086  print 'withhead';
1087  } ?>">
1088 
1089  <div id="poslines" class="div1">
1090  </div>
1091 
1092  <div class="div2">
1093  <button type="button" class="calcbutton" onclick="Edit(7);">7</button>
1094  <button type="button" class="calcbutton" onclick="Edit(8);">8</button>
1095  <button type="button" class="calcbutton" onclick="Edit(9);">9</button>
1096  <button type="button" id="qty" class="calcbutton2" onclick="Edit('qty');"><?php echo $langs->trans("Qty"); ?></button>
1097  <button type="button" class="calcbutton" onclick="Edit(4);">4</button>
1098  <button type="button" class="calcbutton" onclick="Edit(5);">5</button>
1099  <button type="button" class="calcbutton" onclick="Edit(6);">6</button>
1100  <button type="button" id="price" class="calcbutton2" onclick="Edit('p');"><?php echo $langs->trans("Price"); ?></button>
1101  <button type="button" class="calcbutton" onclick="Edit(1);">1</button>
1102  <button type="button" class="calcbutton" onclick="Edit(2);">2</button>
1103  <button type="button" class="calcbutton" onclick="Edit(3);">3</button>
1104  <button type="button" id="reduction" class="calcbutton2" onclick="Edit('r');"><?php echo $langs->trans("ReductionShort"); ?></button>
1105  <button type="button" class="calcbutton" onclick="Edit(0);">0</button>
1106  <button type="button" class="calcbutton" onclick="Edit('.');">.</button>
1107  <button type="button" class="calcbutton poscolorblue" onclick="Edit('c');">C</button>
1108  <button type="button" class="calcbutton2 poscolordelete" id="delete" onclick="deleteline();"><span class="fa fa-trash"></span></button>
1109  </div>
1110 
1111 <?php
1112 
1113 // TakePOS setup check
1114 if (isset($_SESSION["takeposterminal"]) && $_SESSION["takeposterminal"]) {
1115  $sql = "SELECT code, libelle FROM " . MAIN_DB_PREFIX . "c_paiement";
1116  $sql .= " WHERE entity IN (" . getEntity('c_paiement') . ")";
1117  $sql .= " AND active = 1";
1118  $sql .= " ORDER BY libelle";
1119 
1120  $resql = $db->query($sql);
1121  $paiementsModes = array();
1122  if ($resql) {
1123  while ( $obj = $db->fetch_object($resql) ) {
1124  $paycode = $obj->code;
1125  if ($paycode == 'LIQ') {
1126  $paycode = 'CASH';
1127  }
1128  if ($paycode == 'CHQ') {
1129  $paycode = 'CHEQUE';
1130  }
1131 
1132  $constantforkey = "CASHDESK_ID_BANKACCOUNT_" . $paycode . $_SESSION["takeposterminal"];
1133  //var_dump($constantforkey.' '.$conf->global->$constantforkey);
1134  if ( ! empty($conf->global->$constantforkey) && $conf->global->$constantforkey > 0) {
1135  array_push($paiementsModes, $obj);
1136  }
1137  }
1138  }
1139 
1140  if (empty($paiementsModes) && isModEnabled('banque')) {
1141  $langs->load('errors');
1142  setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("TakePOS")), null, 'errors');
1143  setEventMessages($langs->trans("ProblemIsInSetupOfTerminal", $_SESSION["takeposterminal"]), null, 'errors');
1144  }
1145 }
1146 
1147 if (count($maincategories) == 0) {
1148  if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) {
1149  $tmpcategory = new Categorie($db);
1150  $tmpcategory->fetch($conf->global->TAKEPOS_ROOT_CATEGORY_ID);
1151  setEventMessages($langs->trans("TakeposNeedsAtLeastOnSubCategoryIntoParentCategory", $tmpcategory->label), null, 'errors');
1152  } else {
1153  setEventMessages($langs->trans("TakeposNeedsCategories"), null, 'errors');
1154  }
1155 }
1156 // User menu and external TakePOS modules
1157 $menus = array();
1158 $r = 0;
1159 
1160 if (empty($conf->global->TAKEPOS_BAR_RESTAURANT)) {
1161  $menus[$r++] = array('title'=>'<span class="fa fa-layer-group paddingrightonly"></span><div class="trunc">'.$langs->trans("New").'</div>', 'action'=>'New();');
1162 } else {
1163  // BAR RESTAURANT specific menu
1164  $menus[$r++] = array('title'=>'<span class="fa fa-layer-group paddingrightonly"></span><div class="trunc">'.$langs->trans("Place").'</div>', 'action'=>'Floors();');
1165 }
1166 
1167 if (!empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
1168  $menus[$r++] = array('title'=>'<span class="far fa-building paddingrightonly"></span><div class="trunc">'.$langs->trans("Customer").'</div>', 'action'=>'Customer();');
1169 }
1170 $menus[$r++] = array('title'=>'<span class="fa fa-history paddingrightonly"></span><div class="trunc">'.$langs->trans("History").'</div>', 'action'=>'History();');
1171 $menus[$r++] = array('title'=>'<span class="fa fa-cube paddingrightonly"></span><div class="trunc">'.$langs->trans("FreeZone").'</div>', 'action'=>'FreeZone();');
1172 $menus[$r++] = array('title'=>'<span class="fa fa-percent paddingrightonly"></span><div class="trunc">'.$langs->trans("Reduction").'</div>', 'action'=>'Reduction();');
1173 $menus[$r++] = array('title'=>'<span class="far fa-money-bill-alt paddingrightonly"></span><div class="trunc">'.$langs->trans("Payment").'</div>', 'action'=>'CloseBill();');
1174 
1175 if (getDolGlobalString('TAKEPOS_DIRECT_PAYMENT')) {
1176  $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();');
1177 }
1178 
1179 $menus[$r++] = array('title'=>'<span class="fas fa-cut paddingrightonly"></span><div class="trunc">'.$langs->trans("SplitSale").'</div>', 'action'=>'Split();');
1180 
1181 // BAR RESTAURANT specific menu
1182 if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
1183  if (getDolGlobalString('TAKEPOS_ORDER_PRINTERS')) {
1184  $menus[$r++] = array('title'=>'<span class="fa fa-blender-phone paddingrightonly"></span><div class="trunc">'.$langs->trans("Order").'</span>', 'action'=>'TakeposPrintingOrder();');
1185  }
1186  //Button to print receipt before payment
1187  if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
1188  if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") {
1189  if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1190  $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'TakeposConnector(placeid);');
1191  } else {
1192  $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'TakeposPrinting(placeid);');
1193  }
1194  } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") {
1195  $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'DolibarrTakeposPrinting(placeid);');
1196  } else {
1197  $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'Print(placeid);');
1198  }
1199  }
1200  if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector" && getDolGlobalString('TAKEPOS_ORDER_NOTES') == 1) {
1201  $menus[$r++] = array('title'=>'<span class="fa fa-sticky-note paddingrightonly"></span><div class="trunc">'.$langs->trans("OrderNotes").'</div>', 'action'=>'TakeposOrderNotes();');
1202  }
1203  if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
1204  $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("ProductSupplements").'</div>', 'action'=>'LoadProducts(\'supplements\');');
1205  }
1206 }
1207 
1208 if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") {
1209  $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("DOL_OPEN_DRAWER").'</div>', 'action'=>'OpenDrawer();');
1210 }
1211 if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") {
1212  $menus[$r++] = array(
1213  'title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("DOL_OPEN_DRAWER").'</div>',
1214  'action' => 'DolibarrOpenDrawer();',
1215  );
1216 }
1217 
1218 $sql = "SELECT rowid, status, entity FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE";
1219 $sql .= " entity = ".((int) $conf->entity)." AND ";
1220 $sql .= " posnumber = ".((int) $_SESSION["takeposterminal"])." AND ";
1221 $sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'";
1222 
1223 $resql = $db->query($sql);
1224 if ($resql) {
1225  $num = $db->num_rows($resql);
1226  if ($num) {
1227  $obj = $db->fetch_object($resql);
1228  $menus[$r++] = array('title'=>'<span class="fas fa-file-invoice-dollar paddingrightonly"></span><div class="trunc">'.$langs->trans("CashReport").'</div>', 'action'=>'CashReport('.$obj->rowid.');');
1229  if ($obj->status == 0) {
1230  $menus[$r++] = array('title'=>'<span class="fas fa-cash-register paddingrightonly"></span><div class="trunc">'.$langs->trans("CloseCashFence").'</div>', 'action'=>'CloseCashFence('.$obj->rowid.');');
1231  }
1232  }
1233 }
1234 
1235 $hookmanager->initHooks(array('takeposfrontend'));
1236 $parameters = array('menus'=>$menus);
1237 $reshook = $hookmanager->executeHooks('ActionButtons', $parameters);
1238 if ($reshook == 0) { //add buttons
1239  if (is_array($hookmanager->resArray) ) {
1240  foreach ($hookmanager->resArray as $resArray) {
1241  foreach ($resArray as $butmenu) {
1242  $menus[$r++] = $butmenu;
1243  }
1244  }
1245  } elseif ($reshook == 1) {
1246  $r = 0; //replace buttons
1247  if (is_array($hookmanager->resArray) ) {
1248  foreach ($hookmanager->resArray as $resArray) {
1249  foreach ($resArray as $butmenu) {
1250  $menus[$r++] = $butmenu;
1251  }
1252  }
1253  }
1254  }
1255 }
1256 
1257 if ($r % 3 == 2) {
1258  $menus[$r++] = array('title'=>'', 'style'=>'visibility: hidden;');
1259 }
1260 
1261 if (!empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
1262  $menus[$r++] = array('title'=>'<span class="fa fa-sign-out-alt paddingrightonly"></span><div class="trunc">'.$langs->trans("Logout").'</div>', 'action'=>'window.location.href=\''.DOL_URL_ROOT.'/user/logout.php?token='.newToken().'\';');
1263 }
1264 
1265 if (!empty($conf->global->TAKEPOS_WEIGHING_SCALE)) {
1266  $menus[$r++] = array('title'=>'<span class="fa fa-balance-scale paddingrightonly"></span><div class="trunc">'.$langs->trans("WeighingScale").'</div>', 'action'=>'WeighingScale();');
1267 }
1268 
1269 ?>
1270  <!-- Show buttons -->
1271  <div class="div3">
1272  <?php
1273  $i = 0;
1274  foreach ($menus as $menu) {
1275  $i++;
1276  if (count($menus) > 12 and $i == 12) {
1277  echo '<button style="'.(empty($menu['style']) ? '' : $menu['style']).'" type="button" id="actionnext" class="actionbutton" onclick="MoreActions('.count($menus).');">'.$langs->trans("Next").'</button>';
1278  echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
1279  } elseif ($i > 12) {
1280  echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
1281  } else {
1282  echo '<button style="'.(empty($menu['style']) ? '' : $menu['style']).'" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
1283  }
1284  }
1285 
1286  if (!empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
1287  print '<!-- Show the search input text -->'."\n";
1288  print '<div class="margintoponly">';
1289  print '<input type="text" id="search" class="input-search-takepos" 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> ';
1290  print '<a class="marginleftonly hideonsmartphone" onclick="ClearSearch();">'.img_picto('', 'searchclear').'</a>';
1291  print '</div>';
1292  }
1293  ?>
1294  </div>
1295  </div>
1296 
1297  <div class="row2<?php if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
1298  print 'withhead';
1299  } ?>">
1300 
1301  <!-- Show categories -->
1302  <?php
1303  if (getDolGlobalInt('TAKEPOS_HIDE_CATEGORIES') == 1) {
1304  print '<div class="div4" style= "display: none;">';
1305  } else {
1306  print '<div class="div4">';
1307  }
1308 
1309  $count = 0;
1310  while ($count < $MAXCATEG) {
1311  ?>
1312  <div class="wrapper" <?php if ($count == ($MAXCATEG - 2)) {
1313  echo 'onclick="MoreCategories(\'less\');"';
1314  } elseif ($count == ($MAXCATEG - 1)) {
1315  echo 'onclick="MoreCategories(\'more\');"';
1316  } else {
1317  echo 'onclick="LoadProducts('.$count.');"';
1318  } ?> id="catdiv<?php echo $count; ?>">
1319  <?php
1320  if ($count == ($MAXCATEG - 2)) {
1321  //echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="catimg'.$count.'" />';
1322  echo '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1323  } elseif ($count == ($MAXCATEG - 1)) {
1324  //echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="catimg'.$count.'" />';
1325  echo '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1326  } else {
1327  if (!getDolGlobalString('TAKEPOS_HIDE_CATEGORY_IMAGES')) {
1328  echo '<img class="imgwrapper" height="100%" id="catimg'.$count.'" />';
1329  }
1330  }
1331  ?>
1332  <?php if ($count != ($MAXCATEG - 2) && $count != ($MAXCATEG - 1)) { ?>
1333  <div class="description" id="catdivdesc<?php echo $count; ?>">
1334  <div class="description_content" id="catdesc<?php echo $count; ?>"></div>
1335  </div>
1336  <?php } ?>
1337  <div class="catwatermark" id='catwatermark<?php echo $count; ?>'>...</div>
1338  </div>
1339  <?php
1340  $count++;
1341  }
1342  ?>
1343  </div>
1344 
1345  <!-- Show product -->
1346  <div class="div5"<?php if (getDolGlobalInt('TAKEPOS_HIDE_CATEGORIES') == 1) {
1347  print ' style="width:100%;"';
1348  } ?>>
1349  <?php
1350  $count = 0;
1351  while ($count < $MAXPRODUCT) {
1352  print '<div class="wrapper2" id="prodiv'.$count.'" ';
1353  ?>
1354  <?php if ($count == ($MAXPRODUCT - 2)) {
1355  ?> onclick="MoreProducts('less');" <?php
1356  } if ($count == ($MAXPRODUCT - 1)) {
1357  ?> onclick="MoreProducts('more');" <?php
1358  } else {
1359  echo 'onclick="ClickProduct('.$count.');"';
1360  } ?>>
1361  <?php
1362  if ($count == ($MAXPRODUCT - 2)) {
1363  //echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="proimg'.$count.'" />';
1364  print '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1365  } elseif ($count == ($MAXPRODUCT - 1)) {
1366  //echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="proimg'.$count.'" />';
1367  print '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1368  } else {
1369  if (getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
1370  echo '<button type="button" id="probutton'.$count.'" class="productbutton" style="display: none;"></button>';
1371  } else {
1372  print '<div class="" id="proprice'.$count.'"></div>';
1373  print '<img class="imgwrapper" height="100%" title="" id="proimg'.$count.'">';
1374  }
1375  }
1376  ?>
1377  <?php if ($count != ($MAXPRODUCT - 2) && $count != ($MAXPRODUCT - 1) && !getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) { ?>
1378  <div class="description" id="prodivdesc<?php echo $count; ?>">
1379  <div class="description_content" id="prodesc<?php echo $count; ?>"></div>
1380  </div>
1381  <?php } ?>
1382  <div class="catwatermark" id='prowatermark<?php echo $count; ?>'>...</div>
1383  </div>
1384  <?php
1385  $count++;
1386  }
1387  ?>
1388  <input type="hidden" id="search_start_less" value="0">
1389  <input type="hidden" id="search_start_more" value="0">
1390  <input type="hidden" id="search_pagination" value="">
1391  </div>
1392  </div>
1393 </div>
1394 </body>
1395 <?php
1396 
1397 llxFooter();
1398 
1399 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_now($mode= 'auto')
Return date for now.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default= '')
Return dolibarr global constant string value.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:122
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
Class to manage generation of HTML components Only common components must be here.
Class to manage categories.
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge, other ! Closing when no payment: replaced, abandoned
dol_get_first_hour($date, $gm= 'tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part) ...
Definition: date.lib.php:611
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
top_menu_user($hideloginname=0, $urllogout= '')
Build the tooltip on user login.
Definition: main.inc.php:2114
top_htmlhead($head, $title= '', $disablejs=0, $disablehead=0, $arrayofjs= '', $arrayofcss= '', $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput html header of a page.
Definition: main.inc.php:1478
isModEnabled($module)
Is Dolibarr module enabled.
llxFooter()
Empty footer.
Definition: wrapper.php:73
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid