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