create blade excel files
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\V3\AccidentReceipt;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Concerns\WithDrawings;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class CityReport implements FromView, ShouldAutoSize, WithEvents, WithDrawings, WithStyles
|
||||
{
|
||||
public function __construct(private array $data){}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
$data = $this->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'
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
123
app/Exports/V3/AccidentReceipt/CountryReport.php
Normal file
123
app/Exports/V3/AccidentReceipt/CountryReport.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\V3\AccidentReceipt;
|
||||
|
||||
use App\Models\Province;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Concerns\WithDrawings;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class CountryReport implements FromView, ShouldAutoSize, WithEvents, WithDrawings, WithStyles
|
||||
{
|
||||
public function __construct(private array $data){}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
$data = $this->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'
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -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'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user