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