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