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