52 lines
3.1 KiB
JavaScript
52 lines
3.1 KiB
JavaScript
import { SHEET } from "./model.js";
|
||
import { valueAt } from "./evaluate.js";
|
||
|
||
const esc = (s) => String(s).replace(/[&<>]/g, (c) => ({ "&": "&", "<": "<", ">": ">" })[c]);
|
||
const fmt = (n) => (typeof n === "number" ? Math.round(n).toLocaleString("ru-RU").replace(/\s/g, " ") : esc(n));
|
||
const COLS = ["N", "O", "P", "Q", "R", "S", "T"];
|
||
const frame = (title, body) =>
|
||
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 450" font-family="Arial, sans-serif"><rect width="800" height="450" fill="#fff"/><rect width="800" height="36" fill="#1f4e78"/><text x="16" y="24" fill="#fff" font-size="16" font-weight="bold">${esc(title)}</text>${body}</svg>`;
|
||
|
||
// Три «скриншота» листов модели, нарисованные по реальным расчётам примера.
|
||
export function screenshots(result) {
|
||
const v = (sheet, addr) => valueAt(result, sheet, addr);
|
||
const years = COLS.map((c) => v(SHEET.pnl, `${c}6`));
|
||
const max = Math.max(...years, 1);
|
||
const bars = years
|
||
.map((y, i) => {
|
||
const h = Math.round((y / max) * 280);
|
||
return `<rect x="${60 + i * 105}" y="${400 - h}" width="70" height="${h}" fill="#5b9bd5"/><text x="${95 + i * 105}" y="${394 - h}" font-size="12" text-anchor="middle">${fmt(y / 1e6)} млн</text><text x="${95 + i * 105}" y="420" font-size="12" text-anchor="middle">Год ${i + 1}</text>`;
|
||
})
|
||
.join("");
|
||
const dashboard = frame("Дашборд — выручка по годам (пример)", bars);
|
||
|
||
const rows = [
|
||
["Выручка", 6],
|
||
["Валовая прибыль", 8],
|
||
["EBITDA", 12],
|
||
["EBIT", 14],
|
||
["Чистая прибыль", 18],
|
||
];
|
||
const pnlBody = rows
|
||
.map(([l, r], i) => {
|
||
const y = 70 + i * 60;
|
||
const cells = [0, 1, 2].map((k) => `<text x="${420 + k * 125}" y="${y}" font-size="15" text-anchor="end">${fmt(v(SHEET.pnl, `${COLS[k]}${r}`))}</text>`).join("");
|
||
return `<rect x="16" y="${y - 24}" width="768" height="40" fill="${i % 2 ? "#fff" : "#e7eef6"}"/><text x="28" y="${y}" font-size="15" font-weight="bold">${l}</text>${cells}`;
|
||
})
|
||
.join("");
|
||
const pnl = frame("ОПиУ — 1–3 годы (пример, ₸)", pnlBody + `<text x="420" y="50" font-size="12" text-anchor="end">Год 1</text><text x="545" y="50" font-size="12" text-anchor="end">Год 2</text><text x="670" y="50" font-size="12" text-anchor="end">Год 3</text>`);
|
||
|
||
const inputs = [
|
||
["Валюта", "₸"],
|
||
["Цена, кофе и напитки", "1 200"],
|
||
["Объём в 1-м месяце", "1 500"],
|
||
["Налог на прибыль", "вводит пользователь"],
|
||
["Кредит", "6 000 000"],
|
||
];
|
||
const inBody = inputs
|
||
.map(([l, val], i) => `<text x="28" y="${80 + i * 60}" font-size="15">${esc(l)}</text><rect x="400" y="${58 + i * 60}" width="300" height="32" fill="#fff2cc" stroke="#999"/><text x="410" y="${80 + i * 60}" font-size="15">${esc(val)}</text>`)
|
||
.join("");
|
||
const assumptions = frame("Допущения — жёлтые ячейки для ввода", inBody);
|
||
return { "dashboard.svg": dashboard, "pnl.svg": pnl, "assumptions.svg": assumptions };
|
||
}
|