diff --git a/assets/js/app.js b/assets/js/app.js index 38e8a58..e945724 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -865,6 +865,11 @@ async function loadDashboard() { const openedSection = document.getElementById('alert-opened'); const openedList = document.getElementById('opened-list'); if (statsData.opened && statsData.opened.length > 0) { + // Sort by remaining fraction ascending (least remaining first) + statsData.opened.sort((a, b) => { + const fA = openedFraction(a), fB = openedFraction(b); + return fA - fB; + }); openedSection.style.display = 'block'; openedList.innerHTML = statsData.opened.map(item => { const locInfo = LOCATIONS[item.location] || { icon: '📦', label: item.location }; @@ -918,6 +923,15 @@ async function loadDashboard() { } } +function openedFraction(item) { + const qty = parseFloat(item.quantity); + const pkgSize = parseFloat(item.default_quantity); + if (item.unit === 'conf') { + return qty - Math.floor(qty + 0.001); + } + return (qty - Math.floor(qty / pkgSize + 0.001) * pkgSize) / pkgSize; +} + function quickRecipeSuggestion() { // Navigate to chat and auto-send a prompt about expiring products showPage('chat'); diff --git a/data/dispensa.db b/data/dispensa.db index 78bcfb0..f8a6421 100644 Binary files a/data/dispensa.db and b/data/dispensa.db differ diff --git a/index.html b/index.html index 6ffa7e2..6b56501 100644 --- a/index.html +++ b/index.html @@ -911,6 +911,6 @@ - +