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:
@@ -4,18 +4,19 @@ import { useAuth } from "../context/AuthContext";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import ConfirmModal from "../components/ConfirmModal";
|
||||
import FormModal from "../components/FormModal";
|
||||
import Forbidden from "../components/Forbidden";
|
||||
|
||||
import apiFetch from "../utils/api";
|
||||
import { formatCurrency, formatDate, czechPlural } from "../utils/formatters";
|
||||
import SortIcon from "../components/SortIcon";
|
||||
import useTableSort from "../hooks/useTableSort";
|
||||
import { useQueryClient, useQuery } from "@tanstack/react-query";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { usePaginatedQuery } from "../hooks/usePaginatedQuery";
|
||||
import { offerListOptions, offerCustomersOptions } from "../lib/queries/offers";
|
||||
import useModalLock from "../hooks/useModalLock";
|
||||
import Pagination from "../components/Pagination";
|
||||
import FormField from "../components/FormField";
|
||||
import { useApiMutation } from "../lib/queries/mutations";
|
||||
|
||||
const API_BASE = "/api/admin";
|
||||
const DRAFT_KEY = "boha_offer_draft";
|
||||
@@ -27,12 +28,6 @@ const STATUS_FILTERS = [
|
||||
{ value: "invalidated", label: "Zneplatněná" },
|
||||
];
|
||||
|
||||
const ORDER_FILTERS = [
|
||||
{ value: "", label: "Vše" },
|
||||
{ value: "yes", label: "S objednávkou" },
|
||||
{ value: "no", label: "Bez objednávky" },
|
||||
];
|
||||
|
||||
interface Quotation {
|
||||
id: number;
|
||||
quotation_number: string;
|
||||
@@ -70,7 +65,6 @@ export default function Offers() {
|
||||
const [page, setPage] = useState(1);
|
||||
const [statusFilter, setStatusFilter] = useState("");
|
||||
const [customerFilter, setCustomerFilter] = useState<number | "">("");
|
||||
const [orderFilter, setOrderFilter] = useState("");
|
||||
|
||||
const { data: customers } = useQuery(offerCustomersOptions());
|
||||
|
||||
@@ -101,7 +95,6 @@ export default function Offers() {
|
||||
show: boolean;
|
||||
quotation: Quotation | null;
|
||||
}>({ show: false, quotation: null });
|
||||
useModalLock(orderModal.show);
|
||||
const [customerOrderNumber, setCustomerOrderNumber] = useState("");
|
||||
const [orderAttachment, setOrderAttachment] = useState<File | null>(null);
|
||||
const [draft, setDraft] = useState<Draft | null>(() => {
|
||||
@@ -130,10 +123,47 @@ export default function Offers() {
|
||||
page,
|
||||
status: statusFilter || undefined,
|
||||
customer_id: customerFilter || undefined,
|
||||
has_order: orderFilter || undefined,
|
||||
}),
|
||||
);
|
||||
|
||||
const duplicateMutation = useApiMutation<
|
||||
number,
|
||||
{ message?: string; error?: string }
|
||||
>({
|
||||
url: (id) => `${API_BASE}/offers/${id}/duplicate`,
|
||||
method: () => "POST",
|
||||
invalidate: ["offers", "orders", "projects", "invoices"],
|
||||
onSuccess: (data) => {
|
||||
alert.success(data?.message || "Nabídka byla duplikována");
|
||||
},
|
||||
});
|
||||
|
||||
const deleteOfferMutation = useApiMutation<
|
||||
number,
|
||||
{ message?: string; error?: string }
|
||||
>({
|
||||
url: (id) => `${API_BASE}/offers/${id}`,
|
||||
method: () => "DELETE",
|
||||
invalidate: ["offers", "orders", "projects", "invoices"],
|
||||
onSuccess: (data) => {
|
||||
setDeleteConfirm({ show: false, quotation: null });
|
||||
alert.success(data?.message || "Nabídka byla smazána");
|
||||
},
|
||||
});
|
||||
|
||||
const invalidateMutation = useApiMutation<
|
||||
number,
|
||||
{ message?: string; error?: string }
|
||||
>({
|
||||
url: (id) => `${API_BASE}/offers/${id}/invalidate`,
|
||||
method: () => "POST",
|
||||
invalidate: ["offers", "orders", "projects", "invoices"],
|
||||
onSuccess: (data) => {
|
||||
setInvalidateConfirm({ show: false, quotation: null });
|
||||
alert.success(data?.message || "Nabídka byla zneplatněna");
|
||||
},
|
||||
});
|
||||
|
||||
const discardDraft = () => {
|
||||
try {
|
||||
localStorage.removeItem(DRAFT_KEY);
|
||||
@@ -159,25 +189,9 @@ export default function Offers() {
|
||||
const handleDuplicate = async (quotation: Quotation) => {
|
||||
setDuplicating(quotation.id);
|
||||
try {
|
||||
const response = await apiFetch(
|
||||
`${API_BASE}/offers/${quotation.id}/duplicate`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
alert.success(result.message || "Nabídka byla duplikována");
|
||||
queryClient.invalidateQueries({ queryKey: ["offers"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["orders"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["projects"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["invoices"] });
|
||||
} else {
|
||||
alert.error(result.error || "Nepodařilo se duplikovat nabídku");
|
||||
}
|
||||
} catch {
|
||||
alert.error("Chyba připojení");
|
||||
await duplicateMutation.mutateAsync(quotation.id);
|
||||
} catch (e) {
|
||||
alert.error(e instanceof Error ? e.message : "Chyba připojení");
|
||||
} finally {
|
||||
setDuplicating(null);
|
||||
}
|
||||
@@ -187,16 +201,25 @@ export default function Offers() {
|
||||
if (!customerOrderNumber.trim() || !orderModal.quotation) return;
|
||||
setCreatingOrder(orderModal.quotation.id);
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("quotationId", String(orderModal.quotation.id));
|
||||
formData.append("customerOrderNumber", customerOrderNumber.trim());
|
||||
let fetchOptions: RequestInit;
|
||||
if (orderAttachment) {
|
||||
// With attachment: send as multipart/form-data
|
||||
const formData = new FormData();
|
||||
formData.append("quotationId", String(orderModal.quotation.id));
|
||||
formData.append("customerOrderNumber", customerOrderNumber.trim());
|
||||
formData.append("attachment", orderAttachment);
|
||||
fetchOptions = { method: "POST", body: formData };
|
||||
} else {
|
||||
fetchOptions = {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
quotationId: orderModal.quotation.id,
|
||||
customerOrderNumber: customerOrderNumber.trim(),
|
||||
}),
|
||||
};
|
||||
}
|
||||
const response = await apiFetch(`${API_BASE}/orders`, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
const response = await apiFetch(`${API_BASE}/orders`, fetchOptions);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
setOrderModal({ show: false, quotation: null });
|
||||
@@ -220,25 +243,9 @@ export default function Offers() {
|
||||
if (!deleteConfirm.quotation) return;
|
||||
setDeleting(true);
|
||||
try {
|
||||
const response = await apiFetch(
|
||||
`${API_BASE}/offers/${deleteConfirm.quotation.id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
},
|
||||
);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
setDeleteConfirm({ show: false, quotation: null });
|
||||
alert.success(result.message || "Nabídka byla smazána");
|
||||
queryClient.invalidateQueries({ queryKey: ["offers"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["orders"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["projects"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["invoices"] });
|
||||
} else {
|
||||
alert.error(result.error || "Nepodařilo se smazat nabídku");
|
||||
}
|
||||
} catch {
|
||||
alert.error("Chyba připojení");
|
||||
await deleteOfferMutation.mutateAsync(deleteConfirm.quotation.id);
|
||||
} catch (e) {
|
||||
alert.error(e instanceof Error ? e.message : "Chyba připojení");
|
||||
} finally {
|
||||
setDeleting(false);
|
||||
}
|
||||
@@ -248,25 +255,9 @@ export default function Offers() {
|
||||
if (!invalidateConfirm.quotation) return;
|
||||
setInvalidating(true);
|
||||
try {
|
||||
const response = await apiFetch(
|
||||
`${API_BASE}/offers/${invalidateConfirm.quotation.id}/invalidate`,
|
||||
{
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
setInvalidateConfirm({ show: false, quotation: null });
|
||||
alert.success(result.message || "Nabídka byla zneplatněna");
|
||||
queryClient.invalidateQueries({ queryKey: ["offers"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["orders"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["projects"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["invoices"] });
|
||||
} else {
|
||||
alert.error(result.error || "Nepodařilo se zneplatnit nabídku");
|
||||
}
|
||||
} catch {
|
||||
alert.error("Chyba připojení");
|
||||
await invalidateMutation.mutateAsync(invalidateConfirm.quotation.id);
|
||||
} catch (e) {
|
||||
alert.error(e instanceof Error ? e.message : "Chyba připojení");
|
||||
} finally {
|
||||
setInvalidating(false);
|
||||
}
|
||||
@@ -433,28 +424,11 @@ export default function Offers() {
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="admin-filter-group">
|
||||
<label className="admin-filter-label">Objednávka</label>
|
||||
<select
|
||||
value={orderFilter}
|
||||
onChange={(e) => {
|
||||
setOrderFilter(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
className="admin-form-select"
|
||||
>
|
||||
{ORDER_FILTERS.map((f) => (
|
||||
<option key={f.value} value={f.value}>
|
||||
{f.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AnimatePresence mode="wait">
|
||||
<motion.div
|
||||
key={`${statusFilter}-${customerFilter}-${orderFilter}-${search}-${page}-${quotations.length}`}
|
||||
key={`${statusFilter}-${customerFilter}-${search}-${page}-${quotations.length}`}
|
||||
initial={{ opacity: 0, y: 6 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0 }}
|
||||
@@ -959,157 +933,110 @@ export default function Offers() {
|
||||
loading={invalidating}
|
||||
/>
|
||||
|
||||
<AnimatePresence>
|
||||
{orderModal.show && (
|
||||
<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={() =>
|
||||
!creatingOrder &&
|
||||
setOrderModal({ show: false, quotation: null })
|
||||
<FormModal
|
||||
isOpen={orderModal.show}
|
||||
onClose={() => setOrderModal({ show: false, quotation: null })}
|
||||
onSubmit={handleCreateOrder}
|
||||
title="Vytvořit objednávku"
|
||||
submitLabel={creatingOrder ? "Vytváření..." : "Vytvořit"}
|
||||
loading={!!creatingOrder}
|
||||
>
|
||||
<p
|
||||
className="text-secondary text-md"
|
||||
style={{ marginTop: "-0.5rem", marginBottom: "0.5rem" }}
|
||||
>
|
||||
Nabídka: <strong>{orderModal.quotation?.quotation_number}</strong>
|
||||
</p>
|
||||
<div className="admin-form">
|
||||
<FormField label="Číslo objednávky zákazníka" required>
|
||||
<input
|
||||
type="text"
|
||||
value={customerOrderNumber}
|
||||
onChange={(e) => setCustomerOrderNumber(e.target.value)}
|
||||
onKeyDown={(e) =>
|
||||
e.key === "Enter" && !creatingOrder && handleCreateOrder()
|
||||
}
|
||||
className="admin-form-input"
|
||||
placeholder="Např. PO-2026-001"
|
||||
autoFocus
|
||||
/>
|
||||
<motion.div
|
||||
className="admin-modal"
|
||||
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-header">
|
||||
<h2 className="admin-modal-title">Vytvořit objednávku</h2>
|
||||
<p
|
||||
className="text-secondary text-md"
|
||||
style={{ marginTop: "0.25rem" }}
|
||||
</FormField>
|
||||
<FormField label="Příloha (PDF)">
|
||||
{orderAttachment ? (
|
||||
<div className="flex-row gap-2">
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="var(--accent-color)"
|
||||
strokeWidth="2"
|
||||
>
|
||||
Nabídka:{" "}
|
||||
<strong>{orderModal.quotation?.quotation_number}</strong>
|
||||
</p>
|
||||
</div>
|
||||
<div className="admin-modal-body">
|
||||
<div className="admin-form">
|
||||
<FormField label="Číslo objednávky zákazníka" required>
|
||||
<input
|
||||
type="text"
|
||||
value={customerOrderNumber}
|
||||
onChange={(e) => setCustomerOrderNumber(e.target.value)}
|
||||
onKeyDown={(e) =>
|
||||
e.key === "Enter" &&
|
||||
!creatingOrder &&
|
||||
handleCreateOrder()
|
||||
}
|
||||
className="admin-form-input"
|
||||
placeholder="Např. PO-2026-001"
|
||||
autoFocus
|
||||
/>
|
||||
</FormField>
|
||||
<FormField label="Příloha (PDF)">
|
||||
{orderAttachment ? (
|
||||
<div className="flex-row gap-2">
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="var(--accent-color)"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
|
||||
<polyline points="14 2 14 8 20 8" />
|
||||
</svg>
|
||||
<span className="text-md">
|
||||
{orderAttachment.name}{" "}
|
||||
<span className="text-tertiary">
|
||||
({(orderAttachment.size / 1024).toFixed(0)} KB)
|
||||
</span>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOrderAttachment(null)}
|
||||
className="admin-btn-icon"
|
||||
title="Odebrat"
|
||||
style={{ marginLeft: "auto" }}
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path d="M18 6L6 18M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<label
|
||||
className="admin-btn admin-btn-secondary admin-btn-sm inline-flex"
|
||||
style={{
|
||||
cursor: "pointer",
|
||||
gap: "0.4rem",
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
|
||||
<polyline points="17 8 12 3 7 8" />
|
||||
<line x1="12" y1="3" x2="12" y2="15" />
|
||||
</svg>
|
||||
Vybrat soubor
|
||||
<input
|
||||
type="file"
|
||||
accept="application/pdf"
|
||||
onChange={(e) =>
|
||||
setOrderAttachment(e.target.files?.[0] || null)
|
||||
}
|
||||
style={{ display: "none" }}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
<small
|
||||
className="admin-form-hint"
|
||||
style={{ marginTop: "0.25rem" }}
|
||||
>
|
||||
Max 10 MB
|
||||
</small>
|
||||
</FormField>
|
||||
</div>
|
||||
</div>
|
||||
<div className="admin-modal-footer">
|
||||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
|
||||
<polyline points="14 2 14 8 20 8" />
|
||||
</svg>
|
||||
<span className="text-md">
|
||||
{orderAttachment.name}{" "}
|
||||
<span className="text-tertiary">
|
||||
({(orderAttachment.size / 1024).toFixed(0)} KB)
|
||||
</span>
|
||||
</span>
|
||||
<button
|
||||
onClick={() =>
|
||||
setOrderModal({ show: false, quotation: null })
|
||||
type="button"
|
||||
onClick={() => setOrderAttachment(null)}
|
||||
className="admin-btn-icon"
|
||||
title="Odebrat"
|
||||
style={{ marginLeft: "auto" }}
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path d="M18 6L6 18M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<label
|
||||
className="admin-btn admin-btn-secondary admin-btn-sm inline-flex"
|
||||
style={{
|
||||
cursor: "pointer",
|
||||
gap: "0.4rem",
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
|
||||
<polyline points="17 8 12 3 7 8" />
|
||||
<line x1="12" y1="3" x2="12" y2="15" />
|
||||
</svg>
|
||||
Vybrat soubor
|
||||
<input
|
||||
type="file"
|
||||
accept="application/pdf"
|
||||
onChange={(e) =>
|
||||
setOrderAttachment(e.target.files?.[0] || null)
|
||||
}
|
||||
className="admin-btn admin-btn-secondary"
|
||||
disabled={!!creatingOrder}
|
||||
>
|
||||
Zrušit
|
||||
</button>
|
||||
<button
|
||||
onClick={handleCreateOrder}
|
||||
className="admin-btn admin-btn-primary"
|
||||
disabled={!!creatingOrder || !customerOrderNumber.trim()}
|
||||
>
|
||||
{creatingOrder ? "Vytváření..." : "Vytvořit"}
|
||||
</button>
|
||||
</div>
|
||||
</motion.div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
style={{ display: "none" }}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
<small className="admin-form-hint" style={{ marginTop: "0.25rem" }}>
|
||||
Max 10 MB
|
||||
</small>
|
||||
</FormField>
|
||||
</div>
|
||||
</FormModal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user