create report cartable and excel for road observation

This commit is contained in:
2025-09-21 17:28:01 +03:30
parent 1b7e26517a
commit 20dac942a0
8 changed files with 418 additions and 3 deletions

View File

@@ -0,0 +1,70 @@
<?php
namespace App\Exports\V3\RoadObservation;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
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\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
class CountryCartableReport implements FromView, ShouldAutoSize, WithEvents, WithDrawings
{
public function __construct(private Collection $data){}
public function view(): View
{
return view('v3.Reports.RoadObservation.CountryReport', [
'data' => $this->data,
]);
}
public function registerEvents(): array
{
return [
AfterSheet::class => function (AfterSheet $event) {
$event->sheet->getDelegate()->setRightToLeft(true);
$event->sheet->getDelegate()->getStyle('A:U')->getFont()->setName('Arial');
$event->sheet->getDelegate()->getStyle('A:U')
->getAlignment()
->setHorizontal(Alignment::HORIZONTAL_CENTER);
$event->sheet->getDelegate()->getStyle('A:U')
->getAlignment()
->setVertical(Alignment::VERTICAL_CENTER);
}
];
}
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('j1');
return [$drawing, $drawing2];
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace App\Exports\V3\RoadObservation;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
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\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
class ProvinceCartableReport implements FromView, ShouldAutoSize, WithEvents, WithDrawings
{
public function __construct(private Collection $data){}
public function view(): View
{
return view('v3.Reports.RoadObservation.ProvinceReport', [
'data' => $this->data,
]);
}
public function registerEvents(): array
{
return [
AfterSheet::class => function (AfterSheet $event) {
$event->sheet->getDelegate()->setRightToLeft(true);
$event->sheet->getDelegate()->getStyle('A:U')->getFont()->setName('Arial');
$event->sheet->getDelegate()->getStyle('A:U')
->getAlignment()
->setHorizontal(Alignment::HORIZONTAL_CENTER);
$event->sheet->getDelegate()->getStyle('A:U')
->getAlignment()
->setVertical(Alignment::VERTICAL_CENTER);
}
];
}
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('j1');
return [$drawing, $drawing2];
}
}

View File

