Compare commits

16 Commits

Author SHA1 Message Date
852370cfe0 fix(db): add activity_log migrations to central database
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 49s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped
2026-01-28 14:10:53 +08:00
965418077b fix(ui): provide default branding for central admin
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Has been skipped
Koori-ERP-Deploy-System / deploy-production (push) Successful in 40s
2026-01-28 14:01:08 +08:00
c3af92c85c feat(ui): dynamic page title based on tenant context
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Has been skipped
Koori-ERP-Deploy-System / deploy-production (push) Successful in 49s
2026-01-28 13:58:54 +08:00
cca49b5fe8 feat(assets): add default tenant logo and login background
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Has been skipped
Koori-ERP-Deploy-System / deploy-production (push) Successful in 44s
2026-01-28 13:49:24 +08:00
d4cef2cd84 fix(tenancy): force seeders in production and set default branding
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Has been skipped
Koori-ERP-Deploy-System / deploy-production (push) Successful in 51s
2026-01-28 13:45:28 +08:00
4c959efc8b feat: 補齊生產管理與進貨單權限、功能實作及 UI 優化
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 50s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped
2026-01-27 17:40:56 +08:00
95d8dc2e84 feat: 統一進貨單 UI、修復庫存異動紀錄與廠商詳情顯示報錯
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 51s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped
2026-01-27 17:23:31 +08:00
a7c445bd3f fix: 修正部分進貨採購單更新失敗與狀態顯示問題
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 50s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped
2026-01-27 13:27:28 +08:00
293358df62 refactor(inventory): 重構倉庫管理邏輯,移除 is_sellable 欄位並改由類型判定可用庫存 2026-01-27 10:23:49 +08:00
1ed3d6a29d docs(ui-consistency): 優化規範文件,明確標準操作優先使用主題色 2026-01-27 10:15:50 +08:00
646435f87a style(production): 修正檢視按鈕樣式為主題色並保留權限控制 2026-01-27 10:11:16 +08:00
f10c31abd0 style(production): 補齊生產工單列表檢視按鈕 UI 與權限控制 2026-01-27 10:10:10 +08:00
046e0a028b style(production): 統一生產模組操作圖示 UI、權限控制與 AlertDialog 2026-01-27 10:09:43 +08:00
ce0a7b3409 feat(procurement): 採購單號格式增加 PO 前綴 2026-01-27 10:05:46 +08:00
084bbc9f53 docs: 再次確認 framework.md 更新內容並同步
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 50s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped
2026-01-27 09:18:07 +08:00
3af4a1e298 docs: 更新開發框架規範,加入嚴格模組化通訊規範
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 47s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped
2026-01-27 09:15:05 +08:00
61 changed files with 3019 additions and 208 deletions

View File

@@ -50,7 +50,16 @@ trigger: always_on
* Routes: `kebab-case` (小寫橫線分隔)
* **回傳格式** 所有的前後端溝通需維持一致的 JSON 結構,特別是驗證錯誤 (Validation Errors) 與閃存訊息 (Flash Messages)。
## 6. AI 協作規則 (給 Antigravity AI)
## 6. 嚴格模組化通訊規範 (Strict Modular Communication)
為了確保系統的可維護性與獨立性,所有模組必須遵守以下「實體解耦」規範:
* **禁止跨模組 Eloquent 關聯**:禁止在 Model 中定義指向其他模組的 `belongsTo`, `hasMany` 等關聯。
* **介面化通訊 (Contracts)**:模組間的資料交換與功能調用必須透過 `app/Modules/{ModuleName}/Contracts/` 下定義的介面進行。
* **禁止跨模組 Model 引用**Controller 與 Service 禁止 `use` 其他模組的 Model (除非是該模組自身的 Contracts)。
* **手動資料水和 (Manual Hydration)**若頁面需要顯示跨模組資料訂單顯示使用者名稱Controller 應透過 Service 獲取基本資料,再手動組合成前端所需的 JSON/Props 結構。
* **資料一致性**:跨模組的資料操作應由各模組的 Service 處理其內部的 transaction 完整性。
## 7. AI 協作規則 (給 Antigravity AI)
* **角色設定** 你是一位專業的全端開發工程師助手。
* **代碼生成指令**
* 所有的解釋說明請使用 **繁體中文**。
@@ -58,7 +67,7 @@ trigger: always_on
* 必須考慮 ERP 邏輯(例如:權限判斷、操作日誌、資料完整性)。
* 新增功能時,請先判斷應歸屬於哪個 Module並建立在 `app/Modules/` 對應目錄下。
## 7. 運行機制 (Docker / Sail)
## 8. 運行機制 (Docker / Sail)
由於專案運行在 Docker 容器環境中,請勿直接在宿主機 (Host) 執行 php 或 composer 指令。請使用專案內建的 `sail` 指令:
* **啟動環境** `./vendor/bin/sail up -d`

View File

@@ -123,8 +123,8 @@ tooltip
// ✅ 成功操作
<Button className="button-filled-success">確認</Button>
// ✅ 資訊操作
<Button className="button-filled-info">查看詳情</Button>
// ✅ 資訊操作(用於系統提示、說明等非業務主流程)
<Button className="button-filled-info">系統資訊</Button>
// ✅ 警告操作
<Button className="button-filled-warning">警告</Button>
@@ -177,6 +177,23 @@ tooltip
</Can>
```
#### 表格操作列檢視按鈕
```tsx
<Can permission="resource.view">
<Link href={route('resource.show', item.id)}>
<Button
variant="outline"
size="sm"
className="button-outlined-primary"
title="檢視"
>
<Eye className="h-4 w-4" />
</Button>
</Link>
</Can>
```
#### 表格操作列編輯按鈕
```tsx

View File

