dolibarr 21.0.0-alpha
floors.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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('NOREQUIREMENU')) {
30 define('NOREQUIREMENU', '1');
31}
32if (!defined('NOREQUIREHTML')) {
33 define('NOREQUIREHTML', '1');
34}
35if (!defined('NOREQUIREAJAX')) {
36 define('NOREQUIREAJAX', '1');
37}
38
39// Load Dolibarr environment
40require '../main.inc.php'; // Load $user and permissions
41require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
42
43$langs->loadLangs(array("bills", "orders", "commercial", "cashdesk"));
44
45$floor = GETPOSTINT('floor');
46if ($floor == "") {
47 $floor = 1;
48}
49$id = GETPOSTINT('id');
50$action = GETPOST('action', 'aZ09');
51$left = GETPOST('left', 'alpha');
52$top = GETPOST('top', 'alpha');
53
54$place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Ba or Restaurant
55
56$newname = GETPOST('newname', 'alpha');
57$mode = GETPOST('mode', 'alpha');
58
59if (!$user->hasRight('takepos', 'run')) {
61}
62
63
64/*
65 * Actions
66 */
67
68if ($action == "getTables" && $user->hasRight('takepos', 'run')) {
69 $sql = "SELECT rowid, entity, label, leftpos, toppos, floor FROM ".MAIN_DB_PREFIX."takepos_floor_tables WHERE floor = ".((int) $floor)." AND entity IN (".getEntity('takepos').")";
70 $resql = $db->query($sql);
71 $rows = array();
72 while ($row = $db->fetch_array($resql)) {
73 $invoice = new Facture($db);
74 $result = $invoice->fetch('', '(PROV-POS'.$_SESSION['takeposterminal'].'-'.$row['rowid'].')');
75 if ($result > 0) {
76 $row['occupied'] = "red";
77 }
78 $rows[] = $row;
79 }
80
81 top_httphead('application/json');
82 echo json_encode($rows);
83 exit;
84}
85
86if ($action == "update" && $user->hasRight('takepos', 'run')) {
87 if ($left > 95) {
88 $left = 95;
89 }
90 if ($top > 95) {
91 $top = 95;
92 }
93 if ($left > 3 or $top > 4) {
94 $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables SET leftpos = ".((int) $left).", toppos = ".((int) $top)." WHERE rowid = ".((int) $place));
95 } else {
96 $db->query("DELETE from ".MAIN_DB_PREFIX."takepos_floor_tables WHERE rowid = ".((int) $place));
97 }
98}
99
100if ($action == "updatename" && $user->hasRight('takepos', 'run')) {
101 $newname = preg_replace("/[^a-zA-Z0-9\s]/", "", $newname); // Only English chars
102 if (strlen($newname) > 3) {
103 $newname = substr($newname, 0, 3); // Only 3 chars
104 }
105 $resql = $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables SET label='".$db->escape($newname)."' WHERE rowid = ".((int) $place));
106}
107
108if ($action == "add" && $user->hasRight('takepos', 'run')) {
109 $sql = "INSERT INTO ".MAIN_DB_PREFIX."takepos_floor_tables(entity, label, leftpos, toppos, floor) VALUES (".$conf->entity.", '', '45', '45', ".((int) $floor).")";
110 $asdf = $db->query($sql);
111 $db->query("UPDATE ".MAIN_DB_PREFIX."takepos_floor_tables SET label = rowid WHERE label = ''"); // No empty table names
112}
113
114
115/*
116 * View
117 */
118
119// Title
120$head = '';
121$title = 'TakePOS - Dolibarr '.DOL_VERSION;
122if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
123 $title = 'TakePOS - ' . getDolGlobalString('MAIN_APPLICATION_TITLE');
124}
125$arrayofcss = array('/takepos/css/pos.css.php?a=xxx');
126
127top_htmlhead($head, $title, 0, 0, array(), $arrayofcss);
128
129?>
130<body style="overflow: hidden">
131
132<style type="text/css">
133div.tablediv{
134 background-image:url(img/table.gif);
135 -moz-background-size:100% 100%;
136 -webkit-background-size:100% 100%;
137 background-size:100% 100%;
138 height:10%;
139 width:10%;
140 text-align: center;
141 font-size:300%;
142 color:white;
143}
144
145/* Color when a table has a pending order/invoice */
146div.red{
147 color:red;
148}
149</style>
150
151<script>
152var DragDrop='<?php echo $langs->trans("DragDrop"); ?>';
153
154function updateplace(idplace, left, top) {
155 console.log("updateplace idplace="+idplace+" left="+left+" top="+top);
156 $.ajax({
157 type: "POST",
158 url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
159 data: { action: "update", left: left, top: top, place: idplace, token: '<?php echo currentToken(); ?>' }
160 }).done(function( msg ) {
161 window.location.href='floors.php?mode=edit&floor=<?php echo urlencode((string) ($floor)); ?>';
162 });
163}
164
165function updatename(rowid) {
166 var after=$("#tablename"+rowid).text();
167 console.log("updatename rowid="+rowid+" after="+after);
168 $.ajax({
169 type: "POST",
170 url: "<?php echo DOL_URL_ROOT.'/takepos/floors.php'; ?>",
171 data: { action: "updatename", place: rowid, newname: after, token: '<?php echo currentToken(); ?>' }
172 }).done(function( msg ) {
173 window.location.href='floors.php?mode=edit&floor=<?php echo urlencode((string) ($floor)); ?>';
174 });
175}
176
177function LoadPlace(place){
178 parent.location.href='index.php?place='+place;
179}
180
181
182$( document ).ready(function() {
183 $.getJSON('./floors.php?action=getTables&token=<?php echo newToken();?>&floor=<?php echo $floor; ?>', function(data) {
184 $.each(data, function(key, val) {
185 <?php if ($mode == "edit") {?>
186 $('body').append('<div class="tablediv" contenteditable onblur="updatename('+val.rowid+');" style="position: absolute; left: '+val.leftpos+'%; top: '+val.toppos+'%;" id="tablename'+val.rowid+'">'+val.label+'</div>');
187 $( "#tablename"+val.rowid ).draggable(
188 {
189 start: function() {
190 $("#add").html("<?php echo $langs->trans("Delete"); ?>");
191 },
192 stop: function() {
193 var left=$(this).offset().left*100/$(window).width();
194 var top=$(this).offset().top*100/$(window).height();
195 updateplace($(this).attr('id').substr(9), left, top);
196 }
197 }
198 );
199 //simultaneous draggable and contenteditable
200 $('#'+val.label).draggable().bind('click', function(){
201 $(this).focus();
202 })
203 <?php } else {?>
204 $('body').append('<div class="tablediv '+val.occupied+'" onclick="LoadPlace('+val.rowid+');" style="position: absolute; left: '+val.leftpos+'%; top: '+val.toppos+'%;" id="tablename'+val.rowid+'">'+val.label+'</div>');
205 <?php } ?>
206 });
207 });
208});
209
210</script>
211
212<?php if ($user->admin) {?>
213<div style="position: absolute; left: 0.1%; top: 0.8%; width:8%; height:11%;">
214 <?php if ($mode == "edit") {?>
215<a id="add" onclick="window.location.href='floors.php?mode=edit&action=add&token=<?php echo newToken() ?>&floor=<?php echo $floor; ?>';"><?php echo $langs->trans("AddTable"); ?></a>
216 <?php } else { ?>
217<a onclick="window.location.href='floors.php?mode=edit&token=<?php echo newToken() ?>&floor=<?php echo $floor; ?>';"><?php echo $langs->trans("Edit"); ?></a>
218 <?php } ?>
219</div>
220<?php }
221?>
222
223<div style="position: absolute; left: 25%; bottom: 8%; width:50%; height:3%;">
224 <center>
225 <h1>
226 <?php if ($floor > 1) { ?>
227 <img class="valignmiddle" src="./img/arrow-prev.png" width="5%" onclick="location.href='floors.php?floor=<?php if ($floor > 1) {
228 $floor--;
229 echo $floor;
230 $floor++;
231 } else {
232 echo "1";
233 } ?>';">
234 <?php } ?>
235 <span class="valignmiddle"><?php echo $langs->trans("Floor")." ".$floor; ?></span>
236 <img src="./img/arrow-next.png" class="valignmiddle" width="5%" onclick="location.href='floors.php?floor=<?php $floor++;
237 echo $floor; ?>';">
238 </h1>
239 </center>
240</div>
241
242</body>
243</html>
$id
Definition account.php:39
Class to manage invoices.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
treeview li table
No Email.
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(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid
Definition invoice.php:2002