v1.8.0: warehouse module (16 commits), docházka mzda model, leave_type=holiday removal, api.ts race fix
Highlights: - Warehouse module: receipts, issues, reservations, inventory, reports, dashboard, master data (categories, suppliers, locations), FIFO service, integration tests - Docházka: mzda PDF counting model (Odpracováno / Vč. svátků / Přesčas / Svátek / So/Ne / Noc) with Czech weekday names and decimal hours - AttendanceAdmin/AttendanceHistory KPI cards unified to mzda formula with fund bar colored by delta, badges for Práce/Dov/Nem/Sv/Nep - Remove leave_type=holiday entirely (auto-computed from Czech public holidays) - Allow multiple work shifts per day (overlap detection only) - Pre-flight refresh in api.ts eliminates spurious 401s on fresh page loads - Prisma: company_settings gets 6 nullable columns for warehouse numbering (PRI/VYD/INV prefixes, default patterns); migration seeds defaults
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useState } from "react";
|
||||
import { useParams, useNavigate, Link } from "react-router-dom";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useAlert } from "../context/AlertContext";
|
||||
import { useAuth } from "../context/AuthContext";
|
||||
import Forbidden from "../components/Forbidden";
|
||||
@@ -8,12 +8,12 @@ import { motion } from "framer-motion";
|
||||
import ConfirmModal from "../components/ConfirmModal";
|
||||
import FormField from "../components/FormField";
|
||||
|
||||
import apiFetch from "../utils/api";
|
||||
import { formatCurrency, formatDate } from "../utils/formatters";
|
||||
import {
|
||||
warehouseReceiptDetailOptions,
|
||||
type WarehouseReceipt,
|
||||
} from "../lib/queries/warehouse";
|
||||
import { useApiMutation } from "../lib/queries/mutations";
|
||||
|
||||
const STATUS_BADGE: Record<string, string> = {
|
||||
DRAFT: "admin-badge-warning",
|
||||
@@ -38,11 +38,8 @@ export default function WarehouseReceiptDetail() {
|
||||
const alert = useAlert();
|
||||
const { hasPermission } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const [cancelConfirm, setCancelConfirm] = useState(false);
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
const [cancelling, setCancelling] = useState(false);
|
||||
|
||||
const {
|
||||
data: receipt,
|
||||
@@ -54,70 +51,76 @@ export default function WarehouseReceiptDetail() {
|
||||
|
||||
const canOperate = hasPermission("warehouse.operate");
|
||||
|
||||
const confirmMutation = useApiMutation<void, void>({
|
||||
url: () =>
|
||||
receipt
|
||||
? `/api/admin/warehouse/receipts/${receipt.id}/confirm`
|
||||
: "/api/admin/warehouse/receipts/0/confirm",
|
||||
method: () => "POST",
|
||||
invalidate: ["warehouse"],
|
||||
onSuccess: () => {
|
||||
alert.success("Doklad byl potvrzen");
|
||||
},
|
||||
});
|
||||
|
||||
const cancelMutation = useApiMutation<void, void>({
|
||||
url: () =>
|
||||
receipt
|
||||
? `/api/admin/warehouse/receipts/${receipt.id}/cancel`
|
||||
: "/api/admin/warehouse/receipts/0/cancel",
|
||||
method: () => "POST",
|
||||
invalidate: ["warehouse"],
|
||||
onSuccess: () => {
|
||||
setCancelConfirm(false);
|
||||
alert.success("Doklad byl zrušen");
|
||||
},
|
||||
});
|
||||
|
||||
const deleteAttachmentMutation = useApiMutation<
|
||||
{ attachmentId: number },
|
||||
void
|
||||
>({
|
||||
url: ({ attachmentId }) =>
|
||||
receipt
|
||||
? `/api/admin/warehouse/receipts/${receipt.id}/attachments/${attachmentId}`
|
||||
: `/api/admin/warehouse/receipts/0/attachments/0`,
|
||||
method: () => "DELETE",
|
||||
invalidate: ["warehouse"],
|
||||
onSuccess: () => {
|
||||
alert.success("Příloha byla smazána");
|
||||
},
|
||||
});
|
||||
|
||||
const handleConfirm = async () => {
|
||||
if (!receipt) return;
|
||||
setConfirming(true);
|
||||
try {
|
||||
const response = await apiFetch(
|
||||
`/api/admin/warehouse/receipts/${receipt.id}/confirm`,
|
||||
{ method: "POST" },
|
||||
);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
queryClient.invalidateQueries({ queryKey: ["warehouse", "receipts"] });
|
||||
alert.success("Doklad byl potvrzen");
|
||||
} else {
|
||||
alert.error(result.error || "Nepodařilo se potvrdit doklad");
|
||||
}
|
||||
} catch {
|
||||
alert.error("Chyba připojení");
|
||||
} finally {
|
||||
setConfirming(false);
|
||||
await confirmMutation.mutateAsync(undefined);
|
||||
} catch (e) {
|
||||
alert.error(e instanceof Error ? e.message : "Chyba připojení");
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancel = async () => {
|
||||
if (!receipt) return;
|
||||
setCancelling(true);
|
||||
try {
|
||||
const response = await apiFetch(
|
||||
`/api/admin/warehouse/receipts/${receipt.id}/cancel`,
|
||||
{ method: "POST" },
|
||||
);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
queryClient.invalidateQueries({ queryKey: ["warehouse", "receipts"] });
|
||||
setCancelConfirm(false);
|
||||
alert.success("Doklad byl zrušen");
|
||||
} else {
|
||||
alert.error(result.error || "Nepodařilo se zrušit doklad");
|
||||
}
|
||||
} catch {
|
||||
alert.error("Chyba připojení");
|
||||
} finally {
|
||||
setCancelling(false);
|
||||
await cancelMutation.mutateAsync(undefined);
|
||||
} catch (e) {
|
||||
alert.error(e instanceof Error ? e.message : "Chyba připojení");
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteAttachment = async (attachmentId: number) => {
|
||||
if (!receipt) return;
|
||||
try {
|
||||
const response = await apiFetch(
|
||||
`/api/admin/warehouse/receipts/${receipt.id}/attachments/${attachmentId}`,
|
||||
{ method: "DELETE" },
|
||||
);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
queryClient.invalidateQueries({ queryKey: ["warehouse", "receipts"] });
|
||||
alert.success("Příloha byla smazána");
|
||||
} else {
|
||||
alert.error(result.error || "Nepodařilo se smazat přílohu");
|
||||
}
|
||||
} catch {
|
||||
alert.error("Chyba připojení");
|
||||
await deleteAttachmentMutation.mutateAsync({ attachmentId });
|
||||
} catch (e) {
|
||||
alert.error(e instanceof Error ? e.message : "Chyba připojení");
|
||||
}
|
||||
};
|
||||
|
||||
const confirming = confirmMutation.isPending;
|
||||
const cancelling = cancelMutation.isPending;
|
||||
|
||||
if (isPending) {
|
||||
return (
|
||||
<div className="admin-loading">
|
||||
@@ -161,7 +164,7 @@ export default function WarehouseReceiptDetail() {
|
||||
}
|
||||
|
||||
const r = receipt as WarehouseReceipt;
|
||||
const lines = r.lines ?? [];
|
||||
const items = r.items ?? [];
|
||||
const attachments = r.attachments ?? [];
|
||||
|
||||
return (
|
||||
@@ -257,12 +260,14 @@ export default function WarehouseReceiptDetail() {
|
||||
<div className="admin-form">
|
||||
<div className="admin-form-row">
|
||||
<FormField label="Číslo dokladu">
|
||||
<div className="admin-mono" style={{ fontWeight: 500 }}>
|
||||
<div className="admin-mono fw-500">
|
||||
{r.receipt_number || "—"}
|
||||
</div>
|
||||
</FormField>
|
||||
<FormField label="Dodavatel">
|
||||
<div style={{ fontWeight: 500 }}>{r.supplier?.name || "—"}</div>
|
||||
<div className="admin-mono fw-500">
|
||||
{r.supplier?.name || "—"}
|
||||
</div>
|
||||
</FormField>
|
||||
</div>
|
||||
<div className="admin-form-row">
|
||||
@@ -279,7 +284,7 @@ export default function WarehouseReceiptDetail() {
|
||||
</div>
|
||||
<div className="admin-form-row">
|
||||
<FormField label="Přijal">
|
||||
<div>
|
||||
<div className="admin-mono fw-500">
|
||||
{r.received_by_user
|
||||
? `${r.received_by_user.first_name} ${r.received_by_user.last_name}`
|
||||
: "—"}
|
||||
@@ -306,53 +311,42 @@ export default function WarehouseReceiptDetail() {
|
||||
transition={{ duration: 0.25, delay: 0.08 }}
|
||||
>
|
||||
<div className="admin-card-body">
|
||||
<h3 className="admin-card-title">Řádky dokladu</h3>
|
||||
{lines.length === 0 ? (
|
||||
<div
|
||||
style={{
|
||||
color: "var(--text-tertiary)",
|
||||
fontSize: "0.875rem",
|
||||
textAlign: "center",
|
||||
padding: "1.5rem 0",
|
||||
}}
|
||||
>
|
||||
Žádné řádky
|
||||
</div>
|
||||
<h3 className="admin-card-title">Položky</h3>
|
||||
{items.length === 0 ? (
|
||||
<div className="admin-empty-state">Žádné řádky</div>
|
||||
) : (
|
||||
<div className="admin-table-responsive">
|
||||
<table className="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Položka</th>
|
||||
<th className="text-right">Množství</th>
|
||||
<th className="text-right">Cena/ks</th>
|
||||
<th className="text-right">Celkem</th>
|
||||
<th>Množství</th>
|
||||
<th>Cena/ks</th>
|
||||
<th>Celkem</th>
|
||||
<th>Lokace</th>
|
||||
<th>Poznámka</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{lines.map((line) => (
|
||||
<tr key={line.id}>
|
||||
{items.map((item) => (
|
||||
<tr key={item.id}>
|
||||
<td className="fw-500">
|
||||
{line.item?.name || `ID: ${line.item_id}`}
|
||||
{item.item?.name || `ID: ${item.item_id}`}
|
||||
</td>
|
||||
<td className="admin-mono text-right">
|
||||
{Number(line.quantity)}
|
||||
<td className="admin-mono">{Number(item.quantity)}</td>
|
||||
<td className="admin-mono">
|
||||
{formatCurrency(Number(item.unit_price), "CZK")}
|
||||
</td>
|
||||
<td className="admin-mono text-right">
|
||||
{formatCurrency(Number(line.unit_price), "CZK")}
|
||||
</td>
|
||||
<td className="admin-mono text-right fw-500">
|
||||
<td className="admin-mono fw-500">
|
||||
{formatCurrency(
|
||||
Number(line.quantity) * Number(line.unit_price),
|
||||
Number(item.quantity) * Number(item.unit_price),
|
||||
"CZK",
|
||||
)}
|
||||
</td>
|
||||
<td className="admin-mono">
|
||||
{line.location?.code || "—"}
|
||||
{item.location?.code || "—"}
|
||||
</td>
|
||||
<td>{line.notes || "—"}</td>
|
||||
<td>{item.notes || "—"}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
@@ -372,16 +366,7 @@ export default function WarehouseReceiptDetail() {
|
||||
<div className="admin-card-body">
|
||||
<h3 className="admin-card-title">Přílohy</h3>
|
||||
{attachments.length === 0 ? (
|
||||
<div
|
||||
style={{
|
||||
color: "var(--text-tertiary)",
|
||||
fontSize: "0.875rem",
|
||||
textAlign: "center",
|
||||
padding: "1.5rem 0",
|
||||
}}
|
||||
>
|
||||
Žádné přílohy
|
||||
</div>
|
||||
<div className="admin-empty-state">Žádné přílohy</div>
|
||||
) : (
|
||||
<div className="admin-table-responsive">
|
||||
<table className="admin-table">
|
||||
@@ -390,7 +375,7 @@ export default function WarehouseReceiptDetail() {
|
||||
<th>Název souboru</th>
|
||||
<th>Velikost</th>
|
||||
<th>Datum</th>
|
||||
<th></th>
|
||||
<th>Akce</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -412,28 +397,30 @@ export default function WarehouseReceiptDetail() {
|
||||
{formatDate(att.created_at)}
|
||||
</td>
|
||||
<td>
|
||||
{r.status === "DRAFT" && canOperate && (
|
||||
<button
|
||||
onClick={() => handleDeleteAttachment(att.id)}
|
||||
className="admin-btn-icon danger"
|
||||
title="Smazat přílohu"
|
||||
aria-label="Smazat přílohu"
|
||||
>
|
||||
<svg
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
<div className="admin-table-actions">
|
||||
{r.status === "DRAFT" && canOperate && (
|
||||
<button
|
||||
onClick={() => handleDeleteAttachment(att.id)}
|
||||
className="admin-btn-icon danger"
|
||||
title="Smazat přílohu"
|
||||
aria-label="Smazat přílohu"
|
||||
>
|
||||
<polyline points="3 6 5 6 21 6" />
|
||||
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
<svg
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<polyline points="3 6 5 6 21 6" />
|
||||
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user