dolibarr  19.0.0-dev
phone.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
25 //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
26 //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
27 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
28 if (!defined('NOTOKENRENEWAL')) {
29  define('NOTOKENRENEWAL', '1');
30 }
31 if (!defined('NOREQUIREMENU')) {
32  define('NOREQUIREMENU', '1');
33 }
34 if (!defined('NOREQUIREHTML')) {
35  define('NOREQUIREHTML', '1');
36 }
37 if (!defined('NOREQUIREAJAX')) {
38  define('NOREQUIREAJAX', '1');
39 }
40 
41 if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
42  require '../main.inc.php';
43 }
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
47 require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
48 
49 if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
50  // Decode place if it is an order from customer phone
51  $place = GETPOSTISSET("key") ? dol_decode(GETPOST('key')) : GETPOST('place', 'aZ09');
52 } else {
53  $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
54 }
55 $action = GETPOST('action', 'aZ09');
56 $setterminal = GETPOST('setterminal', 'int');
57 $idproduct = GETPOST('idproduct', 'int');
58 
59 if ($setterminal > 0) {
60  $_SESSION["takeposterminal"] = $setterminal;
61 }
62 
63 $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter"));
64 
65 if (empty($user->rights->takepos->run) && !defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
67 }
68 
69 
70 /*
71  * View
72  */
73 
74 if (empty($action)) {
75  // Code for llxHeader()
76  $title = 'TakePOS - Dolibarr '.DOL_VERSION;
77  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
78  $title = 'TakePOS - '.$conf->global->MAIN_APPLICATION_TITLE;
79  }
80  $head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
81  <meta name="apple-mobile-web-app-capable" content="yes">
82  <meta name="mobile-web-app-capable" content="yes">
83  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
84  $arrayofcss = array('/takepos/css/phone.css');
85 
86  top_htmlhead($head, $title, 0, 0, '', $arrayofcss);
87 } else {
88  top_httphead('text/html', 1);
89 }
90 
91 if ($action == "productinfo") {
92  $prod = new Product($db);
93  $prod->fetch($idproduct);
94  print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="AddProductConfirm(place, '.$idproduct.')">'.$langs->trans('Add').'</button>';
95  print "<br><b>".$prod->label."</b><br>";
96  print '<img class="imgwrapper" width="60%" src="'.DOL_URL_ROOT.'/takepos/public/auto_order.php?genimg=pro&query=pro&id='.$idproduct.'">';
97  print "<br>".$prod->description;
98  print "<br><b>".price($prod->price_ttc, 1, $langs, 1, -1, -1, $conf->currency)."</b>";
99  print '<br>';
100 } elseif ($action == "publicpreorder") {
101  print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="TakeposPrintingOrder();">'.$langs->trans('Confirm').'</button>';
102  print "<br><br>";
103  print '<div class="comment">
104  <textarea class="textinput" placeholder="'.$langs->trans('Note').'"></textarea>
105  </div>';
106  print '<br>';
107 } elseif ($action == "publicpayment") {
108  $langs->loadLangs(array("orders"));
109  print '<h1>'.$langs->trans('StatusOrderDelivered').'</h1>';
110  print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="CheckPlease();">'.$langs->trans('Payment').'</button>';
111  print '<br>';
112 } elseif ($action == "checkplease") {
113  if (GETPOSTISSET("payment")) {
114  print '<h1>'.$langs->trans('StatusOrderDelivered').'</h1>';
115  require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
116  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
117  $printer = new dolReceiptPrinter($db);
118  $printer->initPrinter(getDolGlobalString('TAKEPOS_PRINTER_TO_USE'.$_SESSION["takeposterminal"]));
119  $printer->printer->feed();
120  $printer->printer->feed();
121  $printer->printer->text($langs->trans('IM'));
122  $printer->printer->feed();
123  $printer->printer->text($langs->trans('Place').": ".$place);
124  $printer->printer->feed();
125  $printer->printer->text($langs->trans('Payment').": ".$langs->trans(GETPOST('payment', 'alpha')));
126  $printer->printer->feed();
127  $printer->printer->feed();
128  $printer->printer->feed();
129  $printer->printer->feed();
130  $printer->printer->feed();
131  $printer->close();
132  } else {
133  print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="CheckPlease(\'Cash\')">'.$langs->trans('Cash').'</button>';
134  print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="CheckPlease(\'CreditCard\')">'.$langs->trans('CreditCard').'</button>';
135  print '<br>';
136  }
137 } elseif ($action == "editline") {
138  $placeid = GETPOST('placeid', 'int');
139  $selectedline = GETPOST('selectedline', 'int');
140  $invoice = new Facture($db);
141  $invoice->fetch($placeid);
142  foreach ($invoice->lines as $line) {
143  if ($line->id == $selectedline) {
144  $prod = new Product($db);
145  $prod->fetch($line->fk_product);
146  print "<b>".$prod->label."</b><br>";
147  print '<img class="imgwrapper" width="60%" src="'.DOL_URL_ROOT.'/takepos/public/auto_order.php?genimg=pro&query=pro&id='.$line->fk_product.'">';
148  print "<br>".$prod->description;
149  print "<br><b>".price($prod->price_ttc, 1, $langs, 1, -1, -1, $conf->currency)."</b>";
150  print '<br>';
151  print '<button type="button" class="publicphonebutton2 phonered width24" onclick="SetQty(place, '.$selectedline.', '.($line->qty - 1).')">-</button>';
152  print '<button type="button" class="publicphonebutton2 phonegreen width24" onclick="SetQty(place, '.$selectedline.', '.($line->qty + 1).')">+</button>';
153  print '<button type="button" class="publicphonebutton2 phoneblue width24" onclick="SetNote(place, '.$selectedline.')">'.$langs->trans('Note').'</button>';
154  }
155  }
156 } else {
157  ?>
158 <script type="text/javascript">
159  <?php
160  $categorie = new Categorie($db);
161  $categories = $categorie->get_full_arbo('product', (($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) ? $conf->global->TAKEPOS_ROOT_CATEGORY_ID : 0), 1);
162 
163  // Search root category to know its level
164  //$conf->global->TAKEPOS_ROOT_CATEGORY_ID=0;
165  $levelofrootcategory = 0;
166  if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0) {
167  foreach ($categories as $key => $categorycursor) {
168  if ($categorycursor['id'] == $conf->global->TAKEPOS_ROOT_CATEGORY_ID) {
169  $levelofrootcategory = $categorycursor['level'];
170  break;
171  }
172  }
173  }
174  $levelofmaincategories = $levelofrootcategory + 1;
175 
176  $maincategories = array();
177  $subcategories = array();
178  foreach ($categories as $key => $categorycursor) {
179  if ($categorycursor['level'] == $levelofmaincategories) {
180  $maincategories[$key] = $categorycursor;
181  } else {
182  $subcategories[$key] = $categorycursor;
183  }
184  }
185 
186  sort($maincategories);
187  sort($subcategories);
188 
189 
190  ?>
191 
192 var categories = <?php echo json_encode($maincategories); ?>;
193 var subcategories = <?php echo json_encode($subcategories); ?>;
194 
195 var currentcat;
196 var pageproducts=0;
197 var pagecategories=0;
198 var pageactions=0;
199 var place="<?php echo $place; ?>";
200 var editaction="qty";
201 var editnumber="";
202 
203 
204 $( document ).ready(function() {
205  console.log("Refresh");
206  LoadPlace(place);
207 });
208 
209 function LoadPlace(placeid){
210  place=placeid;
211  <?php
212  if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
213  echo '$("#phonediv2").load("auto_order.php?mobilepage=invoice&place="+place, function() {
214  });';
215  } else {
216  echo '$("#phonediv2").load("invoice.php?mobilepage=invoice&place="+place, function() {
217  });';
218  }
219  ?>
220  LoadCats();
221 }
222 
223 function AddProduct(placeid, productid){
224  <?php
225  // If is a public terminal first show product information
226  if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
227  print 'place=placeid;
228  $("#phonediv1").load("auto_order.php?action=productinfo&token='.newToken().'&place="+place+"&idproduct="+productid, function() {
229  });';
230  } else {
231  print 'AddProductConfirm(placeid, productid);';
232  }
233  ?>
234 }
235 
236 function PublicPreOrder(){
237  $("#phonediv1").load("auto_order.php?action=publicpreorder&token=<?php echo newToken(); ?>&place="+place, function() {
238  });
239 }
240 
241 function AddProductConfirm(placeid, productid){
242  place=placeid;
243  <?php
244  if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
245  echo '$("#phonediv2").load("auto_order.php?mobilepage=invoice&action=addline&token='.newToken().'&place="+place+"&idproduct="+productid, function() {
246  });';
247  } else {
248  echo '$("#phonediv2").load("invoice.php?mobilepage=invoice&action=addline&token='.newToken().'&place="+place+"&idproduct="+productid, function() {
249  });';
250  }
251  ?>
252 
253  return true;
254 }
255 
256 function SetQty(place, selectedline, qty){
257  <?php
258  if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
259  ?>
260  if (qty==0){
261  $("#phonediv2").load("auto_order.php?mobilepage=invoice&action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
262  });
263  }
264  else{
265  $("#phonediv2").load("auto_order.php?mobilepage=invoice&action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+qty, function() {
266  });
267  }
268  <?php
269  } else {
270  ?>
271  if (qty==0){
272  $("#phonediv2").load("invoice.php?mobilepage=invoice&action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
273  });
274  }
275  else{
276  $("#phonediv2").load("invoice.php?mobilepage=invoice&action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+qty, function() {
277  });
278  }
279  <?php
280  }
281  ?>
282  LoadCats();
283 
284  return true;
285 }
286 
287 function SetNote(place, selectedline){
288  var note = prompt("<?php $langs->trans('Note'); ?>", "");
289  $("#phonediv2").load("auto_order.php?mobilepage=invoice&action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+qty, function() {
290  });
291  LoadCats();
292 }
293 
294 function LoadCats(){
295  <?php
296  if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
297  echo '$("#phonediv1").load("auto_order.php?mobilepage=cats&place="+place, function() {
298  });';
299  } else {
300  echo '$("#phonediv1").load("invoice.php?mobilepage=cats&place="+place, function() {
301  });';
302  }
303  ?>
304 }
305 
306 function LoadProducts(idcat){
307 
308  <?php
309  if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
310  echo '$("#phonediv1").load("auto_order.php?mobilepage=products&catid="+idcat+"&place="+place, function() {
311  });';
312  } else {
313  echo '$("#phonediv1").load("invoice.php?mobilepage=products&catid="+idcat+"&place="+place, function() {
314  });';
315  }
316  ?>
317 }
318 
319 function LoadPlacesList(){
320  $("#phonediv1").load("invoice.php?mobilepage=places", function() {
321  });
322 }
323 
324 function TakeposPrintingOrder(){
325  console.log("TakeposPrintingOrder");
326  <?php
327  if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
328  echo '$("#phonediv2").load("auto_order.php?action=order&token='.newToken().'&mobilepage=order&place="+place, function() {
329  });';
330  echo '$("#phonediv1").load("auto_order.php?action=publicpayment&token='.newToken().'&place="+place, function() {
331  });';
332  } else {
333  echo '$("#phonediv2").load("invoice.php?action=order&token='.newToken().'&place="+place, function() {
334  });';
335  }
336  ?>
337 }
338 
339 function Exit(){
340  window.location.href='../user/logout.php?token=<?php echo newToken(); ?>';
341 }
342 
343 function CheckPlease(payment){
344  if (payment==undefined){
345  $("#phonediv1").load("auto_order.php?action=checkplease&token=<?php echo newToken(); ?>&place="+place, function() {
346  });
347  }
348  else{
349  console.log("Request the check to the waiter");
350  $("#phonediv1").load("auto_order.php?action=checkplease&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&payment="+payment, function() {
351  });
352  }
353 }
354 
355 </script>
356 
357 <body style="background-color:#D1D1D1;">
358  <?php
359  if ($conf->global->TAKEPOS_NUM_TERMINALS != "1" && $_SESSION["takeposterminal"] == "") {
360  print '<div class="dialog-info-takepos-terminal" id="dialog-info" title="TakePOS">'.$langs->trans('TerminalSelect').'</div>';
361  }
362  ?>
363 <div class="container">
364  <div class="phonebuttonsrow">
365  <?php
366  if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
367  print '<button type="button" class="phonebutton" onclick="LoadPlacesList();">'.strtoupper(substr($langs->trans('Floors'), 0, 3)).'</button>';
368  print '<button type="button" class="phonebutton" onclick="LoadCats();">'.strtoupper(substr($langs->trans('Categories'), 0, 3)).'</button>';
369  print '<button type="button" class="phonebutton" onclick="TakeposPrintingOrder();">'.strtoupper(substr($langs->trans('Order'), 0, 3)).'</button>';
370  print '<button type="button" class="phonebutton" onclick="Exit();">'.strtoupper(substr($langs->trans('Logout'), 0, 3)).'</button>';
371  } else {
372  print '<button type="button" class="publicphonebutton phoneblue" onclick="LoadCats();">'.strtoupper(substr($langs->trans('Categories'), 0, 5)).'</button>';
373  print '<button type="button" class="publicphonebutton phoneorange" onclick="PublicPreOrder();">'.strtoupper(substr($langs->trans('Order'), 0, 5)).'</button>';
374  print '<button type="button" class="publicphonebutton phonegreen" onclick="CheckPlease();">'.strtoupper(substr($langs->trans('Payment'), 0, 5)).'</button>';
375  }
376  ?>
377  </div>
378  <div class="phonerow2">
379  <div id="phonediv2" class="phonediv2"></div>
380  </div>
381  <div class="phonerow1">
382  <div id="phonediv1" class="phonediv1"></div>
383  </div>
384 </div>
385 </body>
386  <?php
387 }
388 
389 llxFooter();
390 
391 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage categories.
Class to manage invoices.
Class to manage products or services.
Class to manage Receipt Printers.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
if(!defined('NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1494
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:1625
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:120
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.