Compare commits

..

2 Commits

Author SHA1 Message Date
BOHA
b197017644 1.5.1 2026-04-02 20:01:44 +02:00
BOHA
e9f07a4a39 fix: invoice edit/list improvements
- Due date uses days selector in edit mode (same as create)
- Overdue invoices fully editable (same as issued)
- Overdue status reversed to issued when due date moved to future
- Invoice list: edit icon for issued/overdue, eye for paid
- Invoice list: PDF opens blob from NAS (removed lang modal)
- NAS cleanup: properly scans directories when cleaning old PDFs
- Fixed syntax error from leftover else block

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 20:01:43 +02:00
6 changed files with 94 additions and 136 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "app-ts", "name": "app-ts",
"version": "1.5.0", "version": "1.5.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "app-ts", "name": "app-ts",
"version": "1.5.0", "version": "1.5.1",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@dnd-kit/core": "^6.3.1", "@dnd-kit/core": "^6.3.1",

View File

@@ -1,6 +1,6 @@
{ {
"name": "app-ts", "name": "app-ts",
"version": "1.5.0", "version": "1.5.1",
"description": "", "description": "",
"main": "dist/server.js", "main": "dist/server.js",
"scripts": { "scripts": {

View File

@@ -615,6 +615,16 @@ export default function InvoiceDetail() {
bank_account: inv.bank_account || "", bank_account: inv.bank_account || "",
}); });
// Calculate dueDays from existing dates
if (inv.issue_date && inv.due_date) {
const issue = new Date(inv.issue_date);
const due = new Date(inv.due_date);
const diffDays = Math.round(
(due.getTime() - issue.getTime()) / (1000 * 60 * 60 * 24),
);
if (diffDays > 0 && diffDays <= 60) setDueDays(diffDays);
}
// Populate items from existing invoice // Populate items from existing invoice
if (inv.items?.length > 0) { if (inv.items?.length > 0) {
setItems( setItems(
@@ -645,14 +655,13 @@ export default function InvoiceDetail() {
if (isEdit) fetchDetail(); if (isEdit) fetchDetail();
}, [isEdit, fetchDetail]); }, [isEdit, fetchDetail]);
// ─── Create mode: due date calculation ─── // ─── Due date calculation from issue date + days ───
useEffect(() => { useEffect(() => {
if (isEdit) return;
if (!form.issue_date) return; if (!form.issue_date) return;
const d = new Date(form.issue_date); const d = new Date(form.issue_date);
d.setDate(d.getDate() + dueDays); d.setDate(d.getDate() + dueDays);
setForm((prev) => ({ ...prev, due_date: d.toISOString().split("T")[0] })); setForm((prev) => ({ ...prev, due_date: d.toISOString().split("T")[0] }));
}, [isEdit, form.issue_date, dueDays]); }, [form.issue_date, dueDays]);
// ─── Create mode: customer filtering ─── // ─── Create mode: customer filtering ───
const filteredCustomers = useMemo(() => { const filteredCustomers = useMemo(() => {
@@ -1540,7 +1549,6 @@ export default function InvoiceDetail() {
}} }}
/> />
</FormField> </FormField>
{!isEdit ? (
<FormField label="Splatnost (dny)"> <FormField label="Splatnost (dny)">
<select <select
value={dueDays} value={dueDays}
@@ -1560,17 +1568,6 @@ export default function InvoiceDetail() {
</span> </span>
)} )}
</FormField> </FormField>
) : (
<FormField label="Datum splatnosti">
<AdminDatePicker
mode="date"
value={form.due_date}
onChange={(val: string) => {
setForm((prev) => ({ ...prev, due_date: val }));
}}
/>
</FormField>
)}
<FormField label="DÚZP" error={errors.tax_date} required> <FormField label="DÚZP" error={errors.tax_date} required>
<AdminDatePicker <AdminDatePicker
mode="date" mode="date"

View File

