Merge pull request #3 from witelgroup/feature/DriverAccident

change export for safty proivecy
This commit is contained in:
Amir Ghasempoor
2025-08-31 11:39:38 +03:30
committed by GitHub
17 changed files with 482 additions and 712 deletions

View File

@@ -21,30 +21,50 @@ class AccessRoadReport implements FromView, WithEvents, ShouldAutoSize, WithDraw
public function view(): View
{
$data = $this->data;
$existedProvinces = array_keys($data);
$axis = [
1 => 'آزادراه',
2 => 'بزرگراه',
3 => 'اصلی',
4 => 'فرعی',
5 => 'روستایی'
];
$grid = [];
$national = null;
foreach (Province::all() as $value) {
$provinceId = $value->id;
foreach ($this->data as $r) {
$pid = $r->province_id;
$name = $r->province_name;
$axisKey = $axis[$r->axis_type_id] ?? "axis_{$r->axis_type_id}";
if (!array_key_exists($provinceId, $existedProvinces)) {
$data[] = (object) [
'province_id' => $provinceId,
'name_fa' => $value->name_fa,
'sum' => 0,
'axis_data' => [
'آزادراه' => ['1' => 0, '2' => 0, '3' => 0],
'بزرگراه' => ['1' => 0, '2' => 0, '3' => 0],
'اصلی' => ['1' => 0, '2' => 0, '3' => 0],
'فرعی' => ['1' => 0, '2' => 0, '3' => 0],
'روستایی' => ['1' => 0, '2' => 0, '3' => 0],
],
];
if ($pid === -1) {
$national ??= ['province_name' => $name, 'total' => 0];
$national["{$axisKey}_1"] = $r->s1;
$national["{$axisKey}_2"] = $r->s2;
$national["{$axisKey}_3"] = $r->s3;
$national['total'] = $r->total_sum;
continue;
}
if (!isset($grid[$pid])) {
$grid[$pid] = ['province_name' => $name, 'total' => 0];
}
$grid[$pid]["{$axisKey}_1"] = $r->s1;
$grid[$pid]["{$axisKey}_2"] = $r->s2;
$grid[$pid]["{$axisKey}_3"] = $r->s3;
$grid[$pid]['total'] = $r->total_sum;
}
$exportRows = [];
if ($national) $exportRows[] = $national;
foreach ($grid as $row) {
$exportRows[] = $row;
}
return view('v3.Reports.SafetyAndPrivacy.Country.AccessRoadActivityReport', [
'data' => $data,
'rows' => $exportRows,
'axis' => $axis,
'axisOrder' => array_keys($axis),
]);
}

View File

@@ -2,18 +2,13 @@
namespace App\Exports\V3\SafetyAndPrivacy\Country;
use App\Models\EdarateShahri;
use App\Models\Province;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
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;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class ConstructionReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings
{
@@ -22,30 +17,50 @@ class ConstructionReport implements FromView, WithEvents, ShouldAutoSize, WithDr
public function view(): View
{
$data = $this->data;
$existedProvinces = array_keys($data);
$axis = [
1 => 'آزادراه',
2 => 'بزرگراه',
3 => 'اصلی',
4 => 'فرعی',
5 => 'روستایی'
];
$grid = [];
$national = null;
foreach (Province::all() as $value) {
$provinceId = $value->id;
foreach ($this->data as $r) {
$pid = $r->province_id;
$name = $r->province_name;
$axisKey = $axis[$r->axis_type_id] ?? "axis_{$r->axis_type_id}";
if (!array_key_exists($provinceId, $existedProvinces)) {
$data[] = (object) [
'province_id' => $provinceId,
'name_fa' => $value->name_fa,
'sum' => 0,
'axis_data' => [
'آزادراه' => ['1' => 0, '2' => 0, '3' => 0],
'بزرگراه' => ['1' => 0, '2' => 0, '3' => 0],
'اصلی' => ['1' => 0, '2' => 0, '3' => 0],
'فرعی' => ['1' => 0, '2' => 0, '3' => 0],
'روستایی' => ['1' => 0, '2' => 0, '3' => 0],
],
];
if ($pid === -1) {
$national ??= ['province_name' => $name, 'total' => 0];
$national["{$axisKey}_1"] = $r->s1;
$national["{$axisKey}_2"] = $r->s2;
$national["{$axisKey}_3"] = $r->s3;
$national['total'] = $r->total_sum;
continue;
}
if (!isset($grid[$pid])) {
$grid[$pid] = ['province_name' => $name, 'total' => 0];
}
$grid[$pid]["{$axisKey}_1"] = $r->s1;
$grid[$pid]["{$axisKey}_2"] = $r->s2;
$grid[$pid]["{$axisKey}_3"] = $r->s3;
$grid[$pid]['total'] = $r->total_sum;
}
$exportRows = [];
if ($national) $exportRows[] = $national;
foreach ($grid as $row) {
$exportRows[] = $row;
}
return view('v3.Reports.SafetyAndPrivacy.Country.ConstructionActivityReport', [
'data' => $data,
'rows' => $exportRows,
'axis' => $axis,
'axisOrder' => array_keys($axis),
]);
}

View File

@@ -22,30 +22,50 @@ class UtilityPassingReport implements FromView, WithEvents, ShouldAutoSize, With
public function view(): View
{
$data = $this->data;
$existedProvinces = array_keys($data);
$axis = [
1 => 'آزادراه',
2 => 'بزرگراه',
3 => 'اصلی',
4 => 'فرعی',
5 => 'روستایی'
];
$grid = [];
$national = null;
foreach (Province::all() as $value) {
$provinceId = $value->id;
foreach ($this->data as $r) {
$pid = $r->province_id;
$name = $r->province_name;
$axisKey = $axis[$r->axis_type_id] ?? "axis_{$r->axis_type_id}";
if (!array_key_exists($provinceId, $existedProvinces)) {
$data[] = (object) [
'province_id' => $provinceId,
'name_fa' => $value->name_fa,
'sum' => 0,
'axis_data' => [
'آزادراه' => ['1' => 0, '2' => 0, '3' => 0],
'بزرگراه' => ['1' => 0, '2' => 0, '3' => 0],
'اصلی' => ['1' => 0, '2' => 0, '3' => 0],
'فرعی' => ['1' => 0, '2' => 0, '3' => 0],
'روستایی' => ['1' => 0, '2' => 0, '3' => 0],
],
];
if ($pid === -1) {
$national ??= ['province_name' => $name, 'total' => 0];
$national["{$axisKey}_1"] = $r->s1;
$national["{$axisKey}_2"] = $r->s2;
$national["{$axisKey}_3"] = $r->s3;
$national['total'] = $r->total_sum;
continue;
}
if (!isset($grid[$pid])) {
$grid[$pid] = ['province_name' => $name, 'total' => 0];
}
$grid[$pid]["{$axisKey}_1"] = $r->s1;
$grid[$pid]["{$axisKey}_2"] = $r->s2;
$grid[$pid]["{$axisKey}_3"] = $r->s3;
$grid[$pid]['total'] = $r->total_sum;
}
$exportRows = [];
if ($national) $exportRows[] = $national;
foreach ($grid as $row) {
$exportRows[] = $row;
}
return view('v3.Reports.SafetyAndPrivacy.Country.UtilityPassingActivityReport', [
'data' => $data,
'rows' => $exportRows,
'axis' => $axis,
'axisOrder' => array_keys($axis),
]);
}

View File

@@ -16,35 +16,51 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class AccessRoadReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings
{
public function __construct(private array $data, public Request $request){}
public function __construct(private array $data){}
public function view(): View
{
$data = $this->data;
$existedCities = array_keys($data);
$edarat = EdarateShahri::query()->where('province_id', '=', $this->request->province_id)->get(['id', 'name_fa']);
$axis = [
1 => 'آزادراه',
2 => 'بزرگراه',
3 => 'اصلی',
4 => 'فرعی',
5 => 'روستایی'
];
$grid = [];
$summary = null; // کل استان
foreach ($edarat as $value) {
$edareId = $value->id;
foreach ($this->data as $r) {
$eid = $r->edare_id;
$name = $r->edare_name;
$axisKey = $axis[$r->axis_type_id] ?? "axis_{$r->axis_type_id}";
if (!array_key_exists($edareId, $existedCities)) {
$data[] = (object) [
'edare_shahri_id' => $edareId,
'name_fa' => $value->name_fa,
'sum' => 0,
'axis_data' => [
'آزادراه' => ['1' => 0, '2' => 0, '3' => 0],
'بزرگراه' => ['1' => 0, '2' => 0, '3' => 0],
'اصلی' => ['1' => 0, '2' => 0, '3' => 0],
'فرعی' => ['1' => 0, '2' => 0, '3' => 0],
'روستایی' => ['1' => 0, '2' => 0, '3' => 0],
],
];
if ($eid === -1) {
$summary ??= ['edare_name' => $name, 'total' => 0];
$summary["{$axisKey}_1"] = $r->s1;
$summary["{$axisKey}_2"] = $r->s2;
$summary["{$axisKey}_3"] = $r->s3;
$summary['total'] = $r->total_sum;
continue;
}
if (!isset($grid[$eid])) {
$grid[$eid] = ['edare_name' => $name, 'total' => 0];
}
$grid[$eid]["{$axisKey}_1"] = $r->s1;
$grid[$eid]["{$axisKey}_2"] = $r->s2;
$grid[$eid]["{$axisKey}_3"] = $r->s3;
$grid[$eid]['total'] = $r->total_sum;
}
$exportRows = [];
if ($summary) $exportRows[] = $summary;
foreach ($grid as $row) $exportRows[] = $row;
return view('v3.Reports.SafetyAndPrivacy.Province.AccessRoadActivityReport', [
'data' => $data,
'rows' => $exportRows,
'axis' => $axis,
'axisOrder' => array_keys($axis),
]);
}

View File

@@ -4,7 +4,6 @@ namespace App\Exports\V3\SafetyAndPrivacy\Province;
use App\Models\EdarateShahri;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
@@ -12,39 +11,54 @@ use Maatwebsite\Excel\Concerns\WithDrawings;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class ConstructionReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings
{
public function __construct(private array $data, public Request $request){}
public function __construct(private array $data){}
public function view(): View
{
$data = $this->data;
$existedCities = array_keys($data);
$edarat = EdarateShahri::query()->where('province_id', '=', $this->request->province_id)->get(['id', 'name_fa']);
$axis = [
1 => 'آزادراه',
2 => 'بزرگراه',
3 => 'اصلی',
4 => 'فرعی',
5 => 'روستایی'
];
$grid = [];
$summary = null; // کل استان
foreach ($edarat as $value) {
$edareId = $value->id;
foreach ($this->data as $r) {
$eid = $r->edare_id;
$name = $r->edare_name;
$axisKey = $axis[$r->axis_type_id] ?? "axis_{$r->axis_type_id}";
if (!array_key_exists($edareId, $existedCities)) {
$data[] = (object) [
'edare_shahri_id' => $edareId,
'name_fa' => $value->name_fa,
'sum' => 0,
'axis_data' => [
'آزادراه' => ['1' => 0, '2' => 0, '3' => 0],
'بزرگراه' => ['1' => 0, '2' => 0, '3' => 0],
'اصلی' => ['1' => 0, '2' => 0, '3' => 0],
'فرعی' => ['1' => 0, '2' => 0, '3' => 0],
'روستایی' => ['1' => 0, '2' => 0, '3' => 0],
],
];
if ($eid === -1) {
$summary ??= ['edare_name' => $name, 'total' => 0];
$summary["{$axisKey}_1"] = $r->s1;
$summary["{$axisKey}_2"] = $r->s2;
$summary["{$axisKey}_3"] = $r->s3;
$summary['total'] = $r->total_sum;
continue;
}
if (!isset($grid[$eid])) {
$grid[$eid] = ['edare_name' => $name, 'total' => 0];
}
$grid[$eid]["{$axisKey}_1"] = $r->s1;
$grid[$eid]["{$axisKey}_2"] = $r->s2;
$grid[$eid]["{$axisKey}_3"] = $r->s3;
$grid[$eid]['total'] = $r->total_sum;
}
$exportRows = [];
if ($summary) $exportRows[] = $summary;
foreach ($grid as $row) $exportRows[] = $row;
return view('v3.Reports.SafetyAndPrivacy.Province.ConstructionActivityReport', [
'data' => $data,
'rows' => $exportRows,
'axis' => $axis,
'axisOrder' => array_keys($axis),
]);
}

View File

@@ -16,35 +16,51 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class UtilityPassingReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings
{
public function __construct(private array $data, public Request $request){}
public function __construct(private array $data){}
public function view(): View
{
$data = $this->data;
$existedCities = array_keys($data);
$edarat = EdarateShahri::query()->where('province_id', '=', $this->request->province_id)->get(['id', 'name_fa']);
$axis = [
1 => 'آزادراه',
2 => 'بزرگراه',
3 => 'اصلی',
4 => 'فرعی',
5 => 'روستایی'
];
$grid = [];
$summary = null; // کل استان
foreach ($edarat as $value) {
$edareId = $value->id;
foreach ($this->data as $r) {
$eid = $r->edare_id;
$name = $r->edare_name;
$axisKey = $axis[$r->axis_type_id] ?? "axis_{$r->axis_type_id}";
if (!array_key_exists($edareId, $existedCities)) {
$data[] = (object) [
'edare_shahri_id' => $edareId,
'name_fa' => $value->name_fa,
'sum' => 0,
'axis_data' => [
'آزادراه' => ['1' => 0, '2' => 0, '3' => 0],
'بزرگراه' => ['1' => 0, '2' => 0, '3' => 0],
'اصلی' => ['1' => 0, '2' => 0, '3' => 0],
'فرعی' => ['1' => 0, '2' => 0, '3' => 0],
'روستایی' => ['1' => 0, '2' => 0, '3' => 0],
],
];
if ($eid === -1) {
$summary ??= ['edare_name' => $name, 'total' => 0];
$summary["{$axisKey}_1"] = $r->s1;
$summary["{$axisKey}_2"] = $r->s2;
$summary["{$axisKey}_3"] = $r->s3;
$summary['total'] = $r->total_sum;
continue;
}
if (!isset($grid[$eid])) {
$grid[$eid] = ['edare_name' => $name, 'total' => 0];
}
$grid[$eid]["{$axisKey}_1"] = $r->s1;
$grid[$eid]["{$axisKey}_2"] = $r->s2;
$grid[$eid]["{$axisKey}_3"] = $r->s3;
$grid[$eid]['total'] = $r->total_sum;
}
$exportRows = [];
if ($summary) $exportRows[] = $summary;
foreach ($grid as $row) $exportRows[] = $row;
return view('v3.Reports.SafetyAndPrivacy.Province.UtilityPassingActivityReport', [
'data' => $data,
'rows' => $exportRows,
'axis' => $axis,
'axisOrder' => array_keys($axis),
]);
}