From f64423296bea92b1009bec875966ae99191b7977 Mon Sep 17 00:00:00 2001 From: dadaloop82 Date: Fri, 13 Mar 2026 15:10:17 +0000 Subject: [PATCH] =?UTF-8?q?Prodotti=20aperti:=20includi=20anche=20non-conf?= =?UTF-8?q?=20con=20quantit=C3=A0=20parziale=20(19=20prodotti)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/index.php | 13 ++++++++++--- assets/js/app.js | 34 ++++++++++++++++++++++++++-------- data/dispensa.db | Bin 155648 -> 155648 bytes index.html | 2 +- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/api/index.php b/api/index.php index d2376ba..df75e36 100644 --- a/api/index.php +++ b/api/index.php @@ -753,12 +753,19 @@ function getStats(PDO $db): void { ORDER BY i.expiry_date ASC ")->fetchAll(); - // Opened (partially used conf items) + // Opened (partially used) products + // 1) conf items with fractional quantity + // 2) non-conf items where quantity is not a clean multiple of default_quantity $opened = $db->query(" SELECT i.*, p.name, p.brand, p.category, p.unit, p.default_quantity, p.package_unit, p.image_url FROM inventory i JOIN products p ON i.product_id = p.id - WHERE p.unit = 'conf' AND p.default_quantity > 0 AND p.package_unit IS NOT NULL - AND i.quantity > 0 AND CAST(i.quantity AS REAL) != CAST(CAST(i.quantity AS INTEGER) AS REAL) + WHERE i.quantity > 0 AND p.default_quantity > 0 AND ( + (p.unit = 'conf' AND p.package_unit IS NOT NULL + AND CAST(i.quantity AS REAL) != CAST(CAST(i.quantity AS INTEGER) AS REAL)) + OR + (p.unit != 'conf' AND p.default_quantity > 1 + AND ABS((CAST(i.quantity AS REAL) / p.default_quantity) - ROUND(CAST(i.quantity AS REAL) / p.default_quantity)) > 0.03) + ) ORDER BY i.updated_at DESC ")->fetchAll(); diff --git a/assets/js/app.js b/assets/js/app.js index 6006eaa..3886376 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -823,19 +823,37 @@ async function loadDashboard() { const locInfo = LOCATIONS[item.location] || { icon: '📦', label: item.location }; const qty = parseFloat(item.quantity); const pkgSize = parseFloat(item.default_quantity); + const unit = item.unit; const pkgUnit = item.package_unit; - const wholeConf = Math.floor(qty + 0.001); - const frac = Math.round((qty - wholeConf) * 1000) / 1000; - const remainderAmt = frac * pkgSize; - const remainderText = formatSubRemainder(remainderAmt, pkgUnit); + const unitLabels = { 'ml': 'ml', 'l': 'L', 'g': 'g', 'kg': 'kg', 'pz': 'pz' }; let qtyText = ''; - if (wholeConf > 0) { - const unitLabels = { 'ml': 'ml', 'l': 'L', 'g': 'g', 'kg': 'kg' }; + + if (unit === 'conf' && pkgUnit && pkgSize > 0) { + // Conf product: show whole conf + remainder in sub-unit + const wholeConf = Math.floor(qty + 0.001); + const frac = Math.round((qty - wholeConf) * 1000) / 1000; + const remainderAmt = frac * pkgSize; + const remainderText = formatSubRemainder(remainderAmt, pkgUnit); const pkgLabel = unitLabels[pkgUnit] || pkgUnit; - qtyText = `${wholeConf} conf (da ${pkgSize}${pkgLabel}) + ${remainderText}`; + if (wholeConf > 0) { + qtyText = `${wholeConf} conf (da ${pkgSize}${pkgLabel}) + ${remainderText}`; + } else { + qtyText = remainderText; + } } else { - qtyText = remainderText; + // Non-conf product: show qty / package size + const wholePacks = Math.floor(qty / pkgSize + 0.001); + const remainder = Math.round((qty - wholePacks * pkgSize) * 100) / 100; + const uLabel = unitLabels[unit] || unit; + if (wholePacks > 0 && remainder > 0) { + qtyText = `${wholePacks} × ${pkgSize}${uLabel} + ${Math.round(remainder)}${uLabel}`; + } else if (remainder > 0) { + qtyText = `${Math.round(qty)}${uLabel} / ${pkgSize}${uLabel}`; + } else { + qtyText = `${qty} ${uLabel}`; + } } + return `
diff --git a/data/dispensa.db b/data/dispensa.db index 8ad65e92ee0daee79eb0272a39fc94531882daa7..bb76ea4ead7eda46c0a8732e506ec015c7a28106 100644 GIT binary patch delta 275 zcmZoTz}awsa|2@o6OYPd=7wx0?#Gk!8mu<2YOvzwVU}e~$t*5N%_~l{n*5>rBqPh@ zT|HhrycZdG7@%OYK<~#OZ6HU8VKD>W4c=Eg-?=AoadDcnzh<{!lVnw3{K0aVC4#w} z=?lYRrgcm{6DO7nH3ix5GpI{S1~!`Wb2O1#=lI7@ArcSX!A{P7Z$XXYT+l zY{kLAD9fa1Y-|H__jCttMhzs*+oRbT-I!Ro^%z_xPITD*l#|huar#0|Mwj*?ZpQ6J I+)RBT0D6m4$^ZZW delta 278 zcmZoTz}awsa|2@o6ZhlE%njL-3mUALcv&{DYOvzwQDNX^fPu*$x=%7*oV=^Yi-((8 znlY^?HMJ_W$ZE4d@5dl*mWvER48aV1H+Wz1eCM9T#l>mP{+iu_O_EiCA(*9vg_Bu> zX(^*WBPYZ1i4)Z)|9JREuqoJvk3n5hGO*E{pQ%aJ*m&~R2NNg%ddxk!f1l9g4V$

ui zy{$To&)FEgCr)(V9?j0^#xz}zo6%+aQ%*)tMjr)_YqB$HK#Vjs Su`)DlFXCq0Uc}AR7XknpfL1#I diff --git a/index.html b/index.html index e57634e..b2b787f 100644 --- a/index.html +++ b/index.html @@ -884,6 +884,6 @@

- +