// ============================================================ // جدول «پیدا شده» — مفقودی‌های باقی‌مانده‌ی انبار (LOSS − FOUND) // با انتخاب انبار همه‌ی مفقودی‌ها می‌آیند و نام متریال فقط فیلتر است. // ============================================================ import type { InventoryTransaction } from "../../../lib/types"; import { faNum } from "../../../lib/formatters"; import { cn } from "../../../lib/utils"; import { specsLine, type RowDraft } from "./StockTable"; export interface LossItem { tx: InventoryTransaction; remaining: number; } interface FoundTableProps { items: LossItem[]; rows: RowDraft[]; setRows: (r: RowDraft[]) => void; unitNameFn: (id: number | null | undefined) => string; emptyMsg: string; loading?: boolean; } function parseLocal(s: string): number { const v = parseFloat(String(s).replace(/[۰-۹]/g, (d) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(d))).replace(/[،,]/g, "")); return isFinite(v) ? v : 0; } export function FoundTable({ items, rows, setRows, unitNameFn, emptyMsg, loading }: FoundTableProps) { if (loading) { return
در حال بارگذاری مفقودی‌ها…
; } if (emptyMsg) { return
{emptyMsg}
; } return ( <> {/* دسکتاپ */}
{items.map(({ tx, remaining }, i) => { const over = parseLocal(rows[i]?.qty || "") > remaining; return ( ); })}
متریال مشخصه‌ها برند واحد مانده مفقودی تعداد پیداشده یادداشت
{tx.material?.name || "—"} {specsLine(tx.specs)} {tx.brand?.name || "—"} {unitNameFn(tx.unit?.id)} {faNum(remaining)} setRows(rows.map((x, xi) => (xi === i ? { ...x, qty: e.target.value } : x)))} /> {over &&
بیشتر از مفقودی!
}
setRows(rows.map((x, xi) => (xi === i ? { ...x, note: e.target.value } : x)))} />
{/* موبایل: کارت‌ها */}
{items.map(({ tx, remaining }, i) => { const over = parseLocal(rows[i]?.qty || "") > remaining; return (
{tx.material?.name || "—"}
{tx.brand?.name || "بدون برند"} · {unitNameFn(tx.unit?.id)}
{tx.specs && Object.keys(tx.specs).length > 0 && (
{specsLine(tx.specs)}
)}
مانده مفقودی
{faNum(remaining)}
setRows(rows.map((x, xi) => (xi === i ? { ...x, qty: e.target.value } : x)))} /> setRows(rows.map((x, xi) => (xi === i ? { ...x, note: e.target.value } : x)))} />
{over &&
بیشتر از مانده مفقودی!
}
); })}
); }