feat(inventory): 實作過期與瑕疵庫存總計顯示,並強化庫存明細過期提示
This commit is contained in:
54
resources/js/Pages/Product/Create.tsx
Normal file
54
resources/js/Pages/Product/Create.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Head, Link } from "@inertiajs/react";
|
||||
import { Package, ArrowLeft } from "lucide-react";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import ProductForm from "@/Components/Product/ProductForm";
|
||||
import { getCreateBreadcrumbs } from "@/utils/breadcrumb";
|
||||
import type { Category } from "./Index";
|
||||
import type { Unit } from "@/Components/Unit/UnitManagerDialog";
|
||||
|
||||
interface Props {
|
||||
categories: Category[];
|
||||
units: Unit[];
|
||||
}
|
||||
|
||||
export default function Create({ categories, units }: Props) {
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
breadcrumbs={getCreateBreadcrumbs("products")}
|
||||
>
|
||||
<Head title="新增商品" />
|
||||
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
{/* Header */}
|
||||
<div className="mb-6">
|
||||
<Link href={route("products.index")}>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="gap-2 button-outlined-primary mb-4"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
返回商品列表
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<div className="mb-4">
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Package className="h-6 w-6 text-primary-main" />
|
||||
新增商品
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
建立新的商品資料,包含基本資訊、價格與單位設定。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 表單內容 */}
|
||||
<ProductForm
|
||||
categories={categories}
|
||||
units={units}
|
||||
/>
|
||||
</div>
|
||||
</AuthenticatedLayout >
|
||||
);
|
||||
}
|
||||
56
resources/js/Pages/Product/Edit.tsx
Normal file
56
resources/js/Pages/Product/Edit.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Head, Link } from "@inertiajs/react";
|
||||
import { Package, ArrowLeft } from "lucide-react";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import ProductForm from "@/Components/Product/ProductForm";
|
||||
import { getEditBreadcrumbs } from "@/utils/breadcrumb";
|
||||
import type { Category, Product } from "./Index";
|
||||
import type { Unit } from "@/Components/Unit/UnitManagerDialog";
|
||||
|
||||
interface Props {
|
||||
product: Product;
|
||||
categories: Category[];
|
||||
units: Unit[];
|
||||
}
|
||||
|
||||
export default function Edit({ product, categories, units }: Props) {
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
breadcrumbs={getEditBreadcrumbs("products")}
|
||||
>
|
||||
<Head title={`編輯商品 - ${product.name}`} />
|
||||
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
{/* Header */}
|
||||
<div className="mb-6">
|
||||
<Link href={route("products.index")}>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="gap-2 button-outlined-primary mb-4"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
返回商品列表
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<div className="mb-4">
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<Package className="h-6 w-6 text-primary-main" />
|
||||
編輯商品:{product.name}
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
修改商品的基本資訊、價格或庫存單位設定。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 表單內容 */}
|
||||
<ProductForm
|
||||
initialData={product}
|
||||
categories={categories}
|
||||
units={units}
|
||||
/>
|
||||
</div>
|
||||
</AuthenticatedLayout >
|
||||
);
|
||||
}
|
||||
@@ -4,12 +4,11 @@ import { Input } from "@/Components/ui/input";
|
||||
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||
import { Plus, Search, Package, X, Upload } from 'lucide-react';
|
||||
import ProductTable from "@/Components/Product/ProductTable";
|
||||
import ProductDialog from "@/Components/Product/ProductDialog";
|
||||
import ProductImportDialog from "@/Components/Product/ProductImportDialog";
|
||||
import CategoryManagerDialog from "@/Components/Category/CategoryManagerDialog";
|
||||
import UnitManagerDialog, { Unit } from "@/Components/Unit/UnitManagerDialog";
|
||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Head, router, usePage } from "@inertiajs/react";
|
||||
import { Head, router, usePage, Link } from "@inertiajs/react";
|
||||
import { PageProps as GlobalPageProps } from "@/types/global";
|
||||
import { debounce } from "lodash";
|
||||
import Pagination from "@/Components/shared/Pagination";
|
||||
@@ -70,11 +69,9 @@ export default function ProductManagement({ products, categories, units, filters
|
||||
const [perPage, setPerPage] = useState<string>(filters.per_page || "10");
|
||||
const [sortField, setSortField] = useState<string | null>(filters.sort_field || null);
|
||||
const [sortDirection, setSortDirection] = useState<"asc" | "desc" | null>(filters.sort_direction as "asc" | "desc" || null);
|
||||
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
||||
const [isCategoryDialogOpen, setIsCategoryDialogOpen] = useState(false);
|
||||
const [isUnitDialogOpen, setIsUnitDialogOpen] = useState(false);
|
||||
const [isImportDialogOpen, setIsImportDialogOpen] = useState(false);
|
||||
const [editingProduct, setEditingProduct] = useState<Product | null>(null);
|
||||
|
||||
// Sync state with props when they change (e.g. navigation)
|
||||
useEffect(() => {
|
||||
@@ -163,15 +160,6 @@ export default function ProductManagement({ products, categories, units, filters
|
||||
);
|
||||
};
|
||||
|
||||
const handleAddProduct = () => {
|
||||
setEditingProduct(null);
|
||||
setIsDialogOpen(true);
|
||||
};
|
||||
|
||||
const handleEditProduct = (product: Product) => {
|
||||
setEditingProduct(product);
|
||||
setIsDialogOpen(true);
|
||||
};
|
||||
|
||||
const handleDeleteProduct = (id: string) => {
|
||||
router.delete(route('products.destroy', id), {
|
||||
@@ -259,10 +247,12 @@ export default function ProductManagement({ products, categories, units, filters
|
||||
</Button>
|
||||
</Can>
|
||||
<Can permission="products.create">
|
||||
<Button onClick={handleAddProduct} className="flex-1 md:flex-none button-filled-primary">
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增商品
|
||||
</Button>
|
||||
<Link href={route("products.create")}>
|
||||
<Button className="w-full md:w-auto button-filled-primary">
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
新增商品
|
||||
</Button>
|
||||
</Link>
|
||||
</Can>
|
||||
</div>
|
||||
</div>
|
||||
@@ -271,7 +261,6 @@ export default function ProductManagement({ products, categories, units, filters
|
||||
{/* Product Table */}
|
||||
<ProductTable
|
||||
products={products.data}
|
||||
onEdit={handleEditProduct}
|
||||
onDelete={handleDeleteProduct}
|
||||
startIndex={products.from}
|
||||
sortField={sortField}
|
||||
@@ -302,13 +291,6 @@ export default function ProductManagement({ products, categories, units, filters
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ProductDialog
|
||||
open={isDialogOpen}
|
||||
onOpenChange={setIsDialogOpen}
|
||||
product={editingProduct}
|
||||
categories={categories}
|
||||
units={units}
|
||||
/>
|
||||
|
||||
<ProductImportDialog
|
||||
open={isImportDialogOpen}
|
||||
|
||||
@@ -37,6 +37,7 @@ interface PageProps {
|
||||
available_amount: number;
|
||||
book_stock: number;
|
||||
book_amount: number;
|
||||
abnormal_amount: number;
|
||||
};
|
||||
filters: {
|
||||
search?: string;
|
||||
@@ -166,18 +167,15 @@ export default function WarehouseIndex({ warehouses, totals, filters }: PageProp
|
||||
</div>
|
||||
|
||||
{/* 統計區塊 */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
|
||||
<Card className="shadow-sm">
|
||||
<CardContent className="p-6">
|
||||
<div className="flex flex-col">
|
||||
<span className="text-sm font-medium text-gray-500 mb-1">可用庫存總計</span>
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span className="text-3xl font-bold text-primary-main">
|
||||
{totals.available_stock.toLocaleString()}
|
||||
</span>
|
||||
<Can permission="inventory.view_cost">
|
||||
<span className="text-lg font-medium text-gray-400">
|
||||
( 總額:${totals.available_amount?.toLocaleString()} )
|
||||
<span className="text-3xl font-bold text-primary-main">
|
||||
${Number(totals.available_amount || 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
|
||||
</span>
|
||||
</Can>
|
||||
</div>
|
||||
@@ -190,12 +188,24 @@ export default function WarehouseIndex({ warehouses, totals, filters }: PageProp
|
||||
<div className="flex flex-col">
|
||||
<span className="text-sm font-medium text-gray-500 mb-1">帳面庫存總計</span>
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span className="text-3xl font-bold text-gray-700">
|
||||
{totals.book_stock.toLocaleString()}
|
||||
</span>
|
||||
<Can permission="inventory.view_cost">
|
||||
<span className="text-lg font-medium text-gray-400">
|
||||
( 總額:${totals.book_amount?.toLocaleString()} )
|
||||
<span className="text-3xl font-bold text-gray-700">
|
||||
${Number(totals.book_amount || 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
|
||||
</span>
|
||||
</Can>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="shadow-sm border-red-100 bg-red-50/10">
|
||||
<CardContent className="p-6">
|
||||
<div className="flex flex-col">
|
||||
<span className="text-sm font-medium text-red-500 mb-1">過期與瑕疵總計</span>
|
||||
<div className="flex items-baseline gap-2">
|
||||
<Can permission="inventory.view_cost">
|
||||
<span className="text-3xl font-bold text-red-600">
|
||||
${Number(totals.abnormal_amount || 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
|
||||
</span>
|
||||
</Can>
|
||||
</div>
|
||||
@@ -252,6 +262,8 @@ export default function WarehouseIndex({ warehouses, totals, filters }: PageProp
|
||||
warehouse={warehouse}
|
||||
stats={{
|
||||
totalQuantity: warehouse.book_stock || 0,
|
||||
totalValue: warehouse.book_amount || 0,
|
||||
abnormalValue: warehouse.abnormal_amount || 0,
|
||||
lowStockCount: warehouse.low_stock_count || 0,
|
||||
replenishmentNeeded: warehouse.low_stock_count || 0
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user