feat: NAS storage for invoices/offers, code cleanup, date/time fixes

- NAS storage for created invoices (PDF via puppeteer), received invoices,
  and offers with auto-save on create/edit
- Deterministic file paths derived from DB fields (no file_path column needed)
- Separate NAS mount points: NAS_FINANCIALS_PATH, NAS_OFFERS_PATH
- Invoice language field (cs/en) stored per invoice, replaces lang modal
- Invoices list filtered by month/year matching KPI card selection
- Centralized date helpers (src/utils/date.ts) replacing all .toISOString()
  calls that returned UTC instead of local time
- Attendance project switching uses exact time (not rounded)
- Comment cleanup: removed ~100 unnecessary/Czech comments
- Removed as-any casts in orders and attendance
- Prisma migrations: add invoice language, drop received_invoices BLOB columns

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
BOHA
2026-03-26 10:36:39 +01:00
parent 0317ba3168
commit baceb88347
60 changed files with 2475 additions and 563 deletions

View File

@@ -3,6 +3,8 @@
* Port of PHP CzechHolidays class.
*/
import { localDateStr } from "./date";
const holidayCache = new Map<number, string[]>();
/** Easter Sunday using the Anonymous Gregorian algorithm */
@@ -30,17 +32,17 @@ export function getHolidays(year: number): string[] {
const y = String(year);
const holidays = [
`${y}-01-01`, // Den obnovy samostatného českého státu
`${y}-05-01`, // Svátek práce
`${y}-05-08`, // Den vítězství
`${y}-07-05`, // Den slovanských věrozvěstů Cyrila a Metoděje
`${y}-07-06`, // Den upálení mistra Jana Husa
`${y}-09-28`, // Den české státnosti
`${y}-10-28`, // Den vzniku samostatného československého státu
`${y}-11-17`, // Den boje za svobodu a demokracii
`${y}-12-24`, // Štědrý den
`${y}-12-25`, // 1. svátek vánoční
`${y}-12-26`, // 2. svátek vánoční
`${y}-01-01`, // New Year's / Restoration of Czech Independence
`${y}-05-01`, // Labour Day
`${y}-05-08`, // Victory Day
`${y}-07-05`, // Saints Cyril and Methodius Day
`${y}-07-06`, // Jan Hus Day
`${y}-09-28`, // Czech Statehood Day
`${y}-10-28`, // Czechoslovak Independence Day
`${y}-11-17`, // Freedom and Democracy Day
`${y}-12-24`, // Christmas Eve
`${y}-12-25`, // Christmas Day
`${y}-12-26`, // St. Stephen's Day
];
// Easter-based
@@ -51,10 +53,8 @@ export function getHolidays(year: number): string[] {
const easterMonday = new Date(easterDate);
easterMonday.setDate(easterMonday.getDate() + 1);
const fmt = (d: Date) =>
`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
holidays.push(fmt(goodFriday)); // Velký pátek
holidays.push(fmt(easterMonday)); // Velikonoční pondělí
holidays.push(localDateStr(goodFriday)); // Good Friday
holidays.push(localDateStr(easterMonday)); // Easter Monday
holidays.sort();
holidayCache.set(year, holidays);

40
src/utils/date.ts Normal file
View File

@@ -0,0 +1,40 @@
/**
* Centralized date/time helpers.
*
* Prisma stores DateTime as UTC in MySQL DATETIME columns.
* The Date.toJSON override in config/env.ts serializes using local getters,
* so the frontend always receives local time. These helpers ensure
* consistent local-time formatting whenever we need a string outside
* of JSON serialization (e.g., building lookup keys, shift_date strings).
*/
/** YYYY-MM-DD in local time */
export function localDateStr(d: Date): string {
const y = d.getFullYear();
const m = String(d.getMonth() + 1).padStart(2, "0");
const day = String(d.getDate()).padStart(2, "0");
return `${y}-${m}-${day}`;
}
/** YYYY-MM in local time */
export function localMonthStr(d: Date): string {
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}`;
}
/** HH:MM in local time */
export function localTimeStr(d: Date): string {
return `${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
}
/** DD.MM.YYYY in local time (Czech date format) */
export function localDateCzStr(d: Date): string {
return `${String(d.getDate()).padStart(2, "0")}.${String(d.getMonth() + 1).padStart(2, "0")}.${d.getFullYear()}`;
}
/** DD.MM.YYYY HH:MM:SS in local time (Czech datetime format) */
export function localDateTimeCzStr(d: Date): string {
const h = String(d.getHours()).padStart(2, "0");
const min = String(d.getMinutes()).padStart(2, "0");
const s = String(d.getSeconds()).padStart(2, "0");
return `${localDateCzStr(d)} ${h}:${min}:${s}`;
}

52
src/utils/html-to-pdf.ts Normal file
View File

@@ -0,0 +1,52 @@
import { Browser } from "puppeteer";
let browser: Browser | null = null;
async function getBrowser(): Promise<Browser> {
if (browser && browser.connected) return browser;
// Try puppeteer (bundles Chromium), fall back to puppeteer-core (system Chromium)
try {
const puppeteer = await import("puppeteer");
browser = await puppeteer.default.launch({
headless: true,
args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-gpu"],
});
} catch {
const core = await import("puppeteer-core");
const executablePath =
process.env.CHROMIUM_PATH ||
"/usr/bin/chromium-browser" ||
"/usr/bin/chromium";
browser = await core.default.launch({
headless: true,
executablePath,
args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-gpu"],
});
}
return browser;
}
export async function htmlToPdf(html: string): Promise<Buffer> {
const b = await getBrowser();
const page = await b.newPage();
try {
await page.setContent(html, { waitUntil: "networkidle0" });
const pdf = await page.pdf({
format: "A4",
printBackground: true,
margin: { top: "10mm", bottom: "10mm", left: "10mm", right: "10mm" },
});
return Buffer.from(pdf);
} finally {
await page.close();
}
}
export async function closeBrowser(): Promise<void> {
if (browser) {
await browser.close();
browser = null;
}
}