dolibarr  16.0.5
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 
588 function Search2(keyCodeForEnter, moreorless) {
589  var eventKeyCode = window.event.keyCode;
590 
591  console.log("Search2 Call ajax search to replace products keyCodeForEnter="+keyCodeForEnter+", eventKeyCode="+eventKeyCode);
592 
593  var search_term = $('#search').val();
594  var search_start = 0;
595  var search_limit = <?php echo $MAXPRODUCT - 2; ?>;
596  if (moreorless != null) {
597  search_term = $('#search_pagination').val();
598  search_start = $('#search_start_'+moreorless).val();
599  }
600 
601  console.log("search_term="+search_term);
602 
603  if (search_term == '') {
604  $("[id^=prowatermark]").html("");
605  $("[id^=prodesc]").text("");
606  $("[id^=probutton]").text("");
607  $("[id^=probutton]").hide();
608  $("[id^=proprice]").attr("class", "hidden");
609  $("[id^=proprice]").html("");
610  $("[id^=proimg]").attr("src", "genimg/empty.png");
611  $("[id^=prodiv]").data("rowid", "");
612  return;
613  }
614 
615  var search = false;
616  if (keyCodeForEnter == '' || eventKeyCode == keyCodeForEnter) {
617  search = true;
618  }
619 
620  if (search === true) {
621  // if a timer has been already started (search2_timer is a global js variable), we cancel it now
622  // we click onto another key, we will restart another timer just after
623  if (search2_timer) {
624  clearTimeout(search2_timer);
625  }
626 
627  // temporization time to give time to type
628  search2_timer = setTimeout(function(){
629  pageproducts = 0;
630  jQuery(".wrapper2 .catwatermark").hide();
631  var nbsearchresults = 0;
632  $.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) {
633  for (i = 0; i < <?php echo $MAXPRODUCT ?>; i++) {
634  if (typeof (data[i]) == "undefined") {
635  $("#prowatermark" + i).html("");
636  $("#prodesc" + i).text("");
637  $("#probutton" + i).text("");
638  $("#probutton" + i).hide();
639  $("#proprice" + i).attr("class", "hidden");
640  $("#proprice" + i).html("");
641  $("#proimg" + i).attr("src", "genimg/empty.png");
642  $("#prodiv" + i).data("rowid", "");
643  continue;
644  }
645  <?php
646  $titlestring = "'".dol_escape_js($langs->transnoentities('Ref').': ')."' + data[i]['ref']";
647  $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[i]['barcode']";
648  ?>
649  var titlestring = <?php echo $titlestring; ?>;
650  <?php
651  if (getDolGlobalInt('TAKEPOS_SHOW_PRODUCT_REFERENCE') == 1) { ?>
652  $("#prodesc" + i).html(data[i]['ref'].bold() + ' - ' + data[i]['label']);
653  <?php } else { ?>
654  $("#prodesc" + i).html(data[i]['label']);
655  <?php } ?>
656  $("#prodivdesc" + i).show();
657  $("#probutton" + i).html(data[i]['label']);
658  $("#probutton" + i).show();
659  if (data[i]['price_formated']) {
660  $("#proprice" + i).attr("class", "productprice");
661  $("#proprice" + i).html(data[i]['price_formated']);
662  }
663  $("#proimg" + i).attr("title", titlestring);
664  if( undefined !== data[i]['img']) {
665  $("#proimg" + i).attr("src", data[i]['img']);
666  }
667  else {
668  $("#proimg" + i).attr("src", "genimg/index.php?query=pro&id=" + data[i]['rowid']);
669  }
670  $("#prodiv" + i).data("rowid", data[i]['rowid']);
671  $("#prodiv" + i).data("iscat", 0);
672 
673  <?php
674  // Add js from hooks
675  $parameters=array();
676  $parameters['caller'] = 'search2';
677  $hookmanager->executeHooks('completeJSProductDisplay', $parameters);
678  print $hookmanager->resPrint;
679  ?>
680 
681  nbsearchresults++;
682  }
683  }).always(function (data) {
684  // If there is only 1 answer
685  if ($('#search').val().length > 0 && data.length == 1) {
686  console.log($('#search').val()+' - '+data[0]['barcode']);
687  if ($('#search').val() == data[0]['barcode'] && 'thirdparty' == data[0]['object']) {
688  console.log("There is only 1 answer with barcode matching the search, so we change the thirdparty "+data[0]['rowid']);
689  ChangeThirdparty(data[0]['rowid']);
690  }
691  else if ($('#search').val() == data[0]['barcode'] && 'product' == data[0]['object']) {
692  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']);
693  ClickProduct(0, data[0]['qty']);
694  }
695  }
696  if (eventKeyCode == keyCodeForEnter){
697  if (data.length == 0) {
698  $('#search').val('<?php
699  $langs->load('errors');
700  echo dol_escape_js($langs->transnoentitiesnoconv("ErrorRecordNotFoundShort"));
701  ?> ('+search_term+')');
702  $('#search').select();
703  }
704  else ClearSearch();
705  }
706  // memorize search_term and start for pagination
707  $("#search_pagination").val($("#search").val());
708  if (search_start == 0) {
709  $("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").hide();
710  }
711  else {
712  $("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").show();
713  var search_start_less = Math.max(0, parseInt(search_start) - parseInt(<?php echo $MAXPRODUCT - 2;?>));
714  $("#search_start_less").val(search_start_less);
715  }
716  if (nbsearchresults != <?php echo $MAXPRODUCT - 2; ?>) {
717  $("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").hide();
718  }
719  else {
720  $("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").show();
721  var search_start_more = parseInt(search_start) + parseInt(<?php echo $MAXPRODUCT - 2;?>);
722  $("#search_start_more").val(search_start_more);
723  }
724  });
725  }, 500); // 500ms delay
726  }
727 
728 }
729 
730 /* Function called on an action into the PAD */
731 function Edit(number) {
732  console.log("We click on PAD on key="+number);
733 
734  if (typeof(selectedtext) == "undefined") {
735  return; // We click on an action on the number pad but there is no line selected
736  }
737 
738  var text=selectedtext+"<br> ";
739 
740 
741  if (number=='c') {
742  editnumber='';
743  Refresh();
744  $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
745  $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
746  $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>").removeClass('clicked');
747  return;
748  } else if (number=='qty') {
749  if (editaction=='qty' && editnumber != '') {
750  $("#poslines").load("invoice.php?action=updateqty&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
751  editnumber="";
752  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
753  $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
754  });
755 
756  setFocusOnSearchField();
757  return;
758  }
759  else {
760  editaction="qty";
761  }
762  } else if (number=='p') {
763  if (editaction=='p' && editnumber!="") {
764  $("#poslines").load("invoice.php?action=updateprice&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
765  editnumber="";
766  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
767  $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
768  });
769 
770  ClearSearch();
771  return;
772  }
773  else {
774  editaction="p";
775  }
776  } else if (number=='r') {
777  if (editaction=='r' && editnumber!="") {
778  $("#poslines").load("invoice.php?action=updatereduction&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
779  editnumber="";
780  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
781  $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>").removeClass('clicked');
782  });
783 
784  ClearSearch();
785  return;
786  }
787  else {
788  editaction="r";
789  }
790  }
791  else {
792  editnumber=editnumber+number;
793  }
794  if (editaction=='qty'){
795  text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Qty").": "; ?>";
796  $("#qty").html("OK").addClass("clicked");
797  $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
798  $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>").removeClass('clicked');
799  }
800  if (editaction=='p'){
801  text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("Price").": "; ?>";
802  $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
803  $("#price").html("OK").addClass("clicked");
804  $("#reduction").html("<?php echo $langs->trans("ReductionShort"); ?>").removeClass('clicked');
805  }
806  if (editaction=='r'){
807  text=text+"<?php echo $langs->trans("Modify")." -> ".$langs->trans("ReductionShort").": "; ?>";
808  $("#qty").html("<?php echo $langs->trans("Qty"); ?>").removeClass('clicked');
809  $("#price").html("<?php echo $langs->trans("Price"); ?>").removeClass('clicked');
810  $("#reduction").html("OK").addClass("clicked");
811  }
812  $('#'+selectedline).find("td:first").html(text+editnumber);
813 }
814 
815 
816 function TakeposPrintingOrder(){
817  console.log("TakeposPrintingOrder");
818  $("#poslines").load("invoice.php?action=order&place="+place, function() {
819  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
820  });
821 }
822 
823 function TakeposPrintingTemp(){
824  console.log("TakeposPrintingTemp");
825  $("#poslines").load("invoice.php?action=temp&place="+place, function() {
826  //$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
827  });
828 }
829 
830 function OpenDrawer(){
831  console.log("OpenDrawer call ajax url http://<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>:8111/print");
832  $.ajax({
833  type: "POST",
834  data: { token: 'notrequired' },
835  <?php
836  if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
837  echo "url: '".getDolGlobalString('TAKEPOS_PRINT_SERVER', 'localhost')."/printer/drawer.php',";
838  } else {
839  echo "url: 'http://".getDolGlobalString('TAKEPOS_PRINT_SERVER', 'localhost').":8111/print',";
840  }
841  ?>
842  data: "opendrawer"
843  });
844 }
845 
846 function DolibarrOpenDrawer() {
847  console.log("DolibarrOpenDrawer call ajax url /takepos/ajax/ajax.php?action=opendrawer&term=<?php print urlencode($_SESSION["takeposterminal"]); ?>");
848  $.ajax({
849  type: "GET",
850  data: { token: '<?php echo currentToken(); ?>' },
851  url: "<?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=opendrawer&term='.urlencode($_SESSION["takeposterminal"]); ?>",
852  });
853 }
854 
855 function MoreActions(totalactions){
856  if (pageactions==0){
857  pageactions=1;
858  for (i = 0; i <= totalactions; i++){
859  if (i<12) $("#action"+i).hide();
860  else $("#action"+i).show();
861  }
862  }
863  else if (pageactions==1){
864  pageactions=0;
865  for (i = 0; i <= totalactions; i++){
866  if (i<12) $("#action"+i).show();
867  else $("#action"+i).hide();
868  }
869  }
870 }
871 
872 function ControlCashOpening()
873 {
874  $.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"); ?>"});
875 }
876 
877 function CloseCashFence(rowid)
878 {
879  $.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"); ?>"});
880 }
881 
882 function CashReport(rowid)
883 {
884  $.colorbox({href:"../compta/cashcontrol/report.php?id="+rowid+"&contextpage=takepos", width:"60%", height:"90%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("CashReport"); ?>"});
885 }
886 
887 // TakePOS Popup
888 function ModalBox(ModalID)
889 {
890  var modal = document.getElementById(ModalID);
891  modal.style.display = "block";
892 }
893 
894 function DirectPayment(){
895  console.log("DirectPayment");
896  $("#poslines").load("invoice.php?place="+place+"&action=valid&pay=LIQ", function() {
897  });
898 }
899 
900 function FullScreen() {
901  document.documentElement.requestFullscreen();
902 }
903 
904 function WeighingScale(){
905  console.log("Weighing Scale");
906  $.ajax({
907  type: "POST",
908  data: { token: 'notrequired' },
909  url: '<?php print getDolGlobalString('TAKEPOS_PRINT_SERVER'); ?>/scale/index.php',
910  })
911  .done(function( editnumber ) {
912  $("#poslines").load("invoice.php?action=updateqty&place="+place+"&idline="+selectedline+"&number="+editnumber, function() {
913  editnumber="";
914  });
915  });
916 }
917 
918 $( document ).ready(function() {
919  PrintCategories(0);
920  LoadProducts(0);
921  Refresh();
922  <?php
923  //IF NO TERMINAL SELECTED
924  if ($_SESSION["takeposterminal"] == "") {
925  print "ModalBox('ModalTerminal');";
926  }
927 
928  if (getDolGlobalString('TAKEPOS_CONTROL_CASH_OPENING')) {
929  $sql = "SELECT rowid, status FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE";
930  $sql .= " entity = ".((int) $conf->entity)." AND ";
931  $sql .= " posnumber = ".((int) $_SESSION["takeposterminal"])." AND ";
932  $sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'";
933  $resql = $db->query($sql);
934  if ($resql) {
935  $obj = $db->fetch_object($resql);
936  // If there is no cash control from today open it
937  if ($obj->rowid == null) {
938  print "ControlCashOpening();";
939  }
940  }
941  }
942  ?>
943 });
944 </script>
945 
946 <body class="bodytakepos" style="overflow: hidden;">
947 <?php
948 $keyCodeForEnter = getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) > 0 ? getDolGlobalInt('CASHDESK_READER_KEYCODE_FOR_ENTER'.$_SESSION['takeposterminal']) : '';
949 ?>
950 <div class="container">
951 
952 <?php
953 if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
954  ?>
955  <div class="header">
956  <div class="topnav">
957  <div class="topnav-left">
958  <div class="inline-block valignmiddle">
959  <a class="topnav-terminalhour" onclick="ModalBox('ModalTerminal');">
960  <span class="fa fa-cash-register"></span>
961  <span class="hideonsmartphone">
962  <?php echo $langs->trans("Terminal"); ?>
963  </span>
964  <?php echo " ";
965  if ($_SESSION["takeposterminal"] == "") {
966  echo "1";
967  } else {
968  echo $_SESSION["takeposterminal"];
969  }
970  echo '<span class="hideonsmartphone"> - '.dol_print_date(dol_now(), "day").'</span>';
971  ?>
972  </a>
973  <?php
974  if (isModEnabled('multicurrency')) {
975  print '<a class="valignmiddle tdoverflowmax100" id="multicurrency" onclick="ModalBox(\'ModalCurrency\');" title=""><span class="fas fa-coins paddingrightonly"></span>';
976  print '<span class="hideonsmartphone">'.$langs->trans("Currency").'</span>';
977  print '</a>';
978  }
979  ?>
980  </div>
981  <!-- section for customer -->
982  <div class="inline-block valignmiddle" id="customerandsales"></div>
983  <!-- section for shopping carts -->
984  <div class="inline-block valignmiddle" id="shoppingcart"></div>
985  <!-- More info about customer -->
986  <div class="inline-block valignmiddle tdoverflowmax150onsmartphone" id="moreinfo"></div>
987  <?php
988  if (isModEnabled('stock')) {
989  ?>
990  <!-- More info about warehouse -->
991  <div class="inline-block valignmiddle tdoverflowmax150onsmartphone" id="infowarehouse"></div>
992  <?php
993  }
994  ?>
995  </div>
996  <div class="topnav-right">
997  <div class="login_block_other">
998  <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>
999  <a onclick="ClearSearch();"><span class="fa fa-backspace"></span></a>
1000  <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 -->
1001  <span class="fas fa-home"></span></a>
1002  <?php if (empty($conf->dol_use_jmobile)) { ?>
1003  <a class="hideonsmartphone" onclick="FullScreen();"><span class="fa fa-expand-arrows-alt"></span></a>
1004  <?php } ?>
1005  </div>
1006  <div class="login_block_user">
1007  <?php
1008  print top_menu_user(1);
1009  ?>
1010  </div>
1011  </div>
1012  </div>
1013  </div>
1014  <?php
1015 }
1016 ?>
1017 
1018 <!-- Modal terminal box -->
1019 <div id="ModalTerminal" class="modal">
1020  <div class="modal-content">
1021  <div class="modal-header">
1022  <span class="close" href="#" onclick="document.getElementById('ModalTerminal').style.display = 'none';">&times;</span>
1023  <h3><?php print $langs->trans("TerminalSelect"); ?></h3>
1024  </div>
1025  <div class="modal-body">
1026  <button type="button" class="block" onclick="location.href='index.php?setterminal=1'"><?php print $langs->trans("Terminal"); ?> 1</button>
1027  <?php
1028  $nbloop = getDolGlobalInt('TAKEPOS_NUM_TERMINALS');
1029  for ($i = 2; $i <= $nbloop; $i++) {
1030  print '<button type="button" class="block" onclick="location.href=\'index.php?setterminal='.$i.'\'">'.$langs->trans("Terminal").' '.$i.'</button>';
1031  }
1032  ?>
1033  </div>
1034 </div>
1035 </div>
1036 
1037 <!-- Modal multicurrency box -->
1038 <?php if (isModEnabled('multicurrency')) { ?>
1039 <div id="ModalCurrency" class="modal">
1040  <div class="modal-content">
1041  <div class="modal-header">
1042  <span class="close" href="#" onclick="document.getElementById('ModalCurrency').style.display = 'none';">&times;</span>
1043  <h3><?php print $langs->trans("SetMultiCurrencyCode"); ?></h3>
1044  </div>
1045  <div class="modal-body">
1046  <?php
1047  $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'multicurrency';
1048  $sql .= " WHERE entity IN ('".getEntity('multicurrency')."')";
1049  $resql = $db->query($sql);
1050  if ($resql) {
1051  while ($obj = $db->fetch_object($resql)) {
1052  print '<button type="button" class="block" onclick="location.href=\'index.php?setcurrency='.$obj->code.'\'">'.$obj->code.'</button>';
1053  }
1054  }
1055  ?>
1056  </div>
1057  </div>
1058 </div>
1059 <?php } ?>
1060 
1061 <!-- Modal terminal Credit Note -->
1062 <div id="ModalCreditNote" class="modal">
1063  <div class="modal-content">
1064  <div class="modal-header">
1065  <span class="close" href="#" onclick="document.getElementById('ModalCreditNote').style.display = 'none';">&times;</span>
1066  <h3><?php print $langs->trans("invoiceAvoirWithLines"); ?></h3>
1067  </div>
1068  <div class="modal-body">
1069  <button type="button" class="block" onclick="CreditNote(); document.getElementById('ModalCreditNote').style.display = 'none';"><?php print $langs->trans("Yes"); ?></button>
1070  <button type="button" class="block" onclick="document.getElementById('ModalCreditNote').style.display = 'none';"><?php print $langs->trans("No"); ?></button>
1071  </div>
1072 </div>
1073 </div>
1074 
1075 <!-- Modal Note -->
1076 <div id="ModalNote" class="modal">
1077  <div class="modal-content">
1078  <div class="modal-header">
1079  <span class="close" href="#" onclick="document.getElementById('ModalNote').style.display = 'none';">&times;</span>
1080  <h3><?php print $langs->trans("Note"); ?></h3>
1081  </div>
1082  <div class="modal-body">
1083  <input type="text" class="block" id="textinput">
1084  <button type="button" class="block" onclick="SetNote(); document.getElementById('ModalNote').style.display = 'none';">OK</button>
1085  </div>
1086 </div>
1087 </div>
1088 
1089  <div class="row1<?php if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
1090  print 'withhead';
1091  } ?>">
1092 
1093  <div id="poslines" class="div1">
1094  </div>
1095 
1096  <div class="div2">
1097  <button type="button" class="calcbutton" onclick="Edit(7);">7</button>
1098  <button type="button" class="calcbutton" onclick="Edit(8);">8</button>
1099  <button type="button" class="calcbutton" onclick="Edit(9);">9</button>
1100  <button type="button" id="qty" class="calcbutton2" onclick="Edit('qty');"><?php echo $langs->trans("Qty"); ?></button>
1101  <button type="button" class="calcbutton" onclick="Edit(4);">4</button>
1102  <button type="button" class="calcbutton" onclick="Edit(5);">5</button>
1103  <button type="button" class="calcbutton" onclick="Edit(6);">6</button>
1104  <button type="button" id="price" class="calcbutton2" onclick="Edit('p');"><?php echo $langs->trans("Price"); ?></button>
1105  <button type="button" class="calcbutton" onclick="Edit(1);">1</button>
1106  <button type="button" class="calcbutton" onclick="Edit(2);">2</button>
1107  <button type="button" class="calcbutton" onclick="Edit(3);">3</button>
1108  <button type="button" id="reduction" class="calcbutton2" onclick="Edit('r');"><?php echo $langs->trans("ReductionShort"); ?></button>
1109  <button type="button" class="calcbutton" onclick="Edit(0);">0</button>
1110  <button type="button" class="calcbutton" onclick="Edit('.');">.</button>
1111  <button type="button" class="calcbutton poscolorblue" onclick="Edit('c');">C</button>
1112  <button type="button" class="calcbutton2 poscolordelete" id="delete" onclick="deleteline();"><span class="fa fa-trash"></span></button>
1113  </div>
1114 
1115 <?php
1116 
1117 // TakePOS setup check
1118 if (isset($_SESSION["takeposterminal"]) && $_SESSION["takeposterminal"]) {
1119  $sql = "SELECT code, libelle FROM " . MAIN_DB_PREFIX . "c_paiement";
1120  $sql .= " WHERE entity IN (" . getEntity('c_paiement') . ")";
1121  $sql .= " AND active = 1";
1122  $sql .= " ORDER BY libelle";
1123 
1124  $resql = $db->query($sql);
1125  $paiementsModes = array();
1126  if ($resql) {
1127  while ( $obj = $db->fetch_object($resql) ) {
1128  $paycode = $obj->code;
1129  if ($paycode == 'LIQ') {
1130  $paycode = 'CASH';
1131  }
1132  if ($paycode == 'CHQ') {
1133  $paycode = 'CHEQUE';
1134  }
1135 
1136  $constantforkey = "CASHDESK_ID_BANKACCOUNT_" . $paycode . $_SESSION["takeposterminal"];
1137  //var_dump($constantforkey.' '.$conf->global->$constantforkey);
1138  if ( ! empty($conf->global->$constantforkey) && $conf->global->$constantforkey > 0) {
1139  array_push($paiementsModes, $obj);
1140  }
1141  }
1142  }
1143 
1144  if (empty($paiementsModes) && isModEnabled('banque')) {
1145  $langs->load('errors');
1146  setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("TakePOS")), null, 'errors');
1147  setEventMessages($langs->trans("ProblemIsInSetupOfTerminal", $_SESSION["takeposterminal"]), null, 'errors');
1148  }
1149 }
1150 
1151 if (count($maincategories) == 0) {
1152  if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) {
1153  $tmpcategory = new Categorie($db);
1154  $tmpcategory->fetch($conf->global->TAKEPOS_ROOT_CATEGORY_ID);
1155  setEventMessages($langs->trans("TakeposNeedsAtLeastOnSubCategoryIntoParentCategory", $tmpcategory->label), null, 'errors');
1156  } else {
1157  setEventMessages($langs->trans("TakeposNeedsCategories"), null, 'errors');
1158  }
1159 }
1160 // User menu and external TakePOS modules
1161 $menus = array();
1162 $r = 0;
1163 
1164 if (empty($conf->global->TAKEPOS_BAR_RESTAURANT)) {
1165  $menus[$r++] = array('title'=>'<span class="fa fa-layer-group paddingrightonly"></span><div class="trunc">'.$langs->trans("New").'</div>', 'action'=>'New();');
1166 } else {
1167  // BAR RESTAURANT specific menu
1168  $menus[$r++] = array('title'=>'<span class="fa fa-layer-group paddingrightonly"></span><div class="trunc">'.$langs->trans("Place").'</div>', 'action'=>'Floors();');
1169 }
1170 
1171 if (!empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
1172  $menus[$r++] = array('title'=>'<span class="far fa-building paddingrightonly"></span><div class="trunc">'.$langs->trans("Customer").'</div>', 'action'=>'Customer();');
1173 }
1174 $menus[$r++] = array('title'=>'<span class="fa fa-history paddingrightonly"></span><div class="trunc">'.$langs->trans("History").'</div>', 'action'=>'History();');
1175 $menus[$r++] = array('title'=>'<span class="fa fa-cube paddingrightonly"></span><div class="trunc">'.$langs->trans("FreeZone").'</div>', 'action'=>'FreeZone();');
1176 $menus[$r++] = array('title'=>'<span class="fa fa-percent paddingrightonly"></span><div class="trunc">'.$langs->trans("Reduction").'</div>', 'action'=>'Reduction();');
1177 $menus[$r++] = array('title'=>'<span class="far fa-money-bill-alt paddingrightonly"></span><div class="trunc">'.$langs->trans("Payment").'</div>', 'action'=>'CloseBill();');
1178 
1179 if (getDolGlobalString('TAKEPOS_DIRECT_PAYMENT')) {
1180  $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();');
1181 }
1182 
1183 $menus[$r++] = array('title'=>'<span class="fas fa-cut paddingrightonly"></span><div class="trunc">'.$langs->trans("SplitSale").'</div>', 'action'=>'Split();');
1184 
1185 // BAR RESTAURANT specific menu
1186 if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
1187  if (getDolGlobalString('TAKEPOS_ORDER_PRINTERS')) {
1188  $menus[$r++] = array('title'=>'<span class="fa fa-blender-phone paddingrightonly"></span><div class="trunc">'.$langs->trans("Order").'</span>', 'action'=>'TakeposPrintingOrder();');
1189  }
1190  //Button to print receipt before payment
1191  if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT')) {
1192  if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") {
1193  if (getDolGlobalString('TAKEPOS_PRINT_SERVER') && filter_var($conf->global->TAKEPOS_PRINT_SERVER, FILTER_VALIDATE_URL) == true) {
1194  $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'TakeposConnector(placeid);');
1195  } else {
1196  $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'TakeposPrinting(placeid);');
1197  }
1198  } elseif (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") {
1199  $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'DolibarrTakeposPrinting(placeid);');
1200  } else {
1201  $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("Receipt").'</div>', 'action'=>'Print(placeid);');
1202  }
1203  }
1204  if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector" && getDolGlobalString('TAKEPOS_ORDER_NOTES') == 1) {
1205  $menus[$r++] = array('title'=>'<span class="fa fa-sticky-note paddingrightonly"></span><div class="trunc">'.$langs->trans("OrderNotes").'</div>', 'action'=>'TakeposOrderNotes();');
1206  }
1207  if (getDolGlobalString('TAKEPOS_SUPPLEMENTS')) {
1208  $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("ProductSupplements").'</div>', 'action'=>'LoadProducts(\'supplements\');');
1209  }
1210 }
1211 
1212 if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") {
1213  $menus[$r++] = array('title'=>'<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("DOL_OPEN_DRAWER").'</div>', 'action'=>'OpenDrawer();');
1214 }
1215 if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") {
1216  $menus[$r++] = array(
1217  'title' => '<span class="fa fa-receipt paddingrightonly"></span><div class="trunc">'.$langs->trans("DOL_OPEN_DRAWER").'</div>',
1218  'action' => 'DolibarrOpenDrawer();',
1219  );
1220 }
1221 
1222 $sql = "SELECT rowid, status, entity FROM ".MAIN_DB_PREFIX."pos_cash_fence WHERE";
1223 $sql .= " entity = ".((int) $conf->entity)." AND ";
1224 $sql .= " posnumber = ".((int) $_SESSION["takeposterminal"])." AND ";
1225 $sql .= " date_creation > '".$db->idate(dol_get_first_hour(dol_now()))."'";
1226 
1227 $resql = $db->query($sql);
1228 if ($resql) {
1229  $num = $db->num_rows($resql);
1230  if ($num) {
1231  $obj = $db->fetch_object($resql);
1232  $menus[$r++] = array('title'=>'<span class="fas fa-file-invoice-dollar paddingrightonly"></span><div class="trunc">'.$langs->trans("CashReport").'</div>', 'action'=>'CashReport('.$obj->rowid.');');
1233  if ($obj->status == 0) {
1234  $menus[$r++] = array('title'=>'<span class="fas fa-cash-register paddingrightonly"></span><div class="trunc">'.$langs->trans("CloseCashFence").'</div>', 'action'=>'CloseCashFence('.$obj->rowid.');');
1235  }
1236  }
1237 }
1238 
1239 $hookmanager->initHooks(array('takeposfrontend'));
1240 $parameters = array('menus'=>$menus);
1241 $reshook = $hookmanager->executeHooks('ActionButtons', $parameters);
1242 if ($reshook == 0) { //add buttons
1243  if (is_array($hookmanager->resArray) ) {
1244  foreach ($hookmanager->resArray as $resArray) {
1245  foreach ($resArray as $butmenu) {
1246  $menus[$r++] = $butmenu;
1247  }
1248  }
1249  } elseif ($reshook == 1) {
1250  $r = 0; //replace buttons
1251  if (is_array($hookmanager->resArray) ) {
1252  foreach ($hookmanager->resArray as $resArray) {
1253  foreach ($resArray as $butmenu) {
1254  $menus[$r++] = $butmenu;
1255  }
1256  }
1257  }
1258  }
1259 }
1260 
1261 if ($r % 3 == 2) {
1262  $menus[$r++] = array('title'=>'', 'style'=>'visibility: hidden;');
1263 }
1264 
1265 if (!empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
1266  $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().'\';');
1267 }
1268 
1269 if (!empty($conf->global->TAKEPOS_WEIGHING_SCALE)) {
1270  $menus[$r++] = array('title'=>'<span class="fa fa-balance-scale paddingrightonly"></span><div class="trunc">'.$langs->trans("WeighingScale").'</div>', 'action'=>'WeighingScale();');
1271 }
1272 
1273 ?>
1274  <!-- Show buttons -->
1275  <div class="div3">
1276  <?php
1277  $i = 0;
1278  foreach ($menus as $menu) {
1279  $i++;
1280  if (count($menus) > 12 and $i == 12) {
1281  echo '<button style="'.(empty($menu['style']) ? '' : $menu['style']).'" type="button" id="actionnext" class="actionbutton" onclick="MoreActions('.count($menus).');">'.$langs->trans("Next").'</button>';
1282  echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
1283  } elseif ($i > 12) {
1284  echo '<button style="display: none;" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
1285  } else {
1286  echo '<button style="'.(empty($menu['style']) ? '' : $menu['style']).'" type="button" id="action'.$i.'" class="actionbutton" onclick="'.(empty($menu['action']) ? '' : $menu['action']).'">'.$menu['title'].'</button>';
1287  }
1288  }
1289 
1290  if (!empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
1291  print '<!-- Show the search input text -->'."\n";
1292  print '<div class="margintoponly">';
1293  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> ';
1294  print '<a class="marginleftonly hideonsmartphone" onclick="ClearSearch();">'.img_picto('', 'searchclear').'</a>';
1295  print '</div>';
1296  }
1297  ?>
1298  </div>
1299  </div>
1300 
1301  <div class="row2<?php if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
1302  print 'withhead';
1303  } ?>">
1304 
1305  <!-- Show categories -->
1306  <?php
1307  if (getDolGlobalInt('TAKEPOS_HIDE_CATEGORIES') == 1) {
1308  print '<div class="div4" style= "display: none;">';
1309  } else {
1310  print '<div class="div4">';
1311  }
1312 
1313  $count = 0;
1314  while ($count < $MAXCATEG) {
1315  ?>
1316  <div class="wrapper" <?php if ($count == ($MAXCATEG - 2)) {
1317  echo 'onclick="MoreCategories(\'less\');"';
1318  } elseif ($count == ($MAXCATEG - 1)) {
1319  echo 'onclick="MoreCategories(\'more\');"';
1320  } else {
1321  echo 'onclick="LoadProducts('.$count.');"';
1322  } ?> id="catdiv<?php echo $count; ?>">
1323  <?php
1324  if ($count == ($MAXCATEG - 2)) {
1325  //echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="catimg'.$count.'" />';
1326  echo '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1327  } elseif ($count == ($MAXCATEG - 1)) {
1328  //echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="catimg'.$count.'" />';
1329  echo '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1330  } else {
1331  if (!getDolGlobalString('TAKEPOS_HIDE_CATEGORY_IMAGES')) {
1332  echo '<img class="imgwrapper" height="100%" id="catimg'.$count.'" />';
1333  }
1334  }
1335  ?>
1336  <?php if ($count != ($MAXCATEG - 2) && $count != ($MAXCATEG - 1)) { ?>
1337  <div class="description" id="catdivdesc<?php echo $count; ?>">
1338  <div class="description_content" id="catdesc<?php echo $count; ?>"></div>
1339  </div>
1340  <?php } ?>
1341  <div class="catwatermark" id='catwatermark<?php echo $count; ?>'>...</div>
1342  </div>
1343  <?php
1344  $count++;
1345  }
1346  ?>
1347  </div>
1348 
1349  <!-- Show product -->
1350  <div class="div5"<?php if (getDolGlobalInt('TAKEPOS_HIDE_CATEGORIES') == 1) {
1351  print ' style="width:100%;"';
1352  } ?>>
1353  <?php
1354  $count = 0;
1355  while ($count < $MAXPRODUCT) {
1356  print '<div class="wrapper2" id="prodiv'.$count.'" ';
1357  ?>
1358  <?php if ($count == ($MAXPRODUCT - 2)) {
1359  ?> onclick="MoreProducts('less');" <?php
1360  } if ($count == ($MAXPRODUCT - 1)) {
1361  ?> onclick="MoreProducts('more');" <?php
1362  } else {
1363  echo 'onclick="ClickProduct('.$count.');"';
1364  } ?>>
1365  <?php
1366  if ($count == ($MAXPRODUCT - 2)) {
1367  //echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="proimg'.$count.'" />';
1368  print '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1369  } elseif ($count == ($MAXPRODUCT - 1)) {
1370  //echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="proimg'.$count.'" />';
1371  print '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
1372  } else {
1373  if (getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
1374  echo '<button type="button" id="probutton'.$count.'" class="productbutton" style="display: none;"></button>';
1375  } else {
1376  print '<div class="" id="proprice'.$count.'"></div>';
1377  print '<img class="imgwrapper" height="100%" title="" id="proimg'.$count.'">';
1378  }
1379  }
1380  ?>
1381  <?php if ($count != ($MAXPRODUCT - 2) && $count != ($MAXPRODUCT - 1) && !getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) { ?>
1382  <div class="description" id="prodivdesc<?php echo $count; ?>">
1383  <div class="description_content" id="prodesc<?php echo $count; ?>"></div>
1384  </div>
1385  <?php } ?>
1386  <div class="catwatermark" id='prowatermark<?php echo $count; ?>'>...</div>
1387  </div>
1388  <?php
1389  $count++;
1390  }
1391  ?>
1392  <input type="hidden" id="search_start_less" value="0">
1393  <input type="hidden" id="search_start_more" value="0">
1394  <input type="hidden" id="search_pagination" value="">
1395  </div>
1396  </div>
1397 </div>
1398 </body>
1399 <?php
1400 
1401 llxFooter();
1402 
1403 $db->close();
restrictedArea
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.
Definition: security.lib.php:234
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
top_menu_user
top_menu_user($hideloginname=0, $urllogout='')
Build the tooltip on user login.
Definition: main.inc.php:2118
top_htmlhead
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:1482
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
rowid
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
Definition: email_expire_services_to_representatives.php:79
name
$conf db name
Definition: repair.php:122
Categorie
Class to manage categories.
Definition: categorie.class.php:47
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
dol_escape_js
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
Definition: functions.lib.php:1423
code
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge,...
Definition: sync_members_ldap2dolibarr.php:60
dol_get_first_hour
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
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
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
price
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.
Definition: functions.lib.php:5541
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119