-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
277 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.