@@ -3,13 +3,18 @@
namespace App\Http\Controllers\V3\Dashboard\RoadObservation;
use App\Exports\V2\RoadObservation\ReportComplaintsExport;
use App\Exports\V3\SafetyAndPrivacy\Country\AccessRoadReport as ExcelReport;
use App\Exports\V3\SafetyAndPrivacy\Province\AccessRoadReport;
use App\Facades\DataTable\DataTableFacade;
use App\Http\Traits\ApiResponse;
use App\Models\EdarateShahri;
use App\Models\RoadObserved;
use App\Services\Cartables\RoadObservation\ReportService;
use App\Services\Cartables\SafetyAndPrivacy\OperatorService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use PhpOffice\PhpSpreadsheet\Exception;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class ReportController
@@ -39,4 +44,39 @@ class ReportController
allowedSelects: ['id', 'lat', 'lng', 'status']
));
}
}
public function countryActivity(Request $request, ReportService $reportService): JsonResponse
{
$data = $reportService->countryActivity($request);
return response()->json($data['data']);
}
public function provinceActivity(Request $request, ReportService $reportService): JsonResponse
{
$data = $reportService->provinceActivity(
province_id: $request->input('province_id')
);
return $this->successResponse([
'activities' => $data,
'edarateShahri' => EdarateShahri::where('province_id', $request->province_id)->get(['id', 'name_fa']),
]);
}
public function countryActivityExcel(Request $request, OperatorService $operatorService): BinaryFileResponse
{
$data = $operatorService->countryActivity();
$name = 'گزارش رسیدگی به شکایات واکنش سریع' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
return Excel::download(new ReportComplaintsExport($data), $name);
}
public function provinceActivityExcel(Request $request, OperatorService $operatorService): BinaryFileResponse
{
$data = $operatorService->provinceActivity(
province_id: $request->input('province_id')
);
$name = 'گزارش رسیدگی به شکایات واکنش سریع' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
return Excel::download(new AccessRoadReport($data, $request), $name);
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Services\Cartables\RoadObservation;
use App\Facades\DataTable\DataTableFacade;
use App\Models\RoadObserved;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ReportService
{
@@ -50,4 +51,94 @@ class ReportService
'toDate' => $toDate,
];
}
public function countryActivity(Request $request): array
{
return DB::select("
SELECT
p.id AS province_id,
p.name_fa AS province_name,
SUM(t.rms_status = 0 ) AS residegiShode,
SUM(t.rms_status = 1 ) AS egdamshode,
SUM(t.rms_status = 2) AS egdamnashodeh,
SUM(t.status = 0 ) AS darhalbarasi,
SUM(t.status = 1 ) AS taayidshode,
SUM(t.status = 2 ) AS adamtaayid,
SUM(t.rms_status = 0 ) + SUM(t.rms_status = 1) + SUM(t.rms_status = 2) AS total
FROM
provinces p
LEFT JOIN
road_observeds t ON t.province_id = p.id
GROUP BY
p.id, p.name_fa
UNION ALL
SELECT
-1 AS province_id,
'کل کشور' AS province_name,
SUM(t.rms_status = 0 ) AS residegiShode,
SUM(t.rms_status = 1 ) AS egdamshode,
SUM(t.rms_status = 2) AS egdamnashodeh,
SUM(t.status = 0 ) AS darhalbarasi,
SUM(t.status = 1 ) AS taayidshode,
SUM(t.status = 2 ) AS adamtaayid,
SUM(t.rms_status = 0 ) + SUM(t.rms_status = 1) + SUM(t.rms_status = 2) AS total
FROM
provinces p
LEFT JOIN
road_observeds t ON t.province_id = p.id
ORDER BY
province_id
");
}
public function provinceActivity(int $province_id): array
{
return DB::select("
SELECT
e.id AS edare_id,
e.name_fa AS edare_name,
COALESCE(SUM(t.rms_status = 0 ),0) AS residegiShode,
COALESCE(SUM(t.rms_status = 1),0) AS egdamshode,
COALESCE(SUM(t.rms_status = 2),0) AS egdamnashodeh,
COALESCE(SUM(t.status = 0 ),0) AS darhalbarasi,
COALESCE(SUM(t.status = 1 ),0) AS taayidshode,
COALESCE(SUM(t.status = 2 ),0) AS adamtaayid,
COALESCE(SUM(t.rms_status = 0 ) + SUM(t.rms_status = 1) + SUM(t.rms_status = 2),0)AS total
FROM
edarate_shahri e
LEFT JOIN
road_observeds t ON t.edarate_shahri_id = e.id AND t.province_id = e.province_id
WHERE
e.province_id = :provinceId
GROUP BY
e.id, e.name_fa
UNION ALL
SELECT
-1 AS edare_id,
'کل استان' AS edare_name,
COALESCE(SUM(t.rms_status = 0 ),0) AS residegiShode,
COALESCE(SUM(t.rms_status = 1),0) AS egdamshode,
COALESCE(SUM(t.rms_status = 2),0) AS egdamnashodeh,
COALESCE(SUM(t.status = 0 ),0) AS darhalbarasi,
COALESCE(SUM(t.status = 1 ),0) AS taayidshode,
COALESCE(SUM(t.status = 2 ),0) AS adamtaayid,
COALESCE(SUM(t.rms_status = 0 ) + SUM(t.rms_status = 1) + SUM(t.rms_status = 2),0)AS total
FROM
edarate_shahri e
LEFT JOIN
road_observeds t ON t.edarate_shahri_id = e.id AND t.province_id = e.province_id
WHERE
e.province_id = :provinceId
ORDER BY
edare_id
", [
'provinceId' => $province_id,
]);
}
}

View File

