fix: 修正部分進貨採購單更新失敗與狀態顯示問題
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 50s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-27 13:27:28 +08:00
parent 293358df62
commit a7c445bd3f
22 changed files with 1413 additions and 42 deletions

View File

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