96 lines
2.6 KiB
PHP
96 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Exports\V3\Mission\Report;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
use Maatwebsite\Excel\Concerns\FromView;
|
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
|
use Maatwebsite\Excel\Concerns\WithDrawings;
|
|
use Maatwebsite\Excel\Concerns\WithEvents;
|
|
use Maatwebsite\Excel\Events\AfterSheet;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
|
|
|
class CountryReport implements FromView, ShouldAutoSize, WithDrawings, WithEvents
|
|
{
|
|
public function __construct(private array $data)
|
|
{
|
|
}
|
|
|
|
public function view(): View
|
|
{
|
|
$grid = [];
|
|
$national = null;
|
|
|
|
foreach ($this->data as $r) {
|
|
$pid = (int) $r->province_id;
|
|
$name = $r->province_name;
|
|
|
|
if ($pid === -1) {
|
|
$national = [
|
|
'province_name' => $name,
|
|
'no_mission_count' => (int) ($r->no_mission_count ?? 0),
|
|
'out_of_area_count' => (int) ($r->out_of_area_count ?? 0),
|
|
];
|
|
|
|
continue;
|
|
}
|
|
|
|
if (! isset($grid[$pid])) {
|
|
$grid[$pid] = [
|
|
'province_name' => $name,
|
|
];
|
|
}
|
|
|
|
$grid[$pid]['no_mission_count'] = (int) ($r->no_mission_count ?? 0);
|
|
$grid[$pid]['out_of_area_count'] = (int) ($r->out_of_area_count ?? 0);
|
|
|
|
}
|
|
|
|
$exportRows = [];
|
|
if ($national) {
|
|
$exportRows[] = $national;
|
|
}
|
|
foreach ($grid as $row) {
|
|
$exportRows[] = $row;
|
|
}
|
|
|
|
return view('v3.Reports.Mission.Report.CountryActivityReport', [
|
|
'rows' => $exportRows,
|
|
]);
|
|
}
|
|
|
|
public function registerEvents(): array
|
|
{
|
|
return [
|
|
AfterSheet::class => function (AfterSheet $event) {
|
|
$event->sheet->getDelegate()->setRightToLeft(true);
|
|
},
|
|
];
|
|
}
|
|
|
|
public function drawings(): array
|
|
{
|
|
$drawing = new Drawing();
|
|
$drawing->setName('Logo');
|
|
$drawing->setDescription('This is my logo');
|
|
$drawing->setPath(public_path('/dist/logo.png'));
|
|
$drawing->setWidth(50);
|
|
$drawing->setHeight(50);
|
|
$drawing->setOffsetX(5);
|
|
$drawing->setOffsetY(5);
|
|
$drawing->setCoordinates('A1');
|
|
|
|
$drawing2 = new Drawing();
|
|
$drawing2->setName('Logo');
|
|
$drawing2->setDescription('This is my logo');
|
|
$drawing2->setPath(public_path('/dist/141icon.png'));
|
|
$drawing2->setWidth(50);
|
|
$drawing2->setHeight(50);
|
|
$drawing2->setOffsetX(5);
|
|
$drawing2->setOffsetY(5);
|
|
$drawing2->setCoordinates('C1');
|
|
|
|
return [$drawing, $drawing2];
|
|
}
|
|
}
|