dolibarr  17.0.4
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($conf->global->{'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 
254 function SetQty(place, selectedline, qty){
255  <?php
256  if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
257  ?>
258  if (qty==0){
259  $("#phonediv2").load("auto_order.php?mobilepage=invoice&action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
260  });
261  }
262  else{
263  $("#phonediv2").load("auto_order.php?mobilepage=invoice&action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+qty, function() {
264  });
265  }
266  <?php
267  } else {
268  ?>
269  if (qty==0){
270  $("#phonediv2").load("invoice.php?mobilepage=invoice&action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
271  });
272  }
273  else{
274  $("#phonediv2").load("invoice.php?mobilepage=invoice&action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+qty, function() {
275  });
276  }
277  <?php
278  }
279  ?>
280  LoadCats();
281 }
282 
283 function SetNote(place, selectedline){
284  var note = prompt("<?php $langs->trans('Note'); ?>", "");
285  $("#phonediv2").load("auto_order.php?mobilepage=invoice&action=updateqty&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&number="+qty, function() {
286  });
287  LoadCats();
288 }
289 
290 function LoadCats(){
291  <?php
292  if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
293  echo '$("#phonediv1").load("auto_order.php?mobilepage=cats&place="+place, function() {
294  });';
295  } else {
296  echo '$("#phonediv1").load("invoice.php?mobilepage=cats&place="+place, function() {
297  });';
298  }
299  ?>
300 }
301 
302 function LoadProducts(idcat){
303 
304  <?php
305  if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
306  echo '$("#phonediv1").load("auto_order.php?mobilepage=products&catid="+idcat+"&place="+place, function() {
307  });';
308  } else {
309  echo '$("#phonediv1").load("invoice.php?mobilepage=products&catid="+idcat+"&place="+place, function() {
310  });';
311  }
312  ?>
313 }
314 
315 function LoadPlacesList(){
316  $("#phonediv1").load("invoice.php?mobilepage=places", function() {
317  });
318 }
319 
320 function TakeposPrintingOrder(){
321  console.log("TakeposPrintingOrder");
322  <?php
323  if (defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
324  echo '$("#phonediv2").load("auto_order.php?action=order&token='.newToken().'&mobilepage=order&place="+place, function() {
325  });';
326  echo '$("#phonediv1").load("auto_order.php?action=publicpayment&token='.newToken().'&place="+place, function() {
327  });';
328  } else {
329  echo '$("#phonediv2").load("invoice.php?action=order&token='.newToken().'&place="+place, function() {
330  });';
331  }
332  ?>
333 }
334 
335 function Exit(){
336  window.location.href='../user/logout.php?token=<?php echo newToken(); ?>';
337 }
338 
339 function CheckPlease(payment){
340  if (payment==undefined){
341  $("#phonediv1").load("auto_order.php?action=checkplease&token=<?php echo newToken(); ?>&place="+place, function() {
342  });
343  }
344  else{
345  console.log("Request the check to the waiter");
346  $("#phonediv1").load("auto_order.php?action=checkplease&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&payment="+payment, function() {
347  });
348  }
349 }
350 
351 </script>
352 
353 <body style="background-color:#D1D1D1;">
354  <?php
355  if ($conf->global->TAKEPOS_NUM_TERMINALS != "1" && $_SESSION["takeposterminal"] == "") {
356  print '<div class="dialog-info-takepos-terminal" id="dialog-info" title="TakePOS">'.$langs->trans('TerminalSelect').'</div>';
357  }
358  ?>
359 <div class="container">
360  <div class="phonebuttonsrow">
361  <?php
362  if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
363  print '<button type="button" class="phonebutton" onclick="LoadPlacesList();">'.strtoupper(substr($langs->trans('Floors'), 0, 3)).'</button>';
364  print '<button type="button" class="phonebutton" onclick="LoadCats();">'.strtoupper(substr($langs->trans('Categories'), 0, 3)).'</button>';
365  print '<button type="button" class="phonebutton" onclick="TakeposPrintingOrder();">'.strtoupper(substr($langs->trans('Order'), 0, 3)).'</button>';
366  print '<button type="button" class="phonebutton" onclick="Exit();">'.strtoupper(substr($langs->trans('Logout'), 0, 3)).'</button>';
367  } else {
368  print '<button type="button" class="publicphonebutton phoneblue" onclick="LoadCats();">'.strtoupper(substr($langs->trans('Categories'), 0, 5)).'</button>';
369  print '<button type="button" class="publicphonebutton phoneorange" onclick="PublicPreOrder();">'.strtoupper(substr($langs->trans('Order'), 0, 5)).'</button>';
370  print '<button type="button" class="publicphonebutton phonegreen" onclick="CheckPlease();">'.strtoupper(substr($langs->trans('Payment'), 0, 5)).'</button>';
371  }
372  ?>
373  </div>
374  <div class="phonerow2">
375  <div id="phonediv2" class="phonediv2"></div>
376  </div>
377  <div class="phonerow1">
378  <div id="phonediv1" class="phonediv1"></div>
379  </div>
380 </div>
381 </body>
382  <?php
383 }
384 
385 llxFooter();
386 
387 $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.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1440
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:1571
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
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.