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:
@@ -12,7 +12,7 @@ import Forbidden from "../components/Forbidden";
|
||||
import FormField from "../components/FormField";
|
||||
import AdminDatePicker from "../components/AdminDatePicker";
|
||||
import ConfirmModal from "../components/ConfirmModal";
|
||||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import { motion } from "framer-motion";
|
||||
import {
|
||||
DndContext,
|
||||
closestCenter,
|
||||
@@ -104,6 +104,7 @@ interface InvoiceForm {
|
||||
issued_by: string;
|
||||
billing_text: string;
|
||||
notes: string;
|
||||
language: string;
|
||||
bank_account_id: number | string;
|
||||
bank_name: string;
|
||||
bank_swift: string;
|
||||
@@ -132,6 +133,7 @@ interface Invoice {
|
||||
issued_by: string | null;
|
||||
paid_date?: string;
|
||||
notes: string;
|
||||
language: string;
|
||||
apply_vat: number | string;
|
||||
items: Omit<InvoiceItem, "_key">[];
|
||||
valid_transitions?: string[];
|
||||
@@ -521,6 +523,7 @@ export default function InvoiceDetail() {
|
||||
issued_by: user?.fullName || "",
|
||||
billing_text: "",
|
||||
notes: "",
|
||||
language: "cs",
|
||||
bank_account_id: "",
|
||||
bank_name: "",
|
||||
bank_swift: "",
|
||||
@@ -536,12 +539,10 @@ export default function InvoiceDetail() {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [invoiceNumber, setInvoiceNumber] = useState("");
|
||||
|
||||
// Customer selector (create mode)
|
||||
const [customers, setCustomers] = useState<Customer[]>([]);
|
||||
const [customerSearch, setCustomerSearch] = useState("");
|
||||
const [showCustomerDropdown, setShowCustomerDropdown] = useState(false);
|
||||
|
||||
// Draft
|
||||
const DRAFT_KEY = "boha_invoice_draft";
|
||||
|
||||
const clearDraft = useCallback(() => {
|
||||
@@ -561,18 +562,15 @@ export default function InvoiceDetail() {
|
||||
status: string | null;
|
||||
}>({ show: false, status: null });
|
||||
const [pdfLoading, setPdfLoading] = useState(false);
|
||||
const [langModal, setLangModal] = useState(false);
|
||||
const [deleteConfirm, setDeleteConfirm] = useState(false);
|
||||
const [deleting, setDeleting] = useState(false);
|
||||
|
||||
// Edit items (edit mode)
|
||||
const [editingItems, setEditingItems] = useState(false);
|
||||
const [editItems, setEditItems] = useState<InvoiceItem[]>([]);
|
||||
const editKeyCounter = useRef(0);
|
||||
|
||||
// ─── Data loading ───
|
||||
|
||||
// Create mode: load next number, customers, bank accounts, order data
|
||||
useEffect(() => {
|
||||
if (isEdit) return;
|
||||
const load = async () => {
|
||||
@@ -843,6 +841,9 @@ export default function InvoiceDetail() {
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
clearDraft();
|
||||
await apiFetch(
|
||||
`${API_BASE}/invoices-pdf/${result.data.invoice_id}?lang=${form.language}&save=1`,
|
||||
).catch(() => {});
|
||||
alert.success(result.message || "Faktura byla vytvořena");
|
||||
navigate(`/invoices/${result.data.invoice_id}`);
|
||||
} else {
|
||||
@@ -918,6 +919,9 @@ export default function InvoiceDetail() {
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
await apiFetch(
|
||||
`${API_BASE}/invoices-pdf/${id}?lang=${invoice?.language || "cs"}&save=1`,
|
||||
).catch(() => {});
|
||||
alert.success("Poznámky byly uloženy");
|
||||
} else {
|
||||
alert.error(result.error || "Nepodařilo se uložit poznámky");
|
||||
@@ -930,28 +934,19 @@ export default function InvoiceDetail() {
|
||||
};
|
||||
|
||||
// ─── Edit mode: PDF export ───
|
||||
const handleViewPdf = async (lang = "cs") => {
|
||||
setLangModal(false);
|
||||
const newWindow = window.open("", "_blank");
|
||||
const handleViewPdf = async (_lang = "cs") => {
|
||||
setPdfLoading(true);
|
||||
try {
|
||||
const response = await apiFetch(
|
||||
`${API_BASE}/invoices-pdf/${id}?lang=${encodeURIComponent(lang)}`,
|
||||
);
|
||||
const response = await apiFetch(`${API_BASE}/invoices/${id}/file`);
|
||||
if (!response.ok) {
|
||||
newWindow?.close();
|
||||
alert.error("Nepodařilo se vygenerovat PDF");
|
||||
alert.error("PDF soubor nenalezen — uložte fakturu pro vygenerování");
|
||||
return;
|
||||
}
|
||||
const html = await response.text();
|
||||
if (newWindow) {
|
||||
newWindow.document.open();
|
||||
newWindow.document.write(html);
|
||||
newWindow.document.close();
|
||||
newWindow.onload = () => newWindow.print();
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
window.open(url, "_blank");
|
||||
setTimeout(() => URL.revokeObjectURL(url), 60000);
|
||||
} catch {
|
||||
newWindow?.close();
|
||||
alert.error("Chyba připojení");
|
||||
} finally {
|
||||
setPdfLoading(false);
|
||||
@@ -1028,6 +1023,10 @@ export default function InvoiceDetail() {
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
// Regenerate PDF on NAS (fire-and-forget)
|
||||
await apiFetch(
|
||||
`${API_BASE}/invoices-pdf/${id}?lang=${invoice?.language || "cs"}&save=1`,
|
||||
).catch(() => {});
|
||||
alert.success("Položky byly uloženy");
|
||||
setEditingItems(false);
|
||||
fetchDetail();
|
||||
@@ -1379,6 +1378,21 @@ export default function InvoiceDetail() {
|
||||
<option value="USD">USD ($)</option>
|
||||
</select>
|
||||
</FormField>
|
||||
<FormField label="Jazyk faktury">
|
||||
<select
|
||||
value={form.language}
|
||||
onChange={(e) =>
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
language: e.target.value,
|
||||
}))
|
||||
}
|
||||
className="admin-form-select"
|
||||
>
|
||||
<option value="cs">Čeština</option>
|
||||
<option value="en">English</option>
|
||||
</select>
|
||||
</FormField>
|
||||
<FormField label="DPH">
|
||||
<div className="flex-row-gap">
|
||||
<label
|
||||
@@ -1608,33 +1622,33 @@ export default function InvoiceDetail() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="admin-page-actions">
|
||||
{hasPermission("invoices.export") && (
|
||||
{hasPermission("invoices.export") && invoice && (
|
||||
<button
|
||||
onClick={() => setLangModal(true)}
|
||||
onClick={() => handleViewPdf(invoice.language || "cs")}
|
||||
className="admin-btn admin-btn-secondary"
|
||||
style={{
|
||||
display: "inline-flex",
|
||||
alignItems: "center",
|
||||
gap: "0.4rem",
|
||||
}}
|
||||
disabled={pdfLoading}
|
||||
>
|
||||
{pdfLoading ? (
|
||||
<>
|
||||
<div className="admin-spinner admin-spinner-sm" />
|
||||
PDF...
|
||||
</>
|
||||
<div className="admin-spinner admin-spinner-sm" />
|
||||
) : (
|
||||
<>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
|
||||
<polyline points="14 2 14 8 20 8" />
|
||||
</svg>
|
||||
PDF
|
||||
</>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
|
||||
<polyline points="14 2 14 8 20 8" />
|
||||
</svg>
|
||||
)}
|
||||
Zobrazit fakturu
|
||||
</button>
|
||||
)}
|
||||
{hasPermission("invoices.edit") &&
|
||||
@@ -2026,70 +2040,6 @@ export default function InvoiceDetail() {
|
||||
type="danger"
|
||||
loading={deleting}
|
||||
/>
|
||||
|
||||
{/* Language selection for PDF */}
|
||||
<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(false)}
|
||||
/>
|
||||
<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={() => handleViewPdf("cs")}
|
||||
className="admin-btn admin-btn-primary"
|
||||
>
|
||||
Čeština
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleViewPdf("en")}
|
||||
className="admin-btn admin-btn-primary"
|
||||
>
|
||||
English
|
||||
</button>
|
||||
</div>
|
||||
</motion.div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user