Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Oct 3, 2024
1 parent a2adec6 commit 45412f5
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 16 deletions.
35 changes: 35 additions & 0 deletions app/Exports/ReportExport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace App\Exports;

use App\Enums\Report\Type;
use App\Exports\Sheets\ReportCoverSheet;
use App\Exports\Sheets\ReportListSheet;
use App\Exports\Sheets\ReportStatisticSheet;
use App\Models\Report;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;

class ReportExport implements WithMultipleSheets
{
public readonly Report $report;

public function __construct(Report $report)
{
$this->report = $report;
}

public function sheets(): array
{
$sheet = match ($this->report->type) {
Type::LIST => ReportListSheet::class,
Type::STATISTIC => ReportStatisticSheet::class,
};

return $this->report->data
->map(fn (array $table) => new $sheet($table))
->prepend(new ReportCoverSheet($this->report))
->all();
}
}
35 changes: 35 additions & 0 deletions app/Exports/Sheets/ReportCoverSheet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace App\Exports\Sheets;

use App\Models\Report;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithTitle;

class ReportCoverSheet implements FromCollection, WithTitle
{
public Report $report;

public function __construct(Report $report)
{
$this->report = $report;
}

public function title(): string
{
return 'Cover';
}

public function collection(): Collection
{
return collect([
[__('report.column.category'), $this->report->category->label()],
[__('report.column.type'), $this->report->type->label()],
[__('report.column.period'), $this->report->period],
[__('report.column.created_at'), $this->report->created_at->toFormattedDateTime()],
]);
}
}
22 changes: 22 additions & 0 deletions app/Exports/Sheets/ReportListSheet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Exports\Sheets;

use Maatwebsite\Excel\Concerns\WithTitle;

class ReportListSheet implements WithTitle
{
public array $table;

public function __construct(array $table)
{
$this->table = $table;
}

public function title(): string
{
return data_get($this->table, 'title');
}
}
22 changes: 22 additions & 0 deletions app/Exports/Sheets/ReportStatisticSheet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Exports\Sheets;

use Maatwebsite\Excel\Concerns\WithTitle;

class ReportStatisticSheet implements WithTitle
{
public array $table;

public function __construct(array $table)
{
$this->table = $table;
}

public function title(): string
{
return data_get($this->table, 'title');
}
}
5 changes: 3 additions & 2 deletions app/Filament/Resources/ReportResource/Pages/ViewReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use App\Filament\Forms\Components\Value;
use App\Filament\Resources\ReportResource;
use Filament\Forms\Components\Group;
use Filament\Pages\Actions\Action;
use Filament\Pages\Actions\DeleteAction;
use Filament\Resources\Pages\ViewRecord;
use pxlrbt\FilamentExcel\Actions\Pages\ExportAction;

class ViewReport extends ViewRecord
{
Expand All @@ -20,7 +20,8 @@ class ViewReport extends ViewRecord
protected function getActions(): array
{
return [
Action::make('export')

ExportAction::make()
->label(__('report.action.export'))
->icon('heroicon-o-download')
->color('secondary'),
Expand Down
12 changes: 12 additions & 0 deletions app/Reports/Queries/General/G25.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,16 @@ public static function query(): Builder
return CommunityActivity::query()
->onlyCampaigns();
}

public static function dateColumn(): string
{
return 'activity_log.created_at';
}

public static function columns(): array
{
return [
//
];
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"laravel/sanctum": "^3.3",
"laravel/tinker": "^2.10",
"maatwebsite/excel": "^3.1",
"pxlrbt/filament-excel": "^1.1",
"saade/filament-fullcalendar": "^1.9",
"sentry/sentry-laravel": "^4.9",
"spatie/laravel-activitylog": "^4.8",
Expand Down
Loading

0 comments on commit 45412f5

Please sign in to comment.