diff --git a/app/Exports/V3/AccidentReceipt/CityReport.php b/app/Exports/V3/AccidentReceipt/CityReport.php
deleted file mode 100644
index db40c177..00000000
--- a/app/Exports/V3/AccidentReceipt/CityReport.php
+++ /dev/null
@@ -1,79 +0,0 @@
-data;
-
- return view('v3.AccidentReceipt.CityReport', [
- 'data' => $data['data'],
- 'fromDate' => $data['fromDate'],
- 'ToDate' => $data['ToDate'],
- ]);
- }
-
- /**
- * @return array
- */
- public function registerEvents(): array
- {
- return [
- AfterSheet::class => function (AfterSheet $event) {
- $event->sheet->getDelegate()->setRightToLeft(true);
- },
- ];
- }
-
- public function drawings()
- {
- $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('B1');
- return [$drawing, $drawing2];
- }
-
- public function styles(Worksheet $sheet)
- {
- return [
- // Style the first row as bold text.
- 'A:BA' => [
- 'font' => [
- 'name' => 'B Nazanin'
- ]
- ],
- ];
- }
-}
diff --git a/app/Exports/V3/AccidentReceipt/CountryReport.php b/app/Exports/V3/AccidentReceipt/CountryReport.php
new file mode 100644
index 00000000..e37c0386
--- /dev/null
+++ b/app/Exports/V3/AccidentReceipt/CountryReport.php
@@ -0,0 +1,123 @@
+data;
+
+ foreach (Province::all() as $province) {
+
+ $existingProvince = array_search($province->id, array_column($data['data'], 'province_id'));
+
+ if ($existingProvince) {
+ $activities[] = [
+ 'name' => $province->name_fa,
+ 'tedade' => $data['data'][$existingProvince]->tedade,
+ 'police_rah' => $data['data'][$existingProvince]->police_rah,
+ 'gozaresh_gasht' => $data['data'][$existingProvince]->gozaresh_gasht,
+ 'kol_sabt_shode' => $data['data'][$existingProvince]->kol_sabt_shode,
+ 'vasel_shode' => $data['data'][$existingProvince]->vasel_shode ?? 0,
+ 'vasel_shode_bimeh' => $data['data'][$existingProvince]->vasel_shode_bimeh ?? 0,
+ 'vasel_shode_daghi' => $data['data'][$existingProvince]->vasel_shode_daghi ?? 0,
+ 'vasel_shode_final' => $data['data'][$existingProvince]->vasel_shode_final ?? 0,
+ ];
+ } else {
+ $activities[] = [
+ 'name' => $province->name_fa,
+ 'tedade' => "",
+ 'police_rah' => "",
+ 'gozaresh_gasht' => "",
+ 'kol_sabt_shode' => "",
+ 'vasel_shode' => "",
+ 'vasel_shode_bimeh' => "",
+ 'vasel_shode_daghi' => "",
+ 'vasel_shode_final' => "",
+ ];
+ }
+ }
+
+ $activities[] = [
+ 'name' => 'کشوری',
+ 'tedade' => $data['data'][-1]->tedade,
+ 'police_rah' => $data['data'][-1]->police_rah,
+ 'gozaresh_gasht' => $data['data'][-1]->gozaresh_gasht,
+ 'kol_sabt_shode' => $data['data'][-1]->kol_sabt_shode,
+ 'vasel_shode' => $data['data'][-1]->vasel_shode ?? 0,
+ 'vasel_shode_bimeh' => $data['data'][-1]->vasel_shode_bimeh ?? 0,
+ 'vasel_shode_daghi' => $data['data'][-1]->vasel_shode_daghi ?? 0,
+ 'vasel_shode_final' => $data['data'][-1]->vasel_shode_final ?? 0,
+ ];
+
+ return view('v3.Reports.AccidentReceipt.CountryReport', [
+ 'data' => $activities,
+ 'fromDate' => $data['fromDate'],
+ 'toDate' => $data['toDate'],
+ ]);
+ }
+
+ /**
+ * @return array
+ */
+ 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('B1');
+ return [$drawing, $drawing2];
+ }
+
+ public function styles(Worksheet $sheet): array
+ {
+ return [
+ // Style the first row as bold text.
+ 'A:BA' => [
+ 'font' => [
+ 'name' => 'B Nazanin'
+ ]
+ ],
+ ];
+ }
+}
diff --git a/app/Exports/V3/AccidentReceipt/DataTableReport.php b/app/Exports/V3/AccidentReceipt/DataTableReport.php
index ba9bed37..4d6a0a5f 100644
--- a/app/Exports/V3/AccidentReceipt/DataTableReport.php
+++ b/app/Exports/V3/AccidentReceipt/DataTableReport.php
@@ -20,7 +20,7 @@ class DataTableReport implements FromView, ShouldAutoSize, WithEvents, WithDrawi
public function view(): View
{
- return view('v3.AccidentReceipt.DataTableReport', [
+ return view('v3.Reports.AccidentReceipt.DataTableReport', [
'data' => $this->data,
]);
}
diff --git a/app/Exports/V3/AccidentReceipt/ProvinceReport.php b/app/Exports/V3/AccidentReceipt/ProvinceReport.php
index 9eee4900..9339384b 100644
--- a/app/Exports/V3/AccidentReceipt/ProvinceReport.php
+++ b/app/Exports/V3/AccidentReceipt/ProvinceReport.php
@@ -20,11 +20,57 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithEvents, WithDrawin
public function view(): View
{
- $data = $this->data;
- return view('v3.AccidentReceipt.ProvinceReport', [
- 'data' => $data['data'],
- 'fromDate' => $data['fromDate'],
- 'ToDate' => $data['ToDate'],
+ $inputData = $this->data;
+ $reportData =$inputData['report'];
+
+ foreach ($inputData['cities'] as $city) {
+
+ $existingCity = array_search($city->id, array_column($inputData['data'], 'city_id'));
+
+ if ($existingCity) {
+ $activities[] = [
+ 'name' => $city->name_fa,
+ 'tedade' => $reportData['data'][$existingCity]->tedade,
+ 'police_rah' => $reportData['data'][$existingCity]->police_rah,
+ 'gozaresh_gasht' => $reportData['data'][$existingCity]->gozaresh_gasht,
+ 'kol_sabt_shode' => $reportData['data'][$existingCity]->kol_sabt_shode,
+ 'vasel_shode' => $reportData['data'][$existingCity]->vasel_shode ?? 0,
+ 'vasel_shode_bimeh' => $reportData['data'][$existingCity]->vasel_shode_bimeh ?? 0,
+ 'vasel_shode_daghi' => $reportData['data'][$existingCity]->vasel_shode_daghi ?? 0,
+ 'vasel_shode_final' => $reportData['data'][$existingCity]->vasel_shode_final ?? 0,
+ ];
+ } else {
+ $activities[] = [
+ 'name' => $city->name_fa,
+ 'tedade' => "",
+ 'police_rah' => "",
+ 'gozaresh_gasht' => "",
+ 'kol_sabt_shode' => "",
+ 'vasel_shode' => "",
+ 'vasel_shode_bimeh' => "",
+ 'vasel_shode_daghi' => "",
+ 'vasel_shode_final' => "",
+ ];
+ }
+ }
+
+ $activities[] = [
+ 'name' => 'استانی',
+ 'tedade' => $reportData['data'][-1]->tedade,
+ 'police_rah' => $reportData['data'][-1]->police_rah,
+ 'gozaresh_gasht' => $reportData['data'][-1]->gozaresh_gasht,
+ 'kol_sabt_shode' => $reportData['data'][-1]->kol_sabt_shode,
+ 'vasel_shode' => $reportData['data'][-1]->vasel_shode ?? 0,
+ 'vasel_shode_bimeh' => $reportData['data'][-1]->vasel_shode_bimeh ?? 0,
+ 'vasel_shode_daghi' => $reportData['data'][-1]->vasel_shode_daghi ?? 0,
+ 'vasel_shode_final' => $reportData['data'][-1]->vasel_shode_final ?? 0,
+ ];
+
+
+ return view('v3.Reports.AccidentReceipt.ProvinceReport', [
+ 'data' => $activities,
+ 'fromDate' => $reportData['fromDate'],
+ 'toDate' => $reportData['toDate'],
]);
}
diff --git a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php
index 9a589e11..9a31cdb2 100644
--- a/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php
+++ b/app/Http/Controllers/V3/Dashboard/AccidentReceiptController.php
@@ -44,7 +44,7 @@ class AccidentReceiptController extends Controller
{
auth()->user()->addActivityComplete(1126);
$name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
- $data = $accidentReceiptTableService->dataTable($request);
+ $data = $accidentReceiptTableService->dataTable($request, true);
return Excel::download(new DataTableReport($data), $name);
}
diff --git a/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php b/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php
index 1af76f3c..e9a29694 100644
--- a/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php
+++ b/app/Http/Controllers/V3/Dashboard/Reports/AccidentReceiptReportController.php
@@ -2,8 +2,8 @@
namespace App\Http\Controllers\V3\Dashboard\Reports;
-use App\Exports\V3\AccidentReceipt\CityReport;
use App\Exports\V3\AccidentReceipt\ProvinceReport;
+use App\Exports\V3\AccidentReceipt\CountryReport;
use App\Http\Controllers\Controller;
use App\Http\Traits\ApiResponse;
use App\Models\City;
@@ -18,18 +18,18 @@ class AccidentReceiptReportController extends Controller
{
use ApiResponse;
- public function provinceReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): JsonResponse
+ public function countryReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): JsonResponse
{
- $data = $accidentReceiptTableService->provinceReport($request);
+ $data = $accidentReceiptTableService->countryReport($request);
return $this->successResponse([
'activities' => $data['data'],
'provinces' => Province::all(['id', 'name_fa']),
]);
}
- public function cityReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): JsonResponse
+ public function provinceReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): JsonResponse
{
- $data = $accidentReceiptTableService->cityReport($request);
+ $data = $accidentReceiptTableService->provinceReport($request);
return $this->successResponse([
'activities' => $data['data'],
'cities' => City::query()->where('province_id', '=', $request->province_id)
@@ -38,17 +38,22 @@ class AccidentReceiptReportController extends Controller
]);
}
+ public function countryExcelReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): BinaryFileResponse
+ {
+ $data = $accidentReceiptTableService->countryReport($request);
+ $name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
+ return Excel::download(new CountryReport($data), $name);
+ }
+
public function provinceExcelReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): BinaryFileResponse
{
$data = $accidentReceiptTableService->provinceReport($request);
$name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
- return Excel::download(new ProvinceReport($data), $name);
- }
-
- public function cityExcelReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): BinaryFileResponse
- {
- $data = $accidentReceiptTableService->cityReport($request);
- $name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
- return Excel::download(new CityReport($data), $name);
+ return Excel::download(new ProvinceReport([
+ 'report' => $data,
+ 'cities' => City::query()->where('province_id', '=', $request->province_id)
+ ->where('type_id', '=', 1)
+ ->get(['id', 'name_fa']),
+ ]), $name);
}
}
diff --git a/app/Services/Cartables/AccidentReceiptTableService.php b/app/Services/Cartables/AccidentReceiptTableService.php
index 3a0ace1a..e757516f 100644
--- a/app/Services/Cartables/AccidentReceiptTableService.php
+++ b/app/Services/Cartables/AccidentReceiptTableService.php
@@ -12,20 +12,23 @@ class AccidentReceiptTableService
{
use ApiResponse;
- public function dataTable(Request $request)
+ public function dataTable(Request $request, $loadRelations = false)
{
$user = auth()->user();
$query = null;
if ($user->hasPermissionTo('show-receipt')) {
- $query = Accident::query();
+ $query = Accident::query()
+ ->when($loadRelations, fn ($query) => $query->with('damages'));
}
else {
if (is_null($user->province_id)) {
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
}
- $query = Accident::query()->where('province_id', '=', $user->province_id);
+ $query = Accident::query()
+ ->where('province_id', '=', $user->province_id)
+ ->when($loadRelations, fn ($query) => $query->with('damages'));
}
return DataTableFacade::run(
@@ -36,7 +39,7 @@ class AccidentReceiptTableService
);
}
- public function provinceReport(Request $request): array
+ public function countryReport(Request $request): array
{
$data = DB::select(
'SELECT
@@ -77,7 +80,7 @@ class AccidentReceiptTableService
];
}
- public function cityReport(Request $request): array
+ public function provinceReport(Request $request): array
{
$data = DB::select(
'SELECT
diff --git a/resources/views/v3/Reports/AccidentReceipt/CountryReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/CountryReport.blade.php
new file mode 100644
index 00000000..9ba1263b
--- /dev/null
+++ b/resources/views/v3/Reports/AccidentReceipt/CountryReport.blade.php
@@ -0,0 +1,108 @@
+
+
+
+
+
+
+
+ کشوری
+
+
+
+
+
+
+
+
+ |
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }}
+ |
+
+
+
+ |
+ |
+
+
+ |
+ گزارش خسارات وارده به ابنیه فنی و تاسیسات راه از تاریخ
+ {{ verta($fromDate)->format('Y/n/j') }}
+ تا
+ تاریخ
+ {{ verta($ToDate)->format('Y/n/j') }}
+
+ |
+
+
+
+
+ |
+ گزارش پلیس راه
+ |
+
+
+ گزارش گشت راهداری
+ |
+
+ بیمه
+ |
+
+ کسر داغی
+ |
+
+ شخص
+ |
+
+
+
+
+
+ @foreach ($data as $road)
+
+ |
+ {{ $road['name'] }} |
+
+ {{ $road['tedade'] }} |
+
+ {{ $road['police_rah'] }} |
+
+ {{ $road['gozaresh_gasht'] }} |
+
+ {{ $road['kol_sabt_shode'] }} |
+
+ {{ $road['vasel_shode'] }} |
+
+ {{ $road['vasel_shode_bimeh'] }} |
+
+ {{ $road['vasel_shode_daghi'] }} |
+
+ {{ $road['vasel_shode_final'] }} |
+
+ @endforeach
+
+
+
+
diff --git a/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php
new file mode 100644
index 00000000..024c9621
--- /dev/null
+++ b/resources/views/v3/Reports/AccidentReceipt/DataTableReport.blade.php
@@ -0,0 +1,82 @@
+
+
+
+
+
+
+ خسارات وارده به تفکیک استان
+
+
+
+
+
+ |
+ تاریخ دریافت گزارش: {{verta()->now()->format('Y/m/d H:i')}}
+ |
+
+
+ |
+
+
+ | گزارش کلی خسارات وارده |
+
+
+
+ | شناسه ثبت در سامانه RMS |
+ تاریخ ثبت در سامانه |
+ نام استان |
+ نام شهرستان |
+ تاریخ تصادف |
+ ساعت تصادف |
+
+ نوع خسارت |
+
+ نوع تجهیزات خسارت دیده |
+ مبلغ برآورد اولیه |
+ آخرین وضعیت |
+ مبلغ وصولی به حساب اداره |
+ میزان فرانشیز کسر شده |
+ میزان داغی تجهیزات خسارت دیده موجود انبار اداره |
+ مبلغ فیش |
+ مبلغ بیمه |
+ مبلغ داغی |
+
+
+
+
+ @foreach ($data as $item)
+
+ | {{$item->id}} |
+ {{Hekmatinasser\Verta\Verta::instance($item->created_at)->format('Y/n/j')}} |
+ {{$item->province_fa}} |
+ {{$item->city_fa}} |
+ {{Hekmatinasser\Verta\Verta::instance($item->accident_date)->format('Y/n/j')}} |
+ {{$item->accident_time}} |
+
+ {{$item->accident_type_fa}} |
+ @php
+ $temp = '';
+ @endphp
+ @foreach ($item->damages as $damage)
+ @php
+ $temp .= $damage->title." (".$damage->pivot->value." ".$damage->unit.") - ";
+ @endphp
+ @endforeach
+
+ {{$temp}} |
+
+
+ {{$item->sum ?? 0}} |
+ {{$item->status_fa}} |
+ {{$item->deposit_insurance_amount + $item->final_amount}} |
+ |
+ |
+ {{$item->final_amount}} |
+ {{$item->deposit_insurance_amount}} |
+ {{$item->deposit_daghi_amount}} |
+
+ @endforeach
+
+
+
+
diff --git a/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php b/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php
new file mode 100644
index 00000000..ae8d4da5
--- /dev/null
+++ b/resources/views/v3/Reports/AccidentReceipt/ProvinceReport.blade.php
@@ -0,0 +1,109 @@
+
+
+
+
+
+
+
+ استانی
+
+
+
+
+
+
+
+
+ |
+ تاریخ دریافت گزارش: {{ verta()->now()->format('Y/m/d H:i') }}
+ |
+
+
+
+ |
+ |
+
+
+ |
+ گزارش خسارات وارده به ابنیه فنی و تاسیسات راه از تاریخ
+ {{ verta($fromDate)->format('Y/n/j') }}
+ تا
+ تاریخ
+ {{ verta($toDate)->format('Y/n/j') }}
+
+ |
+
+
+
+
+
+ |
+ گزارش پلیس راه
+ |
+
+
+ گزارش گشت راهداری
+ |
+
+ بیمه
+ |
+
+ کسر داغی
+ |
+
+ شخص
+ |
+
+
+
+
+
+ @foreach ($data as $road)
+
+ |
+ {{ $road['name'] }} |
+
+ {{ $road['tedade'] }} |
+
+ {{ $road['police_rah'] }} |
+
+ {{ $road['gozaresh_gasht'] }} |
+
+ {{ $road['kol_sabt_shode'] }} |
+
+ {{ $road['vasel_shode'] }} |
+
+ {{ $road['vasel_shode_bimeh'] }} |
+
+ {{ $road['vasel_shode_daghi'] }} |
+
+ {{ $road['vasel_shode_final'] }} |
+
+ @endforeach
+
+
+
+
diff --git a/routes/v3.php b/routes/v3.php
index 759900bc..7c68023c 100644
--- a/routes/v3.php
+++ b/routes/v3.php
@@ -270,8 +270,8 @@ Route::prefix('receipt_reports')
->name('receiptReports.')
->controller(AccidentReceiptReportController::class)
->group(function () {
+ Route::get('/country_report', 'countryReport')->name('countryReport');
Route::get('/province_report', 'provinceReport')->name('provinceReport');
- Route::get('/city_report', 'cityReport')->name('cityReport');
+ Route::get('/country_excel_report', 'countryExcelReport')->name('countryExcelReport');
Route::get('/province_excel_report', 'provinceExcelReport')->name('provinceExcelReport');
- Route::get('/city_excel_report', 'cityExcelReport')->name('cityExcelReport');
});