Fix indicatore confezione: solo ¼ ½ ¾ quando utile, no doppioni

- Frazione mostrata solo se c'è un avanzo reale e default_quantity > 1
- Rimossi duplicati (5 pz + 5 conf), pieno, ⅛, titoli ridondanti
- pz/conf arrotondati a intero (no 8.8 pz)
- Stile più discreto e piccolo
This commit is contained in:
dadaloop82
2026-03-11 13:38:28 +00:00
parent df56d8dc76
commit d5071361b5
2 changed files with 14 additions and 32 deletions
+1 -5
View File
@@ -2559,14 +2559,10 @@ body {
.pkg-fraction { .pkg-fraction {
font-size: 0.7rem; font-size: 0.7rem;
font-weight: 600; font-weight: 600;
color: #6b7280; color: #9ca3af;
white-space: nowrap; white-space: nowrap;
} }
.pkg-fraction.pkg-full {
color: #16a34a;
}
.inv-pkg-frac { .inv-pkg-frac {
display: block; display: block;
text-align: center; text-align: center;
+13 -27
View File
@@ -704,46 +704,32 @@ function formatQuantity(qty, unit) {
const n = parseFloat(qty); const n = parseFloat(qty);
const unitLabels = { 'pz': 'pz', 'kg': 'kg', 'g': 'g', 'l': 'L', 'ml': 'ml', 'conf': 'conf' }; const unitLabels = { 'pz': 'pz', 'kg': 'kg', 'g': 'g', 'l': 'L', 'ml': 'ml', 'conf': 'conf' };
const label = unitLabels[unit] || unit || 'pz'; const label = unitLabels[unit] || unit || 'pz';
// Format nicely
if (n === Math.floor(n)) return `${Math.floor(n)} ${label}`; if (n === Math.floor(n)) return `${Math.floor(n)} ${label}`;
// For pz/conf show whole number
if (unit === 'pz' || unit === 'conf') return `${Math.round(n)} ${label}`;
return `${n.toFixed(1)} ${label}`; return `${n.toFixed(1)} ${label}`;
} }
// Show package fraction indicator (1/4, 1/2, 3/4, pieno) relative to original package size // Show package fraction: only ¼, ½, ¾ when there's a partial package.
// Returns '' if quantity maps to whole packages or fraction is not meaningful.
function formatPackageFraction(qty, defaultQty) { function formatPackageFraction(qty, defaultQty) {
if (!defaultQty || defaultQty <= 0) return ''; if (!defaultQty || defaultQty <= 0) return '';
const n = parseFloat(qty); const n = parseFloat(qty);
const d = parseFloat(defaultQty); const d = parseFloat(defaultQty);
if (isNaN(n) || isNaN(d) || d <= 0) return ''; if (isNaN(n) || isNaN(d) || d <= 0 || d === 1) return '';
const ratio = n / d; const ratio = n / d;
const remainder = ratio - Math.floor(ratio);
// Multiple full packages // Only show if there IS a fractional part
const fullPkgs = Math.floor(ratio); if (remainder < 0.1 || remainder > 0.9) return '';
const remainder = ratio - fullPkgs;
// Map remainder to closest readable fraction let frac = '';
let fracLabel = ''; if (remainder < 0.38) frac = '¼';
if (remainder < 0.1) fracLabel = ''; else if (remainder < 0.62) frac = '½';
else if (remainder < 0.2) fracLabel = ''; else frac = '¾';
else if (remainder < 0.38) fracLabel = '¼';
else if (remainder < 0.62) fracLabel = '½';
else if (remainder < 0.88) fracLabel = '¾';
else { fracLabel = ''; } // close to full → count as full
// Near-full remainder counts as +1 full return `<span class="pkg-fraction">${frac}</span>`;
const effectiveFull = remainder >= 0.88 ? fullPkgs + 1 : fullPkgs;
if (effectiveFull >= 1 && fracLabel) {
return `<span class="pkg-fraction" title="${ratio.toFixed(2)} confezioni">${effectiveFull} + ${fracLabel} conf</span>`;
} else if (effectiveFull >= 2) {
return `<span class="pkg-fraction" title="${ratio.toFixed(2)} confezioni">${effectiveFull} conf</span>`;
} else if (effectiveFull === 1 && !fracLabel) {
return `<span class="pkg-fraction pkg-full" title="1 confezione intera">● pieno</span>`;
} else if (fracLabel) {
return `<span class="pkg-fraction" title="${ratio.toFixed(2)} confezioni">${fracLabel} conf</span>`;
}
return '';
} }
// ===== INVENTORY ===== // ===== INVENTORY =====