@@ -194,7 +194,6 @@ export default function Invoices() {
}>({ show: false, invoice: null }); }>({ show: false, invoice: null });
const [deleting, setDeleting] = useState(false); const [deleting, setDeleting] = useState(false);
const [pdfLoading, setPdfLoading] = useState<number | null>(null); const [pdfLoading, setPdfLoading] = useState<number | null>(null);
const [langModal, setLangModal] = useState<Invoice | null>(null);
const [draft, setDraft] = useState<DraftData | null>(() => { const [draft, setDraft] = useState<DraftData | null>(() => {
try { try {
const raw = localStorage.getItem(DRAFT_KEY); const raw = localStorage.getItem(DRAFT_KEY);
@@ -284,29 +283,25 @@ export default function Invoices() {
} }
}; };
const handlePdf = async (inv: Invoice, lang = "cs") => { const handlePdf = async (inv: Invoice) => {
if (pdfLoading) return; if (pdfLoading) return;
setLangModal(null); const newWindow = window.open("", "_blank");
setPdfLoading(inv.id); setPdfLoading(inv.id);
try { try {
const response = await apiFetch( const response = await apiFetch(`${API_BASE}/invoices/${inv.id}/file`);
`${API_BASE}/invoices-pdf/${inv.id}?lang=${encodeURIComponent(lang)}`, if (response.status === 401) {
); newWindow?.close();
if (response.status === 401) return;
if (!response.ok) {
alert.error("Nepodařilo se vygenerovat PDF");
return; return;
} }
const html = await response.text(); if (!response.ok) {
const w = window.open("", "_blank"); newWindow?.close();
if (w) { alert.error("PDF soubor nenalezen — otevřete fakturu a uložte ji");
w.document.open(); return;
w.document.write(html);
w.document.close();
w.onload = () => w.print();
} else {
alert.error("Prohlížeč zablokoval vyskakovací okno");
} }
const blob = await response.blob();
const url = URL.createObjectURL(blob);
if (newWindow) newWindow.location.href = url;
setTimeout(() => URL.revokeObjectURL(url), 60000);
} catch { } catch {
alert.error("Chyba při generování PDF"); alert.error("Chyba při generování PDF");
} finally { } finally {
@@ -996,9 +991,14 @@ export default function Invoices() {
<Link <Link
to={`/invoices/${inv.id}`} to={`/invoices/${inv.id}`}
className="admin-btn-icon" className="admin-btn-icon"
title="Detail" title={
aria-label="Detail" inv.status === "paid" ? "Detail" : "Upravit"
}
aria-label={
inv.status === "paid" ? "Detail" : "Upravit"
}
> >
{inv.status === "paid" ? (
<svg <svg
width="18" width="18"
height="18" height="18"
@@ -1010,12 +1010,25 @@ export default function Invoices() {
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" /> <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
<circle cx="12" cy="12" r="3" /> <circle cx="12" cy="12" r="3" />
</svg> </svg>
) : (
<svg
width="18"
height="18"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
>
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" />
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" />
</svg>
)}
</Link> </Link>
{hasPermission("invoices.export") && ( {hasPermission("invoices.export") && (
<button <button
onClick={() => setLangModal(inv)} onClick={() => handlePdf(inv)}
className="admin-btn-icon" className="admin-btn-icon"
title="PDF" title="Zobrazit fakturu"
disabled={pdfLoading === inv.id} disabled={pdfLoading === inv.id}
> >
{pdfLoading === inv.id ? ( {pdfLoading === inv.id ? (
@@ -1092,69 +1105,6 @@ export default function Invoices() {
type="danger" type="danger"
loading={deleting} loading={deleting}
/> />
<AnimatePresence>
{langModal && (
<motion.div
className="admin-modal-overlay"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.2 }}
>
<div
className="admin-modal-backdrop"
onClick={() => setLangModal(null)}
/>
<motion.div
className="admin-modal admin-confirm-modal"
role="dialog"
aria-modal="true"
initial={{ opacity: 0, scale: 0.95, y: 20 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
exit={{ opacity: 0, scale: 0.95, y: 20 }}
transition={{ duration: 0.2 }}
>
<div className="admin-modal-body admin-confirm-content">
<div className="admin-confirm-icon admin-confirm-icon-info">
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
>
<path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z" />
<path d="M2 12h20" />
<path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z" />
</svg>
</div>
<h2 className="admin-confirm-title">Jazyk faktury</h2>
<p className="admin-confirm-message">
V jakém jazyce chcete vygenerovat fakturu?
</p>
</div>
<div className="admin-modal-footer">
<button
type="button"
onClick={() => handlePdf(langModal, "cs")}
className="admin-btn admin-btn-primary"
>
Čeština
</button>
<button
type="button"
onClick={() => handlePdf(langModal, "en")}
className="admin-btn admin-btn-primary"
>
English
</button>
</div>
</motion.div>
</motion.div>
)}
</AnimatePresence>
</> </>
)} )}
</div> </div>

View File

@@ -70,6 +70,11 @@ export async function markOverdueInvoices() {
where: { status: "issued", due_date: { lt: new Date() } }, where: { status: "issued", due_date: { lt: new Date() } },
data: { status: "overdue" }, data: { status: "overdue" },
}); });
// Reverse: if due_date was changed to future, set back to issued
await prisma.invoices.updateMany({
where: { status: "overdue", due_date: { gte: new Date() } },
data: { status: "issued" },
});
} catch (err) { } catch (err) {
console.error("markOverdueInvoices failed:", err); console.error("markOverdueInvoices failed:", err);
} }
@@ -350,8 +355,8 @@ export async function updateInvoice(id: number, body: Record<string, any>) {
const data: Record<string, unknown> = { modified_at: new Date() }; const data: Record<string, unknown> = { modified_at: new Date() };
// Only allow full editing in 'issued' state // Allow full editing in 'issued' and 'overdue' states
const isDraft = currentStatus === "issued"; const isDraft = currentStatus === "issued" || currentStatus === "overdue";
if (isDraft) { if (isDraft) {
const strFields = [ const strFields = [
"currency", "currency",

View File

@@ -41,7 +41,13 @@ class NasFinancialsManager {
const yearPath = path.join(issuedDir, yearDir); const yearPath = path.join(issuedDir, yearDir);
if (!fs.statSync(yearPath).isDirectory()) continue; if (!fs.statSync(yearPath).isDirectory()) continue;
for (const monthDir of fs.readdirSync(yearPath)) { for (const monthDir of fs.readdirSync(yearPath)) {
const filePath = path.join(yearPath, monthDir, safeName); const monthPath = path.join(yearPath, monthDir);
try {
if (!fs.statSync(monthPath).isDirectory()) continue;
} catch {
continue;
}
const filePath = path.join(monthPath, safeName);
if (fs.existsSync(filePath)) { if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath); fs.unlinkSync(filePath);
} }