55 lines
1.9 KiB
PHP
55 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Reconcile;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\ReconcileJob;
|
|
use App\Support\ApiResponse;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
/** GET /api/v1/admin/reconcile-jobs */
|
|
final class ReconcileJobIndexController extends Controller
|
|
{
|
|
public function __invoke(Request $request): JsonResponse
|
|
{
|
|
$perPage = min(max((int) $request->integer('per_page', 25), 1), 100);
|
|
$page = max((int) $request->integer('page', 1), 1);
|
|
$type = trim((string) $request->query('reconcile_type', ''));
|
|
|
|
$q = ReconcileJob::query()->orderByDesc('id');
|
|
if ($type !== '') {
|
|
$q->where('reconcile_type', $type);
|
|
}
|
|
|
|
$paginator = $q->paginate($perPage, ['*'], 'page', $page);
|
|
|
|
return ApiResponse::success([
|
|
'items' => collect($paginator->items())->map(fn (ReconcileJob $j) => $this->row($j))->all(),
|
|
'meta' => [
|
|
'current_page' => $paginator->currentPage(),
|
|
'per_page' => $paginator->perPage(),
|
|
'total' => $paginator->total(),
|
|
'last_page' => $paginator->lastPage(),
|
|
],
|
|
]);
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
private function row(ReconcileJob $j): array
|
|
{
|
|
return [
|
|
'id' => (int) $j->id,
|
|
'job_no' => $j->job_no,
|
|
'admin_user_id' => $j->admin_user_id !== null ? (int) $j->admin_user_id : null,
|
|
'reconcile_type' => $j->reconcile_type,
|
|
'status' => $j->status,
|
|
'period_start' => $j->period_start?->toIso8601String(),
|
|
'period_end' => $j->period_end?->toIso8601String(),
|
|
'summary_json' => $j->summary_json,
|
|
'finished_at' => $j->finished_at?->toIso8601String(),
|
|
'created_at' => $j->created_at?->toIso8601String(),
|
|
];
|
|
}
|
|
}
|