refactor: changes to inventory status (approved/unapprove)
This commit is contained in:
@@ -40,7 +40,12 @@ class CountDocController extends Controller
|
||||
$perPage = 15;
|
||||
}
|
||||
|
||||
$docs = $query->orderByDesc('created_at')
|
||||
$countQuery = function ($query) {
|
||||
$query->whereNotNull('counted_qty');
|
||||
};
|
||||
|
||||
$docs = $query->withCount(['items', 'items as counted_items_count' => $countQuery])
|
||||
->orderByDesc('created_at')
|
||||
->paginate($perPage)
|
||||
->withQueryString()
|
||||
->through(function ($doc) {
|
||||
@@ -53,6 +58,8 @@ class CountDocController extends Controller
|
||||
'completed_at' => $doc->completed_at ? $doc->completed_at->format('Y-m-d H:i') : '-',
|
||||
'created_by' => $doc->createdBy?->name,
|
||||
'remarks' => $doc->remarks,
|
||||
'total_items' => $doc->items_count,
|
||||
'counted_items' => $doc->counted_items_count,
|
||||
];
|
||||
});
|
||||
|
||||
@@ -116,6 +123,39 @@ class CountDocController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function print(InventoryCountDoc $doc)
|
||||
{
|
||||
$doc->load(['items.product.baseUnit', 'createdBy', 'completedBy', 'warehouse']);
|
||||
|
||||
$docData = [
|
||||
'id' => (string) $doc->id,
|
||||
'doc_no' => $doc->doc_no,
|
||||
'warehouse_name' => $doc->warehouse->name,
|
||||
'snapshot_date' => $doc->snapshot_date ? $doc->snapshot_date->format('Y-m-d') : date('Y-m-d'), // Use date only
|
||||
'created_at' => $doc->created_at->format('Y-m-d'),
|
||||
'print_date' => date('Y-m-d'),
|
||||
'created_by' => $doc->createdBy?->name,
|
||||
'items' => $doc->items->map(function ($item) {
|
||||
return [
|
||||
'id' => (string) $item->id,
|
||||
'product_name' => $item->product->name,
|
||||
'product_code' => $item->product->code,
|
||||
'specification' => $item->product->specification,
|
||||
'unit' => $item->product->baseUnit?->name,
|
||||
'quantity' => (float) ($item->counted_qty ?? $item->system_qty), // Default to system qty if counted is null, or just counted? User wants "Count Sheet" -> maybe blank if not counted?
|
||||
// Actually, if it's "Completed", we show counted. If it's "Pending", we usually show blank or system.
|
||||
// The 'Show' page logic suggests we show counted_qty.
|
||||
'counted_qty' => $item->counted_qty,
|
||||
'notes' => $item->notes,
|
||||
];
|
||||
}),
|
||||
];
|
||||
|
||||
return Inertia::render('Inventory/Count/Print', [
|
||||
'doc' => $docData,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, InventoryCountDoc $doc)
|
||||
{
|
||||
if ($doc->status === 'completed') {
|
||||
@@ -142,6 +182,23 @@ class CountDocController extends Controller
|
||||
|
||||
return redirect()->back()->with('success', '暫存成功');
|
||||
}
|
||||
|
||||
public function reopen(InventoryCountDoc $doc)
|
||||
{
|
||||
if ($doc->status !== 'completed') {
|
||||
return redirect()->back()->with('error', '只有已核准的盤點單可以取消核准');
|
||||
}
|
||||
|
||||
// TODO: Move logic to Service if complex
|
||||
$doc->update([
|
||||
'status' => 'counting', // Revert to counting (draft)
|
||||
'completed_at' => null,
|
||||
'completed_by' => null,
|
||||
]);
|
||||
|
||||
return redirect()->route('inventory.count.show', [$doc->id])
|
||||
->with('success', '已取消核准,單據回復為盤點中狀態');
|
||||
}
|
||||
|
||||
public function destroy(InventoryCountDoc $doc)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user