From e6674e2014bc99fbf43f43e08dd4754f49082b20 Mon Sep 17 00:00:00 2001 From: 4aiman Date: Fri, 29 May 2026 17:53:57 +0300 Subject: [PATCH] Fix B9 and Se showing 0%: unit mismatch mg vs mcg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- frontend/js/main.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/frontend/js/main.js b/frontend/js/main.js index 663258f..7920d2a 100644 --- a/frontend/js/main.js +++ b/frontend/js/main.js @@ -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 => - `
+ 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 `
- -
` + +
`; + } ).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);