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,4 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useAlert } from "../context/AlertContext";
|
||||
import { useAuth } from "../context/AuthContext";
|
||||
@@ -6,13 +7,14 @@ import Forbidden from "../components/Forbidden";
|
||||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import Pagination from "../components/Pagination";
|
||||
import ConfirmModal from "../components/ConfirmModal";
|
||||
import FormModal from "../components/FormModal";
|
||||
import FormField from "../components/FormField";
|
||||
import ItemPicker from "../components/warehouse/ItemPicker";
|
||||
import useDebounce from "../hooks/useDebounce";
|
||||
import { usePaginatedQuery } from "../hooks/usePaginatedQuery";
|
||||
|
||||
import apiFetch from "../utils/api";
|
||||
import { formatDate } from "../utils/formatters";
|
||||
import { formatDate, czechPlural } from "../utils/formatters";
|
||||
import {
|
||||
warehouseReservationListOptions,
|
||||
type WarehouseReservation,
|
||||
@@ -41,6 +43,7 @@ interface ReservationForm {
|
||||
}
|
||||
|
||||
export default function WarehouseReservations() {
|
||||
const navigate = useNavigate();
|
||||
const alert = useAlert();
|
||||
const { hasPermission } = useAuth();
|
||||
const queryClient = useQueryClient();
|
||||
@@ -112,9 +115,7 @@ export default function WarehouseReservations() {
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["warehouse", "reservations"],
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: ["warehouse"] });
|
||||
setShowCreateModal(false);
|
||||
setForm({ item_id: null, project_id: null, quantity: 0, notes: "" });
|
||||
alert.success("Rezervace byla vytvořena");
|
||||
@@ -138,9 +139,7 @@ export default function WarehouseReservations() {
|
||||
);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["warehouse", "reservations"],
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: ["warehouse"] });
|
||||
setCancelTarget(null);
|
||||
alert.success("Rezervace byla zrušena");
|
||||
} else {
|
||||
@@ -173,13 +172,12 @@ export default function WarehouseReservations() {
|
||||
<h1 className="admin-page-title">Rezervace</h1>
|
||||
<p className="admin-page-subtitle">
|
||||
{pagination?.total ?? items.length}{" "}
|
||||
{pagination?.total === 1
|
||||
? "rezervace"
|
||||
: pagination?.total !== undefined &&
|
||||
pagination.total >= 2 &&
|
||||
pagination.total <= 4
|
||||
? "rezervace"
|
||||
: "rezervací"}
|
||||
{czechPlural(
|
||||
pagination?.total ?? items.length,
|
||||
"rezervace",
|
||||
"rezervace",
|
||||
"rezervací",
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="admin-page-actions">
|
||||
@@ -221,7 +219,6 @@ export default function WarehouseReservations() {
|
||||
setPage(1);
|
||||
}}
|
||||
className="admin-form-select"
|
||||
style={{ minWidth: 140 }}
|
||||
>
|
||||
<option value="">Všechny stavy</option>
|
||||
<option value="ACTIVE">Aktivní</option>
|
||||
@@ -238,7 +235,6 @@ export default function WarehouseReservations() {
|
||||
setPage(1);
|
||||
}}
|
||||
className="admin-form-select"
|
||||
style={{ minWidth: 180 }}
|
||||
>
|
||||
<option value="">Všechny projekty</option>
|
||||
{projects.map((p) => (
|
||||
@@ -309,12 +305,12 @@ export default function WarehouseReservations() {
|
||||
<tr>
|
||||
<th>Položka</th>
|
||||
<th>Projekt</th>
|
||||
<th className="text-right">Množství</th>
|
||||
<th className="text-right">Zbývá</th>
|
||||
<th>Množství</th>
|
||||
<th>Zbývá</th>
|
||||
<th>Stav</th>
|
||||
<th>Rezervoval</th>
|
||||
<th>Vytvořeno</th>
|
||||
{canOperate && <th></th>}
|
||||
{canOperate && <th>Akce</th>}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -324,10 +320,8 @@ export default function WarehouseReservations() {
|
||||
{res.item?.name || `ID: ${res.item_id}`}
|
||||
</td>
|
||||
<td>{res.project?.name || "—"}</td>
|
||||
<td className="admin-mono text-right">
|
||||
{Number(res.quantity)}
|
||||
</td>
|
||||
<td className="admin-mono text-right">
|
||||
<td className="admin-mono">{Number(res.quantity)}</td>
|
||||
<td className="admin-mono">
|
||||
{Number(res.remaining_qty)}
|
||||
</td>
|
||||
<td>
|
||||
@@ -347,29 +341,63 @@ export default function WarehouseReservations() {
|
||||
</td>
|
||||
{canOperate && (
|
||||
<td>
|
||||
{res.status === "ACTIVE" && (
|
||||
<button
|
||||
onClick={() => setCancelTarget(res)}
|
||||
className="admin-btn-icon danger"
|
||||
title="Zrušit rezervaci"
|
||||
aria-label="Zrušit rezervaci"
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
<div className="admin-table-actions">
|
||||
{res.status === "ACTIVE" && (
|
||||
<button
|
||||
onClick={() =>
|
||||
navigate("/warehouse/issues/new", {
|
||||
state: {
|
||||
reservationId: res.id,
|
||||
itemId: res.item_id,
|
||||
projectId: res.project_id,
|
||||
quantity: Number(res.remaining_qty),
|
||||
itemName: res.item?.name,
|
||||
},
|
||||
})
|
||||
}
|
||||
className="admin-btn-icon"
|
||||
title="Vytvořit výdej"
|
||||
aria-label="Vytvořit výdej"
|
||||
>
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
<line x1="15" y1="9" x2="9" y2="15" />
|
||||
<line x1="9" y1="9" x2="15" y2="15" />
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<polyline points="7 13 12 18 17 13" />
|
||||
<line x1="12" y1="18" x2="12" y2="6" />
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
{res.status === "ACTIVE" && (
|
||||
<button
|
||||
onClick={() => setCancelTarget(res)}
|
||||
className="admin-btn-icon danger"
|
||||
title="Zrušit rezervaci"
|
||||
aria-label="Zrušit rezervaci"
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
<line x1="15" y1="9" x2="9" y2="15" />
|
||||
<line x1="9" y1="9" x2="15" y2="15" />
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
@@ -386,120 +414,68 @@ export default function WarehouseReservations() {
|
||||
</motion.div>
|
||||
|
||||
{/* Create reservation modal */}
|
||||
<AnimatePresence>
|
||||
{showCreateModal && (
|
||||
<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={() => setShowCreateModal(false)}
|
||||
<FormModal
|
||||
isOpen={showCreateModal}
|
||||
onClose={() => setShowCreateModal(false)}
|
||||
onSubmit={handleCreate}
|
||||
title="Nová rezervace"
|
||||
submitLabel="Vytvořit rezervaci"
|
||||
loading={saving}
|
||||
>
|
||||
<div className="admin-form">
|
||||
<FormField label="Položka" required>
|
||||
<ItemPicker
|
||||
value={form.item_id}
|
||||
onChange={(id) => setForm((prev) => ({ ...prev, item_id: id }))}
|
||||
/>
|
||||
<motion.div
|
||||
className="admin-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 }}
|
||||
</FormField>
|
||||
<FormField label="Projekt" required>
|
||||
<select
|
||||
value={form.project_id ?? ""}
|
||||
onChange={(e) =>
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
project_id: e.target.value ? Number(e.target.value) : null,
|
||||
}))
|
||||
}
|
||||
className="admin-form-select"
|
||||
>
|
||||
<div className="admin-modal-header">
|
||||
<h2 className="admin-modal-title">Nová rezervace</h2>
|
||||
<button
|
||||
type="button"
|
||||
className="admin-modal-close"
|
||||
onClick={() => setShowCreateModal(false)}
|
||||
aria-label="Zavřít"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
<div className="admin-modal-body">
|
||||
<div className="admin-form">
|
||||
<FormField label="Položka" required>
|
||||
<ItemPicker
|
||||
value={form.item_id}
|
||||
onChange={(id) =>
|
||||
setForm((prev) => ({ ...prev, item_id: id }))
|
||||
}
|
||||
/>
|
||||
</FormField>
|
||||
<FormField label="Projekt" required>
|
||||
<select
|
||||
value={form.project_id ?? ""}
|
||||
onChange={(e) =>
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
project_id: e.target.value
|
||||
? Number(e.target.value)
|
||||
: null,
|
||||
}))
|
||||
}
|
||||
className="admin-form-select"
|
||||
>
|
||||
<option value="">Vyberte projekt</option>
|
||||
{projects.map((p) => (
|
||||
<option key={p.id} value={p.id}>
|
||||
{p.project_number} – {p.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</FormField>
|
||||
<FormField label="Množství" required>
|
||||
<input
|
||||
type="number"
|
||||
value={form.quantity || ""}
|
||||
onChange={(e) =>
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
quantity: Number(e.target.value),
|
||||
}))
|
||||
}
|
||||
className="admin-form-input"
|
||||
min="0"
|
||||
step="0.001"
|
||||
/>
|
||||
</FormField>
|
||||
<FormField label="Poznámky">
|
||||
<textarea
|
||||
value={form.notes}
|
||||
onChange={(e) =>
|
||||
setForm((prev) => ({ ...prev, notes: e.target.value }))
|
||||
}
|
||||
className="admin-form-input"
|
||||
rows={3}
|
||||
placeholder="Volitelné poznámky"
|
||||
/>
|
||||
</FormField>
|
||||
</div>
|
||||
</div>
|
||||
<div className="admin-modal-footer">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowCreateModal(false)}
|
||||
className="admin-btn admin-btn-secondary"
|
||||
disabled={saving}
|
||||
>
|
||||
Zrušit
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleCreate}
|
||||
className="admin-btn admin-btn-primary"
|
||||
disabled={saving}
|
||||
>
|
||||
{saving ? "Ukládání..." : "Vytvořit rezervaci"}
|
||||
</button>
|
||||
</div>
|
||||
</motion.div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
<option value="">Vyberte projekt</option>
|
||||
{projects.map((p) => (
|
||||
<option key={p.id} value={p.id}>
|
||||
{p.project_number} – {p.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</FormField>
|
||||
<FormField label="Množství" required>
|
||||
<input
|
||||
type="number"
|
||||
value={form.quantity || ""}
|
||||
onChange={(e) =>
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
quantity: Number(e.target.value),
|
||||
}))
|
||||
}
|
||||
className="admin-form-input"
|
||||
min="0"
|
||||
step="0.001"
|
||||
/>
|
||||
</FormField>
|
||||
<FormField label="Poznámky">
|
||||
<textarea
|
||||
value={form.notes}
|
||||
onChange={(e) =>
|
||||
setForm((prev) => ({ ...prev, notes: e.target.value }))
|
||||
}
|
||||
className="admin-form-input"
|
||||
rows={3}
|
||||
placeholder="Volitelné poznámky"
|
||||
/>
|
||||
</FormField>
|
||||
</div>
|
||||
</FormModal>
|
||||
|
||||
{/* Cancel confirmation modal */}
|
||||
<ConfirmModal
|
||||
|
||||
Reference in New Issue
Block a user