修正bug
All checks were successful
Koori-ERP-Sync-Only / sync-update (push) Successful in 1m5s

This commit is contained in:
2025-12-31 17:48:36 +08:00
parent c152dc6d81
commit 8cbf73681e
5 changed files with 62 additions and 21 deletions

View File

@@ -123,11 +123,25 @@ class PurchaseOrderController extends Controller
$taxAmount = round($totalAmount * 0.05, 2);
$grandTotal = $totalAmount + $taxAmount;
// 確保有一個有效的使用者 ID
$userId = auth()->id();
if (!$userId) {
$user = \App\Models\User::first();
if (!$user) {
$user = \App\Models\User::create([
'name' => '系統管理員',
'email' => 'admin@example.com',
'password' => bcrypt('password'),
]);
}
$userId = $user->id;
}
$order = PurchaseOrder::create([
'code' => $code,
'vendor_id' => $validated['vendor_id'],
'warehouse_id' => $validated['warehouse_id'],
'user_id' => auth()->id() ?? 1, // Fallback for dev if not using auth
'user_id' => $userId,
'status' => 'draft',
'expected_delivery_date' => $validated['expected_delivery_date'],
'total_amount' => $totalAmount,