fix the directory structure
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Azmayesh;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\Azmayesh\StoreRequest;
|
||||
use App\Http\Requests\V3\Azmayesh\UpdateRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Azmayesh;
|
||||
use App\Models\AzmayeshType;
|
||||
use App\Models\Province;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AzmayeshController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$columns = array(
|
||||
'id',
|
||||
'request_date',
|
||||
'report_date',
|
||||
'request_number',
|
||||
'employer',
|
||||
'contractor',
|
||||
'work_number',
|
||||
'consultant',
|
||||
'applicant',
|
||||
'azmayesh_type_name',
|
||||
'project_name',
|
||||
'updated_at',
|
||||
'created_at',
|
||||
'user_name',
|
||||
'contract_subitem_id'
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$query = Azmayesh::query();
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(StoreRequest $request): JsonResponse
|
||||
{
|
||||
$azmayeshType = AzmayeshType::query()->findOrFail($request->azmayesh_type_id);
|
||||
$province = Province::query()->findOrFail($request->province_id);
|
||||
$user = auth()->user();
|
||||
|
||||
Azmayesh::query()->create([
|
||||
'lat' => $request->lat,
|
||||
'lng' => $request->lng,
|
||||
'azmayesh_type_id' => $azmayeshType->id,
|
||||
'azmayesh_type_name' => $azmayeshType->name,
|
||||
'request_date' => $request->request_date,
|
||||
'report_date' => $request->report_date,
|
||||
'request_number' => $request->request_number ?? '-',
|
||||
'employer' => $request->employer ?? '-',
|
||||
'contractor' => $request->contractor ?? '-',
|
||||
'work_number' => $request->work_number ?? '-',
|
||||
'project_name' => $request->project_name,
|
||||
'consultant' => $request->consultant ?? '-',
|
||||
'applicant' => $request->applicant ?? '-',
|
||||
'province_id' => $province->id,
|
||||
'province_name' => $province->name_fa,
|
||||
'user_id' => $user->id,
|
||||
'user_name' => $user->name,
|
||||
'contract_subitem_id' => $request->contract_subitem_id
|
||||
]);
|
||||
|
||||
$user->addActivityComplete(1158);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Azmayesh $azmayesh): JsonResponse
|
||||
{
|
||||
return $this->successResponse($azmayesh->load('azmayeshSamples'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(UpdateRequest $request, Azmayesh $azmayesh): JsonResponse
|
||||
{
|
||||
$province = Province::query()->findOrFail($request->province_id);
|
||||
$azmayeshType = AzmayeshType::query()->findOrFail($request->azmayesh_type_id);
|
||||
|
||||
$azmayesh->update([
|
||||
'lat' => $request->lat,
|
||||
'lng' => $request->lng,
|
||||
'azmayesh_type_id' => $azmayeshType->id,
|
||||
'azmayesh_type_name' => $azmayeshType->name,
|
||||
'request_date' => $request->request_date,
|
||||
'report_date' => $request->report_date,
|
||||
'request_number' => $request->request_number ?? '-',
|
||||
'employer' => $request->employer ?? '-',
|
||||
'contractor' => $request->contractor ?? '-',
|
||||
'work_number' => $request->work_number ?? '-',
|
||||
'project_name' => $request->project_name,
|
||||
'consultant' => $request->consultant ?? '-',
|
||||
'applicant' => $request->applicant ?? '-',
|
||||
'province_id' => $province->id,
|
||||
'province_name' => $province->name_fa,
|
||||
'contract_subitem_id' => $request->contract_subitem_id
|
||||
]);
|
||||
|
||||
auth()->user()->addActivityComplete(1159);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Azmayesh $azmayesh): JsonResponse
|
||||
{
|
||||
try {
|
||||
$azmayesh->delete();
|
||||
|
||||
auth()->user()->addActivityComplete(1160);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
catch (QueryException $exception) {
|
||||
return $this->errorResponse('امکان حذف وجود ندارد');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Azmayesh;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\AzmayeshSample\StoreRequest;
|
||||
use App\Http\Requests\V3\AzmayeshSample\UpdateRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Azmayesh;
|
||||
use App\Models\AzmayeshSample;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AzmayeshSampleController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request, string $azmayesh_id): JsonResponse
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'updated_at', 'created_at'
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$query = AzmayeshSample::query()->where('azmayesh_id', '=', $azmayesh_id);
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(StoreRequest $request): JsonResponse
|
||||
{
|
||||
$azmayesh = Azmayesh::query()->findOrFail($request->azmayesh_id);
|
||||
|
||||
AzmayeshSample::query()->create([
|
||||
'azmayesh_id' => $azmayesh->id,
|
||||
'azmayesh_project_name' => $azmayesh->project_name,
|
||||
'data' => $request->data,
|
||||
]);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(AzmayeshSample $azmayeshSample): JsonResponse
|
||||
{
|
||||
return $this->successResponse($azmayeshSample);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(UpdateRequest $request, AzmayeshSample $azmayeshSample): JsonResponse
|
||||
{
|
||||
$azmayesh = Azmayesh::query()->findOrFail($request->azmayesh_id);
|
||||
|
||||
$azmayeshSample->update([
|
||||
'azmayesh_id' => $azmayesh->id,
|
||||
'azmayesh_project_name' => $azmayesh->project_name,
|
||||
'data' => $request->data,
|
||||
]);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(AzmayeshSample $azmayeshSample): JsonResponse
|
||||
{
|
||||
$azmayeshSample->delete();
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Azmayesh;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\AzmayeshType\StoreRequest;
|
||||
use App\Http\Requests\V3\AzmayeshType\UpdateRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\AzmayeshField;
|
||||
use App\Models\AzmayeshType;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AzmayeshTypeController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'name', 'updated_at', 'created_at'
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$query = AzmayeshType::query();
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function list(): JsonResponse
|
||||
{
|
||||
$allTypes = AzmayeshType::all();
|
||||
|
||||
return $this->successResponse($allTypes);
|
||||
}
|
||||
|
||||
public function fields(AzmayeshType $azmayeshType): JsonResponse
|
||||
{
|
||||
return $this->successResponse($azmayeshType->azmayeshFields);
|
||||
}
|
||||
|
||||
public function store(StoreRequest $request): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request)
|
||||
{
|
||||
$azmayeshType = AzmayeshType::query()->create([
|
||||
'name' => $request->name
|
||||
]);
|
||||
|
||||
$fieldsID = [];
|
||||
|
||||
foreach ($request->fields as $field)
|
||||
{
|
||||
$azmayeshField = AzmayeshField::query()->firstOrCreate($field, $field);
|
||||
$fieldsID[] = $azmayeshField->id;
|
||||
}
|
||||
|
||||
$azmayeshType->azmayeshFields()->attach($fieldsID);
|
||||
|
||||
auth()->user()->addActivityComplete(1162);
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(AzmayeshType $azmayeshType): JsonResponse
|
||||
{
|
||||
return $this->successResponse($azmayeshType->load(['azmayeshFields']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(UpdateRequest $request, AzmayeshType $azmayeshType): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $azmayeshType)
|
||||
{
|
||||
$azmayeshType->update([
|
||||
'name' => $request->name
|
||||
]);
|
||||
|
||||
$fieldsID = [];
|
||||
|
||||
foreach ($request->fields as $field)
|
||||
{
|
||||
$azmayeshField = AzmayeshField::query()->updateOrCreate($field, $field);
|
||||
$fieldsID[] = $azmayeshField->id;
|
||||
}
|
||||
|
||||
$azmayeshType->azmayeshFields()->sync($fieldsID);
|
||||
|
||||
auth()->user()->addActivityComplete(1163);
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(AzmayeshType $azmayeshType): JsonResponse
|
||||
{
|
||||
try {
|
||||
$azmayeshType->delete();
|
||||
|
||||
auth()->user()->addActivityComplete(1164);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
catch (QueryException $exception) {
|
||||
return $this->errorResponse('امکان حذف وجود ندارد. ابتدا آزمایش های مرتبط با این نوع را حذف نمایید');
|
||||
}
|
||||
}
|
||||
}
|
||||
40
app/Http/Controllers/V3/Dashboard/ObservedItemController.php
Normal file
40
app/Http/Controllers/V3/Dashboard/ObservedItemController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\ObservedItem;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ObservedItemController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
public function show(ObservedItem $observedItem): JsonResponse
|
||||
{
|
||||
return $this->successResponse($observedItem);
|
||||
}
|
||||
|
||||
public function filter(Request $request): JsonResponse
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'item_id', 'road_patrol_id', 'roadPatrol.start_time', 'roadPatrol.end_time',
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$data = ObservedItem::query()->whereNull('road_item_id');
|
||||
|
||||
$dataTable = DataTableFacade::run(
|
||||
$data,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings
|
||||
);
|
||||
|
||||
return response()->json($dataTable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\InfoItem;
|
||||
use App\Models\Province;
|
||||
use App\Models\RoadItemsProject;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RoadItemsReportController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
public function getSubItems(): JsonResponse
|
||||
{
|
||||
$data = InfoItem::all();
|
||||
$items = InfoItem::query()->groupBy('item')->get();
|
||||
|
||||
return $this->successResponse([
|
||||
'items' => $items,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
public function provinceActivityPerSubItem(Request $request): JsonResponse
|
||||
{
|
||||
$fromDate = $request->from_date ? $request->from_date . ' 00:00:00' : now()->startOfDay()->toDateTimeString();
|
||||
$toDate = $request->date_to ? $request->date_to . ' 23:59:59' : now()->endOfDay()->toDateTimeString();
|
||||
$item = $request->item;
|
||||
|
||||
$provinceRoadItemsPerSubItem = RoadItemsProject::query()->selectRaw('
|
||||
sub_item AS t,
|
||||
COUNT(*) AS c,
|
||||
CAST(SUM(CASE WHEN sub_item_data > 0 THEN sub_item_data ELSE ABS(sub_item_data) END) AS UNSIGNED) AS s,
|
||||
province_id AS p')
|
||||
->where('item', '=', $item)
|
||||
->whereBetween('activity_date_time', [$fromDate, $toDate])
|
||||
->where('status', '=', 1)
|
||||
->groupBy('province_id', 'sub_item')
|
||||
->get();
|
||||
|
||||
$countryRoadItemsPerSubItem = RoadItemsProject::query()->selectRaw('
|
||||
sub_item AS t,
|
||||
COUNT(*) AS c,
|
||||
CAST(SUM(CASE WHEN sub_item_data > 0 THEN sub_item_data ELSE ABS(sub_item_data) END) AS UNSIGNED) AS s,
|
||||
-1 AS p')
|
||||
->where('item', '=', $item)
|
||||
->whereBetween('activity_date_time', [$fromDate, $toDate])
|
||||
->where('status', '=', 1)
|
||||
->groupBy('sub_item')
|
||||
->get();
|
||||
|
||||
$infoItems = InfoItem::query()->where('item', '=', $item)->get()->keyBy('sub_item');
|
||||
|
||||
$provinceRoadItemsPerSubItem->each(function ($value) use ($infoItems) {
|
||||
if (isset($infoItems[$value->t])) {
|
||||
$value->u = $infoItems[$value->t]->sub_item_unit;
|
||||
}
|
||||
});
|
||||
|
||||
return $this->successResponse([
|
||||
'provincesData' => $provinceRoadItemsPerSubItem,
|
||||
'countryData' => $countryRoadItemsPerSubItem,
|
||||
'items' => $infoItems
|
||||
]);
|
||||
}
|
||||
|
||||
public function cityActivityPerSubItem(Request $request): JsonResponse
|
||||
{
|
||||
$fromDate = $request->from_date ? $request->from_date . ' 00:00:00' : now()->startOfDay()->toDateTimeString();
|
||||
$toDate = $request->date_to ? $request->date_to . ' 23:59:59' : now()->endOfDay()->toDateTimeString();
|
||||
$item = $request->item;
|
||||
$province = $request->province_id;
|
||||
|
||||
$cityRoadItemsPerSubItem = RoadItemsProject::query()->selectRaw('
|
||||
sub_item AS t,
|
||||
COUNT(*) AS c,
|
||||
CAST(SUM(CASE WHEN sub_item_data > 0 THEN sub_item_data ELSE ABS(sub_item_data) END) AS UNSIGNED) AS s,
|
||||
province_id AS p,
|
||||
edarat_id AS ci
|
||||
')
|
||||
->where('item', '=', $item)
|
||||
->where('province_id', '=', $province)
|
||||
->whereBetween('activity_date_time', [$fromDate, $toDate])
|
||||
->where('status', '=', 1)
|
||||
->groupBy('edarat_id', 'sub_item')
|
||||
->get();
|
||||
|
||||
$items = InfoItem::query()->where('item', $item)->get()->keyBy('sub_item');
|
||||
|
||||
$cityRoadItemsPerSubItem->each(function ($value) use ($items) {
|
||||
if (isset($items[$value->t])) {
|
||||
$value->u = $items[$value->t]->sub_item_unit;
|
||||
}
|
||||
});
|
||||
|
||||
return $this->successResponse([
|
||||
'citiesData' => $cityRoadItemsPerSubItem,
|
||||
'items' => $items
|
||||
]);
|
||||
}
|
||||
|
||||
public function provinceActivityPerItem(Request $request): JsonResponse
|
||||
{
|
||||
if (auth()->check()) {
|
||||
auth()->user()->addActivityComplete(1033);
|
||||
}
|
||||
|
||||
$fromDate = $request->from_date ? $request->from_date . ' 00:00:00' : now()->startOfDay()->toDateTimeString();
|
||||
$toDate = $request->date_to ? $request->date_to . ' 23:59:59' : now()->endOfDay()->toDateTimeString();
|
||||
$user = auth()->user();
|
||||
// $isSpecialUser = in_array($user->username, ['witel', 'drdanesh']);
|
||||
$isSpecialUser = $user->hasPermissionTo("show-road-item-supervise-cartable");
|
||||
$provinceId = $isSpecialUser ? null : $user->province_id;
|
||||
|
||||
$roadItemsProjectsQuery = RoadItemsProject::query()
|
||||
->selectRaw('COUNT(*) AS s, province_id AS p, item AS i')
|
||||
->where('status', 1)
|
||||
->whereBetween('activity_date_time', [$fromDate, $toDate])
|
||||
->when(!$isSpecialUser, function ($query) use ($provinceId) {
|
||||
$query->where('province_id', $provinceId);
|
||||
})
|
||||
->groupBy('province_id', 'item');
|
||||
|
||||
$roadItemsProjectsSummaryQuery = RoadItemsProject::query()
|
||||
->selectRaw('COUNT(*) AS s, -1 AS p, item AS i')
|
||||
->where('status', 1)
|
||||
->whereBetween('activity_date_time', [$fromDate, $toDate])
|
||||
->when(!$isSpecialUser, function ($query) use ($provinceId) {
|
||||
$query->where('province_id', $provinceId);
|
||||
})
|
||||
->groupBy('item');
|
||||
|
||||
$data = $roadItemsProjectsQuery
|
||||
->unionAll($roadItemsProjectsSummaryQuery)
|
||||
->get();
|
||||
|
||||
$provinces = Province::all(['id', 'name_fa']);
|
||||
|
||||
return $this->successResponse([
|
||||
'activities' => $data,
|
||||
'provinces' => $provinces,
|
||||
]);
|
||||
}
|
||||
|
||||
public function cityActivityPerItem(Request $request): JsonResponse
|
||||
{
|
||||
$provinceId = $request->province_id;
|
||||
$fromDate = $request->from_date ? $request->from_date . ' 00:00:00' : now()->startOfDay()->toDateTimeString();
|
||||
$toDate = $request->date_to ? $request->date_to . ' 23:59:59' : now()->endOfDay()->toDateTimeString();
|
||||
|
||||
$roadItemsProjectsQuery = RoadItemsProject::query()
|
||||
->selectRaw('
|
||||
COUNT(*) AS s,
|
||||
edarat_id AS c,
|
||||
item AS i')
|
||||
->where('status', '=', 1)
|
||||
->whereBetween('activity_date_time', [$fromDate, $toDate])
|
||||
->where('province_id', $provinceId)
|
||||
->groupBy('item', 'edarat_id');
|
||||
|
||||
$roadItemsProjectsSummaryQuery = RoadItemsProject::query()
|
||||
->selectRaw('
|
||||
COUNT(*) AS s,
|
||||
-1 AS c,
|
||||
item AS i')
|
||||
->where('status', '=', 1)
|
||||
->whereBetween('activity_date_time', [$fromDate, $toDate])
|
||||
->where('province_id', $provinceId)
|
||||
->groupBy('item');
|
||||
|
||||
$data = $roadItemsProjectsQuery
|
||||
->unionAll($roadItemsProjectsSummaryQuery)
|
||||
->get();
|
||||
|
||||
$edarateShahri = EdarateShahri::query()->where('province_id', '=', $provinceId)->get(['id', 'name_fa']);
|
||||
|
||||
return $this->successResponse([
|
||||
'activities' => $data,
|
||||
'edaratShahri' => $edarateShahri,
|
||||
]);
|
||||
}
|
||||
|
||||
public function map(Request $request): JsonResponse
|
||||
{
|
||||
$provinceId = $request->province_id;
|
||||
$cityId = $request->city_id;
|
||||
$subId = $request->sub_id;
|
||||
$item = $request->item;
|
||||
$dateFrom = $request->date_from ? $request->date_from . ' 00:00:00' : now()->startOfDay()->toDateTimeString();
|
||||
$dateTo = $request->date_to ? $request->date_to . ' 23:59:59' : now()->addDay()->startOfDay()->toDateTimeString();
|
||||
|
||||
$data = RoadItemsProject::query()
|
||||
->where('is_new', '=', 1)
|
||||
->when($provinceId, fn($query) => $query->where('province_id', '=', $provinceId))
|
||||
->when($cityId, fn($query) => $query->where('city_id', '=', $cityId))
|
||||
->when($subId, fn($query) => $query->where('sub_items', 'like', '%' . $subId . '%'))
|
||||
->when($item, fn($query) => $query->where('item', '=', $item))
|
||||
->when(!is_null($request->status), fn($query) => $query->where('status', '=', $request->status))
|
||||
->whereBetween('activity_date', [$dateFrom, $dateTo])
|
||||
->leftJoin('users', 'users.id', '=', 'road_items_projects.user_id')
|
||||
->select('road_items_projects.id as i', 'start_lat as l', 'start_lng as g', 'status')
|
||||
->get();
|
||||
|
||||
return $this->successResponse($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Reports;
|
||||
|
||||
use App\Exports\V2\RoadPatrol\RoadPatrolTable\AllSheets as RoadPatrolTable;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\RoadPatrolProject;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class RoadPatrolReportController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
public function provincePatrolData(Request $request): JsonResponse
|
||||
{
|
||||
$fromDate = $request->from_date ? $request->from_date . ' 00:00:00' : now()->startOfDay()->toDateTimeString();
|
||||
$dateTo = $request->date_to ? $request->date_to . ' 23:59:59' : now()->endOfDay()->toDateTimeString();
|
||||
|
||||
$data = RoadPatrolProject::provincePatrolData($fromDate, $dateTo);
|
||||
return $this->successResponse($data);
|
||||
}
|
||||
|
||||
public function edarehPatrolData(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate(["province_id" => "required",]);
|
||||
$fromDate = $request->from_date ? $request->from_date . ' 00:00:00' : now()->startOfDay()->toDateTimeString();
|
||||
$dateTo = $request->date_to ? $request->date_to . ' 23:59:59' : now()->endOfDay()->toDateTimeString();
|
||||
|
||||
$data = RoadPatrolProject::edarehPatrolData($fromDate, $dateTo, $request->province_id);
|
||||
return $this->successResponse($data);
|
||||
}
|
||||
|
||||
public function roadPatrolsReportTable(Request $request): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از گشت راهداری و ترابری ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
|
||||
return Excel::download(
|
||||
new RoadPatrolTable($request->from_date, $request->date_to), $name
|
||||
);
|
||||
}
|
||||
}
|
||||
333
app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php
Normal file
333
app/Http/Controllers/V3/Dashboard/RoadItemsProjectController.php
Normal file
@@ -0,0 +1,333 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard;
|
||||
|
||||
use App\Exports\V2\RoadItems\OperatorCartableExport;
|
||||
use App\Exports\V2\RoadItems\SupervisorCartableExport;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\RoadItemsProject\StoreRequest;
|
||||
use App\Http\Requests\V3\RoadItemsProject\UpdateRequest;
|
||||
use App\Http\Requests\V3\RoadItemsProject\VerifyBySupervisorRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\InfoItem;
|
||||
use App\Models\RoadItemsProject;
|
||||
use App\Services\NominatimService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class RoadItemsProjectController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function supervisorIndex(Request $request): JsonResponse
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'user_id', 'start_lat', 'start_lng', 'end_lat',
|
||||
'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa',
|
||||
'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa',
|
||||
'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time',
|
||||
'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time','cmmsMachines.machine_code'
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$user = auth()->user();
|
||||
$query = null;
|
||||
|
||||
if ($user->hasPermissionTo('show-road-item-supervise-cartable')) {
|
||||
$query = RoadItemsProject::query()->where('is_new', 1)->with(['files', 'rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-road-item-supervise-cartable-province')) {
|
||||
if (is_null($user->province_id)) {
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
$query = RoadItemsProject::query()->where('is_new', 1)
|
||||
->with(['files', 'rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])->where('province_id', auth()->user()->province_id);
|
||||
}
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
|
||||
foreach ($data['data'] as $road_item) {
|
||||
if (Gate::allows('gate-supervise-road-item', $road_item)) {
|
||||
$road_item['can_supervise'] = 1;
|
||||
} else {
|
||||
$road_item['can_supervise'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function verifyBySupervisor(VerifyBySupervisorRequest $request, RoadItemsProject $roadItemsProject): JsonResponse
|
||||
{
|
||||
$status_fa = $request->verify == 1 ? 'تایید شده' : 'عدم تایید';
|
||||
$user = auth()->user();
|
||||
|
||||
$roadItemsProject->update([
|
||||
'status' => $request->verify,
|
||||
'status_fa' => $status_fa,
|
||||
'supervisor_id' => $user->id,
|
||||
'supervisor_name' => $user->name,
|
||||
'supervisor_description' => $request->description,
|
||||
'supervising_time' => now(),
|
||||
]);
|
||||
|
||||
$user->addActivityComplete(1149);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function restore(RoadItemsProject $roadItemsProject): JsonResponse
|
||||
{
|
||||
if ($roadItemsProject->status == 0) {
|
||||
return response()->json([
|
||||
'message' => 'امکان بازگردانی وضعیت این فعالیت وجود ندارد!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$roadItemsProject->update([
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'supervisor_id' => null,
|
||||
'supervisor_description' => null,
|
||||
'supervising_time' => null,
|
||||
'supervisor_name' => null,
|
||||
]);
|
||||
auth()->user()->addActivityComplete(1150);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function delete(RoadItemsProject $roadItemsProject): JsonResponse
|
||||
{
|
||||
if ($roadItemsProject->files()->exists()) {
|
||||
Storage::delete('public/'. $roadItemsProject->files[0]->path);
|
||||
Storage::delete('public/'. $roadItemsProject->files[1]->path);
|
||||
$roadItemsProject->files()->delete();
|
||||
}
|
||||
auth()->user()->addActivityComplete(1151);
|
||||
|
||||
$roadItemsProject->delete();
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
|
||||
public function supervisorCartableReport(Request $request): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از کارتابل ارزیابی فعالیت روزانه ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
return Excel::download(new SupervisorCartableExport($request->id, $request->item, $request->status,
|
||||
$request->fromDate, $request->toDate, $request->province_id, $request->edarat_id), $name);
|
||||
}
|
||||
|
||||
public function operatorIndex(Request $request): JsonResponse
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'user_id', 'start_lat', 'start_lng', 'end_lat',
|
||||
'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa',
|
||||
'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa',
|
||||
'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time',
|
||||
'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time', 'cmmsMachines.machine_code'
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$query = RoadItemsProject::with(['files', 'rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])
|
||||
->where('is_new', 1)
|
||||
->where('user_id', auth()->user()->id);
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(StoreRequest $request, NominatimService $nominatimService): JsonResponse
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->edarate_ostani_id || is_null($user->city_id)) {
|
||||
return response()->json([
|
||||
'message' => 'امکان ثبت فعالیت برای ادارات استانی و ستادی وجود ندارد!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (is_null($user->edarate_shahri_id)) {
|
||||
return response()->json([
|
||||
'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$info_item = InfoItem::query()->where('item', $request->item_id)
|
||||
->where('sub_item', $request->sub_item_id)
|
||||
->firstOrFail();
|
||||
|
||||
if ($info_item->needs_end_point && !$request->end_point) {
|
||||
throw ValidationException::withMessages([
|
||||
'end_point' => __('validation.required', ['attribute' => 'end_point']),
|
||||
]);
|
||||
}
|
||||
|
||||
if ((!$request->before_image || !$request->after_image) && $info_item->needs_image) {
|
||||
throw ValidationException::withMessages([
|
||||
'before_image' => __('validation.required', ['attribute' => 'before_image']),
|
||||
'after_image' => __('validation.required', ['attribute' => 'after_image']),
|
||||
]);
|
||||
}
|
||||
|
||||
$start_coordinates = explode(',', $request->start_point);
|
||||
$end_coordinates = $info_item->needs_end_point ? explode(',', $request->end_point) : null;
|
||||
|
||||
$attributes = [
|
||||
'start_lat' => $start_coordinates[0],
|
||||
'start_lng' => $start_coordinates[1],
|
||||
'end_lat' => $end_coordinates ? $end_coordinates[0] : null,
|
||||
'end_lng' => $end_coordinates ? $end_coordinates[1] : null,
|
||||
'item' => $info_item->item,
|
||||
'item_fa' => $info_item->item_str,
|
||||
'sub_item' => $info_item->sub_item,
|
||||
'sub_item_fa' => $info_item->sub_item_str,
|
||||
'sub_item_data' => $request->amount,
|
||||
'province_id' => $user->province_id,
|
||||
'province_fa' => $user->province_fa,
|
||||
'city_id' => $user->city_id,
|
||||
'city_fa' => $user->city_fa,
|
||||
'user_name' => $user->name,
|
||||
'start_way_id' => $nominatimService->get_way_id_from_nominatim($start_coordinates[0], $start_coordinates[1]),
|
||||
'end_way_id' => $end_coordinates ? $nominatimService->get_way_id_from_nominatim($end_coordinates[0], $end_coordinates[1]) : null,
|
||||
'unit_fa' => $info_item->sub_item_unit,
|
||||
'created_at_fa' => verta(\Carbon\Carbon::now())->format('Y-m-d H:i:s'),
|
||||
'info_id' => $info_item->id,
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'edarat_id' => $user->edarate_shahri_id,
|
||||
'edarat_type' => EdarateShahri::class,
|
||||
'edarat_name' => $user->edarate_shahri_name,
|
||||
'activity_date' => $request->activity_date,
|
||||
'activity_time' => $request->activity_time,
|
||||
];
|
||||
|
||||
$after_image = ($request->has('after_image') && $info_item->needs_image) ?
|
||||
$request->file('after_image') :
|
||||
null;
|
||||
|
||||
$before_image = ($request->has('before_image') && $info_item->needs_image) ?
|
||||
$request->file('before_image') :
|
||||
null;
|
||||
|
||||
$road_item = RoadItemsProject::store($user, $attributes, $before_image, $after_image, $request->observed_item_id);
|
||||
|
||||
if ($road_item === -1) {
|
||||
return response()->json([
|
||||
'message' => 'اقدام مربوطه قبلا رسیدگی شده است.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$road_item->rahdaran()->attach($request->rahdaran_id);
|
||||
$road_item->cmmsMachines()->attach($request->machines_id);
|
||||
|
||||
auth()->user()->addActivityComplete(1154);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function update(UpdateRequest $request, RoadItemsProject $roadItemsProject): JsonResponse
|
||||
{
|
||||
$info_item = InfoItem::query()->where('item', $roadItemsProject->item)
|
||||
->where('sub_item', $roadItemsProject->sub_item)
|
||||
->firstOrFail();
|
||||
|
||||
$start_coordinates = explode(',', $request->start_point);
|
||||
$end_coordinates = null;
|
||||
|
||||
if ($info_item->needs_end_point) {
|
||||
if (!$request->end_point) {
|
||||
throw ValidationException::withMessages([
|
||||
'end_point' => __('validation.required', ['attribute' => 'end_point']),
|
||||
]);
|
||||
}
|
||||
|
||||
$end_coordinates = explode(',', $request->end_point);
|
||||
}
|
||||
|
||||
if ($info_item->needs_image) {
|
||||
if ($request->has('after_image')) {
|
||||
|
||||
Storage::delete('public/'. $roadItemsProject->files[0]->path);
|
||||
|
||||
$after = $request->file('after_image')->store('road_items_projects_new/after', 'public');
|
||||
$roadItemsProject->files[0]->update([
|
||||
'path' => $after
|
||||
]);
|
||||
// $roadItemsProject->files()->create(['path' => $after]);
|
||||
$urlAfter = "/var/www/rms/public/storage/{$after}";
|
||||
// \App\Helpers\Compress::resize($urlAfter);
|
||||
}
|
||||
if ($request->has('before_image')) {
|
||||
Storage::delete('public/'. $roadItemsProject->files[1]->path);
|
||||
|
||||
$before = $request->file('before_image')->store('/road_items_projects_new/before', 'public');
|
||||
$roadItemsProject->files[1]->update([
|
||||
'path' => $before
|
||||
]);
|
||||
// $roadItemsProject->files()->create(['path' => $before]);
|
||||
$urlBefore = "/var/www/rms/public/storage/{$before}";
|
||||
// \App\Helpers\Compress::resize($urlBefore);
|
||||
}
|
||||
}
|
||||
|
||||
$roadItemsProject->update([
|
||||
'start_lat' => $start_coordinates[0],
|
||||
'start_lng' => $start_coordinates[1],
|
||||
'end_lat' => $end_coordinates ? $end_coordinates[0] : null,
|
||||
'end_lng' => $end_coordinates ? $end_coordinates[1] : null,
|
||||
'sub_item_data' => $request->amount,
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
]);
|
||||
|
||||
$roadItemsProject->rahdaran()->sync($request->rahdaran_id);
|
||||
$roadItemsProject->cmmsMachines()->sync($request->machines_id);
|
||||
|
||||
|
||||
auth()->user()->addActivityComplete(1155);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function operatorCartableReport(Request $request): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از کارتابل عملیات فعالیت روزانه ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
return Excel::download(
|
||||
new OperatorCartableExport($request->id, $request->item, $request->status, $request->fromDate, $request->toDate),
|
||||
$name
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard;
|
||||
|
||||
use App\Exports\V2\RoadPatrol\OperatorCartableExport;
|
||||
use App\Exports\V2\RoadPatrol\SupervisorCartableExport;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Facades\Sms\Sms;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\RoadPatrolProject\DeleteRequest;
|
||||
use App\Http\Requests\V3\RoadPatrolProject\StoreRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\InfoItem;
|
||||
use App\Models\RoadItemsProject;
|
||||
use App\Models\RoadObserved;
|
||||
use App\Models\RoadPatrol;
|
||||
use App\Services\NominatimService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class RoadPatrolProjectController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
public function supervisorIndex(Request $request): JsonResponse
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'start_lat', 'start_lon', 'end_lat', 'end_lon', 'operator_id',
|
||||
'operator_name', 'officer_plaque', 'officer_phone_number', 'officer_name',
|
||||
'supervisor_description', 'supervising_time', 'supervisor_name', 'status',
|
||||
'status_fa', 'distance', 'province_id', 'province_fa', 'edare_id', 'edare_name',
|
||||
'start_time', 'end_time','description', 'cmmsMachines.machine_code'
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$user = auth()->user();
|
||||
$query = null;
|
||||
|
||||
if ($user->hasPermissionTo('show-road-patrol-supervise-cartable')) {
|
||||
$query = RoadPatrol::query()
|
||||
->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-road-patrol-supervise-cartable-province')) {
|
||||
if (is_null($user->province_id)) {
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
$query = RoadPatrol::query()
|
||||
->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])
|
||||
->where('province_id', '=', $user->province_id);
|
||||
}
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
foreach ($data['data'] as $road_patrol) {
|
||||
if (Gate::allows('gate-supervise-road-item', $road_patrol)) {
|
||||
$road_patrol['can_supervise'] = 1;
|
||||
} else {
|
||||
$road_patrol['can_supervise'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function delete(DeleteRequest $request, RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
if ($request->type == 1) {
|
||||
DB::transaction(function () use ($roadPatrol) {
|
||||
$roadPatrol->observedItems()->delete();
|
||||
$roadPatrol->delete();
|
||||
});
|
||||
} else {
|
||||
DB::transaction(function () use ($roadPatrol) {
|
||||
if ($roadPatrol->observedItems) {
|
||||
foreach ($roadPatrol->observedItems as $index => $observed_item) {
|
||||
if ($observed_item->roadItemProject) {
|
||||
$road_item = $observed_item->roadItemProject;
|
||||
|
||||
if ($road_item->files()->exists()) {
|
||||
Storage::delete('public/'. $road_item->files[0]->path);
|
||||
Storage::delete('public/'. $road_item->files[1]->path);
|
||||
$road_item->files()->delete();
|
||||
}
|
||||
|
||||
$road_item->delete();
|
||||
}
|
||||
|
||||
$observed_item->delete();
|
||||
}
|
||||
}
|
||||
auth()->user()->addActivityComplete(1144);
|
||||
|
||||
$roadPatrol->delete();
|
||||
});
|
||||
}
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function supervisorCartableReport(Request $request): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از کارتابل ارزیابی گشت راهداری ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
return Excel::download(
|
||||
new SupervisorCartableExport($request->id, $request->fromDate,
|
||||
$request->toDate, $request->province_id, $request->edare_id
|
||||
), $name
|
||||
);
|
||||
}
|
||||
|
||||
public function operatorIndex(Request $request): JsonResponse
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'start_lat', 'start_lon', 'end_lat', 'end_lon', 'officer_plaque',
|
||||
'officer_phone_number', 'officer_name', 'supervisor_description', 'supervising_time',
|
||||
'supervisor_name', 'status', 'status_fa', 'distance', 'start_time', 'end_time', 'cmmsMachines.machine_code'
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$query = RoadPatrol::query()
|
||||
->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])
|
||||
->where('operator_id', '=', auth()->user()->id);
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function store(StoreRequest $request, NominatimService $nominatimService): JsonResponse
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->edarate_ostani_id || is_null($user->city_id)) {
|
||||
return response()->json([
|
||||
'message' => 'امکان ثبت فعالیت برای ادارات استانی وجود ندارد!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (is_null($user->edarate_shahri_id)) {
|
||||
return response()->json([
|
||||
'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$edare_id = $user->edarate_shahri_id ?? $user->edarate_ostani_id;
|
||||
$edare_name = $user->edarate_shahri_id ? $user->edarate_shahri_name : $user->edarate_ostani_name;
|
||||
|
||||
$road_patrol = DB::transaction(function () use ($request, $edare_id,
|
||||
$edare_name, $nominatimService, $user) {
|
||||
|
||||
$road_patrol = RoadPatrol::query()->create([
|
||||
'operator_id' => $user->id,
|
||||
'operator_name' => $user->name,
|
||||
'province_id' => $user->province_id,
|
||||
'province_fa' => $user->province_fa,
|
||||
'city_id' => $user->city_id,
|
||||
'city_fa' => $user->city_fa,
|
||||
'edare_id' => $edare_id,
|
||||
'edare_name' => $edare_name,
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'distance' => $request->distance,
|
||||
'start_time' => $request->start_time,
|
||||
'end_time' => $request->end_time,
|
||||
'description' => $request->description ?? null,
|
||||
'fuel_consumption' => $request->fuel_consumption,
|
||||
'vehicle_runtime' => $request->vehicle_runtime,
|
||||
'stop_points' => json_encode($request->stop_points),
|
||||
]);
|
||||
|
||||
$road_patrol->rahdaran()->attach($request->road_patrol_rahdaran_id);
|
||||
$road_patrol->cmmsMachines()->attach($request->road_patrol_machines_id);
|
||||
|
||||
if ($request->observed_items) {
|
||||
foreach ($request->observed_items as $index => $item) {
|
||||
$info_item = InfoItem::where('item', $item['item_id'])
|
||||
->where('sub_item', $item['sub_item_id'])
|
||||
->firstOrFail();
|
||||
|
||||
$item_start_coordinates = explode(',', $item['start_point']);
|
||||
|
||||
$observed_item = $road_patrol->observedItems()->create([
|
||||
'item_id' => $info_item->item,
|
||||
'item_name' => $info_item->item_str,
|
||||
'sub_item_id' => $info_item->sub_item,
|
||||
'sub_item_name' => $info_item->sub_item_str,
|
||||
'local_name' => $item['local_name'],
|
||||
'description' => $item['description'] ?? null,
|
||||
'start_lat' => $item_start_coordinates[0],
|
||||
'start_lon' => $item_start_coordinates[1],
|
||||
]);
|
||||
|
||||
$item_end_coordinates = null;
|
||||
if ($item['instant_action'] == 0) {
|
||||
$observed_item->priority = $item['priority'];
|
||||
$observed_item->priority_fa = $item['priority_fa'];
|
||||
$observed_item->save();
|
||||
} elseif ($item['instant_action'] == 1) {
|
||||
if ($info_item->needs_end_point) {
|
||||
if (!isset($item['end_point'])) {
|
||||
throw ValidationException::withMessages([
|
||||
"observed_items.$index.end_point" => __('validation.required', ['attribute' => 'end_point']),
|
||||
]);
|
||||
}
|
||||
|
||||
$item_end_coordinates = explode(',', $item['end_point']);
|
||||
}
|
||||
|
||||
$before_image = null;
|
||||
$after_image = null;
|
||||
if ($info_item->needs_image) {
|
||||
if (!isset($item['before_image'])) {
|
||||
throw ValidationException::withMessages([
|
||||
"observed_items.$index.before_image" => __('validation.required', ['attribute' => 'before_image']),
|
||||
]);
|
||||
}
|
||||
if (!isset($item['after_image'])) {
|
||||
throw ValidationException::withMessages([
|
||||
"observed_items.$index.after_image" => __('validation.required', ['attribute' => 'after_image']),
|
||||
]);
|
||||
}
|
||||
|
||||
$before_image = $item['before_image'];
|
||||
$after_image = $item['after_image'];
|
||||
}
|
||||
|
||||
$start_time = Carbon::createFromFormat('Y-m-d H:i', $request->start_time);
|
||||
$end_time = Carbon::createFromFormat('Y-m-d H:i', $request->end_time);
|
||||
$activity_date = $start_time->average($end_time);
|
||||
|
||||
$attributes = [
|
||||
'start_lat' => $item_start_coordinates[0],
|
||||
'start_lng' => $item_start_coordinates[1],
|
||||
'end_lat' => $item_end_coordinates ? $item_end_coordinates[0] : null,
|
||||
'end_lng' => $item_end_coordinates ? $item_end_coordinates[1] : null,
|
||||
'item' => $info_item->item,
|
||||
'item_fa' => $info_item->item_str,
|
||||
'sub_item' => $info_item->sub_item,
|
||||
'sub_item_fa' => $info_item->sub_item_str,
|
||||
'sub_item_data' => $item['amount'],
|
||||
'province_id' => $user->province_id,
|
||||
'province_fa' => $user->province_fa,
|
||||
'city_id' => $user->city_id,
|
||||
'city_fa' => $user->city_fa,
|
||||
'user_name' => $user->name,
|
||||
'start_way_id' => $nominatimService->get_way_id_from_nominatim($item_start_coordinates[0], $item_start_coordinates[1]),
|
||||
'end_way_id' => $item_end_coordinates ? $nominatimService->get_way_id_from_nominatim($item_end_coordinates[0], $item_end_coordinates[1]) : null,
|
||||
'unit_fa' => $info_item->sub_item_unit,
|
||||
'created_at_fa' => verta(Carbon::now())->format('Y-m-d H:i:s'),
|
||||
'info_id' => $info_item->id,
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'edarat_id' => $user->edarate_shahri_id,
|
||||
'edarat_type' => EdarateShahri::class,
|
||||
'edarat_name' => $user->edarate_shahri_name,
|
||||
'activity_date' => $activity_date->format('Y-m-d'),
|
||||
'activity_time' => $activity_date->format('H:i:s'),
|
||||
];
|
||||
|
||||
$road_item = RoadItemsProject::store($user, $attributes, $before_image, $after_image, $observed_item->id);
|
||||
|
||||
if ($road_item === -1) {
|
||||
return response()->json([
|
||||
'message' => 'اقدام مربوطه قبلا رسیدگی شده است.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$road_item->rahdaran()->attach($item['road_item_rahdaran_id']);
|
||||
$road_item->cmmsMachines()->attach($item['road_item_machines_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auth()->user()->addActivityComplete(1147);
|
||||
|
||||
Sms::sendSms($request->officer_phone_number,
|
||||
"گشت راهداری با کد یکتای $road_patrol->id در تاریخ ".verta(\Carbon\Carbon::now())->format('Y-m-d H:i:s')." با شماره شما در سامانه RMS ثبت شد. \n لینک دریافت گزارش : \n https://rms.rmto.ir/v2/road_patrols/operator/report/$road_patrol->id"
|
||||
);
|
||||
return $road_patrol;
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function getReport(RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
$data = [
|
||||
'serial_no' => $roadPatrol->id,
|
||||
'province_fa' => $roadPatrol->province_fa,
|
||||
'edare_name' => $roadPatrol->edare_name,
|
||||
'start_time' => $roadPatrol->start_time,
|
||||
'end_time' => $roadPatrol->end_time,
|
||||
'officer_name' => $roadPatrol->officer_name,
|
||||
'officer_plaque' => $roadPatrol->officer_plaque,
|
||||
'officer_phone_number' => $roadPatrol->officer_phone_number,
|
||||
'created_at' => $roadPatrol->created_at
|
||||
];
|
||||
|
||||
$observed_items = array();
|
||||
if($roadPatrol->observedItems) {
|
||||
foreach ($roadPatrol->observedItems as $index => $observed_item) {
|
||||
$observed_items[] = [
|
||||
'item' => $observed_item->item_name,
|
||||
'sub_item' => $observed_item->sub_item_name,
|
||||
'local_name' => $observed_item->local_name,
|
||||
'description' => $observed_item->description,
|
||||
'priority_fa' => $observed_item->priority_fa,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['observed_items'] = $observed_items;
|
||||
return $this->successResponse($data);
|
||||
}
|
||||
|
||||
public function getAllDataToMap(Request $request): JsonResponse
|
||||
{
|
||||
$date_from = $request->date_from ? $request->date_from .' 00:00:00' : Date('Y-m-d') .' 00:00:00';
|
||||
$date_to = $request->date_to ? $request->date_to.' 23:59:59' : (new \DateTime('tomorrow'))->format('Y-m-d').' 23:59:59';
|
||||
|
||||
$data = RoadPatrol::query()->when($request->province_id, function ($query, $province) {
|
||||
return $query->where('province_id', '=', $province);
|
||||
})
|
||||
->when($request->edare_id, function ($query, $edare_id) {
|
||||
return $query->where('edare_id', '=', $edare_id);
|
||||
})
|
||||
->whereBetween('created_at', [
|
||||
$date_from,
|
||||
$date_to,
|
||||
])
|
||||
->select('id', 'start_lat', 'start_lon')
|
||||
->get();
|
||||
|
||||
return $this->successResponse($data);
|
||||
}
|
||||
|
||||
public function map(Request $request): JsonResponse
|
||||
{
|
||||
$province = $request->province_id;
|
||||
$edare_shahri = $request->edare_shahri_id;
|
||||
$status = $request->status;
|
||||
$rms_status = $request->rms_status;
|
||||
|
||||
if ($request->date_from && $request->date_to) {
|
||||
$date_from = $request->date_from.' 00:00:00';
|
||||
$date_to = $request->date_to.' 23:59:59';
|
||||
} else {
|
||||
$date_from = Date('Y-m-d');
|
||||
$date_to = new \DateTime('tomorrow');
|
||||
$date_to = $date_to->format('Y-m-d');
|
||||
}
|
||||
|
||||
$projects = RoadObserved::query()->select(['id', 'lng', 'lat','status'])
|
||||
->whereBetween('created_at', [$date_from, $date_to])
|
||||
->when($province, function ($query) use ($province) {
|
||||
return $query->where('province_id', '=', $province);
|
||||
})
|
||||
->when($rms_status, function ($query) use ($rms_status) {
|
||||
if ($rms_status == 2) {
|
||||
return $query->where('rms_status', '<>', 0);
|
||||
} else {
|
||||
return $query->where('rms_status', '=', 0);
|
||||
}
|
||||
})
|
||||
->when($edare_shahri, function ($query) use ($edare_shahri) {
|
||||
return $query->where('edarate_shahri_id', '=', $edare_shahri);
|
||||
})
|
||||
->when($status, function ($query) use ($status) {
|
||||
return $query->where('status', '=', $status);
|
||||
})
|
||||
->get();
|
||||
return $this->successResponse($projects);
|
||||
}
|
||||
|
||||
public function show(RoadPatrol $roadPatrol): JsonResponse
|
||||
{
|
||||
return $this->successResponse($roadPatrol);
|
||||
}
|
||||
|
||||
public function operatorCartableReport(Request $request): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از کارتابل عملیات گشت راهداری ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
return Excel::download(
|
||||
new OperatorCartableExport($request->id, $request->status, $request->officer_name, $request->fromDate, $request->toDate),
|
||||
$name
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user