dolibarr 23.0.3
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
34//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
35//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
36//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
37//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
38if (!defined('NOTOKENRENEWAL')) {
39 define('NOTOKENRENEWAL', '1');
40}
41if (!defined('NOREQUIREMENU')) {
42 define('NOREQUIREMENU', '1');
43}
44if (!defined('NOREQUIREHTML')) {
45 define('NOREQUIREHTML', '1');
46}
47if (!defined('NOREQUIREAJAX')) {
48 define('NOREQUIREAJAX', '1');
49}
50
51if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
52 print 'This page must be called by takepos/public/auto_order.php';
53 exit;
54}
55
56require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
57require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
58require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
59require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
60
61// Decode place if it is an order from a customer phone
62$place = GETPOSTISSET("key") ? dol_decode(GETPOST('key')) : GETPOST('place', 'aZ09');
63
64$action = GETPOST('action', 'aZ09');
65$setterminal = GETPOSTINT('setterminal');
66$idproduct = GETPOSTINT('idproduct');
67$mobilepage = GETPOST('mobilepage', 'alphanohtml'); // Set when page is loaded by a js .load()
68
69if ($setterminal > 0) {
70 $_SESSION["takeposterminal"] = $setterminal;
71}
72
73$langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter"));
74
75
76/*
77 * View
78 */
79
80$title = 'TakePOS - Dolibarr '.DOL_VERSION;
81if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
82 $title = 'TakePOS - ' . getDolGlobalString('MAIN_APPLICATION_TITLE');
83}
84
85// llxHeader
86if (empty($mobilepage)) {
87 $head = '<meta name="apple-mobile-web-app-title" content="TakePOS"/>
88 <meta name="apple-mobile-web-app-capable" content="yes">
89 <meta name="mobile-web-app-capable" content="yes">
90 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>';
91 $arrayofcss = array(
92 '/takepos/css/phone.css',
93 );
94 $arrayofjs = array('/takepos/js/jquery.colorbox-min.js');
95 $disablejs = 0;
96 $disablehead = 0;
97 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
98
99 print '<body style="background-color:#D1D1D1;">'."\n";
100} else {
101 top_htmlhead('', $title);
102
103 print '<body>'."\n";
104}
105
106
107if ($action == "productinfo" && $user->hasRight('takepos', 'run')) {
108 $prod = new Product($db);
109 $prod->fetch($idproduct);
110 print '<button type="button" class="publicphonebutton2 phoneblue total" onclick="AddProductConfirm(place, '.$idproduct.')">'.$langs->trans('Add').'</button>';
111 print "<br><b>".$prod->label."</b><br>";
112 print '<img class="imgwrapper" width="60%" src="'.DOL_URL_ROOT.'/takepos/public/auto_order.php?genimg=pro&query=pro&id='.$idproduct.'">';
113 print "<br>".$prod->description;
114 print "<br><b>".price($prod->price_ttc, 1, $langs, 1, -1, -1, getDolCurrency())."</b>";
115 print '<br>';
116} elseif ($action == "editline" && $user->hasRight('takepos', 'run')) {
117 $placeid = GETPOSTINT('placeid');
118 $selectedline = GETPOSTINT('selectedline');
119 $invoice = new Facture($db);
120 $invoice->fetch($placeid);
121 foreach ($invoice->lines as $line) {
122 if ($line->id == $selectedline) {
123 $prod = new Product($db);
124 $prod->fetch($line->fk_product);
125 print "<b>".$prod->label."</b><br>";
126 print '<img class="imgwrapper" width="60%" src="'.DOL_URL_ROOT.'/takepos/public/auto_order.php?genimg=pro&query=pro&id='.$line->fk_product.'">';
127 print "<br>".$prod->description;
128 print "<br><b>".price($prod->price_ttc, 1, $langs, 1, -1, -1, getDolCurrency())."</b>";
129 print '<br>';
130 print '<button type="button" class="publicphonebutton2 phonered width24" onclick="SetQty(place, '.$selectedline.', '.($line->qty - 1).')">-</button>';
131 print '<button type="button" class="publicphonebutton2 phonegreen width24" onclick="SetQty(place, '.$selectedline.', '.($line->qty + 1).')">+</button>';
132 print '<button type="button" class="publicphonebutton2 phoneblue width24" onclick="SetNote(place, '.$selectedline.')">'.$langs->trans('Note').'</button>';
133 }
134 }
135} else {
136 ?>
137 <div class="container">
138 <div class="phonebuttonsrow center">
139 <?php
140 print '<button type="button" class="publicphonebutton phoneblue uppercase" onclick="LoadCats();">'.dol_trunc($langs->trans('Categories'), 8, 'right', 'UTF-8').'</button>';
141 print '<button type="button" class="publicphonebutton phoneorange uppercase" onclick="PublicPreOrder();">'.dol_trunc($langs->trans('Order'), 8, 'right', 'UTF-8').'</button>';
142 // 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)
143 //print '<button type="button" class="publicphonebutton phonegreen uppercase" onclick="CheckPlease();">'.dol_trunc($langs->trans('Payment'), 8, 'right', 'UTF-8').'</button>';
144 ?>
145 </div>
146 <div class="phonerow2">
147 <div id="phonediv2" class="phonediv2"></div>
148 </div>
149 <div class="phonerow1">
150 <div id="phonediv1" class="phonediv1"></div>
151 </div>
152 </div>
153
154 <script type="text/javascript">
155 <?php
156 $categorie = new Categorie($db);
157 $categories = $categorie->get_full_arbo('product', getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID'), 1);
158
159 // Search root category to know its level
160 //$conf->global->TAKEPOS_ROOT_CATEGORY_ID=0;
161 $levelofrootcategory = 0;
162 if (getDolGlobalInt('TAKEPOS_ROOT_CATEGORY_ID') > 0) {
163 foreach ($categories as $key => $categorycursor) {
164 if ($categorycursor['id'] == getDolGlobalInt('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 var categories = <?php echo json_encode($maincategories); ?>;
187 var subcategories = <?php echo json_encode($subcategories); ?>;
188
189 var currentcat;
190 var pageproducts=0;
191 var pagecategories=0;
192 var pageactions=0;
193 var place="<?php echo $place; ?>";
194 var editaction="qty";
195 var editnumber="";
196
197
198 $( document ).ready(function() {
199 console.log("Refresh");
200 LoadPlace(place);
201 });
202
203 function LoadPlace(placeid){
204 place=placeid;
205 <?php
206 echo '$("#phonediv2").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?mobilepage=invoice&place="+place+" #tablelines", function() {
207 });';
208 ?>
209 LoadCats();
210 }
211
212 function AddProduct(placeid, productid){
213 <?php
214 // If is a public terminal first show product information
215 print 'place=placeid;
216 $("#phonediv1").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?action=productinfo&token='.newToken().'&place="+place+"&idproduct="+productid, function() {
217 });';
218 ?>
219 }
220
221 function PublicPreOrder(){
222 $("#phonediv1").load("<?php echo DOL_URL_ROOT.'/takepos/public/auto_order.php?action=publicpreorder&token='.newToken(); ?>&place="+place, function() {
223 });
224 }
225
226 function AddProductConfirm(placeid, productid){
227 place=placeid;
228 <?php
229 echo '$("#phonediv2").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?mobilepage=invoice&action=addline&token='.newToken().'&place="+place+"&idproduct="+productid, function() {
230 });';
231 ?>
232
233 return true;
234 }
235
236 function SetQty(place, selectedline, qty){
237 console.log("We click on SetQty()");
238 if (qty==0){
239 $("#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() {
240 });
241 }
242 else{
243 $("#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() {
244 });
245 }
246 LoadCats();
247
248 return true;
249 }
250
251 function SetNote(place, selectedline){
252 console.log("We click on SetNote()");
253 var note = prompt("<?php dol_escape_js($langs->trans('Note')); ?>", "");
254 $("#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() {
255 });
256 LoadCats();
257 }
258
259 function LoadCats(){
260 console.log("We click on LoadCats()");
261 <?php
262 // Load invoice.php to get categories by using auto_order so it will define INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE
263 echo '$("#phonediv1").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?format=div&mobilepage=cats&place="+place+" #tablelines", function() {
264 });';
265 ?>
266 }
267
268 function LoadProducts(idcat) {
269 console.log("We click on LoadProducts()");
270 <?php
271 echo '$("#phonediv1").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?format=div&mobilepage=products&catid="+idcat+"&place="+place+"", function() {
272 });';
273 ?>
274 }
275
276 function LoadPlacesList(){
277 $("#phonediv1").load("invoice.php?mobilepage=places", function() {
278 });
279 }
280
281 function TakeposPrintingOrder(){
282 console.log("TakeposPrintingOrder");
283 <?php
284 echo '$("#phonediv2").load("'.DOL_URL_ROOT.'/takepos/public/auto_order.php?action=order&token='.newToken().'&mobilepage=order&place="+place, function() {
285 });';
286 ?>
287 }
288
289 function Exit(){
290 console.log("Click on Exit");
291 window.location.href='<?php echo DOL_URL_ROOT ?>/user/logout.php?token=<?php echo newToken(); ?>';
292 }
293
294 function CheckPlease(payment){
295 console.log("Click on CheckPlease");
296 if (payment==undefined){
297 $("#phonediv1").load("<?php echo DOL_URL_ROOT ?>/takepos/public/auto_order.php?action=checkplease&token=<?php echo newToken(); ?>&place="+place, function() {
298 });
299 }
300 else{
301 console.log("Request the check to the waiter");
302 $("#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() {
303 });
304 }
305 }
306
307 </script>
308
309
310 <?php
311 if (getDolGlobalString('TAKEPOS_NUM_TERMINALS') != "1" && $_SESSION["takeposterminal"] == "") {
312 print '<div class="dialog-info-takepos-terminal" id="dialog-info" title="TakePOS">'.$langs->trans('TerminalSelect').'</div>';
313 }
314}
315
316print '</body>';
317print '</html>';
318
319
320$db->close();
Class to manage categories.
Class to manage invoices.
Class to manage products or services.
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'.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
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.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:125
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.