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