Wykrywanie imienia i nazwiska kelnera oraz info czy sesja dostala sie do aplikacji
This commit is contained in:
@@ -102,13 +102,54 @@ function trackEvent(eventName, payload = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
let cachedOpenBills = [];
|
||||
|
||||
function cacheOpenBills(bills) {
|
||||
cachedOpenBills = Array.isArray(bills) ? bills : [];
|
||||
}
|
||||
|
||||
function getQueueOperatorFields() {
|
||||
const bills = cachedOpenBills;
|
||||
if (!bills.length) {
|
||||
return { otwierajacyImie: "", otwierajacyNazwisko: "" };
|
||||
}
|
||||
|
||||
let bill = bills[0];
|
||||
if (billState.selectedBillId) {
|
||||
const selected = bills.find((b) => b.id === billState.selectedBillId);
|
||||
if (selected) bill = selected;
|
||||
}
|
||||
|
||||
const o = bill.otwierajacy || {};
|
||||
return {
|
||||
otwierajacyImie: String(o.imie || "").trim(),
|
||||
otwierajacyNazwisko: String(o.nazwisko || "").trim(),
|
||||
};
|
||||
}
|
||||
|
||||
async function prefetchOpenBills() {
|
||||
if (!hashParam) return;
|
||||
try {
|
||||
const res = await fetch(`../api/bills.php?h=${encodeURIComponent(hashParam)}`);
|
||||
const result = await res.json();
|
||||
if (result.status === "success") {
|
||||
cacheOpenBills(result.data);
|
||||
}
|
||||
} catch {
|
||||
// best effort
|
||||
}
|
||||
}
|
||||
|
||||
function queueGuestAction(messageType, messageText, extra = {}) {
|
||||
const operator = getQueueOperatorFields();
|
||||
const body = {
|
||||
tableId: tableParam || null,
|
||||
qrHash: hashParam || null,
|
||||
messageType,
|
||||
messageText,
|
||||
extra
|
||||
otwierajacyImie: operator.otwierajacyImie,
|
||||
otwierajacyNazwisko: operator.otwierajacyNazwisko,
|
||||
extra,
|
||||
};
|
||||
|
||||
fetch(guestActionQueueEndpoint, {
|
||||
@@ -677,6 +718,7 @@ window.openBillDialog = async function () {
|
||||
|
||||
if (result.status === 'success' && result.data.length > 0) {
|
||||
const bills = result.data;
|
||||
cacheOpenBills(bills);
|
||||
|
||||
if (bills.length === 1) {
|
||||
showBillReview(bills[0]);
|
||||
@@ -1094,6 +1136,7 @@ function startApp() {
|
||||
|
||||
initUserProfile();
|
||||
fetchOrders();
|
||||
prefetchOpenBills();
|
||||
if (!window.ordersInterval) {
|
||||
window.ordersInterval = setInterval(fetchOrders, 10000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user