diff --git a/src/admin/pages/WarehouseInventoryDetail.tsx b/src/admin/pages/WarehouseInventoryDetail.tsx index 517de9d..0f6f58a 100644 --- a/src/admin/pages/WarehouseInventoryDetail.tsx +++ b/src/admin/pages/WarehouseInventoryDetail.tsx @@ -1,23 +1,38 @@ import { useState } from "react"; -import { useParams, Link } from "react-router-dom"; +import { useParams, Link as RouterLink } from "react-router-dom"; import { useQuery } from "@tanstack/react-query"; +import { motion } from "framer-motion"; +import Box from "@mui/material/Box"; +import Typography from "@mui/material/Typography"; import { useAlert } from "../context/AlertContext"; import { useAuth } from "../context/AuthContext"; import Forbidden from "../components/Forbidden"; -import { motion } from "framer-motion"; -import ConfirmModal from "../components/ConfirmModal"; -import FormField from "../components/FormField"; import { formatDate } from "../utils/formatters"; import { warehouseInventoryDetailOptions, type WarehouseInventorySession, + type WarehouseInventoryItem, } from "../lib/queries/warehouse"; import { useApiMutation } from "../lib/queries/mutations"; +import { + Button, + Card, + DataTable, + StatusChip, + EmptyState, + LoadingState, + PageHeader, + ConfirmDialog, + type DataColumn, +} from "../ui"; -const STATUS_BADGE: Record = { - DRAFT: "admin-badge-warning", - CONFIRMED: "admin-badge-active", +const STATUS_COLOR: Record< + string, + "default" | "success" | "error" | "warning" | "info" +> = { + DRAFT: "warning", + CONFIRMED: "success", }; const STATUS_LABEL: Record = { @@ -25,6 +40,19 @@ const STATUS_LABEL: Record = { CONFIRMED: "Potvrzeno", }; +const BackIcon = ( + + + +); + export default function WarehouseInventoryDetail() { const { id } = useParams(); const alert = useAlert(); @@ -65,206 +93,222 @@ export default function WarehouseInventoryDetail() { const confirming = confirmMutation.isPending; if (isPending) { - return ( -
-
-
- ); + return ; } if (error || !session) { return ( -
-
-
- + - - - - -
-
-
-
-
-

Inventura nebyla nalezena.

-
-
-
-
+ Zpět + + } + /> + + + + ); } const s = session as WarehouseInventorySession; const items = s.items ?? []; + const itemColumns: DataColumn[] = [ + { + key: "item", + header: "Položka", + width: "25%", + bold: true, + render: (row) => row.item?.name || `ID: ${row.item_id}`, + }, + { + key: "location", + header: "Lokace", + width: "15%", + mono: true, + render: (row) => row.location?.code || "—", + }, + { + key: "system_qty", + header: "Systémové množství", + width: "18%", + mono: true, + render: (row) => String(Number(row.system_qty)), + }, + { + key: "actual_qty", + header: "Skutečné množství", + width: "18%", + mono: true, + render: (row) => String(Number(row.actual_qty)), + }, + { + key: "difference", + header: "Rozdíl", + width: "12%", + render: (row) => { + const diff = Number(row.difference); + const color = + diff > 0 + ? "success.main" + : diff < 0 + ? "error.main" + : "text.secondary"; + return ( + + {diff > 0 ? `+${diff}` : diff} + + ); + }, + }, + { + key: "notes", + header: "Poznámka", + width: "12%", + render: (row) => row.notes || "—", + }, + ]; + return ( -
+ {/* Header */} -
- - - - - -
-

- {s.session_number || "Inventura"} -

-
- - {STATUS_LABEL[s.status] ?? s.status} - -
-
- {s.status === "DRAFT" && ( - - )} -
+ + + + {s.status === "DRAFT" && ( + + )} +
+ } + /> {/* Header info */} -
-

Základní údaje

-
-
- -
- {s.session_number || "—"} -
-
- -
{formatDate(s.created_at)}
-
-
+ + + Základní údaje + + + + + Číslo inventury + + + {s.session_number || "—"} + + + + + Vytvořeno + + + {formatDate(s.created_at)} + + {s.notes && ( - -
{s.notes}
-
+ + + Poznámky + + + {s.notes} + + )} -
-
+ +
{/* Lines table */} -
-

Položky

- {items.length === 0 ? ( -
Žádné řádky
- ) : ( -
- - - - - - - - - - - - - {items.map((item) => { - const diff = Number(item.difference); - const diffColor = - diff > 0 - ? "var(--success)" - : diff < 0 - ? "var(--danger)" - : "var(--text-secondary)"; - return ( - - - - - - - - - ); - })} - -
PoložkaLokaceSystémové množstvíSkutečné množstvíRozdílPoznámka
- {item.item?.name || `ID: ${item.item_id}`} - - {item.location?.code || "—"} - - {Number(item.system_qty)} - - {Number(item.actual_qty)} - - {diff > 0 ? `+${diff}` : diff} - {item.notes || "—"}
-
- )} -
+ + + Položky + + + columns={itemColumns} + rows={items} + rowKey={(row) => row.id} + empty={} + /> +
{/* Confirm modal */} - setShowConfirmModal(false)} onConfirm={handleConfirm} title="Potvrdit inventuru" message={`Opravdu chcete potvrdit inventuru „${s.session_number || s.id}"? Potvrzením se aktualizují skladové zásoby.`} confirmText="Potvrdit inventuru" - type="warning" loading={confirming} /> -
+ ); }