Changes to import and notifications
This commit is contained in:
@@ -66,21 +66,44 @@ public function share(Request $request): array
|
||||
}
|
||||
|
||||
$today = now()->toDateString();
|
||||
|
||||
// Base fetch to avoid serialization issues; eager load relations afterwards
|
||||
$activities = \App\Models\Activity::query()
|
||||
->with([
|
||||
// Include contract uuid and reference, keep id for relation mapping, and client_case_id for nested eager load
|
||||
'contract:id,uuid,reference,client_case_id',
|
||||
// Include client case uuid (id required for mapping, will be hidden in JSON)
|
||||
'contract.clientCase:id,uuid',
|
||||
// Include account amounts; contract_id needed for relation mapping
|
||||
'contract.account:contract_id,balance_amount,initial_amount',
|
||||
])
|
||||
->select(['id', 'due_date', 'amount', 'contract_id', 'client_case_id', 'created_at'])
|
||||
->whereDate('due_date', $today)
|
||||
->where('user_id', $user->id)
|
||||
->whereNotExists(function ($q) use ($request) {
|
||||
$q->from('activity_notification_reads as anr')
|
||||
->whereColumn('anr.activity_id', 'activities.id')
|
||||
->where('anr.user_id', optional($request->user())->id)
|
||||
->whereColumn('anr.due_date', 'activities.due_date');
|
||||
})
|
||||
->orderBy('created_at')
|
||||
->limit(20)
|
||||
->get();
|
||||
|
||||
// Eager load needed relations (contracts and client cases) with qualified selects
|
||||
$activities->load([
|
||||
'contract' => function ($q) {
|
||||
$q->select(['contracts.id', 'contracts.uuid', 'contracts.reference', 'contracts.client_case_id'])
|
||||
->with([
|
||||
'clientCase' => function ($qq) {
|
||||
$qq->select(['client_cases.id', 'client_cases.uuid']);
|
||||
},
|
||||
'account' => function ($qq) {
|
||||
$qq->select(['accounts.id', 'accounts.contract_id', 'accounts.balance_amount', 'accounts.initial_amount']);
|
||||
},
|
||||
]);
|
||||
},
|
||||
'clientCase' => function ($q) {
|
||||
$q->select(['client_cases.id', 'client_cases.uuid', 'client_cases.person_id'])
|
||||
->with([
|
||||
'person' => function ($qq) {
|
||||
$qq->select(['person.id', 'person.full_name']);
|
||||
},
|
||||
]);
|
||||
},
|
||||
]);
|
||||
|
||||
return [
|
||||
'dueToday' => [
|
||||
'count' => $activities->count(),
|
||||
|
||||
Reference in New Issue
Block a user