refactor: changes to inventory status (approved/unapprove)
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 1m6s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-29 13:04:54 +08:00
parent 46753cc3bc
commit 56e30a85bb
11 changed files with 683 additions and 398 deletions

View File

@@ -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)
{

View File

@@ -81,7 +81,9 @@ Route::middleware('auth')->group(function () {
Route::post('/inventory/count-docs', [CountDocController::class, 'store'])->name('inventory.count.store');
Route::put('/inventory/count-docs/{doc}', [CountDocController::class, 'update'])->name('inventory.count.update');
Route::delete('/inventory/count-docs/{doc}', [CountDocController::class, 'destroy'])->name('inventory.count.destroy');
Route::put('/inventory/count-docs/{doc}/reopen', [CountDocController::class, 'reopen'])->name('inventory.count.reopen');
});
Route::get('/inventory/count-docs/{doc}/print', [CountDocController::class, 'print'])->name('inventory.count.print');
});
// 庫存盤調 (Stock Adjustment) - Global