44
55namespace App \Filament \Resources \OrganizationResource \Actions \Tables ;
66
7+ use App \Enums \UserRole ;
78use App \Filament \Exports \ExcelExportWithNotificationInDB ;
89use App \Filament \Resources \OrganizationResource ;
910use App \Models \Organization ;
1516
1617class ExportAction extends BaseAction
1718{
18- protected string | null $ status = null ;
19+ protected string | null $ status = null ;
1920
2021 protected function setUp (): void
2122 {
@@ -26,6 +27,7 @@ protected function setUp(): void
2627
2728 $ this ->exports ([
2829 ExcelExportWithNotificationInDB::make ()
30+ ->fromTable ()
2931 ->withFilename (fn () => sprintf (
3032 '%s-%s-%s ' ,
3133 now ()->format ('Y_m_d-H_i_s ' ),
@@ -34,6 +36,7 @@ protected function setUp(): void
3436 ))
3537 ->modifyQueryUsing (function (Builder $ query ) use ($ status ) {
3638 return $ query
39+ ->addSelect (['accepts_volunteers ' , 'eu_platesc_merchant_id ' , 'eu_platesc_private_key ' , 'cif ' , 'description ' , 'address ' , 'contact_person ' , 'contact_phone ' , 'contact_email ' , 'website ' , 'facebook ' ])
3740 ->status ($ status )
3841 ->with ([
3942 'activityDomains ' ,
@@ -55,11 +58,24 @@ protected function setUp(): void
5558 ->heading (__ ('organization.labels.name ' )),
5659
5760 Column::make ('status ' )
61+ ->formatStateUsing (fn (Organization $ record ) => $ record ->status ->label ())
5862 ->heading (__ ('organization.labels.status ' )),
5963
60- Column::make ('cif ' )
61- ->heading (__ ('organization.labels.cif ' )),
64+ Column::make ('accepts_donations ' )
65+ ->heading (__ ('organization.labels.accepts_donations ' ))
66+ ->formatStateUsing (
67+ fn (Organization $ record ) => $ record ->accept_donations
68+ ? __ ('forms::components.select.boolean.true ' )
69+ : __ ('forms::components.select.boolean.false ' )
70+ ),
6271
72+ Column::make ('counties ' )
73+ ->heading (__ ('organization.labels.counties ' ))
74+ ->formatStateUsing (
75+ fn (Organization $ record ) => $ record ->counties
76+ ->pluck ('name ' )
77+ ->join (', ' )
78+ ),
6379 Column::make ('description ' )
6480 ->heading (__ ('organization.labels.description ' )),
6581
@@ -71,34 +87,38 @@ protected function setUp(): void
7187 ->join (', ' )
7288 ),
7389
74- Column::make ('users ' )
75- ->heading (__ ('organization.labels.admin ' ))
90+ Column::make ('cif ' )
91+ ->heading (__ ('organization.labels.cif ' )),
92+
93+ Column::make ('statute ' )
94+ ->heading (__ ('organization.labels.statute ' ))
7695 ->formatStateUsing (
77- fn (Collection $ state ) => $ state ->pluck ('name ' )
78- ->join (', ' )
96+ fn (Organization $ record ) => $ record ->has_statute
97+ ? $ record ->statute_file
98+ : __ ('forms::components.select.boolean.false ' )
7999 ),
80100
81- Column::make ('contact_person ' )
82- ->heading (__ ('organization.labels.contact_person ' )),
101+ Column::make ('website ' )
102+ ->heading (__ ('organization.labels.website ' )),
103+
104+ Column::make ('address ' )
105+ ->heading (__ ('organization.labels.address ' )),
83106
84107 Column::make ('contact_phone ' )
85108 ->heading (__ ('organization.labels.contact_phone ' )),
86109
87110 Column::make ('contact_email ' )
88111 ->heading (__ ('organization.labels.contact_email ' )),
89112
90- Column::make ('website ' )
91- ->heading (__ ('organization.labels.website ' )),
92-
93- Column::make ('address ' )
94- ->heading (__ ('organization.labels.address ' )),
113+ Column::make ('contact_person ' )
114+ ->heading (__ ('organization.labels.contact_person ' )),
95115
96- Column::make ('counties ' )
97- ->heading (__ ('organization.labels.counties ' ))
116+ Column::make ('users ' )
117+ ->heading (__ ('organization.labels.admin_count ' ))
98118 ->formatStateUsing (
99- fn (Organization $ record ) => $ record -> counties
100- -> pluck ( ' name ' )
101- -> join ( ' , ' )
119+ fn (Collection $ state ) => $ state -> filter (
120+ fn ( $ record ) => $ record -> role !== UserRole:: ADMIN -> value
121+ )-> count ( )
102122 ),
103123
104124 Column::make ('accepts_volunteers ' )
@@ -109,73 +129,41 @@ protected function setUp(): void
109129 : __ ('forms::components.select.boolean.false ' )
110130 ),
111131
112- Column::make ('has_volunteers ' )
113- ->heading (__ ('organization.labels.has_volunteers ' ))
114- ->formatStateUsing (
115- fn (Organization $ record ) => $ record ->volunteers_count
116- ? __ ('forms::components.select.boolean.true ' )
117- : __ ('forms::components.select.boolean.false ' )
118- ),
119-
120132 Column::make ('projects_count ' )
121133 ->heading (__ ('organization.labels.projects_count ' ))
122134 ->formatStateUsing (
123- fn (Organization $ record ) => $ record ->projects
135+ fn (Organization $ record ) => $ record ->projects ()
124136 ->count ()
125137 ),
126138
127139 Column::make ('active_projects_count ' )
128140 ->heading (__ ('organization.labels.active_projects_count ' ))
129141 ->formatStateUsing (
130- fn (Organization $ record ) => $ record ->projects ()
131- ->whereIsOpen ()
132- ->count ()
133- ),
134-
135- Column::make ('has_projects ' )
136- ->heading (__ ('organization.labels.has_projects ' ))
137- ->formatStateUsing (
138- fn (Organization $ record ) => $ record ->projects ->count ()
139- ? __ ('forms::components.select.boolean.true ' )
140- : __ ('forms::components.select.boolean.false ' )
141- ),
142-
143- Column::make ('has_active_projects ' )
144- ->heading (__ ('organization.labels.has_active_projects ' ))
145- ->formatStateUsing (
146- fn (Organization $ record ) => $ record ->projects ()->whereIsOpen ()->count ()
147- ? __ ('forms::components.select.boolean.true ' )
148- : __ ('forms::components.select.boolean.false ' )
149- ),
150-
151- Column::make ('has_eu_platesc ' )
152- ->heading (__ ('organization.labels.has_eu_platesc ' ))
153- ->formatStateUsing (
154- fn (Organization $ record ) => $ record ->eu_platesc_merchant_id !== null && $ record ->eu_platesc_private_key !== null
155- ? __ ('forms::components.select.boolean.true ' )
156- : __ ('forms::components.select.boolean.false ' )
157- ),
158-
159- Column::make ('has_donations ' )
160- ->heading (__ ('organization.labels.has_donations ' ))
161- ->formatStateUsing (
162- fn (Organization $ record ) => $ record ->projects ->sum ('donations_count ' )
163- ? __ ('forms::components.select.boolean.true ' )
164- : __ ('forms::components.select.boolean.false ' )
142+ function (Organization $ record ) {
143+ $ count = $ record ->projects ()
144+ ->whereIsOpen ()
145+ ->count ();
146+
147+ return $ count > 0 ?
148+ $ count :
149+ '0 ' ;
150+ }
165151 ),
166152
167153 Column::make ('donations_count ' )
168154 ->heading (__ ('organization.labels.donations_count ' ))
169155 ->formatStateUsing (
170156 fn (Organization $ record ) => $ record ->donations ()
157+ ->whereCharged ()
171158 ->count ()
172159 ),
173160
174161 Column::make ('donations_amount ' )
175162 ->heading (__ ('organization.labels.donations_amount ' ))
176163 ->formatStateUsing (
177164 fn (Organization $ record ) => $ record ->donations ()
178- ->sum ('amount ' )
165+ ->whereCharged ()
166+ ->sum ('charge_amount ' )
179167 ),
180168
181169 ])
0 commit comments