feat(inventory): 實作過期與瑕疵庫存總計顯示,並強化庫存明細過期提示

This commit is contained in:
2026-02-05 15:50:14 +08:00
parent ba3c10ac13
commit a518d390bd
16 changed files with 751 additions and 574 deletions

View File

@@ -63,8 +63,14 @@ class ProductImport implements ToModel, WithHeadingRow, WithValidation, WithMapp
return null;
}
// 處理商品代號:若為空則自動生成
$code = $row['商品代號'] ?? null;
if (empty($code)) {
$code = $this->generateRandomCode();
}
return new Product([
'code' => $row['商品代號'],
'code' => $code,
'barcode' => $row['條碼'],
'name' => $row['商品名稱'],
'category_id' => $categoryId,
@@ -81,10 +87,28 @@ class ProductImport implements ToModel, WithHeadingRow, WithValidation, WithMapp
]);
}
/**
* 生成隨機 8 碼代號 (大寫英文+數字)
*/
private function generateRandomCode(): string
{
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$code = '';
do {
$code = '';
for ($i = 0; $i < 8; $i++) {
$code .= $characters[rand(0, strlen($characters) - 1)];
}
} while (Product::where('code', $code)->exists());
return $code;
}
public function rules(): array
{
return [
'商品代號' => ['required', 'string', 'min:2', 'max:8', 'unique:products,code'],
'商品代號' => ['nullable', 'string', 'min:2', 'max:8', 'unique:products,code'],
'條碼' => ['required', 'string', 'unique:products,barcode'],
'商品名稱' => ['required', 'string'],
'類別名稱' => ['required', function($attribute, $value, $fail) {