create blade file for report

This commit is contained in:
2025-03-02 10:11:13 +03:30
parent cb91f469f8
commit a65ec5e2bd
4 changed files with 246 additions and 36 deletions

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Exports\V3\SafetyAndPrivacy;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
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 CartableReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings
{
public function __construct(private ?Collection $data){}
public function view(): View
{
return view('v3.Reports.SafetyAndPrivacy.CartableReport', [
'data' => $this->data,
]);
}
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 [
'A:BA' => [
'font' => [
'name' => 'B Nazanin'
]
],
];
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers\V3\Dashboard;
use App\Exports\V3\SafetyAndPrivacy\CartableReport;
use App\Facades\File\FileFacade;
use App\Http\Controllers\Controller;
use App\Http\Requests\V3\SafetyAndPrivacy\FirstStepStoreRequest;
@@ -18,6 +19,8 @@ use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Maatwebsite\Excel\Facades\Excel;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class SafetyAndPrivacyController extends Controller
{
@@ -28,15 +31,22 @@ class SafetyAndPrivacyController extends Controller
return response()->json($safetyAndPrivacyTableService->datatable($request));
}
public function excelReport(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse
{
$name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
$data = $safetyAndPrivacyTableService->datatable($request);
return Excel::download(new CartableReport($data['data']), $name);
}
public function firstStepStore(FirstStepStoreRequest $request, NominatimService $nominatimService): JsonResponse
{
$user = auth()->user();
if (auth()->user()->edarate_ostani_id || is_null(auth()->user()->city_id)) {
if ($user->edarate_ostani_id || is_null($user->city_id)) {
return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!');
}
if (is_null(auth()->user()->edarate_shahri_id)) {
if (is_null($user->edarate_shahri_id)) {
return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!');
}
@@ -46,84 +56,90 @@ class SafetyAndPrivacyController extends Controller
->where('item', 17)
->firstOrFail();
DB::transaction(function () use ($request, $coordinates, $item, $nominatimService)
DB::transaction(function () use ($request, $coordinates, $item, $nominatimService, $user)
{
$safety_and_privacy = SafetyAndPrivacy::query()->create([
'lat' => $coordinates[0],
'lon' => $coordinates[1],
'operator_id' => auth()->user()->id,
'operator_name' => auth()->user()->name,
'province_id' => auth()->user()->province_id,
'province_fa' => auth()->user()->province_fa,
'operator_id' => $user->id,
'operator_name' => $user->name,
'province_id' => $user->province_id,
'province_fa' => $user->province_fa,
'info_id' => $item->id,
'info_fa' => $item->sub_item_str,
'city_id' => auth()->user()->city_id,
'city_fa' => auth()->user()->city_fa,
'city_id' => $user->city_id,
'city_fa' => $user->city_fa,
'activity_date_time' => $request->activity_date." ".$request->activity_time,
'edare_shahri_id' => auth()->user()->edarate_shahri_id,
'edare_shahri_name' => auth()->user()->edarate_shahri_name,
'edare_shahri_id' => $user->edarate_shahri_id,
'edare_shahri_name' => $user->edarate_shahri_name,
'way_id' => $nominatimService->get_way_id_from_nominatim($coordinates[0], $coordinates[1]),
'recognize_picture' => $request->has('recognize_picture') ? FileFacade::save($request->recognize_picture, 'safety_and_privacy') : null,
'step' => 1,
'step_fa' => 'گام اول (شناسایی)'
]);
auth()->user()->addActivityComplete(1134);
$safety_and_privacy->recognize_picture = $request->has('recognize_picture') ?
FileFacade::save($request->recognize_picture, "safety_and_privacy/{$safety_and_privacy->id}") :
null;
$safety_and_privacy->save();
$user->addActivityComplete(1134);
});
return $this->successResponse();
}
public function secondStepStore(SecondStepStoreRequest $safety_and_privacy, Request $request): JsonResponse
public function secondStepStore(SafetyAndPrivacy $safety_and_privacy, SecondStepStoreRequest $request): JsonResponse
{
$user = auth()->user();
if (auth()->user()->edarate_ostani_id || is_null(auth()->user()->city_id)) {
if ($user->edarate_ostani_id || is_null($user->city_id)) {
return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!');
}
if (is_null(auth()->user()->edarate_shahri_id)) {
if (is_null($user->edarate_shahri_id)) {
return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!');
}
DB::transaction(function () use ($request, $safety_and_privacy)
DB::transaction(function () use ($request, $safety_and_privacy, $user)
{
$judiciary_document = [];
foreach ($request->judiciary_document as $index => $item) {
$judiciary_document[] = $item->store('safety_and_privacy/'.$safety_and_privacy->id.'/judiciary_document', 'public');
foreach ($request->judiciary_document as $index => $file) {
$judiciary_document[] = FileFacade::save($file, "safety_and_privacy/{$safety_and_privacy->id}/judiciary_document");
}
$safety_and_privacy->judiciary_document = serialize($judiciary_document);
$safety_and_privacy->judiciary_document_upload_date = now();
$safety_and_privacy->update([
'judiciary_document' => serialize($judiciary_document),
'judiciary_document_upload_date' => now(),
'step' => 2,
'step_fa' => 'گام دوم (مستندات قضایی)'
]);
$safety_and_privacy->goToSecondStep();
$safety_and_privacy->save();
auth()->user()->addActivityComplete(1135);
$user->addActivityComplete(1135);
});
return $this->successResponse();
}
public function thirdStepStore(ThirdStepStoreRequest $safety_and_privacy, Request $request): JsonResponse
public function thirdStepStore(SafetyAndPrivacy $safety_and_privacy, ThirdStepStoreRequest $request): JsonResponse
{
$user = auth()->user();
if (auth()->user()->edarate_ostani_id || is_null(auth()->user()->city_id)) {
if ($user->edarate_ostani_id || is_null($user->city_id)) {
return $this->errorResponse('امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!');
}
if (is_null(auth()->user()->edarate_shahri_id)) {
if (is_null($user->edarate_shahri_id)) {
return $this->errorResponse('اداره شهری برای شما در سامانه ثبت نشده است!');
}
DB::transaction(function () use ($request, $safety_and_privacy) {
$action_picture = $request->file('action_picture')->store('safety_and_privacy/'.$safety_and_privacy->id.'/action_picture', 'public');
$safety_and_privacy->action_picture = Storage::disk('public')->url($action_picture);
$safety_and_privacy->action_picture_document_upload_date = now();
DB::transaction(function () use ($request, $safety_and_privacy, $user) {
$safety_and_privacy->update([
'step' => 3,
'step_fa' => 'گام سوم (برخورد)',
'action_picture' => FileFacade::save($request->action_picture, "safety_and_privacy/{$safety_and_privacy->id}/action_picture"),
'action_picture_document_upload_date' => now(),
]);
$safety_and_privacy->goToThirdStep();
$safety_and_privacy->save();
auth()->user()->addActivityComplete(1136);
$user->addActivityComplete(1136);
});
return $this->successResponse();
@@ -136,7 +152,7 @@ class SafetyAndPrivacyController extends Controller
public function destroy(SafetyAndPrivacy $safetyAndPrivacy): JsonResponse
{
Storage::deleteDirectory('public/' . 'safety_and_privacy/' . $safetyAndPrivacy->id);
Storage::deleteDirectory("public/safety_and_privacy/{$safetyAndPrivacy->id}");
DB::transaction(function () use ($safetyAndPrivacy)
{

View File

@@ -2,9 +2,11 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Traits\SafetyAndPrivacyReportAble;
use Illuminate\Support\Facades\Storage;
class SafetyAndPrivacy extends Model
{
@@ -60,4 +62,23 @@ class SafetyAndPrivacy extends Model
}
}
protected function recognizePicture(): Attribute
{
return Attribute::make(
get: fn($value) => $value == null ? null :
(filter_var($value, FILTER_VALIDATE_URL)
? $value
: Storage::disk('public')->url($value))
);
}
protected function actionPicture(): Attribute
{
return Attribute::make(
get: fn($value) => $value == null ? null :
(filter_var($value, FILTER_VALIDATE_URL)
? $value
: Storage::disk('public')->url($value))
);
}
}

View File

@@ -0,0 +1,104 @@
<!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="9"
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="9"
style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;">
</th>
</tr>
<tr>
<th colspan="9"
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>
</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['province_fa'] ?? '-' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['edare_shahri_name'] ?? '-' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['info_fa'] ?? '-' }}</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['activity_date_time'] ? verta($item['activity_date_time'])->format('Y/n/j H:i:s') : '-' }}</td>
<td style="border: 1px solid black;text-align: center;">
{{ $item['judiciary_document_upload_date'] && $item['judiciary_document_upload_date'] != '0000-00-00 00:00:00' ? verta($item['judiciary_document_upload_date'])->format('Y/n/j H:i:s') : '-' }}
</td>
<td style="border: 1px solid black;text-align: center;">
{{ $item['action_picture_document_upload_date'] ? verta($item['action_picture_document_upload_date'])->format('Y/n/j H:i:s') : '-' }}
</td>
<td style="border: 1px solid black;text-align: center;">{{ $item['step_fa'] ?? '-' }}</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>