Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
164ce54adf | ||
|
|
6877919133 | ||
|
|
5ec70599aa | ||
|
|
7e4469b29a | ||
|
|
08af4cd0ae | ||
|
|
eb279a87a9 | ||
|
|
ea3b595b32 | ||
|
|
e9b432bec6 |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "app-ts",
|
"name": "app-ts",
|
||||||
"version": "2.4.24",
|
"version": "2.4.28",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "app-ts",
|
"name": "app-ts",
|
||||||
"version": "2.4.24",
|
"version": "2.4.28",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@anthropic-ai/sdk": "^0.102.0",
|
"@anthropic-ai/sdk": "^0.102.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "app-ts",
|
"name": "app-ts",
|
||||||
"version": "2.4.24",
|
"version": "2.4.28",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/server.js",
|
"main": "dist/server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -765,6 +765,34 @@ describe("ai-tools — employees, attendance detail, trips, work plan", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("get_document_totals: received_invoices sums gross + converts to CZK", async () => {
|
||||||
|
// invoices.view alone unlocks the received-invoices branch.
|
||||||
|
const res = await executeTool(
|
||||||
|
"get_document_totals",
|
||||||
|
{ type: "received_invoices", month: 6, year: 2098 },
|
||||||
|
VIEWER_INVOICES,
|
||||||
|
);
|
||||||
|
expect(res.ok).toBe(true);
|
||||||
|
const r = res.result as {
|
||||||
|
period: string;
|
||||||
|
invoice_count: number;
|
||||||
|
totals: { currency: string; amount: number }[];
|
||||||
|
total_czk: number;
|
||||||
|
};
|
||||||
|
expect(r.period).toBe("6/2098");
|
||||||
|
expect(r.invoice_count).toBe(1);
|
||||||
|
expect(r.totals).toEqual([{ currency: "CZK", amount: 1210 }]);
|
||||||
|
expect(r.total_czk).toBe(1210); // CZK rows convert 1:1, no rate fetch
|
||||||
|
|
||||||
|
// orders.view alone cannot read expense totals.
|
||||||
|
const denied = await executeTool(
|
||||||
|
"get_document_totals",
|
||||||
|
{ type: "received_invoices" },
|
||||||
|
{ userId: 999999998, roleName: "viewer", permissions: ["orders.view"] },
|
||||||
|
);
|
||||||
|
expect(denied.ok).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it("get_top_customers aggregates per customer across the whole table", async () => {
|
it("get_top_customers aggregates per customer across the whole table", async () => {
|
||||||
const res = await executeTool(
|
const res = await executeTool(
|
||||||
"get_top_customers",
|
"get_top_customers",
|
||||||
|
|||||||
55
src/__tests__/pdf-shared.test.ts
Normal file
55
src/__tests__/pdf-shared.test.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { describe, it, expect } from "vitest";
|
||||||
|
import { cleanQuillHtml } from "../utils/pdf-shared";
|
||||||
|
|
||||||
|
describe("cleanQuillHtml — inline-style whitelist", () => {
|
||||||
|
it("keeps Quill text and background colors", () => {
|
||||||
|
const html =
|
||||||
|
'<p><span style="color: rgb(230, 0, 0);">červeně</span> ' +
|
||||||
|
'<span style="background-color: #ffff00;">zvýrazněně</span> ' +
|
||||||
|
'<span style="color: #06c;">modře</span></p>';
|
||||||
|
const out = cleanQuillHtml(html);
|
||||||
|
expect(out).toContain('style="color: rgb(230, 0, 0)"');
|
||||||
|
expect(out).toContain('style="background-color: #ffff00"');
|
||||||
|
expect(out).toContain('style="color: #06c"');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("drops every non-color style declaration", () => {
|
||||||
|
const out = cleanQuillHtml(
|
||||||
|
'<span style="position: fixed; color: red; font-size: 99px;">x</span>',
|
||||||
|
);
|
||||||
|
expect(out).toBe('<span style="color: red">x</span>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("drops unsafe color values (url, expression, quotes)", () => {
|
||||||
|
expect(
|
||||||
|
cleanQuillHtml('<span style="color: url(javascript:alert(1))">x</span>'),
|
||||||
|
).toBe("<span>x</span>");
|
||||||
|
expect(
|
||||||
|
cleanQuillHtml('<span style="color: expression(alert(1))">x</span>'),
|
||||||
|
).toBe("<span>x</span>");
|
||||||
|
expect(cleanQuillHtml("<span style='color: \"red\"'>x</span>")).toBe(
|
||||||
|
"<span>x</span>",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("restores Quill 2's empty <p></p> blank lines to <p><br></p>", () => {
|
||||||
|
// Quill 2's semantic HTML drops the <br> placeholder from blank lines.
|
||||||
|
expect(cleanQuillHtml("<p>A</p><p></p><p>B</p>")).toBe(
|
||||||
|
"<p>A</p><p><br></p><p>B</p>",
|
||||||
|
);
|
||||||
|
// Attribute-carrying and whitespace-only empties too.
|
||||||
|
expect(cleanQuillHtml('<p class="ql-align-center"> </p>')).toBe(
|
||||||
|
'<p class="ql-align-center"><br></p>',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps stripping scripts, event handlers and js: URLs", () => {
|
||||||
|
const out = cleanQuillHtml(
|
||||||
|
'<p onclick="alert(1)"><script>alert(1)</script>' +
|
||||||
|
'<a href="javascript:alert(1)">x</a></p>',
|
||||||
|
);
|
||||||
|
expect(out).not.toContain("script");
|
||||||
|
expect(out).not.toContain("onclick");
|
||||||
|
expect(out).not.toContain("javascript:");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -214,7 +214,8 @@ function SortableItemRow({
|
|||||||
placeholder="Volitelný"
|
placeholder="Volitelný"
|
||||||
InputProps={{ readOnly }}
|
InputProps={{ readOnly }}
|
||||||
multiline
|
multiline
|
||||||
rows={2}
|
minRows={2}
|
||||||
|
maxRows={16}
|
||||||
slotProps={{ htmlInput: { maxLength: itemDescriptionMaxLength } }}
|
slotProps={{ htmlInput: { maxLength: itemDescriptionMaxLength } }}
|
||||||
sx={{ "& textarea": { resize: "vertical" } }}
|
sx={{ "& textarea": { resize: "vertical" } }}
|
||||||
/>
|
/>
|
||||||
@@ -352,7 +353,8 @@ function SortableItemRow({
|
|||||||
placeholder="Podrobný popis (volitelný)"
|
placeholder="Podrobný popis (volitelný)"
|
||||||
InputProps={{ readOnly }}
|
InputProps={{ readOnly }}
|
||||||
multiline
|
multiline
|
||||||
rows={2}
|
minRows={2}
|
||||||
|
maxRows={16}
|
||||||
slotProps={{ htmlInput: { maxLength: itemDescriptionMaxLength } }}
|
slotProps={{ htmlInput: { maxLength: itemDescriptionMaxLength } }}
|
||||||
sx={{
|
sx={{
|
||||||
"& textarea": {
|
"& textarea": {
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ import {
|
|||||||
formatCurrency,
|
formatCurrency,
|
||||||
formatDate,
|
formatDate,
|
||||||
numberOr,
|
numberOr,
|
||||||
|
restoreQuillBlankLines,
|
||||||
todayLocalStr,
|
todayLocalStr,
|
||||||
} from "../utils/formatters";
|
} from "../utils/formatters";
|
||||||
import { normalizeDateStr } from "../utils/attendanceHelpers";
|
import { normalizeDateStr } from "../utils/attendanceHelpers";
|
||||||
@@ -317,7 +318,8 @@ function SortableInvoiceRow({
|
|||||||
onChange={(e) => onUpdate(index, "item_description", e.target.value)}
|
onChange={(e) => onUpdate(index, "item_description", e.target.value)}
|
||||||
placeholder="Volitelný"
|
placeholder="Volitelný"
|
||||||
multiline
|
multiline
|
||||||
rows={2}
|
minRows={2}
|
||||||
|
maxRows={16}
|
||||||
sx={{ "& textarea": { resize: "vertical" } }}
|
sx={{ "& textarea": { resize: "vertical" } }}
|
||||||
/>
|
/>
|
||||||
<Box
|
<Box
|
||||||
@@ -418,7 +420,8 @@ function SortableInvoiceRow({
|
|||||||
}
|
}
|
||||||
placeholder="Podrobný popis (volitelný)"
|
placeholder="Podrobný popis (volitelný)"
|
||||||
multiline
|
multiline
|
||||||
rows={2}
|
minRows={2}
|
||||||
|
maxRows={16}
|
||||||
sx={{
|
sx={{
|
||||||
"& textarea": {
|
"& textarea": {
|
||||||
fontSize: "0.8rem",
|
fontSize: "0.8rem",
|
||||||
@@ -1668,7 +1671,9 @@ export default function InvoiceDetail() {
|
|||||||
{(s.content || "").replace(/<[^>]*>/g, "").trim() && (
|
{(s.content || "").replace(/<[^>]*>/g, "").trim() && (
|
||||||
<RichTextView
|
<RichTextView
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: DOMPurify.sanitize(s.content || ""),
|
__html: DOMPurify.sanitize(
|
||||||
|
restoreQuillBlankLines(s.content),
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -1688,7 +1693,9 @@ export default function InvoiceDetail() {
|
|||||||
invoice.internal_notes !== "<p><br></p>" ? (
|
invoice.internal_notes !== "<p><br></p>" ? (
|
||||||
<RichTextView
|
<RichTextView
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: DOMPurify.sanitize(invoice.internal_notes),
|
__html: DOMPurify.sanitize(
|
||||||
|
restoreQuillBlankLines(invoice.internal_notes),
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ import Typography from "@mui/material/Typography";
|
|||||||
import OrderConfirmationModal from "../components/OrderConfirmationModal";
|
import OrderConfirmationModal from "../components/OrderConfirmationModal";
|
||||||
import Forbidden from "../components/Forbidden";
|
import Forbidden from "../components/Forbidden";
|
||||||
import apiFetch from "../utils/api";
|
import apiFetch from "../utils/api";
|
||||||
import { formatCurrency, formatDate } from "../utils/formatters";
|
import {
|
||||||
|
formatCurrency,
|
||||||
|
formatDate,
|
||||||
|
restoreQuillBlankLines,
|
||||||
|
} from "../utils/formatters";
|
||||||
import { ORDER_STATUS, statusLabel, statusColor } from "../lib/documentStatus";
|
import { ORDER_STATUS, statusLabel, statusColor } from "../lib/documentStatus";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -713,7 +717,9 @@ export default function OrderDetail() {
|
|||||||
<RichTextView
|
<RichTextView
|
||||||
sx={{ p: 2 }}
|
sx={{ p: 2 }}
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: DOMPurify.sanitize(section.content),
|
__html: DOMPurify.sanitize(
|
||||||
|
restoreQuillBlankLines(section.content),
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -76,3 +76,15 @@ export function czechPlural(
|
|||||||
if (n >= 2 && n <= 4) return few;
|
if (n >= 2 && n <= 4) return few;
|
||||||
return many;
|
return many;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quill 2's semantic HTML saves blank lines as truly empty <p></p>, which
|
||||||
|
* collapse to zero height outside the editor — restore the <br> placeholder
|
||||||
|
* before rendering stored rich text read-only. (The PDF path does the same
|
||||||
|
* in cleanQuillHtml.)
|
||||||
|
*/
|
||||||
|
export function restoreQuillBlankLines(
|
||||||
|
html: string | null | undefined,
|
||||||
|
): string {
|
||||||
|
return (html || "").replace(/<p([^>]*)>\s*<\/p>/gi, "<p$1><br></p>");
|
||||||
|
}
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ export function buildInvoicePdfFooter(
|
|||||||
const t = translations[lang] || translations.cs;
|
const t = translations[lang] || translations.cs;
|
||||||
const pageWord = lang === "cs" ? "Strana" : "Page";
|
const pageWord = lang === "cs" ? "Strana" : "Page";
|
||||||
const ofWord = lang === "cs" ? "z" : "of";
|
const ofWord = lang === "cs" ? "z" : "of";
|
||||||
return `<div style="width:100%; font-size:8pt; font-family:Tahoma, sans-serif; color:#646464; padding:0 12mm; box-sizing:border-box; display:flex; align-items:center;">
|
return `<div style="width:100%; font-size:8pt; font-family:'Segoe UI', Tahoma, Arial, sans-serif; color:#646464; padding:0 12mm; box-sizing:border-box; display:flex; align-items:center;">
|
||||||
<div style="flex:1; text-align:left;"><span style="font-weight:600;">${escapeHtml(t.issued_by)}</span> ${escapeHtml(issuerLine)}</div>
|
<div style="flex:1; text-align:left;"><span style="font-weight:600;">${escapeHtml(t.issued_by)}</span> ${escapeHtml(issuerLine)}</div>
|
||||||
<div style="flex:1; text-align:center;">${pageWord} <span class="pageNumber"></span> ${ofWord} <span class="totalPages"></span></div>
|
<div style="flex:1; text-align:center;">${pageWord} <span class="pageNumber"></span> ${ofWord} <span class="totalPages"></span></div>
|
||||||
<div style="flex:1;"></div>
|
<div style="flex:1;"></div>
|
||||||
@@ -898,7 +898,7 @@ export default async function invoicesPdfRoutes(
|
|||||||
}
|
}
|
||||||
.section-content,
|
.section-content,
|
||||||
.section-content * {
|
.section-content * {
|
||||||
font-family: Tahoma, sans-serif !important;
|
font-family: "Segoe UI", Tahoma, Arial, sans-serif !important;
|
||||||
}
|
}
|
||||||
.section-content { font-size: 14px; }
|
.section-content { font-size: 14px; }
|
||||||
.section-content h1 { font-size: 20px; }
|
.section-content h1 { font-size: 20px; }
|
||||||
@@ -910,7 +910,7 @@ export default async function invoicesPdfRoutes(
|
|||||||
.section-content li { margin-bottom: 0.2em; }
|
.section-content li { margin-bottom: 0.2em; }
|
||||||
|
|
||||||
/* Quill fonty – v PDF vynuceno Tahoma */
|
/* Quill fonty – v PDF vynuceno Tahoma */
|
||||||
[class*="ql-font-"] { font-family: Tahoma, sans-serif !important; }
|
[class*="ql-font-"] { font-family: "Segoe UI", Tahoma, Arial, sans-serif !important; }
|
||||||
.ql-align-center { text-align: center; }
|
.ql-align-center { text-align: center; }
|
||||||
.ql-align-right { text-align: right; }
|
.ql-align-right { text-align: right; }
|
||||||
.ql-align-justify { text-align: justify; }
|
.ql-align-justify { text-align: justify; }
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ export function buildIssuedOrderPdfFooter(
|
|||||||
const t = translations[lang];
|
const t = translations[lang];
|
||||||
const pageWord = lang === "cs" ? "Strana" : "Page";
|
const pageWord = lang === "cs" ? "Strana" : "Page";
|
||||||
const ofWord = lang === "cs" ? "z" : "of";
|
const ofWord = lang === "cs" ? "z" : "of";
|
||||||
return `<div style="width:100%; font-size:8pt; font-family:Tahoma, sans-serif; color:#646464; padding:0 12mm; box-sizing:border-box; display:flex; align-items:center;">
|
return `<div style="width:100%; font-size:8pt; font-family:'Segoe UI', Tahoma, Arial, sans-serif; color:#646464; padding:0 12mm; box-sizing:border-box; display:flex; align-items:center;">
|
||||||
<div style="flex:1; text-align:left;"><span style="font-weight:600;">${escapeHtml(t.issued_by)}</span> ${escapeHtml(issuerName)}</div>
|
<div style="flex:1; text-align:left;"><span style="font-weight:600;">${escapeHtml(t.issued_by)}</span> ${escapeHtml(issuerName)}</div>
|
||||||
<div style="flex:1; text-align:center;">${pageWord} <span class="pageNumber"></span> ${ofWord} <span class="totalPages"></span></div>
|
<div style="flex:1; text-align:center;">${pageWord} <span class="pageNumber"></span> ${ofWord} <span class="totalPages"></span></div>
|
||||||
<div style="flex:1;"></div>
|
<div style="flex:1;"></div>
|
||||||
@@ -655,7 +655,7 @@ export function renderIssuedOrderHtml(
|
|||||||
}
|
}
|
||||||
.section-content,
|
.section-content,
|
||||||
.section-content * {
|
.section-content * {
|
||||||
font-family: Tahoma, sans-serif !important;
|
font-family: "Segoe UI", Tahoma, Arial, sans-serif !important;
|
||||||
}
|
}
|
||||||
.section-content { font-size: 14px; }
|
.section-content { font-size: 14px; }
|
||||||
.section-content h1 { font-size: 20px; }
|
.section-content h1 { font-size: 20px; }
|
||||||
@@ -667,7 +667,7 @@ export function renderIssuedOrderHtml(
|
|||||||
.section-content li { margin-bottom: 0.2em; }
|
.section-content li { margin-bottom: 0.2em; }
|
||||||
|
|
||||||
/* Quill fonty – v PDF vynuceno Tahoma */
|
/* Quill fonty – v PDF vynuceno Tahoma */
|
||||||
[class*="ql-font-"] { font-family: Tahoma, sans-serif !important; }
|
[class*="ql-font-"] { font-family: "Segoe UI", Tahoma, Arial, sans-serif !important; }
|
||||||
.ql-align-center { text-align: center; }
|
.ql-align-center { text-align: center; }
|
||||||
.ql-align-right { text-align: right; }
|
.ql-align-right { text-align: right; }
|
||||||
.ql-align-justify { text-align: justify; }
|
.ql-align-justify { text-align: justify; }
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ export function renderOfferHtml(
|
|||||||
img, table, pre, code { max-width: 100%; }
|
img, table, pre, code { max-width: 100%; }
|
||||||
|
|
||||||
/* ---- Quill font classes – v PDF vynuceno Tahoma ---- */
|
/* ---- Quill font classes – v PDF vynuceno Tahoma ---- */
|
||||||
[class*="ql-font-"] { font-family: Tahoma, sans-serif !important; }
|
[class*="ql-font-"] { font-family: "Segoe UI", Tahoma, Arial, sans-serif !important; }
|
||||||
|
|
||||||
/* ---- Quill alignment ---- */
|
/* ---- Quill alignment ---- */
|
||||||
.ql-align-center { text-align: center; }
|
.ql-align-center { text-align: center; }
|
||||||
@@ -502,7 +502,7 @@ ${indentCSS}
|
|||||||
}
|
}
|
||||||
.section-content,
|
.section-content,
|
||||||
.section-content * {
|
.section-content * {
|
||||||
font-family: Tahoma, sans-serif !important;
|
font-family: "Segoe UI", Tahoma, Arial, sans-serif !important;
|
||||||
}
|
}
|
||||||
.section-content { font-size: 14px; }
|
.section-content { font-size: 14px; }
|
||||||
.section-content h1 { font-size: 20px; }
|
.section-content h1 { font-size: 20px; }
|
||||||
|
|||||||
@@ -570,7 +570,7 @@ export function renderOrderConfirmationHtml(
|
|||||||
.invoice-notes-content li { margin-bottom: 0.2em; }
|
.invoice-notes-content li { margin-bottom: 0.2em; }
|
||||||
.invoice-notes-content,
|
.invoice-notes-content,
|
||||||
.invoice-notes-content * {
|
.invoice-notes-content * {
|
||||||
font-family: Tahoma, sans-serif !important;
|
font-family: "Segoe UI", Tahoma, Arial, sans-serif !important;
|
||||||
}
|
}
|
||||||
.invoice-notes-content { font-size: 14px; }
|
.invoice-notes-content { font-size: 14px; }
|
||||||
.invoice-notes-content h1 { font-size: 20px; }
|
.invoice-notes-content h1 { font-size: 20px; }
|
||||||
@@ -579,7 +579,7 @@ export function renderOrderConfirmationHtml(
|
|||||||
.invoice-notes-content h4 { font-size: 15px; }
|
.invoice-notes-content h4 { font-size: 15px; }
|
||||||
|
|
||||||
/* Quill fonty – v PDF vynuceno Tahoma */
|
/* Quill fonty – v PDF vynuceno Tahoma */
|
||||||
[class*="ql-font-"] { font-family: Tahoma, sans-serif !important; }
|
[class*="ql-font-"] { font-family: "Segoe UI", Tahoma, Arial, sans-serif !important; }
|
||||||
.ql-align-center { text-align: center; }
|
.ql-align-center { text-align: center; }
|
||||||
.ql-align-right { text-align: right; }
|
.ql-align-right { text-align: right; }
|
||||||
.ql-align-justify { text-align: justify; }
|
.ql-align-justify { text-align: justify; }
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
getWorkfund,
|
getWorkfund,
|
||||||
getProjectReport,
|
getProjectReport,
|
||||||
} from "./attendance.service";
|
} from "./attendance.service";
|
||||||
|
import { toCzk } from "./exchange-rates";
|
||||||
import { resolveGrid, listPlanUsers } from "./plan.service";
|
import { resolveGrid, listPlanUsers } from "./plan.service";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1688,35 +1689,38 @@ const TOOLS: ToolSpec[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Coarse gate any-of; the handler re-checks the exact permission per
|
// Coarse gate any-of; the handler re-checks the exact permission per
|
||||||
// document type (offers vs orders families).
|
// document type (offers vs orders vs invoices families).
|
||||||
permission: ["offers.view", "orders.view"],
|
permission: ["offers.view", "orders.view", "invoices.view"],
|
||||||
definition: {
|
definition: {
|
||||||
name: "get_document_totals",
|
name: "get_document_totals",
|
||||||
description:
|
description:
|
||||||
"Součty hodnot dokumentů za CELÝ filtr (ne jen prvních 20 z listu!) po měnách, BEZ DPH. Typy: offers (nabídky), orders (objednávky přijaté), issued_orders (objednávky vydané). VŽDY použij tento nástroj místo sčítání řádků z list_* nástrojů, když je výsledků víc než 20.",
|
"Součty hodnot dokumentů za CELÝ filtr (ne jen prvních 20 z listu!) po měnách. Typy: offers (nabídky, bez DPH), orders (objednávky přijaté, bez DPH), issued_orders (objednávky vydané, bez DPH), received_invoices (přijaté faktury = VÝDAJE, včetně DPH, s přepočtem do CZK). VŽDY použij tento nástroj místo sčítání řádků z list_* nástrojů. Na dotazy 'kolik jsme utratili' použij received_invoices a/nebo issued_orders.",
|
||||||
input_schema: {
|
input_schema: {
|
||||||
type: "object",
|
type: "object",
|
||||||
properties: {
|
properties: {
|
||||||
type: {
|
type: {
|
||||||
type: "string",
|
type: "string",
|
||||||
enum: ["offers", "orders", "issued_orders"],
|
enum: ["offers", "orders", "issued_orders", "received_invoices"],
|
||||||
description: "Typ dokumentů",
|
description:
|
||||||
|
"Typ dokumentů (received_invoices = přijaté faktury / výdaje, VČETNĚ DPH + přepočet do CZK)",
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
type: "string",
|
type: "string",
|
||||||
description: "Filtr stavu (vynech pro všechny)",
|
description:
|
||||||
|
"Filtr stavu (vynech pro všechny; received_invoices: unpaid/paid)",
|
||||||
},
|
},
|
||||||
search: {
|
search: {
|
||||||
type: "string",
|
type: "string",
|
||||||
description: "Hledání jako v list_* nástroji",
|
description:
|
||||||
|
"Hledání jako v list_* nástroji (ne received_invoices)",
|
||||||
},
|
},
|
||||||
month: {
|
month: {
|
||||||
type: "number",
|
type: "number",
|
||||||
description: "Měsíc 1-12 (jen orders/issued_orders)",
|
description: "Měsíc 1-12 (ne offers)",
|
||||||
},
|
},
|
||||||
year: {
|
year: {
|
||||||
type: "number",
|
type: "number",
|
||||||
description: "Rok (jen orders/issued_orders)",
|
description: "Rok (ne offers)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
required: ["type"],
|
required: ["type"],
|
||||||
@@ -1766,6 +1770,59 @@ const TOOLS: ToolSpec[] = [
|
|||||||
const { totals } = await getOrderTotals(filters);
|
const { totals } = await getOrderTotals(filters);
|
||||||
return { type, period, totals, note: "Součty bez DPH, po měnách." };
|
return { type, period, totals, note: "Součty bez DPH, po měnách." };
|
||||||
}
|
}
|
||||||
|
if (type === "received_invoices") {
|
||||||
|
if (!ctxCan(ctx, "invoices.view")) {
|
||||||
|
return { error: DENIED("přijaté faktury") };
|
||||||
|
}
|
||||||
|
// month/year are literal columns on received_invoices; gross sums
|
||||||
|
// per currency + CZK conversion mirror GET /received-invoices/stats.
|
||||||
|
const where: Record<string, unknown> = {};
|
||||||
|
if (month && year) {
|
||||||
|
where.month = month;
|
||||||
|
where.year = year;
|
||||||
|
} else if (year) {
|
||||||
|
where.year = year;
|
||||||
|
}
|
||||||
|
const status = str(input.status);
|
||||||
|
if (status === "unpaid" || status === "paid") where.status = status;
|
||||||
|
const rows = await prisma.received_invoices.findMany({
|
||||||
|
where,
|
||||||
|
select: { amount: true, currency: true },
|
||||||
|
});
|
||||||
|
const byCurrency: Record<string, number> = {};
|
||||||
|
for (const r of rows) {
|
||||||
|
const cur = r.currency || "CZK";
|
||||||
|
byCurrency[cur] = (byCurrency[cur] || 0) + (Number(r.amount) || 0);
|
||||||
|
}
|
||||||
|
const totals = Object.entries(byCurrency).map(([currency, amount]) => ({
|
||||||
|
currency,
|
||||||
|
amount: round2(amount),
|
||||||
|
}));
|
||||||
|
// CZK conversion mirrors the stats route: a row with an unknown
|
||||||
|
// currency is skipped (logged), never fails the whole sum.
|
||||||
|
let totalCzk = 0;
|
||||||
|
let skipped = 0;
|
||||||
|
for (const r of rows) {
|
||||||
|
try {
|
||||||
|
totalCzk += await toCzk(Number(r.amount) || 0, r.currency);
|
||||||
|
} catch (e) {
|
||||||
|
skipped += 1;
|
||||||
|
console.error(
|
||||||
|
`[ai-tools] toCzk failed for currency "${r.currency}"`,
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
period: month && year ? `${month}/${year}` : year ? `${year}` : "vše",
|
||||||
|
invoice_count: rows.length,
|
||||||
|
totals,
|
||||||
|
total_czk: round2(totalCzk),
|
||||||
|
...(skipped ? { czk_conversion_skipped_rows: skipped } : {}),
|
||||||
|
note: "Částky jsou VČETNĚ DPH (gross); total_czk je přepočet aktuálním kurzem.",
|
||||||
|
};
|
||||||
|
}
|
||||||
if (type === "issued_orders") {
|
if (type === "issued_orders") {
|
||||||
if (!ctxCan(ctx, "orders.view")) {
|
if (!ctxCan(ctx, "orders.view")) {
|
||||||
return { error: DENIED("objednávky vydané") };
|
return { error: DENIED("objednávky vydané") };
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ export function buildPdfHeaderTemplate(
|
|||||||
logoDataUri: string,
|
logoDataUri: string,
|
||||||
heading: string,
|
heading: string,
|
||||||
): string {
|
): string {
|
||||||
return `<div style="width:100%; font-family:Tahoma, sans-serif; padding:0 12mm; box-sizing:border-box;">
|
return `<div style="width:100%; font-family:'Segoe UI', Tahoma, Arial, sans-serif; padding:0 12mm; box-sizing:border-box;">
|
||||||
<div style="display:flex; justify-content:space-between; align-items:center; padding-bottom:1mm; border-bottom:2pt solid #de3a3a;">
|
<div style="display:flex; justify-content:space-between; align-items:center; padding-bottom:1mm; border-bottom:2pt solid #de3a3a;">
|
||||||
<div style="flex:0 0 auto;">${logoDataUri ? `<img src="${logoDataUri}" style="max-width:42mm; max-height:22mm; object-fit:contain;" />` : ""}</div>
|
<div style="flex:0 0 auto;">${logoDataUri ? `<img src="${logoDataUri}" style="max-width:42mm; max-height:22mm; object-fit:contain;" />` : ""}</div>
|
||||||
<div style="font-size:13pt; font-weight:700; color:#de3a3a; text-align:right; letter-spacing:0.03em;">${escapeHtml(heading)}</div>
|
<div style="font-size:13pt; font-weight:700; color:#de3a3a; text-align:right; letter-spacing:0.03em;">${escapeHtml(heading)}</div>
|
||||||
@@ -108,6 +108,13 @@ export function buildPdfHeaderTemplate(
|
|||||||
* and merge adjacent identical spans. Runs AFTER DOMPurify at every call site
|
* and merge adjacent identical spans. Runs AFTER DOMPurify at every call site
|
||||||
* (regex pass = defense-in-depth, not the primary sanitizer).
|
* (regex pass = defense-in-depth, not the primary sanitizer).
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* Literal CSS color values only: #hex, rgb()/rgba() with numeric components,
|
||||||
|
* or a bare keyword. No quotes, parentheses beyond rgb(a), url(), variables.
|
||||||
|
*/
|
||||||
|
const SAFE_CSS_COLOR =
|
||||||
|
/^(#[0-9a-f]{3,8}|rgba?\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*(,\s*(0|1|0?\.\d+)\s*)?\)|[a-z]{3,20})$/i;
|
||||||
|
|
||||||
export function cleanQuillHtml(html: string | null | undefined): string {
|
export function cleanQuillHtml(html: string | null | undefined): string {
|
||||||
if (!html) return "";
|
if (!html) return "";
|
||||||
let s = html;
|
let s = html;
|
||||||
@@ -134,7 +141,32 @@ export function cleanQuillHtml(html: string | null | undefined): string {
|
|||||||
);
|
);
|
||||||
// Replace with regular space (outside of tags)
|
// Replace with regular space (outside of tags)
|
||||||
s = s.replace(/( )/g, " ");
|
s = s.replace(/( )/g, " ");
|
||||||
s = s.replace(/\s+style\s*=\s*("[^"]*"|'[^']*'|[^\s>]*)/gi, "");
|
// Quill 2's semantic HTML saves blank lines as truly empty <p></p>, which
|
||||||
|
// collapse to zero height in the PDF — restore the <br> placeholder so an
|
||||||
|
// editor blank line stays a blank line.
|
||||||
|
s = s.replace(/<p([^>]*)>\s*<\/p>/gi, "<p$1><br></p>");
|
||||||
|
// Inline styles: Quill writes text/background colors as style attributes.
|
||||||
|
// Keep ONLY color/background-color with literal color values — everything
|
||||||
|
// else (url(), expression(), positioning…) must never reach Puppeteer.
|
||||||
|
s = s.replace(
|
||||||
|
/\s+style\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi,
|
||||||
|
(_m, dq, sq, bare) => {
|
||||||
|
const kept = String(dq ?? sq ?? bare ?? "")
|
||||||
|
.split(";")
|
||||||
|
.map((decl) => {
|
||||||
|
const i = decl.indexOf(":");
|
||||||
|
if (i < 0) return null;
|
||||||
|
const prop = decl.slice(0, i).trim().toLowerCase();
|
||||||
|
const val = decl.slice(i + 1).trim();
|
||||||
|
return (prop === "color" || prop === "background-color") &&
|
||||||
|
SAFE_CSS_COLOR.test(val)
|
||||||
|
? `${prop}: ${val}`
|
||||||
|
: null;
|
||||||
|
})
|
||||||
|
.filter((d): d is string => d !== null);
|
||||||
|
return kept.length ? ` style="${kept.join("; ")}"` : "";
|
||||||
|
},
|
||||||
|
);
|
||||||
// Merge adjacent spans with same attributes
|
// Merge adjacent spans with same attributes
|
||||||
let prev = "";
|
let prev = "";
|
||||||
while (prev !== s) {
|
while (prev !== s) {
|
||||||
|
|||||||
Reference in New Issue
Block a user