Big changes added events for decisions
This commit is contained in:
@@ -48,6 +48,7 @@ public function show(\App\Models\Segment $segment)
|
||||
{
|
||||
// Retrieve contracts that are active in this segment, eager-loading required relations
|
||||
$search = request('search');
|
||||
$clientFilter = request('client') ?? request('client_id'); // support either ?client=<uuid|id> or ?client_id=<id>
|
||||
$contractsQuery = \App\Models\Contract::query()
|
||||
->whereHas('segments', function ($q) use ($segment) {
|
||||
$q->where('segments.id', $segment->id)
|
||||
@@ -61,7 +62,18 @@ public function show(\App\Models\Segment $segment)
|
||||
])
|
||||
->latest('id');
|
||||
|
||||
if (!empty($search)) {
|
||||
// Optional filter by client (accepts numeric id or client uuid)
|
||||
if (! empty($clientFilter)) {
|
||||
$contractsQuery->whereHas('clientCase.client', function ($q) use ($clientFilter) {
|
||||
if (is_numeric($clientFilter)) {
|
||||
$q->where('clients.id', (int) $clientFilter);
|
||||
} else {
|
||||
$q->where('clients.uuid', $clientFilter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (! empty($search)) {
|
||||
$contractsQuery->where(function ($qq) use ($search) {
|
||||
$qq->where('contracts.reference', 'ilike', '%'.$search.'%')
|
||||
->orWhereHas('clientCase.person', function ($p) use ($search) {
|
||||
@@ -88,9 +100,27 @@ public function show(\App\Models\Segment $segment)
|
||||
$contracts->setCollection($items);
|
||||
}
|
||||
|
||||
// Build a full client list for this segment (not limited to current page) for the dropdown
|
||||
$clients = \App\Models\Client::query()
|
||||
->whereHas('clientCases.contracts.segments', function ($q) use ($segment) {
|
||||
$q->where('segments.id', $segment->id)
|
||||
->where('contract_segment.active', '=', 1);
|
||||
})
|
||||
->with(['person:id,full_name'])
|
||||
->get(['uuid', 'person_id'])
|
||||
->map(function ($c) {
|
||||
return [
|
||||
'uuid' => (string) $c->uuid,
|
||||
'name' => (string) optional($c->person)->full_name,
|
||||
];
|
||||
})
|
||||
->sortBy('name', SORT_NATURAL | SORT_FLAG_CASE)
|
||||
->values();
|
||||
|
||||
return Inertia::render('Segments/Show', [
|
||||
'segment' => $segment->only(['id','name','description']),
|
||||
'segment' => $segment->only(['id', 'name', 'description']),
|
||||
'contracts' => $contracts,
|
||||
'clients' => $clients,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -120,7 +150,7 @@ public function update(UpdateSegmentRequest $request, Segment $segment)
|
||||
'name' => $data['name'],
|
||||
'description' => $data['description'] ?? null,
|
||||
'active' => $data['active'] ?? $segment->active,
|
||||
'exclude' => $data['exclude'] ?? $segment->exclude
|
||||
'exclude' => $data['exclude'] ?? $segment->exclude,
|
||||
]);
|
||||
|
||||
return to_route('settings.segments')->with('success', 'Segment updated');
|
||||
|
||||
Reference in New Issue
Block a user