@@ -13,7 +13,7 @@ Star ERP 是一個基於 **Laravel 12**、**Inertia.js (React)** 與 **Tailwind
## 📂 系統功能詳細說明
### 🌳 系統功能架構樹 (含 2.0 升級規劃)
### 🌳 預計系統功能架構樹 (含 2.0 升級規劃)
```text
Star ERP
├── 🏠 儀表板 (Dashboard)

View File

@@ -56,6 +56,11 @@ class TenantController extends Controller
'name' => $validated['name'],
'email' => $validated['email'] ?? null,
'is_active' => true,
'branding' => [
'logo_path' => 'defaults/logo.png', // 預設 Logo 路徑
'login_background_path' => 'defaults/login_bg.jpg', // 預設登入背景
'primary_color' => '#4F46E5', // 預設主色系 (Indigo-600)
],
]);
// 綁定網域(如果沒有輸入,使用預設網域)

View File

@@ -37,8 +37,15 @@ class HandleInertiaRequests extends Middleware
{
$user = $request->user();
$tenant = tenancy()->tenant;
$appName = $tenant ? ($tenant->name ?? 'Star ERP') : 'Star ERP 中央後台';
// 分享給 Blade View (給 app.blade.php 使用)
\Illuminate\Support\Facades\View::share('appName', $appName);
return [
...parent::share($request),
'appName' => $appName,
'auth' => [
'user' => $user ? [
'id' => $user->id,
@@ -58,7 +65,12 @@ class HandleInertiaRequests extends Middleware
'branding' => function () {
$tenant = tenancy()->tenant;
if (!$tenant) {
return null;
// 中央後台預設 Branding
return [
'logo_url' => \Storage::url('defaults/logo.png'), // 中央後台也使用預設 Logo
'primary_color' => '#4F46E5',
'text_color' => '#1a1a1a',
];
}
$logoUrl = null;

View File

@@ -23,6 +23,11 @@ class ActivityLogController extends Controller
'App\Modules\Inventory\Models\Warehouse' => '倉庫',
'App\Modules\Inventory\Models\Inventory' => '庫存',
'App\Modules\Finance\Models\UtilityFee' => '公共事業費',
'App\Modules\Inventory\Models\GoodsReceipt' => '進貨單',
'App\Modules\Production\Models\ProductionOrder' => '生產工單',
'App\Modules\Production\Models\Recipe' => '生產配方',
'App\Modules\Production\Models\RecipeItem' => '配方品項',
'App\Modules\Production\Models\ProductionOrderItem' => '工單品項',
];
}

View File

@@ -178,8 +178,12 @@ class RoleController extends Controller
'inventory' => '庫存管理',
'vendors' => '廠商資料管理',
'purchase_orders' => '採購單管理',
'goods_receipts' => '進貨單管理',
'production_orders' => '生產工單管理',
'recipes' => '配方管理',
'users' => '使用者管理',
'roles' => '角色與權限',
'system' => '系統管理',
'utility_fees' => '公共事業費管理',
'accounting' => '會計報表',
];

View File

@@ -0,0 +1,248 @@
<?php
namespace App\Modules\Inventory\Controllers;
use App\Http\Controllers\Controller;
use App\Modules\Inventory\Services\GoodsReceiptService;
use App\Modules\Inventory\Services\InventoryService;
use App\Modules\Procurement\Contracts\ProcurementServiceInterface;
use Illuminate\Http\Request;
use App\Modules\Procurement\Models\Vendor;
use Inertia\Inertia;
use App\Modules\Inventory\Models\GoodsReceipt;
class GoodsReceiptController extends Controller
{
protected $goodsReceiptService;
protected $inventoryService;
protected $procurementService;
public function __construct(
GoodsReceiptService $goodsReceiptService,
InventoryService $inventoryService,
ProcurementServiceInterface $procurementService
) {
$this->goodsReceiptService = $goodsReceiptService;
$this->inventoryService = $inventoryService;
$this->procurementService = $procurementService;
}
public function index(Request $request)
{
$query = GoodsReceipt::query()
->select(['id', 'code', 'type', 'warehouse_id', 'vendor_id', 'received_date', 'status', 'created_at'])
->with(['warehouse'])
->withSum('items', 'total_amount');
// 關鍵字搜尋(單號)
if ($request->filled('search')) {
$search = $request->input('search');
$query->where('code', 'like', "%{$search}%");
}
// 狀態篩選
if ($request->filled('status') && $request->input('status') !== 'all') {
$query->where('status', $request->input('status'));
}
// 倉庫篩選
if ($request->filled('warehouse_id') && $request->input('warehouse_id') !== 'all') {
$query->where('warehouse_id', $request->input('warehouse_id'));
}
// 日期範圍篩選
if ($request->filled('date_start')) {
$query->whereDate('received_date', '>=', $request->input('date_start'));
}
if ($request->filled('date_end')) {
$query->whereDate('received_date', '<=', $request->input('date_end'));
}
// 每頁筆數
$perPage = $request->input('per_page', 10);
$receipts = $query->orderBy('created_at', 'desc')
->paginate($perPage)
->withQueryString();
// Manual Hydration for Vendors (Cross-Module)
$vendorIds = collect($receipts->items())->pluck('vendor_id')->unique()->filter()->toArray();
$vendors = $this->procurementService->getVendorsByIds($vendorIds)->keyBy('id');
$receipts->getCollection()->transform(function ($receipt) use ($vendors) {
$receipt->vendor = $vendors->get($receipt->vendor_id);
return $receipt;
});
// 取得倉庫列表用於篩選
$warehouses = $this->inventoryService->getAllWarehouses();
return Inertia::render('Inventory/GoodsReceipt/Index', [
'receipts' => $receipts,
'filters' => $request->only(['search', 'status', 'warehouse_id', 'date_start', 'date_end', 'per_page']),
'warehouses' => $warehouses,
]);
}
public function show($id)
{
$receipt = GoodsReceipt::with([
'warehouse',
'items.product.category',
'items.product.baseUnit'
])->findOrFail($id);
// Manual Hydration for Vendor (Cross-Module)
if ($receipt->vendor_id) {
$receipt->vendor = $this->procurementService->getVendorsByIds([$receipt->vendor_id])->first();
}
// 手動計算統計資訊 (如果 Model 沒有定義對應的 Attribute)
$receipt->items_sum_total_amount = $receipt->items->sum('total_amount');
return Inertia::render('Inventory/GoodsReceipt/Show', [
'receipt' => $receipt
]);
}
public function create()
{
// 取得待進貨的採購單列表(用於標準採購類型選擇)
$pendingPOs = $this->procurementService->getPendingPurchaseOrders();
// 提取所有產品 ID 以便跨模組水和資料
$productIds = $pendingPOs->flatMap(fn($po) => $po->items->pluck('product_id'))->unique()->filter()->toArray();
$products = $this->inventoryService->getProductsByIds($productIds)->keyBy('id');
// 處理採購單資料,計算剩餘可收貨數量
$formattedPOs = $pendingPOs->map(function ($po) use ($products) {
return [
'id' => $po->id,
'code' => $po->code,
'status' => $po->status,
'vendor_id' => $po->vendor_id,
'vendor_name' => $po->vendor?->name ?? '',
'warehouse_id' => $po->warehouse_id,
'order_date' => $po->order_date,
'items' => $po->items->map(function ($item) use ($products) {
$product = $products->get($item->product_id);
$remaining = max(0, $item->quantity - ($item->received_quantity ?? 0));
return [
'id' => $item->id,
'product_id' => $item->product_id,
'product_name' => $product?->name ?? '',
'product_code' => $product?->code ?? '',
'unit' => $product?->baseUnit?->name ?? '個',
'quantity' => $item->quantity,
'received_quantity' => $item->received_quantity ?? 0,
'remaining' => $remaining,
'unit_price' => $item->unit_price,
];
})->filter(fn($item) => $item['remaining'] > 0)->values(),
];
})->filter(fn($po) => $po['items']->count() > 0)->values();
// 取得所有廠商列表(用於雜項入庫/其他類型選擇)
$vendors = $this->procurementService->getAllVendors();
return Inertia::render('Inventory/GoodsReceipt/Create', [
'warehouses' => $this->inventoryService->getAllWarehouses(),
'pendingPurchaseOrders' => $formattedPOs,
'vendors' => $vendors,
]);
}
public function store(Request $request)
{
$validated = $request->validate([
'warehouse_id' => 'required|exists:warehouses,id',
'type' => 'required|in:standard,miscellaneous,other',
'purchase_order_id' => 'nullable|required_if:type,standard|exists:purchase_orders,id',
// Vendor ID is required if standard, but optional/nullable for misc/other?
// Stick to existing logic: if standard, we infer vendor from PO usually, or frontend sends it.
// For now let's make vendor_id optional for misc/other or user must select one?
// "雜項入庫" might not have a vendor. Let's make it nullable.
'vendor_id' => 'nullable|integer',
'received_date' => 'required|date',
'remarks' => 'nullable|string',
'items' => 'required|array|min:1',
'items.*.product_id' => 'required|integer|exists:products,id',
'items.*.purchase_order_item_id' => 'nullable|required_if:type,standard|integer',
'items.*.quantity_received' => 'required|numeric|min:0',
'items.*.unit_price' => 'required|numeric|min:0',
'items.*.batch_number' => 'nullable|string',
'items.*.expiry_date' => 'nullable|date',
]);
$this->goodsReceiptService->store($validated);
return redirect()->route('goods-receipts.index')->with('success', '進貨單已建立');
}
// API to search POs
public function searchPOs(Request $request)
{
$search = $request->input('query');
if (!$search) {
return response()->json([]);
}
$pos = $this->procurementService->searchPendingPurchaseOrders($search);
return response()->json($pos);
}
// API to search Products for Manual Entry
public function searchProducts(Request $request)
{
$search = $request->input('query');
if (!$search) {
return response()->json([]);
}
$products = $this->inventoryService->getProductsByName($search);
// Format for frontend
$mapped = $products->map(function($product) {
return [
'id' => $product->id,
'name' => $product->name,
'code' => $product->code,
'unit' => $product->baseUnit?->name ?? '個', // Ensure unit is included
'price' => $product->purchase_price ?? 0, // Suggest price from product info if available
];
});
return response()->json($mapped);
}
// API to search Vendors
public function searchVendors(Request $request)
{
$search = $request->input('query');
if (!$search) {
return response()->json([]);
}
$vendors = $this->procurementService->searchVendors($search);
return response()->json($vendors);
}
/**
* 刪除進貨單
*/
public function destroy(GoodsReceipt $goodsReceipt)
{
// 只有有權限的人可以刪除
if (!auth()->user()->can('goods_receipts.delete')) {
return redirect()->back()->with('error', '您沒有權限刪除進貨單');
}
// 簡單刪除邏輯:刪除進貨單(品項由資料庫級聯刪除或手動處理)
// 注意:實務上可能需要處理已入庫的庫存回滾,但在這個簡易 ERP 中通常是行政刪除
$goodsReceipt->delete();
return redirect()->route('goods-receipts.index')->with('success', '進貨單已刪除');
}
}

View File

@@ -10,6 +10,7 @@ use Inertia\Inertia;
use App\Modules\Inventory\Models\Warehouse;
use App\Modules\Inventory\Models\Product;
use App\Modules\Inventory\Models\Inventory;
use App\Modules\Inventory\Models\InventoryTransaction;
use App\Modules\Inventory\Models\WarehouseProductSafetyStock;
use App\Modules\Core\Contracts\CoreServiceInterface;
@@ -482,7 +483,60 @@ class InventoryController extends Controller
$productId = $request->query('productId');
if ($productId) {
// ... (略) ...
$product = Product::findOrFail($productId);
// 取得該倉庫中該商品的所有批號 ID
$inventoryIds = Inventory::where('warehouse_id', $warehouse->id)
->where('product_id', $productId)
->pluck('id')
->toArray();
$transactionsRaw = InventoryTransaction::whereIn('inventory_id', $inventoryIds)
->with('inventory') // 需要批號資訊
->orderBy('actual_time', 'desc')
->orderBy('id', 'desc')
->get();
// 手動 Hydrate 使用者資料
$userIds = $transactionsRaw->pluck('user_id')->filter()->unique()->toArray();
$users = $this->coreService->getUsersByIds($userIds)->keyBy('id');
// 計算商品在該倉庫的總量(不分批號)
$currentRunningTotal = (float) Inventory::whereIn('id', $inventoryIds)->sum('quantity');
$transactions = $transactionsRaw->map(function ($tx) use ($users, &$currentRunningTotal) {
$user = $tx->user_id ? ($users[$tx->user_id] ?? null) : null;
$balanceAfter = $currentRunningTotal;
// 為下一筆(較舊的)紀錄更新 Running Total
$currentRunningTotal -= (float) $tx->quantity;
return [
'id' => (string) $tx->id,
'type' => $tx->type,
'quantity' => (float) $tx->quantity,
'unit_cost' => (float) $tx->unit_cost,
'balanceAfter' => (float) $balanceAfter, // 顯示該商品在倉庫的累計結餘
'reason' => $tx->reason,
'userName' => $user ? $user->name : '系統',
'actualTime' => $tx->actual_time ? $tx->actual_time->format('Y-m-d H:i') : $tx->created_at->format('Y-m-d H:i'),
'batchNumber' => $tx->inventory?->batch_number ?? '-', // 補上批號資訊
];
});
// 重新計算目前的總量(用於 Header 顯示,確保一致性)
$totalQuantity = Inventory::whereIn('id', $inventoryIds)->sum('quantity');
return Inertia::render('Warehouse/InventoryHistory', [
'warehouse' => $warehouse,
'inventory' => [
'id' => null, // 跨批號查詢沒有單一 ID
'productName' => $product->name,
'productCode' => $product->code,
'batchNumber' => '所有批號',
'quantity' => (float) $totalQuantity,
],
'transactions' => $transactions
]);
}
if ($inventoryId) {

View File

@@ -26,9 +26,12 @@ class WarehouseController extends Controller
$warehouses = $query->withSum('inventories as book_stock', 'quantity') // 帳面庫存 = 所有庫存總和
->withSum(['inventories as available_stock' => function ($query) {
// 可用庫存 = 庫存 > 0 且 品質正常 且 (未過期 或 無效期)
// 可用庫存 = 庫存 > 0 且 品質正常 且 (未過期 或 無效期) 且 倉庫類型不為瑕疵倉
$query->where('quantity', '>', 0)
->where('quality_status', 'normal')
->whereHas('warehouse', function ($q) {
$q->where('type', '!=', \App\Enums\WarehouseType::QUARANTINE);
})
->where(function ($q) {
$q->whereNull('expiry_date')
->orWhere('expiry_date', '>=', now());
@@ -38,20 +41,15 @@ class WarehouseController extends Controller
->paginate(10)
->withQueryString();
// 修正各倉庫列表中的可用庫存計算:若倉庫不可銷售,則可用庫存為 0
$warehouses->getCollection()->transform(function ($w) {
if (!$w->is_sellable) {
$w->available_stock = 0;
}
return $w;
});
// 移除原本對 is_sellable 的手動修正邏輯,現在由 type 自動過濾
// 計算全域總計 (不分頁)
$totals = [
'available_stock' => \App\Modules\Inventory\Models\Inventory::where('quantity', '>', 0)
->where('quality_status', 'normal')
->whereHas('warehouse', function ($q) {
$q->where('is_sellable', true);
$q->where('type', '!=', \App\Enums\WarehouseType::QUARANTINE);
})
->where(function ($q) {
$q->whereNull('expiry_date')
@@ -73,7 +71,6 @@ class WarehouseController extends Controller
'name' => 'required|string|max:50',
'address' => 'nullable|string|max:255',
'description' => 'nullable|string',
'is_sellable' => 'nullable|boolean',
'type' => 'required|string',
'license_plate' => 'nullable|string|max:20',
'driver_name' => 'nullable|string|max:50',
@@ -98,7 +95,6 @@ class WarehouseController extends Controller
'name' => 'required|string|max:50',
'address' => 'nullable|string|max:255',
'description' => 'nullable|string',
'is_sellable' => 'nullable|boolean',
'type' => 'required|string',
'license_plate' => 'nullable|string|max:20',
'driver_name' => 'nullable|string|max:50',

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Modules\Inventory\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class GoodsReceipt extends Model
{
use HasFactory, SoftDeletes;
use \Spatie\Activitylog\Traits\LogsActivity;
protected $fillable = [
'code',
'type',
'warehouse_id',
'purchase_order_id',
'vendor_id',
'received_date',
'status',
'remarks',
'user_id',
];
protected $casts = [
'received_date' => 'date:Y-m-d',
];
public function getActivitylogOptions(): \Spatie\Activitylog\LogOptions
{
return \Spatie\Activitylog\LogOptions::defaults()
->logAll()
->logOnlyDirty()
->dontSubmitEmptyLogs();
}
public function items()
{
return $this->hasMany(GoodsReceiptItem::class);
}
// Strict Mode: relationships to Warehouse is allowed (same module).
public function warehouse()
{
return $this->belongsTo(Warehouse::class);
}
// Strict Mode: cross-module relationship to Vendor/User/PurchaseOrder is restricted.
// They are accessed via IDs or Services.
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Modules\Inventory\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class GoodsReceiptItem extends Model
{
use HasFactory;
protected $fillable = [
'goods_receipt_id',
'product_id',
'purchase_order_item_id',
'quantity_received',
'unit_price',
'total_amount',
'batch_number',
'expiry_date',
];
protected $casts = [
'quantity_received' => 'decimal:2',
'unit_price' => 'decimal:2', // 暫定價格
'total_amount' => 'decimal:2',
'expiry_date' => 'date:Y-m-d',
];
public function goodsReceipt()
{
return $this->belongsTo(GoodsReceipt::class);
}
public function product()
{
return $this->belongsTo(Product::class);
}
}

View File

@@ -18,13 +18,11 @@ class Warehouse extends Model
'type',
'address',
'description',
'is_sellable',
'license_plate',
'driver_name',
];
protected $casts = [
'is_sellable' => 'boolean',
'type' => \App\Enums\WarehouseType::class,
];

View File

@@ -77,4 +77,15 @@ Route::middleware('auth')->group(function () {
Route::get('/api/warehouses/{warehouse}/inventories', [TransferOrderController::class, 'getWarehouseInventories'])
->middleware('permission:inventory.view')
->name('api.warehouses.inventories');
// 進貨單 (Goods Receipts)
Route::middleware('permission:goods_receipts.view')->group(function () {
Route::get('/goods-receipts', [\App\Modules\Inventory\Controllers\GoodsReceiptController::class, 'index'])->name('goods-receipts.index');
Route::get('/goods-receipts/create', [\App\Modules\Inventory\Controllers\GoodsReceiptController::class, 'create'])->middleware('permission:goods_receipts.create')->name('goods-receipts.create');
Route::get('/goods-receipts/{goods_receipt}', [\App\Modules\Inventory\Controllers\GoodsReceiptController::class, 'show'])->name('goods-receipts.show');
Route::post('/goods-receipts', [\App\Modules\Inventory\Controllers\GoodsReceiptController::class, 'store'])->middleware('permission:goods_receipts.create')->name('goods-receipts.store');
Route::get('/api/goods-receipts/search-pos', [\App\Modules\Inventory\Controllers\GoodsReceiptController::class, 'searchPOs'])->name('goods-receipts.search-pos');
Route::get('/api/goods-receipts/search-products', [\App\Modules\Inventory\Controllers\GoodsReceiptController::class, 'searchProducts'])->name('goods-receipts.search-products');
Route::get('/api/goods-receipts/search-vendors', [\App\Modules\Inventory\Controllers\GoodsReceiptController::class, 'searchVendors'])->name('goods-receipts.search-vendors');
});
});

View File

@@ -0,0 +1,109 @@
<?php
namespace App\Modules\Inventory\Services;
use App\Modules\Inventory\Models\GoodsReceipt;
use App\Modules\Inventory\Models\GoodsReceiptItem;
use App\Modules\Inventory\Contracts\InventoryServiceInterface;
use App\Modules\Procurement\Contracts\ProcurementServiceInterface;
use Illuminate\Support\Facades\DB;
class GoodsReceiptService
{
protected $inventoryService;
protected $procurementService;
public function __construct(
InventoryServiceInterface $inventoryService,
ProcurementServiceInterface $procurementService
) {
$this->inventoryService = $inventoryService;
$this->procurementService = $procurementService;
}
/**
* Store a new Goods Receipt and process inventory.
*
* @param array $data
* @return GoodsReceipt
* @throws \Exception
*/
public function store(array $data)
{
return DB::transaction(function () use ($data) {
// 1. Generate Code
$data['code'] = $this->generateCode($data['received_date']);
$data['user_id'] = auth()->id();
$data['status'] = 'completed'; // Direct completion for now
// 2. Create Header
$goodsReceipt = GoodsReceipt::create($data);
// 3. Process Items
foreach ($data['items'] as $itemData) {
// Create GR Item
$grItem = new GoodsReceiptItem([
'product_id' => $itemData['product_id'],
'purchase_order_item_id' => $itemData['purchase_order_item_id'] ?? null,
'quantity_received' => $itemData['quantity_received'],
'unit_price' => $itemData['unit_price'],
'total_amount' => $itemData['quantity_received'] * $itemData['unit_price'],
'batch_number' => $itemData['batch_number'] ?? null,
'expiry_date' => $itemData['expiry_date'] ?? null,
]);
$goodsReceipt->items()->save($grItem);
// 4. Update Inventory
$reason = match($goodsReceipt->type) {
'standard' => '採購進貨',
'miscellaneous' => '雜項入庫',
'other' => '其他入庫',
default => '進貨入庫',
};
$this->inventoryService->createInventoryRecord([
'warehouse_id' => $goodsReceipt->warehouse_id,
'product_id' => $grItem->product_id,
'quantity' => $grItem->quantity_received,
'unit_cost' => $grItem->unit_price,
'batch_number' => $grItem->batch_number,
'expiry_date' => $grItem->expiry_date,
'reason' => $reason,
'reference_type' => GoodsReceipt::class,
'reference_id' => $goodsReceipt->id,
'source_purchase_order_id' => $goodsReceipt->purchase_order_id,
'arrival_date' => $goodsReceipt->received_date,
]);
// 5. Update PO if linked and type is standard
if ($goodsReceipt->type === 'standard' && $goodsReceipt->purchase_order_id && $grItem->purchase_order_item_id) {
$this->procurementService->updateReceivedQuantity(
$grItem->purchase_order_item_id,
$grItem->quantity_received
);
}
}
return $goodsReceipt;
});
}
private function generateCode(string $date)
{
// Format: GR + YYYYMMDD + NNN
$prefix = 'GR' . date('Ymd', strtotime($date));
$last = GoodsReceipt::where('code', 'like', $prefix . '%')
->orderBy('id', 'desc')
->lockForUpdate()
->first();
if ($last) {
$seq = intval(substr($last->code, -3)) + 1;
} else {
$seq = 1;
}
return $prefix . str_pad($seq, 3, '0', STR_PAD_LEFT);
}
}

View File

@@ -17,7 +17,7 @@ class InventoryService implements InventoryServiceInterface
public function getAllProducts()
{
return Product::with(['baseUnit'])->get();
return Product::with(['baseUnit', 'largeUnit'])->get();
}
public function getUnits()
@@ -32,17 +32,17 @@ class InventoryService implements InventoryServiceInterface
public function getProduct(int $id)
{
return Product::find($id);
return Product::with(['baseUnit', 'largeUnit'])->find($id);
}
public function getProductsByIds(array $ids)
{
return Product::whereIn('id', $ids)->get();
return Product::whereIn('id', $ids)->with(['baseUnit', 'largeUnit'])->get();
}
public function getProductsByName(string $name)
{
return Product::where('name', 'like', "%{$name}%")->get();
return Product::where('name', 'like', "%{$name}%")->with(['baseUnit', 'largeUnit'])->get();
}
public function getWarehouse(int $id)

View File

@@ -31,4 +31,52 @@ interface ProcurementServiceInterface
* @return array
*/
public function getDashboardStats(): array;
/**
* Update received quantity for a PO item.
*
* @param int $poItemId
* @param float $quantity
* @return void
*/
public function updateReceivedQuantity(int $poItemId, float $quantity): void;
/**
* Search pending or partial purchase orders.
*
* @param string $query
* @return Collection
*/
public function searchPendingPurchaseOrders(string $query): Collection;
/**
* Search vendors by name or code.
*
* @param string $query
* @return Collection
*/
public function searchVendors(string $query): Collection;
/**
* 取得所有待進貨的採購單列表(不需搜尋條件)。
* 用於進貨單頁面直接顯示可選擇的採購單。
*
* @return Collection
*/
public function getPendingPurchaseOrders(): Collection;
/**
* 取得所有廠商列表。
*
* @return Collection
*/
public function getAllVendors(): Collection;
/**
* Get vendors by multiple IDs.
*
* @param array $ids
* @return Collection
*/
public function getVendorsByIds(array $ids): Collection;
}

View File

@@ -187,9 +187,10 @@ class PurchaseOrderController extends Controller
try {
DB::beginTransaction();
// 生成單號YYYYMMDD001
// 生成單號:POYYYYMMDD001
$today = now()->format('Ymd');
$lastOrder = PurchaseOrder::where('code', 'like', $today . '%')
$prefix = 'PO' . $today;
$lastOrder = PurchaseOrder::where('code', 'like', $prefix . '%')
->lockForUpdate() // 鎖定以避免並發衝突
->orderBy('code', 'desc')
->first();
@@ -201,7 +202,7 @@ class PurchaseOrderController extends Controller
} else {
$sequence = '001';
}
$code = $today . $sequence;
$code = $prefix . $sequence;
$totalAmount = 0;
foreach ($validated['items'] as $item) {
@@ -419,7 +420,7 @@ class PurchaseOrderController extends Controller
'order_date' => 'required|date', // 新增驗證
'expected_delivery_date' => 'nullable|date',
'remark' => 'nullable|string',
'status' => 'required|string|in:draft,pending,processing,shipping,confirming,completed,cancelled',
'status' => 'required|string|in:draft,pending,approved,partial,completed,closed,cancelled',
'invoice_number' => ['nullable', 'string', 'max:11', 'regex:/^[A-Z]{2}-\d{8}$/'],
'invoice_date' => 'nullable|date',
'invoice_amount' => 'nullable|numeric|min:0',
@@ -476,14 +477,21 @@ class PurchaseOrderController extends Controller
$order->saveQuietly();
// 2. 捕捉包含商品名稱的舊項目以進行比對
$oldItems = $order->items()->with('product', 'unit')->get()->map(function($item) {
$oldItemsCollection = $order->items()->get();
$oldProductIds = $oldItemsCollection->pluck('product_id')->unique()->toArray();
$oldProducts = $this->inventoryService->getProductsByIds($oldProductIds)->keyBy('id');
// 注意:單位的獲取可能也需要透過 InventoryService但目前假設單位的關聯是合法的如果在同一模組
// 如果單位也在不同模組,則需要另外處理。這裡暫時假設可以動手水和一下基本單位名稱。
$oldItems = $oldItemsCollection->map(function($item) use ($oldProducts) {
$product = $oldProducts->get($item->product_id);
return [
'id' => $item->id,
'product_id' => $item->product_id,
'product_name' => $item->product?->name,
'product_name' => $product?->name ?? 'Unknown',
'quantity' => (float) $item->quantity,
'unit_id' => $item->unit_id,
'unit_name' => $item->unit?->name,
'unit_name' => 'N/A', // 簡化處理,或可透過服務獲取
'subtotal' => (float) $item->subtotal,
];
})->keyBy('product_id');
@@ -513,14 +521,19 @@ class PurchaseOrderController extends Controller
'updated' => [],
];
// 重新獲取新項目以確保擁有最新的關聯
$newItemsFormatted = $order->items()->with('product', 'unit')->get()->map(function($item) {
// 重新獲取新項目並水和產品資料
$newItemsCollection = $order->items()->get();
$newProductIds = $newItemsCollection->pluck('product_id')->unique()->toArray();
$newProducts = $this->inventoryService->getProductsByIds($newProductIds)->keyBy('id');
$newItemsFormatted = $newItemsCollection->map(function($item) use ($newProducts) {
$product = $newProducts->get($item->product_id);
return [
'product_id' => $item->product_id,
'product_name' => $item->product?->name,
'product_name' => $product?->name ?? 'Unknown',
'quantity' => (float) $item->quantity,
'unit_id' => $item->unit_id,
'unit_name' => $item->unit?->name,
'unit_name' => 'N/A',
'subtotal' => (float) $item->subtotal,
];
})->keyBy('product_id');

View File

@@ -95,14 +95,15 @@ class VendorController extends Controller
if (!$product) return null;
return (object) [
'id' => (string) $pivot->id,
'productId' => (string) $product->id,
'productName' => $product->name,
'unit' => $product->baseUnit?->name ?? 'N/A',
'baseUnit' => $product->baseUnit?->name,
'largeUnit' => $product->largeUnit?->name,
'conversionRate' => (float) $product->conversion_rate,
'lastPrice' => (float) $pivot->last_price,
'id' => (string) $product->id, // Frontend expects product ID here as p.id
'name' => $product->name,
'baseUnit' => $product->baseUnit ? (object)['name' => $product->baseUnit->name] : null,
'largeUnit' => $product->largeUnit ? (object)['name' => $product->largeUnit->name] : null,
'conversion_rate' => (float) $product->conversion_rate,
'purchase_unit' => $product->purchaseUnit?->name,
'pivot' => (object) [
'last_price' => (float) $pivot->last_price,
],
];
})->filter()->values();
@@ -119,7 +120,7 @@ class VendorController extends Controller
'email' => $vendor->email,
'address' => $vendor->address,
'remark' => $vendor->remark,
'supplyProducts' => $supplyProducts,
'products' => $supplyProducts, // Changed from supplyProducts to products
];
return Inertia::render('Vendor/Show', [

View File

@@ -29,4 +29,74 @@ class ProcurementService implements ProcurementServiceInterface
'pendingOrdersCount' => PurchaseOrder::where('status', 'pending')->count(),
];
}
public function updateReceivedQuantity(int $poItemId, float $quantity): void
{
$item = \App\Modules\Procurement\Models\PurchaseOrderItem::findOrFail($poItemId);
$item->increment('received_quantity', $quantity);
$item->refresh();
// Check PO status
$po = $item->purchaseOrder;
// Load items to check completion
$po->load('items');
$allReceived = $po->items->every(function ($i) {
return $i->received_quantity >= $i->quantity;
});
$anyReceived = $po->items->contains(function ($i) {
return $i->received_quantity > 0;
});
if ($allReceived) {
$po->status = 'completed'; // or 'received' based on workflow
} elseif ($anyReceived) {
$po->status = 'partial';
}
$po->save();
}
public function searchPendingPurchaseOrders(string $query): Collection
{
return PurchaseOrder::with(['vendor', 'items'])
->whereIn('status', ['approved', 'partial'])
->where(function($q) use ($query) {
$q->where('code', 'like', "%{$query}%")
->orWhereHas('vendor', function($vq) use ($query) {
$vq->where('name', 'like', "%{$query}%");
});
})
->limit(20)
->get();
}
public function searchVendors(string $query): Collection
{
return \App\Modules\Procurement\Models\Vendor::where('name', 'like', "%{$query}%")
->orWhere('code', 'like', "%{$query}%")
->limit(20)
->get(['id', 'name', 'code']);
}
public function getPendingPurchaseOrders(): Collection
{
return PurchaseOrder::with(['vendor', 'items'])
->whereIn('status', ['approved', 'partial'])
->orderBy('created_at', 'desc')
->limit(50)
->get();
}
public function getAllVendors(): Collection
{
return \App\Modules\Procurement\Models\Vendor::orderBy('name')->get(['id', 'name', 'code']);
}
public function getVendorsByIds(array $ids): Collection
{
return \App\Modules\Procurement\Models\Vendor::whereIn('id', $ids)->get(['id', 'name', 'code']);
}
}

View File

@@ -204,6 +204,6 @@ return [
*/
'seeder_parameters' => [
'--class' => 'TenantDatabaseSeeder', // 租戶專用 seeder
// '--force' => true, // This needs to be true to seed tenant databases in production
'--force' => true, // 強制在正式環境執行 Seeder
],
];

View File

@@ -0,0 +1,27 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateActivityLogTable extends Migration
{
public function up()
{
Schema::connection(config('activitylog.database_connection'))->create(config('activitylog.table_name'), function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('log_name')->nullable();
$table->text('description');
$table->nullableMorphs('subject', 'subject');
$table->nullableMorphs('causer', 'causer');
$table->json('properties')->nullable();
$table->timestamps();
$table->index('log_name');
});
}
public function down()
{
Schema::connection(config('activitylog.database_connection'))->dropIfExists(config('activitylog.table_name'));
}
}

View File

@@ -0,0 +1,22 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddEventColumnToActivityLogTable extends Migration
{
public function up()
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->string('event')->nullable()->after('subject_type');
});
}
public function down()
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->dropColumn('event');
});
}
}

View File

@@ -0,0 +1,22 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddBatchUuidColumnToActivityLogTable extends Migration
{
public function up()
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->uuid('batch_uuid')->nullable()->after('properties');
});
}
public function down()
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->dropColumn('batch_uuid');
});
}
}

View File

@@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
// 單欄索引:事件類型(高頻過濾條件)
$table->index('event', 'idx_event');
// 單欄索引:批次 UUID未來批次操作查詢
$table->index('batch_uuid', 'idx_batch_uuid');
// 複合索引 1時間 + 事件類型(最常見的組合查詢)
$table->index(['created_at', 'event'], 'idx_created_event');
// 複合索引 2主體類型 + 主體 ID + 時間(查詢特定資源的操作歷史)
$table->index(['subject_type', 'subject_id', 'created_at'], 'idx_subject_created');
// 複合索引 3操作者 + 時間(查詢特定使用者的操作紀錄)
$table->index(['causer_id', 'created_at'], 'idx_causer_created');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->dropIndex('idx_event');
$table->dropIndex('idx_batch_uuid');
$table->dropIndex('idx_created_event');
$table->dropIndex('idx_subject_created');
$table->dropIndex('idx_causer_created');
});
}
};

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('warehouses', function (Blueprint $table) {
$table->dropColumn('is_sellable');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('warehouses', function (Blueprint $table) {
$table->boolean('is_sellable')->default(true)->after('description')->comment('是否可銷售');
});
}
};

View File

@@ -0,0 +1,50 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('goods_receipts', function (Blueprint $table) {
$table->id();
$table->string('code')->index(); // GR 單號
$table->foreignId('warehouse_id')->constrained()->onDelete('restrict');
$table->foreignId('purchase_order_id')->nullable()->constrained()->onDelete('set null');
$table->foreignId('vendor_id')->constrained()->onDelete('restrict'); // 關聯到 Inventory 模組內的 Vendor 邏輯或跨模組 ID (此處僅 FK 約束通常指向同一 DB 的 vendors 表)
$table->date('received_date');
$table->enum('status', ['draft', 'completed', 'cancelled'])->default('draft');
$table->text('remarks')->nullable();
$table->foreignId('user_id')->constrained()->onDelete('restrict'); // 經辦人
$table->timestamps();
$table->softDeletes();
});
Schema::create('goods_receipt_items', function (Blueprint $table) {
$table->id();
$table->foreignId('goods_receipt_id')->constrained()->onDelete('cascade');
$table->foreignId('product_id')->constrained()->onDelete('restrict');
$table->foreignId('purchase_order_item_id')->nullable()->constrained()->onDelete('set null'); // 用於回寫 PO Item
$table->decimal('quantity_received', 10, 2);
$table->decimal('unit_price', 10, 2); // 暫定價格 (來自 PO)
$table->decimal('total_amount', 12, 2); // 小計
$table->string('batch_number')->nullable();
$table->date('expiry_date')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('goods_receipt_items');
Schema::dropIfExists('goods_receipts');
}
};

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('goods_receipts', function (Blueprint $table) {
$table->enum('type', ['standard', 'miscellaneous', 'other'])->default('standard')->after('warehouse_id');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('goods_receipts', function (Blueprint $table) {
$table->dropColumn('type');
});
}
};

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
// Update old statuses to 'approved'
DB::table('purchase_orders')
->whereIn('status', ['processing', 'shipping', 'confirming'])
->update(['status' => 'approved']);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
// Cannot easily reverse without knowing original status,
// but typically we can revert 'approved' back to 'processing' as a safeguard if needed,
// or just leave it since 'approved' is broader.
// For strict reversal, we might try to map back, but effectively this is a one-way consolidation.
// We will leave it as is for down/safe side.
}
};

View File

@@ -37,6 +37,25 @@ class PermissionSeeder extends Seeder
'inventory.view_cost', // 查看成本與價值
'inventory.adjust',
'inventory.transfer',
'inventory.delete',
// 進貨單管理
'goods_receipts.view',
'goods_receipts.create',
'goods_receipts.edit',
'goods_receipts.delete',
// 生產工單管理
'production_orders.view',
'production_orders.create',
'production_orders.edit',
'production_orders.delete',
// 配方管理
'recipes.view',
'recipes.create',
'recipes.edit',
'recipes.delete',
// 供應商管理
'vendors.view',
@@ -97,7 +116,10 @@ class PermissionSeeder extends Seeder
'products.view', 'products.create', 'products.edit', 'products.delete',
'purchase_orders.view', 'purchase_orders.create', 'purchase_orders.edit',
'purchase_orders.delete', 'purchase_orders.publish',
'inventory.view', 'inventory.view_cost', 'inventory.adjust', 'inventory.transfer',
'inventory.view', 'inventory.view_cost', 'inventory.adjust', 'inventory.transfer', 'inventory.delete',
'goods_receipts.view', 'goods_receipts.create', 'goods_receipts.edit', 'goods_receipts.delete',
'production_orders.view', 'production_orders.create', 'production_orders.edit', 'production_orders.delete',
'recipes.view', 'recipes.create', 'recipes.edit', 'recipes.delete',
'vendors.view', 'vendors.create', 'vendors.edit', 'vendors.delete',
'warehouses.view', 'warehouses.create', 'warehouses.edit', 'warehouses.delete',
'users.view', 'users.create', 'users.edit',
@@ -110,7 +132,9 @@ class PermissionSeeder extends Seeder
// warehouse-manager 管理庫存與倉庫
$warehouseManager->givePermissionTo([
'products.view',
'inventory.view', 'inventory.adjust', 'inventory.transfer',
'inventory.view', 'inventory.adjust', 'inventory.transfer', 'inventory.delete',
'goods_receipts.view', 'goods_receipts.create', 'goods_receipts.edit', 'goods_receipts.delete',
'production_orders.view', 'production_orders.create', 'production_orders.edit',
'warehouses.view', 'warehouses.create', 'warehouses.edit',
]);
@@ -120,6 +144,7 @@ class PermissionSeeder extends Seeder
'purchase_orders.view', 'purchase_orders.create', 'purchase_orders.edit',
'vendors.view', 'vendors.create', 'vendors.edit',
'inventory.view',
'goods_receipts.view', 'goods_receipts.create',
]);
// viewer 僅能查看
@@ -127,6 +152,7 @@ class PermissionSeeder extends Seeder
'products.view',
'purchase_orders.view',
'inventory.view',
'goods_receipts.view',
'vendors.view',
'warehouses.view',
'utility_fees.view',

View File

@@ -114,10 +114,24 @@ const fieldLabels: Record<string, string> = {
transaction_date: '費用日期',
category: '費用類別',
amount: '金額',
// 進貨單欄位
gr_number: '進貨單號',
received_date: '入庫日期',
type: '入庫類型',
remarks: '備註',
// 生產管理欄位
production_number: '工單編號',
production_date: '生產日期',
actual_quantity: '實際產量',
consumption_status: '物料消耗狀態',
recipe_id: '生產配方',
recipe_name: '配方名稱',
yield_quantity: '預期產量',
};
// 採購單狀態對照表
// 狀態翻譯對照表
const statusMap: Record<string, string> = {
// 採購單狀態
draft: '草稿',
pending: '待審核',
approved: '已核准',
@@ -125,6 +139,10 @@ const statusMap: Record<string, string> = {
received: '已收貨',
cancelled: '已取消',
completed: '已完成',
// 生產工單狀態
planned: '已計畫',
in_progress: '生產中',
// completed 已定義
};
// 庫存品質狀態對照表

View File

@@ -0,0 +1,101 @@
import { useState } from "react";
import { Eye, Trash2 } from "lucide-react";
import { Button } from "@/Components/ui/button";
import { Link, useForm } from "@inertiajs/react";
import { toast } from "sonner";
import { Can } from "@/Components/Permission/Can";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/Components/ui/alert-dialog";
export interface GoodsReceipt {
id: number;
code: string;
warehouse_id: number;
warehouse?: { name: string };
vendor_id?: number;
vendor?: { name: string };
received_date: string;
status: string;
type?: string;
items_sum_total_amount?: number;
user?: { name: string };
}
export default function GoodsReceiptActions({
receipt,
}: { receipt: GoodsReceipt }) {
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
const { delete: destroy, processing } = useForm({});
const handleConfirmDelete = () => {
// @ts-ignore
destroy(route('goods-receipts.destroy', receipt.id), {
onSuccess: () => {
toast.success("進貨單已成功刪除");
setShowDeleteDialog(false);
},
onError: (errors: any) => toast.error(errors.error || "刪除過程中發生錯誤"),
});
};
return (
<div className="flex justify-center gap-2">
<Link href={route('goods-receipts.show', receipt.id)}>
<Button
variant="outline"
size="sm"
className="button-outlined-primary"
title="查看詳情"
>
<Eye className="h-4 w-4" />
</Button>
</Link>
{/* Delete typically restricted for Goods Receipts, checking permission */}
<Can permission="goods_receipts.delete">
<Button
variant="outline"
size="sm"
className="button-outlined-error"
title="刪除"
onClick={() => setShowDeleteDialog(true)}
disabled={processing}
>
<Trash2 className="h-4 w-4" />
</Button>
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle></AlertDialogTitle>
<AlertDialogDescription>
{receipt.code}
<br />
<span className="text-red-500 font-bold mt-2 block">
</span>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel className="button-outlined-primary"></AlertDialogCancel>
<AlertDialogAction
onClick={handleConfirmDelete}
className="button-filled-error"
>
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</Can>
</div>
);
}

View File

@@ -0,0 +1,46 @@
import { Badge } from "@/Components/ui/badge";
export type GoodsReceiptStatus = 'processing' | 'completed' | 'cancelled';
export const GOODS_RECEIPT_STATUS_CONFIG: Record<string, { label: string; variant: "default" | "secondary" | "destructive" | "outline" | "success" | "warning" }> = {
processing: { label: "處理中", variant: "warning" },
completed: { label: "已完成", variant: "success" },
cancelled: { label: "已取消", variant: "destructive" },
};
interface GoodsReceiptStatusBadgeProps {
status: string;
className?: string;
}
export default function GoodsReceiptStatusBadge({
status,
className,
}: GoodsReceiptStatusBadgeProps) {
const config = GOODS_RECEIPT_STATUS_CONFIG[status] || { label: "未知", variant: "outline" };
// Apply custom styling based on variant mapping if not using standard badge variants
let badgeClass = "";
switch (config.variant) {
case "success":
badgeClass = "bg-green-100 text-green-800 hover:bg-green-200 border-green-200";
break;
case "warning":
badgeClass = "bg-yellow-100 text-yellow-800 hover:bg-yellow-200 border-yellow-200";
break;
case "destructive":
badgeClass = "bg-red-100 text-red-800 hover:bg-red-200 border-red-200";
break;
default:
badgeClass = "bg-gray-100 text-gray-800 hover:bg-gray-200 border-gray-200";
}
return (
<Badge
variant="outline"
className={`${className} font-medium px-2.5 py-0.5 rounded-full border ${badgeClass}`}
>
{config.label}
</Badge>
);
}

View File

@@ -0,0 +1,258 @@
/**
* 進貨單列表表格
*/
import { useState, useMemo } from "react";
import { ArrowUpDown, ArrowUp, ArrowDown } from "lucide-react";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/Components/ui/table";
import GoodsReceiptActions, { GoodsReceipt } from "./GoodsReceiptActions";
import GoodsReceiptStatusBadge from "./GoodsReceiptStatusBadge";
import CopyButton from "@/Components/shared/CopyButton";
import { formatCurrency, formatDate } from "@/utils/format";
interface GoodsReceiptTableProps {
receipts: GoodsReceipt[];
}
type SortField = "code" | "type" | "warehouse_name" | "vendor_name" | "received_date" | "total_amount" | "status";
type SortDirection = "asc" | "desc" | null;
export default function GoodsReceiptTable({
receipts,
}: GoodsReceiptTableProps) {
const [sortField, setSortField] = useState<SortField | null>(null);
const [sortDirection, setSortDirection] = useState<SortDirection>(null);
// 處理排序
const handleSort = (field: SortField) => {
if (sortField === field) {
if (sortDirection === "asc") {
setSortDirection("desc");
} else if (sortDirection === "desc") {
setSortDirection(null);
setSortField(null);
} else {
setSortDirection("asc");
}
} else {
setSortField(field);
setSortDirection("asc");
}
};
// 類型翻譯映射
const typeMap: Record<string, string> = {
standard: "標準採購",
miscellaneous: "雜項入庫",
other: "其他入庫",
};
// 排序後的進貨單列表
const sortedReceipts = useMemo(() => {
if (!sortField || !sortDirection) {
return receipts;
}
return [...receipts].sort((a, b) => {
let aValue: string | number;
let bValue: string | number;
switch (sortField) {
case "code":
aValue = a.code;
bValue = b.code;
break;
case "type":
aValue = typeMap[a.status] || a.status; // status here might actually refer to type in existing code logic? Let's use a.type if it exists.
// Checking if 'type' is in receipt - based on implementation plan we want it.
// Currently GoodsReceipt model HAS type.
// @ts-ignore
aValue = typeMap[a.type] || a.type || "";
// @ts-ignore
bValue = typeMap[b.type] || b.type || "";
break;
case "warehouse_name":
aValue = a.warehouse?.name || "";
bValue = b.warehouse?.name || "";
break;
case "vendor_name":
aValue = a.vendor?.name || "";
bValue = b.vendor?.name || "";
break;
case "received_date":
aValue = a.received_date;
bValue = b.received_date;
break;
case "total_amount":
aValue = a.items_sum_total_amount || 0;
bValue = b.items_sum_total_amount || 0;
break;
case "status":
aValue = a.status;
bValue = b.status;
break;
default:
return 0;
}
if (typeof aValue === "string" && typeof bValue === "string") {
return sortDirection === "asc"
? aValue.localeCompare(bValue, "zh-TW")
: bValue.localeCompare(aValue, "zh-TW");
} else {
return sortDirection === "asc"
? (aValue as number) - (bValue as number)
: (bValue as number) - (aValue as number);
}
});
}, [receipts, sortField, sortDirection]);
const SortIcon = ({ field }: { field: SortField }) => {
if (sortField !== field) {
return <ArrowUpDown className="h-4 w-4 text-muted-foreground" />;
}
if (sortDirection === "asc") {
return <ArrowUp className="h-4 w-4 text-primary" />;
}
if (sortDirection === "desc") {
return <ArrowDown className="h-4 w-4 text-primary" />;
}
return <ArrowUpDown className="h-4 w-4 text-muted-foreground" />;
};
return (
<div className="bg-white rounded-lg border shadow-sm overflow-hidden mt-6">
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow className="bg-gray-50/50">
<TableHead className="w-[50px] text-center">#</TableHead>
<TableHead className="w-[180px]">
<button
onClick={() => handleSort("code")}
className="flex items-center gap-2 hover:text-foreground transition-colors"
>
<SortIcon field="code" />
</button>
</TableHead>
<TableHead className="w-[120px]">
<button
onClick={() => handleSort("type")}
className="flex items-center gap-2 hover:text-foreground transition-colors"
>
<SortIcon field="type" />
</button>
</TableHead>
<TableHead className="w-[180px]">
<button
onClick={() => handleSort("warehouse_name")}
className="flex items-center gap-2 hover:text-foreground transition-colors"
>
<SortIcon field="warehouse_name" />
</button>
</TableHead>
<TableHead className="w-[180px]">
<button
onClick={() => handleSort("vendor_name")}
className="flex items-center gap-2 hover:text-foreground transition-colors"
>
<SortIcon field="vendor_name" />
</button>
</TableHead>
<TableHead className="w-[150px]">
<button
onClick={() => handleSort("received_date")}
className="flex items-center gap-2 hover:text-foreground transition-colors"
>
<SortIcon field="received_date" />
</button>
</TableHead>
<TableHead className="w-[140px] text-right">
<button
onClick={() => handleSort("total_amount")}
className="flex items-center gap-2 ml-auto hover:text-foreground transition-colors"
>
<SortIcon field="total_amount" />
</button>
</TableHead>
<TableHead className="w-[120px] text-center">
<button
onClick={() => handleSort("status")}
className="flex items-center gap-2 mx-auto hover:text-foreground transition-colors"
>
<SortIcon field="status" />
</button>
</TableHead>
<TableHead className="text-center"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{sortedReceipts.length === 0 ? (
<TableRow>
<TableCell colSpan={9} className="text-center text-muted-foreground py-12">
</TableCell>
</TableRow>
) : (
sortedReceipts.map((receipt, index) => (
<TableRow key={receipt.id}>
<TableCell className="text-gray-500 font-medium text-center">
{index + 1}
</TableCell>
<TableCell>
<div className="flex items-center gap-1.5">
<span className="font-mono text-sm font-medium">{receipt.code}</span>
<CopyButton text={receipt.code} label="複製單號" />
</div>
</TableCell>
<TableCell>
<span className="text-sm">
{/* @ts-ignore */}
{typeMap[receipt.type] || receipt.type || "-"}
</span>
</TableCell>
<TableCell>
<div className="text-sm font-medium text-gray-900">
{receipt.warehouse?.name || "-"}
</div>
</TableCell>
<TableCell>
<span className="text-sm text-gray-700">{receipt.vendor?.name || "-"}</span>
</TableCell>
<TableCell>
<span className="text-sm text-gray-500">{formatDate(receipt.received_date)}</span>
</TableCell>
<TableCell className="text-right">
<span className="font-semibold text-gray-900">
{formatCurrency(receipt.items_sum_total_amount)}
</span>
</TableCell>
<TableCell className="text-center">
<GoodsReceiptStatusBadge status={receipt.status} />
</TableCell>
<TableCell className="text-center">
<GoodsReceiptActions receipt={receipt} />
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
</div>
);
}

View File

@@ -14,6 +14,17 @@ import {
TableHeader,
TableRow,
} from "@/Components/ui/table";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/Components/ui/alert-dialog";
import type { PurchaseOrderItem, Supplier } from "@/types/purchase-order";
import { formatCurrency } from "@/utils/purchase-order";
@@ -204,14 +215,35 @@ export function PurchaseOrderItemsTable({
{/* 刪除按鈕 */}
{!isReadOnly && onRemoveItem && (
<TableCell className="text-center">
<Button
variant="ghost"
size="icon"
onClick={() => onRemoveItem(index)}
className="h-8 w-8 text-gray-300 hover:text-red-500 hover:bg-red-50 transition-colors"
>
<Trash2 className="h-4 w-4" />
</Button>
<AlertDialog>
<AlertDialogTrigger asChild>
<Button
variant="outline"
size="sm"
className="button-outlined-error"
title="移除項目"
>
<Trash2 className="h-4 w-4" />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle></AlertDialogTitle>
<AlertDialogDescription>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel></AlertDialogCancel>
<AlertDialogAction
onClick={() => onRemoveItem(index)}
className="bg-red-600 hover:bg-red-700"
>
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</TableCell>
)}
</TableRow>

View File

@@ -4,6 +4,7 @@
import { Badge } from "@/Components/ui/badge";
import { PurchaseOrderStatus } from "@/types/purchase-order";
import { STATUS_CONFIG } from "@/constants/purchase-order";
interface PurchaseOrderStatusBadgeProps {
status: PurchaseOrderStatus;
@@ -14,33 +15,12 @@ export default function PurchaseOrderStatusBadge({
status,
className,
}: PurchaseOrderStatusBadgeProps) {
const getStatusConfig = (status: PurchaseOrderStatus) => {
switch (status) {
case "draft":
return { label: "草稿", className: "bg-gray-100 text-gray-700 border-gray-200" };
case "pending":
return { label: "待審核", className: "bg-blue-100 text-blue-700 border-blue-200" };
case "processing":
return { label: "處理中", className: "bg-yellow-100 text-yellow-700 border-yellow-200" };
case "shipping":
return { label: "運送中", className: "bg-purple-100 text-purple-700 border-purple-200" };
case "confirming":
return { label: "待確認", className: "bg-orange-100 text-orange-700 border-orange-200" };
case "completed":
return { label: "已完成", className: "bg-green-100 text-green-700 border-green-200" };
case "cancelled":
return { label: "已取消", className: "bg-red-100 text-red-700 border-red-200" };
default:
return { label: "未知", className: "bg-gray-100 text-gray-700 border-gray-200" };
}
};
const config = getStatusConfig(status);
const config = STATUS_CONFIG[status] || { label: "未知", variant: "outline" };
return (
<Badge
variant="outline"
className={`${config.className} ${className} font-medium px-2.5 py-0.5 rounded-full`}
variant={config.variant}
className={`${className} font-medium px-2.5 py-0.5 rounded-full`}
>
{config.label}
</Badge>

View File

@@ -10,13 +10,13 @@ interface StatusProgressBarProps {
}
// 流程步驟定義
const FLOW_STEPS: { key: PurchaseOrderStatus | "approved"; label: string }[] = [
const FLOW_STEPS: { key: PurchaseOrderStatus; label: string }[] = [
{ key: "draft", label: "草稿" },
{ key: "pending", label: "待審核" },
{ key: "processing", label: "處理中" },
{ key: "shipping", label: "運送中" },
{ key: "confirming", label: "待確認" },
{ key: "completed", label: "已完成" },
{ key: "pending", label: "簽核中" },
{ key: "approved", label: "已核准" },
{ key: "partial", label: "部分收貨" },
{ key: "completed", label: "全數收貨" },
{ key: "closed", label: "已結案" },
];
export function StatusProgressBar({ currentStatus }: StatusProgressBarProps) {
@@ -82,7 +82,7 @@ export function StatusProgressBar({ currentStatus }: StatusProgressBarProps) {
: "text-gray-400"
}`}
>
{isRejectedAtThisStep ? "已取消" : step.label}
{isRejectedAtThisStep ? "已作廢" : step.label}
</p>
</div>
</div>

