feat: 新增採購單發票欄位、更新 SearchableSelect 樣式與搜尋門檻至 10 個項目
This commit is contained in:
@@ -94,6 +94,9 @@ class PurchaseOrderController extends Controller
|
||||
'warehouse_id' => 'required|exists:warehouses,id',
|
||||
'expected_delivery_date' => 'nullable|date',
|
||||
'remark' => 'nullable|string',
|
||||
'invoice_number' => ['nullable', 'string', 'max:11', 'regex:/^[A-Z]{2}-\d{8}$/'],
|
||||
'invoice_date' => 'nullable|date',
|
||||
'invoice_amount' => 'nullable|numeric|min:0',
|
||||
'items' => 'required|array|min:1',
|
||||
'items.*.productId' => 'required|exists:products,id',
|
||||
'items.*.quantity' => 'required|numeric|min:0.01',
|
||||
@@ -154,6 +157,9 @@ class PurchaseOrderController extends Controller
|
||||
'tax_amount' => $taxAmount,
|
||||
'grand_total' => $grandTotal,
|
||||
'remark' => $validated['remark'],
|
||||
'invoice_number' => $validated['invoice_number'] ?? null,
|
||||
'invoice_date' => $validated['invoice_date'] ?? null,
|
||||
'invoice_amount' => $validated['invoice_amount'] ?? null,
|
||||
]);
|
||||
|
||||
foreach ($validated['items'] as $item) {
|
||||
@@ -310,6 +316,9 @@ class PurchaseOrderController extends Controller
|
||||
'expected_delivery_date' => 'nullable|date',
|
||||
'remark' => 'nullable|string',
|
||||
'status' => 'required|string|in:draft,pending,processing,shipping,confirming,completed,cancelled',
|
||||
'invoice_number' => ['nullable', 'string', 'max:11', 'regex:/^[A-Z]{2}-\d{8}$/'],
|
||||
'invoice_date' => 'nullable|date',
|
||||
'invoice_amount' => 'nullable|numeric|min:0',
|
||||
'items' => 'required|array|min:1',
|
||||
'items.*.productId' => 'required|exists:products,id',
|
||||
'items.*.quantity' => 'required|numeric|min:0.01',
|
||||
@@ -338,6 +347,9 @@ class PurchaseOrderController extends Controller
|
||||
'grand_total' => $grandTotal,
|
||||
'remark' => $validated['remark'],
|
||||
'status' => $validated['status'],
|
||||
'invoice_number' => $validated['invoice_number'] ?? null,
|
||||
'invoice_date' => $validated['invoice_date'] ?? null,
|
||||
'invoice_amount' => $validated['invoice_amount'] ?? null,
|
||||
]);
|
||||
|
||||
// Sync items
|
||||
|
||||
@@ -22,13 +22,18 @@ class PurchaseOrder extends Model
|
||||
'tax_amount',
|
||||
'grand_total',
|
||||
'remark',
|
||||
'invoice_number',
|
||||
'invoice_date',
|
||||
'invoice_amount',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'expected_delivery_date' => 'date',
|
||||
'invoice_date' => 'date',
|
||||
'total_amount' => 'decimal:2',
|
||||
'tax_amount' => 'decimal:2',
|
||||
'grand_total' => 'decimal:2',
|
||||
'invoice_amount' => 'decimal:2',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
@@ -40,6 +45,9 @@ class PurchaseOrder extends Model
|
||||
'createdBy',
|
||||
'warehouse_name',
|
||||
'createdAt',
|
||||
'invoiceNumber',
|
||||
'invoiceDate',
|
||||
'invoiceAmount',
|
||||
];
|
||||
|
||||
public function getCreatedAtAttribute()
|
||||
@@ -82,6 +90,22 @@ class PurchaseOrder extends Model
|
||||
return $this->warehouse ? $this->warehouse->name : '';
|
||||
}
|
||||
|
||||
public function getInvoiceNumberAttribute(): ?string
|
||||
{
|
||||
return $this->attributes['invoice_number'] ?? null;
|
||||
}
|
||||
|
||||
public function getInvoiceDateAttribute(): ?string
|
||||
{
|
||||
$date = $this->attributes['invoice_date'] ?? null;
|
||||
return $date ? \Illuminate\Support\Carbon::parse($date)->format('Y-m-d') : null;
|
||||
}
|
||||
|
||||
public function getInvoiceAmountAttribute(): ?float
|
||||
{
|
||||
return isset($this->attributes['invoice_amount']) ? (float) $this->attributes['invoice_amount'] : null;
|
||||
}
|
||||
|
||||
public function vendor(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Vendor::class);
|
||||
|
||||
Reference in New Issue
Block a user