fix and update v2 for operator
This commit is contained in:
70
app/Exports/V3/RoadObservation/OperatorCartableReport.php
Normal file
70
app/Exports/V3/RoadObservation/OperatorCartableReport.php
Normal 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 OperatorCartableReport implements FromView, ShouldAutoSize, WithEvents, WithDrawings
|
||||
{
|
||||
public function __construct(private ?Collection $data){}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
return view ("test", [
|
||||
'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('q1');
|
||||
return [$drawing, $drawing2];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard;
|
||||
use App\Exports\V3\RoadObservation\OperatorCartableReport;
|
||||
use App\Exports\V3\RoadObservation\SupervisorCartableReport;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\RoadObservation\VerifyBySupervisorRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\RoadObserved;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -15,42 +17,54 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class RoadObservationController extends Controller
|
||||
{
|
||||
public function supervisorIndex (Request $request,RoadObservationTableservice $roadObservationTableservice ): JsonResponse
|
||||
use ApiResponse;
|
||||
|
||||
public function supervisorindex (Request $request,RoadObservationTableservice $roadObservationTableservice ): JsonResponse
|
||||
{
|
||||
$data = $roadObservationTableservice-> supervisorCartableIndex($request);
|
||||
foreach ($data['data'] as &$roadItem) {
|
||||
$roadItem['can_supervise'] = Gate::allows('gate-supervise-road-item', $roadItem) ? 1 : 0;
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function verifyBySupervisor(VerifyBySupervisorRequest $request, RoadObserved $roadObserved): JsonResponse
|
||||
public function verifybysupervisor (VerifyBySupervisorRequest $request, RoadObserved $roadObserved): JsonResponse
|
||||
{
|
||||
$statusFa = $request->verify == 1 ? 'تایید شده' : 'عدم تایید';
|
||||
|
||||
$roadObserved->update([
|
||||
'status' => $request->verify,
|
||||
'status_fa' => $statusFa,
|
||||
'supervisor_id' => Auth::id(),
|
||||
'supervisor_name' => Auth::user()->name,
|
||||
'supervisor_description' => $request->description,
|
||||
'supervising_time' => now(),
|
||||
]);
|
||||
'status' => $request->verify,
|
||||
'status_fa' => $statusFa,
|
||||
'supervisor_id' => auth()->user()->id(),
|
||||
'supervisor_name' => auth()->user()->name,
|
||||
'supervisor_description' => $request->description,
|
||||
'supervising_time' => now(),
|
||||
]);
|
||||
|
||||
Auth::user()->addActivityComplete(1138);
|
||||
auth()->user()->addActivityComplete(1138);
|
||||
|
||||
return $this->successResponse(['status' => 'succeed']);
|
||||
|
||||
return response()->json(['status' => 'succeed']);
|
||||
}
|
||||
|
||||
|
||||
public function supervisorCartableReport (Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse
|
||||
public function supervisorcartablereport (Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse
|
||||
|
||||
{
|
||||
$name = 'گزارش از کارتابل ارزیابی واکنش سریع '. verta()->now()->format('Y-m-d') . '.xlsx';
|
||||
$name = 'گزارش از کارتابل ارزیابی واکنش سریع '. verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
$data = $roadObservationTableService->supervisorCartableIndex($request, true);
|
||||
|
||||
return Excel::download(new SupervisorCartableReport($data['data']), $name);
|
||||
}
|
||||
return Excel::download(new SupervisorCartableReport($data), $name);
|
||||
}
|
||||
|
||||
public function operatorindex(Request $request, RoadObservationTableService $roadObservationTableService): JsonResponse
|
||||
{
|
||||
$data = $roadObservationTableService->operatorCartableIndex($request);
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function operatorcartablereport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از کارتابل ارزیابی واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
$data = $roadObservationTableService->operatorCartableIndex($request);
|
||||
return Excel::download(new OperatorCartableReport($data), $name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Requests\V3\RoadObservation;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class VerifyBySupervisorRequest extends FormRequest
|
||||
{
|
||||
@@ -11,7 +12,7 @@ class VerifyBySupervisorRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
return Gate::allows('gate-supervise-road-observed');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,7 +23,7 @@ class VerifyBySupervisorRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{return [
|
||||
'verify' => ['required', 'in:1,2'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'description' => ['string'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,20 +3,83 @@
|
||||
namespace App\Services\Cartables;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\RoadObserved;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RoadObservationTableService
|
||||
{
|
||||
public function supervisorCartableIndex(Request $request, $loadRelations = false)
|
||||
use ApiResponse;
|
||||
public function supervisorCartableIndex(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$fields = [
|
||||
'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at',
|
||||
'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms',
|
||||
'rms_description', 'rms_status', 'rms_last_activity_fa', 'rms_last_activity',
|
||||
'road_observeds.province_id', 'province_fa', 'city_fa', 'edarate_shahri.name_fa',
|
||||
'status', 'status_fa', 'supervisor_description', 'supervising_time'
|
||||
];
|
||||
|
||||
|
||||
if ($user->hasPermissionTo('supervise-fast-react')) {
|
||||
$query = RoadObserved::query();
|
||||
$query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->whereNotNull('road_observeds.status');
|
||||
}
|
||||
elseif ($user->hasPermissionTo('supervise-fast-react-province') && $user->province_id) {
|
||||
$query = RoadObserved::where('province_id', $user->province_id);
|
||||
elseif ($user->hasPermissionTo('supervise-fast-react-province'))
|
||||
{
|
||||
if (is_null($user->province_id))
|
||||
{
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
|
||||
$query = RoadObserved::query()->leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->where('road_observeds.province_id', $user->province_id)
|
||||
->whereNotNull('road_observeds.status');
|
||||
}
|
||||
|
||||
return DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*']);
|
||||
}
|
||||
|
||||
public function operatorCartableIndex(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$fields = [
|
||||
'fk_RegisteredEventMessage', 'road_observeds.id', 'Title', 'road_observeds.created_at',
|
||||
'lat', 'lng', 'FeatureTypeTitle', 'Description', 'MobileForSendEventSms',
|
||||
'rms_description', 'rms_status', 'rms_start_latlng', 'rms_last_activity_fa',
|
||||
'rms_last_activity', 'road_observeds.province_id', 'province_fa', 'city_fa',
|
||||
'edarate_shahri.name_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time'
|
||||
];
|
||||
|
||||
$query = RoadObserved::query()
|
||||
->where('rms_status', '!=', 0)
|
||||
->whereNotNull('road_observeds.province_id')
|
||||
->whereNotNull('status')
|
||||
->leftJoin('edarate_shahri', 'road_observeds.edarate_shahri_id', '=', 'edarate_shahri.id')
|
||||
->select($fields)
|
||||
->addSelect([
|
||||
DB::raw("CONCAT('https://rms.rmto.ir/', image_before) as image_before"),
|
||||
DB::raw("CONCAT('https://rms.rmto.ir/', image_after) as image_after")
|
||||
]);
|
||||
|
||||
if ($user->hasPermissionTo('show-fast-react-province')) {
|
||||
if (is_null($user->province_id)) {
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
$query->where('rms_province_id', $user->province_id);
|
||||
} elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) {
|
||||
if (is_null($user->edarate_shahri_id)) {
|
||||
return $this->errorResponse('ادارهای برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
$query->where('edarate_shahri_id', $user->edarate_shahri_id);
|
||||
}
|
||||
|
||||
return DataTableFacade::run(
|
||||
|
||||
Reference in New Issue
Block a user