Skip to content

Commit 1ecedf9

Browse files
authored
fix: report queries (#417)
* fix: report queries * wip * fix: project export action * fix: user export action * wip
1 parent b8ef65a commit 1ecedf9

File tree

5 files changed

+150
-292
lines changed

5 files changed

+150
-292
lines changed

app/Filament/Resources/OrganizationResource/Actions/Tables/ExportAction.php

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function setUp(): void
3131
$this->exports([
3232
ExcelExportWithNotificationInDB::make()
3333
->fromTable()
34-
->withFilename(fn () => sprintf(
34+
->withFilename(fn () => \sprintf(
3535
'%s-%s-%s',
3636
now()->format('Y_m_d-H_i_s'),
3737
Str::slug(OrganizationResource::getPluralModelLabel()),
@@ -42,15 +42,21 @@ protected function setUp(): void
4242
->addSelect(['accepts_volunteers', 'eu_platesc_merchant_id', 'eu_platesc_private_key', 'cif', 'description', 'address', 'contact_person', 'contact_phone', 'contact_email', 'website', 'facebook'])
4343
->status($status)
4444
->with([
45-
'activityDomains',
46-
'counties',
45+
'activityDomains:id,name',
46+
'counties:id,name',
4747
'projects' => fn ($q) => $q->select('id', 'organization_id', 'status')
4848
->withCount('donations'),
4949
'users' => fn ($q) => $q->select('organization_id', 'name', 'role')
5050
->onlyOrganizationAdmins(),
5151
])
52+
->withSum([
53+
'donations' => fn ($q) => $q->whereCharged(),
54+
], 'charge_amount')
5255
->withCount([
5356
'volunteers',
57+
'donations' => fn ($q) => $q->whereCharged(),
58+
'projects',
59+
'projects as active_projects_count' => fn ($q) => $q->whereIsOpen(),
5460
]);
5561
})
5662
->withColumns([
@@ -79,6 +85,7 @@ protected function setUp(): void
7985
->pluck('name')
8086
->join(', ')
8187
),
88+
8289
Column::make('description')
8390
->heading(__('organization.labels.description')),
8491

@@ -133,41 +140,16 @@ protected function setUp(): void
133140
),
134141

135142
Column::make('projects_count')
136-
->heading(__('organization.labels.projects_count'))
137-
->formatStateUsing(
138-
fn (Organization $record) => $record->projects()
139-
->count()
140-
),
143+
->heading(__('organization.labels.projects_count')),
141144

142145
Column::make('active_projects_count')
143-
->heading(__('organization.labels.active_projects_count'))
144-
->formatStateUsing(
145-
function (Organization $record) {
146-
$count = $record->projects()
147-
->whereIsOpen()
148-
->count();
149-
150-
return $count > 0 ?
151-
$count :
152-
'0';
153-
}
154-
),
146+
->heading(__('organization.labels.active_projects_count')),
155147

156148
Column::make('donations_count')
157-
->heading(__('organization.labels.donations_count'))
158-
->formatStateUsing(
159-
fn (Organization $record) => $record->donations()
160-
->whereCharged()
161-
->count()
162-
),
149+
->heading(__('organization.labels.donations_count')),
163150

164-
Column::make('donations_amount')
165-
->heading(__('organization.labels.donations_amount'))
166-
->formatStateUsing(
167-
fn (Organization $record) => $record->donations()
168-
->whereCharged()
169-
->sum('charge_amount')
170-
),
151+
Column::make('donations_sum_amount')
152+
->heading(__('organization.labels.donations_amount')),
171153

172154
])
173155
->queue(),

app/Filament/Resources/ProjectResource/Actions/ExportAction.php

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)