Store UI cleanup and rework
This commit is contained in:
+44
-37
@@ -36,6 +36,7 @@ async function checkAdminStatus() {
|
||||
function updateAdminUI() {
|
||||
const adminBtn = document.getElementById('adminToggleBtn');
|
||||
const addBtn = document.querySelector('[onclick="openAddParticipantModal()"]');
|
||||
const participantsToolbar = document.getElementById('participantsToolbar');
|
||||
const addUnregisteredBtn = document.getElementById('addUnregisteredBtn');
|
||||
const addItemBtn = document.getElementById('addItemBtn');
|
||||
const editBalanceBtn = document.getElementById('editBalanceBtn');
|
||||
@@ -47,6 +48,7 @@ function updateAdminUI() {
|
||||
adminBtn.onclick = adminLogout;
|
||||
adminBtn.classList.add('active');
|
||||
if (addBtn) addBtn.style.display = 'block';
|
||||
if (participantsToolbar) participantsToolbar.style.display = '';
|
||||
if (addItemBtn) addItemBtn.style.display = 'inline-flex';
|
||||
if (editBalanceBtn) editBalanceBtn.style.display = 'inline-flex';
|
||||
} else {
|
||||
@@ -54,6 +56,7 @@ function updateAdminUI() {
|
||||
adminBtn.onclick = openLoginModal;
|
||||
adminBtn.classList.remove('active');
|
||||
if (addBtn) addBtn.style.display = 'none';
|
||||
if (participantsToolbar) participantsToolbar.style.display = 'none';
|
||||
if (addItemBtn) addItemBtn.style.display = 'none';
|
||||
if (editBalanceBtn) editBalanceBtn.style.display = 'none';
|
||||
}
|
||||
@@ -532,7 +535,10 @@ function resetFilters() {
|
||||
}
|
||||
|
||||
function getDateString(date) {
|
||||
return date.toISOString().split('T')[0];
|
||||
const y = date.getFullYear();
|
||||
const m = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const d = String(date.getDate()).padStart(2, '0');
|
||||
return `${y}-${m}-${d}`;
|
||||
}
|
||||
|
||||
function filterByToday() {
|
||||
@@ -732,6 +738,7 @@ function switchTab(tabName, event) {
|
||||
event.target.classList.add('active');
|
||||
|
||||
// Load tab-specific data
|
||||
if (tabName === 'logs') filterByToday();
|
||||
if (tabName === 'documents') loadDocuments();
|
||||
if (tabName === 'store') {
|
||||
// Always return to shop view when switching to store tab
|
||||
@@ -903,7 +910,7 @@ async function loadBalance() {
|
||||
const response = await fetch('/api/store/balance');
|
||||
const data = await response.json();
|
||||
currentBalance = data.balance;
|
||||
document.getElementById('storeBalanceDisplay').textContent = '€' + currentBalance.toFixed(2);
|
||||
document.getElementById('storeBalanceDisplay').textContent = '€ ' + currentBalance.toFixed(2);
|
||||
updateCartTotals();
|
||||
} catch (error) {
|
||||
console.error('Error loading balance:', error);
|
||||
@@ -933,13 +940,17 @@ function renderInventory() {
|
||||
${imgHtml}
|
||||
<div class="inventory-card-body">
|
||||
<div class="inventory-card-name">${item.name}</div>
|
||||
<div class="inventory-card-price">€${item.price.toFixed(2)}</div>
|
||||
<div class="inventory-card-stock ${item.stock === 0 ? 'stock-empty' : ''}">Zaloga: ${item.stock}</div>
|
||||
<div class="inventory-card-meta">
|
||||
<div class="inventory-card-price">€ ${item.price.toFixed(2)}</div>
|
||||
<div class="inventory-card-stock ${item.stock === 0 ? 'stock-empty' : ''}">${item.stock === 0 ? 'Ni zaloge' : item.stock + ' kos'}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="inventory-card-actions">
|
||||
<button class="btn btn-primary inventory-add-btn" onclick="addToCart(${item.id})" ${item.stock === 0 ? 'disabled' : ''}>+ Dodaj</button>
|
||||
${isAdmin ? `<button class="action-btn edit-btn" onclick="openEditItemModal(${item.id})">Uredi</button>
|
||||
<button class="action-btn delete-btn" onclick="deleteStoreItem(${item.id})">Izbriši</button>` : ''}
|
||||
${isAdmin ? `<div class="inventory-card-admin-actions">
|
||||
<button class="action-btn edit-btn" onclick="openEditItemModal(${item.id})">Uredi</button>
|
||||
<button class="action-btn delete-btn" onclick="deleteStoreItem(${item.id})">Izbriši</button>
|
||||
</div>` : ''}
|
||||
</div>
|
||||
`;
|
||||
grid.appendChild(card);
|
||||
@@ -1003,7 +1014,7 @@ function renderCart() {
|
||||
<span class="cart-qty">${item.qty}</span>
|
||||
<button class="cart-qty-btn" onclick="addToCart(${item.id})">+</button>
|
||||
</div>
|
||||
<div class="cart-item-subtotal">€${(item.price * item.qty).toFixed(2)}</div>
|
||||
<div class="cart-item-subtotal">€ ${(item.price * item.qty).toFixed(2)}</div>
|
||||
`;
|
||||
container.appendChild(row);
|
||||
});
|
||||
@@ -1018,9 +1029,9 @@ function updateCartTotals() {
|
||||
const totalEl = document.getElementById('cartTotal');
|
||||
const balanceAfterEl = document.getElementById('cartBalanceAfter');
|
||||
|
||||
if (totalEl) totalEl.textContent = '€' + total.toFixed(2);
|
||||
if (totalEl) totalEl.textContent = '€ ' + total.toFixed(2);
|
||||
if (balanceAfterEl) {
|
||||
balanceAfterEl.textContent = '€' + balanceAfter.toFixed(2);
|
||||
balanceAfterEl.textContent = '€ ' + balanceAfter.toFixed(2);
|
||||
balanceAfterEl.className = 'cart-balance-after';
|
||||
}
|
||||
}
|
||||
@@ -1033,12 +1044,11 @@ function processPayment() {
|
||||
const total = cart.reduce((sum, i) => sum + i.price * i.qty, 0);
|
||||
const balanceAfter = currentBalance + total;
|
||||
|
||||
document.getElementById('checkoutFirstName').value = '';
|
||||
document.getElementById('checkoutLastName').value = '';
|
||||
document.getElementById('checkoutTotal').textContent = '€' + total.toFixed(2);
|
||||
document.getElementById('checkoutBalanceAfter').textContent = '€' + balanceAfter.toFixed(2);
|
||||
document.getElementById('checkoutBuyer').value = '';
|
||||
document.getElementById('checkoutTotal').textContent = '€ ' + total.toFixed(2);
|
||||
document.getElementById('checkoutBalanceAfter').textContent = '€ ' + balanceAfter.toFixed(2);
|
||||
document.getElementById('checkoutModal').classList.add('show');
|
||||
document.getElementById('checkoutFirstName').focus();
|
||||
document.getElementById('checkoutBuyer').focus();
|
||||
}
|
||||
|
||||
function closeCheckoutModal() {
|
||||
@@ -1046,15 +1056,12 @@ function closeCheckoutModal() {
|
||||
}
|
||||
|
||||
async function confirmCheckout() {
|
||||
const firstName = document.getElementById('checkoutFirstName').value.trim();
|
||||
const lastName = document.getElementById('checkoutLastName').value.trim();
|
||||
const seller = document.getElementById('checkoutBuyer').value.trim();
|
||||
|
||||
if (!firstName || !lastName) {
|
||||
alert('Prosimo, vnesite ime in priimek kupca');
|
||||
if (!seller) {
|
||||
alert('Prosimo, vnesite ime in priimek prodajalca');
|
||||
return;
|
||||
}
|
||||
|
||||
const buyer = firstName + ' ' + lastName;
|
||||
const total = cart.reduce((sum, i) => sum + i.price * i.qty, 0);
|
||||
const balanceAfter = currentBalance + total;
|
||||
|
||||
@@ -1077,7 +1084,7 @@ async function confirmCheckout() {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
buyer,
|
||||
seller,
|
||||
items: cart.map(i => ({ name: i.name, qty: i.qty, price: i.price })),
|
||||
cart_items: cartItems,
|
||||
total,
|
||||
@@ -1090,7 +1097,7 @@ async function confirmCheckout() {
|
||||
if (!data.success) { alert('Napaka: ' + data.message); return; }
|
||||
|
||||
const payment = {
|
||||
buyer,
|
||||
seller,
|
||||
items: cart.map(i => ({ name: i.name, qty: i.qty, price: i.price })),
|
||||
total,
|
||||
balance_before: currentBalance,
|
||||
@@ -1299,13 +1306,13 @@ async function loadPaymentHistory() {
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML = `
|
||||
<td>${p.id}</td>
|
||||
<td style="font-weight:600;">${p.buyer || '-'}</td>
|
||||
<td style="font-weight:600;">${p.seller || '-'}</td>
|
||||
<td>${date}</td>
|
||||
<td>${time}</td>
|
||||
<td style="max-width:200px;word-break:break-word;">${itemsSummary}</td>
|
||||
<td style="font-weight:700;color:var(--accent-blue);">€${p.total.toFixed(2)}</td>
|
||||
<td>€${p.balance_before.toFixed(2)}</td>
|
||||
<td>€${p.balance_after.toFixed(2)}</td>
|
||||
<td style="font-weight:700;color:var(--accent-blue);">€ ${p.total.toFixed(2)}</td>
|
||||
<td>€ ${p.balance_before.toFixed(2)}</td>
|
||||
<td>€ ${p.balance_after.toFixed(2)}</td>
|
||||
<td><button class="action-btn edit-btn" onclick="printReceipt(${JSON.stringify(p).replace(/"/g, '"')})">🖨 Natisni</button></td>
|
||||
`;
|
||||
tbody.appendChild(row);
|
||||
@@ -1323,7 +1330,7 @@ function printReceipt(payment) {
|
||||
const date = fmtDate(ts.split('T')[0]);
|
||||
const time = ts.split('T')[1] ? ts.split('T')[1].substring(0, 5) : '';
|
||||
const rows = payment.items.map(i =>
|
||||
`<tr><td class="rp-td-name">${i.name}</td><td class="rp-td-qty">${i.qty}×</td><td class="rp-td-price">€${i.price.toFixed(2)}</td><td class="rp-td-sub">€${(i.price * i.qty).toFixed(2)}</td></tr>`
|
||||
`<tr><td class="rp-td-name">${i.name}</td><td class="rp-td-qty">${i.qty}×</td><td class="rp-td-price">€ ${i.price.toFixed(2)}</td><td class="rp-td-sub">€ ${(i.price * i.qty).toFixed(2)}</td></tr>`
|
||||
).join('');
|
||||
|
||||
const html = `
|
||||
@@ -1335,17 +1342,17 @@ function printReceipt(payment) {
|
||||
<div class="rp-title">POTRDILO O PLAČILU</div>
|
||||
<div class="rp-meta">
|
||||
<span>${date} ${time}</span>
|
||||
<span>Prodajalec: <strong>${payment.buyer || '-'}</strong></span>
|
||||
<span>Prodajalec: <strong>${payment.seller || '-'}</strong></span>
|
||||
</div>
|
||||
<div class="rp-divider-dashed"></div>
|
||||
<table class="rp-table">
|
||||
<thead><tr><th>Artikel</th><th>Kol.</th><th>Cena</th><th style="text-align:right;">Znesek</th></tr></thead>
|
||||
<thead><tr><th>Artikel</th><th style="text-align:center;">Količina</th><th style="text-align:right;">Cena</th><th style="text-align:right;">Znesek</th></tr></thead>
|
||||
<tbody>${rows}</tbody>
|
||||
</table>
|
||||
<div class="rp-divider"></div>
|
||||
<div class="rp-total">
|
||||
<span>SKUPAJ</span>
|
||||
<span>€${payment.total.toFixed(2)}</span>
|
||||
<span>€ ${payment.total.toFixed(2)}</span>
|
||||
</div>
|
||||
<div class="rp-divider-dashed"></div>
|
||||
<div class="rp-footer">Hvala za nakup!</div>
|
||||
@@ -1404,17 +1411,17 @@ async function renderMonthlyOverview() {
|
||||
}));
|
||||
|
||||
const itemRows = Object.entries(itemTotals).map(([name, v]) =>
|
||||
`<tr><td>${name}</td><td style="text-align:center;">${v.qty}</td><td style="text-align:right;font-weight:600;">€${v.revenue.toFixed(2)}</td></tr>`
|
||||
`<tr><td>${name}</td><td style="text-align:center;">${v.qty}</td><td style="text-align:right;font-weight:600;">€ ${v.revenue.toFixed(2)}</td></tr>`
|
||||
).join('');
|
||||
|
||||
const txRows = [...filtered].reverse().map(p => {
|
||||
const date = fmtDate(p.timestamp.split('T')[0]);
|
||||
const time = p.timestamp.split('T')[1].substring(0, 5);
|
||||
return `<tr><td>${date}</td><td>${time}</td><td style="font-weight:600;">${p.buyer || '-'}</td><td>${p.items.map(i => `${i.name} ×${i.qty}`).join(', ')}</td><td style="text-align:right;font-weight:700;color:var(--accent-blue);">€${p.total.toFixed(2)}</td></tr>`;
|
||||
return `<tr><td>${date}</td><td>${time}</td><td style="font-weight:600;">${p.seller || '-'}</td><td>${p.items.map(i => `${i.name} ×${i.qty}`).join(', ')}</td><td style="text-align:right;font-weight:700;color:var(--accent-blue);">€ ${p.total.toFixed(2)}</td></tr>`;
|
||||
}).join('');
|
||||
|
||||
content.innerHTML = `
|
||||
<div class="monthly-summary-total">Skupaj prihodek: <strong>€${grandTotal.toFixed(2)}</strong> (${filtered.length} transakcij)</div>
|
||||
<div class="monthly-summary-total">Skupaj prihodek: <strong>€ ${grandTotal.toFixed(2)}</strong> (${filtered.length} transakcij)</div>
|
||||
<h4 class="monthly-section-title">Po artiklih</h4>
|
||||
<div class="table-container" style="margin-bottom:16px;">
|
||||
<table><thead><tr><th>Artikel</th><th style="text-align:center;">Količina</th><th style="text-align:right;">Prihodek</th></tr></thead>
|
||||
@@ -1445,14 +1452,14 @@ function printMonthlyOverview() {
|
||||
}));
|
||||
|
||||
const itemRows = Object.entries(itemTotals).map(([name, v]) =>
|
||||
`<tr><td>${name}</td><td style="text-align:center;">${v.qty}</td><td style="text-align:right;font-weight:600;">€${v.revenue.toFixed(2)}</td></tr>`
|
||||
`<tr><td>${name}</td><td style="text-align:center;">${v.qty}</td><td style="text-align:right;font-weight:600;">€ ${v.revenue.toFixed(2)}</td></tr>`
|
||||
).join('');
|
||||
|
||||
const txRows = [...filtered].reverse().map(p => {
|
||||
const date = fmtDate(p.timestamp.split('T')[0]);
|
||||
const time = p.timestamp.split('T')[1].substring(0, 5);
|
||||
const items = p.items.map(i => `${i.name} ×${i.qty} (€${(i.price*i.qty).toFixed(2)})`).join(', ');
|
||||
return `<tr><td>${date}</td><td>${time}</td><td style="font-weight:600;">${p.buyer || '-'}</td><td>${items}</td><td style="text-align:right;font-weight:700;">€${p.total.toFixed(2)}</td></tr>`;
|
||||
const items = p.items.map(i => `${i.name} ×${i.qty} (€ ${(i.price*i.qty).toFixed(2)})`).join(', ');
|
||||
return `<tr><td>${date}</td><td>${time}</td><td style="font-weight:600;">${p.seller || '-'}</td><td>${items}</td><td style="text-align:right;font-weight:700;">€ ${p.total.toFixed(2)}</td></tr>`;
|
||||
}).join('');
|
||||
|
||||
const [year, month] = picker.split('-');
|
||||
@@ -1469,7 +1476,7 @@ function printMonthlyOverview() {
|
||||
<div class="rp-meta"><span>${monthName}</span><span>Natisnjeno: ${printDate}</span></div>
|
||||
<div class="rp-divider-dashed"></div>
|
||||
<div class="rp-monthly-kpi">
|
||||
<div class="rp-kpi-box"><div class="rp-kpi-label">Skupaj prihodek</div><div class="rp-kpi-value">€${grandTotal.toFixed(2)}</div></div>
|
||||
<div class="rp-kpi-box"><div class="rp-kpi-label">Skupaj prihodek</div><div class="rp-kpi-value">€ ${grandTotal.toFixed(2)}</div></div>
|
||||
<div class="rp-kpi-box"><div class="rp-kpi-label">Št. transakcij</div><div class="rp-kpi-value">${filtered.length}</div></div>
|
||||
</div>
|
||||
<div class="rp-section-title">Po artiklih</div>
|
||||
|
||||
Reference in New Issue
Block a user