Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Enums/EuPlatescStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum EuPlatescStatus: string
case PAYMENT_DECLINED = 'payment_declined';
case POSSIBLE_FRAUD = 'possible_fraud';
case CHARGED = 'charged';
case CAPTURE = 'capture';

public function labelKeyPrefix(): string
{
Expand Down
16 changes: 16 additions & 0 deletions app/Filament/Exports/ExcelExportWithNotificationInDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@

class ExcelExportWithNotificationInDB extends ExcelExport
{
public function getColumns(): array
{
$columns = [];
foreach ($this->evaluate($this->columns) as $column) {
$columns[$column->getName()] = $column;
}

return $columns;
}

public function export()
{
$this->resolveFilename();
Expand All @@ -34,5 +44,11 @@ function () use ($authUser, $filename) {
new ExportExcelNotification($authUser, $filename)
);
}]);

\Filament\Notifications\Notification::make('export')
->title(__('notification.export.success.title'))
->body(__('notification.export.success.body'))
->success()
->send();
}
}
2 changes: 1 addition & 1 deletion app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public function getHeaderWidgets(): array

protected function getHeaderWidgetsColumns(): int
{
return 3;
return 4;
}
}
4 changes: 4 additions & 0 deletions app/Filament/Resources/DonationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Enums\EuPlatescStatus;
use App\Filament\Filters\DateFilter;
use App\Filament\Resources\DonationResource\Actions\ExportAction;
use App\Filament\Resources\DonationResource\Pages;
use App\Forms\Components\Link;
use App\Models\Donation;
Expand Down Expand Up @@ -148,6 +149,9 @@ public static function table(Table $table): Table
DateFilter::make('created_at'),
])
->defaultSort('created_at', 'desc')
->headerActions([
ExportAction::make('download'),
])
->actions([
ViewAction::make()->iconButton(),
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\DonationResource\Actions;

use App\Filament\Exports\ExcelExportWithNotificationInDB;
use App\Filament\Resources\DonationResource;
use App\Models\Donation;
use Filament\Notifications\Notification;
use Illuminate\Support\Str;
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction as BaseAction;
use pxlrbt\FilamentExcel\Columns\Column;

class ExportAction extends BaseAction
{
protected string | null $status = null;

protected function setUp(): void
{
parent::setUp();

$this->color('secondary');

try {
$this->exports([
ExcelExportWithNotificationInDB::make()
->withFilename(fn () => sprintf(
'%s-%s',
now()->format('Y_m_d-H_i_s'),
Str::slug(DonationResource::getPluralModelLabel()),
))
->fromTable()

->withColumns([
Column::make('id')
->heading('ID'),

Column::make('organization.name')
->formatStateUsing(fn ($state) => Str::upper($state))
->heading(__('organization.label.singular')),

Column::make('project.name')
->formatStateUsing(fn ($state) => Str::upper($state))
->heading(__('project.label.singular')),

Column::make('full_name')
->formatStateUsing(fn ($state) => Str::upper($state))
->heading(__('donation.labels.full_name')),

Column::make('amount')
->heading(__('donation.labels.amount')),

Column::make('created_at')
->formatStateUsing(fn (Donation $record) => $record->created_at->toFormattedDateTime())
->heading(__('donation.labels.created_at')),

Column::make('updated_at')
->formatStateUsing(fn (Donation $record) => $record->updated_at?->toFormattedDateTime())
->heading(__('donation.labels.status_updated_at')),

Column::make('status')
->formatStateUsing(fn (Donation $record) => $record->status->label())
->heading(__('donation.labels.status')),

])
->queue(),
]);
} catch (\Throwable $exception) {
logger()->error($exception->getMessage());
Notification::make('export')
->title(__('notification.export.error.title'))
->body(__('notification.export.error.body'))
->danger()
->send();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class ListDonations extends ListRecords
protected function getActions(): array
{
return [
Actions\CreateAction::make(),
];
}

protected function getTableHeading(): string
{
return __('donation.header', ['number' => Donation::count()]);
}

}
Loading
Loading