This commit is contained in:
baodev0
2026-10-30 13:05:47 +07:00
parent 1d40dfbb44
commit 047c23beff
@@ -29,6 +29,7 @@ class ServiceController extends Controller
public function index(Request $request): JsonResponse
{
$perPage = min((int) ($request->per_page ?? 15), 100);
$expiringDays = in_array((int) $request->expiring_days, [1, 3, 10, 20, 30], true) ? (int) $request->expiring_days : null;
$query = Service::with(['customer:id,uuid,fullname,email', 'product:id,uuid,name,product_type', 'invoice:id,invoice_number', 'vmware:id,name,module_ip_address', 'orderItem:id,order_id', 'orderItem.order:id,order_num', 'tags'])
->withExists(['cancellationRequests as pending_cancellation' => fn ($q) => $q->pending()])
@@ -40,9 +41,10 @@ class ServiceController extends Controller
->where('type', $v)
->orWhere(fn($legacy) => $legacy->whereNull('type')->whereHas('product', fn($product) => $product->where('product_type', $v)))))
->when($request->customer_id, fn($q, $v) => $q->where('customer_id', $v))
->when($request->boolean('unassigned'), fn($q) => $q->whereNull('customer_id'));
->when($request->boolean('unassigned'), fn($q) => $q->whereNull('customer_id'))
->when($expiringDays, fn($q, $days) => $q->whereBetween('expires_at', [now(), now()->addDays($days)]));
$paginator = $query->latest()->paginate($perPage);
$paginator = ($expiringDays ? $query->orderBy('expires_at') : $query->latest())->paginate($perPage);
$invoices = $this->linkedInvoices($paginator->getCollection());
$paginator->getCollection()->each(fn (Service $service) => $service->setAttribute(
'linked_invoices',