@@ -12,7 +12,7 @@ return new class extends Migration
public function up(): void
{
Schema::table('road_items_projects', function (Blueprint $table) {
$table->foreignId('mission_id')->nullable()->constrained('missions');
$table->unsignedBigInteger('mission_id')->nullable();
});
}
@@ -22,7 +22,6 @@ return new class extends Migration
public function down(): void
{
Schema::table('road_items_projects', function (Blueprint $table) {
$table->dropForeign('road_items_projects_mission_id_foreign');
$table->dropColumn('mission_id');
});
}

View File

@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>گزارش واکنش سریع</title>
<style>
table,
th,
td {
border: 1px solid black;
}
</style>
</head>
<body dir="rtl" style="text-align: center;">
<table>
<thead>
<tr>
<th colspan="10"
style="background-color: #DAEEF3;text-align: center;border-right: 1px solid black;font-weight:bolder;">
تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }}
</th>
</tr>
<tr>
<th colspan="10"
style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;">
</th>
</tr>
<tr>
<th colspan="10"
style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13px;">
گزارش رسیدگی به شکایات واکنش سریع
</th>
</tr>
<tr>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">کد یکتا</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">رسیدگی نشده</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">اقدام شده</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;"> اقدام نشده </th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">درحال بررسی</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">تائید شده</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">عدم تائید</th>
</tr>
</thead>
<tbody>
@foreach ($data as $item)
<tr>
<td style="border: 1px solid black;text-align: center;">{{ $item['id'] ?? '-' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['rms_status'] ?? '0' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['rms_status'] ?? '1' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['rms_status'] ?? '2' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['status'] ?? '0' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['status'] ?? '1' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['status'] ?? '2' }}</td>
</tr>
@endforeach
</tbody>
</table>
</body>
</html>

View File

@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>گزارش واکنش سریع</title>
<style>
table,
th,
td {
border: 1px solid black;
}
</style>
</head>
<body dir="rtl" style="text-align: center;">
<table>
<thead>
<tr>
<th colspan="10"
style="background-color: #DAEEF3;text-align: center;border-right: 1px solid black;font-weight:bolder;">
تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }}
</th>
</tr>
<tr>
<th colspan="10"
style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;">
</th>
</tr>
<tr>
<th colspan="10"
style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13px;">
گزارش رسیدگی به شکایات واکنش سریع
</th>
</tr>
<tr>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">کد یکتا</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">کد سوانح</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">استان</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">اداره</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">موضوع گزارش</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">نوع گزارش</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">توضیح گزارش</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">موقعیت مکانی</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">شماره تماس گیرنده</th>
<th rowspan="1" style="text-align: center;border: 1px solid black;background-color: #EBF1DE;font-weight: bold;">تاریخ ثبت</th>
</tr>
</thead>
<tbody>
@foreach ($data as $item)
<tr>
<td style="border: 1px solid black;text-align: center;">{{ $item['id'] ?? '-' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['fk_RegisteredEventMessage'] ?? '-' }}</td>
<td>{{ $item['province_fa'] ?? '-' }}</td>
<td>{{ $item['edarate_shahri_name_fa'] ?? '-' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['Title'] ?? '-' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['FeatureTypeTitle'] ?? '-' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['Description'] ?? '-' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ isset($item['lat']) && isset($item['lng']) ? $item['lat'] . ' ' . $item['lng'] : '-' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['MobileForSendEventSms'] ?? '-' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['created_at'] ? verta($item['created_at'])->format('Y/n/j H:i:s') : '-' }}</td>
</tr>
@endforeach
</tbody>
</table>
</body>
</html>

View File

@@ -351,6 +351,10 @@ Route::prefix('road_observations')
Route::get('/index', 'index')->name('index')->middleware('permission:show-fast-react-province|show-fast-react');
Route::get('/excel', 'excel')->name('excel')->middleware('permission:show-fast-react-province|show-fast-react');
Route::get('/map', 'map')->name('map');
Route::get('/country_activity', 'countryActivity')->name('countryActivity');
Route::get('/province_activity', 'provinceActivity')->name('provinceActivity');
Route::get('/country_activity_excels', 'countryActivityExcel')->name('countryExcelActivity');
Route::get('/province_activity_excel', 'provinceActivityExcel')->name('provinceExcelActivity');
});
});