Poprawka generatora QR i ukrycie imienia

This commit is contained in:
2026-05-27 15:06:53 +02:00
parent d54c93623f
commit f4fb540652
3 changed files with 104 additions and 36 deletions

View File

@@ -28,6 +28,7 @@ const userProfileKey = "karczma_user_profile";
const USER_PROFILE_EXPIRE_MS = 180 * 24 * 60 * 60 * 1000; // ~6 months
function initUserProfile() {
return; // Funkcja tymczasowo wyłączona
try {
const raw = localStorage.getItem(userProfileKey);
let profile = null;
@@ -146,7 +147,7 @@ const msgInterval = setInterval(() => {
// Initial State
if (tableParam) {
tableLabel.textContent = `Stolik ${tableParam}`;
tableLabel.textContent = tableParam.toUpperCase().startsWith("STOLIK") ? tableParam : `Stolik ${tableParam}`;
}
function hideLoader() {
@@ -460,7 +461,7 @@ async function fetchOrders() {
if (result.status === 'success') {
if (result.tableName && result.tableName !== '') {
tableLabel.textContent = `Stolik ${result.tableName}`;
tableLabel.textContent = result.tableName.toUpperCase().startsWith("STOLIK") ? result.tableName : `Stolik ${result.tableName}`;
tableParam = result.tableName; // Aktualizacja do właściwej nazwy na poczet innych zapytań
}
@@ -758,7 +759,7 @@ window.selectDocument = function (docType) {
}
};
window.fetchGUS = function () {
window.fetchGUS = async function () {
const nip = document.getElementById("nipInput").value.replace(/[\s-]/g, '');
if (nip.length < 10) {
alert("Wprowadź poprawny numer NIP.");
@@ -768,34 +769,51 @@ window.fetchGUS = function () {
btn.textContent = "Szukam...";
btn.disabled = true;
// Symulacja pobrania z GUS
setTimeout(() => {
try {
const apiKey = "d8bdc252-e0f1-4863-97a1-826faddbc49c";
const response = await fetch(`https://api.magico.pro/v1/gus/${nip}?api_key=${apiKey}`);
const result = await response.json();
if (result.status && result.data) {
const data = result.data;
let fullStreet = data.street || '';
if (data.propertyNumber) fullStreet += ' ' + data.propertyNumber;
if (data.apartmentNumber) fullStreet += '/' + data.apartmentNumber;
billState.nip = nip;
billState.company = {
name: data.name,
street: fullStreet.trim(),
zip: data.zipCode,
city: data.city,
nip: data.nip
};
document.getElementById("cmpName").value = billState.company.name;
document.getElementById("cmpStreet").value = billState.company.street;
document.getElementById("cmpZip").value = billState.company.zip;
document.getElementById("cmpCity").value = billState.company.city;
document.getElementById("cmpNip").value = "NIP: " + billState.company.nip;
// reset do readonly
document.getElementById("cmpName").readOnly = true;
document.getElementById("cmpStreet").readOnly = true;
document.getElementById("cmpZip").readOnly = true;
document.getElementById("cmpCity").readOnly = true;
document.getElementById("btnEditCompany").textContent = "Popraw ręcznie";
goToStep("stepVerify");
} else {
alert("Nie udało się pobrać danych z GUS dla podanego NIP-u.");
}
} catch (error) {
console.error("Błąd pobierania danych z GUS:", error);
alert("Błąd połączenia z API GUS.");
} finally {
btn.textContent = "Pobierz z GUS";
btn.disabled = false;
billState.nip = nip;
billState.company = {
name: "Przykładowa Firma Sp. z o.o.",
street: "ul. Gastronomiczna 12/4",
zip: "00-120",
city: "Warszawa",
nip: nip
};
document.getElementById("cmpName").value = billState.company.name;
document.getElementById("cmpStreet").value = billState.company.street;
document.getElementById("cmpZip").value = billState.company.zip;
document.getElementById("cmpCity").value = billState.company.city;
document.getElementById("cmpNip").value = "NIP: " + billState.company.nip;
// reset do readonly
document.getElementById("cmpName").readOnly = true;
document.getElementById("cmpStreet").readOnly = true;
document.getElementById("cmpZip").readOnly = true;
document.getElementById("cmpCity").readOnly = true;
document.getElementById("btnEditCompany").textContent = "Popraw ręcznie";
goToStep("stepVerify");
}, 1200);
}
};
// --- DYNAMIC MENU LOADING ---
@@ -806,19 +824,19 @@ async function loadMenu() {
const menuData = await response.json();
const container = document.getElementById('menuContainer');
if (!container) return;
container.innerHTML = '';
menuData.forEach(category => {
const catId = category.items.length > 0 ? category.items[0].categoryId : '';
const catDiv = document.createElement('div');
catDiv.className = 'rm-category';
catDiv.setAttribute('data-cat-id', catId);
let html = `<div class="restaurant-menu-category">${category.categoryName}</div>
<div class="rmc-positions">`;
category.items.forEach(item => {
html += `
<div class="rmc-position" data-position="${item.position}" data-category-id="${item.categoryId}">
@@ -830,7 +848,7 @@ async function loadMenu() {
</div>
`;
});
html += `</div>`;
catDiv.innerHTML = html;
container.appendChild(catDiv);
@@ -945,7 +963,7 @@ window.initGeolocation = function () {
return;
}
geoMsg.innerHTML = "Pobieranie lokalizacji...";
geoMsg.innerHTML = "Sprawdzamy Twoją lokalizację...";
navigator.geolocation.getCurrentPosition(
(position) => {