Fix B9 and Se showing 0%: unit mismatch mg vs mcg

B9 (folate) label said "мкг" but packaging shows "мг" — user entered
0.4 mg, DB stored 0.4 mcg, 0.4/200 = 0%. Fixed: label says "мг",
mult:1000 converts to mcg on save, back to mg on display.
Same for selenium: packaging uses mg, DB uses mcg.

Beta-carotene showing 0% is correct — Daily Men supplement contains
retinol acetate (vit A), not beta-carotene. They are different forms.
This commit is contained in:
4aiman 2026-05-29 17:53:57 +03:00
commit e6674e2014

View file

@ -3292,14 +3292,14 @@ const MICRO_FIELDS = [
{ key: "vit_b5_mg", label: "B5 (мг)" },
{ key: "vit_b6_mg", label: "B6 (мг)" },
{ key: "vit_b7_mcg", label: "B7/биотин (мкг)" },
{ key: "folate_mcg", label: "B9/фолат (мкг)" },
{ key: "folate_mcg", label: "B9/фолат (мг)", mult: 1000 },
{ key: "vit_b12_mcg", label: "B12 (мкг)" },
{ key: "calcium_mg", label: "Кальций (мг)" },
{ key: "magnesium_mg", label: "Магний (мг)" },
{ key: "iron_mg", label: "Железо (мг)" },
{ key: "zinc_mg", label: "Цинк (мг)" },
{ key: "copper_mg", label: "Медь (мг)" },
{ key: "selenium_mcg", label: "Селен (мкг)" },
{ key: "selenium_mcg", label: "Селен (мг)", mult: 1000 },
{ key: "potassium_mg", label: "Калий (мг)" },
{ key: "sodium_mg", label: "Натрий (мг)" },
{ key: "phosphorus_mg", label: "Фосфор (мг)" },
@ -3365,11 +3365,14 @@ function showEditSupplementModal(existing) {
const isNew = !existing;
const s = existing || {};
const microHtml = MICRO_FIELDS.map(f =>
`<div class="form-group micro-field">
const microHtml = MICRO_FIELDS.map(f => {
let displayVal = s[f.key] ?? "";
if (displayVal && f.mult) displayVal = Math.round(displayVal / f.mult * 1000) / 1000; // mcg→mg for display
return `<div class="form-group micro-field">
<label>${f.label}</label>
<input id="m-${f.key}" type="number" inputmode="decimal" step="any" value="${s[f.key] ?? ""}" placeholder="—" />
</div>`
<input id="m-${f.key}" type="number" inputmode="decimal" step="any" value="${displayVal}" placeholder="—" />
</div>`;
}
).join("");
showModal(`
@ -3390,7 +3393,9 @@ function showEditSupplementModal(existing) {
if (!name) return false;
const data = { name, daily_dose_g: parseFloat(overlay.querySelector("#m-dose").value) || null };
for (const f of MICRO_FIELDS) {
data[f.key] = parseFloat(overlay.querySelector(`#m-${f.key}`).value) || null;
let val = parseFloat(overlay.querySelector(`#m-${f.key}`).value) || null;
if (val && f.mult) val *= f.mult; // convert mg→mcg where needed
data[f.key] = val;
}
if (isNew) {
await DB.addSupplement(data);