Compare commits
10 Commits
3fd333085b
...
b6fe9ad9f3
| Author | SHA1 | Date | |
|---|---|---|---|
| b6fe9ad9f3 | |||
| 590580e20a | |||
| c2e0ff726d | |||
| 5e542752ba | |||
| f22df90e01 | |||
| e018b75783 | |||
| 200d1989bd | |||
| 6c259859cf | |||
| 6bfdd92347 | |||
| 70f1709bd0 |
@@ -1086,3 +1086,132 @@ import { Pencil } from 'lucide-react';
|
|||||||
5. ✅ **安全性**:統一的權限控制確保資料安全
|
5. ✅ **安全性**:統一的權限控制確保資料安全
|
||||||
|
|
||||||
當你在開發或審查 Star ERP 客戶端後台的 UI 時,請務必參考此規範!
|
當你在開發或審查 Star ERP 客戶端後台的 UI 時,請務必參考此規範!
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 15. 批次匯入彈窗規範 (Batch Import Dialog)
|
||||||
|
|
||||||
|
為了確保系統中所有批次匯入功能(如:商品、庫存、客戶)的體驗一致,必須遵循以下 UI 結構與樣式。
|
||||||
|
|
||||||
|
### 15.1 標題結構
|
||||||
|
|
||||||
|
- **樣式**:保持簡潔,僅使用文字標題,不帶額外圖示。
|
||||||
|
- **文字**:統一為「匯入XXXX資料」。
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>匯入商品資料</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
請先下載範本,填寫完畢後上傳檔案進行批次處理。
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 15.2 分步引導區塊 (Step-by-Step Guide)
|
||||||
|
|
||||||
|
匯入流程必須分為三個清晰的步驟區塊:
|
||||||
|
|
||||||
|
#### 步驟 1:取得匯入範本
|
||||||
|
- **容器樣式**:`bg-gray-50 rounded-lg border border-gray-100 p-4 space-y-2`
|
||||||
|
- **標題圖示**:`<FileSpreadsheet className="w-4 h-4 text-green-600" />`
|
||||||
|
- **下載按鈕**:`variant="outline" size="sm" className="w-full sm:w-auto button-outlined-primary"`,並明確標註 `.xlsx`。
|
||||||
|
|
||||||
|
#### 步驟 2:設定資訊 (選甜)
|
||||||
|
- **容器樣式**:`space-y-2`
|
||||||
|
- **標題圖示**:`<Info className="w-4 h-4 text-primary-main" />`
|
||||||
|
- **欄位樣式**:使用標準 `Input`,標籤文字使用 `text-sm text-gray-700`。
|
||||||
|
- **預設值**:若有備註欄位,應提供合適的預設值(例如:「Excel 匯入」)。
|
||||||
|
|
||||||
|
#### 步驟 3:上傳填寫後的檔案
|
||||||
|
- **容器樣式**:`space-y-2`
|
||||||
|
- **標題圖示**:`<FileUp className="w-4 h-4 text-blue-600" />`
|
||||||
|
- **Input 樣式**:`type="file"`,並開啟 `cursor-pointer`。
|
||||||
|
|
||||||
|
### 15.3 規則說明面板 (Accordion Rules)
|
||||||
|
|
||||||
|
詳細的填寫說明必須收納於 `Accordion` 中,避免干擾主流程:
|
||||||
|
|
||||||
|
- **樣式**:標準灰色邊框,不使用特殊背景色 (如琥珀色)。
|
||||||
|
- **容器**:`className="w-full border rounded-lg px-2"`
|
||||||
|
- **觸發文字**:`text-sm text-gray-500`
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
<Accordion type="single" collapsible className="w-full border rounded-lg px-2">
|
||||||
|
<AccordionItem value="rules" className="border-b-0">
|
||||||
|
<AccordionTrigger className="text-sm text-gray-500 hover:no-underline py-3">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Info className="h-4 w-4" />
|
||||||
|
匯入規則與提示
|
||||||
|
</div>
|
||||||
|
</AccordionTrigger>
|
||||||
|
<AccordionContent>
|
||||||
|
<div className="text-sm text-gray-600 space-y-2 pb-2 pl-6">
|
||||||
|
<ul className="list-disc space-y-1">
|
||||||
|
<li>使用加粗文字標註關鍵欄位:<span className="font-medium text-gray-700">關鍵字</span></li>
|
||||||
|
<li>說明文字簡潔明瞭。</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</AccordionContent>
|
||||||
|
</AccordionItem>
|
||||||
|
</Accordion>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 15.4 底部操作 (Footer)
|
||||||
|
|
||||||
|
- **取消按鈕**:`variant="outline"`,且為 `button-outlined-primary`。
|
||||||
|
- **提交按鈕**:`button-filled-primary`,且在處理中時顯示 `Loader2`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 16. 詳情頁面項目清單規範 (Detail Page Item List Standards)
|
||||||
|
|
||||||
|
為了確保詳情頁面(如:採購單詳情、進貨單詳情、銷售匯入詳情)的資訊層級清晰且視覺統一,所有項目清單必須遵循以下規範。
|
||||||
|
|
||||||
|
### 16.1 容器結構 (Container Structure)
|
||||||
|
|
||||||
|
項目清單應封裝在一個帶有內距的卡片容器中,而不是讓表格直接緊貼外層卡片邊緣。
|
||||||
|
|
||||||
|
1. **外層卡片**:`bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden`
|
||||||
|
2. **標題區塊**:`p-6 border-b border-gray-100 bg-gray-50/30`
|
||||||
|
3. **內容內距**:標題下方的內容區塊應加上 `p-6`。
|
||||||
|
4. **表格包裹層**:表格應再包裹一層 `border rounded-lg overflow-hidden`,以確保表格內部的邊角與隔線視覺完整。
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
|
||||||
|
{/* 標題 */}
|
||||||
|
<div className="p-6 border-b border-gray-100 bg-gray-50/30">
|
||||||
|
<h2 className="text-lg font-bold text-gray-900">項目清單標題</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 內容區塊 */}
|
||||||
|
<div className="p-6">
|
||||||
|
<div className="border rounded-lg overflow-hidden">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow className="bg-gray-50 hover:bg-gray-50">
|
||||||
|
{/* 標頭欄位 */}
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{/* 表格內容 */}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 若有分頁,直接放在 p-6 容器內,並加 mt-6 分隔 */}
|
||||||
|
<div className="mt-6">
|
||||||
|
<Pagination ... />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 16.2 表格樣式細節 (Table Styling)
|
||||||
|
|
||||||
|
1. **標頭背景**:`TableHeader` 的第一個 `TableRow` 應使用 `bg-gray-50 hover:bg-gray-50` 強化視覺區隔。
|
||||||
|
2. **文字顏色**:主體文字使用 `text-gray-900`(標題/重要數據)或 `text-gray-500`(輔助/序號)。
|
||||||
|
3. **數據對齊**:
|
||||||
|
* **數量/序號**:文字置中 (`text-center`) 或依據數據類型對齊。
|
||||||
|
* **金額**:金額欄位必須使用 `text-right` 並視情況加粗 (`font-bold`) 或加上 `text-primary-main` 顏色。
|
||||||
|
4. **表格隔線**:確保表格具有清晰但不過於突出的水平隔線,提升長列表的可讀性。
|
||||||
|
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -28,3 +28,4 @@ Thumbs.db
|
|||||||
/docs/pptx_build
|
/docs/pptx_build
|
||||||
/docs/presentation
|
/docs/presentation
|
||||||
docs/Monthly_Report_2026_01.pptx
|
docs/Monthly_Report_2026_01.pptx
|
||||||
|
docs/f6_1770350984272.xlsx
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ class ProductSyncController extends Controller
|
|||||||
'external_pos_id' => 'required|string',
|
'external_pos_id' => 'required|string',
|
||||||
'name' => 'required|string',
|
'name' => 'required|string',
|
||||||
'price' => 'nullable|numeric',
|
'price' => 'nullable|numeric',
|
||||||
'sku' => 'nullable|string',
|
|
||||||
'barcode' => 'nullable|string',
|
'barcode' => 'nullable|string',
|
||||||
'category' => 'nullable|string',
|
'category' => 'nullable|string',
|
||||||
'unit' => 'nullable|string',
|
'unit' => 'nullable|string',
|
||||||
|
|||||||
@@ -15,16 +15,15 @@ interface InventoryServiceInterface
|
|||||||
public function checkStock(int $productId, int $warehouseId, float $quantity): bool;
|
public function checkStock(int $productId, int $warehouseId, float $quantity): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrease stock for a product (e.g., when an order is placed).
|
|
||||||
*
|
|
||||||
* @param int $productId
|
* @param int $productId
|
||||||
* @param int $warehouseId
|
* @param int $warehouseId
|
||||||
* @param float $quantity
|
* @param float $quantity
|
||||||
* @param string|null $reason
|
* @param string|null $reason
|
||||||
* @param bool $force
|
* @param bool $force
|
||||||
|
* @param string|null $slot
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function decreaseStock(int $productId, int $warehouseId, float $quantity, ?string $reason = null, bool $force = false): void;
|
public function decreaseStock(int $productId, int $warehouseId, float $quantity, ?string $reason = null, bool $force = false, ?string $slot = null): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all active warehouses.
|
* Get all active warehouses.
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ use App\Modules\Inventory\Models\Product;
|
|||||||
use App\Modules\Inventory\Models\Inventory;
|
use App\Modules\Inventory\Models\Inventory;
|
||||||
use App\Modules\Inventory\Models\InventoryTransaction;
|
use App\Modules\Inventory\Models\InventoryTransaction;
|
||||||
use App\Modules\Inventory\Models\WarehouseProductSafetyStock;
|
use App\Modules\Inventory\Models\WarehouseProductSafetyStock;
|
||||||
|
use App\Modules\Inventory\Imports\InventoryImport;
|
||||||
|
use App\Modules\Inventory\Exports\InventoryTemplateExport;
|
||||||
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||||
|
|
||||||
use App\Modules\Core\Contracts\CoreServiceInterface;
|
use App\Modules\Core\Contracts\CoreServiceInterface;
|
||||||
|
|
||||||
@@ -49,12 +53,18 @@ class InventoryController extends Controller
|
|||||||
->pluck('safety_stock', 'product_id')
|
->pluck('safety_stock', 'product_id')
|
||||||
->mapWithKeys(fn($val, $key) => [(string)$key => (float)$val]);
|
->mapWithKeys(fn($val, $key) => [(string)$key => (float)$val]);
|
||||||
|
|
||||||
// 3. 準備 inventories (批號分組)
|
|
||||||
$items = $warehouse->inventories()
|
$items = $warehouse->inventories()
|
||||||
->with(['product.baseUnit', 'lastIncomingTransaction', 'lastOutgoingTransaction'])
|
->with(['product.baseUnit', 'lastIncomingTransaction', 'lastOutgoingTransaction'])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$inventories = $items->groupBy('product_id')->map(function ($batchItems) use ($safetyStockMap) {
|
// 判斷是否為販賣機並調整分組
|
||||||
|
$isVending = $warehouse->type === 'vending';
|
||||||
|
|
||||||
|
$inventories = $items->groupBy(function ($item) use ($isVending) {
|
||||||
|
return $isVending
|
||||||
|
? $item->product_id . '-' . ($item->location ?? 'NO-SLOT')
|
||||||
|
: $item->product_id;
|
||||||
|
})->map(function ($batchItems) use ($safetyStockMap, $isVending) {
|
||||||
$firstItem = $batchItems->first();
|
$firstItem = $batchItems->first();
|
||||||
$product = $firstItem->product;
|
$product = $firstItem->product;
|
||||||
$totalQuantity = $batchItems->sum('quantity');
|
$totalQuantity = $batchItems->sum('quantity');
|
||||||
@@ -94,6 +104,7 @@ class InventoryController extends Controller
|
|||||||
'safetyStock' => null, // 批號層級不再有安全庫存
|
'safetyStock' => null, // 批號層級不再有安全庫存
|
||||||
'status' => '正常',
|
'status' => '正常',
|
||||||
'batchNumber' => $inv->batch_number ?? 'BATCH-' . $inv->id,
|
'batchNumber' => $inv->batch_number ?? 'BATCH-' . $inv->id,
|
||||||
|
'location' => $inv->location,
|
||||||
'expiryDate' => $inv->expiry_date ? $inv->expiry_date->format('Y-m-d') : null,
|
'expiryDate' => $inv->expiry_date ? $inv->expiry_date->format('Y-m-d') : null,
|
||||||
'lastInboundDate' => $inv->lastIncomingTransaction ? ($inv->lastIncomingTransaction->actual_time ? $inv->lastIncomingTransaction->actual_time->format('Y-m-d') : $inv->lastIncomingTransaction->created_at->format('Y-m-d')) : null,
|
'lastInboundDate' => $inv->lastIncomingTransaction ? ($inv->lastIncomingTransaction->actual_time ? $inv->lastIncomingTransaction->actual_time->format('Y-m-d') : $inv->lastIncomingTransaction->created_at->format('Y-m-d')) : null,
|
||||||
'lastOutboundDate' => $inv->lastOutgoingTransaction ? ($inv->lastOutgoingTransaction->actual_time ? $inv->lastOutgoingTransaction->actual_time->format('Y-m-d') : $inv->lastOutgoingTransaction->created_at->format('Y-m-d')) : null,
|
'lastOutboundDate' => $inv->lastOutgoingTransaction ? ($inv->lastOutgoingTransaction->actual_time ? $inv->lastOutgoingTransaction->actual_time->format('Y-m-d') : $inv->lastOutgoingTransaction->created_at->format('Y-m-d')) : null,
|
||||||
@@ -163,10 +174,11 @@ class InventoryController extends Controller
|
|||||||
'items.*.productId' => 'required|exists:products,id',
|
'items.*.productId' => 'required|exists:products,id',
|
||||||
'items.*.quantity' => 'required|numeric|min:0.01',
|
'items.*.quantity' => 'required|numeric|min:0.01',
|
||||||
'items.*.unit_cost' => 'nullable|numeric|min:0', // 新增成本驗證
|
'items.*.unit_cost' => 'nullable|numeric|min:0', // 新增成本驗證
|
||||||
'items.*.batchMode' => 'required|in:existing,new',
|
'items.*.batchMode' => 'required|in:existing,new,none',
|
||||||
'items.*.inventoryId' => 'required_if:items.*.batchMode,existing|nullable|exists:inventories,id',
|
'items.*.inventoryId' => 'required_if:items.*.batchMode,existing|nullable|exists:inventories,id',
|
||||||
'items.*.originCountry' => 'required_if:items.*.batchMode,new|nullable|string|max:2',
|
'items.*.originCountry' => 'required_if:items.*.batchMode,new|nullable|string|max:2',
|
||||||
'items.*.expiryDate' => 'nullable|date',
|
'items.*.expiryDate' => 'nullable|date',
|
||||||
|
'items.*.location' => 'nullable|string|max:50',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return DB::transaction(function () use ($validated, $warehouse) {
|
return DB::transaction(function () use ($validated, $warehouse) {
|
||||||
@@ -188,6 +200,26 @@ class InventoryController extends Controller
|
|||||||
if (isset($item['unit_cost'])) {
|
if (isset($item['unit_cost'])) {
|
||||||
$inventory->unit_cost = $item['unit_cost'];
|
$inventory->unit_cost = $item['unit_cost'];
|
||||||
}
|
}
|
||||||
|
} elseif ($item['batchMode'] === 'none') {
|
||||||
|
// 模式 C:不使用批號 (自動累加至 NO-BATCH)
|
||||||
|
$inventory = $warehouse->inventories()->withTrashed()->firstOrNew(
|
||||||
|
[
|
||||||
|
'product_id' => $item['productId'],
|
||||||
|
'batch_number' => 'NO-BATCH'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'quantity' => 0,
|
||||||
|
'unit_cost' => $item['unit_cost'] ?? 0,
|
||||||
|
'total_value' => 0,
|
||||||
|
'arrival_date' => $validated['inboundDate'],
|
||||||
|
'expiry_date' => null,
|
||||||
|
'origin_country' => 'TW',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($inventory->trashed()) {
|
||||||
|
$inventory->restore();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 模式 B:建立新批號
|
// 模式 B:建立新批號
|
||||||
$originCountry = $item['originCountry'] ?? 'TW';
|
$originCountry = $item['originCountry'] ?? 'TW';
|
||||||
@@ -209,6 +241,7 @@ class InventoryController extends Controller
|
|||||||
'quantity' => 0,
|
'quantity' => 0,
|
||||||
'unit_cost' => $item['unit_cost'] ?? 0, // 新增
|
'unit_cost' => $item['unit_cost'] ?? 0, // 新增
|
||||||
'total_value' => 0, // 稍後計算
|
'total_value' => 0, // 稍後計算
|
||||||
|
'location' => $item['location'] ?? null,
|
||||||
'arrival_date' => $validated['inboundDate'],
|
'arrival_date' => $validated['inboundDate'],
|
||||||
'expiry_date' => $item['expiryDate'] ?? null,
|
'expiry_date' => $item['expiryDate'] ?? null,
|
||||||
'origin_country' => $originCountry,
|
'origin_country' => $originCountry,
|
||||||
@@ -522,6 +555,7 @@ class InventoryController extends Controller
|
|||||||
'userName' => $user ? $user->name : '系統',
|
'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'),
|
'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 ?? '-', // 補上批號資訊
|
'batchNumber' => $tx->inventory?->batch_number ?? '-', // 補上批號資訊
|
||||||
|
'slot' => $tx->inventory?->location, // 加入貨道資訊
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -552,7 +586,7 @@ class InventoryController extends Controller
|
|||||||
$userIds = $inventory->transactions->pluck('user_id')->filter()->unique()->toArray();
|
$userIds = $inventory->transactions->pluck('user_id')->filter()->unique()->toArray();
|
||||||
$users = $this->coreService->getUsersByIds($userIds)->keyBy('id');
|
$users = $this->coreService->getUsersByIds($userIds)->keyBy('id');
|
||||||
|
|
||||||
$transactions = $inventory->transactions->map(function ($tx) use ($users) {
|
$transactions = $inventory->transactions->map(function ($tx) use ($users, $inventory) {
|
||||||
$user = $tx->user_id ? ($users[$tx->user_id] ?? null) : null;
|
$user = $tx->user_id ? ($users[$tx->user_id] ?? null) : null;
|
||||||
return [
|
return [
|
||||||
'id' => (string) $tx->id,
|
'id' => (string) $tx->id,
|
||||||
@@ -563,6 +597,7 @@ class InventoryController extends Controller
|
|||||||
'reason' => $tx->reason,
|
'reason' => $tx->reason,
|
||||||
'userName' => $user ? $user->name : '系統', // 手動對應
|
'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'),
|
'actualTime' => $tx->actual_time ? $tx->actual_time->format('Y-m-d H:i') : $tx->created_at->format('Y-m-d H:i'),
|
||||||
|
'slot' => $inventory->location, // 加入貨道資訊
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -583,4 +618,35 @@ class InventoryController extends Controller
|
|||||||
|
|
||||||
return redirect()->back()->with('error', '未提供查詢參數');
|
return redirect()->back()->with('error', '未提供查詢參數');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 匯入入庫
|
||||||
|
*/
|
||||||
|
public function import(Request $request, Warehouse $warehouse)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'file' => 'required|mimes:xlsx,xls,csv',
|
||||||
|
'inboundDate' => 'required|date',
|
||||||
|
'notes' => 'nullable|string',
|
||||||
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Excel::import(
|
||||||
|
new InventoryImport($warehouse, $request->inboundDate, $request->notes),
|
||||||
|
$request->file('file')
|
||||||
|
);
|
||||||
|
|
||||||
|
return back()->with('success', '庫存資料匯入成功');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return back()->withErrors(['file' => '匯入過程中發生錯誤: ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下載匯入範本 (.xlsx)
|
||||||
|
*/
|
||||||
|
public function template()
|
||||||
|
{
|
||||||
|
return Excel::download(new InventoryTemplateExport, '庫存匯入範本.xlsx');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,51 @@ class SafetyStockController extends Controller
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
// 準備現有庫存列表 (用於庫存量對比)
|
// 獲取現有庫存 (用於抓取「已在倉庫中」的商品)
|
||||||
|
$inventoryProductIds = Inventory::where('warehouse_id', $warehouse->id)->pluck('product_id')->unique();
|
||||||
|
|
||||||
|
// 準備安全庫存設定列表 (從資料庫讀取)
|
||||||
|
$existingSettings = WarehouseProductSafetyStock::where('warehouse_id', $warehouse->id)
|
||||||
|
->with(['product.category', 'product.baseUnit'])
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$existingProductIds = $existingSettings->pluck('product_id')->toArray();
|
||||||
|
|
||||||
|
// 找出:有庫存但是「還沒設定過安全庫存」的商品
|
||||||
|
$missingProductIds = $inventoryProductIds->diff($existingProductIds);
|
||||||
|
|
||||||
|
$missingProducts = Product::whereIn('id', $missingProductIds)
|
||||||
|
->with(['category', 'baseUnit'])
|
||||||
|
->get();
|
||||||
|
|
||||||
|
// 合併:已設定的 + 有庫存未設定的 (預設值 0)
|
||||||
|
$safetyStockSettings = $existingSettings->map(function ($setting) {
|
||||||
|
return [
|
||||||
|
'id' => (string) $setting->id,
|
||||||
|
'warehouseId' => (string) $setting->warehouse_id,
|
||||||
|
'productId' => (string) $setting->product_id,
|
||||||
|
'productName' => $setting->product->name,
|
||||||
|
'productType' => $setting->product->category ? $setting->product->category->name : '其他',
|
||||||
|
'safetyStock' => (float) $setting->safety_stock,
|
||||||
|
'unit' => $setting->product->baseUnit?->name ?? '個',
|
||||||
|
'updatedAt' => $setting->updated_at->toIso8601String(),
|
||||||
|
'isNew' => false, // 標記為舊有設定
|
||||||
|
];
|
||||||
|
})->concat($missingProducts->map(function ($product) use ($warehouse) {
|
||||||
|
return [
|
||||||
|
'id' => 'temp_' . $product->id, // 暫時 ID
|
||||||
|
'warehouseId' => (string) $warehouse->id,
|
||||||
|
'productId' => (string) $product->id,
|
||||||
|
'productName' => $product->name,
|
||||||
|
'productType' => $product->category ? $product->category->name : '其他',
|
||||||
|
'safetyStock' => 0, // 預設 0
|
||||||
|
'unit' => $product->baseUnit?->name ?? '個',
|
||||||
|
'updatedAt' => now()->toIso8601String(),
|
||||||
|
'isNew' => true, // 標記為建議新增
|
||||||
|
];
|
||||||
|
}))->values();
|
||||||
|
|
||||||
|
// 原本的 inventories 映射 (供顯示對比)
|
||||||
$inventories = Inventory::where('warehouse_id', $warehouse->id)
|
$inventories = Inventory::where('warehouse_id', $warehouse->id)
|
||||||
->select('product_id', DB::raw('SUM(quantity) as total_quantity'))
|
->select('product_id', DB::raw('SUM(quantity) as total_quantity'))
|
||||||
->groupBy('product_id')
|
->groupBy('product_id')
|
||||||
@@ -43,23 +87,6 @@ class SafetyStockController extends Controller
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
// 準備安全庫存設定列表 (從新表格讀取)
|
|
||||||
$safetyStockSettings = WarehouseProductSafetyStock::where('warehouse_id', $warehouse->id)
|
|
||||||
->with(['product.category', 'product.baseUnit'])
|
|
||||||
->get()
|
|
||||||
->map(function ($setting) {
|
|
||||||
return [
|
|
||||||
'id' => (string) $setting->id,
|
|
||||||
'warehouseId' => (string) $setting->warehouse_id,
|
|
||||||
'productId' => (string) $setting->product_id,
|
|
||||||
'productName' => $setting->product->name,
|
|
||||||
'productType' => $setting->product->category ? $setting->product->category->name : '其他',
|
|
||||||
'safetyStock' => (float) $setting->safety_stock,
|
|
||||||
'unit' => $setting->product->baseUnit?->name ?? '個',
|
|
||||||
'updatedAt' => $setting->updated_at->toIso8601String(),
|
|
||||||
];
|
|
||||||
});
|
|
||||||
|
|
||||||
return Inertia::render('Warehouse/SafetyStockSettings', [
|
return Inertia::render('Warehouse/SafetyStockSettings', [
|
||||||
'warehouse' => $warehouse,
|
'warehouse' => $warehouse,
|
||||||
'safetyStockSettings' => $safetyStockSettings,
|
'safetyStockSettings' => $safetyStockSettings,
|
||||||
|
|||||||
@@ -212,7 +212,8 @@ class TransferOrderController extends Controller
|
|||||||
return [
|
return [
|
||||||
'product_id' => (string) $inv->product_id,
|
'product_id' => (string) $inv->product_id,
|
||||||
'product_name' => $inv->product->name,
|
'product_name' => $inv->product->name,
|
||||||
'product_code' => $inv->product->code, // Added code
|
'product_code' => $inv->product->code,
|
||||||
|
'product_barcode' => $inv->product->barcode,
|
||||||
'batch_number' => $inv->batch_number,
|
'batch_number' => $inv->batch_number,
|
||||||
'quantity' => (float) $inv->quantity,
|
'quantity' => (float) $inv->quantity,
|
||||||
'unit_cost' => (float) $inv->unit_cost,
|
'unit_cost' => (float) $inv->unit_cost,
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ class WarehouseController extends Controller
|
|||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
|
'code' => 'required|string|max:20|unique:warehouses,code',
|
||||||
'name' => 'required|string|max:50',
|
'name' => 'required|string|max:50',
|
||||||
'address' => 'nullable|string|max:255',
|
'address' => 'nullable|string|max:255',
|
||||||
'description' => 'nullable|string',
|
'description' => 'nullable|string',
|
||||||
@@ -131,14 +132,6 @@ class WarehouseController extends Controller
|
|||||||
'driver_name' => 'nullable|string|max:50',
|
'driver_name' => 'nullable|string|max:50',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 自動產生代碼
|
|
||||||
$prefix = 'WH';
|
|
||||||
$lastWarehouse = Warehouse::latest('id')->first();
|
|
||||||
$nextId = $lastWarehouse ? $lastWarehouse->id + 1 : 1;
|
|
||||||
$code = $prefix . str_pad($nextId, 3, '0', STR_PAD_LEFT);
|
|
||||||
|
|
||||||
$validated['code'] = $code;
|
|
||||||
|
|
||||||
Warehouse::create($validated);
|
Warehouse::create($validated);
|
||||||
|
|
||||||
return redirect()->back()->with('success', '倉庫已建立');
|
return redirect()->back()->with('success', '倉庫已建立');
|
||||||
@@ -147,6 +140,7 @@ class WarehouseController extends Controller
|
|||||||
public function update(Request $request, Warehouse $warehouse)
|
public function update(Request $request, Warehouse $warehouse)
|
||||||
{
|
{
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
|
'code' => 'required|string|max:20|unique:warehouses,code,' . $warehouse->id,
|
||||||
'name' => 'required|string|max:50',
|
'name' => 'required|string|max:50',
|
||||||
'address' => 'nullable|string|max:255',
|
'address' => 'nullable|string|max:255',
|
||||||
'description' => 'nullable|string',
|
'description' => 'nullable|string',
|
||||||
@@ -162,8 +156,9 @@ class WarehouseController extends Controller
|
|||||||
|
|
||||||
public function destroy(Warehouse $warehouse)
|
public function destroy(Warehouse $warehouse)
|
||||||
{
|
{
|
||||||
// 檢查是否有相關聯的採購單
|
// 檢查是否有相關聯的採購單 (跨模組檢查,不使用模型關聯以符合解耦規範)
|
||||||
if ($warehouse->purchaseOrders()->exists()) {
|
$hasPurchaseOrders = \App\Modules\Procurement\Models\PurchaseOrder::where('warehouse_id', $warehouse->id)->exists();
|
||||||
|
if ($hasPurchaseOrders) {
|
||||||
return redirect()->back()->with('error', '無法刪除:該倉庫有相關聯的採購單,請先處理採購單。');
|
return redirect()->back()->with('error', '無法刪除:該倉庫有相關聯的採購單,請先處理採購單。');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
87
app/Modules/Inventory/Exports/InventoryTemplateExport.php
Normal file
87
app/Modules/Inventory/Exports/InventoryTemplateExport.php
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Inventory\Exports;
|
||||||
|
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||||
|
use Maatwebsite\Excel\Concerns\FromArray;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||||
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||||
|
|
||||||
|
class InventoryTemplateExport implements WithMultipleSheets
|
||||||
|
{
|
||||||
|
public function sheets(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new InventoryDataSheet(),
|
||||||
|
new InventoryInstructionSheet(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InventoryDataSheet implements FromArray, WithHeadings, WithTitle, ShouldAutoSize
|
||||||
|
{
|
||||||
|
public function array(): array
|
||||||
|
{
|
||||||
|
// 資料分頁保持完全空白
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function headings(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'商品條碼',
|
||||||
|
'商品代號',
|
||||||
|
'商品名稱',
|
||||||
|
'數量',
|
||||||
|
'入庫單價',
|
||||||
|
'儲位/貨道',
|
||||||
|
'批號',
|
||||||
|
'產地',
|
||||||
|
'效期',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function title(): string
|
||||||
|
{
|
||||||
|
return '資料填寫';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InventoryInstructionSheet implements FromArray, WithHeadings, WithTitle, ShouldAutoSize
|
||||||
|
{
|
||||||
|
public function array(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['商品條碼', '擇一輸入', '系統會「優先」依據條碼匹配商品。若有填寫,條碼必須存在於系統中'],
|
||||||
|
['商品代號', '擇一輸入', '若條碼未填寫,系統會依據代號匹配商品'],
|
||||||
|
['商品名稱', '選填', '僅供對照參考,匯入時系統會自動忽略此欄位內容'],
|
||||||
|
['數量', '必填', '入庫的商品數量,須為大於 0 的數字'],
|
||||||
|
['入庫單價', '選填', '未填寫時將預設使用商品的「採購成本價」'],
|
||||||
|
['儲位/貨道', '選填', '一般倉庫請填寫「儲位(位址)」,販賣機倉庫請填寫「貨道編號」(如: A1)'],
|
||||||
|
['批號', '選填', '如需批次控管請填寫,若留空系統會自動標記為 "NO-BATCH"'],
|
||||||
|
['產地', '選填', '商品的生產地資訊 (如:TW)'],
|
||||||
|
['效期', '選填', '格式請務必使用 YYYY-MM-DD (例如: 2026-12-31)'],
|
||||||
|
['', '', ''],
|
||||||
|
['倉庫類型參考', '', '系統支援以下倉庫性質:'],
|
||||||
|
['標準倉', '', '一般總倉、儲備倉'],
|
||||||
|
['生產倉', '', '加工廠、中央廚房、原材料存放處'],
|
||||||
|
['門市倉', '', '前台通路、店舖銷售現場'],
|
||||||
|
['販賣機', '', 'IoT 自動販賣機設備,建議搭配「貨道」填寫'],
|
||||||
|
['', '', ''],
|
||||||
|
['匹配與匯入規則', '', '1. 系統會優先比對「商品條碼」,其次為「商品代號」。'],
|
||||||
|
['', '', '2. 庫存將匯入至您在匯入前於系統介面所選擇的目標倉庫。'],
|
||||||
|
['', '', '3. 若需區分不同貨道或批次,請分行填寫。'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function headings(): array
|
||||||
|
{
|
||||||
|
return ['欄位名稱', '必要性', '填寫說明'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function title(): string
|
||||||
|
{
|
||||||
|
return '填寫規則';
|
||||||
|
}
|
||||||
|
}
|
||||||
137
app/Modules/Inventory/Imports/InventoryImport.php
Normal file
137
app/Modules/Inventory/Imports/InventoryImport.php
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Inventory\Imports;
|
||||||
|
|
||||||
|
use App\Modules\Inventory\Models\Product;
|
||||||
|
use App\Modules\Inventory\Models\Inventory;
|
||||||
|
use App\Modules\Inventory\Models\Warehouse;
|
||||||
|
use Maatwebsite\Excel\Concerns\ToModel;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithValidation;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||||
|
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||||
|
use Maatwebsite\Excel\Imports\HeadingRowFormatter;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class InventoryImport implements ToModel, WithHeadingRow, WithValidation, WithMapping, SkipsEmptyRows
|
||||||
|
{
|
||||||
|
private $warehouse;
|
||||||
|
private $inboundDate;
|
||||||
|
private $notes;
|
||||||
|
|
||||||
|
public function __construct(Warehouse $warehouse, string $inboundDate, ?string $notes = null)
|
||||||
|
{
|
||||||
|
HeadingRowFormatter::default('none');
|
||||||
|
$this->warehouse = $warehouse;
|
||||||
|
$this->inboundDate = $inboundDate;
|
||||||
|
$this->notes = $notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($row): array
|
||||||
|
{
|
||||||
|
// 處理條碼或代號為字串
|
||||||
|
if (isset($row['商品條碼'])) {
|
||||||
|
$row['商品條碼'] = (string) $row['商品條碼'];
|
||||||
|
}
|
||||||
|
if (isset($row['商品代號'])) {
|
||||||
|
$row['商品代號'] = (string) $row['商品代號'];
|
||||||
|
}
|
||||||
|
if (isset($row['儲位/貨道'])) {
|
||||||
|
$row['儲位/貨道'] = (string) $row['儲位/貨道'];
|
||||||
|
}
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function model(array $row)
|
||||||
|
{
|
||||||
|
// 查找商品
|
||||||
|
$product = null;
|
||||||
|
if (!empty($row['商品條碼'])) {
|
||||||
|
$product = Product::where('barcode', $row['商品條碼'])->first();
|
||||||
|
}
|
||||||
|
if (!$product && !empty($row['商品代號'])) {
|
||||||
|
$product = Product::where('code', $row['商品代號'])->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$product) {
|
||||||
|
return null; // 透過 Validation 攔截
|
||||||
|
}
|
||||||
|
|
||||||
|
$quantity = (float) $row['數量'];
|
||||||
|
$unitCost = isset($row['入庫單價']) ? (float) $row['入庫單價'] : ($product->cost_price ?? 0);
|
||||||
|
$location = $row['儲位/貨道'] ?? null;
|
||||||
|
|
||||||
|
// 批號邏輯:若 Excel 留空則使用 NO-BATCH
|
||||||
|
$batchNumber = !empty($row['批號']) ? $row['批號'] : 'NO-BATCH';
|
||||||
|
$originCountry = $row['產地'] ?? 'TW';
|
||||||
|
$expiryDate = !empty($row['效期']) ? $row['效期'] : null;
|
||||||
|
|
||||||
|
return DB::transaction(function () use ($product, $quantity, $unitCost, $location, $batchNumber, $originCountry, $expiryDate) {
|
||||||
|
// 使用與 InventoryController 相同的 firstOrNew 邏輯
|
||||||
|
$inventory = $this->warehouse->inventories()->withTrashed()->firstOrNew(
|
||||||
|
[
|
||||||
|
'product_id' => $product->id,
|
||||||
|
'batch_number' => $batchNumber,
|
||||||
|
'location' => $location, // 加入儲位/貨道作為區分關鍵字
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'quantity' => 0,
|
||||||
|
'unit_cost' => $unitCost,
|
||||||
|
'total_value' => 0,
|
||||||
|
'arrival_date' => $this->inboundDate,
|
||||||
|
'expiry_date' => $expiryDate,
|
||||||
|
'origin_country' => $originCountry,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($inventory->trashed()) {
|
||||||
|
$inventory->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新數量
|
||||||
|
$oldQty = $inventory->quantity;
|
||||||
|
$inventory->quantity += $quantity;
|
||||||
|
|
||||||
|
// 更新單價與總價值
|
||||||
|
$inventory->unit_cost = $unitCost;
|
||||||
|
$inventory->total_value = $inventory->quantity * $unitCost;
|
||||||
|
$inventory->save();
|
||||||
|
|
||||||
|
// 記錄交易歷史
|
||||||
|
$inventory->transactions()->create([
|
||||||
|
'warehouse_id' => $this->warehouse->id,
|
||||||
|
'product_id' => $product->id,
|
||||||
|
'batch_number' => $inventory->batch_number,
|
||||||
|
'quantity' => $quantity,
|
||||||
|
'unit_cost' => $unitCost,
|
||||||
|
'type' => '手動入庫',
|
||||||
|
'reason' => 'Excel 匯入入庫',
|
||||||
|
'balance_before' => $oldQty,
|
||||||
|
'balance_after' => $inventory->quantity,
|
||||||
|
'actual_time' => $this->inboundDate,
|
||||||
|
'notes' => $this->notes,
|
||||||
|
'expiry_date' => $inventory->expiry_date,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $inventory;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'商品條碼' => ['nullable', 'string'],
|
||||||
|
'商品代號' => ['nullable', 'string'],
|
||||||
|
'數量' => [
|
||||||
|
'required_with:商品條碼,商品代號', // 只有在有商品資訊時,數量才是必填
|
||||||
|
'numeric',
|
||||||
|
'min:0' // 允許數量為 0
|
||||||
|
],
|
||||||
|
'入庫單價' => ['nullable', 'numeric', 'min:0'],
|
||||||
|
'儲位/貨道' => ['nullable', 'string', 'max:50'],
|
||||||
|
'批號' => ['nullable', 'string'],
|
||||||
|
'效期' => ['nullable', 'date'],
|
||||||
|
'產地' => ['nullable', 'string', 'max:2'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,6 @@ class Product extends Model
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'code',
|
'code',
|
||||||
'barcode',
|
'barcode',
|
||||||
'sku',
|
|
||||||
'name',
|
'name',
|
||||||
'external_pos_id',
|
'external_pos_id',
|
||||||
'category_id',
|
'category_id',
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Unit extends Model
|
|||||||
{
|
{
|
||||||
use HasFactory, LogsActivity;
|
use HasFactory, LogsActivity;
|
||||||
|
|
||||||
protected $fillable = ['name', 'abbreviation'];
|
protected $fillable = ['name', 'code'];
|
||||||
|
|
||||||
public function productsAsBase(): HasMany
|
public function productsAsBase(): HasMany
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ Route::middleware('auth')->group(function () {
|
|||||||
Route::middleware('permission:inventory.adjust')->group(function () {
|
Route::middleware('permission:inventory.adjust')->group(function () {
|
||||||
Route::get('/warehouses/{warehouse}/inventory/create', [InventoryController::class, 'create'])->name('warehouses.inventory.create');
|
Route::get('/warehouses/{warehouse}/inventory/create', [InventoryController::class, 'create'])->name('warehouses.inventory.create');
|
||||||
Route::post('/warehouses/{warehouse}/inventory', [InventoryController::class, 'store'])->name('warehouses.inventory.store');
|
Route::post('/warehouses/{warehouse}/inventory', [InventoryController::class, 'store'])->name('warehouses.inventory.store');
|
||||||
|
Route::get('/warehouses/inventory/template', [InventoryController::class, 'template'])->name('warehouses.inventory.template');
|
||||||
|
Route::post('/warehouses/{warehouse}/inventory/import', [InventoryController::class, 'import'])->name('warehouses.inventory.import');
|
||||||
Route::get('/warehouses/{warehouse}/inventory/{inventoryId}/edit', [InventoryController::class, 'edit'])->name('warehouses.inventory.edit');
|
Route::get('/warehouses/{warehouse}/inventory/{inventoryId}/edit', [InventoryController::class, 'edit'])->name('warehouses.inventory.edit');
|
||||||
Route::put('/warehouses/{warehouse}/inventory/{inventoryId}', [InventoryController::class, 'update'])->name('warehouses.inventory.update');
|
Route::put('/warehouses/{warehouse}/inventory/{inventoryId}', [InventoryController::class, 'update'])->name('warehouses.inventory.update');
|
||||||
Route::delete('/warehouses/{warehouse}/inventory/{inventoryId}', [InventoryController::class, 'destroy'])->name('warehouses.inventory.destroy');
|
Route::delete('/warehouses/{warehouse}/inventory/{inventoryId}', [InventoryController::class, 'destroy'])->name('warehouses.inventory.destroy');
|
||||||
|
|||||||
@@ -59,13 +59,18 @@ class InventoryService implements InventoryServiceInterface
|
|||||||
return $stock >= $quantity;
|
return $stock >= $quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function decreaseStock(int $productId, int $warehouseId, float $quantity, ?string $reason = null, bool $force = false): void
|
public function decreaseStock(int $productId, int $warehouseId, float $quantity, ?string $reason = null, bool $force = false, ?string $slot = null): void
|
||||||
{
|
{
|
||||||
DB::transaction(function () use ($productId, $warehouseId, $quantity, $reason, $force) {
|
DB::transaction(function () use ($productId, $warehouseId, $quantity, $reason, $force, $slot) {
|
||||||
$inventories = Inventory::where('product_id', $productId)
|
$query = Inventory::where('product_id', $productId)
|
||||||
->where('warehouse_id', $warehouseId)
|
->where('warehouse_id', $warehouseId)
|
||||||
->where('quantity', '>', 0)
|
->where('quantity', '>', 0);
|
||||||
->orderBy('arrival_date', 'asc')
|
|
||||||
|
if ($slot) {
|
||||||
|
$query->where('location', $slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
$inventories = $query->orderBy('arrival_date', 'asc')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$remainingToDecrease = $quantity;
|
$remainingToDecrease = $quantity;
|
||||||
@@ -80,19 +85,25 @@ class InventoryService implements InventoryServiceInterface
|
|||||||
|
|
||||||
if ($remainingToDecrease > 0) {
|
if ($remainingToDecrease > 0) {
|
||||||
if ($force) {
|
if ($force) {
|
||||||
// Find any existing inventory record in this warehouse to subtract from, or create one
|
// Find any existing inventory record in this warehouse/slot to subtract from, or create one
|
||||||
$inventory = Inventory::where('product_id', $productId)
|
$query = Inventory::where('product_id', $productId)
|
||||||
->where('warehouse_id', $warehouseId)
|
->where('warehouse_id', $warehouseId);
|
||||||
->first();
|
|
||||||
|
if ($slot) {
|
||||||
|
$query->where('location', $slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
$inventory = $query->first();
|
||||||
|
|
||||||
if (!$inventory) {
|
if (!$inventory) {
|
||||||
$inventory = Inventory::create([
|
$inventory = Inventory::create([
|
||||||
'warehouse_id' => $warehouseId,
|
'warehouse_id' => $warehouseId,
|
||||||
'product_id' => $productId,
|
'product_id' => $productId,
|
||||||
|
'location' => $slot,
|
||||||
'quantity' => 0,
|
'quantity' => 0,
|
||||||
'unit_cost' => 0,
|
'unit_cost' => 0,
|
||||||
'total_value' => 0,
|
'total_value' => 0,
|
||||||
'batch_number' => 'POS-AUTO-' . time(),
|
'batch_number' => 'POS-AUTO-' . ($slot ? $slot . '-' : '') . time(),
|
||||||
'arrival_date' => now(),
|
'arrival_date' => now(),
|
||||||
'origin_country' => 'TW',
|
'origin_country' => 'TW',
|
||||||
'quality_status' => 'normal',
|
'quality_status' => 'normal',
|
||||||
|
|||||||
@@ -38,12 +38,11 @@ class ProductService
|
|||||||
// Map allowed fields
|
// Map allowed fields
|
||||||
$product->name = $data['name'];
|
$product->name = $data['name'];
|
||||||
$product->barcode = $data['barcode'] ?? $product->barcode;
|
$product->barcode = $data['barcode'] ?? $product->barcode;
|
||||||
$product->sku = $data['sku'] ?? $product->sku; // Maybe allow SKU update?
|
|
||||||
$product->price = $data['price'] ?? 0;
|
$product->price = $data['price'] ?? 0;
|
||||||
|
|
||||||
// Generate Code if missing (use sku or external_id)
|
// Generate Code if missing (use code or external_id)
|
||||||
if (empty($product->code)) {
|
if (empty($product->code)) {
|
||||||
$product->code = $data['code'] ?? ($product->sku ?? $product->external_pos_id);
|
$product->code = $data['code'] ?? $product->external_pos_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Category (Default: 未分類)
|
// Handle Category (Default: 未分類)
|
||||||
|
|||||||
@@ -447,11 +447,17 @@ class PurchaseOrderController extends Controller
|
|||||||
$taxAmount = !is_null($inputTax) ? $inputTax : round($totalAmount * 0.05, 2);
|
$taxAmount = !is_null($inputTax) ? $inputTax : round($totalAmount * 0.05, 2);
|
||||||
$grandTotal = $totalAmount + $taxAmount;
|
$grandTotal = $totalAmount + $taxAmount;
|
||||||
|
|
||||||
|
// 狀態轉移權限檢查
|
||||||
|
if (isset($validated['status']) && $order->status !== $validated['status']) {
|
||||||
|
if (!$order->canTransitionTo($validated['status'])) {
|
||||||
|
return back()->withErrors(['error' => '您沒有權限將狀態從 ' . $order->status . ' 變更為 ' . $validated['status']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
// 1. 填充屬性但暫不儲存以捕捉變更
|
// 1. 填充屬性但暫不儲存以捕捉變更
|
||||||
$order->fill([
|
$order->fill([
|
||||||
'vendor_id' => $validated['vendor_id'],
|
'vendor_id' => $validated['vendor_id'],
|
||||||
'warehouse_id' => $validated['warehouse_id'],
|
'warehouse_id' => $validated['warehouse_id'],
|
||||||
'order_date' => $validated['order_date'], // 新增
|
'order_date' => $validated['order_date'],
|
||||||
'expected_delivery_date' => $validated['expected_delivery_date'],
|
'expected_delivery_date' => $validated['expected_delivery_date'],
|
||||||
'total_amount' => $totalAmount,
|
'total_amount' => $totalAmount,
|
||||||
'tax_amount' => $taxAmount,
|
'tax_amount' => $taxAmount,
|
||||||
@@ -460,11 +466,22 @@ class PurchaseOrderController extends Controller
|
|||||||
'status' => $validated['status'],
|
'status' => $validated['status'],
|
||||||
'invoice_number' => $validated['invoice_number'] ?? null,
|
'invoice_number' => $validated['invoice_number'] ?? null,
|
||||||
'invoice_date' => $validated['invoice_date'] ?? null,
|
'invoice_date' => $validated['invoice_date'] ?? null,
|
||||||
'invoice_amount' => $validated['invoice_amount'] ?? null,
|
'invoice_amount' => (float) ($validated['invoice_amount'] ?? 0),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 捕捉變更屬性以進行手動記錄
|
// 捕捉變更屬性
|
||||||
$dirty = $order->getDirty();
|
$dirty = $order->getDirty();
|
||||||
|
|
||||||
|
// 嚴格權限檢查:如果修改了 status 以外的任何欄位,必須具備編輯權限
|
||||||
|
$otherChanges = array_diff(array_keys($dirty), ['status']);
|
||||||
|
if (!empty($otherChanges)) {
|
||||||
|
$canEdit = auth()->user()->hasRole('super-admin') || auth()->user()->can('purchase_orders.edit');
|
||||||
|
if (!$canEdit) {
|
||||||
|
throw new \Exception('您沒有權限修改採購單的基本內容,僅能執行流程異動(如:送審)。');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 捕捉舊屬性以進行記錄
|
||||||
$oldAttributes = [];
|
$oldAttributes = [];
|
||||||
$newAttributes = [];
|
$newAttributes = [];
|
||||||
|
|
||||||
@@ -657,7 +674,7 @@ class PurchaseOrderController extends Controller
|
|||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
|
|
||||||
return redirect()->route('purchase-orders.index')->with('success', '採購單已刪除');
|
return redirect()->route('purchase-orders.index')->with('success', '採購單已作廢');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
return back()->withErrors(['error' => '刪除失敗:' . $e->getMessage()]);
|
return back()->withErrors(['error' => '刪除失敗:' . $e->getMessage()]);
|
||||||
|
|||||||
@@ -70,4 +70,50 @@ class PurchaseOrder extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(PurchaseOrderItem::class);
|
return $this->hasMany(PurchaseOrderItem::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 檢查是否可以轉移至新狀態,並驗證權限。
|
||||||
|
*/
|
||||||
|
public function canTransitionTo(string $newStatus, $user = null): bool
|
||||||
|
{
|
||||||
|
$user = $user ?? auth()->user();
|
||||||
|
if (!$user) return false;
|
||||||
|
if ($user->hasRole('super-admin')) return true;
|
||||||
|
|
||||||
|
$currentStatus = $this->status;
|
||||||
|
|
||||||
|
// 定義合法的狀態轉移路徑與所需權限
|
||||||
|
$transitions = [
|
||||||
|
'draft' => [
|
||||||
|
'pending' => 'purchase_orders.view', // 基本檢視者即可送審
|
||||||
|
'cancelled' => 'purchase_orders.cancel',
|
||||||
|
],
|
||||||
|
'pending' => [
|
||||||
|
'approved' => 'purchase_orders.approve',
|
||||||
|
'draft' => 'purchase_orders.approve', // 退回草稿
|
||||||
|
'cancelled' => 'purchase_orders.cancel',
|
||||||
|
],
|
||||||
|
'approved' => [
|
||||||
|
'cancelled' => 'purchase_orders.cancel',
|
||||||
|
'partial' => null, // 系統自動轉移,不需手動權限點
|
||||||
|
],
|
||||||
|
'partial' => [
|
||||||
|
'completed' => null, // 系統自動轉移
|
||||||
|
'closed' => 'purchase_orders.approve', // 手動結案通常需要核准權限
|
||||||
|
'cancelled' => 'purchase_orders.cancel',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!isset($transitions[$currentStatus])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!array_key_exists($newStatus, $transitions[$currentStatus])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$requiredPermission = $transitions[$currentStatus][$newStatus];
|
||||||
|
|
||||||
|
return $requiredPermission ? $user->can($requiredPermission) : true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ Route::middleware('auth')->group(function () {
|
|||||||
Route::get('/purchase-orders/{id}', [PurchaseOrderController::class, 'show'])->name('purchase-orders.show');
|
Route::get('/purchase-orders/{id}', [PurchaseOrderController::class, 'show'])->name('purchase-orders.show');
|
||||||
|
|
||||||
Route::get('/purchase-orders/{id}/edit', [PurchaseOrderController::class, 'edit'])->middleware('permission:purchase_orders.edit')->name('purchase-orders.edit');
|
Route::get('/purchase-orders/{id}/edit', [PurchaseOrderController::class, 'edit'])->middleware('permission:purchase_orders.edit')->name('purchase-orders.edit');
|
||||||
Route::put('/purchase-orders/{id}', [PurchaseOrderController::class, 'update'])->middleware('permission:purchase_orders.edit')->name('purchase-orders.update');
|
Route::match(['PUT', 'PATCH'], '/purchase-orders/{id}', [PurchaseOrderController::class, 'update'])->name('purchase-orders.update');
|
||||||
Route::delete('/purchase-orders/{id}', [PurchaseOrderController::class, 'destroy'])->middleware('permission:purchase_orders.delete')->name('purchase-orders.destroy');
|
Route::delete('/purchase-orders/{id}', [PurchaseOrderController::class, 'destroy'])->middleware('permission:purchase_orders.delete')->name('purchase-orders.destroy');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
152
app/Modules/Sales/Controllers/SalesImportController.php
Normal file
152
app/Modules/Sales/Controllers/SalesImportController.php
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Sales\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Modules\Sales\Models\SalesImportBatch;
|
||||||
|
use App\Modules\Sales\Imports\SalesImport;
|
||||||
|
use App\Modules\Inventory\Services\InventoryService; // Assuming this exists or we need to use ProductService
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class SalesImportController extends Controller
|
||||||
|
{
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
$perPage = $request->input('per_page', 10);
|
||||||
|
|
||||||
|
$batches = SalesImportBatch::with('importer')
|
||||||
|
->orderByDesc('created_at')
|
||||||
|
->paginate($perPage)
|
||||||
|
->withQueryString();
|
||||||
|
|
||||||
|
return Inertia::render('Sales/Import/Index', [
|
||||||
|
'batches' => $batches,
|
||||||
|
'filters' => [
|
||||||
|
'per_page' => $perPage,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
return Inertia::render('Sales/Import/Create');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'file' => 'required|file|mimes:xlsx,xls,csv,zip',
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::transaction(function () use ($request) {
|
||||||
|
$batch = SalesImportBatch::create([
|
||||||
|
'import_date' => now(),
|
||||||
|
'imported_by' => auth()->id(),
|
||||||
|
'status' => 'pending',
|
||||||
|
'tenant_id' => tenant('id'), // If tenant context requires it, but usually automatic
|
||||||
|
]);
|
||||||
|
|
||||||
|
Excel::import(new SalesImport($batch), $request->file('file'));
|
||||||
|
});
|
||||||
|
|
||||||
|
return redirect()->route('sales-imports.index')->with('success', '匯入成功,請確認內容。');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show(Request $request, SalesImportBatch $import)
|
||||||
|
{
|
||||||
|
$import->load(['items', 'importer']);
|
||||||
|
|
||||||
|
$perPage = $request->input('per_page', 10);
|
||||||
|
|
||||||
|
return Inertia::render('Sales/Import/Show', [
|
||||||
|
'import' => $import,
|
||||||
|
'items' => $import->items()->with(['product', 'warehouse'])->paginate($perPage)->withQueryString(),
|
||||||
|
'filters' => [
|
||||||
|
'per_page' => $perPage,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function confirm(SalesImportBatch $import, InventoryService $inventoryService)
|
||||||
|
{
|
||||||
|
if ($import->status !== 'pending') {
|
||||||
|
return back()->with('error', '此批次無法確認。');
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::transaction(function () use ($import, $inventoryService) {
|
||||||
|
// 1. Prepare Aggregation
|
||||||
|
$aggregatedDeductions = []; // Key: "warehouse_id:product_id:slot"
|
||||||
|
|
||||||
|
// Pre-load necessary warehouses for matching
|
||||||
|
$machineIds = $import->items->pluck('machine_id')->filter()->unique();
|
||||||
|
$warehouses = \App\Modules\Inventory\Models\Warehouse::whereIn('code', $machineIds)->get()->keyBy('code');
|
||||||
|
|
||||||
|
foreach ($import->items as $item) {
|
||||||
|
// Only process shipped items with a valid product
|
||||||
|
if ($item->product_id && $item->original_status === '已出貨') {
|
||||||
|
// Resolve Warehouse from Machine ID
|
||||||
|
$warehouse = $warehouses->get($item->machine_id);
|
||||||
|
|
||||||
|
// Skip if machine_id is empty or warehouse not found
|
||||||
|
if (!$warehouse) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregation Key includes Slot (貨道)
|
||||||
|
$slot = $item->slot ?: '';
|
||||||
|
$key = "{$warehouse->id}:{$item->product_id}:{$slot}";
|
||||||
|
|
||||||
|
if (!isset($aggregatedDeductions[$key])) {
|
||||||
|
$aggregatedDeductions[$key] = [
|
||||||
|
'warehouse_id' => $warehouse->id,
|
||||||
|
'product_id' => $item->product_id,
|
||||||
|
'slot' => $slot,
|
||||||
|
'quantity' => 0,
|
||||||
|
'details' => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$aggregatedDeductions[$key]['quantity'] += $item->quantity;
|
||||||
|
$aggregatedDeductions[$key]['details'][] = $item->transaction_serial;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Execute Aggregated Deductions
|
||||||
|
foreach ($aggregatedDeductions as $deduction) {
|
||||||
|
// Construct a descriptive reason
|
||||||
|
$serialCount = count($deduction['details']);
|
||||||
|
$reason = "銷售出貨彙總 (批號: {$import->id}, 貨道: {$deduction['slot']}, 共 {$serialCount} 筆交易)";
|
||||||
|
|
||||||
|
$inventoryService->decreaseStock(
|
||||||
|
$deduction['product_id'],
|
||||||
|
$deduction['warehouse_id'],
|
||||||
|
$deduction['quantity'],
|
||||||
|
$reason,
|
||||||
|
true, // Force deduction
|
||||||
|
$deduction['slot'] // Location/Slot
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Update Batch Status
|
||||||
|
$import->update([
|
||||||
|
'status' => 'confirmed',
|
||||||
|
'confirmed_at' => now(),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
return redirect()->route('sales-imports.index')->with('success', '已彙總(含貨道)並扣除庫存。');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(SalesImportBatch $import)
|
||||||
|
{
|
||||||
|
if ($import->status !== 'pending') {
|
||||||
|
return back()->with('error', '只能刪除待確認的批次。');
|
||||||
|
}
|
||||||
|
|
||||||
|
$import->delete();
|
||||||
|
return redirect()->route('sales-imports.index')->with('success', '已刪除匯入批次。');
|
||||||
|
}
|
||||||
|
}
|
||||||
24
app/Modules/Sales/Imports/SalesImport.php
Normal file
24
app/Modules/Sales/Imports/SalesImport.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Sales\Imports;
|
||||||
|
|
||||||
|
use App\Modules\Sales\Models\SalesImportBatch;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||||
|
|
||||||
|
class SalesImport implements WithMultipleSheets
|
||||||
|
{
|
||||||
|
protected $batch;
|
||||||
|
|
||||||
|
public function __construct(SalesImportBatch $batch)
|
||||||
|
{
|
||||||
|
$this->batch = $batch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sheets(): array
|
||||||
|
{
|
||||||
|
// Only import the first sheet (index 0)
|
||||||
|
return [
|
||||||
|
0 => new SalesImportSheet($this->batch),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
106
app/Modules/Sales/Imports/SalesImportSheet.php
Normal file
106
app/Modules/Sales/Imports/SalesImportSheet.php
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Sales\Imports;
|
||||||
|
|
||||||
|
use App\Modules\Sales\Models\SalesImportBatch;
|
||||||
|
use App\Modules\Sales\Models\SalesImportItem;
|
||||||
|
use App\Modules\Inventory\Models\Product;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithStartRow;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class SalesImportSheet implements ToCollection, WithStartRow
|
||||||
|
{
|
||||||
|
protected $batch;
|
||||||
|
protected $products;
|
||||||
|
|
||||||
|
public function __construct(SalesImportBatch $batch)
|
||||||
|
{
|
||||||
|
$this->batch = $batch;
|
||||||
|
// Pre-load all products to minimize queries (keyed by code)
|
||||||
|
$this->products = Product::pluck('id', 'code'); // assumes code is unique
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startRow(): int
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function collection(Collection $rows)
|
||||||
|
{
|
||||||
|
$totalQuantity = 0;
|
||||||
|
$totalAmount = 0;
|
||||||
|
$items = [];
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
// Index mapping based on analysis:
|
||||||
|
// 0: 銷貨單號 (Serial)
|
||||||
|
// 1: 機台編號 (Machine ID)
|
||||||
|
// 4: 訂單狀態 (Original Status)
|
||||||
|
// 7: 產品代號 (Product Code)
|
||||||
|
// 9: 銷貨日期 (Transaction At)
|
||||||
|
// 11: 金額 (Amount)
|
||||||
|
// 19: 貨道 (Slot)
|
||||||
|
// Quantity default to 1
|
||||||
|
|
||||||
|
$serial = $row[0];
|
||||||
|
$machineId = $row[1];
|
||||||
|
$originalStatus = $row[4];
|
||||||
|
$productCode = $row[7];
|
||||||
|
$transactionAt = $row[9];
|
||||||
|
$amount = $row[11];
|
||||||
|
$slot = $row[19] ?? null;
|
||||||
|
|
||||||
|
// Skip empty rows
|
||||||
|
if (empty($serial) && empty($productCode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse Date
|
||||||
|
try {
|
||||||
|
// Formatting might be needed depending on Excel date format
|
||||||
|
$transactionAt = Carbon::parse($transactionAt);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$transactionAt = now();
|
||||||
|
}
|
||||||
|
|
||||||
|
$quantity = 1; // Default
|
||||||
|
|
||||||
|
// Clean amount (remove comma etc if needed)
|
||||||
|
$amount = is_numeric($amount) ? $amount : 0;
|
||||||
|
|
||||||
|
$items[] = [
|
||||||
|
'batch_id' => $this->batch->id,
|
||||||
|
'machine_id' => $machineId,
|
||||||
|
'slot' => $slot,
|
||||||
|
'product_code' => $productCode,
|
||||||
|
'product_id' => $this->products[$productCode] ?? null,
|
||||||
|
'transaction_at' => $transactionAt,
|
||||||
|
'transaction_serial' => $serial,
|
||||||
|
'quantity' => (int)$quantity,
|
||||||
|
'amount' => $amount,
|
||||||
|
'original_status' => $originalStatus,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
];
|
||||||
|
|
||||||
|
$totalQuantity += $quantity;
|
||||||
|
$totalAmount += $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bulk insert items (chunk if necessary, but assuming reasonable size)
|
||||||
|
foreach (array_chunk($items, 1000) as $chunk) {
|
||||||
|
SalesImportItem::insert($chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update Batch Totals
|
||||||
|
// Increment totals instead of overwriting, in case we decide to process multiple sheets later?
|
||||||
|
// But for now, since we only process sheet 0, overwriting or incrementing is fine.
|
||||||
|
// Given we strictly return [0 => ...], only one sheet runs.
|
||||||
|
$this->batch->update([
|
||||||
|
'total_quantity' => $totalQuantity,
|
||||||
|
'total_amount' => $totalAmount,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
43
app/Modules/Sales/Models/SalesImportBatch.php
Normal file
43
app/Modules/Sales/Models/SalesImportBatch.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Sales\Models;
|
||||||
|
|
||||||
|
use App\Modules\Core\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
class SalesImportBatch extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $table = 'sales_import_batches';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'import_date',
|
||||||
|
'total_quantity',
|
||||||
|
'total_amount',
|
||||||
|
'status',
|
||||||
|
'imported_by',
|
||||||
|
'confirmed_at',
|
||||||
|
'note',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'import_date' => 'date',
|
||||||
|
'confirmed_at' => 'datetime',
|
||||||
|
'total_quantity' => 'decimal:4',
|
||||||
|
'total_amount' => 'decimal:4',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function items(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(SalesImportItem::class, 'batch_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function importer(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'imported_by');
|
||||||
|
}
|
||||||
|
}
|
||||||
51
app/Modules/Sales/Models/SalesImportItem.php
Normal file
51
app/Modules/Sales/Models/SalesImportItem.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Sales\Models;
|
||||||
|
|
||||||
|
use App\Modules\Inventory\Models\Product;
|
||||||
|
use App\Modules\Inventory\Models\Warehouse;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
class SalesImportItem extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $table = 'sales_import_items';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'batch_id',
|
||||||
|
'machine_id',
|
||||||
|
'slot',
|
||||||
|
'product_code',
|
||||||
|
'product_id',
|
||||||
|
'transaction_at',
|
||||||
|
'transaction_serial',
|
||||||
|
'quantity',
|
||||||
|
'amount',
|
||||||
|
'original_status',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'transaction_at' => 'datetime',
|
||||||
|
'quantity' => 'integer',
|
||||||
|
'amount' => 'decimal:4',
|
||||||
|
'original_status' => 'string',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function batch(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(SalesImportBatch::class, 'batch_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function product(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Product::class, 'product_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function warehouse(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Warehouse::class, 'machine_id', 'code');
|
||||||
|
}
|
||||||
|
}
|
||||||
13
app/Modules/Sales/Routes/web.php
Normal file
13
app/Modules/Sales/Routes/web.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use App\Modules\Sales\Controllers\SalesImportController;
|
||||||
|
|
||||||
|
Route::middleware(['auth', 'verified'])->prefix('sales')->name('sales-imports.')->group(function () {
|
||||||
|
Route::get('/imports', [SalesImportController::class, 'index'])->name('index');
|
||||||
|
Route::get('/imports/create', [SalesImportController::class, 'create'])->name('create');
|
||||||
|
Route::post('/imports', [SalesImportController::class, 'store'])->name('store');
|
||||||
|
Route::get('/imports/{import}', [SalesImportController::class, 'show'])->name('show');
|
||||||
|
Route::post('/imports/{import}/confirm', [SalesImportController::class, 'confirm'])->name('confirm');
|
||||||
|
Route::delete('/imports/{import}', [SalesImportController::class, 'destroy'])->name('destroy');
|
||||||
|
});
|
||||||
@@ -11,16 +11,18 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Schema::create('personal_access_tokens', function (Blueprint $table) {
|
if (!Schema::hasTable('personal_access_tokens')) {
|
||||||
$table->id();
|
Schema::create('personal_access_tokens', function (Blueprint $table) {
|
||||||
$table->morphs('tokenable');
|
$table->id();
|
||||||
$table->text('name');
|
$table->morphs('tokenable');
|
||||||
$table->string('token', 64)->unique();
|
$table->text('name');
|
||||||
$table->text('abilities')->nullable();
|
$table->string('token', 64)->unique();
|
||||||
$table->timestamp('last_used_at')->nullable();
|
$table->text('abilities')->nullable();
|
||||||
$table->timestamp('expires_at')->nullable()->index();
|
$table->timestamp('last_used_at')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamp('expires_at')->nullable()->index();
|
||||||
});
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?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
|
||||||
|
{
|
||||||
|
Schema::table('inventories', function (Blueprint $table) {
|
||||||
|
// 不刪除舊索引(以免外鍵報錯),直接建立新的、更精確的唯一索引
|
||||||
|
// 這樣「商品+批號+貨道」的組合就會被視為唯一,達成多貨道支援
|
||||||
|
$table->unique(['warehouse_id', 'product_id', 'batch_number', 'location'], 'warehouse_product_batch_location_unique');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('inventories', function (Blueprint $table) {
|
||||||
|
$table->dropUnique('warehouse_product_batch_location_unique');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?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
|
||||||
|
{
|
||||||
|
// 最直接的做法:暫時關閉外鍵檢查,然後強制刪除報錯的索引
|
||||||
|
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 直接下達 SQL 指令刪除索引
|
||||||
|
DB::statement('ALTER TABLE inventories DROP INDEX warehouse_product_batch_unique;');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 索引不存在則跳過
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
|
||||||
|
|
||||||
|
DB::statement('ALTER TABLE inventories ADD UNIQUE INDEX warehouse_product_batch_unique (warehouse_id, product_id, batch_number);');
|
||||||
|
|
||||||
|
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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('products', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('sku');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('products', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?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('sales_import_batches', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->date('import_date')->default(now());
|
||||||
|
$table->decimal('total_quantity', 12, 4)->default(0);
|
||||||
|
$table->decimal('total_amount', 12, 4)->default(0);
|
||||||
|
$table->string('status')->default('pending')->comment('pending, confirmed, cancelled');
|
||||||
|
$table->foreignId('imported_by')->nullable()->constrained('users')->nullOnDelete();
|
||||||
|
$table->timestamp('confirmed_at')->nullable();
|
||||||
|
$table->text('note')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::create('sales_import_items', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('batch_id')->constrained('sales_import_batches')->cascadeOnDelete();
|
||||||
|
$table->string('machine_id')->nullable()->comment('機台編號');
|
||||||
|
$table->string('product_code')->comment('商品代碼');
|
||||||
|
// product_id could be null if product not found at import time, but we should try to link it.
|
||||||
|
// Constraint might fail if product doesn't exist, so maybe just foreignId without constrained first,
|
||||||
|
// or nullable constrained. Since we might import data for products not yet in system?
|
||||||
|
// Better to allow null product_id.
|
||||||
|
$table->foreignId('product_id')->nullable()->constrained('products')->nullOnDelete();
|
||||||
|
$table->timestamp('transaction_at')->nullable()->comment('交易時間');
|
||||||
|
$table->string('transaction_serial')->nullable()->comment('交易序號');
|
||||||
|
$table->decimal('quantity', 12, 4)->default(0);
|
||||||
|
$table->decimal('amount', 12, 4)->default(0);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('sales_import_items');
|
||||||
|
Schema::dropIfExists('sales_import_batches');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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('sales_import_items', function (Blueprint $table) {
|
||||||
|
$table->string('original_status')->nullable()->after('amount')->comment('原始檔案狀態');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('sales_import_items', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('original_status');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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('sales_import_items', function (Blueprint $table) {
|
||||||
|
$table->string('slot')->nullable()->after('machine_id')->comment('貨道');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('sales_import_items', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('slot');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -30,6 +30,8 @@ class PermissionSeeder extends Seeder
|
|||||||
'purchase_orders.create',
|
'purchase_orders.create',
|
||||||
'purchase_orders.edit',
|
'purchase_orders.edit',
|
||||||
'purchase_orders.delete',
|
'purchase_orders.delete',
|
||||||
|
'purchase_orders.approve', // 核准權限
|
||||||
|
'purchase_orders.cancel', // 作廢權限(原取消)
|
||||||
|
|
||||||
|
|
||||||
// 庫存管理
|
// 庫存管理
|
||||||
@@ -138,7 +140,7 @@ class PermissionSeeder extends Seeder
|
|||||||
$admin->givePermissionTo([
|
$admin->givePermissionTo([
|
||||||
'products.view', 'products.create', 'products.edit', 'products.delete',
|
'products.view', 'products.create', 'products.edit', 'products.delete',
|
||||||
'purchase_orders.view', 'purchase_orders.create', 'purchase_orders.edit',
|
'purchase_orders.view', 'purchase_orders.create', 'purchase_orders.edit',
|
||||||
'purchase_orders.delete',
|
'purchase_orders.delete', 'purchase_orders.approve', 'purchase_orders.cancel',
|
||||||
'inventory.view', 'inventory.view_cost', 'inventory.delete',
|
'inventory.view', 'inventory.view_cost', 'inventory.delete',
|
||||||
'inventory_count.view', 'inventory_count.create', 'inventory_count.edit', 'inventory_count.delete',
|
'inventory_count.view', 'inventory_count.create', 'inventory_count.edit', 'inventory_count.delete',
|
||||||
'inventory_adjust.view', 'inventory_adjust.create', 'inventory_adjust.edit', 'inventory_adjust.delete',
|
'inventory_adjust.view', 'inventory_adjust.create', 'inventory_adjust.edit', 'inventory_adjust.delete',
|
||||||
|
|||||||
BIN
docs/~$f6_1770350984272.xlsx
Normal file
BIN
docs/~$f6_1770350984272.xlsx
Normal file
Binary file not shown.
@@ -1,10 +1,11 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Pencil, Eye, Trash2 } from "lucide-react";
|
import { Pencil, Eye, Trash2 } from "lucide-react";
|
||||||
import { Button } from "@/Components/ui/button";
|
import { Button } from "@/Components/ui/button";
|
||||||
import { Link, useForm } from "@inertiajs/react";
|
import { Link, useForm, usePage } from "@inertiajs/react";
|
||||||
import type { PurchaseOrder } from "@/types/purchase-order";
|
import type { PurchaseOrder } from "@/types/purchase-order";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Can } from "@/Components/Permission/Can";
|
import { Can } from "@/Components/Permission/Can";
|
||||||
|
import { PageProps } from "@/types/global";
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
AlertDialogAction,
|
AlertDialogAction,
|
||||||
@@ -21,6 +22,18 @@ export function PurchaseOrderActions({
|
|||||||
}: { order: PurchaseOrder }) {
|
}: { order: PurchaseOrder }) {
|
||||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||||||
const { delete: destroy, processing } = useForm({});
|
const { delete: destroy, processing } = useForm({});
|
||||||
|
const { auth } = usePage<PageProps>().props;
|
||||||
|
const permissions = auth.user?.permissions || [];
|
||||||
|
const isSuperAdmin = auth.user?.roles?.some((r: any) => r.name === 'super-admin');
|
||||||
|
|
||||||
|
const canApprove = isSuperAdmin || permissions.includes('purchase_orders.approve');
|
||||||
|
const canEdit = isSuperAdmin || permissions.includes('purchase_orders.edit');
|
||||||
|
|
||||||
|
// 編輯按鈕顯示邏輯:
|
||||||
|
// 1. 草稿狀態 + 編輯權限
|
||||||
|
// 2. 待核准狀態 + 核准權限 (讓主管能直接改)
|
||||||
|
const showEditButton = (order.status === 'draft' && canEdit) ||
|
||||||
|
(order.status === 'pending' && canApprove);
|
||||||
|
|
||||||
const handleConfirmDelete = () => {
|
const handleConfirmDelete = () => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -45,7 +58,7 @@ export function PurchaseOrderActions({
|
|||||||
<Eye className="h-4 w-4" />
|
<Eye className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<Can permission="purchase_orders.edit">
|
{showEditButton && (
|
||||||
<Link href={`/purchase-orders/${order.id}/edit`}>
|
<Link href={`/purchase-orders/${order.id}/edit`}>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
@@ -56,18 +69,20 @@ export function PurchaseOrderActions({
|
|||||||
<Pencil className="h-4 w-4" />
|
<Pencil className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</Can>
|
)}
|
||||||
<Can permission="purchase_orders.delete">
|
<Can permission="purchase_orders.delete">
|
||||||
<Button
|
{order.status === 'draft' && (
|
||||||
variant="outline"
|
<Button
|
||||||
size="sm"
|
variant="outline"
|
||||||
className="button-outlined-error"
|
size="sm"
|
||||||
title="刪除"
|
className="button-outlined-error"
|
||||||
onClick={() => setShowDeleteDialog(true)}
|
title="刪除"
|
||||||
disabled={processing}
|
onClick={() => setShowDeleteDialog(true)}
|
||||||
>
|
disabled={processing}
|
||||||
<Trash2 className="h-4 w-4" />
|
>
|
||||||
</Button>
|
<Trash2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
||||||
<AlertDialogContent>
|
<AlertDialogContent>
|
||||||
|
|||||||
@@ -0,0 +1,207 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { useForm } from "@inertiajs/react";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/Components/ui/dialog";
|
||||||
|
import { Button } from "@/Components/ui/button";
|
||||||
|
import { Input } from "@/Components/ui/input";
|
||||||
|
import { Label } from "@/Components/ui/label";
|
||||||
|
import { Download, FileUp, Loader2, AlertCircle, FileSpreadsheet, Info } from "lucide-react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { Alert, AlertDescription } from "@/Components/ui/alert";
|
||||||
|
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/Components/ui/accordion";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
warehouseId: string;
|
||||||
|
warehouseName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function InventoryImportDialog({ open, onOpenChange, warehouseId, warehouseName }: Props) {
|
||||||
|
const { data, setData, post, processing, errors, reset, clearErrors } = useForm({
|
||||||
|
file: null as File | null,
|
||||||
|
inboundDate: new Date().toISOString().split('T')[0],
|
||||||
|
notes: "Excel 匯入",
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
post(route("warehouses.inventory.import", warehouseId), {
|
||||||
|
forceFormData: true,
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success("庫存匯入完成");
|
||||||
|
onOpenChange(false);
|
||||||
|
reset();
|
||||||
|
},
|
||||||
|
onError: (err) => {
|
||||||
|
console.error("Import error:", err);
|
||||||
|
toast.error("匯入失敗,請檢查檔案格式");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDownloadTemplate = () => {
|
||||||
|
window.location.href = route("warehouses.inventory.template");
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={(val) => {
|
||||||
|
onOpenChange(val);
|
||||||
|
if (!val) {
|
||||||
|
reset();
|
||||||
|
clearErrors();
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<DialogContent className="sm:max-w-[550px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>匯入庫存資料</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
請先下載範本,填寫完畢後上傳檔案進行批次入庫。
|
||||||
|
<div className="mt-2 p-2 bg-primary-main/5 border border-primary-main/20 rounded text-primary-main font-medium">
|
||||||
|
目標倉庫:{warehouseName}
|
||||||
|
</div>
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-6">
|
||||||
|
{/* 步驟 1: 下載範本 */}
|
||||||
|
<div className="space-y-2 p-4 bg-gray-50 rounded-lg border border-gray-100">
|
||||||
|
<Label className="font-medium flex items-center gap-2">
|
||||||
|
<FileSpreadsheet className="w-4 h-4 text-green-600" />
|
||||||
|
步驟 1:取得匯入範本
|
||||||
|
</Label>
|
||||||
|
<div className="text-sm text-gray-500 mb-2">
|
||||||
|
下載標準範本以確保資料格式正確。請勿修改標題欄位。
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleDownloadTemplate}
|
||||||
|
className="w-full sm:w-auto button-outlined-primary"
|
||||||
|
>
|
||||||
|
<Download className="w-4 h-4 mr-2" />
|
||||||
|
下載庫存匯入範本 (.xlsx)
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 步驟 2: 設定資訊 */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label className="font-medium flex items-center gap-2">
|
||||||
|
<Info className="w-4 h-4 text-primary-main" />
|
||||||
|
步驟 2:設定入庫資訊
|
||||||
|
</Label>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="inboundDate" className="text-sm text-gray-700 flex items-center gap-1.5 align-middle">
|
||||||
|
入庫日期 <span className="text-red-500">*</span>
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="inboundDate"
|
||||||
|
type="date"
|
||||||
|
value={data.inboundDate}
|
||||||
|
onChange={e => setData('inboundDate', e.target.value)}
|
||||||
|
required
|
||||||
|
className="cursor-pointer"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="notes" className="text-sm text-gray-700 flex items-center gap-1.5">
|
||||||
|
入庫備註
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="notes"
|
||||||
|
placeholder="選填備註"
|
||||||
|
value={data.notes}
|
||||||
|
onChange={e => setData('notes', e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 步驟 3: 上傳檔案 */}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label className="font-medium flex items-center gap-2">
|
||||||
|
<FileUp className="w-4 h-4 text-blue-600" />
|
||||||
|
步驟 3:上傳填寫後的檔案
|
||||||
|
</Label>
|
||||||
|
<div className="grid w-full max-w-sm items-center gap-1.5">
|
||||||
|
<Input
|
||||||
|
id="file"
|
||||||
|
type="file"
|
||||||
|
accept=".xlsx,.xls,.csv"
|
||||||
|
onChange={e => setData('file', e.target.files ? e.target.files[0] : null)}
|
||||||
|
required
|
||||||
|
className="cursor-pointer"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{errors.file && (
|
||||||
|
<Alert variant="destructive" className="mt-2">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<AlertDescription className="whitespace-pre-wrap">
|
||||||
|
{errors.file}
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 欄位說明 */}
|
||||||
|
<Accordion type="single" collapsible className="w-full border rounded-lg px-2">
|
||||||
|
<AccordionItem value="rules" className="border-b-0">
|
||||||
|
<AccordionTrigger className="text-sm text-gray-500 hover:no-underline py-3">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Info className="h-4 w-4" />
|
||||||
|
庫存匯入規則與提示
|
||||||
|
</div>
|
||||||
|
</AccordionTrigger>
|
||||||
|
<AccordionContent>
|
||||||
|
<div className="text-sm text-gray-600 space-y-2 pb-2 pl-6">
|
||||||
|
<ul className="list-disc space-y-1">
|
||||||
|
<li><span className="font-medium text-gray-700">商品匹配</span>:優先使用「商品條碼」匹配,其次為「商品代號」。</li>
|
||||||
|
<li><span className="font-medium text-gray-700">無批號模式</span>:若 Excel 中的「批號」欄位保持空白,系統將自動累加至該商品的「通用紀錄」。(對販賣機而言,此紀錄通常對應至預設的一般庫存)。</li>
|
||||||
|
<li><span className="font-medium text-gray-700">效期設定</span>:若商品無效期概念可留空,或輸入格式如:2026/12/31。</li>
|
||||||
|
<li><span className="font-medium text-gray-700">入庫單價</span>:未填寫時將預設使用商品的「採購成本價」。</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</AccordionContent>
|
||||||
|
</AccordionItem>
|
||||||
|
</Accordion>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => onOpenChange(false)}
|
||||||
|
disabled={processing}
|
||||||
|
className="button-outlined-primary"
|
||||||
|
>
|
||||||
|
取消
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
disabled={processing || !data.file}
|
||||||
|
className="button-filled-primary"
|
||||||
|
>
|
||||||
|
{processing ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||||
|
上傳中...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
"開始匯入"
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -42,7 +42,11 @@ export default function InventoryTable({
|
|||||||
onView,
|
onView,
|
||||||
onDelete,
|
onDelete,
|
||||||
onViewProduct,
|
onViewProduct,
|
||||||
}: InventoryTableProps) {
|
warehouse,
|
||||||
|
}: InventoryTableProps & { warehouse: any }) {
|
||||||
|
// 判斷是否為販賣機倉庫
|
||||||
|
const isVending = warehouse?.type === "vending";
|
||||||
|
|
||||||
// 每個商品的展開/折疊狀態
|
// 每個商品的展開/折疊狀態
|
||||||
const [expandedProducts, setExpandedProducts] = useState<Set<string>>(new Set());
|
const [expandedProducts, setExpandedProducts] = useState<Set<string>>(new Set());
|
||||||
|
|
||||||
@@ -131,9 +135,19 @@ export default function InventoryTable({
|
|||||||
) : (
|
) : (
|
||||||
<ChevronRight className="h-5 w-5 text-gray-600" />
|
<ChevronRight className="h-5 w-5 text-gray-600" />
|
||||||
)}
|
)}
|
||||||
<h3 className="font-semibold text-gray-900">{group.productName}</h3>
|
<h3 className="font-semibold text-gray-900">
|
||||||
|
{group.productName}
|
||||||
|
{isVending && group.batches.length > 0 && (() => {
|
||||||
|
const locations = Array.from(new Set(group.batches.map(b => b.location).filter(Boolean)));
|
||||||
|
return locations.length > 0 ? (
|
||||||
|
<span className="ml-2 text-primary-main font-bold">
|
||||||
|
{locations.map(loc => `[${loc}]`).join('')}
|
||||||
|
</span>
|
||||||
|
) : null;
|
||||||
|
})()}
|
||||||
|
</h3>
|
||||||
<span className="text-sm text-gray-500">
|
<span className="text-sm text-gray-500">
|
||||||
{hasInventory ? `${group.batches.length} 個批號` : '無庫存'}
|
{isVending ? '' : (hasInventory ? `${group.batches.length} 個批號` : '無庫存')}
|
||||||
</span>
|
</span>
|
||||||
{group.batches.some(b => b.expiryDate && new Date(b.expiryDate) < new Date()) && (
|
{group.batches.some(b => b.expiryDate && new Date(b.expiryDate) < new Date()) && (
|
||||||
<Badge className="bg-red-50 text-red-600 border-red-200">
|
<Badge className="bg-red-50 text-red-600 border-red-200">
|
||||||
@@ -197,7 +211,8 @@ export default function InventoryTable({
|
|||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className="w-[5%]">#</TableHead>
|
<TableHead className="w-[5%]">#</TableHead>
|
||||||
<TableHead className="w-[12%]">批號</TableHead>
|
<TableHead className="w-[15%]">批號</TableHead>
|
||||||
|
<TableHead className="w-[10%]">{isVending ? "貨道" : "儲位"}</TableHead>
|
||||||
<TableHead className="w-[10%]">庫存數量</TableHead>
|
<TableHead className="w-[10%]">庫存數量</TableHead>
|
||||||
<Can permission="inventory.view_cost">
|
<Can permission="inventory.view_cost">
|
||||||
<TableHead className="w-[10%]">單位成本</TableHead>
|
<TableHead className="w-[10%]">單位成本</TableHead>
|
||||||
@@ -215,6 +230,7 @@ export default function InventoryTable({
|
|||||||
<TableRow key={batch.id}>
|
<TableRow key={batch.id}>
|
||||||
<TableCell className="text-grey-2">{index + 1}</TableCell>
|
<TableCell className="text-grey-2">{index + 1}</TableCell>
|
||||||
<TableCell>{batch.batchNumber || "-"}</TableCell>
|
<TableCell>{batch.batchNumber || "-"}</TableCell>
|
||||||
|
<TableCell className="font-medium text-primary-main">{batch.location || "-"}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<span>{batch.quantity} {batch.unit}</span>
|
<span>{batch.quantity} {batch.unit}</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export interface Transaction {
|
|||||||
userName: string;
|
userName: string;
|
||||||
actualTime: string;
|
actualTime: string;
|
||||||
batchNumber?: string; // 商品層級查詢時顯示批號
|
batchNumber?: string; // 商品層級查詢時顯示批號
|
||||||
|
slot?: string; // 貨道資訊
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TransactionTableProps {
|
interface TransactionTableProps {
|
||||||
@@ -27,6 +28,8 @@ export default function TransactionTable({ transactions, showBatchNumber = false
|
|||||||
|
|
||||||
// 自動偵測是否需要顯示批號(如果任一筆記錄有 batchNumber)
|
// 自動偵測是否需要顯示批號(如果任一筆記錄有 batchNumber)
|
||||||
const shouldShowBatchNumber = showBatchNumber || transactions.some(tx => tx.batchNumber);
|
const shouldShowBatchNumber = showBatchNumber || transactions.some(tx => tx.batchNumber);
|
||||||
|
// 自動偵測是否需要顯示貨道(如果任一筆記錄有 slot)
|
||||||
|
const shouldShowSlot = transactions.some(tx => tx.slot);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
@@ -39,6 +42,7 @@ export default function TransactionTable({ transactions, showBatchNumber = false
|
|||||||
<th className="px-4 py-3">類型</th>
|
<th className="px-4 py-3">類型</th>
|
||||||
<th className="px-4 py-3 text-right">變動數量</th>
|
<th className="px-4 py-3 text-right">變動數量</th>
|
||||||
<th className="px-4 py-3 text-right">結餘</th>
|
<th className="px-4 py-3 text-right">結餘</th>
|
||||||
|
{shouldShowSlot && <th className="px-4 py-3">貨道</th>}
|
||||||
<th className="px-4 py-3">經手人</th>
|
<th className="px-4 py-3">經手人</th>
|
||||||
<th className="px-4 py-3">原因/備註</th>
|
<th className="px-4 py-3">原因/備註</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -66,6 +70,9 @@ export default function TransactionTable({ transactions, showBatchNumber = false
|
|||||||
{tx.quantity > 0 ? '+' : ''}{tx.quantity}
|
{tx.quantity > 0 ? '+' : ''}{tx.quantity}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-4 py-3 text-right">{tx.balanceAfter}</td>
|
<td className="px-4 py-3 text-right">{tx.balanceAfter}</td>
|
||||||
|
{shouldShowSlot && (
|
||||||
|
<td className="px-4 py-3 font-medium text-primary-main">{tx.slot || '-'}</td>
|
||||||
|
)}
|
||||||
<td className="px-4 py-3">{tx.userName}</td>
|
<td className="px-4 py-3">{tx.userName}</td>
|
||||||
<td className="px-4 py-3 text-gray-500">{tx.reason || '-'}</td>
|
<td className="px-4 py-3 text-gray-500">{tx.reason || '-'}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -53,7 +53,16 @@ export default function SafetyStockList({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 獲取狀態徽章 (與 InventoryTable 保持一致)
|
// 獲取狀態徽章 (與 InventoryTable 保持一致)
|
||||||
const getStatusBadge = (quantity: number, safetyStock: number) => {
|
const getStatusBadge = (quantity: number, safetyStock: number, isNew?: boolean) => {
|
||||||
|
// 如果是自動帶入的品項且尚未存檔,顯示「未設定」
|
||||||
|
if (isNew) {
|
||||||
|
return (
|
||||||
|
<Badge variant="outline" className="text-gray-400 border-gray-200 font-normal">
|
||||||
|
未設定
|
||||||
|
</Badge>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const status = getSafetyStockStatus(quantity, safetyStock);
|
const status = getSafetyStockStatus(quantity, safetyStock);
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case "正常":
|
case "正常":
|
||||||
@@ -122,7 +131,7 @@ export default function SafetyStockList({
|
|||||||
</span>
|
</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{getStatusBadge(currentStock, setting.safetyStock)}
|
{getStatusBadge(currentStock, setting.safetyStock, setting.isNew)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="text-right">
|
<TableCell className="text-right">
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import {
|
|||||||
Edit,
|
Edit,
|
||||||
Info,
|
Info,
|
||||||
FileText,
|
FileText,
|
||||||
|
CupSoda,
|
||||||
|
QrCode,
|
||||||
|
Milk,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { Warehouse, WarehouseStats } from "@/types/warehouse";
|
import { Warehouse, WarehouseStats } from "@/types/warehouse";
|
||||||
import { Button } from "@/Components/ui/button";
|
import { Button } from "@/Components/ui/button";
|
||||||
@@ -50,17 +53,28 @@ export default function WarehouseCard({
|
|||||||
onEdit,
|
onEdit,
|
||||||
}: WarehouseCardProps) {
|
}: WarehouseCardProps) {
|
||||||
const [showInfoDialog, setShowInfoDialog] = useState(false);
|
const [showInfoDialog, setShowInfoDialog] = useState(false);
|
||||||
|
const isVending = warehouse.type === 'vending';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
className={`relative overflow-hidden transition-all hover:shadow-lg flex flex-col ${hasWarning
|
className={`relative overflow-hidden transition-all duration-300 hover:shadow-lg flex flex-col group ${isVending
|
||||||
? "border-orange-400 border-2 bg-orange-50/50"
|
? "border-primary-400 border-2 bg-white min-h-[300px]"
|
||||||
: "border-gray-200"
|
: hasWarning
|
||||||
|
? "border-orange-400 border-2 bg-orange-50/50"
|
||||||
|
: "border-gray-200"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
|
{/* 裝飾性背景元素 (僅限販賣機) */}
|
||||||
|
{isVending && (
|
||||||
|
<>
|
||||||
|
{/* LED 裝飾線條 - 保持主色調 */}
|
||||||
|
<div className="absolute top-0 bottom-0 left-0 w-1 bg-primary-500 shadow-[1px_0_5px_rgba(var(--primary-main-rgb),0.2)]" />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* 警告橫幅 */}
|
{/* 警告橫幅 */}
|
||||||
{hasWarning && (
|
{hasWarning && (
|
||||||
<div className="absolute top-0 left-0 right-0 bg-orange-500 text-white px-4 py-1 flex items-center justify-between text-sm">
|
<div className="absolute top-0 left-0 right-0 bg-orange-500 text-white px-4 py-1 flex items-center justify-between text-sm z-10">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<AlertTriangle className="h-4 w-4" />
|
<AlertTriangle className="h-4 w-4" />
|
||||||
<span>低庫存警告</span>
|
<span>低庫存警告</span>
|
||||||
@@ -71,12 +85,14 @@ export default function WarehouseCard({
|
|||||||
|
|
||||||
<CardContent className={`p-6 flex flex-col flex-1 ${hasWarning ? "pt-12" : "pt-6"}`}>
|
<CardContent className={`p-6 flex flex-col flex-1 ${hasWarning ? "pt-12" : "pt-6"}`}>
|
||||||
{/* 上半部:資訊區域 */}
|
{/* 上半部:資訊區域 */}
|
||||||
<div className="flex-1">
|
<div className="flex-1 relative z-10">
|
||||||
{/* 標題區塊 */}
|
{/* 標題區塊 */}
|
||||||
<div className="flex items-start justify-between mb-4">
|
<div className="flex items-start justify-between mb-2">
|
||||||
<div>
|
<div>
|
||||||
<div className="flex items-center gap-2 mb-1">
|
<div className="flex items-center gap-2 mb-1">
|
||||||
<h3 className="text-2xl font-bold">{warehouse.name}</h3>
|
<h3 className="text-2xl font-bold text-gray-900">
|
||||||
|
{warehouse.name}
|
||||||
|
</h3>
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowInfoDialog(true)}
|
onClick={() => setShowInfoDialog(true)}
|
||||||
className="text-gray-400 hover:text-gray-600 transition-colors"
|
className="text-gray-400 hover:text-gray-600 transition-colors"
|
||||||
@@ -92,30 +108,22 @@ export default function WarehouseCard({
|
|||||||
{WAREHOUSE_TYPE_LABELS[warehouse.type || 'standard'] || '標準倉'}
|
{WAREHOUSE_TYPE_LABELS[warehouse.type || 'standard'] || '標準倉'}
|
||||||
{warehouse.type === 'quarantine' ? ' (不計入可用)' : ' (計入可用)'}
|
{warehouse.type === 'quarantine' ? ' (不計入可用)' : ' (計入可用)'}
|
||||||
</Badge>
|
</Badge>
|
||||||
{warehouse.type === 'transit' && warehouse.license_plate && (
|
|
||||||
<Badge variant="secondary" className="text-xs font-normal bg-yellow-100 text-yellow-800 border-yellow-200">
|
|
||||||
{warehouse.license_plate} {warehouse.driver_name && `(${warehouse.driver_name})`}
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="text-sm text-gray-600 mb-4 line-clamp-2 min-h-[40px]">
|
<div className="text-sm text-gray-600 mb-4 line-clamp-2 min-h-[40px]">
|
||||||
{warehouse.description || "無描述"}
|
{warehouse.description || (isVending ? "管理此機台的商品配貨與補貨狀況" : "無描述")}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* 統計區塊 */}
|
||||||
{/* 統計區塊 - 狀態標籤 */}
|
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
|
|
||||||
{/* 帳面庫存總計 (金額) - 瑕疵倉隱藏此項以減少重複 */}
|
|
||||||
<Can permission="inventory.view_cost">
|
<Can permission="inventory.view_cost">
|
||||||
{warehouse.type !== 'quarantine' && (
|
{warehouse.type !== 'quarantine' && (
|
||||||
<div className="flex items-center justify-between p-3 rounded-lg bg-primary-50/50 border border-primary-100">
|
<div className="flex items-center justify-between p-3 rounded-lg bg-primary-50/50 border border-primary-100 text-primary-700">
|
||||||
<div className="flex items-center gap-2 text-primary-700">
|
<div className="flex items-center gap-2">
|
||||||
<Package className="h-4 w-4" />
|
<Package className="h-4 w-4 opacity-80" />
|
||||||
<span className="text-sm font-medium">帳面庫存總計</span>
|
<span className="text-sm font-medium">帳面庫存估值</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-sm font-bold text-primary-main">
|
<div className="text-sm font-bold text-primary-main">
|
||||||
${Number(stats.totalValue || 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
|
${Number(stats.totalValue || 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
|
||||||
@@ -124,7 +132,6 @@ export default function WarehouseCard({
|
|||||||
)}
|
)}
|
||||||
</Can>
|
</Can>
|
||||||
|
|
||||||
{/* 過期統計 (金額) */}
|
|
||||||
<Can permission="inventory.view_cost">
|
<Can permission="inventory.view_cost">
|
||||||
{Number(stats.abnormalValue || 0) > 0 && (
|
{Number(stats.abnormalValue || 0) > 0 && (
|
||||||
<div className="flex items-center justify-between p-3 rounded-lg bg-red-50/50 border border-red-100 mt-3">
|
<div className="flex items-center justify-between p-3 rounded-lg bg-red-50/50 border border-red-100 mt-3">
|
||||||
@@ -141,12 +148,31 @@ export default function WarehouseCard({
|
|||||||
)}
|
)}
|
||||||
</Can>
|
</Can>
|
||||||
|
|
||||||
|
{/* 販賣機特色視覺:投幣、取物口裝飾 (移動至帳面庫存下方,顏色更顯眼) */}
|
||||||
|
{isVending && (
|
||||||
|
<div className="flex gap-4 mt-6 items-end">
|
||||||
|
<div className="flex-1 h-12 bg-gray-100 rounded-lg border-2 border-gray-300 shadow-inner flex items-center justify-center relative overflow-hidden">
|
||||||
|
<div className="absolute inset-0 bg-gradient-to-b from-gray-200/50 to-transparent pointer-events-none" />
|
||||||
|
<div className="flex gap-1 items-end opacity-30 pb-1">
|
||||||
|
<CupSoda className="h-5 w-5 text-gray-400 rotate-12 -translate-x-1" />
|
||||||
|
<Milk className="h-6 w-6 text-gray-500 -rotate-12 translate-y-1" />
|
||||||
|
<CupSoda className="h-5 w-5 text-gray-400 rotate-3" />
|
||||||
|
<Milk className="h-5 w-5 text-gray-400 -rotate-6 translate-x-1" />
|
||||||
|
<CupSoda className="h-6 w-6 text-gray-500 rotate-12 translate-y-1" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="w-10 h-10 bg-gray-200 rounded-sm border-2 border-gray-400 flex items-center justify-center p-1 shadow-sm self-center">
|
||||||
|
<div className="text-gray-600 opacity-60">
|
||||||
|
<QrCode className="h-6 w-6" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 下半部:操作按鈕 */}
|
{/* 下半部:操作按鈕 */}
|
||||||
<div className="mt-5 pt-3 border-t border-gray-200">
|
<div className="mt-5 pt-4 border-t border-gray-200">
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => onViewInventory(warehouse.id)}
|
onClick={() => onViewInventory(warehouse.id)}
|
||||||
|
|||||||
@@ -143,14 +143,15 @@ export default function WarehouseDialog({
|
|||||||
{/* 倉庫編號 */}
|
{/* 倉庫編號 */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="code">
|
<Label htmlFor="code">
|
||||||
倉庫編號
|
倉庫編號 <span className="text-red-500">*</span>
|
||||||
</Label>
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
id="code"
|
id="code"
|
||||||
value={warehouse ? formData.code : ""}
|
value={formData.code}
|
||||||
disabled={true}
|
onChange={(e) => setFormData({ ...formData, code: e.target.value })}
|
||||||
placeholder={warehouse ? "" : "系統自動產生"}
|
placeholder="請輸入倉庫編號"
|
||||||
className="bg-gray-100"
|
required
|
||||||
|
className="h-9"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const buttonVariants = cva(
|
|||||||
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
||||||
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
||||||
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
||||||
|
xl: "h-14 px-12 text-lg font-bold rounded-xl shadow-lg transition-all hover:scale-[1.02] active:scale-[0.98] gap-2",
|
||||||
icon: "size-9 rounded-md",
|
icon: "size-9 rounded-md",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ import {
|
|||||||
FileSpreadsheet,
|
FileSpreadsheet,
|
||||||
BookOpen,
|
BookOpen,
|
||||||
ClipboardCheck,
|
ClipboardCheck,
|
||||||
ArrowLeftRight
|
ArrowLeftRight,
|
||||||
|
TrendingUp,
|
||||||
|
FileUp
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { toast, Toaster } from "sonner";
|
import { toast, Toaster } from "sonner";
|
||||||
import { useState, useEffect, useMemo, useRef } from "react";
|
import { useState, useEffect, useMemo, useRef } from "react";
|
||||||
@@ -159,6 +161,21 @@ export default function AuthenticatedLayout({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "sales-management",
|
||||||
|
label: "銷售管理",
|
||||||
|
icon: <TrendingUp className="h-5 w-5" />,
|
||||||
|
// permission: ["sales.view_imports"], // Temporarily disabled for immediate visibility
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
id: "sales-import-list",
|
||||||
|
label: "銷售單匯入",
|
||||||
|
icon: <FileUp className="h-4 w-4" />,
|
||||||
|
route: "/sales/imports",
|
||||||
|
// permission: "sales.view_imports",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "production-management",
|
id: "production-management",
|
||||||
label: "生產管理",
|
label: "生產管理",
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ export default function PermissionSelector({ groupedPermissions, selectedPermiss
|
|||||||
'view_cost': '檢視成本',
|
'view_cost': '檢視成本',
|
||||||
'view_logs': '檢視日誌',
|
'view_logs': '檢視日誌',
|
||||||
'activate': '啟用/停用',
|
'activate': '啟用/停用',
|
||||||
|
'approve': '核准/退回',
|
||||||
|
'cancel': '取消',
|
||||||
};
|
};
|
||||||
|
|
||||||
const actionText = map[action] || action;
|
const actionText = map[action] || action;
|
||||||
@@ -203,6 +205,11 @@ export default function PermissionSelector({ groupedPermissions, selectedPermiss
|
|||||||
const totalCount = group.permissions.length;
|
const totalCount = group.permissions.length;
|
||||||
const isAllSelected = selectedCount === totalCount;
|
const isAllSelected = selectedCount === totalCount;
|
||||||
|
|
||||||
|
// 將權限分為「基本操作」與「狀態/進階操作」
|
||||||
|
const statusActions = ['approve', 'cancel', 'complete', 'activate'];
|
||||||
|
const normalPermissions = group.permissions.filter(p => !statusActions.includes(p.name.split('.').pop() || ''));
|
||||||
|
const specialPermissions = group.permissions.filter(p => statusActions.includes(p.name.split('.').pop() || ''));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AccordionItem
|
<AccordionItem
|
||||||
key={group.key}
|
key={group.key}
|
||||||
@@ -210,18 +217,11 @@ export default function PermissionSelector({ groupedPermissions, selectedPermiss
|
|||||||
className="bg-white border rounded-lg px-2 data-[state=open]:bg-gray-50/50 last:border-b"
|
className="bg-white border rounded-lg px-2 data-[state=open]:bg-gray-50/50 last:border-b"
|
||||||
>
|
>
|
||||||
<div className="flex items-center w-full">
|
<div className="flex items-center w-full">
|
||||||
{/* Group Selection Checkbox - Moved outside trigger to avoid bubbling issues, positioned left */}
|
|
||||||
<div className="flex items-center pl-2 pr-1">
|
<div className="flex items-center pl-2 pr-1">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
id={`group-select-${group.key}`}
|
id={`group-select-${group.key}`}
|
||||||
checked={isAllSelected}
|
checked={isAllSelected}
|
||||||
onCheckedChange={() => {
|
onCheckedChange={() => toggleGroup(group.permissions)}
|
||||||
// Stop propagation to prevent accordion from toggling
|
|
||||||
// This is implicitly handled by the checkbox being a sibling,
|
|
||||||
// but if it were a child of AccordionTrigger, stopPropagation would be needed.
|
|
||||||
// For clarity, we can add it here if needed, but the current structure makes it unnecessary.
|
|
||||||
toggleGroup(group.permissions);
|
|
||||||
}}
|
|
||||||
className="data-[state=checked]:bg-primary-main"
|
className="data-[state=checked]:bg-primary-main"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -241,30 +241,47 @@ export default function PermissionSelector({ groupedPermissions, selectedPermiss
|
|||||||
</AccordionTrigger>
|
</AccordionTrigger>
|
||||||
</div>
|
</div>
|
||||||
<AccordionContent className="px-2 pb-4">
|
<AccordionContent className="px-2 pb-4">
|
||||||
<div className="pl-10 space-y-3 pt-1">
|
<div className="pl-10 space-y-6 pt-1">
|
||||||
{/* Permissions Grid */}
|
{/* 基本操作 */}
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-y-3 gap-x-4">
|
{normalPermissions.length > 0 && (
|
||||||
{group.permissions.map((permission) => (
|
<div className="space-y-3">
|
||||||
<div key={permission.id} className="flex items-start space-x-3">
|
<div className="text-xs font-semibold text-gray-400 uppercase tracking-wider">
|
||||||
<Checkbox
|
基本功能權限
|
||||||
id={permission.name}
|
|
||||||
checked={selectedPermissions.includes(permission.name)}
|
|
||||||
onCheckedChange={() => togglePermission(permission.name)}
|
|
||||||
/>
|
|
||||||
<div className="grid gap-1.5 leading-none">
|
|
||||||
<label
|
|
||||||
htmlFor={permission.name}
|
|
||||||
className="text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer text-gray-700 hover:text-primary-main transition-colors"
|
|
||||||
>
|
|
||||||
{translateAction(permission.name)}
|
|
||||||
</label>
|
|
||||||
<p className="text-[10px] text-gray-400 font-mono">
|
|
||||||
{permission.name}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-y-3 gap-x-4">
|
||||||
</div>
|
{normalPermissions.map((permission) => (
|
||||||
|
<PermissionItem
|
||||||
|
key={permission.id}
|
||||||
|
permission={permission}
|
||||||
|
selectedPermissions={selectedPermissions}
|
||||||
|
onToggle={togglePermission}
|
||||||
|
translate={translateAction}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* 狀態操作/進階權限 */}
|
||||||
|
{specialPermissions.length > 0 && (
|
||||||
|
<div className="space-y-3 pt-2 border-t border-gray-100 italic">
|
||||||
|
<div className="text-xs font-semibold text-amber-600/70 uppercase tracking-wider flex items-center gap-1">
|
||||||
|
<span className="w-1 h-3 bg-amber-500 rounded-full" />
|
||||||
|
單據狀態與進階操作權限
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-y-3 gap-x-4">
|
||||||
|
{specialPermissions.map((permission) => (
|
||||||
|
<PermissionItem
|
||||||
|
key={permission.id}
|
||||||
|
permission={permission}
|
||||||
|
selectedPermissions={selectedPermissions}
|
||||||
|
onToggle={togglePermission}
|
||||||
|
translate={translateAction}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</AccordionContent>
|
</AccordionContent>
|
||||||
</AccordionItem>
|
</AccordionItem>
|
||||||
@@ -275,3 +292,26 @@ export default function PermissionSelector({ groupedPermissions, selectedPermiss
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function PermissionItem({ permission, selectedPermissions, onToggle, translate }: any) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-start space-x-3">
|
||||||
|
<Checkbox
|
||||||
|
id={permission.name}
|
||||||
|
checked={selectedPermissions.includes(permission.name)}
|
||||||
|
onCheckedChange={() => onToggle(permission.name)}
|
||||||
|
/>
|
||||||
|
<div className="grid gap-1.5 leading-none">
|
||||||
|
<label
|
||||||
|
htmlFor={permission.name}
|
||||||
|
className="text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer text-gray-700 hover:text-primary-main transition-colors"
|
||||||
|
>
|
||||||
|
{translate(permission.name)}
|
||||||
|
</label>
|
||||||
|
<p className="text-[10px] text-gray-400 font-mono">
|
||||||
|
{permission.name}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -452,7 +452,12 @@ export default function Show({ doc }: { auth: any, doc: AdjDoc }) {
|
|||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell className="font-semibold text-grey-0">{inv.product_name}</TableCell>
|
<TableCell className="py-3">
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<span className="font-semibold text-grey-0">{inv.product_name}</span>
|
||||||
|
<span className="text-xs text-grey-2 font-mono">{inv.product_code}</span>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
<TableCell className="text-sm font-mono text-grey-2">{inv.batch_number || '-'}</TableCell>
|
<TableCell className="text-sm font-mono text-grey-2">{inv.batch_number || '-'}</TableCell>
|
||||||
<TableCell className="text-sm font-mono text-grey-2">{inv.expiry_date || '-'}</TableCell>
|
<TableCell className="text-sm font-mono text-grey-2">{inv.expiry_date || '-'}</TableCell>
|
||||||
<TableCell className="text-right font-bold text-primary-main pr-6">{inv.quantity} {inv.unit_name}</TableCell>
|
<TableCell className="text-right font-bold text-primary-main pr-6">{inv.quantity} {inv.unit_name}</TableCell>
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ export default function GoodsReceiptCreate({ warehouses, pendingPurchaseOrders,
|
|||||||
product_id: item.product_id,
|
product_id: item.product_id,
|
||||||
purchase_order_item_id: item.id,
|
purchase_order_item_id: item.id,
|
||||||
product_name: item.product_name,
|
product_name: item.product_name,
|
||||||
sku: item.product_code,
|
product_code: item.product_code,
|
||||||
unit: item.unit,
|
unit: item.unit,
|
||||||
quantity_ordered: item.quantity,
|
quantity_ordered: item.quantity,
|
||||||
quantity_received_so_far: item.received_quantity,
|
quantity_received_so_far: item.received_quantity,
|
||||||
@@ -157,7 +157,7 @@ export default function GoodsReceiptCreate({ warehouses, pendingPurchaseOrders,
|
|||||||
const newItem = {
|
const newItem = {
|
||||||
product_id: product.id,
|
product_id: product.id,
|
||||||
product_name: product.name,
|
product_name: product.name,
|
||||||
sku: product.code,
|
product_code: product.code,
|
||||||
quantity_received: 0,
|
quantity_received: 0,
|
||||||
unit_price: product.price || 0,
|
unit_price: product.price || 0,
|
||||||
batch_number: '',
|
batch_number: '',
|
||||||
@@ -266,7 +266,7 @@ export default function GoodsReceiptCreate({ warehouses, pendingPurchaseOrders,
|
|||||||
// Note: fetch might not have returned yet, so seq might be default 001 until fetch updates nextSequences
|
// Note: fetch might not have returned yet, so seq might be default 001 until fetch updates nextSequences
|
||||||
|
|
||||||
const datePart = dateStr.replace(/-/g, '');
|
const datePart = dateStr.replace(/-/g, '');
|
||||||
const generatedBatch = `${item.sku}-${country}-${datePart}-${seq}`;
|
const generatedBatch = `${item.product_code}-${country}-${datePart}-${seq}`;
|
||||||
|
|
||||||
if (item.batch_number !== generatedBatch) {
|
if (item.batch_number !== generatedBatch) {
|
||||||
// Update WITHOUT triggering re-render loop
|
// Update WITHOUT triggering re-render loop
|
||||||
@@ -278,7 +278,7 @@ export default function GoodsReceiptCreate({ warehouses, pendingPurchaseOrders,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [nextSequences, JSON.stringify(data.items.map(i => ({ m: i.batchMode, c: i.originCountry, s: i.sku, p: i.product_id }))), data.received_date]);
|
}, [nextSequences, JSON.stringify(data.items.map(i => ({ m: i.batchMode, c: i.originCountry, s: i.product_code, p: i.product_id }))), data.received_date]);
|
||||||
|
|
||||||
const submit = (e: React.FormEvent) => {
|
const submit = (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -610,7 +610,7 @@ export default function GoodsReceiptCreate({ warehouses, pendingPurchaseOrders,
|
|||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<span className="font-medium text-gray-900">{item.product_name}</span>
|
<span className="font-medium text-gray-900">{item.product_name}</span>
|
||||||
<span className="text-xs text-gray-500">{item.sku}</span>
|
<span className="text-xs text-gray-500">{item.product_code}</span>
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
@@ -654,7 +654,7 @@ export default function GoodsReceiptCreate({ warehouses, pendingPurchaseOrders,
|
|||||||
className="w-16 text-center px-1"
|
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">
|
<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)}
|
{getBatchPreview(item.product_id, item.product_code, item.originCountry || 'TW', data.received_date)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|||||||
@@ -140,15 +140,15 @@ export default function ViewGoodsReceiptPage({ receipt }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 品項清單卡片 */}
|
{/* 品項清單卡片 */}
|
||||||
<div className="bg-white rounded-lg border shadow-sm overflow-hidden">
|
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
|
||||||
<div className="p-6 border-b border-gray-100">
|
<div className="p-6 border-b border-gray-100 bg-gray-50/30">
|
||||||
<h2 className="text-lg font-bold text-gray-900">進貨品項清單</h2>
|
<h2 className="text-lg font-bold text-gray-900">進貨品項清單</h2>
|
||||||
</div>
|
</div>
|
||||||
<div className="p-0">
|
<div className="p-6">
|
||||||
<div className="overflow-x-auto">
|
<div className="border rounded-lg overflow-hidden">
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow className="bg-gray-50/50">
|
<TableRow className="bg-gray-50 hover:bg-gray-50">
|
||||||
<TableHead className="w-[80px] text-center">#</TableHead>
|
<TableHead className="w-[80px] text-center">#</TableHead>
|
||||||
<TableHead>商品名稱</TableHead>
|
<TableHead>商品名稱</TableHead>
|
||||||
<TableHead className="text-right">進貨數量</TableHead>
|
<TableHead className="text-right">進貨數量</TableHead>
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ export default function Show({ order }: any) {
|
|||||||
const toggleSelectAll = () => {
|
const toggleSelectAll = () => {
|
||||||
const filtered = availableInventory.filter(inv =>
|
const filtered = availableInventory.filter(inv =>
|
||||||
inv.product_name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
inv.product_name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||||
inv.product_code.toLowerCase().includes(searchQuery.toLowerCase())
|
inv.product_code.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||||
|
(inv.product_barcode && inv.product_barcode.toLowerCase().includes(searchQuery.toLowerCase()))
|
||||||
);
|
);
|
||||||
const filteredKeys = filtered.map(inv => `${inv.product_id}-${inv.batch_number}`);
|
const filteredKeys = filtered.map(inv => `${inv.product_id}-${inv.batch_number}`);
|
||||||
|
|
||||||
@@ -338,10 +339,10 @@ export default function Show({ order }: any) {
|
|||||||
<DialogContent className="max-w-4xl max-h-[85vh] flex flex-col p-6">
|
<DialogContent className="max-w-4xl max-h-[85vh] flex flex-col p-6">
|
||||||
<DialogHeader className="flex flex-row items-center justify-between space-y-0 pb-4">
|
<DialogHeader className="flex flex-row items-center justify-between space-y-0 pb-4">
|
||||||
<DialogTitle className="text-xl">選擇來源庫存 ({order.from_warehouse_name})</DialogTitle>
|
<DialogTitle className="text-xl">選擇來源庫存 ({order.from_warehouse_name})</DialogTitle>
|
||||||
<div className="relative w-64">
|
<div className="relative w-72">
|
||||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-grey-3" />
|
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-grey-3" />
|
||||||
<Input
|
<Input
|
||||||
placeholder="搜尋品名或代號..."
|
placeholder="搜尋品名、代號或條碼..."
|
||||||
className="pl-9 h-9 border-2 border-grey-3 focus:ring-primary-main"
|
className="pl-9 h-9 border-2 border-grey-3 focus:ring-primary-main"
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
@@ -364,7 +365,8 @@ export default function Show({ order }: any) {
|
|||||||
checked={availableInventory.length > 0 && (() => {
|
checked={availableInventory.length > 0 && (() => {
|
||||||
const filtered = availableInventory.filter(inv =>
|
const filtered = availableInventory.filter(inv =>
|
||||||
inv.product_name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
inv.product_name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||||
inv.product_code.toLowerCase().includes(searchQuery.toLowerCase())
|
inv.product_code.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||||
|
(inv.product_barcode && inv.product_barcode.toLowerCase().includes(searchQuery.toLowerCase()))
|
||||||
);
|
);
|
||||||
const filteredKeys = filtered.map(inv => `${inv.product_id}-${inv.batch_number}`);
|
const filteredKeys = filtered.map(inv => `${inv.product_id}-${inv.batch_number}`);
|
||||||
return filteredKeys.length > 0 && filteredKeys.every(k => selectedInventory.includes(k));
|
return filteredKeys.length > 0 && filteredKeys.every(k => selectedInventory.includes(k));
|
||||||
@@ -373,7 +375,7 @@ export default function Show({ order }: any) {
|
|||||||
/>
|
/>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
|
|
||||||
<TableHead className="font-medium text-grey-600">品名</TableHead>
|
<TableHead className="font-medium text-grey-600">品名 / 代號</TableHead>
|
||||||
<TableHead className="font-medium text-grey-600">批號</TableHead>
|
<TableHead className="font-medium text-grey-600">批號</TableHead>
|
||||||
<TableHead className="font-medium text-grey-600">效期</TableHead>
|
<TableHead className="font-medium text-grey-600">效期</TableHead>
|
||||||
<TableHead className="text-right font-medium text-grey-600 pr-6">現有庫存</TableHead>
|
<TableHead className="text-right font-medium text-grey-600 pr-6">現有庫存</TableHead>
|
||||||
@@ -383,7 +385,8 @@ export default function Show({ order }: any) {
|
|||||||
{(() => {
|
{(() => {
|
||||||
const filtered = availableInventory.filter(inv =>
|
const filtered = availableInventory.filter(inv =>
|
||||||
inv.product_name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
inv.product_name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||||
inv.product_code.toLowerCase().includes(searchQuery.toLowerCase())
|
inv.product_code.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||||
|
(inv.product_barcode && inv.product_barcode.toLowerCase().includes(searchQuery.toLowerCase()))
|
||||||
);
|
);
|
||||||
|
|
||||||
if (filtered.length === 0) {
|
if (filtered.length === 0) {
|
||||||
@@ -412,7 +415,12 @@ export default function Show({ order }: any) {
|
|||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell className="font-semibold text-grey-0">{inv.product_name}</TableCell>
|
<TableCell className="py-3">
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<span className="font-semibold text-grey-0">{inv.product_name}</span>
|
||||||
|
<span className="text-xs text-grey-2 font-mono">{inv.product_code}</span>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
<TableCell className="text-sm font-mono text-grey-2">{inv.batch_number || '-'}</TableCell>
|
<TableCell className="text-sm font-mono text-grey-2">{inv.batch_number || '-'}</TableCell>
|
||||||
<TableCell className="text-sm font-mono text-grey-2">{inv.expiry_date || '-'}</TableCell>
|
<TableCell className="text-sm font-mono text-grey-2">{inv.expiry_date || '-'}</TableCell>
|
||||||
<TableCell className="text-right font-bold text-primary-main pr-6">{inv.quantity} {inv.unit_name}</TableCell>
|
<TableCell className="text-right font-bold text-primary-main pr-6">{inv.quantity} {inv.unit_name}</TableCell>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { Textarea } from "@/Components/ui/textarea";
|
|||||||
import { Alert, AlertDescription } from "@/Components/ui/alert";
|
import { Alert, AlertDescription } from "@/Components/ui/alert";
|
||||||
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||||
import { Head, Link, router } from "@inertiajs/react";
|
import { Head, Link, router, usePage } from "@inertiajs/react";
|
||||||
import { PurchaseOrderItemsTable } from "@/Components/PurchaseOrder/PurchaseOrderItemsTable";
|
import { PurchaseOrderItemsTable } from "@/Components/PurchaseOrder/PurchaseOrderItemsTable";
|
||||||
import type { PurchaseOrder, Supplier } from "@/types/purchase-order";
|
import type { PurchaseOrder, Supplier } from "@/types/purchase-order";
|
||||||
import type { Warehouse } from "@/types/requester";
|
import type { Warehouse } from "@/types/requester";
|
||||||
@@ -21,8 +21,9 @@ import {
|
|||||||
getTodayDate,
|
getTodayDate,
|
||||||
formatCurrency,
|
formatCurrency,
|
||||||
} from "@/utils/purchase-order";
|
} from "@/utils/purchase-order";
|
||||||
import { STATUS_OPTIONS } from "@/constants/purchase-order";
|
import { STATUS_CONFIG, MANUAL_STATUS_OPTIONS } from "@/constants/purchase-order";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { Can } from "@/Components/Permission/Can";
|
||||||
import { getCreateBreadcrumbs, getEditBreadcrumbs } from "@/utils/breadcrumb";
|
import { getCreateBreadcrumbs, getEditBreadcrumbs } from "@/utils/breadcrumb";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -36,6 +37,17 @@ export default function CreatePurchaseOrder({
|
|||||||
suppliers,
|
suppliers,
|
||||||
warehouses,
|
warehouses,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const { auth } = usePage<any>().props;
|
||||||
|
const permissions = auth.user?.permissions || [];
|
||||||
|
const isSuperAdmin = auth.user?.roles?.some((r: any) => r.name === 'super-admin');
|
||||||
|
|
||||||
|
const canApprove = isSuperAdmin || permissions.includes('purchase_orders.approve');
|
||||||
|
const canCreate = isSuperAdmin || permissions.includes('purchase_orders.create');
|
||||||
|
const canEdit = isSuperAdmin || permissions.includes('purchase_orders.edit');
|
||||||
|
|
||||||
|
// 儲存權限判斷
|
||||||
|
const canSave = order ? canEdit : canCreate;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
supplierId,
|
supplierId,
|
||||||
expectedDate,
|
expectedDate,
|
||||||
@@ -273,12 +285,26 @@ export default function CreatePurchaseOrder({
|
|||||||
{order && (
|
{order && (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<label className="text-sm font-bold text-gray-700">狀態</label>
|
<label className="text-sm font-bold text-gray-700">狀態</label>
|
||||||
<SearchableSelect
|
<Can permission="purchase_orders.approve">
|
||||||
value={status}
|
<SearchableSelect
|
||||||
onValueChange={(v) => setStatus(v as any)}
|
value={status}
|
||||||
options={STATUS_OPTIONS.map((opt) => ({ label: opt.label, value: opt.value }))}
|
onValueChange={(v) => setStatus(v as any)}
|
||||||
placeholder="選擇狀態"
|
options={MANUAL_STATUS_OPTIONS}
|
||||||
/>
|
placeholder="選擇狀態"
|
||||||
|
/>
|
||||||
|
</Can>
|
||||||
|
<div className="!mt-1">
|
||||||
|
{!canApprove && (
|
||||||
|
<>
|
||||||
|
<div className="px-3 py-2 bg-gray-50 border rounded-md text-sm text-gray-600">
|
||||||
|
{STATUS_CONFIG[status as keyof typeof STATUS_CONFIG]?.label || status}
|
||||||
|
</div>
|
||||||
|
<p className="text-[10px] text-gray-400 mt-1 italic">
|
||||||
|
* 您沒有權限在此修改狀態,請使用詳情頁面的動作按鈕進行操作。
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -454,9 +480,11 @@ export default function CreatePurchaseOrder({
|
|||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<Button
|
<Button
|
||||||
size="lg"
|
size="xl"
|
||||||
className="bg-primary hover:bg-primary/90 text-white px-12 h-14 rounded-xl shadow-lg shadow-primary/20 text-lg font-bold transition-all hover:scale-[1.02] active:scale-[0.98]"
|
className="bg-primary hover:bg-primary/90 text-white shadow-primary/20"
|
||||||
onClick={handleSave}
|
onClick={handleSave}
|
||||||
|
disabled={!canSave}
|
||||||
|
title={!canSave ? "您沒有執行此動作的權限" : ""}
|
||||||
>
|
>
|
||||||
{order ? "更新採購單" : "確認發布採購單"}
|
{order ? "更新採購單" : "確認發布採購單"}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/Components/ui/select";
|
} from "@/Components/ui/select";
|
||||||
import { STATUS_OPTIONS } from "@/constants/purchase-order";
|
import { MANUAL_STATUS_OPTIONS } from "@/constants/purchase-order";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
orders: {
|
orders: {
|
||||||
@@ -177,7 +177,7 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
|
|||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="all">全部狀態</SelectItem>
|
<SelectItem value="all">全部狀態</SelectItem>
|
||||||
{STATUS_OPTIONS.map((option) => (
|
{MANUAL_STATUS_OPTIONS.map((option) => (
|
||||||
<SelectItem key={option.value} value={option.value}>
|
<SelectItem key={option.value} value={option.value}>
|
||||||
{option.label}
|
{option.label}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
* 查看採購單詳情頁面
|
* 查看採購單詳情頁面
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ArrowLeft, ShoppingCart } from "lucide-react";
|
import { ArrowLeft, ShoppingCart, Send, CheckCircle, XCircle, RotateCcw } from "lucide-react";
|
||||||
import { Button } from "@/Components/ui/button";
|
import { Button } from "@/Components/ui/button";
|
||||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||||
import { Head, Link } from "@inertiajs/react";
|
import { Head, Link, useForm, usePage, router } from "@inertiajs/react";
|
||||||
import { StatusProgressBar } from "@/Components/PurchaseOrder/StatusProgressBar";
|
import { StatusProgressBar } from "@/Components/PurchaseOrder/StatusProgressBar";
|
||||||
import PurchaseOrderStatusBadge from "@/Components/PurchaseOrder/PurchaseOrderStatusBadge";
|
import PurchaseOrderStatusBadge from "@/Components/PurchaseOrder/PurchaseOrderStatusBadge";
|
||||||
import CopyButton from "@/Components/shared/CopyButton";
|
import CopyButton from "@/Components/shared/CopyButton";
|
||||||
@@ -13,6 +13,8 @@ import { PurchaseOrderItemsTable } from "@/Components/PurchaseOrder/PurchaseOrde
|
|||||||
import type { PurchaseOrder } from "@/types/purchase-order";
|
import type { PurchaseOrder } from "@/types/purchase-order";
|
||||||
import { formatCurrency, formatDateTime } from "@/utils/format";
|
import { formatCurrency, formatDateTime } from "@/utils/format";
|
||||||
import { getShowBreadcrumbs } from "@/utils/breadcrumb";
|
import { getShowBreadcrumbs } from "@/utils/breadcrumb";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { PageProps } from "@/types/global";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
order: PurchaseOrder;
|
order: PurchaseOrder;
|
||||||
@@ -44,11 +46,6 @@ export default function ViewPurchaseOrderPage({ order }: Props) {
|
|||||||
<p className="text-gray-500 mt-1">單號:{order.poNumber}</p>
|
<p className="text-gray-500 mt-1">單號:{order.poNumber}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<Link href={`/purchase-orders/${order.id}/edit`}>
|
|
||||||
<Button variant="outline" className="button-outlined-primary">
|
|
||||||
編輯採購單
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
<PurchaseOrderStatusBadge status={order.status} />
|
<PurchaseOrderStatusBadge status={order.status} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -171,9 +168,111 @@ export default function ViewPurchaseOrderPage({ order }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* 操作按鈕 (底部) */}
|
||||||
|
<div className="flex justify-end pt-4">
|
||||||
|
<PurchaseOrderActions order={order} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</AuthenticatedLayout>
|
</AuthenticatedLayout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function PurchaseOrderActions({ order }: { order: PurchaseOrder }) {
|
||||||
|
const { auth } = usePage<PageProps>().props;
|
||||||
|
const permissions = auth.user?.permissions || [];
|
||||||
|
|
||||||
|
const { processing } = useForm({
|
||||||
|
status: order.status,
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleUpdateStatus = (newStatus: string, actionName: string) => {
|
||||||
|
const formData = {
|
||||||
|
vendor_id: order.supplierId,
|
||||||
|
warehouse_id: order.warehouse_id,
|
||||||
|
order_date: order.orderDate,
|
||||||
|
expected_delivery_date: order.expectedDate ? new Date(order.expectedDate).toISOString().split('T')[0] : null,
|
||||||
|
items: order.items.map((item: any) => ({
|
||||||
|
productId: item.productId,
|
||||||
|
quantity: item.quantity,
|
||||||
|
unitId: item.unitId,
|
||||||
|
subtotal: item.subtotal,
|
||||||
|
})),
|
||||||
|
tax_amount: order.taxAmount,
|
||||||
|
status: newStatus,
|
||||||
|
remark: order.remark || "",
|
||||||
|
};
|
||||||
|
|
||||||
|
router.patch(route('purchase-orders.update', order.id), formData, {
|
||||||
|
onSuccess: () => toast.success(`採購單已${actionName === '取消' ? '作廢' : actionName}`),
|
||||||
|
onError: (errors: any) => {
|
||||||
|
console.error("Status Update Error:", errors);
|
||||||
|
toast.error(errors.error || "操作失敗");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 權限判斷 (包含超級管理員檢查)
|
||||||
|
const isSuperAdmin = auth.user?.roles?.some((r: any) => r.name === 'super-admin');
|
||||||
|
const canApprove = isSuperAdmin || permissions.includes('purchase_orders.approve');
|
||||||
|
const canCancel = isSuperAdmin || permissions.includes('purchase_orders.cancel');
|
||||||
|
const canEdit = isSuperAdmin || permissions.includes('purchase_orders.edit');
|
||||||
|
const canView = isSuperAdmin || permissions.includes('purchase_orders.view');
|
||||||
|
|
||||||
|
// 送審權限:擁有檢視或編輯權限的人都可以送審
|
||||||
|
const canSubmit = canEdit || canView;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
{['draft', 'pending', 'approved'].includes(order.status) && canCancel && (
|
||||||
|
<Button
|
||||||
|
onClick={() => handleUpdateStatus('cancelled', '作廢')}
|
||||||
|
disabled={processing}
|
||||||
|
variant="outline"
|
||||||
|
size="xl"
|
||||||
|
className="button-outlined-error shadow-red-200/20 border-red-600 text-red-600 hover:bg-red-50"
|
||||||
|
>
|
||||||
|
<XCircle className="h-5 w-5" /> 作廢
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{order.status === 'pending' && canApprove && (
|
||||||
|
<Button
|
||||||
|
onClick={() => handleUpdateStatus('draft', '退回')}
|
||||||
|
disabled={processing}
|
||||||
|
variant="outline"
|
||||||
|
size="xl"
|
||||||
|
className="button-outlined-warning shadow-amber-200/20"
|
||||||
|
>
|
||||||
|
<RotateCcw className="h-5 w-5" /> 退回
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="flex-1" />
|
||||||
|
|
||||||
|
{order.status === 'draft' && canSubmit && (
|
||||||
|
<Button
|
||||||
|
onClick={() => handleUpdateStatus('pending', '送出審核')}
|
||||||
|
disabled={processing}
|
||||||
|
size="xl"
|
||||||
|
className="button-filled-primary shadow-primary/20"
|
||||||
|
>
|
||||||
|
<Send className="h-5 w-5" /> 送審
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{order.status === 'pending' && canApprove && (
|
||||||
|
<Button
|
||||||
|
onClick={() => handleUpdateStatus('approved', '核准')}
|
||||||
|
disabled={processing}
|
||||||
|
size="xl"
|
||||||
|
className="button-filled-primary shadow-primary/20"
|
||||||
|
>
|
||||||
|
<CheckCircle className="h-5 w-5" /> 核准
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
90
resources/js/Pages/Sales/Import/Create.tsx
Normal file
90
resources/js/Pages/Sales/Import/Create.tsx
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
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 { Upload, ArrowLeft, FileSpreadsheet } from 'lucide-react';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
export default function SalesImportCreate() {
|
||||||
|
const { data, setData, post, processing, errors } = useForm({
|
||||||
|
file: null as File | null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const submit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
post(route('sales-imports.store'));
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AuthenticatedLayout
|
||||||
|
breadcrumbs={[
|
||||||
|
{ label: '銷售管理', href: '#' },
|
||||||
|
{ label: '銷售單匯入', href: route('sales-imports.index') },
|
||||||
|
{ label: '新增匯入', href: route('sales-imports.create'), isPage: true },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Head title="新增銷售匯入" />
|
||||||
|
|
||||||
|
<div className="container mx-auto p-6 max-w-3xl">
|
||||||
|
<div className="mb-6">
|
||||||
|
<Link href={route('sales-imports.index')}>
|
||||||
|
<Button variant="outline" type="button" className="gap-2 mb-4">
|
||||||
|
<ArrowLeft className="h-4 w-4" />
|
||||||
|
返回列表
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
<h1 className="text-2xl font-bold text-gray-900 flex items-center gap-2">
|
||||||
|
<FileSpreadsheet className="h-6 w-6 text-primary-main" />
|
||||||
|
新增銷售匯入
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="bg-white rounded-lg border shadow-sm p-8">
|
||||||
|
<form onSubmit={submit} className="space-y-6">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="file" className="text-lg font-medium">上傳 Excel 檔案</Label>
|
||||||
|
<div className="border-2 border-dashed border-gray-300 rounded-xl p-10 flex flex-col items-center justify-center bg-gray-50 hover:bg-gray-100 transition-colors cursor-pointer relative">
|
||||||
|
<Input
|
||||||
|
id="file"
|
||||||
|
type="file"
|
||||||
|
accept=".xlsx,.xls,.csv"
|
||||||
|
onChange={(e) => setData('file', e.target.files ? e.target.files[0] : null)}
|
||||||
|
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
|
||||||
|
/>
|
||||||
|
<Upload className="h-10 w-10 text-gray-400 mb-4" />
|
||||||
|
<div className="text-center">
|
||||||
|
<p className="text-sm font-medium text-gray-700">
|
||||||
|
{data.file ? data.file.name : '點擊或拖曳檔案至此'}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs text-gray-500 mt-1">支援 .xlsx, .xls, .csv</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{errors.file && <p className="text-red-500 text-sm">{errors.file}</p>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-end pt-4">
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
size="lg"
|
||||||
|
className="button-filled-primary w-full md:w-auto px-8"
|
||||||
|
disabled={processing}
|
||||||
|
>
|
||||||
|
{processing ? '處理中...' : '開始匯入'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-8 bg-blue-50 p-6 rounded-lg border border-blue-100">
|
||||||
|
<h3 className="font-bold text-blue-800 mb-2">匯入說明</h3>
|
||||||
|
<ul className="list-disc list-inside text-sm text-blue-700 space-y-1">
|
||||||
|
<li>請使用統一的 Excel 格式(商品銷貨單)。</li>
|
||||||
|
<li>系統將自動解析機台編號、商品代號與交易時間。</li>
|
||||||
|
<li>匯入後請至「待確認」清單檢查內容,確認無誤後再執行扣庫。</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</AuthenticatedLayout>
|
||||||
|
);
|
||||||
|
}
|
||||||
203
resources/js/Pages/Sales/Import/Index.tsx
Normal file
203
resources/js/Pages/Sales/Import/Index.tsx
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
|
||||||
|
import { Head, Link } from '@inertiajs/react';
|
||||||
|
import { Button } from '@/Components/ui/button';
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from '@/Components/ui/table';
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
AlertDialogTrigger,
|
||||||
|
} from "@/Components/ui/alert-dialog";
|
||||||
|
import { Badge } from "@/Components/ui/badge";
|
||||||
|
import { Plus, FileUp, Eye, Trash2 } from 'lucide-react';
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
import Pagination from "@/Components/shared/Pagination";
|
||||||
|
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||||
|
import { router } from "@inertiajs/react";
|
||||||
|
|
||||||
|
interface ImportBatch {
|
||||||
|
id: number;
|
||||||
|
import_date: string;
|
||||||
|
status: 'pending' | 'confirmed';
|
||||||
|
total_quantity: number;
|
||||||
|
total_amount: number;
|
||||||
|
importer?: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
created_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
batches: {
|
||||||
|
data: ImportBatch[];
|
||||||
|
links: any[]; // Pagination links
|
||||||
|
};
|
||||||
|
filters?: { // Add filters prop if not present, though we main need per_page state
|
||||||
|
per_page?: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function SalesImportIndex({ batches, filters = {} }: Props) {
|
||||||
|
const [perPage, setPerPage] = useState(filters?.per_page?.toString() || "10");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (filters?.per_page) {
|
||||||
|
setPerPage(filters.per_page.toString());
|
||||||
|
}
|
||||||
|
}, [filters?.per_page]);
|
||||||
|
|
||||||
|
const handlePerPageChange = (value: string) => {
|
||||||
|
setPerPage(value);
|
||||||
|
router.get(
|
||||||
|
route("sales-imports.index"),
|
||||||
|
{ per_page: value },
|
||||||
|
{ preserveState: true, preserveScroll: true, replace: true }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AuthenticatedLayout
|
||||||
|
breadcrumbs={[
|
||||||
|
{ label: '銷售管理', href: '#' },
|
||||||
|
{ label: '銷售單匯入', href: route('sales-imports.index'), isPage: true },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Head title="銷售單匯入管理" />
|
||||||
|
|
||||||
|
<div className="container mx-auto p-6 max-w-7xl">
|
||||||
|
<div className="flex justify-between items-center mb-6">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-2xl font-bold text-gray-900 flex items-center gap-2">
|
||||||
|
<FileUp className="h-6 w-6 text-primary-main" />
|
||||||
|
銷售單匯入管理
|
||||||
|
</h1>
|
||||||
|
<p className="text-gray-500 mt-1">
|
||||||
|
匯入並管理銷售出貨紀錄
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Link href={route('sales-imports.create')}>
|
||||||
|
<Button className="button-filled-primary gap-2">
|
||||||
|
<Plus className="h-4 w-4" />
|
||||||
|
新增匯入
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="bg-white rounded-lg border shadow-sm overflow-hidden">
|
||||||
|
<Table>
|
||||||
|
<TableHeader className="bg-gray-50">
|
||||||
|
<TableRow>
|
||||||
|
<TableHead className="w-[100px]">ID</TableHead>
|
||||||
|
<TableHead>匯入日期</TableHead>
|
||||||
|
<TableHead>匯入人員</TableHead>
|
||||||
|
<TableHead className="text-center w-[120px]">總數量</TableHead>
|
||||||
|
<TableHead className="text-right w-[150px]">總金額</TableHead>
|
||||||
|
<TableHead className="text-center w-[100px]">狀態</TableHead>
|
||||||
|
<TableHead className="text-center w-[120px]">操作</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{batches.data.length === 0 ? (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={7} className="text-center py-8 text-gray-500">
|
||||||
|
尚無匯入紀錄
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
) : (
|
||||||
|
batches.data.map((batch) => (
|
||||||
|
<TableRow key={batch.id} className="hover:bg-gray-50/50">
|
||||||
|
<TableCell className="font-medium">#{batch.id}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{format(new Date(batch.created_at), 'yyyy/MM/dd HH:mm')}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{batch.importer?.name || '--'}</TableCell>
|
||||||
|
<TableCell className="text-center font-bold text-gray-900">
|
||||||
|
{Math.floor(batch.total_quantity || 0).toLocaleString()}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-right font-bold text-primary-main">
|
||||||
|
NT$ {Number(batch.total_amount || 0).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-center">
|
||||||
|
<Badge variant={batch.status === 'confirmed' ? 'default' : 'secondary'}>
|
||||||
|
{batch.status === 'confirmed' ? '已確認' : '待確認'}
|
||||||
|
</Badge>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="flex justify-center gap-2">
|
||||||
|
<Link href={route('sales-imports.show', batch.id)}>
|
||||||
|
<Button variant="outline" size="sm" className="button-outlined-primary" title="查看詳情">
|
||||||
|
<Eye className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
{batch.status === 'pending' && (
|
||||||
|
<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>
|
||||||
|
確定要刪除此筆匯入紀錄(#{batch.id})嗎?此操作將會移除所有相關的明細資料且無法復原。
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
className="bg-red-600 hover:bg-red-700"
|
||||||
|
onClick={() => router.delete(route('sales-imports.destroy', batch.id), { preserveScroll: true })}
|
||||||
|
>
|
||||||
|
確認刪除
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 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={batches.links} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</AuthenticatedLayout>
|
||||||
|
);
|
||||||
|
}
|
||||||
338
resources/js/Pages/Sales/Import/Show.tsx
Normal file
338
resources/js/Pages/Sales/Import/Show.tsx
Normal file
@@ -0,0 +1,338 @@
|
|||||||
|
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
|
||||||
|
import { Head, Link, useForm, router } from '@inertiajs/react'; // Add router import
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||||
|
import { Button } from '@/Components/ui/button';
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from '@/Components/ui/table';
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
AlertDialogTrigger,
|
||||||
|
} from "@/Components/ui/alert-dialog";
|
||||||
|
import { Badge } from "@/Components/ui/badge";
|
||||||
|
import { ArrowLeft, CheckCircle, Trash2, Printer } from 'lucide-react';
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
import Pagination from "@/Components/shared/Pagination";
|
||||||
|
|
||||||
|
interface ImportItem {
|
||||||
|
id: number;
|
||||||
|
transaction_serial: string;
|
||||||
|
machine_id: string;
|
||||||
|
slot: string | null;
|
||||||
|
product_code: string;
|
||||||
|
product_id: number | null;
|
||||||
|
product?: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
quantity: number;
|
||||||
|
amount: number;
|
||||||
|
transaction_at: string;
|
||||||
|
original_status: string;
|
||||||
|
warehouse?: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImportBatch {
|
||||||
|
id: number;
|
||||||
|
import_date: string;
|
||||||
|
status: 'pending' | 'confirmed';
|
||||||
|
total_quantity: number;
|
||||||
|
total_amount: number;
|
||||||
|
items: ImportItem[]; // Note: items might be paginated in props, handled below
|
||||||
|
created_at: string;
|
||||||
|
confirmed_at?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
import: ImportBatch;
|
||||||
|
items: {
|
||||||
|
data: ImportItem[];
|
||||||
|
links: any[];
|
||||||
|
current_page: number;
|
||||||
|
per_page: number;
|
||||||
|
total: number;
|
||||||
|
};
|
||||||
|
filters?: {
|
||||||
|
per_page?: string;
|
||||||
|
};
|
||||||
|
flash?: {
|
||||||
|
success?: string;
|
||||||
|
error?: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function SalesImportShow({ import: batch, items, filters = {} }: Props) {
|
||||||
|
const { post, processing } = useForm({});
|
||||||
|
const [perPage, setPerPage] = useState(filters?.per_page?.toString() || "10");
|
||||||
|
|
||||||
|
// Sync state with prop if it changes via navigation
|
||||||
|
useEffect(() => {
|
||||||
|
if (filters?.per_page) {
|
||||||
|
setPerPage(filters.per_page.toString());
|
||||||
|
}
|
||||||
|
}, [filters?.per_page]);
|
||||||
|
|
||||||
|
const handlePerPageChange = (value: string) => {
|
||||||
|
setPerPage(value);
|
||||||
|
router.get(
|
||||||
|
route("sales-imports.show", batch.id),
|
||||||
|
{ per_page: value },
|
||||||
|
{ preserveState: true, preserveScroll: true, replace: true }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleConfirm = () => {
|
||||||
|
post(route('sales-imports.confirm', batch.id));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = () => {
|
||||||
|
router.delete(route('sales-imports.destroy', batch.id));
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AuthenticatedLayout
|
||||||
|
breadcrumbs={[
|
||||||
|
{ label: '銷售管理', href: '#' },
|
||||||
|
{ label: '銷售單匯入', href: route('sales-imports.index') },
|
||||||
|
{ label: '匯入明細', href: '#', isPage: true },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Head title={`匯入批次 #${batch.id}`} />
|
||||||
|
|
||||||
|
<div className="container mx-auto p-6 max-w-7xl">
|
||||||
|
{/* Header */}
|
||||||
|
<div className="mb-6">
|
||||||
|
<Link href={route('sales-imports.index')}>
|
||||||
|
<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">
|
||||||
|
<CheckCircle className="h-6 w-6 text-primary-main" />
|
||||||
|
銷售匯入詳情
|
||||||
|
</h1>
|
||||||
|
<p className="text-gray-500 mt-1">批次編號:#{batch.id} | 匯入時間:{format(new Date(batch.created_at), 'yyyy/MM/dd HH:mm')}</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Badge variant={batch.status === 'confirmed' ? 'default' : 'secondary'}>
|
||||||
|
{batch.status === 'confirmed' ? '已確認' : '待確認'}
|
||||||
|
</Badge>
|
||||||
|
{batch.status === 'pending' && (
|
||||||
|
<>
|
||||||
|
<AlertDialog>
|
||||||
|
<AlertDialogTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="gap-2 button-outlined-error"
|
||||||
|
>
|
||||||
|
<Trash2 className="h-4 w-4" />
|
||||||
|
刪除批次
|
||||||
|
</Button>
|
||||||
|
</AlertDialogTrigger>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>確認刪除匯入紀錄</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
確定要刪除此筆匯入紀錄(#{batch.id})嗎?此操作將會移除所有相關的明細資料且無法復原。
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
className="bg-red-600 hover:bg-red-700"
|
||||||
|
onClick={handleDelete}
|
||||||
|
>
|
||||||
|
確認刪除
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
|
||||||
|
<AlertDialog>
|
||||||
|
<AlertDialogTrigger asChild>
|
||||||
|
<Button
|
||||||
|
className="button-filled-primary gap-2"
|
||||||
|
disabled={processing}
|
||||||
|
>
|
||||||
|
<CheckCircle className="h-4 w-4" />
|
||||||
|
{processing ? '處理中...' : '確認並扣庫'}
|
||||||
|
</Button>
|
||||||
|
</AlertDialogTrigger>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>確認執行庫存扣取</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
確認要執行扣庫嗎?系統將會根據此匯入內容減少對應倉庫的商品庫存。此操作無法復原。
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
className="button-filled-primary"
|
||||||
|
onClick={handleConfirm}
|
||||||
|
>
|
||||||
|
確認執行
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{batch.status === 'confirmed' && (
|
||||||
|
<Button variant="outline" className="gap-2 button-outlined-primary">
|
||||||
|
<Printer className="h-4 w-4" />
|
||||||
|
列印報表
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 gap-8">
|
||||||
|
{/* 統計資訊卡片 */}
|
||||||
|
<div className="bg-white rounded-xl border border-gray-200 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-3 gap-x-8 gap-y-6">
|
||||||
|
<div>
|
||||||
|
<span className="text-sm text-gray-500 block mb-1 font-medium">總筆數</span>
|
||||||
|
<span className="text-2xl font-bold text-gray-900">{Math.floor(batch.total_quantity || 0).toLocaleString()}</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span className="text-sm text-gray-500 block mb-1 font-medium">總金額</span>
|
||||||
|
<span className="text-2xl font-bold text-primary-main">
|
||||||
|
NT$ {Number(batch.total_amount || 0).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span className="text-sm text-gray-500 block mb-1 font-medium">確認時間</span>
|
||||||
|
<span className="text-2xl font-bold text-gray-900">
|
||||||
|
{batch.confirmed_at ? format(new Date(batch.confirmed_at), 'yyyy/MM/dd HH:mm') : '--'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 匯入明細清單 */}
|
||||||
|
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
|
||||||
|
<div className="p-6 border-b border-gray-100 bg-gray-50/30">
|
||||||
|
<h2 className="text-lg font-bold text-gray-900">匯入明細清單</h2>
|
||||||
|
</div>
|
||||||
|
<div className="p-6">
|
||||||
|
<div className="border rounded-lg overflow-hidden">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow className="bg-gray-50 hover:bg-gray-50">
|
||||||
|
<TableHead className="w-[80px] text-center">#</TableHead>
|
||||||
|
<TableHead>交易序號 / 時間</TableHead>
|
||||||
|
<TableHead>倉庫 (機台編號)</TableHead>
|
||||||
|
<TableHead>商品代碼</TableHead>
|
||||||
|
<TableHead>商品名稱</TableHead>
|
||||||
|
<TableHead className="w-[120px] text-center">機台 / 貨道</TableHead>
|
||||||
|
<TableHead className="text-center">原始狀態</TableHead>
|
||||||
|
<TableHead className="text-right w-[100px]">數量</TableHead>
|
||||||
|
<TableHead className="text-right">金額</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{items.data.length === 0 ? (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={9} className="h-24 text-center text-gray-500">
|
||||||
|
無匯入明細資料
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
) : (
|
||||||
|
items.data.map((item, index) => (
|
||||||
|
<TableRow key={item.id}>
|
||||||
|
<TableCell className="text-center text-gray-500">
|
||||||
|
{(items.current_page - 1) * items.per_page + index + 1}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<span className="font-mono text-sm font-bold text-gray-900">{item.transaction_serial}</span>
|
||||||
|
<span className="text-[10px] text-gray-400">
|
||||||
|
{format(new Date(item.transaction_at), 'yyyy/MM/dd HH:mm:ss')}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<span className="text-sm font-medium text-gray-900">{item.warehouse?.name || '--'}</span>
|
||||||
|
<span className="font-mono text-[10px] text-gray-400">{item.machine_id}</span>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="font-mono text-sm font-bold text-gray-900">{item.product_code}</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="text-sm text-gray-600 truncate max-w-[200px]" title={item.product?.name}>
|
||||||
|
{item.product?.name || '--'}
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-center font-bold">
|
||||||
|
{item.slot || '--'}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-center">
|
||||||
|
<Badge variant="outline" className={item.original_status === '已出貨' ? "text-green-600 border-green-200 bg-green-50" : "text-gray-500"}>
|
||||||
|
{item.original_status}
|
||||||
|
</Badge>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-right font-medium">{Math.floor(item.quantity)}</TableCell>
|
||||||
|
<TableCell className="text-right font-bold text-primary">
|
||||||
|
NT$ {Number(item.amount).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Pagination */}
|
||||||
|
<div className="mt-6 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={items.links} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</AuthenticatedLayout>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -510,6 +510,9 @@ export default function AddInventoryPage({ warehouse, products }: Props) {
|
|||||||
數量 <span className="text-red-500">*</span>
|
數量 <span className="text-red-500">*</span>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableHead className="w-[90px]">單位</TableHead>
|
<TableHead className="w-[90px]">單位</TableHead>
|
||||||
|
<TableHead className="w-[120px]">
|
||||||
|
{warehouse.type === 'vending' ? '貨道' : '儲位'}
|
||||||
|
</TableHead>
|
||||||
<TableHead className="w-[50px]"></TableHead>
|
<TableHead className="w-[50px]"></TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
@@ -548,7 +551,7 @@ export default function AddInventoryPage({ warehouse, products }: Props) {
|
|||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<SearchableSelect
|
<SearchableSelect
|
||||||
value={item.batchMode === 'new' ? 'new_batch' : (item.inventoryId || "")}
|
value={item.batchMode === 'none' ? 'no_batch' : (item.batchMode === 'new' ? 'new_batch' : (item.inventoryId || ""))}
|
||||||
onValueChange={(value) => {
|
onValueChange={(value) => {
|
||||||
if (value === 'new_batch') {
|
if (value === 'new_batch') {
|
||||||
handleUpdateItem(item.tempId, {
|
handleUpdateItem(item.tempId, {
|
||||||
@@ -557,6 +560,15 @@ export default function AddInventoryPage({ warehouse, products }: Props) {
|
|||||||
originCountry: 'TW',
|
originCountry: 'TW',
|
||||||
expiryDate: undefined
|
expiryDate: undefined
|
||||||
});
|
});
|
||||||
|
} else if (value === 'no_batch') {
|
||||||
|
// 嘗試匹配現有的 NO-BATCH 紀錄
|
||||||
|
const existingNoBatch = (batchesCache[item.productId]?.batches || []).find(b => b.batchNumber === 'NO-BATCH');
|
||||||
|
handleUpdateItem(item.tempId, {
|
||||||
|
batchMode: 'none',
|
||||||
|
inventoryId: existingNoBatch?.inventoryId || undefined,
|
||||||
|
originCountry: 'TW',
|
||||||
|
expiryDate: undefined
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
const selectedBatch = (batchesCache[item.productId]?.batches || []).find(b => b.inventoryId === value);
|
const selectedBatch = (batchesCache[item.productId]?.batches || []).find(b => b.inventoryId === value);
|
||||||
handleUpdateItem(item.tempId, {
|
handleUpdateItem(item.tempId, {
|
||||||
@@ -568,9 +580,10 @@ export default function AddInventoryPage({ warehouse, products }: Props) {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
options={[
|
options={[
|
||||||
|
{ label: "📦 不使用批號 (自動累加)", value: "no_batch" },
|
||||||
{ label: "+ 建立新批號", value: "new_batch" },
|
{ label: "+ 建立新批號", value: "new_batch" },
|
||||||
...(batchesCache[item.productId]?.batches || []).map(b => ({
|
...(batchesCache[item.productId]?.batches || []).map(b => ({
|
||||||
label: `${b.batchNumber} - 庫存: ${b.quantity}`,
|
label: `${b.batchNumber === 'NO-BATCH' ? '(無批號紀錄)' : b.batchNumber} - 庫存: ${b.quantity}`,
|
||||||
value: b.inventoryId
|
value: b.inventoryId
|
||||||
}))
|
}))
|
||||||
]}
|
]}
|
||||||
@@ -582,50 +595,55 @@ export default function AddInventoryPage({ warehouse, products }: Props) {
|
|||||||
{errors[`item-${index}-batch`]}
|
{errors[`item-${index}-batch`]}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{item.batchMode === 'new' && (
|
{item.batchMode === 'new' && (
|
||||||
<>
|
<div className="flex items-center gap-2 mt-2">
|
||||||
<div className="flex items-center gap-2 mt-2">
|
<div className="flex-1">
|
||||||
<div className="flex-1">
|
<Input
|
||||||
<Input
|
value={item.originCountry || ""}
|
||||||
value={item.originCountry || ""}
|
onChange={(e) => {
|
||||||
onChange={(e) => {
|
const val = e.target.value.toUpperCase().slice(0, 2);
|
||||||
const val = e.target.value.toUpperCase().slice(0, 2);
|
handleUpdateItem(item.tempId, { originCountry: val });
|
||||||
handleUpdateItem(item.tempId, { originCountry: val });
|
}}
|
||||||
}}
|
maxLength={2}
|
||||||
maxLength={2}
|
placeholder="產地"
|
||||||
placeholder="產地"
|
className="h-8 text-xs text-center border-gray-300"
|
||||||
className="h-8 text-xs text-center border-gray-300"
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="flex-[3] text-xs bg-primary-50/50 text-primary-main px-2 py-1 rounded border border-primary-200/50 font-mono overflow-hidden whitespace-nowrap">
|
|
||||||
{getBatchPreview(item.productId, product?.code, item.originCountry || 'TW', inboundDate)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{/* 新增效期輸入 (在新增批號模式下) */}
|
<div className="flex-[3] text-xs bg-primary-50/50 text-primary-main px-2 py-1 rounded border border-primary-200/50 font-mono overflow-hidden whitespace-nowrap">
|
||||||
<div className="mt-2 flex items-center gap-2">
|
{getBatchPreview(item.productId, product?.code, item.originCountry || 'TW', inboundDate)}
|
||||||
<span className="text-xs text-gray-500 whitespace-nowrap">效期:</span>
|
|
||||||
<div className="relative flex-1">
|
|
||||||
<Calendar className="absolute left-2.5 top-2.5 h-3.5 w-3.5 text-gray-400 pointer-events-none" />
|
|
||||||
<Input
|
|
||||||
type="date"
|
|
||||||
value={item.expiryDate || ""}
|
|
||||||
onChange={(e) =>
|
|
||||||
handleUpdateItem(item.tempId, {
|
|
||||||
expiryDate: e.target.value,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
className="h-8 pl-8 text-xs border-gray-300 w-full"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</div>
|
||||||
|
)}
|
||||||
|
{/* 新增效期輸入 (僅在建立新批號模式下) */}
|
||||||
|
{item.batchMode === 'new' && (
|
||||||
|
<div className="mt-2 flex items-center gap-2">
|
||||||
|
<span className="text-xs text-gray-500 whitespace-nowrap">效期:</span>
|
||||||
|
<div className="relative flex-1">
|
||||||
|
<Calendar className="absolute left-2.5 top-2.5 h-3.5 w-3.5 text-gray-400 pointer-events-none" />
|
||||||
|
<Input
|
||||||
|
type="date"
|
||||||
|
value={item.expiryDate || ""}
|
||||||
|
onChange={(e) =>
|
||||||
|
handleUpdateItem(item.tempId, {
|
||||||
|
expiryDate: e.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
className="h-8 pl-8 text-xs border-gray-300 w-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{item.batchMode === 'none' && (
|
||||||
|
<div className="mt-1 px-2 py-1 bg-amber-50 text-amber-700 text-[10px] rounded border border-amber-100 flex items-center gap-1">
|
||||||
|
<span className="shrink-0 font-bold">INFO</span>
|
||||||
|
系統將自動累加至該商品的通用庫存紀錄
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{item.batchMode === 'existing' && item.inventoryId && (
|
{item.batchMode === 'existing' && item.inventoryId && (
|
||||||
<div className="flex flax-col gap-1 mt-1">
|
<div className="flex flax-col gap-1 mt-1">
|
||||||
<div className="text-xs text-gray-500 font-mono">
|
<div className="text-xs text-gray-500 font-mono">
|
||||||
效期: {item.expiryDate || '未設定'}
|
效期: {item.expiryDate || '無效期紀錄'}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -699,6 +717,16 @@ export default function AddInventoryPage({ warehouse, products }: Props) {
|
|||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
|
{/* 儲位/貨道 */}
|
||||||
|
<TableCell>
|
||||||
|
<Input
|
||||||
|
value={item.location || ""}
|
||||||
|
onChange={(e) => handleUpdateItem(item.tempId, { location: e.target.value })}
|
||||||
|
className="border-gray-300"
|
||||||
|
placeholder={warehouse.type === 'vending' ? "貨道 (如: A1)" : "儲位 (選填)"}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
{/* 刪除按鈕 */}
|
{/* 刪除按鈕 */}
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useState, useMemo } from "react";
|
import { useState, useMemo, useEffect } from "react";
|
||||||
import { ArrowLeft, PackagePlus, AlertTriangle, Shield, Boxes } from "lucide-react";
|
import { ArrowLeft, PackagePlus, AlertTriangle, Shield, Boxes, FileUp } from "lucide-react";
|
||||||
import { Button } from "@/Components/ui/button";
|
import { Button } from "@/Components/ui/button";
|
||||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||||
import { Head, Link, router } from "@inertiajs/react";
|
import { Head, Link, router } from "@inertiajs/react";
|
||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
AlertDialogTitle,
|
AlertDialogTitle,
|
||||||
} from "@/Components/ui/alert-dialog";
|
} from "@/Components/ui/alert-dialog";
|
||||||
import { Can } from "@/Components/Permission/Can";
|
import { Can } from "@/Components/Permission/Can";
|
||||||
|
import InventoryImportDialog from "@/Components/Warehouse/Inventory/InventoryImportDialog";
|
||||||
|
|
||||||
// 庫存頁面 Props
|
// 庫存頁面 Props
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -35,9 +36,30 @@ export default function WarehouseInventoryPage({
|
|||||||
safetyStockSettings,
|
safetyStockSettings,
|
||||||
availableProducts,
|
availableProducts,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [searchTerm, setSearchTerm] = useState("");
|
// 從 URL 讀取初始狀態
|
||||||
const [typeFilter, setTypeFilter] = useState<string>("all");
|
const queryParams = new URLSearchParams(window.location.search);
|
||||||
|
const [searchTerm, setSearchTerm] = useState(queryParams.get("search") || "");
|
||||||
|
const [typeFilter, setTypeFilter] = useState<string>(queryParams.get("type") || "all");
|
||||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||||
|
const [importDialogOpen, setImportDialogOpen] = useState(false);
|
||||||
|
|
||||||
|
// 當搜尋或篩選變更時,同步到 URL (使用 replace: true 避免產生過多歷史紀錄)
|
||||||
|
useEffect(() => {
|
||||||
|
const params: any = {};
|
||||||
|
if (searchTerm) params.search = searchTerm;
|
||||||
|
if (typeFilter !== "all") params.type = typeFilter;
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
route("warehouses.inventory.index", warehouse.id),
|
||||||
|
params,
|
||||||
|
{
|
||||||
|
preserveState: true,
|
||||||
|
preserveScroll: true,
|
||||||
|
replace: true,
|
||||||
|
only: ["inventories"], // 僅重新拉取數據,避免全頁重新渲染 (如有後端過濾)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}, [searchTerm, typeFilter]);
|
||||||
|
|
||||||
// 篩選庫存列表
|
// 篩選庫存列表
|
||||||
const filteredInventories = useMemo(() => {
|
const filteredInventories = useMemo(() => {
|
||||||
@@ -131,7 +153,7 @@ export default function WarehouseInventoryPage({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 操作按鈕 (位於標題下方) */}
|
{/* 操作按鈕 (位於標題下方) */}
|
||||||
<div className="flex items-center gap-3 mb-6">
|
<div className="flex flex-wrap items-center gap-3 mb-6">
|
||||||
{/* 安全庫存設定按鈕 */}
|
{/* 安全庫存設定按鈕 */}
|
||||||
<Can permission="inventory.safety_stock">
|
<Can permission="inventory.safety_stock">
|
||||||
<Link href={route('warehouses.safety-stock.index', warehouse.id)}>
|
<Link href={route('warehouses.safety-stock.index', warehouse.id)}>
|
||||||
@@ -157,6 +179,18 @@ export default function WarehouseInventoryPage({
|
|||||||
庫存警告:{lowStockItems} 項
|
庫存警告:{lowStockItems} 項
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
{/* 匯入入庫按鈕 */}
|
||||||
|
<Can permission="inventory.adjust">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="button-outlined-primary"
|
||||||
|
onClick={() => setImportDialogOpen(true)}
|
||||||
|
>
|
||||||
|
<FileUp className="mr-2 h-4 w-4" />
|
||||||
|
匯入入庫
|
||||||
|
</Button>
|
||||||
|
</Can>
|
||||||
|
|
||||||
{/* 新增庫存按鈕 */}
|
{/* 新增庫存按鈕 */}
|
||||||
<Can permission="inventory.adjust">
|
<Can permission="inventory.adjust">
|
||||||
<Link href={route('warehouses.inventory.create', warehouse.id)}>
|
<Link href={route('warehouses.inventory.create', warehouse.id)}>
|
||||||
@@ -187,6 +221,7 @@ export default function WarehouseInventoryPage({
|
|||||||
onView={handleView}
|
onView={handleView}
|
||||||
onDelete={confirmDelete}
|
onDelete={confirmDelete}
|
||||||
onViewProduct={handleViewProduct}
|
onViewProduct={handleViewProduct}
|
||||||
|
warehouse={warehouse}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<AlertDialog open={!!deleteId} onOpenChange={(open) => !open && setDeleteId(null)}>
|
<AlertDialog open={!!deleteId} onOpenChange={(open) => !open && setDeleteId(null)}>
|
||||||
@@ -210,6 +245,14 @@ export default function WarehouseInventoryPage({
|
|||||||
</AlertDialogFooter>
|
</AlertDialogFooter>
|
||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
</AlertDialog>
|
</AlertDialog>
|
||||||
|
|
||||||
|
{/* 匯入對話框 */}
|
||||||
|
<InventoryImportDialog
|
||||||
|
open={importDialogOpen}
|
||||||
|
onOpenChange={setImportDialogOpen}
|
||||||
|
warehouseId={warehouse.id}
|
||||||
|
warehouseName={warehouse.name}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</AuthenticatedLayout>
|
</AuthenticatedLayout>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -69,18 +69,39 @@ export default function SafetyStockPage({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleEdit = (updatedSetting: SafetyStockSetting) => {
|
const handleEdit = (updatedSetting: SafetyStockSetting) => {
|
||||||
router.put(route('warehouses.safety-stock.update', [warehouse.id, updatedSetting.id]), {
|
// 如果 ID 包含 temp_,表示這是一個「自動帶入但尚未存入資料庫」的建議項
|
||||||
safetyStock: updatedSetting.safetyStock,
|
// 這種情況應該呼叫 POST (store) 而非 PUT (update),以避免被後端路由模型綁定報 404
|
||||||
}, {
|
if (updatedSetting.id.includes('temp_')) {
|
||||||
onSuccess: () => {
|
router.post(route('warehouses.safety-stock.store', warehouse.id), {
|
||||||
setEditingSetting(null);
|
settings: [{
|
||||||
toast.success(`成功更新 ${updatedSetting.productName} 的安全庫存`);
|
productId: updatedSetting.productId,
|
||||||
},
|
quantity: updatedSetting.safetyStock
|
||||||
onError: (errors) => {
|
}],
|
||||||
const firstError = Object.values(errors)[0];
|
}, {
|
||||||
toast.error(typeof firstError === 'string' ? firstError : "更新失敗");
|
onSuccess: () => {
|
||||||
}
|
setEditingSetting(null);
|
||||||
});
|
toast.success(`成功設定 ${updatedSetting.productName} 的安全庫存`);
|
||||||
|
},
|
||||||
|
onError: (errors) => {
|
||||||
|
const firstError = Object.values(errors)[0];
|
||||||
|
toast.error(typeof firstError === 'string' ? firstError : "設定失敗");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 已存在的項目,正常執行 PUT 更新
|
||||||
|
router.put(route('warehouses.safety-stock.update', [warehouse.id, updatedSetting.id]), {
|
||||||
|
safetyStock: updatedSetting.safetyStock,
|
||||||
|
}, {
|
||||||
|
onSuccess: () => {
|
||||||
|
setEditingSetting(null);
|
||||||
|
toast.success(`成功更新 ${updatedSetting.productName} 的安全庫存`);
|
||||||
|
},
|
||||||
|
onError: (errors) => {
|
||||||
|
const firstError = Object.values(errors)[0];
|
||||||
|
toast.error(typeof firstError === 'string' ? firstError : "更新失敗");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
|
|||||||
@@ -18,6 +18,14 @@ export const STATUS_CONFIG: Record<
|
|||||||
cancelled: { label: "已作廢", variant: "destructive" },
|
cancelled: { label: "已作廢", variant: "destructive" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 供下單/編輯頁面使用的手動狀態選項 (排除系統自動狀態)
|
||||||
|
export const MANUAL_STATUS_OPTIONS = [
|
||||||
|
{ value: 'draft', label: '草稿' },
|
||||||
|
{ value: 'pending', label: '送審中' },
|
||||||
|
{ value: 'approved', label: '已核准' },
|
||||||
|
{ value: 'cancelled', label: '已作廢' },
|
||||||
|
];
|
||||||
|
|
||||||
export const STATUS_OPTIONS = Object.entries(STATUS_CONFIG).map(([value, config]) => ({
|
export const STATUS_OPTIONS = Object.entries(STATUS_CONFIG).map(([value, config]) => ({
|
||||||
value,
|
value,
|
||||||
label: (config as any).label,
|
label: (config as any).label,
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export interface WarehouseInventory {
|
|||||||
safetyStock: number | null;
|
safetyStock: number | null;
|
||||||
status?: '正常' | '低於'; // 後端可能回傳的狀態
|
status?: '正常' | '低於'; // 後端可能回傳的狀態
|
||||||
batchNumber: string; // 批號 (Mock for now)
|
batchNumber: string; // 批號 (Mock for now)
|
||||||
|
location?: string; // 儲位/貨道
|
||||||
expiryDate: string;
|
expiryDate: string;
|
||||||
lastInboundDate: string | null;
|
lastInboundDate: string | null;
|
||||||
lastOutboundDate: string | null;
|
lastOutboundDate: string | null;
|
||||||
@@ -112,6 +113,7 @@ export interface SafetyStockSetting {
|
|||||||
unit?: string;
|
unit?: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
|
isNew?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -174,9 +176,10 @@ export interface InboundItem {
|
|||||||
largeUnit?: string;
|
largeUnit?: string;
|
||||||
conversionRate?: number;
|
conversionRate?: number;
|
||||||
selectedUnit?: 'base' | 'large';
|
selectedUnit?: 'base' | 'large';
|
||||||
batchMode?: 'existing' | 'new'; // 批號模式
|
batchMode?: 'existing' | 'new' | 'none'; // 批號模式
|
||||||
inventoryId?: string; // 選擇現有批號時的 ID
|
inventoryId?: string; // 選擇現有批號時的 ID
|
||||||
batchNumber?: string;
|
batchNumber?: string;
|
||||||
|
location?: string; // 儲位/貨道
|
||||||
originCountry?: string; // 新增產地
|
originCountry?: string; // 新增產地
|
||||||
expiryDate?: string;
|
expiryDate?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user