Compare commits
34 Commits
v1.3.4
...
b197017644
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b197017644 | ||
|
|
e9f07a4a39 | ||
|
|
44d389201c | ||
|
|
3106aaf314 | ||
|
|
90e797b8fa | ||
|
|
1f7362c8af | ||
|
|
fe44a2b12d | ||
|
|
8a9239311d | ||
|
|
cd25cd6ee4 | ||
|
|
967fbba2a4 | ||
|
|
41fe65c7fc | ||
|
|
09d345a312 | ||
|
|
1a13d745f1 | ||
|
|
ce184771a6 | ||
|
|
7b6365f6b3 | ||
|
|
44867c79f8 | ||
|
|
09a9e8c2f0 | ||
|
|
b26a6f40b9 | ||
|
|
40cb5a4d76 | ||
|
|
ecd97ae5a3 | ||
|
|
d14e97d7bd | ||
|
|
ef891f8e01 | ||
|
|
96ba5d034f | ||
|
|
2402b7cbc8 | ||
|
|
79b2fa5570 | ||
|
|
35fa172d36 | ||
|
|
000a77ccf4 | ||
|
|
ecd9f6a181 | ||
|
|
68e6d80903 | ||
|
|
af1b41994c | ||
|
|
9779112066 | ||
|
|
e8d6dc1567 | ||
|
|
f9dd49591e | ||
|
|
8cdf057ab3 |
28
package-lock.json
generated
28
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "app-ts",
|
"name": "app-ts",
|
||||||
"version": "1.3.4",
|
"version": "1.5.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "app-ts",
|
"name": "app-ts",
|
||||||
"version": "1.3.4",
|
"version": "1.5.1",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dnd-kit/core": "^6.3.1",
|
"@dnd-kit/core": "^6.3.1",
|
||||||
@@ -2089,9 +2089,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/brace-expansion": {
|
"node_modules/brace-expansion": {
|
||||||
"version": "5.0.4",
|
"version": "5.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.5.tgz",
|
||||||
"integrity": "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg==",
|
"integrity": "sha512-VZznLgtwhn+Mact9tfiwx64fA9erHH/MCXEUfB/0bX/6Fz6ny5EGTXYltMocqg4xFAQZtnO3DHWWXi8RiuN7cQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"balanced-match": "^4.0.2"
|
"balanced-match": "^4.0.2"
|
||||||
@@ -3086,9 +3086,9 @@
|
|||||||
"license": "BSD-3-Clause"
|
"license": "BSD-3-Clause"
|
||||||
},
|
},
|
||||||
"node_modules/fastify": {
|
"node_modules/fastify": {
|
||||||
"version": "5.8.2",
|
"version": "5.8.4",
|
||||||
"resolved": "https://registry.npmjs.org/fastify/-/fastify-5.8.2.tgz",
|
"resolved": "https://registry.npmjs.org/fastify/-/fastify-5.8.4.tgz",
|
||||||
"integrity": "sha512-lZmt3navvZG915IE+f7/TIVamxIwmBd+OMB+O9WBzcpIwOo6F0LTh0sluoMFk5VkrKTvvrwIaoJPkir4Z+jtAg==",
|
"integrity": "sha512-sa42J1xylbBAYUWALSBoyXKPDUvM3OoNOibIefA+Oha57FryXKKCZarA1iDntOCWp3O35voZLuDg2mdODXtPzQ==",
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "github",
|
"type": "github",
|
||||||
@@ -4282,9 +4282,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/nodemailer": {
|
"node_modules/nodemailer": {
|
||||||
"version": "8.0.2",
|
"version": "8.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-8.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-8.0.4.tgz",
|
||||||
"integrity": "sha512-zbj002pZAIkWQFxyAaqoxvn+zoIwRnS40hgjqTXudKOOJkiFFgBeNqjgD3/YCR12sZnrghWYBY+yP1ZucdDRpw==",
|
"integrity": "sha512-k+jf6N8PfQJ0Fe8ZhJlgqU5qJU44Lpvp2yvidH3vp1lPnVQMgi4yEEMPXg5eJS1gFIJTVq1NHBk7Ia9ARdSBdQ==",
|
||||||
"license": "MIT-0",
|
"license": "MIT-0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.0.0"
|
"node": ">=6.0.0"
|
||||||
@@ -4540,9 +4540,9 @@
|
|||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
"node_modules/picomatch": {
|
"node_modules/picomatch": {
|
||||||
"version": "4.0.3",
|
"version": "4.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz",
|
||||||
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
"integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "app-ts",
|
"name": "app-ts",
|
||||||
"version": "1.3.4",
|
"version": "1.5.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/server.js",
|
"main": "dist/server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -412,4 +412,9 @@ img {
|
|||||||
transition-duration: 0.01ms !important;
|
transition-duration: 0.01ms !important;
|
||||||
scroll-behavior: auto !important;
|
scroll-behavior: auto !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.admin-spinner {
|
||||||
|
animation-duration: 0.8s !important;
|
||||||
|
animation-iteration-count: infinite !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -561,7 +561,9 @@ export default function useAttendanceAdmin({ alert }: AlertContext) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadUsers = async () => {
|
const loadUsers = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await apiFetch(`${API_BASE}/users?limit=1000`);
|
const response = await apiFetch(
|
||||||
|
`${API_BASE}/attendance?action=attendance_users`,
|
||||||
|
);
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const apiUsers: ApiUser[] = result.data;
|
const apiUsers: ApiUser[] = result.data;
|
||||||
|
|||||||
@@ -576,10 +576,7 @@ export default function Attendance() {
|
|||||||
<div className="attendance-project-header">
|
<div className="attendance-project-header">
|
||||||
<span className="attendance-shift-label">Projekt</span>
|
<span className="attendance-shift-label">Projekt</span>
|
||||||
{activeProjectId ? (
|
{activeProjectId ? (
|
||||||
<span
|
<span className="admin-badge admin-badge-wrap text-sm">
|
||||||
className="admin-badge admin-badge-wrap"
|
|
||||||
style={{ fontSize: "0.8125rem" }}
|
|
||||||
>
|
|
||||||
{projects.find(
|
{projects.find(
|
||||||
(p) => String(p.id) === String(activeProjectId),
|
(p) => String(p.id) === String(activeProjectId),
|
||||||
)
|
)
|
||||||
@@ -587,12 +584,7 @@ export default function Attendance() {
|
|||||||
: `Projekt #${activeProjectId}`}
|
: `Projekt #${activeProjectId}`}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span
|
<span className="text-muted text-sm">Žádný</span>
|
||||||
className="text-muted"
|
|
||||||
style={{ fontSize: "0.8125rem" }}
|
|
||||||
>
|
|
||||||
Žádný
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<select
|
<select
|
||||||
@@ -601,8 +593,7 @@ export default function Attendance() {
|
|||||||
handleSwitchProject(e.target.value || null)
|
handleSwitchProject(e.target.value || null)
|
||||||
}
|
}
|
||||||
disabled={switchingProject}
|
disabled={switchingProject}
|
||||||
className="admin-form-select"
|
className="admin-form-select text-md"
|
||||||
style={{ fontSize: "0.875rem" }}
|
|
||||||
>
|
>
|
||||||
<option value="">— Bez projektu —</option>
|
<option value="">— Bez projektu —</option>
|
||||||
{projects.map((p) => (
|
{projects.map((p) => (
|
||||||
@@ -654,8 +645,7 @@ export default function Attendance() {
|
|||||||
<button
|
<button
|
||||||
onClick={handleBreak}
|
onClick={handleBreak}
|
||||||
disabled={submitting}
|
disabled={submitting}
|
||||||
className="admin-btn admin-btn-secondary"
|
className="admin-btn admin-btn-secondary w-full"
|
||||||
style={{ width: "100%" }}
|
|
||||||
>
|
>
|
||||||
Pauza (30 min)
|
Pauza (30 min)
|
||||||
</button>
|
</button>
|
||||||
@@ -663,15 +653,13 @@ export default function Attendance() {
|
|||||||
<button
|
<button
|
||||||
onClick={() => handlePunch("departure")}
|
onClick={() => handlePunch("departure")}
|
||||||
disabled={submitting}
|
disabled={submitting}
|
||||||
className="admin-btn admin-btn-primary"
|
className="admin-btn admin-btn-primary w-full"
|
||||||
style={{ width: "100%" }}
|
|
||||||
>
|
>
|
||||||
{submitting ? "Zpracovávám..." : "Odchod"}
|
{submitting ? "Zpracovávám..." : "Odchod"}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowLeaveModal(true)}
|
onClick={() => setShowLeaveModal(true)}
|
||||||
className="admin-btn admin-btn-secondary"
|
className="admin-btn admin-btn-secondary w-full"
|
||||||
style={{ width: "100%" }}
|
|
||||||
>
|
>
|
||||||
Žádost o nepřítomnost
|
Žádost o nepřítomnost
|
||||||
</button>
|
</button>
|
||||||
@@ -703,16 +691,14 @@ export default function Attendance() {
|
|||||||
<button
|
<button
|
||||||
onClick={() => handlePunch("arrival")}
|
onClick={() => handlePunch("arrival")}
|
||||||
disabled={submitting}
|
disabled={submitting}
|
||||||
className="admin-btn admin-btn-primary"
|
className="admin-btn admin-btn-primary w-full"
|
||||||
style={{ width: "100%" }}
|
|
||||||
>
|
>
|
||||||
{submitting ? "Zpracovávám..." : "Příchod"}
|
{submitting ? "Zpracovávám..." : "Příchod"}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowLeaveModal(true)}
|
onClick={() => setShowLeaveModal(true)}
|
||||||
className="admin-btn admin-btn-secondary"
|
className="admin-btn admin-btn-secondary w-full"
|
||||||
style={{ width: "100%" }}
|
|
||||||
>
|
>
|
||||||
Žádost o nepřítomnost
|
Žádost o nepřítomnost
|
||||||
</button>
|
</button>
|
||||||
@@ -877,11 +863,10 @@ export default function Attendance() {
|
|||||||
</div>
|
</div>
|
||||||
<div style={{ marginTop: "0.75rem" }}>
|
<div style={{ marginTop: "0.75rem" }}>
|
||||||
<div
|
<div
|
||||||
className="text-secondary"
|
className="text-secondary text-sm"
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
fontSize: "0.8125rem",
|
|
||||||
marginBottom: "0.5rem",
|
marginBottom: "0.5rem",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -905,8 +890,8 @@ export default function Attendance() {
|
|||||||
</div>
|
</div>
|
||||||
{data.monthly_fund.leave_hours > 0 && (
|
{data.monthly_fund.leave_hours > 0 && (
|
||||||
<div
|
<div
|
||||||
className="text-muted"
|
className="text-muted text-xs"
|
||||||
style={{ fontSize: "0.75rem", marginTop: "0.375rem" }}
|
style={{ marginTop: "0.375rem" }}
|
||||||
>
|
>
|
||||||
{"Pokryto: "}
|
{"Pokryto: "}
|
||||||
{data.monthly_fund.covered}h (práce{" "}
|
{data.monthly_fund.covered}h (práce{" "}
|
||||||
|
|||||||
@@ -493,7 +493,7 @@ export default function Dashboard() {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="dash-stat-row">
|
<div className="dash-stat-row">
|
||||||
<span>Prošlé</span>
|
<span>Zneplatněné</span>
|
||||||
<span className="admin-badge admin-badge-warning">
|
<span className="admin-badge admin-badge-warning">
|
||||||
{dashData.offers.expired_count}
|
{dashData.offers.expired_count}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -56,7 +56,7 @@ function formatCzkWithDetail(
|
|||||||
if (!Array.isArray(amounts) || amounts.length === 0)
|
if (!Array.isArray(amounts) || amounts.length === 0)
|
||||||
return { value: "0 Kč", detail: null };
|
return { value: "0 Kč", detail: null };
|
||||||
const hasForeign = amounts.some((a) => a.currency !== "CZK");
|
const hasForeign = amounts.some((a) => a.currency !== "CZK");
|
||||||
if (hasForeign && totalCzk !== null && totalCzk !== undefined) {
|
if (hasForeign && totalCzk != null) {
|
||||||
return {
|
return {
|
||||||
value: formatCurrency(totalCzk, "CZK"),
|
value: formatCurrency(totalCzk, "CZK"),
|
||||||
detail: formatMultiCurrency(amounts),
|
detail: formatMultiCurrency(amounts),
|
||||||
@@ -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,26 +991,44 @@ 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"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<svg
|
{inv.status === "paid" ? (
|
||||||
width="18"
|
<svg
|
||||||
height="18"
|
width="18"
|
||||||
viewBox="0 0 24 24"
|
height="18"
|
||||||
fill="none"
|
viewBox="0 0 24 24"
|
||||||
stroke="currentColor"
|
fill="none"
|
||||||
strokeWidth="2"
|
stroke="currentColor"
|
||||||
>
|
strokeWidth="2"
|
||||||
<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" />
|
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
|
||||||
</svg>
|
<circle cx="12" cy="12" r="3" />
|
||||||
|
</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>
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export default function LeaveRequests() {
|
|||||||
|
|
||||||
const fetchRequests = useCallback(async () => {
|
const fetchRequests = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await apiFetch(`${API_BASE}/leave-requests`);
|
const response = await apiFetch(`${API_BASE}/leave-requests?mine=1`);
|
||||||
if (response.status === 401) return;
|
if (response.status === 401) return;
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
|||||||
@@ -180,9 +180,7 @@ function SortableItemRow({
|
|||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
)}
|
)}
|
||||||
<td style={{ textAlign: "center", color: "var(--text-tertiary)" }}>
|
<td className="text-center text-tertiary">{index + 1}</td>
|
||||||
{index + 1}
|
|
||||||
</td>
|
|
||||||
<td style={{ verticalAlign: "top" }}>
|
<td style={{ verticalAlign: "top" }}>
|
||||||
<div
|
<div
|
||||||
style={{ display: "flex", flexDirection: "column", gap: "0.25rem" }}
|
style={{ display: "flex", flexDirection: "column", gap: "0.25rem" }}
|
||||||
@@ -191,10 +189,9 @@ function SortableItemRow({
|
|||||||
type="text"
|
type="text"
|
||||||
value={item.description}
|
value={item.description}
|
||||||
onChange={(e) => onUpdate("description", e.target.value)}
|
onChange={(e) => onUpdate("description", e.target.value)}
|
||||||
className="admin-form-input"
|
className="admin-form-input fw-500"
|
||||||
placeholder="Název položky"
|
placeholder="Název položky"
|
||||||
readOnly={readOnly}
|
readOnly={readOnly}
|
||||||
style={{ fontWeight: 500 }}
|
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
@@ -240,7 +237,7 @@ function SortableItemRow({
|
|||||||
readOnly={readOnly}
|
readOnly={readOnly}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td style={{ textAlign: "center" }}>
|
<td className="text-center">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={item.is_included_in_total}
|
checked={item.is_included_in_total}
|
||||||
@@ -248,10 +245,7 @@ function SortableItemRow({
|
|||||||
disabled={readOnly}
|
disabled={readOnly}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td
|
<td className="admin-mono text-right fw-600">
|
||||||
className="admin-mono"
|
|
||||||
style={{ textAlign: "right", fontWeight: 600 }}
|
|
||||||
>
|
|
||||||
{formatCurrency(lineTotal, currency)}
|
{formatCurrency(lineTotal, currency)}
|
||||||
</td>
|
</td>
|
||||||
{!readOnly && (
|
{!readOnly && (
|
||||||
@@ -874,11 +868,10 @@ export default function OfferDetail() {
|
|||||||
{isEdit ? `Nabídka ${form.quotation_number}` : "Nová nabídka"}
|
{isEdit ? `Nabídka ${form.quotation_number}` : "Nová nabídka"}
|
||||||
{isInvalidated && (
|
{isInvalidated && (
|
||||||
<span
|
<span
|
||||||
className="admin-badge admin-badge-danger"
|
className="admin-badge admin-badge-danger text-xs"
|
||||||
style={{
|
style={{
|
||||||
marginLeft: "0.75rem",
|
marginLeft: "0.75rem",
|
||||||
verticalAlign: "middle",
|
verticalAlign: "middle",
|
||||||
fontSize: "0.75rem",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Zneplatněna
|
Zneplatněna
|
||||||
@@ -1208,10 +1201,7 @@ export default function OfferDetail() {
|
|||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
<label
|
<label className="admin-form-checkbox whitespace-nowrap">
|
||||||
className="admin-form-checkbox"
|
|
||||||
style={{ whiteSpace: "nowrap" }}
|
|
||||||
>
|
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={form.apply_vat}
|
checked={form.apply_vat}
|
||||||
@@ -1672,7 +1662,7 @@ export default function OfferDetail() {
|
|||||||
<FormField label="Příloha (PDF)">
|
<FormField label="Příloha (PDF)">
|
||||||
{orderAttachment ? (
|
{orderAttachment ? (
|
||||||
<div className="flex-row gap-2">
|
<div className="flex-row gap-2">
|
||||||
<span style={{ fontSize: "0.875rem" }}>
|
<span className="text-md">
|
||||||
{orderAttachment.name}{" "}
|
{orderAttachment.name}{" "}
|
||||||
<span className="text-tertiary">
|
<span className="text-tertiary">
|
||||||
({(orderAttachment.size / 1024).toFixed(0)} KB)
|
({(orderAttachment.size / 1024).toFixed(0)} KB)
|
||||||
|
|||||||
@@ -814,8 +814,8 @@ export default function Offers() {
|
|||||||
<tr>
|
<tr>
|
||||||
<td
|
<td
|
||||||
colSpan={8}
|
colSpan={8}
|
||||||
className="text-muted"
|
className="text-muted text-center"
|
||||||
style={{ textAlign: "center", padding: "1.5rem" }}
|
style={{ padding: "1.5rem" }}
|
||||||
>
|
>
|
||||||
Žádné nabídky odpovídající hledání.
|
Žádné nabídky odpovídající hledání.
|
||||||
</td>
|
</td>
|
||||||
@@ -879,8 +879,8 @@ export default function Offers() {
|
|||||||
<div className="admin-modal-header">
|
<div className="admin-modal-header">
|
||||||
<h2 className="admin-modal-title">Vytvořit objednávku</h2>
|
<h2 className="admin-modal-title">Vytvořit objednávku</h2>
|
||||||
<p
|
<p
|
||||||
className="text-secondary"
|
className="text-secondary text-md"
|
||||||
style={{ marginTop: "0.25rem", fontSize: "0.875rem" }}
|
style={{ marginTop: "0.25rem" }}
|
||||||
>
|
>
|
||||||
Nabídka:{" "}
|
Nabídka:{" "}
|
||||||
<strong>{orderModal.quotation?.quotation_number}</strong>
|
<strong>{orderModal.quotation?.quotation_number}</strong>
|
||||||
@@ -917,7 +917,7 @@ export default function Offers() {
|
|||||||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
|
<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" />
|
<polyline points="14 2 14 8 20 8" />
|
||||||
</svg>
|
</svg>
|
||||||
<span style={{ fontSize: "0.875rem" }}>
|
<span className="text-md">
|
||||||
{orderAttachment.name}{" "}
|
{orderAttachment.name}{" "}
|
||||||
<span className="text-tertiary">
|
<span className="text-tertiary">
|
||||||
({(orderAttachment.size / 1024).toFixed(0)} KB)
|
({(orderAttachment.size / 1024).toFixed(0)} KB)
|
||||||
@@ -944,11 +944,9 @@ export default function Offers() {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<label
|
<label
|
||||||
className="admin-btn admin-btn-secondary admin-btn-sm"
|
className="admin-btn admin-btn-secondary admin-btn-sm inline-flex"
|
||||||
style={{
|
style={{
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
display: "inline-flex",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: "0.4rem",
|
gap: "0.4rem",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ function formatCzkWithDetail(
|
|||||||
return { value: "0 Kč", detail: null };
|
return { value: "0 Kč", detail: null };
|
||||||
}
|
}
|
||||||
const hasForeign = amounts.some((a) => a.currency !== "CZK");
|
const hasForeign = amounts.some((a) => a.currency !== "CZK");
|
||||||
if (hasForeign && totalCzk !== null && totalCzk !== undefined) {
|
if (hasForeign && totalCzk != null) {
|
||||||
return {
|
return {
|
||||||
value: formatCurrency(totalCzk, "CZK"),
|
value: formatCurrency(totalCzk, "CZK"),
|
||||||
detail: formatMultiCurrency(amounts),
|
detail: formatMultiCurrency(amounts),
|
||||||
@@ -709,9 +709,9 @@ export default function ReceivedInvoices({
|
|||||||
<p>Žádné přijaté faktury v tomto měsíci.</p>
|
<p>Žádné přijaté faktury v tomto měsíci.</p>
|
||||||
{hasPermission("invoices.create") && (
|
{hasPermission("invoices.create") && (
|
||||||
<p
|
<p
|
||||||
|
className="text-md"
|
||||||
style={{
|
style={{
|
||||||
color: "var(--text-tertiary)",
|
color: "var(--text-tertiary)",
|
||||||
fontSize: "0.875rem",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Nahrajte faktury tlačítkem výše.
|
Nahrajte faktury tlačítkem výše.
|
||||||
@@ -780,7 +780,8 @@ export default function ReceivedInvoices({
|
|||||||
/>
|
/>
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
style={{ textAlign: "right", cursor: "pointer" }}
|
className="text-right"
|
||||||
|
style={{ cursor: "pointer" }}
|
||||||
onClick={() => handleSort("amount")}
|
onClick={() => handleSort("amount")}
|
||||||
>
|
>
|
||||||
Částka{" "}
|
Částka{" "}
|
||||||
@@ -959,9 +960,9 @@ export default function ReceivedInvoices({
|
|||||||
Vybrat soubory
|
Vybrat soubory
|
||||||
</button>
|
</button>
|
||||||
<span
|
<span
|
||||||
|
className="text-sm"
|
||||||
style={{
|
style={{
|
||||||
marginLeft: "0.75rem",
|
marginLeft: "0.75rem",
|
||||||
fontSize: "0.8125rem",
|
|
||||||
color: "var(--text-tertiary)",
|
color: "var(--text-tertiary)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -1106,8 +1107,8 @@ export default function ReceivedInvoices({
|
|||||||
</div>
|
</div>
|
||||||
{uploadMeta[idx]?.amount && (
|
{uploadMeta[idx]?.amount && (
|
||||||
<div
|
<div
|
||||||
|
className="text-xs"
|
||||||
style={{
|
style={{
|
||||||
fontSize: "0.75rem",
|
|
||||||
color: "var(--text-tertiary)",
|
color: "var(--text-tertiary)",
|
||||||
marginTop: "-0.25rem",
|
marginTop: "-0.25rem",
|
||||||
marginBottom: "0.5rem",
|
marginBottom: "0.5rem",
|
||||||
@@ -1320,8 +1321,8 @@ export default function ReceivedInvoices({
|
|||||||
</div>
|
</div>
|
||||||
{editInvoice.amount && (
|
{editInvoice.amount && (
|
||||||
<div
|
<div
|
||||||
|
className="text-xs"
|
||||||
style={{
|
style={{
|
||||||
fontSize: "0.75rem",
|
|
||||||
color: "var(--text-tertiary)",
|
color: "var(--text-tertiary)",
|
||||||
marginBottom: "0.75rem",
|
marginBottom: "0.75rem",
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -639,17 +639,16 @@ export default function Settings() {
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
|
className="fw-500 text-md"
|
||||||
style={{
|
style={{
|
||||||
fontWeight: 500,
|
|
||||||
color: "var(--text-primary)",
|
color: "var(--text-primary)",
|
||||||
fontSize: "0.875rem",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Povinné dvoufaktorové ověření (2FA)
|
Povinné dvoufaktorové ověření (2FA)
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
className="text-xs"
|
||||||
style={{
|
style={{
|
||||||
fontSize: "0.75rem",
|
|
||||||
color: "var(--text-secondary)",
|
color: "var(--text-secondary)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -781,16 +780,16 @@ export default function Settings() {
|
|||||||
<tr key={role.id}>
|
<tr key={role.id}>
|
||||||
<td>
|
<td>
|
||||||
<div
|
<div
|
||||||
|
className="fw-500"
|
||||||
style={{
|
style={{
|
||||||
fontWeight: 500,
|
|
||||||
color: "var(--text-primary)",
|
color: "var(--text-primary)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{role.display_name}
|
{role.display_name}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
className="text-xs"
|
||||||
style={{
|
style={{
|
||||||
fontSize: "0.75rem",
|
|
||||||
color: "var(--text-tertiary)",
|
color: "var(--text-tertiary)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -1077,9 +1076,9 @@ export default function Settings() {
|
|||||||
/>
|
/>
|
||||||
</FormField>
|
</FormField>
|
||||||
<small
|
<small
|
||||||
|
className="text-xs"
|
||||||
style={{
|
style={{
|
||||||
color: "var(--text-tertiary)",
|
color: "var(--text-tertiary)",
|
||||||
fontSize: "0.75rem",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Změna se projeví po restartu serveru
|
Změna se projeví po restartu serveru
|
||||||
@@ -1179,10 +1178,9 @@ export default function Settings() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<div
|
<div
|
||||||
|
className="fw-600 text-md"
|
||||||
style={{
|
style={{
|
||||||
fontWeight: 600,
|
|
||||||
marginBottom: "0.5rem",
|
marginBottom: "0.5rem",
|
||||||
fontSize: "0.875rem",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{cfg.label}
|
{cfg.label}
|
||||||
@@ -1355,8 +1353,8 @@ export default function Settings() {
|
|||||||
<div className="admin-card-body">
|
<div className="admin-card-body">
|
||||||
{systemInfo ? (
|
{systemInfo ? (
|
||||||
<table
|
<table
|
||||||
|
className="w-full"
|
||||||
style={{
|
style={{
|
||||||
width: "100%",
|
|
||||||
fontSize: "0.85rem",
|
fontSize: "0.85rem",
|
||||||
borderCollapse: "collapse",
|
borderCollapse: "collapse",
|
||||||
}}
|
}}
|
||||||
@@ -1374,16 +1372,16 @@ export default function Settings() {
|
|||||||
).map(([label, val]) => (
|
).map(([label, val]) => (
|
||||||
<tr key={label}>
|
<tr key={label}>
|
||||||
<td
|
<td
|
||||||
|
className="whitespace-nowrap"
|
||||||
style={{
|
style={{
|
||||||
padding: "6px 12px 6px 0",
|
padding: "6px 12px 6px 0",
|
||||||
color: "var(--text-secondary)",
|
color: "var(--text-secondary)",
|
||||||
whiteSpace: "nowrap",
|
|
||||||
width: 160,
|
width: 160,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
</td>
|
</td>
|
||||||
<td style={{ padding: "6px 0", fontWeight: 500 }}>
|
<td className="fw-500" style={{ padding: "6px 0" }}>
|
||||||
{val}
|
{val}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -1516,9 +1514,9 @@ export default function Settings() {
|
|||||||
</span>
|
</span>
|
||||||
{info?.configured && (
|
{info?.configured && (
|
||||||
<span
|
<span
|
||||||
|
className="text-xs"
|
||||||
style={{
|
style={{
|
||||||
marginLeft: 8,
|
marginLeft: 8,
|
||||||
fontSize: "0.75rem",
|
|
||||||
color: "var(--text-tertiary)",
|
color: "var(--text-tertiary)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -1548,8 +1546,7 @@ export default function Settings() {
|
|||||||
<button
|
<button
|
||||||
onClick={handleSaveSystemSettings}
|
onClick={handleSaveSystemSettings}
|
||||||
disabled={sysSettingsSaving}
|
disabled={sysSettingsSaving}
|
||||||
className="admin-btn admin-btn-primary"
|
className="admin-btn admin-btn-primary w-full"
|
||||||
style={{ width: "100%" }}
|
|
||||||
>
|
>
|
||||||
{sysSettingsSaving ? (
|
{sysSettingsSaving ? (
|
||||||
<>
|
<>
|
||||||
@@ -1637,9 +1634,9 @@ export default function Settings() {
|
|||||||
/>
|
/>
|
||||||
{!editingRole && (
|
{!editingRole && (
|
||||||
<small
|
<small
|
||||||
|
className="text-xs"
|
||||||
style={{
|
style={{
|
||||||
color: "var(--text-tertiary)",
|
color: "var(--text-tertiary)",
|
||||||
fontSize: "0.75rem",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Pouze malá písmena, čísla a pomlčky. Nelze později
|
Pouze malá písmena, čísla a pomlčky. Nelze později
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ export default function TripsAdmin() {
|
|||||||
try {
|
try {
|
||||||
const [vRes, uRes, csRes] = await Promise.all([
|
const [vRes, uRes, csRes] = await Promise.all([
|
||||||
apiFetch(`${API_BASE}/vehicles`),
|
apiFetch(`${API_BASE}/vehicles`),
|
||||||
apiFetch(`${API_BASE}/users?limit=1000`),
|
apiFetch(`${API_BASE}/trips/users`),
|
||||||
apiFetch(`${API_BASE}/company-settings`),
|
apiFetch(`${API_BASE}/company-settings`),
|
||||||
]);
|
]);
|
||||||
const vJson = await vRes.json();
|
const vJson = await vRes.json();
|
||||||
@@ -136,14 +136,7 @@ export default function TripsAdmin() {
|
|||||||
if (vJson.success) setVehicles(vJson.data);
|
if (vJson.success) setVehicles(vJson.data);
|
||||||
if (csJson.success) setCompanyName(csJson.data.company_name || "");
|
if (csJson.success) setCompanyName(csJson.data.company_name || "");
|
||||||
if (uJson.success) {
|
if (uJson.success) {
|
||||||
setUsers(
|
setUsers(uJson.data);
|
||||||
uJson.data.map(
|
|
||||||
(u: { id: number; first_name: string; last_name: string }) => ({
|
|
||||||
id: u.id,
|
|
||||||
name: `${u.first_name} ${u.last_name}`,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// silently fail, filters will just be empty
|
// silently fail, filters will just be empty
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { FastifyInstance } from "fastify";
|
import { FastifyInstance } from "fastify";
|
||||||
|
import prisma from "../../config/database";
|
||||||
import { requireAuth, requirePermission } from "../../middleware/auth";
|
import { requireAuth, requirePermission } from "../../middleware/auth";
|
||||||
import { logAudit } from "../../services/audit";
|
import { logAudit } from "../../services/audit";
|
||||||
import { success, error, parseId } from "../../utils/response";
|
import { success, error, parseId } from "../../utils/response";
|
||||||
@@ -132,6 +133,38 @@ export default async function attendanceRoutes(
|
|||||||
return reply.send({ success: true, data });
|
return reply.send({ success: true, data });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- action=attendance_users: users with attendance.record permission ---
|
||||||
|
if (action === "attendance_users") {
|
||||||
|
const users = await prisma.users.findMany({
|
||||||
|
where: {
|
||||||
|
is_active: true,
|
||||||
|
roles: {
|
||||||
|
is: {
|
||||||
|
OR: [
|
||||||
|
{ name: "admin" },
|
||||||
|
{
|
||||||
|
role_permissions: {
|
||||||
|
some: { permissions: { name: "attendance.record" } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: { id: true, first_name: true, last_name: true, username: true },
|
||||||
|
orderBy: { last_name: "asc" },
|
||||||
|
});
|
||||||
|
return reply.send({
|
||||||
|
success: true,
|
||||||
|
data: users.map((u) => ({
|
||||||
|
id: u.id,
|
||||||
|
first_name: u.first_name,
|
||||||
|
last_name: u.last_name,
|
||||||
|
username: u.username,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// --- action=projects: active projects for attendance project switching ---
|
// --- action=projects: active projects for attendance project switching ---
|
||||||
if (action === "projects") {
|
if (action === "projects") {
|
||||||
const data = await attendanceService.getActiveProjects();
|
const data = await attendanceService.getActiveProjects();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import prisma from "../../config/database";
|
|||||||
import { requireAuth } from "../../middleware/auth";
|
import { requireAuth } from "../../middleware/auth";
|
||||||
import { success } from "../../utils/response";
|
import { success } from "../../utils/response";
|
||||||
import { localTimeStr } from "../../utils/date";
|
import { localTimeStr } from "../../utils/date";
|
||||||
|
import { toCzk } from "../../services/exchange-rates";
|
||||||
|
|
||||||
export default async function dashboardRoutes(
|
export default async function dashboardRoutes(
|
||||||
fastify: FastifyInstance,
|
fastify: FastifyInstance,
|
||||||
@@ -141,8 +142,8 @@ export default async function dashboardRoutes(
|
|||||||
const [openCount, convertedCount, expiredCount, createdThisMonth] =
|
const [openCount, convertedCount, expiredCount, createdThisMonth] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
prisma.quotations.count({ where: { status: "active" } }),
|
prisma.quotations.count({ where: { status: "active" } }),
|
||||||
prisma.quotations.count({ where: { status: "converted" } }),
|
prisma.quotations.count({ where: { status: "ordered" } }),
|
||||||
prisma.quotations.count({ where: { status: "expired" } }),
|
prisma.quotations.count({ where: { status: "invalidated" } }),
|
||||||
prisma.quotations.count({
|
prisma.quotations.count({
|
||||||
where: { created_at: { gte: monthStart, lt: monthEnd } },
|
where: { created_at: { gte: monthStart, lt: monthEnd } },
|
||||||
}),
|
}),
|
||||||
@@ -206,10 +207,13 @@ export default async function dashboardRoutes(
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
unpaid_count: unpaidCount,
|
unpaid_count: unpaidCount,
|
||||||
revenue_czk:
|
revenue_czk: await (async () => {
|
||||||
revenueByCurrency["CZK"] != null
|
let total = 0;
|
||||||
? Math.round(revenueByCurrency["CZK"] * 100) / 100
|
for (const [cur, amount] of Object.entries(revenueByCurrency)) {
|
||||||
: null,
|
total += await toCzk(Math.round(amount * 100) / 100, cur);
|
||||||
|
}
|
||||||
|
return Math.round(total * 100) / 100;
|
||||||
|
})(),
|
||||||
};
|
};
|
||||||
result.unpaid_invoices = unpaidCount;
|
result.unpaid_invoices = unpaidCount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { requirePermission } from "../../middleware/auth";
|
|||||||
import { localDateCzStr } from "../../utils/date";
|
import { localDateCzStr } from "../../utils/date";
|
||||||
import { nasFinancialsManager } from "../../services/nas-financials-manager";
|
import { nasFinancialsManager } from "../../services/nas-financials-manager";
|
||||||
import { htmlToPdf } from "../../utils/html-to-pdf";
|
import { htmlToPdf } from "../../utils/html-to-pdf";
|
||||||
|
import { getRate } from "../../services/exchange-rates";
|
||||||
|
import { localDateStr } from "../../utils/date";
|
||||||
|
|
||||||
/* ── Helpers ─────────────────────────────────────────────────────── */
|
/* ── Helpers ─────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
@@ -282,6 +284,7 @@ export default async function invoicesPdfRoutes(
|
|||||||
> | null;
|
> | null;
|
||||||
|
|
||||||
let orderNumber = "";
|
let orderNumber = "";
|
||||||
|
let orderDate = "";
|
||||||
if (invoice.order_id) {
|
if (invoice.order_id) {
|
||||||
const orderRow = await prisma.orders.findUnique({
|
const orderRow = await prisma.orders.findUnique({
|
||||||
where: { id: invoice.order_id },
|
where: { id: invoice.order_id },
|
||||||
@@ -297,6 +300,9 @@ export default async function invoicesPdfRoutes(
|
|||||||
orderRow.customer_order_number || orderRow.order_number || "",
|
orderRow.customer_order_number || orderRow.order_number || "",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
if (orderRow.created_at) {
|
||||||
|
orderDate = formatDate(orderRow.created_at);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,9 +364,12 @@ export default async function invoicesPdfRoutes(
|
|||||||
// QR generation failed — leave empty
|
// QR generation failed — leave empty
|
||||||
}
|
}
|
||||||
|
|
||||||
// VAT recapitulation (always in CZK)
|
// VAT recapitulation (always in CZK — Czech tax requirement)
|
||||||
const isForeign = currency.toUpperCase() !== "CZK";
|
const isForeign = currency.toUpperCase() !== "CZK";
|
||||||
const cnbRate = 1.0; // Skip CNB rate conversion
|
const issueDateStr = invoice.issue_date
|
||||||
|
? localDateStr(new Date(invoice.issue_date))
|
||||||
|
: undefined;
|
||||||
|
const cnbRate = isForeign ? await getRate(currency, issueDateStr) : 1.0;
|
||||||
const vatRates = [21, 12, 0];
|
const vatRates = [21, 12, 0];
|
||||||
const vatRecap: Array<{
|
const vatRecap: Array<{
|
||||||
rate: number;
|
rate: number;
|
||||||
@@ -422,7 +431,7 @@ export default async function invoicesPdfRoutes(
|
|||||||
return `<tr>
|
return `<tr>
|
||||||
<td class="row-num">${i + 1}</td>
|
<td class="row-num">${i + 1}</td>
|
||||||
<td class="desc">${escapeHtml(item.description)}</td>
|
<td class="desc">${escapeHtml(item.description)}</td>
|
||||||
<td class="center">${formatNum(qty, qtyDecimals)}</td>
|
<td class="center">${formatNum(qty, qtyDecimals)}${item.unit ? ` / ${escapeHtml(item.unit)}` : ""}</td>
|
||||||
<td class="right">${formatNum(unitPrice)}</td>
|
<td class="right">${formatNum(unitPrice)}</td>
|
||||||
<td class="right">${formatNum(lineSubtotal)}</td>
|
<td class="right">${formatNum(lineSubtotal)}</td>
|
||||||
<td class="center">${applyVat ? Math.floor(vatRate) : 0}%</td>
|
<td class="center">${applyVat ? Math.floor(vatRate) : 0}%</td>
|
||||||
@@ -486,14 +495,14 @@ export default async function invoicesPdfRoutes(
|
|||||||
<style>
|
<style>
|
||||||
@page {
|
@page {
|
||||||
size: A4;
|
size: A4;
|
||||||
margin: 12mm 15mm 15mm 15mm;
|
margin: 8mm 12mm 10mm 12mm;
|
||||||
}
|
}
|
||||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
html, body {
|
html, body {
|
||||||
font-family: "Segoe UI", Tahoma, Arial, sans-serif;
|
font-family: "Segoe UI", Tahoma, Arial, sans-serif;
|
||||||
font-size: 9pt;
|
font-size: 10pt;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
width: 180mm;
|
width: 186mm;
|
||||||
}
|
}
|
||||||
|
|
||||||
.invoice-page {
|
.invoice-page {
|
||||||
@@ -504,82 +513,35 @@ export default async function invoicesPdfRoutes(
|
|||||||
.invoice-content { flex: 1 1 auto; }
|
.invoice-content { flex: 1 1 auto; }
|
||||||
.invoice-footer {
|
.invoice-footer {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
page-break-inside: avoid;
|
|
||||||
break-inside: avoid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.accent { color: #de3a3a; }
|
.accent { color: #de3a3a; }
|
||||||
|
|
||||||
/* Hlavicka */
|
/* ── Hlavicka ── */
|
||||||
.invoice-header {
|
.invoice-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: flex-start;
|
align-items: center;
|
||||||
margin-bottom: 0;
|
margin-bottom: 1mm;
|
||||||
padding-bottom: 1mm;
|
padding-bottom: 1mm;
|
||||||
|
border-bottom: 2pt solid #de3a3a;
|
||||||
}
|
}
|
||||||
.invoice-header .left {
|
.invoice-header .left {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-start;
|
align-items: center;
|
||||||
gap: 3mm;
|
gap: 3mm;
|
||||||
}
|
}
|
||||||
.logo-header {
|
.logo-header { text-align: left; }
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
.company-title {
|
.company-title {
|
||||||
font-size: 12pt;
|
font-size: 12pt;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
margin-top: 2mm;
|
|
||||||
}
|
}
|
||||||
.invoice-title {
|
.invoice-title {
|
||||||
font-size: 10pt;
|
font-size: 13pt;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: #de3a3a;
|
color: #de3a3a;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
margin-top: 2mm;
|
letter-spacing: 0.03em;
|
||||||
}
|
|
||||||
|
|
||||||
/* Adresy - dva sloupce, stejna vyska */
|
|
||||||
.addresses-row {
|
|
||||||
display: flex;
|
|
||||||
gap: 8mm;
|
|
||||||
align-items: stretch;
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
.addresses-row .address-block {
|
|
||||||
flex: 1;
|
|
||||||
padding-bottom: 2mm;
|
|
||||||
border-bottom: 0.5pt solid #e0e0e0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Detaily pod adresami */
|
|
||||||
.details-row {
|
|
||||||
display: flex;
|
|
||||||
gap: 8mm;
|
|
||||||
margin-bottom: 3mm;
|
|
||||||
}
|
|
||||||
.details-row .col { flex: 1; }
|
|
||||||
|
|
||||||
/* Adresy - styl z nabidek */
|
|
||||||
.address-block {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
.address-label {
|
|
||||||
font-size: 8pt;
|
|
||||||
font-weight: 600;
|
|
||||||
color: #646464;
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
.address-name {
|
|
||||||
font-size: 9pt;
|
|
||||||
font-weight: 700;
|
|
||||||
color: #1a1a1a;
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
.address-line {
|
|
||||||
font-size: 8.5pt;
|
|
||||||
color: #1a1a1a;
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo {
|
.logo {
|
||||||
@@ -588,74 +550,87 @@ export default async function invoicesPdfRoutes(
|
|||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Separator */
|
/* ── Adresy ── */
|
||||||
.header-separator {
|
.header-grid {
|
||||||
border: none;
|
border: 0.5pt solid #d0d0d0;
|
||||||
border-top: 0.5pt solid #e0e0e0;
|
border-collapse: collapse;
|
||||||
margin: 2mm 0 3mm 0;
|
width: 100%;
|
||||||
|
margin-bottom: 1mm;
|
||||||
}
|
}
|
||||||
|
.header-grid td {
|
||||||
/* Banka */
|
padding: 2mm 3mm;
|
||||||
.bank-box {
|
border: 0.5pt solid #d0d0d0;
|
||||||
|
vertical-align: top;
|
||||||
|
width: 50%;
|
||||||
|
}
|
||||||
|
.header-grid td.addr-customer {
|
||||||
|
background: #f5f5f5;
|
||||||
|
}
|
||||||
|
.header-grid td.details-bank {
|
||||||
|
background: #f5f5f5;
|
||||||
|
}
|
||||||
|
.address-label {
|
||||||
font-size: 8pt;
|
font-size: 8pt;
|
||||||
line-height: 1.4;
|
font-weight: 700;
|
||||||
padding-top: 2mm;
|
color: #de3a3a;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
margin-bottom: 1mm;
|
||||||
}
|
}
|
||||||
.bank-box .lbl {
|
.address-name {
|
||||||
font-weight: 600;
|
font-size: 10pt;
|
||||||
|
font-weight: 700;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
display: inline-block;
|
line-height: 1.3;
|
||||||
min-width: 16mm;
|
margin-bottom: 1mm;
|
||||||
|
}
|
||||||
|
.address-line {
|
||||||
|
font-size: 9pt;
|
||||||
|
color: #444;
|
||||||
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Datumy */
|
/* ── Detaily (banka + datumy) — inside header-grid ── */
|
||||||
.dates-box {
|
|
||||||
font-size: 8pt;
|
.info-row {
|
||||||
line-height: 1.4;
|
|
||||||
padding-top: 2mm;
|
|
||||||
}
|
|
||||||
.dates-row {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: baseline;
|
||||||
margin-bottom: 0.5mm;
|
font-size: 9pt;
|
||||||
|
padding: 1mm 0;
|
||||||
|
border-bottom: 0.5pt solid #f0f0f0;
|
||||||
}
|
}
|
||||||
.dates-row .lbl {
|
.info-row:last-child { border-bottom: none; }
|
||||||
flex: 1;
|
.info-row .lbl {
|
||||||
color: #1a1a1a;
|
color: #666;
|
||||||
|
font-weight: 400;
|
||||||
|
flex-shrink: 0;
|
||||||
|
white-space: nowrap;
|
||||||
|
margin-right: 3mm;
|
||||||
}
|
}
|
||||||
.dates-row .val {
|
.info-row .val {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
min-width: 22mm;
|
color: #1a1a1a;
|
||||||
text-align: center;
|
text-align: right;
|
||||||
padding: 0.5mm 2mm;
|
margin-left: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* VS/KS blok */
|
/* VS/KS blok */
|
||||||
.vs-block {
|
.vs-block {
|
||||||
font-size: 8pt;
|
font-size: 9pt;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
padding-top: 2mm;
|
padding-top: 2mm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Konecny prijemce */
|
/* ── Polozky ── */
|
||||||
.recipient-box {
|
|
||||||
font-size: 8pt;
|
|
||||||
margin-top: 2mm;
|
|
||||||
padding-top: 2mm;
|
|
||||||
border-top: 0.5pt solid #e0e0e0;
|
|
||||||
}
|
|
||||||
.recipient-box .lbl {
|
|
||||||
font-weight: 600;
|
|
||||||
font-style: italic;
|
|
||||||
color: #646464;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Polozky tabulka - styl z nabidek */
|
|
||||||
.billing-label {
|
.billing-label {
|
||||||
font-weight: 600;
|
font-weight: 700;
|
||||||
color: #de3a3a;
|
color: #1a1a1a;
|
||||||
font-size: 8.5pt;
|
font-size: 10pt;
|
||||||
padding: 3px 5px;
|
padding: 2mm 0 1mm 0;
|
||||||
|
border-bottom: 1.5pt solid #de3a3a;
|
||||||
|
margin-bottom: 0;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.03em;
|
||||||
}
|
}
|
||||||
|
|
||||||
table.items {
|
table.items {
|
||||||
@@ -666,20 +641,18 @@ export default async function invoicesPdfRoutes(
|
|||||||
margin-bottom: 2mm;
|
margin-bottom: 2mm;
|
||||||
}
|
}
|
||||||
table.items thead th {
|
table.items thead th {
|
||||||
font-size: 8pt;
|
font-size: 8.5pt;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #646464;
|
color: #646464;
|
||||||
padding: 6px 8px;
|
padding: 4px 4px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
letter-spacing: 0.02em;
|
border-bottom: 0.5pt solid #d0d0d0;
|
||||||
text-transform: uppercase;
|
|
||||||
border-bottom: 1pt solid #1a1a1a;
|
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
table.items thead th.center { text-align: center; }
|
table.items thead th.center { text-align: center; }
|
||||||
table.items thead th.right { text-align: right; }
|
table.items thead th.right { text-align: right; }
|
||||||
table.items tbody td {
|
table.items tbody td {
|
||||||
padding: 5px 8px;
|
padding: 4px 4px;
|
||||||
border-bottom: 0.5pt solid #e0e0e0;
|
border-bottom: 0.5pt solid #e0e0e0;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
@@ -690,11 +663,11 @@ export default async function invoicesPdfRoutes(
|
|||||||
table.items tbody td.row-num {
|
table.items tbody td.row-num {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #969696;
|
color: #969696;
|
||||||
font-size: 8pt;
|
font-size: 9pt;
|
||||||
}
|
}
|
||||||
table.items tbody td.desc {
|
table.items tbody td.desc {
|
||||||
font-size: 9.5pt;
|
font-size: 9pt;
|
||||||
font-weight: 500;
|
font-weight: 600;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
}
|
}
|
||||||
table.items tbody td.total-cell { font-weight: 700; }
|
table.items tbody td.total-cell { font-weight: 700; }
|
||||||
@@ -715,7 +688,7 @@ export default async function invoicesPdfRoutes(
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
font-size: 8.5pt;
|
font-size: 9.5pt;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
margin-bottom: 2mm;
|
margin-bottom: 2mm;
|
||||||
}
|
}
|
||||||
@@ -727,7 +700,7 @@ export default async function invoicesPdfRoutes(
|
|||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
}
|
}
|
||||||
.totals .grand .label {
|
.totals .grand .label {
|
||||||
font-size: 9.5pt;
|
font-size: 10.5pt;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
align-self: center;
|
align-self: center;
|
||||||
@@ -741,14 +714,14 @@ export default async function invoicesPdfRoutes(
|
|||||||
}
|
}
|
||||||
.totals .currency-note {
|
.totals .currency-note {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
font-size: 7.5pt;
|
font-size: 8pt;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
margin-top: 2mm;
|
margin-top: 2mm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Vystavil */
|
/* Vystavil */
|
||||||
.issued-by {
|
.issued-by {
|
||||||
font-size: 8pt;
|
font-size: 9pt;
|
||||||
margin: 2mm 0;
|
margin: 2mm 0;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
}
|
}
|
||||||
@@ -756,7 +729,7 @@ export default async function invoicesPdfRoutes(
|
|||||||
|
|
||||||
/* Upozorneni */
|
/* Upozorneni */
|
||||||
.notice {
|
.notice {
|
||||||
font-size: 7pt;
|
font-size: 8pt;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
margin: 2mm 0;
|
margin: 2mm 0;
|
||||||
line-height: 1.3;
|
line-height: 1.3;
|
||||||
@@ -778,11 +751,11 @@ export default async function invoicesPdfRoutes(
|
|||||||
|
|
||||||
.recap-section table {
|
.recap-section table {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
font-size: 8pt;
|
font-size: 9pt;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
.recap-section table th {
|
.recap-section table th {
|
||||||
font-size: 7.5pt;
|
font-size: 8pt;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #555;
|
color: #555;
|
||||||
padding: 3px 6px;
|
padding: 3px 6px;
|
||||||
@@ -796,7 +769,7 @@ export default async function invoicesPdfRoutes(
|
|||||||
}
|
}
|
||||||
.recap-section table td.center { text-align: center; }
|
.recap-section table td.center { text-align: center; }
|
||||||
.recap-section table td.cnb-rate {
|
.recap-section table td.cnb-rate {
|
||||||
font-size: 7pt;
|
font-size: 8pt;
|
||||||
color: #888;
|
color: #888;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
@@ -806,13 +779,14 @@ export default async function invoicesPdfRoutes(
|
|||||||
/* Prevzal / razitko */
|
/* Prevzal / razitko */
|
||||||
.footer-row {
|
.footer-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
margin-top: 4mm;
|
margin-top: 4mm;
|
||||||
font-size: 8pt;
|
font-size: 9pt;
|
||||||
}
|
|
||||||
.footer-row .col {
|
|
||||||
flex: 1;
|
|
||||||
border-top: 0.5pt solid #aaa;
|
border-top: 0.5pt solid #aaa;
|
||||||
padding-top: 2mm;
|
padding-top: 2mm;
|
||||||
|
min-height: 15mm;
|
||||||
|
}
|
||||||
|
.footer-row .col {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #555;
|
color: #555;
|
||||||
}
|
}
|
||||||
@@ -820,13 +794,13 @@ export default async function invoicesPdfRoutes(
|
|||||||
/* Poznamky */
|
/* Poznamky */
|
||||||
.invoice-notes {
|
.invoice-notes {
|
||||||
margin-top: 4mm;
|
margin-top: 4mm;
|
||||||
font-size: 9pt;
|
font-size: 10pt;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
}
|
}
|
||||||
.invoice-notes-label {
|
.invoice-notes-label {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
font-size: 8pt;
|
font-size: 9pt;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
color: #555;
|
color: #555;
|
||||||
margin-bottom: 1mm;
|
margin-bottom: 1mm;
|
||||||
@@ -893,59 +867,54 @@ ${indentCSS}
|
|||||||
<div class="invoice-title">${escapeHtml(t.heading)} ${invoiceNumber}</div>
|
<div class="invoice-title">${escapeHtml(t.heading)} ${invoiceNumber}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="header-separator" />
|
<!-- Dodavatel / Odberatel + Banka / Datumy -->
|
||||||
|
<table class="header-grid" cellspacing="0">
|
||||||
<!-- Dodavatel / Odberatel - stejna vyska -->
|
<tr>
|
||||||
<div class="addresses-row">
|
<td>
|
||||||
<div class="address-block">
|
<div class="address-label">${escapeHtml(t.supplier)}</div>
|
||||||
<div class="address-label">${escapeHtml(t.supplier)}</div>
|
<div class="address-name">${escapeHtml(supp.name)}</div>
|
||||||
<div class="address-name">${escapeHtml(supp.name)}</div>
|
${suppLinesHtml}
|
||||||
${suppLinesHtml}
|
</td>
|
||||||
</div>
|
<td class="addr-customer">
|
||||||
<div class="address-block">
|
<div class="address-label">${escapeHtml(t.customer)}</div>
|
||||||
<div class="address-label">${escapeHtml(t.customer)}</div>
|
<div class="address-name">${escapeHtml(cust.name)}</div>
|
||||||
<div class="address-name">${escapeHtml(cust.name)}</div>
|
${custLinesHtml}
|
||||||
${custLinesHtml}
|
</td>
|
||||||
</div>
|
</tr>
|
||||||
</div>
|
<tr>
|
||||||
|
<td class="details-bank">
|
||||||
<!-- Banka + VS / Datumy -->
|
<div class="info-row"><span class="lbl">${escapeHtml(t.bank)}</span> <span class="val">${escapeHtml(invoice.bank_name)}</span></div>
|
||||||
<div class="details-row">
|
<div class="info-row"><span class="lbl">${escapeHtml(t.swift)}</span> <span class="val">${escapeHtml(invoice.bank_swift)}</span></div>
|
||||||
<div class="col">
|
<div class="info-row"><span class="lbl">${escapeHtml(t.iban)}</span> <span class="val">${escapeHtml(invoice.bank_iban)}</span></div>
|
||||||
<div class="bank-box">
|
<div class="info-row"><span class="lbl">${escapeHtml(t.account_no)}</span> <span class="val">${escapeHtml(invoice.bank_account)}</span></div>
|
||||||
<span class="lbl">${escapeHtml(t.bank)}</span> ${escapeHtml(invoice.bank_name)}<br>
|
<div class="vs-block">
|
||||||
<span class="lbl">${escapeHtml(t.swift)}</span> ${escapeHtml(invoice.bank_swift)}<br>
|
${escapeHtml(t.var_symbol)} <strong>${invoiceNumber}</strong>
|
||||||
<span class="lbl">${escapeHtml(t.iban)}</span> ${escapeHtml(invoice.bank_iban)}<br>
|
${escapeHtml(t.const_symbol)} <strong>${escapeHtml(invoice.constant_symbol)}</strong>
|
||||||
<span class="lbl">${escapeHtml(t.account_no)}</span> ${escapeHtml(invoice.bank_account)}
|
</div>
|
||||||
</div>
|
</td>
|
||||||
<div class="vs-block">
|
<td>
|
||||||
${escapeHtml(t.var_symbol)} <strong>${invoiceNumber}</strong>
|
<div class="info-row"><span class="lbl">${escapeHtml(t.issue_date)}</span> <span class="val">${escapeHtml(formatDate(invoice.issue_date))}</span></div>
|
||||||
${escapeHtml(t.const_symbol)} <strong>${escapeHtml(invoice.constant_symbol)}</strong><br>
|
<div class="info-row"><span class="lbl">${escapeHtml(t.due_date)}</span> <span class="val">${escapeHtml(formatDate(invoice.due_date))}</span></div>
|
||||||
${orderNumber ? `${escapeHtml(t.order_no)} ${orderNumber}` : ""}
|
<div class="info-row"><span class="lbl">${escapeHtml(t.tax_date)}</span> <span class="val">${escapeHtml(formatDate(invoice.tax_date))}</span></div>
|
||||||
</div>
|
<div class="info-row"><span class="lbl">${escapeHtml(t.payment_method)}</span> <span class="val">${escapeHtml(invoice.payment_method)}</span></div>
|
||||||
</div>
|
${orderNumber ? `<div class="info-row"><span class="lbl">${lang === "cs" ? "Objednávka č.:" : "Order no.:"}</span> <span class="val">${orderNumber}</span></div>` : ""}
|
||||||
<div class="col">
|
${orderDate ? `<div class="info-row"><span class="lbl">${lang === "cs" ? "Objednávka ze dne:" : "Order date:"}</span> <span class="val">${escapeHtml(orderDate)}</span></div>` : ""}
|
||||||
<div class="dates-box">
|
</td>
|
||||||
<div class="dates-row"><span class="lbl">${escapeHtml(t.issue_date)}</span> <span class="val">${escapeHtml(formatDate(invoice.issue_date))}</span></div>
|
</tr>
|
||||||
<div class="dates-row"><span class="lbl">${escapeHtml(t.due_date)}</span> <span class="val">${escapeHtml(formatDate(invoice.due_date))}</span></div>
|
</table>
|
||||||
<div class="dates-row"><span class="lbl">${escapeHtml(t.tax_date)}</span> <span class="val">${escapeHtml(formatDate(invoice.tax_date))}</span></div>
|
|
||||||
<div class="dates-row"><span class="lbl">${escapeHtml(t.payment_method)}</span> <span class="val">${escapeHtml(invoice.payment_method)}</span></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Polozky -->
|
<!-- Polozky -->
|
||||||
<div class="billing-label">${escapeHtml(invoice.billing_text || t.billing)}</div>
|
<div class="billing-label">${escapeHtml(invoice.billing_text || t.billing)}</div>
|
||||||
<table class="items">
|
<table class="items">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="center" style="width:5%">${escapeHtml(t.col_no)}</th>
|
<th class="center" style="width:3%">${escapeHtml(t.col_no)}</th>
|
||||||
<th style="width:30%">${escapeHtml(t.col_desc)}</th>
|
<th style="width:36%">${escapeHtml(t.col_desc)}</th>
|
||||||
<th class="center" style="width:9%">${escapeHtml(t.col_qty)}</th>
|
<th class="center" style="width:10%">${escapeHtml(t.col_qty)}</th>
|
||||||
<th class="right" style="width:11%">${escapeHtml(t.col_unit_price)}</th>
|
<th class="right" style="width:10%">${escapeHtml(t.col_unit_price)}</th>
|
||||||
<th class="right" style="width:11%">${escapeHtml(t.col_price)}</th>
|
<th class="right" style="width:10%">${escapeHtml(t.col_price)}</th>
|
||||||
<th class="center" style="width:7%">${escapeHtml(t.col_vat_pct)}</th>
|
<th class="center" style="width:5%">${escapeHtml(t.col_vat_pct)}</th>
|
||||||
<th class="right" style="width:11%">${escapeHtml(t.col_vat)}</th>
|
<th class="right" style="width:10%">${escapeHtml(t.col_vat)}</th>
|
||||||
<th class="right" style="width:16%">${escapeHtml(t.col_total)}</th>
|
<th class="right" style="width:16%">${escapeHtml(t.col_total)}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -1007,6 +976,17 @@ ${indentCSS}
|
|||||||
<tbody>
|
<tbody>
|
||||||
${vatRecapHtml}
|
${vatRecapHtml}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
${
|
||||||
|
isForeign
|
||||||
|
? `<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" style="font-size:0.7em; color:#666; padding-top:6px; text-align:left;">
|
||||||
|
Přepočet kurzem ČNB ke dni ${formatDate(invoice.issue_date)}: 1 ${escapeHtml(currency)} = ${cnbRate.toFixed(3).replace(".", ",")} CZK
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1028,6 +1008,7 @@ ${indentCSS}
|
|||||||
? new Date(invoice.issue_date)
|
? new Date(invoice.issue_date)
|
||||||
: new Date();
|
: new Date();
|
||||||
const saveMode = query.save === "1";
|
const saveMode = query.save === "1";
|
||||||
|
nasFinancialsManager.cleanIssuedInvoice(invoice.invoice_number!);
|
||||||
const pdfPromise = htmlToPdf(html)
|
const pdfPromise = htmlToPdf(html)
|
||||||
.then((pdfBuffer) => {
|
.then((pdfBuffer) => {
|
||||||
nasFinancialsManager.saveIssuedInvoicePdf(
|
nasFinancialsManager.saveIssuedInvoicePdf(
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export default async function leaveRequestsRoutes(
|
|||||||
const isAdmin = authData.permissions.includes("attendance.approve");
|
const isAdmin = authData.permissions.includes("attendance.approve");
|
||||||
|
|
||||||
const where: Record<string, unknown> = {};
|
const where: Record<string, unknown> = {};
|
||||||
if (!isAdmin) where.user_id = authData.userId;
|
if (!isAdmin || query.mine === "1") where.user_id = authData.userId;
|
||||||
else if (query.user_id) where.user_id = Number(query.user_id);
|
else if (query.user_id) where.user_id = Number(query.user_id);
|
||||||
if (query.status) where.status = String(query.status);
|
if (query.status) where.status = String(query.status);
|
||||||
|
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ ${indentCSS}
|
|||||||
}
|
}
|
||||||
table.items tbody td.desc {
|
table.items tbody td.desc {
|
||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
font-weight: 500;
|
font-weight: 600;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
}
|
}
|
||||||
table.items tbody td.total-cell {
|
table.items tbody td.total-cell {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
UpdateReceivedInvoiceSchema,
|
UpdateReceivedInvoiceSchema,
|
||||||
} from "../../schemas/received-invoices.schema";
|
} from "../../schemas/received-invoices.schema";
|
||||||
import { nasFinancialsManager } from "../../services/nas-financials-manager";
|
import { nasFinancialsManager } from "../../services/nas-financials-manager";
|
||||||
|
import { toCzk } from "../../services/exchange-rates";
|
||||||
|
|
||||||
const VALID_STATUSES = ["unpaid", "paid"] as const;
|
const VALID_STATUSES = ["unpaid", "paid"] as const;
|
||||||
const ALLOWED_SORT_FIELDS = [
|
const ALLOWED_SORT_FIELDS = [
|
||||||
@@ -108,12 +109,15 @@ export default async function receivedInvoicesRoutes(
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const sumCzk = (
|
const sumCzk = async (
|
||||||
invs: typeof monthInvoices,
|
invs: typeof monthInvoices,
|
||||||
field: "amount" | "vat_amount",
|
field: "amount" | "vat_amount",
|
||||||
) => {
|
) => {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
for (const inv of invs) total += Number(inv[field]) || 0;
|
for (const inv of invs) {
|
||||||
|
const amount = Number(inv[field]) || 0;
|
||||||
|
total += await toCzk(amount, inv.currency);
|
||||||
|
}
|
||||||
return Math.round(total * 100) / 100;
|
return Math.round(total * 100) / 100;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -124,11 +128,11 @@ export default async function receivedInvoicesRoutes(
|
|||||||
|
|
||||||
return success(reply, {
|
return success(reply, {
|
||||||
total_month: aggregateByCurrency(monthInvoices, "amount"),
|
total_month: aggregateByCurrency(monthInvoices, "amount"),
|
||||||
total_month_czk: sumCzk(monthInvoices, "amount"),
|
total_month_czk: await sumCzk(monthInvoices, "amount"),
|
||||||
vat_month: aggregateByCurrency(monthInvoices, "vat_amount"),
|
vat_month: aggregateByCurrency(monthInvoices, "vat_amount"),
|
||||||
vat_month_czk: sumCzk(monthInvoices, "vat_amount"),
|
vat_month_czk: await sumCzk(monthInvoices, "vat_amount"),
|
||||||
unpaid: aggregateByCurrency(allUnpaid, "amount"),
|
unpaid: aggregateByCurrency(allUnpaid, "amount"),
|
||||||
unpaid_czk: sumCzk(allUnpaid, "amount"),
|
unpaid_czk: await sumCzk(allUnpaid, "amount"),
|
||||||
unpaid_count: allUnpaid.length,
|
unpaid_count: allUnpaid.length,
|
||||||
month_count: monthInvoices.length,
|
month_count: monthInvoices.length,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -66,6 +66,45 @@ export default async function tripsRoutes(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// GET /api/admin/trips/users — users with trips.record permission
|
||||||
|
fastify.get(
|
||||||
|
"/users",
|
||||||
|
{ preHandler: requireAuth },
|
||||||
|
async (_request, reply) => {
|
||||||
|
const users = await prisma.users.findMany({
|
||||||
|
where: {
|
||||||
|
is_active: true,
|
||||||
|
roles: {
|
||||||
|
is: {
|
||||||
|
OR: [
|
||||||
|
{ name: "admin" },
|
||||||
|
{
|
||||||
|
role_permissions: {
|
||||||
|
some: { permissions: { name: "trips.record" } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
first_name: true,
|
||||||
|
last_name: true,
|
||||||
|
username: true,
|
||||||
|
},
|
||||||
|
orderBy: { last_name: "asc" },
|
||||||
|
});
|
||||||
|
return success(
|
||||||
|
reply,
|
||||||
|
users.map((u) => ({
|
||||||
|
id: u.id,
|
||||||
|
name: `${u.first_name} ${u.last_name}`.trim() || u.username,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// GET /api/admin/trips/print — print data for trip report
|
// GET /api/admin/trips/print — print data for trip report
|
||||||
fastify.get(
|
fastify.get(
|
||||||
"/print",
|
"/print",
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ export const AttendanceBalancesSchema = z.object({
|
|||||||
|
|
||||||
export const AttendanceBulkSchema = z.object({
|
export const AttendanceBulkSchema = z.object({
|
||||||
month: z.string().regex(/^\d{4}-\d{2}$/, "Měsíc je povinný (formát YYYY-MM)"),
|
month: z.string().regex(/^\d{4}-\d{2}$/, "Měsíc je povinný (formát YYYY-MM)"),
|
||||||
user_ids: z.array(z.number()).min(1, "Vyberte alespoň jednoho zaměstnance"),
|
user_ids: z
|
||||||
|
.array(z.union([z.number(), z.string()]).transform((v) => Number(v)))
|
||||||
|
.min(1, "Vyberte alespoň jednoho zaměstnance"),
|
||||||
arrival_time: z.string().optional().default("08:00"),
|
arrival_time: z.string().optional().default("08:00"),
|
||||||
departure_time: z.string().optional().default("16:30"),
|
departure_time: z.string().optional().default("16:30"),
|
||||||
break_start_time: z.string().optional().default("12:00"),
|
break_start_time: z.string().optional().default("12:00"),
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ export const CreateUserSchema = z.object({
|
|||||||
export const UpdateUserSchema = z.object({
|
export const UpdateUserSchema = z.object({
|
||||||
username: z.string().optional(),
|
username: z.string().optional(),
|
||||||
email: z.string().email("Neplatný formát e-mailu").optional(),
|
email: z.string().email("Neplatný formát e-mailu").optional(),
|
||||||
password: z.string().min(8, "Heslo musí mít alespoň 8 znaků").optional(),
|
password: z.preprocess(
|
||||||
|
(v) => (v === "" ? undefined : v),
|
||||||
|
z.string().min(8, "Heslo musí mít alespoň 8 znaků").optional(),
|
||||||
|
),
|
||||||
first_name: z.string().optional(),
|
first_name: z.string().optional(),
|
||||||
last_name: z.string().optional(),
|
last_name: z.string().optional(),
|
||||||
role_id: z.union([z.number(), z.string(), z.null()]).optional(),
|
role_id: z.union([z.number(), z.string(), z.null()]).optional(),
|
||||||
|
|||||||
@@ -1,9 +1,32 @@
|
|||||||
import { attendance_leave_type, Prisma } from "@prisma/client";
|
import { attendance_leave_type, Prisma } from "@prisma/client";
|
||||||
import prisma from "../config/database";
|
import prisma from "../config/database";
|
||||||
import { getBusinessDaysInMonth } from "../utils/czech-holidays";
|
import { getBusinessDaysInMonth, isHoliday } from "../utils/czech-holidays";
|
||||||
import { localDateStr } from "../utils/date";
|
import { localDateStr } from "../utils/date";
|
||||||
import { getSystemSettings } from "./system-settings";
|
import { getSystemSettings } from "./system-settings";
|
||||||
|
|
||||||
|
/** Get active users whose role has attendance.record permission (or admin role) */
|
||||||
|
async function getAttendanceUsers() {
|
||||||
|
return prisma.users.findMany({
|
||||||
|
where: {
|
||||||
|
is_active: true,
|
||||||
|
roles: {
|
||||||
|
is: {
|
||||||
|
OR: [
|
||||||
|
{ name: "admin" },
|
||||||
|
{
|
||||||
|
role_permissions: {
|
||||||
|
some: { permissions: { name: "attendance.record" } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: { id: true, first_name: true, last_name: true },
|
||||||
|
orderBy: { last_name: "asc" },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
type AttendanceWithRelations = Prisma.attendanceGetPayload<{
|
type AttendanceWithRelations = Prisma.attendanceGetPayload<{
|
||||||
include: {
|
include: {
|
||||||
users: { select: { id: true; first_name: true; last_name: true } };
|
users: { select: { id: true; first_name: true; last_name: true } };
|
||||||
@@ -421,11 +444,7 @@ export async function switchProject(userId: number, projectId: number | null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getBalances(year: number) {
|
export async function getBalances(year: number) {
|
||||||
const users = await prisma.users.findMany({
|
const users = await getAttendanceUsers();
|
||||||
where: { is_active: true },
|
|
||||||
select: { id: true, first_name: true, last_name: true },
|
|
||||||
orderBy: { last_name: "asc" },
|
|
||||||
});
|
|
||||||
|
|
||||||
const balances: Record<
|
const balances: Record<
|
||||||
string,
|
string,
|
||||||
@@ -463,11 +482,7 @@ export async function getBalances(year: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getWorkfund(year: number) {
|
export async function getWorkfund(year: number) {
|
||||||
const users = await prisma.users.findMany({
|
const users = await getAttendanceUsers();
|
||||||
where: { is_active: true },
|
|
||||||
select: { id: true, first_name: true, last_name: true },
|
|
||||||
orderBy: { last_name: "asc" },
|
|
||||||
});
|
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const currentYear = now.getFullYear();
|
const currentYear = now.getFullYear();
|
||||||
@@ -734,11 +749,7 @@ export async function getPrintData(
|
|||||||
const monthStart = new Date(yr, mo - 1, 1);
|
const monthStart = new Date(yr, mo - 1, 1);
|
||||||
const monthEnd = new Date(yr, mo, 0, 23, 59, 59);
|
const monthEnd = new Date(yr, mo, 0, 23, 59, 59);
|
||||||
|
|
||||||
const users = await prisma.users.findMany({
|
const users = await getAttendanceUsers();
|
||||||
where: { is_active: true },
|
|
||||||
select: { id: true, first_name: true, last_name: true },
|
|
||||||
orderBy: { last_name: "asc" },
|
|
||||||
});
|
|
||||||
|
|
||||||
const where: Record<string, unknown> = {
|
const where: Record<string, unknown> = {
|
||||||
shift_date: { gte: monthStart, lte: monthEnd },
|
shift_date: { gte: monthStart, lte: monthEnd },
|
||||||
@@ -1083,6 +1094,20 @@ export async function bulkCreateAttendance(data: BulkAttendanceData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const shiftDate = new Date(Date.UTC(yr, mo - 1, day, 12, 0, 0));
|
const shiftDate = new Date(Date.UTC(yr, mo - 1, day, 12, 0, 0));
|
||||||
|
|
||||||
|
if (isHoliday(dateStr)) {
|
||||||
|
await prisma.attendance.create({
|
||||||
|
data: {
|
||||||
|
user_id: userId,
|
||||||
|
shift_date: shiftDate,
|
||||||
|
leave_type: "holiday",
|
||||||
|
leave_hours: 8,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
inserted++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
await prisma.attendance.create({
|
await prisma.attendance.create({
|
||||||
data: {
|
data: {
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
|
|||||||
65
src/services/exchange-rates.ts
Normal file
65
src/services/exchange-rates.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* Czech National Bank (ČNB) exchange rate service.
|
||||||
|
* Fetches daily rates and caches them.
|
||||||
|
* API: https://api.cnb.cz/cnbapi/exrates/daily
|
||||||
|
*/
|
||||||
|
|
||||||
|
interface CnbRate {
|
||||||
|
currencyCode: string;
|
||||||
|
rate: number;
|
||||||
|
amount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rateCache: Record<string, Record<string, number>> = {};
|
||||||
|
|
||||||
|
async function fetchRatesForDate(
|
||||||
|
date?: string,
|
||||||
|
): Promise<Record<string, number>> {
|
||||||
|
const key = date || "today";
|
||||||
|
if (rateCache[key]) return rateCache[key];
|
||||||
|
|
||||||
|
try {
|
||||||
|
let url = "https://api.cnb.cz/cnbapi/exrates/daily?lang=EN";
|
||||||
|
if (date) url += `&date=${date}`;
|
||||||
|
|
||||||
|
const response = await fetch(url);
|
||||||
|
if (!response.ok) throw new Error(`CNB API: ${response.status}`);
|
||||||
|
|
||||||
|
const data = (await response.json()) as { rates: CnbRate[] };
|
||||||
|
const rates: Record<string, number> = { CZK: 1 };
|
||||||
|
|
||||||
|
for (const r of data.rates) {
|
||||||
|
rates[r.currencyCode] = r.rate / r.amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
rateCache[key] = rates;
|
||||||
|
return rates;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Failed to fetch CNB exchange rates:", err);
|
||||||
|
if (rateCache["today"]) return rateCache["today"];
|
||||||
|
return { CZK: 1, EUR: 25, USD: 22, GBP: 28 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Convert an amount from a given currency to CZK using CNB rates */
|
||||||
|
export async function toCzk(
|
||||||
|
amount: number,
|
||||||
|
currency: string,
|
||||||
|
date?: string,
|
||||||
|
): Promise<number> {
|
||||||
|
if (currency === "CZK") return amount;
|
||||||
|
const rates = await fetchRatesForDate(date);
|
||||||
|
const rate = rates[currency];
|
||||||
|
if (!rate) return amount;
|
||||||
|
return Math.round(amount * rate * 100) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get CNB rate for a currency (CZK per 1 unit), optionally for a specific date */
|
||||||
|
export async function getRate(
|
||||||
|
currency: string,
|
||||||
|
date?: string,
|
||||||
|
): Promise<number> {
|
||||||
|
if (currency === "CZK") return 1;
|
||||||
|
const rates = await fetchRatesForDate(date);
|
||||||
|
return rates[currency] || 1;
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import prisma from "../config/database";
|
import prisma from "../config/database";
|
||||||
|
import { toCzk } from "./exchange-rates";
|
||||||
|
|
||||||
// Status transition rules matching PHP
|
// Status transition rules matching PHP
|
||||||
const VALID_TRANSITIONS: Record<string, string[]> = {
|
const VALID_TRANSITIONS: Record<string, string[]> = {
|
||||||
@@ -69,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);
|
||||||
}
|
}
|
||||||
@@ -186,10 +192,11 @@ export async function getInvoiceStats(queryMonth?: number, queryYear?: number) {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const sumCzk = (invoices: typeof allInvoices) => {
|
const sumCzk = async (invoices: typeof allInvoices) => {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
for (const inv of invoices) {
|
for (const inv of invoices) {
|
||||||
total += invoiceTotalWithVat(inv); // Simplified: no real FX conversion
|
const amount = invoiceTotalWithVat(inv);
|
||||||
|
total += await toCzk(amount, inv.currency || "CZK");
|
||||||
}
|
}
|
||||||
return Math.round(total * 100) / 100;
|
return Math.round(total * 100) / 100;
|
||||||
};
|
};
|
||||||
@@ -224,18 +231,24 @@ export async function getInvoiceStats(queryMonth?: number, queryYear?: number) {
|
|||||||
let vatCzk = 0;
|
let vatCzk = 0;
|
||||||
for (const [, v] of Object.entries(vatMap)) vatCzk += v;
|
for (const [, v] of Object.entries(vatMap)) vatCzk += v;
|
||||||
|
|
||||||
|
// VAT also needs conversion
|
||||||
|
let vatCzkConverted = 0;
|
||||||
|
for (const [cur, amount] of Object.entries(vatMap)) {
|
||||||
|
vatCzkConverted += await toCzk(amount, cur);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
paid_month: aggregateByCurrency(paidInvoices),
|
paid_month: aggregateByCurrency(paidInvoices),
|
||||||
paid_month_czk: sumCzk(paidInvoices),
|
paid_month_czk: await sumCzk(paidInvoices),
|
||||||
paid_month_count: paidInvoices.length,
|
paid_month_count: paidInvoices.length,
|
||||||
awaiting: aggregateByCurrency(awaitingInvoices),
|
awaiting: aggregateByCurrency(awaitingInvoices),
|
||||||
awaiting_czk: sumCzk(awaitingInvoices),
|
awaiting_czk: await sumCzk(awaitingInvoices),
|
||||||
awaiting_count: awaitingInvoices.length,
|
awaiting_count: awaitingInvoices.length,
|
||||||
overdue: aggregateByCurrency(overdueInvoices),
|
overdue: aggregateByCurrency(overdueInvoices),
|
||||||
overdue_czk: sumCzk(overdueInvoices),
|
overdue_czk: await sumCzk(overdueInvoices),
|
||||||
overdue_count: overdueInvoices.length,
|
overdue_count: overdueInvoices.length,
|
||||||
vat_month: vatAmounts,
|
vat_month: vatAmounts,
|
||||||
vat_month_czk: Math.round(vatCzk * 100) / 100,
|
vat_month_czk: Math.round(vatCzkConverted * 100) / 100,
|
||||||
month,
|
month,
|
||||||
year,
|
year,
|
||||||
};
|
};
|
||||||
@@ -342,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",
|
||||||
|
|||||||
@@ -30,6 +30,34 @@ class NasFinancialsManager {
|
|||||||
|
|
||||||
// ── Created (issued) invoices ────────────────────────────────────
|
// ── Created (issued) invoices ────────────────────────────────────
|
||||||
|
|
||||||
|
/** Remove any existing PDF for this invoice number across all year/month folders */
|
||||||
|
cleanIssuedInvoice(invoiceNumber: string): void {
|
||||||
|
if (!this.basePath) return;
|
||||||
|
const safeName = this.sanitizeFilename(invoiceNumber) + ".pdf";
|
||||||
|
const issuedDir = path.join(this.basePath, DIR_ISSUED);
|
||||||
|
try {
|
||||||
|
if (!fs.existsSync(issuedDir)) return;
|
||||||
|
for (const yearDir of fs.readdirSync(issuedDir)) {
|
||||||
|
const yearPath = path.join(issuedDir, yearDir);
|
||||||
|
if (!fs.statSync(yearPath).isDirectory()) continue;
|
||||||
|
for (const monthDir of fs.readdirSync(yearPath)) {
|
||||||
|
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)) {
|
||||||
|
fs.unlinkSync(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// best effort
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
saveIssuedInvoicePdf(
|
saveIssuedInvoicePdf(
|
||||||
invoiceNumber: string,
|
invoiceNumber: string,
|
||||||
year: number,
|
year: number,
|
||||||
|
|||||||
Reference in New Issue
Block a user