View File

@@ -100,12 +100,18 @@ export default function WarehouseCard({
{/* 統計區塊 - 狀態標籤 */}
<div className="space-y-3">
{/* 銷售狀態 */}
{/* 銷售狀態與可用性說明 */}
<div className="flex items-center justify-between">
<span className="text-sm text-gray-500"></span>
<Badge variant={warehouse.is_sellable ? "default" : "secondary"} className={warehouse.is_sellable ? "bg-green-600" : "bg-gray-400"}>
{warehouse.is_sellable ? "可銷售" : "暫停銷售"}
</Badge>
<span className="text-sm text-gray-500"></span>
{warehouse.type === 'quarantine' ? (
<Badge variant="secondary" className="bg-red-100 text-red-700 border-red-200">
</Badge>
) : (
<Badge variant="default" className="bg-green-600">
</Badge>
)}
</div>
{/* 低庫存警告狀態 */}

View File

@@ -62,7 +62,6 @@ export default function WarehouseDialog({
address: string;
description: string;
type: WarehouseType;
is_sellable: boolean;
license_plate: string;
driver_name: string;
}>({
@@ -71,7 +70,6 @@ export default function WarehouseDialog({
address: "",
description: "",
type: "standard",
is_sellable: true,
license_plate: "",
driver_name: "",
});
@@ -86,7 +84,6 @@ export default function WarehouseDialog({
address: warehouse.address || "",
description: warehouse.description || "",
type: warehouse.type || "standard",
is_sellable: warehouse.is_sellable ?? true,
license_plate: warehouse.license_plate || "",
driver_name: warehouse.driver_name || "",
});
@@ -97,7 +94,6 @@ export default function WarehouseDialog({
address: "",
description: "",
type: "standard",
is_sellable: true,
license_plate: "",
driver_name: "",
});
@@ -219,25 +215,7 @@ export default function WarehouseDialog({
</div>
)}
{/* 銷售設定 */}
<div className="space-y-4">
<div className="border-b pb-2">
<h4 className="text-sm text-gray-700"></h4>
</div>
<div className="flex items-center space-x-2">
<input
type="checkbox"
id="is_sellable"
className="h-4 w-4 rounded border-gray-300 text-primary-main focus:ring-primary-main"
checked={formData.is_sellable}
onChange={(e) => setFormData({ ...formData, is_sellable: e.target.checked })}
/>
<Label htmlFor="is_sellable"></Label>
</div>
<p className="text-xs text-gray-500 ml-6">
POS
</p>
</div>
{/* 區塊 B位置 */}
<div className="space-y-4">

View File

@@ -21,10 +21,11 @@ import {
Wallet,
BarChart3,
FileSpreadsheet,
BookOpen
BookOpen,
ClipboardCheck
} from "lucide-react";
import { toast, Toaster } from "sonner";
import { useState, useEffect, useMemo } from "react";
import { useState, useEffect, useMemo, useRef } from "react";
import { Link, usePage, Head } from "@inertiajs/react";
import { cn } from "@/lib/utils";
import BreadcrumbNav, { BreadcrumbItemType } from "@/Components/shared/BreadcrumbNav";
@@ -101,10 +102,10 @@ export default function AuthenticatedLayout({
],
},
{
id: "vendor-management",
label: "廠商管理",
id: "supply-chain-management",
label: "供應鏈管理",
icon: <Truck className="h-5 w-5" />,
permission: "vendors.view",
permission: ["vendors.view", "purchase_orders.view", "goods_receipts.view"],
children: [
{
id: "vendor-list",
@@ -113,14 +114,6 @@ export default function AuthenticatedLayout({
route: "/vendors",
permission: "vendors.view",
},
],
},
{
id: "purchase-management",
label: "採購管理",
icon: <ShoppingCart className="h-5 w-5" />,
permission: "purchase_orders.view",
children: [
{
id: "purchase-order-list",
label: "採購單管理",
@@ -128,6 +121,20 @@ export default function AuthenticatedLayout({
route: "/purchase-orders",
permission: "purchase_orders.view",
},
{
id: "goods-receipt-list",
label: "進貨單管理",
icon: <ClipboardCheck className="h-4 w-4" />,
route: "/goods-receipts",
permission: "goods_receipts.view",
},
// {
// id: "delivery-note-list",
// label: "出貨單管理 (開發中)",
// icon: <Package className="h-4 w-4" />,
// // route: "/delivery-notes",
// permission: "delivery_notes.view",
// },
],
},
{
@@ -277,17 +284,21 @@ export default function AuthenticatedLayout({
}, [isCollapsed]);
// 全域監聽 flash 訊息並顯示 Toast
const lastFlash = useRef<any>(null);
useEffect(() => {
// @ts-ignore
if (props.flash?.success) {
// @ts-ignore
if (!props.flash) return;
// 檢查是否與上次顯示的訊息相同透過簡單的物件引用比對Inertia 在重導向後會產生新的 props 物件)
if (props.flash === lastFlash.current) return;
if (props.flash.success) {
toast.success(props.flash.success);
}
// @ts-ignore
if (props.flash?.error) {
// @ts-ignore
if (props.flash.error) {
toast.error(props.flash.error);
}
lastFlash.current = props.flash;
}, [props.flash]);
const toggleExpand = (itemId: string) => {

View File

@@ -71,10 +71,13 @@ export default function RoleCreate({ groupedPermissions }: Props) {
'edit': '編輯',
'delete': '刪除',
'publish': '發布',
'adjust': '新增 / 調整',
'adjust': '調整',
'transfer': '調撥',
'safety_stock': '安全庫存設定',
'export': '匯出',
'complete': '完成',
'view_cost': '檢視成本',
'view_logs': '檢視日誌',
};
return map[action] || action;

View File

@@ -78,10 +78,13 @@ export default function RoleEdit({ role, groupedPermissions, currentPermissions
'edit': '編輯',
'delete': '刪除',
'publish': '發布',
'adjust': '新增 / 調整',
'adjust': '調整',
'transfer': '調撥',
'safety_stock': '安全庫存設定',
'export': '匯出',
'complete': '完成',
'view_cost': '檢視成本',
'view_logs': '檢視日誌',
};
return map[action] || action;

View File

@@ -0,0 +1,763 @@
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
import { Head, useForm, Link } from '@inertiajs/react';
import { Button } from '@/Components/ui/button';
import { Input } from '@/Components/ui/input';
import { Label } from '@/Components/ui/label';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/Components/ui/select';
import { SearchableSelect } from '@/Components/ui/searchable-select';
import React, { useState, useEffect } from 'react';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/Components/ui/table';
import { Badge } from "@/Components/ui/badge";
import {
Search,
Trash2,
Calendar as CalendarIcon,
Save,
ArrowLeft,
Package
} from 'lucide-react';
import axios from 'axios';
import { PurchaseOrderStatus } from '@/types/purchase-order';
import { STATUS_CONFIG } from '@/constants/purchase-order';
interface BatchItem {
inventoryId: string;
batchNumber: string;
originCountry: string;
expiryDate: string | null;
quantity: number;
}
// 待進貨採購單 Item 介面
interface PendingPOItem {
id: number;
product_id: number;
product_name: string;
product_code: string;
unit: string;
quantity: number;
received_quantity: number;
remaining: number;
unit_price: number;
batchMode?: 'existing' | 'new';
originCountry?: string; // For new batch generation
}
// 待進貨採購單介面
interface PendingPO {
id: number;
code: string;
status: PurchaseOrderStatus;
vendor_id: number;
vendor_name: string;
warehouse_id: number | null;
order_date: string;
items: PendingPOItem[];
}
// 廠商介面
interface Vendor {
id: number;
name: string;
code: string;
}
interface Props {
warehouses: { id: number; name: string; type: string }[];
pendingPurchaseOrders: PendingPO[];
vendors: Vendor[];
}
export default function GoodsReceiptCreate({ warehouses, pendingPurchaseOrders, vendors }: Props) {
const [selectedPO, setSelectedPO] = useState<PendingPO | null>(null);
const [selectedVendor, setSelectedVendor] = useState<Vendor | null>(null);
const [isSearching, setIsSearching] = useState(false);
// Manual Product Search States
const [productSearch, setProductSearch] = useState('');
const [foundProducts, setFoundProducts] = useState<any[]>([]);
const { data, setData, post, processing, errors } = useForm({
type: 'standard', // 'standard', 'miscellaneous', 'other'
warehouse_id: '',
purchase_order_id: '',
vendor_id: '',
received_date: new Date().toISOString().split('T')[0],
remarks: '',
items: [] as any[],
});
// 搜尋商品 API用於雜項入庫/其他類型)
const searchProducts = async () => {
if (!productSearch) return;
setIsSearching(true);
try {
const response = await axios.get(route('goods-receipts.search-products'), {
params: { query: productSearch },
});
setFoundProducts(response.data);
} catch (error) {
console.error('Failed to search products', error);
} finally {
setIsSearching(false);
}
};
// 選擇採購單
const handleSelectPO = (po: PendingPO) => {
setSelectedPO(po);
// 將採購單項目轉換為進貨單項目,預填剩餘可收貨量
const pendingItems = po.items.map((item) => ({
product_id: item.product_id,
purchase_order_item_id: item.id,
product_name: item.product_name,
sku: item.product_code,
unit: item.unit,
quantity_ordered: item.quantity,
quantity_received_so_far: item.received_quantity,
quantity_received: item.remaining, // 預填剩餘量
unit_price: item.unit_price,
batch_number: '',
batchMode: 'new',
originCountry: 'TW',
expiry_date: '',
}));
setData((prev) => ({
...prev,
purchase_order_id: po.id.toString(),
vendor_id: po.vendor_id.toString(),
warehouse_id: po.warehouse_id ? po.warehouse_id.toString() : prev.warehouse_id,
items: pendingItems,
}));
};
// 選擇廠商(雜項入庫/其他)
const handleSelectVendor = (vendorId: string) => {
const vendor = vendors.find(v => v.id.toString() === vendorId);
if (vendor) {
setSelectedVendor(vendor);
setData('vendor_id', vendor.id.toString());
}
};
const handleAddProduct = (product: any) => {
const newItem = {
product_id: product.id,
product_name: product.name,
sku: product.code,
quantity_received: 0,
unit_price: product.price || 0,
batch_number: '',
batchMode: 'new',
originCountry: 'TW',
expiry_date: '',
};
setData('items', [...data.items, newItem]);
setFoundProducts([]);
setProductSearch('');
};
const removeItem = (index: number) => {
const newItems = [...data.items];
newItems.splice(index, 1);
setData('items', newItems);
};
const updateItem = (index: number, field: string, value: any) => {
const newItems = [...data.items];
newItems[index] = { ...newItems[index], [field]: value };
setData('items', newItems);
};
// Generate batch preview (Added)
const getBatchPreview = (productId: number, productCode: string, country: string, dateStr: string) => {
if (!productCode || !productId) return "--";
try {
const datePart = dateStr.includes('T') ? dateStr.split('T')[0] : dateStr;
const [yyyy, mm, dd] = datePart.split('-');
const dateFormatted = `${yyyy}${mm}${dd}`;
const seqKey = `${productId}-${country}-${datePart}`;
// Handle sequence. Note: nextSequences values are numbers.
const seq = nextSequences[seqKey]?.toString().padStart(2, '0') || "01";
return `${productCode}-${country}-${dateFormatted}-${seq}`;
} catch (e) {
return "--";
}
};
// Batch management
const [batchesCache, setBatchesCache] = useState<Record<string, BatchItem[]>>({});
const [nextSequences, setNextSequences] = useState<Record<string, number>>({});
// Fetch batches and sequence for a product
const fetchProductBatches = async (productId: number, country: string = 'TW', dateStr: string = '') => {
if (!data.warehouse_id) return;
const cacheKey = `${productId}-${data.warehouse_id}`;
try {
const today = new Date().toISOString().split('T')[0];
const targetDate = dateStr || data.received_date || today;
// Adjust API endpoint to match AddInventory logic
// Assuming GoodsReceiptController or existing WarehouseController can handle this.
// Using the same endpoint as AddInventory: /api/warehouses/{id}/inventory/batches/{productId}
const response = await axios.get(
`/api/warehouses/${data.warehouse_id}/inventory/batches/${productId}`,
{
params: {
origin_country: country,
arrivalDate: targetDate
}
}
);
if (response.data) {
// Update existing batches list
if (response.data.batches) {
setBatchesCache(prev => ({
...prev,
[cacheKey]: response.data.batches
}));
}
// Update next sequence for new batch generation
if (response.data.nextSequence !== undefined) {
const seqKey = `${productId}-${country}-${targetDate}`;
setNextSequences(prev => ({
...prev,
[seqKey]: parseInt(response.data.nextSequence)
}));
}
}
} catch (error) {
console.error("Failed to fetch batches", error);
}
};
// Trigger batch fetch when relevant fields change
useEffect(() => {
data.items.forEach(item => {
if (item.product_id && data.warehouse_id) {
const country = item.originCountry || 'TW';
const date = data.received_date;
fetchProductBatches(item.product_id, country, date);
}
});
}, [data.items.length, data.warehouse_id, data.received_date, JSON.stringify(data.items.map(i => i.originCountry))]);
useEffect(() => {
data.items.forEach((item, index) => {
if (item.batchMode === 'new' && item.originCountry && data.received_date) {
const country = item.originCountry;
// Use date from form or today
const dateStr = data.received_date || new Date().toISOString().split('T')[0];
const seqKey = `${item.product_id}-${country}-${dateStr}`;
const seq = nextSequences[seqKey]?.toString().padStart(3, '0') || '001';
// Only generate if we have a sequence (or default)
// Note: fetch might not have returned yet, so seq might be default 001 until fetch updates nextSequences
const datePart = dateStr.replace(/-/g, '');
const generatedBatch = `${item.sku}-${country}-${datePart}-${seq}`;
if (item.batch_number !== generatedBatch) {
// Update WITHOUT triggering re-render loop
// Need a way to update item silently or check condition carefully
// Using setBatchNumber might trigger this effect again but value will be same.
const newItems = [...data.items];
newItems[index].batch_number = generatedBatch;
setData('items', newItems);
}
}
});
}, [nextSequences, JSON.stringify(data.items.map(i => ({ m: i.batchMode, c: i.originCountry, s: i.sku, p: i.product_id }))), data.received_date]);
const submit = (e: React.FormEvent) => {
e.preventDefault();
post(route('goods-receipts.store'));
};
return (
<AuthenticatedLayout
breadcrumbs={[
{ label: '供應鏈管理', href: '#' },
{ label: '進貨單管理', href: route('goods-receipts.index') },
{ label: '新增進貨單', href: route('goods-receipts.create'), isPage: true },
]}
>
<Head title="新增進貨單" />
<div className="container mx-auto p-6 max-w-7xl">
{/* Header */}
<div className="mb-6">
<Link href={route('goods-receipts.index')}>
<Button variant="outline" className="gap-2 mb-4 w-fit">
<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>
<div className="space-y-6">
{/* Step 0: Select Type */}
<div className="bg-white rounded-lg border shadow-sm p-6">
<Label className="text-sm font-bold mb-3 block"></Label>
<div className="flex gap-4">
{[
{ id: 'standard', label: '標準採購', desc: '從採購單帶入' },
{ id: 'miscellaneous', label: '雜項入庫', desc: '非採購之入庫' },
{ id: 'other', label: '其他', desc: '其他原因入庫' },
].map((t) => (
<button
key={t.id}
onClick={() => {
setData((prev) => ({
...prev,
type: t.id,
purchase_order_id: '',
items: [],
vendor_id: t.id === 'standard' ? prev.vendor_id : '',
}));
setSelectedPO(null);
if (t.id !== 'standard') setSelectedVendor(null);
}}
className={`flex-1 p-4 rounded-xl border-2 text-left transition-all ${data.type === t.id
? 'border-primary-main bg-primary-main/5'
: 'border-gray-100 hover:border-gray-200'
}`}
>
<div className={`font-bold ${data.type === t.id ? 'text-primary-main' : 'text-gray-700'}`}>
{t.label}
</div>
<div className="text-xs text-gray-500">{t.desc}</div>
</button>
))}
</div>
</div>
{/* Step 1: Source Selection */}
<div className="bg-white rounded-lg border shadow-sm overflow-hidden">
<div className="p-6 bg-gray-50/50 border-b flex items-center gap-3">
<div className={`w-8 h-8 rounded-full flex items-center justify-center font-bold text-sm ${(data.type === 'standard' ? !!selectedPO : !!selectedVendor)
? 'bg-green-500 text-white shadow-sm' : 'bg-primary-main text-white shadow-sm'}`}>
{(data.type === 'standard' ? selectedPO : selectedVendor) ? '✓' : '1'}
</div>
<h2 className="text-lg font-bold text-gray-800">
{data.type === 'standard' ? '選擇來源採購單' : '選擇供應商'}
</h2>
</div>
<div className="p-6">
{data.type === 'standard' ? (
!selectedPO ? (
<div className="space-y-4">
<Label className="text-sm font-medium text-gray-700"></Label>
{pendingPurchaseOrders.length === 0 ? (
<div className="text-center py-8 text-gray-500 bg-gray-50 rounded-lg border border-dashed">
</div>
) : (
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
<Table>
<TableHeader className="bg-gray-50">
<TableRow>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-center"></TableHead>
<TableHead className="text-center"></TableHead>
<TableHead className="w-[100px] text-center"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{pendingPurchaseOrders.map((po) => (
<TableRow key={po.id} className="hover:bg-gray-50/50">
<TableCell className="font-medium text-primary-main">{po.code}</TableCell>
<TableCell>{po.vendor_name}</TableCell>
<TableCell className="text-center">
<Badge variant={STATUS_CONFIG[po.status]?.variant || 'outline'}>
{STATUS_CONFIG[po.status]?.label || po.status}
</Badge>
</TableCell>
<TableCell className="text-center text-gray-600">
{po.items.length}
</TableCell>
<TableCell className="text-center">
<Button size="sm" onClick={() => handleSelectPO(po)} className="button-filled-primary">
</Button>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
)}
</div>
) : (
<div className="flex items-center justify-between bg-primary-main/5 p-4 rounded-xl border border-primary-main/20">
<div className="flex gap-8">
<div>
<span className="text-xs text-gray-500 block"></span>
<span className="font-bold text-primary-main">{selectedPO.code}</span>
</div>
<div>
<span className="text-xs text-gray-500 block"></span>
<span className="font-bold text-gray-800">{selectedPO.vendor_name}</span>
</div>
<div>
<span className="text-xs text-gray-500 block"></span>
<span className="font-bold text-gray-800">{selectedPO.items.length} </span>
</div>
</div>
<Button variant="ghost" size="sm" onClick={() => setSelectedPO(null)} className="text-gray-500 hover:text-red-500">
</Button>
</div>
)
) : (
!selectedVendor ? (
<div className="space-y-4">
<div className="space-y-2">
<Label className="text-sm font-medium text-gray-700"></Label>
<SearchableSelect
value=""
onValueChange={handleSelectVendor}
options={vendors.map(v => ({
label: `${v.name} (${v.code})`,
value: v.id.toString()
}))}
placeholder="選擇供應商..."
searchPlaceholder="搜尋供應商..."
className="h-9 w-full max-w-md"
/>
</div>
{vendors.length === 0 && (
<div className="text-center py-8 text-gray-500 bg-gray-50 rounded-lg border border-dashed">
</div>
)}
</div>
) : (
<div className="flex items-center justify-between bg-primary-main/5 p-4 rounded-xl border border-primary-main/20">
<div className="flex gap-8">
<div>
<span className="text-xs text-gray-500 block"></span>
<span className="font-bold text-primary-main">{selectedVendor.name}</span>
</div>
<div>
<span className="text-xs text-gray-500 block"></span>
<span className="font-bold text-gray-800">{selectedVendor.code}</span>
</div>
</div>
<Button variant="ghost" size="sm" onClick={() => setSelectedVendor(null)} className="text-gray-500 hover:text-red-500">
</Button>
</div>
)
)}
</div>
</div>
{/* Step 2: Details & Items */}
{((data.type === 'standard' && selectedPO) || (data.type !== 'standard' && selectedVendor)) && (
<div className="bg-white rounded-lg border shadow-sm overflow-hidden animate-in fade-in slide-in-from-bottom-4 duration-500">
<div className="p-6 bg-gray-50/50 border-b flex items-center gap-3">
<div className="w-8 h-8 rounded-full bg-primary-main text-white flex items-center justify-center font-bold text-sm shadow-sm">2</div>
<h2 className="text-lg font-bold text-gray-800"></h2>
</div>
<div className="p-6 space-y-8">
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
<div className="space-y-2">
<Label htmlFor="warehouse_id"> <span className="text-red-500">*</span></Label>
<Select
value={data.warehouse_id}
onValueChange={(val) => setData('warehouse_id', val)}
>
<SelectTrigger className="h-9">
<SelectValue placeholder="選擇倉庫" />
</SelectTrigger>
<SelectContent>
{warehouses.map(w => (
<SelectItem key={w.id} value={w.id.toString()}>{w.name} ({w.type})</SelectItem>
))}
</SelectContent>
</Select>
{errors.warehouse_id && <p className="text-red-500 text-xs">{errors.warehouse_id}</p>}
</div>
<div className="space-y-2">
<Label htmlFor="received_date"> <span className="text-red-500">*</span></Label>
<div className="relative">
<CalendarIcon className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={data.received_date}
onChange={(e) => setData('received_date', e.target.value)}
className="pl-9 h-9 block w-full"
/>
</div>
{errors.received_date && <p className="text-red-500 text-xs">{errors.received_date}</p>}
</div>
<div className="space-y-2">
<Label htmlFor="remarks"></Label>
<Input
value={data.remarks}
onChange={(e) => setData('remarks', e.target.value)}
className="h-9"
placeholder="選填..."
/>
</div>
</div>
<div className="space-y-4">
<div className="flex items-center justify-between">
<h3 className="font-bold text-gray-700"></h3>
{data.type !== 'standard' && (
<div className="flex gap-2 items-center">
<div className="relative">
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
<Input
placeholder="搜尋商品加入..."
value={productSearch}
onChange={(e) => setProductSearch(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && searchProducts()}
className="h-9 w-64 pl-9"
/>
{foundProducts.length > 0 && (
<div className="absolute top-10 left-0 w-full bg-white border rounded-lg shadow-xl z-50 max-h-60 overflow-y-auto">
{foundProducts.map(p => (
<button
key={p.id}
onClick={() => handleAddProduct(p)}
className="w-full text-left p-3 hover:bg-gray-50 border-b last:border-0 flex flex-col"
>
<span className="font-bold text-sm">{p.name}</span>
<span className="text-xs text-gray-500">{p.code}</span>
</button>
))}
</div>
)}
</div>
<Button onClick={searchProducts} disabled={isSearching} size="sm" className="button-filled-primary h-9">
</Button>
</div>
)}
</div>
{/* Calculated Totals for usage in Table Footer or Summary */}
{(() => {
const subTotal = data.items.reduce((acc, item) => {
const qty = parseFloat(item.quantity_received) || 0;
const price = parseFloat(item.unit_price) || 0;
return acc + (qty * price);
}, 0);
const taxAmount = Math.round(subTotal * 0.05);
const grandTotal = subTotal + taxAmount;
return (
<>
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
<Table>
<TableHeader className="bg-gray-50/50">
<TableRow>
<TableHead className="w-[180px]"></TableHead>
<TableHead className="w-[80px] text-center"></TableHead>
<TableHead className="w-[80px] text-center"></TableHead>
<TableHead className="w-[120px]"> <span className="text-red-500">*</span></TableHead>
<TableHead className="w-[200px]"> <span className="text-red-500">*</span></TableHead>
<TableHead className="w-[150px]"></TableHead>
<TableHead className="w-[80px] text-right"></TableHead>
<TableHead className="w-[50px]"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{data.items.length === 0 ? (
<TableRow>
<TableCell colSpan={8} className="text-center py-8 text-gray-400 italic">
</TableCell>
</TableRow>
) : (
data.items.map((item, index) => {
const errorKey = `items.${index}.quantity_received` as keyof typeof errors;
const itemTotal = (parseFloat(item.quantity_received || 0) * parseFloat(item.unit_price || 0));
return (
<TableRow key={index} className="hover:bg-gray-50/50 text-sm">
{/* Product Info */}
<TableCell>
<div className="flex flex-col">
<span className="font-medium text-gray-900">{item.product_name}</span>
<span className="text-xs text-gray-500">{item.sku}</span>
</div>
</TableCell>
{/* Total Quantity */}
<TableCell className="text-center">
<span className="text-gray-500 text-sm">
{Math.round(item.quantity_ordered)}
</span>
</TableCell>
{/* Remaining */}
<TableCell className="text-center">
<span className="text-gray-900 font-medium text-sm">
{Math.round(item.quantity_ordered - item.quantity_received_so_far)}
</span>
</TableCell>
{/* Received Quantity */}
<TableCell>
<Input
type="number"
step="1"
min="0"
value={item.quantity_received}
onChange={(e) => updateItem(index, 'quantity_received', e.target.value)}
className={`w-full ${(errors as any)[errorKey] ? 'border-red-500' : ''}`}
/>
{(errors as any)[errorKey] && (
<p className="text-xs text-red-500 mt-1">{(errors as any)[errorKey]}</p>
)}
</TableCell>
{/* Batch Settings */}
<TableCell>
<div className="flex gap-2 items-center">
<Input
value={item.originCountry || 'TW'}
onChange={(e) => updateItem(index, 'originCountry', e.target.value.toUpperCase().slice(0, 2))}
placeholder="產地"
maxLength={2}
className="w-16 text-center px-1"
/>
<div className="flex-1 text-sm font-mono bg-gray-50 px-3 py-2 rounded text-gray-600 truncate">
{getBatchPreview(item.product_id, item.sku, item.originCountry || 'TW', data.received_date)}
</div>
</div>
</TableCell>
{/* Expiry Date */}
<TableCell>
<div className="relative">
<CalendarIcon className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={item.expiry_date}
onChange={(e) => updateItem(index, 'expiry_date', e.target.value)}
className={`pl-9 ${item.batchMode === 'existing' ? 'bg-gray-50' : ''}`}
disabled={item.batchMode === 'existing'}
/>
</div>
</TableCell>
{/* Subtotal */}
<TableCell className="text-right font-medium">
${itemTotal.toLocaleString()}
</TableCell>
{/* Actions */}
<TableCell>
<Button
type="button"
variant="ghost"
size="icon"
onClick={() => removeItem(index)}
className="hover:bg-red-50 hover:text-red-600 h-8 w-8"
>
<Trash2 className="h-4 w-4" />
</Button>
</TableCell>
</TableRow>
);
})
)}
</TableBody>
</Table>
</div>
<div className="mt-6 flex justify-end">
<div className="w-full max-w-sm bg-primary/5 px-6 py-4 rounded-xl border border-primary/10 flex flex-col gap-3">
<div className="flex justify-between items-center w-full">
<span className="text-sm text-gray-500 font-medium"></span>
<span className="text-lg font-bold text-gray-700">${subTotal.toLocaleString()}</span>
</div>
<div className="flex justify-between items-center w-full">
<span className="text-sm text-gray-500 font-medium"> (5%)</span>
<span className="text-lg font-bold text-gray-700">${taxAmount.toLocaleString()}</span>
</div>
<div className="h-px bg-primary/10 w-full my-1"></div>
<div className="flex justify-between items-end w-full">
<span className="text-sm text-gray-500 font-medium mb-1"></span>
<span className="text-2xl font-black text-primary">
${grandTotal.toLocaleString()}
</span>
</div>
</div>
</div>
</>
);
})()}
</div>
</div>
</div>
)}
</div>
{/* Bottom Action Bar */}
<div className="flex items-center justify-end gap-4 py-6 border-t border-gray-100 mt-6">
<Button variant="ghost" className="h-11 px-6 text-gray-500 hover:text-gray-700" onClick={() => window.history.back()}>
</Button>
<Button
size="lg"
className="button-filled-primary px-12 h-14 rounded-xl shadow-lg text-lg font-bold transition-all hover:scale-[1.02] active:scale-[0.98]"
onClick={submit}
disabled={processing || (data.type === 'standard' ? !selectedPO : !selectedVendor)}
>
<Save className="mr-2 h-5 w-5" />
{processing ? '處理中...' : '確認進貨'}
</Button>
</div>
</div>
</AuthenticatedLayout >
);
}

View File

@@ -0,0 +1,328 @@
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
import { Head, Link, router } from '@inertiajs/react';
import { Button } from '@/Components/ui/button';
import { Plus, Search, FileText, RotateCcw, Calendar, ChevronDown, ChevronUp } from 'lucide-react';
import { Input } from '@/Components/ui/input';
import { Label } from '@/Components/ui/label';
import { SearchableSelect } from '@/Components/ui/searchable-select';
import Pagination from '@/Components/shared/Pagination';
import { useState, useEffect } from 'react';
import { Can } from '@/Components/Permission/Can';
import { getDateRange } from '@/utils/format';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/Components/ui/select';
import GoodsReceiptTable from '@/Components/Inventory/GoodsReceiptTable';
interface Warehouse {
id: number;
name: string;
type: string;
}
interface Filters {
search?: string;
status?: string;
warehouse_id?: string;
date_start?: string;
date_end?: string;
per_page?: string;
}
interface Props {
receipts: any;
filters: Filters;
warehouses: Warehouse[];
}
export default function GoodsReceiptIndex({ receipts, filters, warehouses }: Props) {
const [search, setSearch] = useState(filters.search || '');
const [status, setStatus] = useState(filters.status || 'all');
const [warehouseId, setWarehouseId] = useState(filters.warehouse_id || 'all');
const [dateStart, setDateStart] = useState(filters.date_start || '');
const [dateEnd, setDateEnd] = useState(filters.date_end || '');
const [perPage, setPerPage] = useState(filters.per_page || '10');
const [dateRangeType, setDateRangeType] = useState('custom');
// Advanced Filter Toggle
const [showAdvanced, setShowAdvanced] = useState(
!!(filters.date_start || filters.date_end)
);
// Sync filters from props
useEffect(() => {
setSearch(filters.search || '');
setStatus(filters.status || 'all');
setWarehouseId(filters.warehouse_id || 'all');
setDateStart(filters.date_start || '');
setDateEnd(filters.date_end || '');
setPerPage(filters.per_page || '10');
}, [filters]);
const handleFilter = () => {
router.get(route('goods-receipts.index'), {
search,
status: status !== 'all' ? status : undefined,
warehouse_id: warehouseId !== 'all' ? warehouseId : undefined,
date_start: dateStart || undefined,
date_end: dateEnd || undefined,
per_page: perPage,
}, { preserveState: true, replace: true });
};
const handleReset = () => {
setSearch('');
setStatus('all');
setWarehouseId('all');
setDateStart('');
setDateEnd('');
setDateRangeType('custom');
setPerPage('10');
router.get(route('goods-receipts.index'), {}, { preserveState: false });
};
const handleDateRangeChange = (type: string) => {
setDateRangeType(type);
if (type === 'custom') return;
const { start, end } = getDateRange(type);
setDateStart(start);
setDateEnd(end);
};
const handlePerPageChange = (value: string) => {
setPerPage(value);
router.get(route('goods-receipts.index'), {
search,
status: status !== 'all' ? status : undefined,
warehouse_id: warehouseId !== 'all' ? warehouseId : undefined,
date_start: dateStart || undefined,
date_end: dateEnd || undefined,
per_page: value,
}, { preserveState: true, preserveScroll: true, replace: true });
};
const statusOptions = [
{ label: '全部狀態', value: 'all' },
{ label: '已完成', value: 'completed' },
{ label: '處理中', value: 'processing' },
];
const warehouseOptions = [
{ label: '全部倉庫', value: 'all' },
...warehouses.map(w => ({ label: w.name, value: w.id.toString() }))
];
return (
<AuthenticatedLayout
breadcrumbs={[
{ label: '供應鏈管理', href: '#' },
{ label: '進貨單管理', href: route('goods-receipts.index'), isPage: true },
]}
>
<Head title="進貨單管理" />
<div className="container mx-auto p-6 max-w-7xl">
{/* Header Section */}
<div className="flex items-center justify-between mb-6">
<div>
<h1 className="text-2xl font-bold text-gray-900 flex items-center gap-2">
<FileText className="h-6 w-6 text-primary-main" />
</h1>
<p className="text-gray-500 mt-1">
</p>
</div>
<Can permission="goods_receipts.create">
<Link href={route('goods-receipts.create')}>
<Button className="button-filled-primary">
<Plus className="mr-2 h-4 w-4" />
</Button>
</Link>
</Can>
</div>
{/* Filter Bar */}
<div className="bg-white p-5 rounded-lg shadow-sm border border-gray-200 mb-6">
{/* Row 1: Search, Status, Warehouse */}
<div className="grid grid-cols-1 md:grid-cols-12 gap-4 mb-4">
<div className="md:col-span-4 space-y-1">
<Label className="text-xs font-medium text-grey-1"></Label>
<div className="relative">
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4" />
<Input
placeholder="搜尋單號..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-10 h-9 block"
onKeyDown={(e) => e.key === 'Enter' && handleFilter()}
/>
</div>
</div>
<div className="md:col-span-4 space-y-1">
<Label className="text-xs font-medium text-grey-1"></Label>
<Select value={status} onValueChange={setStatus}>
<SelectTrigger className="h-9">
<SelectValue placeholder="選擇狀態" />
</SelectTrigger>
<SelectContent>
{statusOptions.map(opt => (
<SelectItem key={opt.value} value={opt.value}>{opt.label}</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="md:col-span-4 space-y-1">
<Label className="text-xs font-medium text-grey-1"></Label>
<SearchableSelect
value={warehouseId}
onValueChange={setWarehouseId}
options={warehouseOptions}
placeholder="選擇倉庫"
className="w-full h-9"
showSearch={warehouses.length > 10}
/>
</div>
</div>
{/* Row 2: Date Filters (Collapsible) */}
{showAdvanced && (
<div className="grid grid-cols-1 md:grid-cols-12 gap-4 items-end animate-in fade-in slide-in-from-top-2 duration-200">
<div className="md:col-span-6 space-y-2">
<Label className="text-xs font-medium text-grey-1"></Label>
<div className="flex flex-wrap gap-2">
{[
{ label: "今日", value: "today" },
{ label: "昨日", value: "yesterday" },
{ label: "本週", value: "this_week" },
{ label: "本月", value: "this_month" },
{ label: "上月", value: "last_month" },
].map((opt) => (
<Button
key={opt.value}
size="sm"
onClick={() => handleDateRangeChange(opt.value)}
className={
dateRangeType === opt.value
? 'button-filled-primary h-9 px-4 shadow-sm'
: 'button-outlined-primary h-9 px-4 bg-white'
}
>
{opt.label}
</Button>
))}
</div>
</div>
<div className="md:col-span-6">
<div className="grid grid-cols-2 gap-4 items-end">
<div className="space-y-1">
<Label className="text-xs text-grey-2 font-medium"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={dateStart}
onChange={(e) => {
setDateStart(e.target.value);
setDateRangeType('custom');
}}
className="pl-9 block w-full h-9 bg-white"
/>
</div>
</div>
<div className="space-y-1">
<Label className="text-xs text-grey-2 font-medium"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
type="date"
value={dateEnd}
onChange={(e) => {
setDateEnd(e.target.value);
setDateRangeType('custom');
}}
className="pl-9 block w-full h-9 bg-white text-left"
/>
</div>
</div>
</div>
</div>
</div>
)}
<div className="flex items-center justify-end border-t border-gray-100 pt-5 gap-3 mt-4">
<Button
variant="ghost"
size="sm"
onClick={() => setShowAdvanced(!showAdvanced)}
className="mr-auto text-gray-500 hover:text-gray-900 h-9"
>
{showAdvanced ? (
<>
<ChevronUp className="h-4 w-4 mr-1" />
</>
) : (
<>
<ChevronDown className="h-4 w-4 mr-1" />
{(dateStart || dateEnd) && (
<span className="ml-2 w-2 h-2 rounded-full bg-primary-main" />
)}
</>
)}
</Button>
<Button
variant="outline"
onClick={handleReset}
className="flex items-center gap-2 button-outlined-primary h-9"
>
<RotateCcw className="h-4 w-4" />
</Button>
<Button
onClick={handleFilter}
className="flex items-center gap-2 button-filled-primary h-9 px-6"
>
<Search className="h-4 w-4" />
</Button>
</div>
</div>
{/* Table Section */}
<GoodsReceiptTable receipts={receipts.data} />
{/* Pagination */}
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
<div className="flex items-center gap-2 text-sm text-gray-500">
<span></span>
<SearchableSelect
value={perPage}
onValueChange={handlePerPageChange}
options={[
{ label: "10", value: "10" },
{ label: "20", value: "20" },
{ label: "50", value: "50" },
{ label: "100", value: "100" }
]}
className="w-[100px] h-8"
showSearch={false}
/>
<span></span>
</div>
<Pagination links={receipts.links} />
</div>
</div>
</AuthenticatedLayout>
);
}

View File

@@ -0,0 +1,221 @@
/**
* 查看進貨單詳情頁面
*/
import { ArrowLeft, Package } from "lucide-react";
import { Button } from "@/Components/ui/button";
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
import { Head, Link } from "@inertiajs/react";
import GoodsReceiptStatusBadge from "@/Components/Inventory/GoodsReceiptStatusBadge";
import CopyButton from "@/Components/shared/CopyButton";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/Components/ui/table";
import { formatCurrency, formatDate, formatDateTime } from "@/utils/format";
import { getShowBreadcrumbs } from "@/utils/breadcrumb";
interface GoodsReceiptItem {
id: number;
product_id: number;
product: {
id: number;
name: string;
code: string;
baseUnit?: {
name: string;
};
};
quantity_received: string | number;
unit_price: string | number;
total_amount: string | number;
batch_number?: string;
expiry_date?: string;
}
interface GoodsReceipt {
id: number;
code: string;
type: string;
received_date: string;
status: string;
remark?: string;
warehouse?: {
name: string;
};
vendor?: {
name: string;
};
items: GoodsReceiptItem[];
items_sum_total_amount: number;
created_at: string;
}
interface Props {
receipt: GoodsReceipt;
}
export default function ViewGoodsReceiptPage({ receipt }: Props) {
const typeMap: Record<string, string> = {
standard: "標準採購進貨",
miscellaneous: "雜項入庫",
other: "其他入庫",
};
return (
<AuthenticatedLayout breadcrumbs={getShowBreadcrumbs("goodsReceipts", `詳情 (#${receipt.code})`)}>
<Head title={`進貨單詳情 - ${receipt.code}`} />
<div className="container mx-auto p-6 max-w-7xl">
{/* Header */}
<div className="mb-6">
<Link href="/goods-receipts">
<Button
variant="outline"
className="gap-2 button-outlined-primary mb-6"
>
<ArrowLeft className="h-4 w-4" />
</Button>
</Link>
<div className="flex items-center justify-between mb-6">
<div>
<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">{receipt.code}</p>
</div>
<div className="flex items-center gap-3">
<GoodsReceiptStatusBadge status={receipt.status} />
</div>
</div>
</div>
<div className="grid grid-cols-1 gap-8">
{/* 基本資訊卡片 */}
<div className="bg-white rounded-lg border shadow-sm p-6">
<h2 className="text-lg font-bold text-gray-900 mb-6 border-b pb-4"></h2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-x-8 gap-y-6">
<div>
<span className="text-sm text-gray-500 block mb-1"></span>
<div className="flex items-center gap-1.5">
<span className="font-mono font-medium text-gray-900">{receipt.code}</span>
<CopyButton text={receipt.code} label="複製單號" />
</div>
</div>
<div>
<span className="text-sm text-gray-500 block mb-1"></span>
<span className="font-medium text-gray-900">{typeMap[receipt.type] || receipt.type}</span>
</div>
<div>
<span className="text-sm text-gray-500 block mb-1"></span>
<span className="font-medium text-gray-900">{receipt.warehouse?.name || "-"}</span>
</div>
<div>
<span className="text-sm text-gray-500 block mb-1"></span>
<span className="font-medium text-gray-900">{receipt.vendor?.name || "-"}</span>
</div>
<div>
<span className="text-sm text-gray-500 block mb-1"></span>
<span className="font-medium text-gray-900">{formatDate(receipt.received_date)}</span>
</div>
<div>
<span className="text-sm text-gray-500 block mb-1"></span>
<span className="font-medium text-gray-900">{formatDateTime(receipt.created_at)}</span>
</div>
</div>
{receipt.remark && (
<div className="mt-8 pt-6 border-t border-gray-100">
<span className="text-sm text-gray-500 block mb-2"></span>
<p className="text-sm text-gray-700 bg-gray-50 p-4 rounded-lg leading-relaxed">
{receipt.remark}
</p>
</div>
)}
</div>
{/* 品項清單卡片 */}
<div className="bg-white rounded-lg border shadow-sm overflow-hidden">
<div className="p-6 border-b border-gray-100">
<h2 className="text-lg font-bold text-gray-900"></h2>
</div>
<div className="p-0">
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow className="bg-gray-50/50">
<TableHead className="w-[80px] text-center">#</TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-center"></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{receipt.items.length === 0 ? (
<TableRow>
<TableCell colSpan={8} className="h-24 text-center text-gray-500">
</TableCell>
</TableRow>
) : (
receipt.items.map((item, index) => (
<TableRow key={item.id}>
<TableCell className="text-center text-gray-500">{index + 1}</TableCell>
<TableCell>
<div className="flex flex-col">
<span className="font-medium text-gray-900">{item.product.name}</span>
<span className="text-xs text-gray-500 font-mono">{item.product.code}</span>
</div>
</TableCell>
<TableCell className="text-right font-medium">
{Number(item.quantity_received).toLocaleString()}
</TableCell>
<TableCell className="text-center">
{item.product.baseUnit?.name || "個"}
</TableCell>
<TableCell className="text-right">
{formatCurrency(Number(item.unit_price))}
</TableCell>
<TableCell className="text-right font-bold text-primary">
{formatCurrency(Number(item.total_amount))}
</TableCell>
<TableCell>
<span className="text-sm font-mono">{item.batch_number || "-"}</span>
</TableCell>
<TableCell>
<span className="text-sm">{item.expiry_date ? formatDate(item.expiry_date) : "-"}</span>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
{/* 總計 */}
<div className="p-6 border-t border-gray-100 flex justify-end">
<div className="w-full max-w-xs bg-gray-50/50 px-6 py-4 rounded-xl border border-gray-100 flex flex-col gap-3">
<div className="flex justify-between items-end w-full">
<span className="text-sm text-gray-500 font-medium mb-1"></span>
<span className="text-2xl font-black text-primary">
{formatCurrency(receipt.items_sum_total_amount)}
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</AuthenticatedLayout>
);
}

View File

@@ -3,7 +3,7 @@
*/
import { useState, useEffect } from "react";
import { Plus, Factory, Search, RotateCcw, Eye, Pencil } from 'lucide-react';
import { Plus, Factory, Search, RotateCcw, Eye, Pencil, Trash2 } from 'lucide-react';
import { Button } from "@/Components/ui/button";
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
import { Head, router, Link } from "@inertiajs/react";
@@ -254,16 +254,33 @@ export default function ProductionIndex({ productionOrders, filters }: Props) {
</Link>
</Can>
)}
<Link href={route('production-orders.show', order.id)}>
<Can permission="production_orders.view">
<Link href={route('production-orders.show', order.id)}>
<Button
variant="outline"
size="sm"
className="button-outlined-primary"
title="檢視"
>
<Eye className="h-4 w-4" />
</Button>
</Link>
</Can>
<Can permission="production_orders.delete">
<Button
variant="outline"
size="sm"
className="button-outlined-primary"
title="檢視"
className="button-outlined-error"
title="刪除"
onClick={() => {
if (confirm('確定要刪除此生產工單嗎?')) {
router.delete(route('production-orders.destroy', order.id));
}
}}
>
<Eye className="h-4 w-4" />
<Trash2 className="h-4 w-4" />
</Button>
</Link>
</Can>
</div>
</TableCell>
</TableRow>
@@ -296,6 +313,6 @@ export default function ProductionIndex({ productionOrders, filters }: Props) {
</div>
</div>
</div>
</AuthenticatedLayout>
</AuthenticatedLayout >
);
}

View File

@@ -14,6 +14,18 @@ import { Input } from "@/Components/ui/input";
import { Label } from "@/Components/ui/label";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/Components/ui/table";
import { Badge } from "@/Components/ui/badge";
import { Can } from "@/Components/Permission/Can";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/Components/ui/alert-dialog";
interface Recipe {
id: number;
@@ -98,12 +110,14 @@ export default function RecipeIndex({ recipes, filters }: Props) {
</p>
</div>
<div className="flex gap-2">
<Link href={route('recipes.create')}>
<Button className="gap-2 button-filled-primary">
<Plus className="h-4 w-4" />
</Button>
</Link>
<Can permission="recipes.create">
<Link href={route('recipes.create')}>
<Button className="gap-2 button-filled-primary">
<Plus className="h-4 w-4" />
</Button>
</Link>
</Can>
</div>
</div>
@@ -207,25 +221,50 @@ export default function RecipeIndex({ recipes, filters }: Props) {
</TableCell>
<TableCell className="text-center">
<div className="flex items-center justify-center gap-2">
<Link href={route('recipes.edit', recipe.id)}>
<Button
variant="outline"
size="sm"
className="button-outlined-primary"
title="編輯"
>
<Pencil className="h-4 w-4" />
</Button>
</Link>
<Button
variant="ghost"
size="sm"
onClick={() => handleDelete(recipe.id)}
className="text-red-500 hover:text-red-700 hover:bg-red-50"
title="刪除"
>
<Trash2 className="h-4 w-4" />
</Button>
<Can permission="recipes.edit">
<Link href={route('recipes.edit', recipe.id)}>
<Button
variant="outline"
size="sm"
className="button-outlined-primary"
title="編輯"
>
<Pencil className="h-4 w-4" />
</Button>
</Link>
</Can>
<Can permission="recipes.delete">
<AlertDialog>
<AlertDialogTrigger asChild>
<Button
variant="outline"
size="sm"
className="button-outlined-error"
title="刪除"
>
<Trash2 className="h-4 w-4" />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle></AlertDialogTitle>
<AlertDialogDescription>
{recipe.name}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel></AlertDialogCancel>
<AlertDialogAction
onClick={() => handleDelete(recipe.id)}
className="bg-red-600 hover:bg-red-700"
>
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</Can>
</div>
</TableCell>
</TableRow>

View File

@@ -146,7 +146,8 @@ export default function CreatePurchaseOrder({
if (order) {
router.put(`/purchase-orders/${order.id}`, data, {
onSuccess: () => toast.success("採購單已更新"),
onSuccess: () => { },//toast.success("採購單已更新"),
onError: (errors) => {
// 顯示更詳細的錯誤訊息
if (errors.items) {
@@ -161,7 +162,8 @@ export default function CreatePurchaseOrder({
});
} else {
router.post("/purchase-orders", data, {
onSuccess: () => toast.success("採購單已成功建立"),
onSuccess: () => { },//toast.success("採購單已成功建立"),
onError: (errors) => {
if (errors.items) {
toast.error("商品資料有誤,請檢查數量和單價是否正確填寫");

View File

@@ -23,6 +23,7 @@ import {
SelectTrigger,
SelectValue,
} from "@/Components/ui/select";
import { STATUS_OPTIONS } from "@/constants/purchase-order";
interface Props {
orders: {
@@ -176,13 +177,11 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
</SelectTrigger>
<SelectContent>
<SelectItem value="all"></SelectItem>
<SelectItem value="draft">稿</SelectItem>
<SelectItem value="pending"></SelectItem>
<SelectItem value="processing"></SelectItem>
<SelectItem value="shipping"></SelectItem>
<SelectItem value="confirming"></SelectItem>
<SelectItem value="completed"></SelectItem>
<SelectItem value="cancelled"></SelectItem>
{STATUS_OPTIONS.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>

View File

@@ -147,20 +147,26 @@ export default function ViewPurchaseOrderPage({ order }: Props) {
items={order.items}
isReadOnly={true}
/>
<div className="mt-4 flex flex-col items-end gap-2 border-t pt-4">
<div className="flex items-center gap-8 text-gray-600">
<span className="font-medium"></span>
<span>{formatCurrency(order.totalAmount)}</span>
</div>
<div className="flex items-center gap-8 text-gray-600">
<span className="font-medium"></span>
<span>{formatCurrency(order.tax_amount || 0)}</span>
</div>
<div className="flex items-center gap-8 pt-2 mt-2 border-t border-gray-100">
<span className="font-bold text-lg"></span>
<span className="text-xl font-bold text-primary">
{formatCurrency(order.grand_total || (order.totalAmount + (order.tax_amount || 0)))}
</span>
<div className="mt-6 flex justify-end">
<div className="w-full max-w-sm bg-primary/5 px-6 py-4 rounded-xl border border-primary/10 flex flex-col gap-3">
<div className="flex justify-between items-center w-full">
<span className="text-sm text-gray-500 font-medium"></span>
<span className="text-lg font-bold text-gray-700">{formatCurrency(order.totalAmount)}</span>
</div>
<div className="flex justify-between items-center w-full">
<span className="text-sm text-gray-500 font-medium"></span>
<span className="text-lg font-bold text-gray-700">{formatCurrency(order.taxAmount || 0)}</span>
</div>
<div className="h-px bg-primary/10 w-full my-1"></div>
<div className="flex justify-between items-end w-full">
<span className="text-sm text-gray-500 font-medium mb-1"> ()</span>
<span className="text-2xl font-black text-primary">
{formatCurrency(order.grandTotal || (order.totalAmount + (order.taxAmount || 0)))}
</span>
</div>
</div>
</div>
</div>

View File

@@ -8,7 +8,7 @@ import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
createInertiaApp({
title: (title) => `${title} - ${appName}`,
title: (title) => `${title} - ${window.appName || appName}`,
resolve: (name) => resolvePageComponent(`./Pages/${name}.tsx`, import.meta.glob('./Pages/**/*.tsx')),
setup({ el, App, props }) {
const root = createRoot(el);

View File

@@ -10,12 +10,12 @@ export const STATUS_CONFIG: Record<
{ label: string; variant: "default" | "secondary" | "destructive" | "outline" }
> = {
draft: { label: "草稿", variant: "outline" },
pending: { label: "待審核", variant: "outline" },
processing: { label: "處理中", variant: "outline" },
shipping: { label: "運送中", variant: "outline" },
confirming: { label: "待確認", variant: "outline" },
completed: { label: "已完成", variant: "outline" },
cancelled: { label: "已取消", variant: "outline" },
pending: { label: "簽核中", variant: "outline" },
approved: { label: "已核准", variant: "default" },
partial: { label: "部分收貨", variant: "secondary" },
completed: { label: "全數收貨", variant: "outline" },
closed: { label: "已結案", variant: "outline" },
cancelled: { label: "已作廢", variant: "destructive" },
};
export const STATUS_OPTIONS = Object.entries(STATUS_CONFIG).map(([value, config]) => ({

View File

@@ -31,6 +31,7 @@ export interface PageProps {
declare global {
interface Window {
axios: AxiosInstance;
appName: string;
}
var route: typeof routeFn;

View File

@@ -0,0 +1,27 @@
export interface GoodsReceipt {
id: number;
code: string;
warehouse_id: number;
warehouse?: {
id: number;
name: string;
};
vendor_id?: number;
vendor?: {
id: number;
name: string;
};
purchase_order_id?: number;
purchase_order?: {
code: string; // If loaded
};
received_date: string;
status: 'completed' | 'processing' | 'cancelled';
remarks?: string;
items_sum_total_amount?: number; // Calculated field
created_at: string;
updated_at: string;
user?: {
name: string;
};
}

View File

@@ -4,12 +4,12 @@
export type PurchaseOrderStatus =
| "draft" // 草稿
| "pending" // 待審核
| "processing" // 處理中
| "shipping" // 運送中
| "confirming" // 待確認
| "completed" // 已完成
| "cancelled"; // 已取消
| "pending" // 簽核中
| "approved" // 已核准
| "partial" // 部分收貨
| "completed" // 全數收貨
| "closed" // 已結案
| "cancelled"; // 已作廢

View File

@@ -25,7 +25,6 @@ export interface Warehouse {
total_quantity?: number;
low_stock_count?: number;
type?: WarehouseType;
is_sellable?: boolean;
license_plate?: string; // 車牌號碼 (移動倉)
driver_name?: string; // 司機姓名 (移動倉)
book_stock?: number;

View File

@@ -15,12 +15,12 @@ export const BREADCRUMB_MAP: Record<string, BreadcrumbItemType[]> = {
{ label: "倉庫管理", href: "/warehouses", isPage: true }
],
vendors: [
{ label: "廠商管理" },
{ label: "供應鏈管理", href: '#' },
{ label: "廠商資料管理", href: "/vendors", isPage: true }
],
purchaseOrders: [
{ label: "採購管理" },
{ label: "管理採購單", href: "/purchase-orders", isPage: true }
{ label: "供應鏈管理", href: '#' },
{ label: "採購單管理", href: "/purchase-orders", isPage: true }
],
productionOrders: [
{ label: "生產管理" },

View File

@@ -18,6 +18,9 @@
@viteReactRefresh
@vite(['resources/js/app.tsx', "resources/js/Pages/{$page['component']}.tsx"])
@inertiaHead
<script>
window.appName = "{{ $appName ?? config('app.name') }}";
</script>
</head>
<body class="font-sans antialiased">
@inertia

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 KiB