45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Reconcile;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\ReconcileItem;
|
|
use App\Models\ReconcileJob;
|
|
use App\Support\ApiResponse;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
/** GET /api/v1/admin/reconcile-jobs/{reconcile_job}/items */
|
|
final class ReconcileItemIndexController extends Controller
|
|
{
|
|
public function __invoke(Request $request, ReconcileJob $reconcile_job): JsonResponse
|
|
{
|
|
$perPage = min(max((int) $request->integer('per_page', 50), 1), 200);
|
|
$page = max((int) $request->integer('page', 1), 1);
|
|
|
|
$paginator = $reconcile_job->items()
|
|
->orderBy('id')
|
|
->paginate($perPage, ['*'], 'page', $page);
|
|
|
|
return ApiResponse::success([
|
|
'job_id' => (int) $reconcile_job->id,
|
|
'job_no' => $reconcile_job->job_no,
|
|
'items' => collect($paginator->items())->map(fn (ReconcileItem $r) => [
|
|
'id' => (int) $r->id,
|
|
'side_a_ref' => $r->side_a_ref,
|
|
'side_b_ref' => $r->side_b_ref,
|
|
'difference_amount' => (int) $r->difference_amount,
|
|
'status' => $r->status,
|
|
'resolved_at' => $r->resolved_at?->toIso8601String(),
|
|
'created_at' => $r->created_at?->toIso8601String(),
|
|
])->all(),
|
|
'meta' => [
|
|
'current_page' => $paginator->currentPage(),
|
|
'per_page' => $paginator->perPage(),
|
|
'total' => $paginator->total(),
|
|
'last_page' => $paginator->lastPage(),
|
|
],
|
|
]);
|
|
}
|
|
}
|