inital commit
This commit is contained in:
67
app/Http/Controllers/V2/Dashboard/ContractController.php
Normal file
67
app/Http/Controllers/V2/Dashboard/ContractController.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ContractSubItems;
|
||||
use App\Models\Contracts;
|
||||
|
||||
|
||||
class ContractController extends Controller
|
||||
{
|
||||
public function getAllDataToMap(Request $request)
|
||||
{
|
||||
|
||||
$projectType = $request->type;
|
||||
$province = $request->province_id;
|
||||
$axis = $request->axis;
|
||||
$lastStatus = $request->last_status;
|
||||
$fromDate = $request->date_from;
|
||||
$toDate = $request->date_to;
|
||||
$priority = $request->priority;
|
||||
$followup_priority_project_id = $request->followup;
|
||||
|
||||
$data = ContractSubItems::select('id', 'start_lat', 'start_lng', 'project_type_id')
|
||||
->when($projectType, function ($query, $projectType) {
|
||||
return $query->where('project_type_id', $projectType);
|
||||
})
|
||||
->when($province, function ($query, $province) {
|
||||
return $query->where('province_id', $province);
|
||||
})
|
||||
->when($axis, function ($query, $axis) {
|
||||
return $query->where('axis_type_id', $axis);
|
||||
})
|
||||
->when($followup_priority_project_id, function ($query, $followup_priority_project_id) {
|
||||
return $query->where('followup_priority_project_id', $followup_priority_project_id);
|
||||
})
|
||||
->when($lastStatus, function ($query, $lastStatus) {
|
||||
return $query->where('last_status_id', $lastStatus);
|
||||
})
|
||||
->when($fromDate, function ($query) use ($fromDate, $toDate) {
|
||||
return $query->whereBetween('contract_date_from_parent_contract', [$fromDate, $toDate]);
|
||||
})
|
||||
->when($priority, function ($query, $priority) {
|
||||
return $query->where('priority_project', $priority);
|
||||
})
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'count' => count($data),
|
||||
'data' => $data
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function detail(ContractSubItems $contract_sub_item)
|
||||
{
|
||||
return response()->json($contract_sub_item, 200);
|
||||
}
|
||||
|
||||
public function unserialize(Contracts $contract)
|
||||
{
|
||||
return response()->json([
|
||||
'data' => $contract->documents ? unserialize($contract->documents) : [] ,
|
||||
]);
|
||||
}
|
||||
}
|
||||
355
app/Http/Controllers/V2/Dashboard/GeneralController.php
Normal file
355
app/Http/Controllers/V2/Dashboard/GeneralController.php
Normal file
@@ -0,0 +1,355 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\RoadItemsProject;
|
||||
use App\Models\RoadPatrol;
|
||||
use App\Models\RoadObserved;
|
||||
use App\Models\InfoItem;
|
||||
use App\Models\User;
|
||||
use App\Models\HttpErorrsList;
|
||||
use App\Models\SafetyAndPrivacy;
|
||||
use GuzzleHttp\Client;
|
||||
use Auth;
|
||||
use App\Models\EdarateOstani;
|
||||
|
||||
|
||||
class GeneralController extends Controller
|
||||
{
|
||||
public function errors()
|
||||
{
|
||||
$post = array(
|
||||
// 'username' => env("PAYMENT_USERNAME"),
|
||||
// 'password' => env("PAYMENT_PASSWORD"),
|
||||
// 'amount' => $final_amount,
|
||||
// 'serial' => "12345",
|
||||
// 'type' => 1,
|
||||
// 'instanceid' => 123,
|
||||
// 'ownerid' => $driver_national_code,
|
||||
// 'calculationBox' => "{\"rows\":[{\"amount\":". $final_amount .",\"code\":\"7070021060000015\"}]}"
|
||||
);
|
||||
// 204063776282400001230003985031/4001063704010676
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "http://payment.rmto.ir/acc/rest/payid/track2/".env("PAYMENT_USERNAME")."/".env("PAYMENT_PASSWORD")."/204063776282400001230003985031");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
// curl_setopt($ch, CURLOPT_POST, true);
|
||||
// curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
// dd("http://payment.rmto.ir/acc/rest/payid/track2/".env("PAYMENT_USERNAME")."/".env("PAYMENT_PASSWORD")."/{204063776282400001230003985031}");
|
||||
return $response;
|
||||
|
||||
|
||||
|
||||
// $client = new \GuzzleHttp\Client();
|
||||
|
||||
// $url = "http://payment.rmto.ir/acc/rest/payid/gen";
|
||||
|
||||
// // $post = [
|
||||
// $body['Username'] = 'cspay';
|
||||
// $body['Password'] = 'cspay123';
|
||||
// $body['Amount'] = 10;
|
||||
// $body['Serial'] = 10;
|
||||
// $body['Type'] = 1;
|
||||
// $body['Instanceid'] = 358063754282400001100000010676;
|
||||
// $body['Ownerid'] = 1450103456;
|
||||
// $body['calculationBox'] = "{\"rows\":[{\"amount\":10,\"code\":\"7070021060000015\"}]}";
|
||||
|
||||
// [
|
||||
// "rows" =>[
|
||||
// ["amount" => 10,"code" => "707001"]
|
||||
// ],
|
||||
// // [],
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// $myBody['name'] = "Demo";
|
||||
|
||||
// $request = $client->post($url, ['body'=>$body]);
|
||||
|
||||
// $response = $request->send();
|
||||
|
||||
|
||||
|
||||
// dd($response);
|
||||
|
||||
// $arrayName = array('' => , );
|
||||
$post = array(
|
||||
'username' => env("PAYMENT_USERNAME"),
|
||||
'password' => env("PAYMENT_PASSWORD"),
|
||||
'amount' => "1000",
|
||||
'serial' => "12345",
|
||||
'type' => 1,
|
||||
'instanceid' => 123,
|
||||
'ownerid' => "1450103456",
|
||||
'calculationBox' => "{\"rows\":[{\"amount\":1000,\"code\":\"7070021060000015\"}]}"
|
||||
);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "http://payment.rmto.ir/acc/rest/payid/gen");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $response;
|
||||
var_dump($response);
|
||||
dd();
|
||||
|
||||
// $tmp = User::with("permissions")->whereHas("permissions", function($q) {
|
||||
// $q->where("id", 140);
|
||||
// })->get();
|
||||
|
||||
// dd($tmp);
|
||||
$data = [];
|
||||
$key_ = 0;
|
||||
// try {
|
||||
foreach (HttpErorrsList::all() as $key => $value) {
|
||||
try {
|
||||
$data[] = unserialize(base64_decode($value->value));
|
||||
} catch (\Throwable $th) {
|
||||
$data[] = $value->id;
|
||||
}
|
||||
}
|
||||
|
||||
dd($data);
|
||||
// } catch (\Throwable $th) {
|
||||
// // return response()->json($key_, 200);
|
||||
// }
|
||||
|
||||
echo "<pre>";
|
||||
echo var_dump($data);
|
||||
echo "</pre>";
|
||||
}
|
||||
public function getActivityStatistics(Request $request)
|
||||
{
|
||||
$data = array();
|
||||
|
||||
$road_items = array();
|
||||
$road_items['total'] = 0;
|
||||
if (auth()->user()->can('create-road-item')) {
|
||||
$road_items['operation_cnt'] = RoadItemsProject::where('is_new', 1)
|
||||
->where('user_id', auth()->user()->id)
|
||||
->where('status', 2)
|
||||
->count();
|
||||
|
||||
$road_items['total'] += $road_items['operation_cnt'];
|
||||
}
|
||||
|
||||
if (auth()->user()->can('supervise-road-item')) {
|
||||
$road_items['supervise_cnt'] = RoadItemsProject::where('is_new', 1)
|
||||
->where(function ($query) {
|
||||
$query->where('status', 0);
|
||||
// ->orWhere('supervisor_id', auth()->user()->id);
|
||||
})->count();
|
||||
|
||||
$road_items['total'] += $road_items['supervise_cnt'];
|
||||
} elseif (auth()->user()->can('supervise-road-item-province')) {
|
||||
if (is_null(auth()->user()->province_id) || !auth()->user()->province_id) {
|
||||
return response()->json([
|
||||
'message' => 'استانی برای شما در سامانه ثبت نشده است!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$road_items['supervise_cnt'] = RoadItemsProject::where('is_new', 1)
|
||||
->where('province_id', auth()->user()->province_id)
|
||||
->where(function ($query) {
|
||||
$query->where('status', 0);
|
||||
// ->orWhere('supervisor_id', auth()->user()->id);
|
||||
})
|
||||
->count();
|
||||
|
||||
$road_items['total'] += $road_items['supervise_cnt'];
|
||||
}elseif (auth()->user()->can('supervise-road-item-by-edareostani')) {
|
||||
if (is_null(auth()->user()->edarate_ostani_id) || !auth()->user()->edarate_ostani_id) {
|
||||
return response()->json([
|
||||
'message' => 'اداره ای برای شما در سامانه ثبت نشده است!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$road_items['supervise_cnt'] = RoadItemsProject::where('is_new', 1)
|
||||
->where('province_id', auth()->user()->province_id)
|
||||
->whereIn('item', explode(",", EdarateOstani::where('id', auth()->user()->edarate_ostani_id)->first()->items_for_confirm))
|
||||
->where(function ($query) {
|
||||
$query->where('status', 0);
|
||||
// ->orWhere('supervisor_id', auth()->user()->id);
|
||||
})
|
||||
->count();
|
||||
|
||||
$road_items['total'] += $road_items['supervise_cnt'];
|
||||
}
|
||||
|
||||
if (!empty($road_items)) {
|
||||
$data['road_items'] = $road_items;
|
||||
}
|
||||
// road item (end)
|
||||
|
||||
// road patrol (begin)
|
||||
$road_patrols = array();
|
||||
$road_patrols['total'] = 0;
|
||||
// if (auth()->user()->can('add-road-patrol')) {
|
||||
// $road_patrols['operation_cnt'] = RoadPatrol::where('operator_id', auth()->user()->id)
|
||||
// ->where('status', 2)
|
||||
// ->count();
|
||||
|
||||
// $road_patrols['total'] += $road_patrols['operation_cnt'];
|
||||
// }
|
||||
|
||||
// if (auth()->user()->can('show-road-patrol-supervise-cartable')) {
|
||||
// $road_patrols['supervise_cnt'] = RoadPatrol::where(function ($query) {
|
||||
// $query->where('status', 0);
|
||||
// // ->orWhere('supervisor_id', auth()->user()->id);
|
||||
// })->count();
|
||||
|
||||
// $road_patrols['total'] += $road_patrols['supervise_cnt'];
|
||||
// } elseif (auth()->user()->can('show-road-patrol-supervise-cartable-province')) {
|
||||
// if (is_null(auth()->user()->province_id) || !auth()->user()->province_id) {
|
||||
// return response()->json([
|
||||
// 'message' => 'استانی برای شما در سامانه ثبت نشده است!'
|
||||
// ], 403);
|
||||
// }
|
||||
|
||||
// $road_patrols['supervise_cnt'] = RoadPatrol::where('province_id', auth()->user()->province_id)
|
||||
// ->where(function ($query) {
|
||||
// $query->where('status', 0);
|
||||
// // ->orWhere('supervisor_id', auth()->user()->id);
|
||||
// })
|
||||
// ->count();
|
||||
|
||||
// $road_patrols['total'] += $road_patrols['supervise_cnt'];
|
||||
// }
|
||||
|
||||
if (!empty($road_patrols)) {
|
||||
$data['road_patrols'] = $road_patrols;
|
||||
}
|
||||
// road patrol (end)
|
||||
|
||||
// road observation (begin)
|
||||
$road_observations = array();
|
||||
$road_observations['total'] = 0;
|
||||
if (auth()->user()->can('show-fast-react')) {
|
||||
$road_observations['operation_cnt'] = RoadObserved::where('status', 2)
|
||||
->count();
|
||||
|
||||
$road_observations['total'] += $road_observations['operation_cnt'];
|
||||
} elseif (auth()->user()->can('show-fast-react-province')) {
|
||||
if (is_null(auth()->user()->province_id) || !auth()->user()->province_id) {
|
||||
return response()->json([
|
||||
'message' => 'استانی برای شما در سامانه ثبت نشده است!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$road_observations['operation_cnt'] = RoadObserved::where('status', 2)
|
||||
->where('rms_province_id', auth()->user()->province_id)
|
||||
->count();
|
||||
|
||||
$road_observations['total'] += $road_observations['operation_cnt'];
|
||||
} elseif (auth()->user()->can('show-fast-react-edarate-shahri')) {
|
||||
if (is_null(auth()->user()->edarate_shahri_id)) {
|
||||
return response()->json([
|
||||
'message' => 'اداره ای برای شما در سامانه ثبت نشده است!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$road_observations['operation_cnt'] = RoadObserved::where('status', 2)
|
||||
->where('edarate_shahri_id', auth()->user()->edarate_shahri_id)
|
||||
->count();
|
||||
|
||||
$road_observations['total'] += $road_observations['operation_cnt'];
|
||||
}
|
||||
|
||||
if (auth()->user()->can('supervise-fast-react')) {
|
||||
$road_observations['supervise_cnt'] = RoadObserved::where(function ($query) {
|
||||
$query->where('status', 0);
|
||||
// ->orWhere('supervisor_id', auth()->user()->id);
|
||||
})->count();
|
||||
|
||||
$road_observations['total'] += $road_observations['supervise_cnt'];
|
||||
} elseif (auth()->user()->can('supervise-fast-react-province')) {
|
||||
if (is_null(auth()->user()->province_id) || !auth()->user()->province_id) {
|
||||
return response()->json([
|
||||
'message' => 'استانی برای شما در سامانه ثبت نشده است!'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$road_observations['supervise_cnt'] = RoadObserved::where('province_id', auth()->user()->province_id)
|
||||
->where(function ($query) {
|
||||
$query->where('status', 0);
|
||||
// ->orWhere('supervisor_id', auth()->user()->id);
|
||||
})
|
||||
->count();
|
||||
|
||||
$road_observations['total'] += $road_observations['supervise_cnt'];
|
||||
}
|
||||
|
||||
if (!empty($road_observations)) {
|
||||
$data['road_observations'] = $road_observations;
|
||||
}
|
||||
// road observation (end)
|
||||
|
||||
// safety and privacy (begin)
|
||||
$safety_and_privacy = array();
|
||||
// $safety_and_privacy['total'] = 0;
|
||||
if (auth()->user()->hasPermissionTo('show-safety-and-privacy-operator-cartable')) {
|
||||
$temp_data = SafetyAndPrivacy::selectRaw('count(*) as cnt, step')
|
||||
->groupby('step')
|
||||
->orderBy('step')
|
||||
->get();
|
||||
|
||||
} elseif (auth()->user()->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) {
|
||||
if (is_null(auth()->user()->province_id)) {
|
||||
return response()->json([
|
||||
'message' => 'استانی برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$temp_data = SafetyAndPrivacy::where('province_id', auth()->user()->province_id)
|
||||
->selectRaw('count(*) as cnt, step')
|
||||
->groupby('step')
|
||||
->orderBy('step')
|
||||
->get();
|
||||
|
||||
} elseif (auth()->user()->hasPermissionTo('show-safety-and-privacy-operator-cartable-edarate-shahri')) {
|
||||
if (is_null(auth()->user()->edarate_shahri_id)) {
|
||||
return response()->json([
|
||||
'message' => 'اداره ای برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$temp_data = SafetyAndPrivacy::where('edare_shahri_id', auth()->user()->edarate_shahri_id)
|
||||
->selectRaw('count(*) as cnt, step')
|
||||
->groupby('step')
|
||||
->orderBy('step')
|
||||
->get();
|
||||
}
|
||||
|
||||
$safety_and_privacy['step_one'] = isset($temp_data[0]) ? $temp_data[0]->cnt : 0;
|
||||
$safety_and_privacy['step_two'] = isset($temp_data[1]) ? $temp_data[1]->cnt : 0;
|
||||
$safety_and_privacy['step_three'] = isset($temp_data[2]) ? $temp_data[2]->cnt : 0;
|
||||
|
||||
if (!empty($safety_and_privacy)) {
|
||||
$data['safety_and_privacy'] = $safety_and_privacy;
|
||||
}
|
||||
// safety and privacy (end)
|
||||
|
||||
return response()->json(
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
public function getItems()
|
||||
{
|
||||
return response()->json([
|
||||
'data' => InfoItem::select('item as id', 'item_str as name', 'icon')->where('type', 'item')->groupby('item')->get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function getSubItems(Request $request, $item)
|
||||
{
|
||||
return response()->json([
|
||||
'data' => InfoItem::where('item', $item)->select('id', 'item', 'item_str', 'sub_item_str as name', 'sub_item_unit as unit', 'needs_image', 'needs_end_point', 'sub_item')->get()
|
||||
]);
|
||||
}
|
||||
}
|
||||
54
app/Http/Controllers/V2/Dashboard/ObservedItemController.php
Normal file
54
app/Http/Controllers/V2/Dashboard/ObservedItemController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ObservedItem;
|
||||
use App\Models\RoadPatrol;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ObservedItemController extends Controller
|
||||
{
|
||||
public function details(ObservedItem $observed_item)
|
||||
{
|
||||
return response()->json($observed_item);
|
||||
}
|
||||
|
||||
public function searchByFilter(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'start_date' => 'date_format:Y-m-d',
|
||||
'end_date' => 'date_format:Y-m-d|after_or_equal:start_date',
|
||||
'road_patrol_id' => 'numeric',
|
||||
'item_id' => 'numeric',
|
||||
], [], [
|
||||
'start_date' => 'ساعت شروع گشت',
|
||||
'end_date' => 'ساعت پایان گشت',
|
||||
])->validate();
|
||||
|
||||
$data = ObservedItem::whereNull('road_item_id')
|
||||
->when($request->start_date, function (Builder $query) use ($request) {
|
||||
return $query->whereHas('roadPatrol', function (Builder $query) use ($request) {
|
||||
$query->WhereBetween('start_time', [$request->start_date.' 00:00:00', $request->end_date.' 23:59:59'])->orWhereBetween('end_time', [$request->start_date.' 00:00:00', $request->end_date.' 23:59:59']);
|
||||
});
|
||||
})
|
||||
->when($request->road_patrol_id, function (Builder $query) use ($request) {
|
||||
return $query->where('road_patrol_id', $request->road_patrol_id);
|
||||
})
|
||||
->when($request->item_id, function (Builder $query) use ($request) {
|
||||
return $query->where('item_id', $request->item_id);
|
||||
})
|
||||
->selectRaw('id as item, item_id, item_name, sub_item_id, sub_item_name, local_name')->get();
|
||||
|
||||
// dd($data);
|
||||
if($data->isEmpty()) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return response()->json(
|
||||
$data
|
||||
);
|
||||
}
|
||||
}
|
||||
46
app/Http/Controllers/V2/Dashboard/OtpController.php
Normal file
46
app/Http/Controllers/V2/Dashboard/OtpController.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Facades\Otp\Otp;
|
||||
|
||||
class OtpController extends Controller
|
||||
{
|
||||
public function getOtpToken(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'phone_number' => 'required|digits:11|starts_with:09'
|
||||
], [
|
||||
'starts_with' => ':attribute باید با :values شروع شود.'
|
||||
], [
|
||||
'phone_number' => 'شماره تلفن'
|
||||
]);
|
||||
|
||||
Otp::getOtpToken($request, $request->ip(), $request->phone_number, "کد تایید تلفن همراه سامانه جامع راهداری (RMS) : \n");
|
||||
return response()->json([
|
||||
'message' => 'The code was sent.'
|
||||
]);
|
||||
}
|
||||
|
||||
public function verifyOtp(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'phone_number' => 'required|digits:11',
|
||||
'verification_code' => 'required|digits:6'
|
||||
]);
|
||||
|
||||
$verified = Otp::verifyOtpToken($request->phone_number, $request->verification_code);
|
||||
if (!$verified) {
|
||||
return response()->json([
|
||||
'message' => 'کد تایید اشتباه است.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'token' => '',
|
||||
'message' => 'Code has been verified.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
450
app/Http/Controllers/V2/Dashboard/RoadItemsProjectController.php
Normal file
450
app/Http/Controllers/V2/Dashboard/RoadItemsProjectController.php
Normal file
@@ -0,0 +1,450 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\RoadItemsProject;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\ObservedItem;
|
||||
use App\Models\InfoItem;
|
||||
|
||||
use App\Exports\V2\RoadItems\OperatorCartableExport;
|
||||
use App\Exports\V2\RoadItems\SupervisorCartableExport;
|
||||
|
||||
class RoadItemsProjectController extends Controller
|
||||
{
|
||||
/**
|
||||
* Supervisor(Begin)
|
||||
*/
|
||||
public function supervisorCartable()
|
||||
{
|
||||
if (!auth()->user()->can('show-road-item-supervise-cartable')
|
||||
&& !auth()->user()->can('show-road-item-supervise-cartable-province')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
auth()->user()->addActivityComplete(1148);
|
||||
|
||||
return view('version2.dashboard_pages.road_items.supervise_cartable');
|
||||
}
|
||||
|
||||
public function supervisorShow(Request $request)
|
||||
{
|
||||
$fields = ['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'];
|
||||
|
||||
$aliases = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
|
||||
|
||||
$selectRaw = makeSelectQuery($fields, $aliases);
|
||||
|
||||
if (auth()->user()->can('show-road-item-supervise-cartable')) {
|
||||
$query = RoadItemsProject::where('is_new', 1)
|
||||
->with('files')
|
||||
// ->where(function ($query) {
|
||||
// $query->where('status', 0);
|
||||
// })
|
||||
->selectRaw($selectRaw);
|
||||
} elseif (auth()->user()->can('show-road-item-supervise-cartable-province')) {
|
||||
if (is_null(auth()->user()->province_id)) {
|
||||
return response()->json([
|
||||
'message' => 'استانی برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$query = RoadItemsProject::where('is_new', 1)->with('files')->where('province_id', auth()->user()->province_id)
|
||||
// ->where(function ($query) {
|
||||
// $query->where('status', 0)
|
||||
// ->orWhere('supervisor_id', auth()->user()->id);
|
||||
// })
|
||||
->selectRaw($selectRaw);
|
||||
} else {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$road_items = processDataTable($request, '', $fields, $query);
|
||||
$road_items['data']->map(function ($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(
|
||||
$road_items,
|
||||
$road_items['status'],
|
||||
);
|
||||
}
|
||||
|
||||
public function verifyBySupervisor(Request $request, RoadItemsProject $road_item)
|
||||
{
|
||||
if (Gate::allows('gate-supervise-road-item', $road_item)) {
|
||||
$request->validate([
|
||||
'verify' => 'required|in:1,2',
|
||||
'description' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$status_fa = $request->verify == 1 ? 'تایید شده' : 'عدم تایید';
|
||||
$road_item->update([
|
||||
'status' => $request->verify,
|
||||
'status_fa' => $status_fa,
|
||||
'supervisor_id' => auth()->user()->id,
|
||||
'supervisor_name' => auth()->user()->name,
|
||||
'supervisor_description' => $request->description,
|
||||
'supervising_time' => now(),
|
||||
]);
|
||||
|
||||
auth()->user()->addActivityComplete(1149);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
public function restore(Request $request, RoadItemsProject $road_item)
|
||||
{
|
||||
if (!auth()->user()->can('restore-road-item')) {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
if ($road_item->status == 0) {
|
||||
return response()->json([
|
||||
'message' => 'امکان بازگردانی وضعیت این فعالیت وجود ندارد!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$road_item->update([
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'supervisor_id' => null,
|
||||
'supervisor_description' => null,
|
||||
'supervising_time' => null,
|
||||
'supervisor_name' => null,
|
||||
]);
|
||||
auth()->user()->addActivityComplete(1150);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete(Request $request, RoadItemsProject $road_item)
|
||||
{
|
||||
if (!auth()->user()->can('delete-road-item')) {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
auth()->user()->addActivityComplete(1151);
|
||||
|
||||
$road_item->delete();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function supervisorCartableReport(Request $request)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supervisor(End)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Operator(Begin)
|
||||
*/
|
||||
|
||||
public function operatorCreateView()
|
||||
{
|
||||
if (!auth()->user()->can('create-road-item')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
auth()->user()->addActivityComplete(1153);
|
||||
|
||||
return view('version2.dashboard_pages.road_items.operation_create');
|
||||
}
|
||||
|
||||
public function operatorCartable()
|
||||
{
|
||||
if (!auth()->user()->can('create-road-item')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
auth()->user()->addActivityComplete(1152);
|
||||
|
||||
return view('version2.dashboard_pages.road_items.operation_cartable');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!Auth::user()->can('create-road-item')) {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
if (Auth::user()->edarate_ostani_id || is_null(Auth::user()->city_id)) {
|
||||
return response()->json([
|
||||
'message' => 'امکان ثبت فعالیت برای ادارات استانی و ستادی وجود ندارد!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (is_null(Auth::user()->edarate_shahri_id)) {
|
||||
return response()->json([
|
||||
'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'start_point' => 'required',
|
||||
'item_id' => 'required|integer',
|
||||
'sub_item_id' => 'required|integer',
|
||||
'amount' => 'required|numeric',
|
||||
// 'project_distance' => 'numeric',
|
||||
'before_image' => 'image|max:4096',
|
||||
'after_image' => 'image|max:4096',
|
||||
'observed_item_id' => 'integer|exists:observed_items,id',
|
||||
'activity_date' => 'required|date_format:Y-m-d',
|
||||
'activity_time' => 'required|date_format:H:i',
|
||||
], [], [
|
||||
'activity_date' => 'تاریخ فعالیت',
|
||||
'activity_time' => 'ساعت فعالیت',
|
||||
])->validate();
|
||||
|
||||
$info_item = InfoItem::where('item', $request->item_id)
|
||||
->where('sub_item', $request->sub_item_id)
|
||||
->firstOrFail();
|
||||
|
||||
// $project_distance = null;
|
||||
if ($info_item->needs_end_point) {
|
||||
if (!$request->end_point) {
|
||||
throw ValidationException::withMessages([
|
||||
'end_point' => __('validation.required', ['attribute' => 'end_point']),
|
||||
]);
|
||||
}
|
||||
|
||||
// if (!$request->project_distance) {
|
||||
// throw ValidationException::withMessages([
|
||||
// "project_distance" => __('validation.required', ['attribute' => 'project_distance']),
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// $project_distance = $request->project_distance;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
// prepare data array
|
||||
$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,
|
||||
// 'project_distance' => $project_distance,
|
||||
'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' => Auth::user()->province_id,
|
||||
'province_fa' => Auth::user()->province_fa,
|
||||
'city_id' => Auth::user()->city_id,
|
||||
'city_fa' => Auth::user()->city_fa,
|
||||
'user_name' => Auth::user()->name,
|
||||
'start_way_id' => get_way_id_from_nominatim($start_coordinates[0], $start_coordinates[1]),
|
||||
'end_way_id' => $end_coordinates ? 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' => Auth::user()->edarate_shahri_id,
|
||||
'edarat_type' => EdarateShahri::class,
|
||||
'edarat_name' => Auth::user()->edarate_shahri_name,
|
||||
'activity_date' => $request->activity_date,
|
||||
'activity_time' => $request->activity_time,
|
||||
];
|
||||
|
||||
$before_image = null;
|
||||
$after_image = null;
|
||||
if ($info_item->needs_image) {
|
||||
if ($request->has('after_image')) {
|
||||
$after_image = $request->file('after_image');
|
||||
}
|
||||
if ($request->has('before_image')) {
|
||||
$before_image = $request->file('before_image');
|
||||
}
|
||||
}
|
||||
|
||||
$road_item = RoadItemsProject::store(Auth::user(), $attributes, $before_image, $after_image, $request->observed_item_id);
|
||||
|
||||
if ($road_item == -1) {
|
||||
return response()->json([
|
||||
'message' => 'اقدام مربوطه قبلا رسیدگی شده است.'
|
||||
], 400);
|
||||
}
|
||||
auth()->user()->addActivityComplete(1154);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'succussful'
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, RoadItemsProject $road_item)
|
||||
{
|
||||
// can edit this item?
|
||||
if ($road_item->user_id != auth()->user()->id || $road_item->status != 2) {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'start_point' => 'required',
|
||||
'amount' => 'required|numeric',
|
||||
'before_image' => 'image|max:4096',
|
||||
'after_image' => 'image|max:4096',
|
||||
])->validate();
|
||||
|
||||
$info_item = InfoItem::where('item', $road_item->item)
|
||||
->where('sub_item', $road_item->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/'. $road_item->files[0]->path);
|
||||
|
||||
$after = $request->file('after_image')->store('road_items_projects_new/after', 'public');
|
||||
$road_item->files[0]->update([
|
||||
'path' => $after
|
||||
]);
|
||||
// $road_item->files()->create(['path' => $after]);
|
||||
$urlAfter = "/var/www/rms/public/storage/{$after}";
|
||||
\App\Helpers\Compress::resize($urlAfter);
|
||||
}
|
||||
if ($request->has('before_image')) {
|
||||
Storage::delete('public/'. $road_item->files[1]->path);
|
||||
|
||||
$before = $request->file('before_image')->store('/road_items_projects_new/before', 'public');
|
||||
$road_item->files[1]->update([
|
||||
'path' => $before
|
||||
]);
|
||||
// $road_item->files()->create(['path' => $before]);
|
||||
$urlBefore = "/var/www/rms/public/storage/{$before}";
|
||||
\App\Helpers\Compress::resize($urlBefore);
|
||||
}
|
||||
}
|
||||
|
||||
$road_item->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' => 'در حال بررسی',
|
||||
// 'supervisor_id' => null,
|
||||
// 'supervisor_description' => null,
|
||||
// 'supervising_time' => null,
|
||||
// 'supervisor_name' => null,
|
||||
]);
|
||||
|
||||
|
||||
auth()->user()->addActivityComplete(1155);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'succussful'
|
||||
]);
|
||||
}
|
||||
|
||||
public function operatorShow(Request $request)
|
||||
{
|
||||
if (!auth()->user()->can('create-road-item')) {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$fields = ['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'];
|
||||
|
||||
$aliases = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
|
||||
|
||||
$selectRaw = makeSelectQuery($fields, $aliases);
|
||||
|
||||
$query = RoadItemsProject::with('files')
|
||||
->where('is_new', 1)
|
||||
->where('user_id', auth()->user()->id)
|
||||
->selectRaw($selectRaw);
|
||||
|
||||
$data = processDataTable($request, '', $fields, $query);
|
||||
return response()->json(
|
||||
$data,
|
||||
$data['status'],
|
||||
);
|
||||
}
|
||||
|
||||
public function operatorCartableReport(Request $request)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator(End)
|
||||
*/
|
||||
|
||||
}
|
||||
183
app/Http/Controllers/V2/Dashboard/RoadItemsReportController.php
Normal file
183
app/Http/Controllers/V2/Dashboard/RoadItemsReportController.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use SoapFault;
|
||||
use SoapClient;
|
||||
use App\Models\InfoItem;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\RoadObserved;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
|
||||
class RoadItemsReportController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('version2.dashboard_pages.road_items.reports');
|
||||
}
|
||||
|
||||
public function get_sub_items(Request $request)
|
||||
{
|
||||
$data = InfoItem::all();
|
||||
$items = InfoItem::groupBy('item')->get();
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $data,
|
||||
'items' => $items
|
||||
], 200);
|
||||
}
|
||||
public function get_items(Request $request)
|
||||
{
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$from_date = $request->from_date;
|
||||
$date_to = $request->date_to;
|
||||
$from_date = $from_date.' 00:00:00';
|
||||
$date_to = $date_to.' 23:59:59';
|
||||
} else {
|
||||
$from_date = Date('Y-m-d');
|
||||
$from_date = $from_date.' 00:00:00';
|
||||
$date_to = Date('Y-m-d');
|
||||
$date_to = $date_to.' 23:59:59';
|
||||
}
|
||||
$item = $request->item;
|
||||
$all = array();
|
||||
$all = DB::select(DB::raw(
|
||||
'SELECT 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 FROM road_items_projects WHERE item = '.$item.' AND activity_date_time BETWEEN "'.$from_date.'" AND "'.$date_to.'" and status = 1 GROUP BY p, sub_item'));
|
||||
$country =DB::select(DB::raw(
|
||||
'SELECT 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 FROM road_items_projects WHERE item = '.$item.' AND activity_date_time BETWEEN "'.$from_date.'" AND "'.$date_to.'" and status = 1 GROUP BY sub_item'));
|
||||
$items_fa = InfoItem::where('item', $item)->get();
|
||||
foreach ($all as $value) {
|
||||
foreach ($items_fa as $val) {
|
||||
if ($value->t == $val->sub_item) {
|
||||
$value->u = $val->sub_item_unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $all,
|
||||
'country' =>$country,
|
||||
'items_fa' => $items_fa
|
||||
], 200);
|
||||
}
|
||||
public function get_items_city(Request $request)
|
||||
{
|
||||
$item = $request->item;
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$from_date = $request->from_date.' 00:00:00';
|
||||
$date_to = $request->date_to.' 23:59:59';
|
||||
} else {
|
||||
$from_date = Date('Y-m-d');
|
||||
$from_date = $from_date.' 00:00:00';
|
||||
$date_to = Date('Y-m-d');
|
||||
$date_to = $date_to.' 23:59:59';
|
||||
}
|
||||
$item = $request->item;
|
||||
$province = $request->province_id;
|
||||
$all = array();
|
||||
$all = DB::select(DB::raw(
|
||||
'SELECT 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 FROM road_items_projects WHERE item = '.$item.' AND province_id = '.$province.' AND activity_date_time BETWEEN "'.$from_date.'" AND "'.$date_to.'" and status = 1 GROUP BY ci, sub_item'));
|
||||
$items_fa = InfoItem::where('item', $item)->get();
|
||||
foreach ($all as $value) {
|
||||
foreach ($items_fa as $val) {
|
||||
if ($value->t == $val->sub_item) {
|
||||
$value->u = $val->sub_item_unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $all,
|
||||
'items_fa' => $items_fa
|
||||
], 200);
|
||||
}
|
||||
public function excel1(Request $request)
|
||||
{
|
||||
if (auth()->user()) {
|
||||
auth()->user()->addActivityComplete(1033);
|
||||
}
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$from_date = $request->from_date;
|
||||
$date_to = $request->date_to;
|
||||
} else {
|
||||
$from_date = Date('Y-m-d');
|
||||
$date_to = Date('Y-m-d');
|
||||
}
|
||||
|
||||
if (Auth::user()->username == 'witel' || Auth::user()->username == 'drdanesh') {
|
||||
$sql = "SELECT COUNT(*) AS s,province_id AS p,item AS i
|
||||
FROM road_items_projects WHERE
|
||||
road_items_projects.status = 1 and road_items_projects.activity_date_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59' GROUP BY province_id,item
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,province_id AS p,77 AS i FROM road_patrols
|
||||
WHERE
|
||||
start_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59' GROUP BY province_id
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,-1 AS p,item AS i FROM road_items_projects
|
||||
WHERE road_items_projects.status = 1 and road_items_projects.activity_date_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59'
|
||||
GROUP BY item
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,-1 AS p,77 AS i FROM road_patrols
|
||||
WHERE start_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59'";
|
||||
} else {
|
||||
|
||||
$province_id = Auth::user()->province_id;
|
||||
$sql = "SELECT COUNT(*) AS s,province_id AS p,item AS i
|
||||
FROM road_items_projects WHERE road_items_projects.status = 1 and road_items_projects.province_id = ".$province_id." and
|
||||
road_items_projects.activity_date_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59' GROUP BY province_id,item
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,province_id AS p,77 AS i FROM road_patrols
|
||||
WHERE road_patrols.province_id = ".$province_id." and
|
||||
road_patrols.start_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59' GROUP BY province_id
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,-1 AS p,item AS i FROM road_items_projects
|
||||
WHERE road_items_projects.status = 1 and road_items_projects.province_id = ".$province_id." and road_items_projects.activity_date_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59'
|
||||
GROUP BY item
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,-1 AS p,77 AS i FROM road_patrols
|
||||
WHERE road_patrols.province_id = ".$province_id." and road_patrols.start_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59'";
|
||||
}
|
||||
$data = DB::select(DB::raw($sql));
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $data,
|
||||
], 200);
|
||||
}
|
||||
public function excel1_city(Request $request)
|
||||
{
|
||||
$p = $request->province_id;
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$from_date = $request->from_date;
|
||||
$date_to = $request->date_to;
|
||||
} else {
|
||||
$from_date = Date('Y-m-d');
|
||||
$date_to = Date('Y-m-d');
|
||||
}
|
||||
|
||||
$sql = "SELECT COUNT(*) AS s,edarat_id AS c,item AS i
|
||||
FROM road_items_projects where
|
||||
status = 1 and road_items_projects.activity_date_time between '".$from_date." 00:00:00' and '".$date_to." 23:59:59'
|
||||
and province_id= '".$p."' GROUP BY item,c
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,edare_id AS c,77 AS i FROM road_patrols
|
||||
where
|
||||
road_patrols.start_time between '".$from_date." 00:00:00' and '".$date_to." 23:59:59'
|
||||
and province_id= '".$p."' GROUP BY c";
|
||||
|
||||
$data = DB::select(DB::raw($sql));
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $data,
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
547
app/Http/Controllers/V2/Dashboard/RoadObservationController.php
Normal file
547
app/Http/Controllers/V2/Dashboard/RoadObservationController.php
Normal file
@@ -0,0 +1,547 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Models\RoadObservationHistory;
|
||||
use Carbon\Carbon;
|
||||
use SoapClient;
|
||||
use App\Models\RoadObserved;
|
||||
use App\Models\City;
|
||||
use App\Models\User;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\Contractor;
|
||||
use App\Facades\Sms\Sms;
|
||||
|
||||
use App\Exports\V2\RoadObservation\OperatorCartableExport;
|
||||
use App\Exports\V2\RoadObservation\SupervisorCartableExport;
|
||||
use App\Exports\V2\RoadObservation\PendingComplaintsExport;
|
||||
use App\Exports\V2\RoadObservation\ReportComplaintsExport;
|
||||
|
||||
class RoadObservationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Supervisor(Begin)
|
||||
*/
|
||||
public function supervisorCartable()
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['supervise-fast-react', 'supervise-fast-react-province'])) {
|
||||
abort(403);
|
||||
}
|
||||
auth()->user()->addActivityComplete(1137);
|
||||
|
||||
return view('version2.dashboard_pages.fast_react.supervise_cartable');
|
||||
}
|
||||
|
||||
public function supervisorShow(Request $request)
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['supervise-fast-react', 'supervise-fast-react-province'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
// if($request->dev)
|
||||
// dd($request->query());
|
||||
|
||||
$fields = ['AutoID', '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'];
|
||||
|
||||
$aliases = ['', 'road_observeds_id', '', 'road_observeds_created_at', '', '', '', '', '', '', '', '', '', 'province_id', '', '', 'edarate_shahri_name_fa', '', '', '', ''];
|
||||
|
||||
$selectRaw = makeSelectQuery($fields, $aliases);
|
||||
|
||||
if (auth()->user()->hasPermissionTo('supervise-fast-react')) {
|
||||
|
||||
$query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
// ->where('rms_status', '!=', 0)
|
||||
->whereNotNull('road_observeds.status')
|
||||
// ->where(function ($query) {
|
||||
// $query->where('status', 0)
|
||||
// ->orWhere('supervisor_id', auth()->user()->id);
|
||||
// })
|
||||
->selectRaw($selectRaw)
|
||||
->selectRaw("CONCAT('https://rms.rmto.ir/',image_before) as image_before, CONCAT('https://rms.rmto.ir/', image_after) as image_after");
|
||||
|
||||
} elseif (auth()->user()->hasPermissionTo('supervise-fast-react-province')) {
|
||||
if (is_null(auth()->user()->province_id)) {
|
||||
return response()->json([
|
||||
'message' => 'استانی برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
// ->where('rms_status', '!=', 0)
|
||||
->where('road_observeds.province_id', auth()->user()->province_id)
|
||||
->whereNotNull('road_observeds.status')
|
||||
// ->where(function ($query) {
|
||||
// $query->where('status', 0)
|
||||
// ->orWhere('supervisor_id', auth()->user()->id);
|
||||
// })
|
||||
->selectRaw($selectRaw)
|
||||
->selectRaw("CONCAT('https://rms.rmto.ir/',image_before) as image_before, CONCAT('https://rms.rmto.ir/', image_after) as image_after");
|
||||
}
|
||||
|
||||
$data = processDataTable($request, '', $fields, $query);
|
||||
return response()->json(
|
||||
$data,
|
||||
$data['status'],
|
||||
);
|
||||
}
|
||||
|
||||
public function verifyBySupervisor(Request $request, RoadObserved $roadObserved)
|
||||
{
|
||||
if (Gate::allows('gate-supervise-road-observed', $roadObserved)) {
|
||||
$request->validate([
|
||||
'verify' => 'required|in:1,2',
|
||||
'description' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$status_fa = $request->verify == 1 ? 'تایید شده' : 'عدم تایید';
|
||||
$roadObserved->update([
|
||||
'status' => $request->verify,
|
||||
'status_fa' => $status_fa,
|
||||
'supervisor_id' => auth()->user()->id,
|
||||
'supervisor_name' => auth()->user()->name,
|
||||
'supervisor_description' => $request->description,
|
||||
'supervising_time' => now(),
|
||||
]);
|
||||
auth()->user()->addActivityComplete(1138);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
public function supervisorCartableReport(Request $request)
|
||||
{
|
||||
$name = 'گزارش از کارتابل ارزیابی واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
return Excel::download(new SupervisorCartableExport($request->id, $request->status, $request->fromDate, $request->toDate, $request->province_id), $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supervisor(End)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Operator(Begin)
|
||||
*/
|
||||
public function operatorCartable()
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['show-fast-react-edarate-shahri', 'show-fast-react-province', 'show-fast-react'])) {
|
||||
abort(403);
|
||||
}
|
||||
auth()->user()->addActivityComplete(1139);
|
||||
|
||||
return view('version2.dashboard_pages.fast_react.operation_cartable');
|
||||
}
|
||||
|
||||
public function operatorShow(Request $request)
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['show-fast-react-edarate-shahri', 'show-fast-react-province', 'show-fast-react'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$fields = ['AutoID', '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'];
|
||||
|
||||
$aliases = ['', 'road_observeds_id', '', 'road_observeds_created_at', '', '', '', '', '', '', '', '', '', '', 'province_id', '', '', 'edarate_shahri_name_fa', '', '', '', ''];
|
||||
|
||||
$selectRaw = makeSelectQuery($fields, $aliases);
|
||||
|
||||
if (auth()->user()->hasPermissionTo('show-fast-react')) {
|
||||
$query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->where('rms_status', '!=', 0)
|
||||
->whereNotNull('road_observeds.province_id')
|
||||
->whereNotNull('status')
|
||||
->selectRaw($selectRaw)
|
||||
->selectRaw("CONCAT('https://rms.rmto.ir/',image_before) as image_before, CONCAT('https://rms.rmto.ir/', image_after) as image_after");
|
||||
} elseif (auth()->user()->hasPermissionTo('show-fast-react-province')) {
|
||||
if (is_null(auth()->user()->province_id)) {
|
||||
return response()->json([
|
||||
'message' => 'استانی برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->where('rms_province_id', auth()->user()->province_id)
|
||||
->where('rms_status', '!=', 0)
|
||||
->whereNotNull('road_observeds.province_id')
|
||||
->whereNotNull('status')
|
||||
->selectRaw($selectRaw)
|
||||
->selectRaw("CONCAT('https://rms.rmto.ir/',image_before) as image_before, CONCAT('https://rms.rmto.ir/', image_after) as image_after");
|
||||
} elseif (auth()->user()->hasPermissionTo('show-fast-react-edarate-shahri')) {
|
||||
if (is_null(auth()->user()->edarate_shahri_id)) {
|
||||
return response()->json([
|
||||
'message' => 'اداره ای برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->where('edarate_shahri_id', auth()->user()->edarate_shahri_id)
|
||||
->where('rms_status', '!=', 0)
|
||||
->whereNotNull('road_observeds.province_id')
|
||||
->whereNotNull('status')
|
||||
->selectRaw($selectRaw)
|
||||
->selectRaw("CONCAT('https://rms.rmto.ir/',image_before) as image_before, CONCAT('https://rms.rmto.ir/', image_after) as image_after");
|
||||
}
|
||||
|
||||
$data = processDataTable($request, '', $fields, $query);
|
||||
return response()->json(
|
||||
$data,
|
||||
$data['status'],
|
||||
);
|
||||
}
|
||||
|
||||
public function operatorCartableReport(Request $request)
|
||||
{
|
||||
$name = 'گزارش از کارتابل عملیات واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
return Excel::download(new OperatorCartableExport($request->id, $request->status, $request->fromDate, $request->toDate), $name);
|
||||
}
|
||||
/**
|
||||
* Operator(End)
|
||||
*/
|
||||
|
||||
public function pendingView()
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['show-fast-react-edarate-shahri', 'show-fast-react-province', 'show-fast-react'])) {
|
||||
abort(403);
|
||||
}
|
||||
auth()->user()->addActivityComplete(1140);
|
||||
|
||||
return view('version2.dashboard_pages.fast_react.pending');
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
if (! auth()->user()->permissions()->where('type', 'fastreact')->exists()) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$from_date_array = explode('-', verta()->startYear()->format('Y-m-d'));
|
||||
$from_datetime = implode('-', verta()->getGregorian($from_date_array[0], $from_date_array[1], $from_date_array[2])) . ' 00:00:00';
|
||||
$to_datetime = Carbon::now()->toDateString() . ' 23:59:59';
|
||||
|
||||
if (auth()->user()->hasPermissionTo('show-fast-react')) {
|
||||
$data = RoadObserved::whereBetween('created_at', [$from_datetime, $to_datetime])
|
||||
->selectRaw('sum(case when rms_status = 0 then 1 else 0 end) as pending,
|
||||
sum(case when rms_status != 0 then 1 else 0 end) as done')
|
||||
->get();
|
||||
} elseif (auth()->user()->hasPermissionTo('show-fast-react-province')) {
|
||||
if (!auth()->user()->province_id) {
|
||||
return response()->json([
|
||||
'message' => 'استانی برای شما در سامانه مشخص نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$data = RoadObserved::where('rms_province_id', Auth::user()->province_id)
|
||||
->whereBetween('created_at', [$from_datetime, $to_datetime])
|
||||
->selectRaw('sum(case when rms_status = 0 then 1 else 0 end) as pending,
|
||||
sum(case when rms_status != 0 then 1 else 0 end) as done')
|
||||
->get();
|
||||
} elseif (auth()->user()->hasPermissionTo('show-fast-react-city')) {
|
||||
if (!auth()->user()->city_id) {
|
||||
return response()->json([
|
||||
'message' => 'شهری برای شما در سامانه مشخص نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$data = RoadObserved::where('rms_city_id', Auth::user()->city_id)
|
||||
->whereBetween('created_at', [$from_datetime, $to_datetime])
|
||||
->selectRaw('sum(case when rms_status = 0 then 1 else 0 end) as pending,
|
||||
sum(case when rms_status != 0 then 1 else 0 end) as done')
|
||||
->get();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succuss',
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public function showPending(Request $request)
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['show-fast-react-edarate-shahri', 'show-fast-react-province', 'show-fast-react'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
if($request->dev)
|
||||
dd(auth()->user()->permissions->pluck('name'));
|
||||
|
||||
$fields = ['AutoID', 'road_observeds.id', 'Title', 'road_observeds.created_at', 'lat', 'lng',
|
||||
'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', 'road_observeds.province_id','province_fa', 'city_fa', 'edarate_shahri.name_fa'];
|
||||
|
||||
$aliases = ['', 'road_observeds_id', '', 'road_observeds_created_at', '', '', '', '', '', 'province_id', '', '', 'edarate_shahri_name_fa'];
|
||||
|
||||
$selectRaw = makeSelectQuery($fields, $aliases);
|
||||
|
||||
if (auth()->user()->hasPermissionTo('show-fast-react')) {
|
||||
$query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->where('rms_status', 0)
|
||||
->whereNotNull('edarate_shahri_id')
|
||||
->selectRaw($selectRaw);
|
||||
} elseif (auth()->user()->hasPermissionTo('show-fast-react-province')) {
|
||||
if (is_null(auth()->user()->province_id)) {
|
||||
return response()->json([
|
||||
'message' => 'استانی برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->where('rms_status', 0)
|
||||
->whereNotNull('edarate_shahri_id')
|
||||
->where('road_observeds.province_id', auth()->user()->province_id)
|
||||
->selectRaw($selectRaw);
|
||||
|
||||
// dd(2);
|
||||
} elseif (auth()->user()->hasPermissionTo('show-fast-react-edarate-shahri')) {
|
||||
if (is_null(auth()->user()->edarate_shahri_id)) {
|
||||
return response()->json([
|
||||
'message' => 'اداره ای برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->where('rms_status', 0)
|
||||
->whereNotNull('edarate_shahri_id')
|
||||
->where('edarate_shahri_id', auth()->user()->edarate_shahri_id)
|
||||
->selectRaw($selectRaw);
|
||||
|
||||
}
|
||||
|
||||
$data = processDataTable($request, '', $fields, $query);
|
||||
|
||||
return response()->json(
|
||||
$data,
|
||||
$data['status'],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function referList(int $id)
|
||||
{
|
||||
$edarat_shahri = EdarateShahri::where('province_id', $id)->select('id', 'name_fa', 'province_id')->get();
|
||||
// $contractors = Contractor::where('province_id', $id)->select('id', 'name', 'province_id')->get();
|
||||
|
||||
return response()->json([
|
||||
'status' => 200,
|
||||
'data' => $edarat_shahri,
|
||||
]);
|
||||
}
|
||||
|
||||
public function refer(Request $request, RoadObserved $roadObserved)
|
||||
{
|
||||
$request->validate([
|
||||
'edarate_shahri_id' => 'required|numeric',
|
||||
'refer_description' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($roadObserved->rms_status != 0) {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$roadObserved->update([
|
||||
'edarate_shahri_id' => $request->edarate_shahri_id,
|
||||
]);
|
||||
|
||||
RoadObservationHistory::create([
|
||||
'id' => $roadObserved->id,
|
||||
'user_id' => auth()->user()->id,
|
||||
'action' => 'refer',
|
||||
'description' => $request->refer_description,
|
||||
]);
|
||||
|
||||
auth()->user()->addActivityComplete(1037);
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $roadObserved
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function restore(Request $request, RoadObserved $roadObserved)
|
||||
{
|
||||
if (! auth()->user()->hasPermissionTo('restore-fast-react')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'restore_description' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($roadObserved->image_before) {
|
||||
$before_path = explode('/', $roadObserved->image_before);
|
||||
Storage::delete('public/'. implode('/', array_slice($before_path, 1)));
|
||||
}
|
||||
|
||||
if ($roadObserved->image_after) {
|
||||
$after_path = explode('/', $roadObserved->image_after);
|
||||
Storage::delete('public/'. implode('/', array_slice($after_path, 1)));
|
||||
}
|
||||
|
||||
$roadObserved->update([
|
||||
'image_before' => null,
|
||||
'image_after' => null,
|
||||
'rms_last_activity' => null,
|
||||
'rms_last_activity_fa' => null,
|
||||
'updated_at_fa' => null,
|
||||
'updated_at' => null,
|
||||
'rms_status' => 0,
|
||||
'status' => null,
|
||||
'status_fa' => null,
|
||||
]);
|
||||
|
||||
RoadObservationHistory::create([
|
||||
'id' => $roadObserved->id,
|
||||
'user_id' => auth()->user()->id,
|
||||
'action' => 'restore',
|
||||
'description' => $request->restore_description,
|
||||
]);
|
||||
|
||||
auth()->user()->addActivityComplete(1141);
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $roadObserved
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function handle(Request $request, RoadObserved $roadObserved)
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['show-fast-react-edarate-shahri', 'show-fast-react-province', 'show-fast-react'])) {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$files_path = [];
|
||||
$file_index = 0;
|
||||
$file_time = time();
|
||||
$uuid = \Uuid::generate();
|
||||
if ($request->file('image-before-1')) {
|
||||
$roadObserved->files()->where('path', 'like', '%_image-before-1_%')->delete();
|
||||
|
||||
$files_path[$file_index]['path'] = $request->file('image-before-1')->storeAs(
|
||||
'public/road_observeds',
|
||||
'img4_' . $file_time . '_image-before-1_' . $roadObserved->id . '_' . $uuid.'.'. $request->file('image-before-1')->extension()
|
||||
);
|
||||
$file_index++;
|
||||
$roadObserved->image_before = 'storage/road_observeds/'.'img4_' . $file_time . '_image-before-1_' . $roadObserved->id . '_' . $uuid.'.'. $request->file('image-before-1')->extension();
|
||||
}
|
||||
|
||||
if ($request->file('image-after-1')) {
|
||||
$roadObserved->files()->where('path', 'like', '%_image-after-1_%')->delete();
|
||||
|
||||
$files_path[$file_index]['path'] = $request->file('image-after-1')->storeAs(
|
||||
'public/road_observeds',
|
||||
'img4_' . $file_time . '_image-after-1_' . $roadObserved->id . '_' . $uuid.'.'. $request->file('image-after-1')->extension()
|
||||
);
|
||||
$file_index++;
|
||||
$roadObserved->image_after = 'storage/road_observeds/'.'img4_' . $file_time . '_image-after-1_' . $roadObserved->id . '_' . $uuid.'.'.$request->file('image-after-1')->extension();
|
||||
}
|
||||
|
||||
/////// milad i uncomment this
|
||||
$files = json_encode($files_path);
|
||||
$roadObserved->problemHistories()->create([
|
||||
'user_id' => Auth::user()->id, //$request->user()->id,// 470
|
||||
'previous_rms_status' => $roadObserved->rms_status,
|
||||
'previous_rms_start_latlng' => $roadObserved->rms_start_latlng,
|
||||
'previous_rms_end_latlng' => $roadObserved->rms_end_latlng,
|
||||
'previous_rms_description' => $roadObserved->rms_description,
|
||||
'new_files' => $files
|
||||
]);
|
||||
|
||||
$roadObserved->rms_status = $request->input('rms-status') ?? $roadObserved->rms_status;
|
||||
if ($request->input('rms-start-latlng')) {
|
||||
$roadObserved->rms_start_latlng = explode(',', $request->input('rms-start-latlng')) ?? null;
|
||||
}
|
||||
if ($request->input('rms-end-latlng')) {
|
||||
$roadObserved->rms_end_latlng = explode(',', $request->input('rms-end-latlng')) ?? null;
|
||||
}
|
||||
$roadObserved->rms_description = $request->input('rms-description') ?? $roadObserved->rms_description;
|
||||
|
||||
$now_date_time = Carbon::now();
|
||||
$roadObserved->updated_at_fa = Verta::instance($now_date_time);
|
||||
|
||||
$roadObserved->rms_last_activity_fa = Verta::instance($now_date_time);
|
||||
$roadObserved->rms_last_activity = $now_date_time;
|
||||
|
||||
/**
|
||||
* Hamid edit
|
||||
*/
|
||||
$roadObserved->status = 0;
|
||||
$roadObserved->status_fa = 'در حال بررسی';
|
||||
$roadObserved->save();
|
||||
auth()->user()->addActivityComplete(1142);
|
||||
|
||||
// if ($file_index > 0) {
|
||||
// $roadObserved->files()->createMany($files_path);
|
||||
// }
|
||||
$url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl";
|
||||
try {
|
||||
$array = array('strUserName' => 'vaytelrop',
|
||||
'strPassword' => 'VaYtelROP*2024',
|
||||
'strAutoID' => $roadObserved->fk_RegisteredEventMessage,
|
||||
'strStateID' => ($request->input('rms-status') == 1) ? '2' : '3',
|
||||
'strDescription' => $request->input('rms-description') ?? $roadObserved->rms_description,
|
||||
'strPreviousImageLink' => "https://rms.rmto.ir/".$files,
|
||||
'strNextImageLink' => "https://rms.rmto.ir/".$files,
|
||||
'strRMSDateAndTime' => $roadObserved->updated_at
|
||||
);
|
||||
$soap_client = new SoapClient($url);
|
||||
$result = $soap_client->UpdateInfo_RoadObservedProblems($array);
|
||||
} catch (SoapFault $e) {
|
||||
|
||||
$msg = "error in send to nikarayan at".date("Y-m-d H:i:s")."\n".'rms: error in get road observation webservice babe!!!!'."\n";
|
||||
$msg .= $e->getMessage();
|
||||
|
||||
Sms::sendSms(env('RMS_CTO_PHONE_NUMBER'), $msg);
|
||||
}
|
||||
///// sms send
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => 1,
|
||||
'data' => $roadObserved,
|
||||
'nikarayan_res' => $result
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function pendingReport(Request $request)
|
||||
{
|
||||
$name = 'گزارش از رسیدگی به شکایات واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
return Excel::download(new PendingComplaintsExport($request->province_id, $request->fromDate, $request->toDate), $name);
|
||||
}
|
||||
|
||||
public function report(Request $request)
|
||||
{
|
||||
$name = 'گزارش رسیدگی به شکایات واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
|
||||
return Excel::download(new ReportComplaintsExport($request->province_id, $request->fromDate, $request->toDate), $name);
|
||||
}
|
||||
|
||||
public function roadObserveDetail(RoadObserved $roadObserved)
|
||||
{
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => 1,
|
||||
'data' => $roadObserved->load("edarateShahri"),
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use SoapFault;
|
||||
use SoapClient;
|
||||
use App\Models\InfoItem;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\RoadObserved;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
|
||||
class RoadObservationReportController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('version2.dashboard_pages.fast_react.by_table_report');
|
||||
}
|
||||
|
||||
public function reportTable(Request $request)
|
||||
{
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$from_date = $request->from_date;
|
||||
$date_to = $request->date_to;
|
||||
$from_date = $from_date.' 00:00:00';
|
||||
$date_to = $date_to.' 23:59:59';
|
||||
} else {
|
||||
$from_date = Date('Y-m-d');
|
||||
$from_date = $from_date.' 00:00:00';
|
||||
$date_to = Date('Y-m-d');
|
||||
$date_to = $date_to.' 23:59:59';
|
||||
}
|
||||
|
||||
|
||||
$fields = ['AutoID', 'road_observeds.id', 'Title', 'road_observeds.created_at', 'lat', 'lng',
|
||||
'FeatureTypeTitle', 'Description', 'MobileForSendEventSms', 'road_observeds.province_id','province_fa', 'city_fa', 'edarate_shahri.name_fa', 'rms_last_activity_fa', 'rms_description'];
|
||||
|
||||
$aliases = ['', 'road_observeds_id', '', 'road_observeds_created_at', '', '', '', '', '', 'province_id', '', '', 'edarate_shahri_name_fa', '', ''];
|
||||
|
||||
$selectRaw = makeSelectQuery($fields, $aliases);
|
||||
|
||||
$query = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')
|
||||
->where('rms_status', "<>", 0)
|
||||
->whereNotNull('edarate_shahri_id')
|
||||
->whereBetween('road_observeds.created_at', [$from_date . ' 00:00:00', $date_to . ' 23:59:59'])
|
||||
->selectRaw($selectRaw);
|
||||
|
||||
$data = processDataTable($request, '', $fields, $query);
|
||||
|
||||
// $data = RoadObserved::leftjoin('edarate_shahri', 'road_observeds.edarate_shahri_id', 'edarate_shahri.id')->select('road_observeds.id', 'province_fa', 'city_fa', 'FeatureTypeTitle', 'road_observeds.created_at', 'Title', 'Description', 'MobileForSendEventSms', 'lat', 'lng', 'rms_description', 'road_observeds.updated_at', 'rms_status', 'rms_last_activity_fa', 'rms_description', 'AutoId', 'edarate_shahri.name_fa')
|
||||
// ->whereIn('fk_FeatureType', ['1', '2', '3', '4', '5', '6'])
|
||||
// ->where('rms_status', "<>", 1)
|
||||
// ->get();
|
||||
|
||||
// $all = DB::select(DB::raw(
|
||||
// 'SELECT
|
||||
// "کشوری" as province_fa,
|
||||
// -1 as province_id,
|
||||
// COUNT(*) tedade,
|
||||
// SUM(tedad_mavarede_moshede_shode) as tedad_mavarede_moshede_shode,
|
||||
// SUM(tedad_mavarede_peygiri_shode) as tedad_mavarede_peygiri_shode,
|
||||
// SUM(tedad_faliyat_sabt_shode) as tedad_faliyat_sabt_shode,
|
||||
// ROUND(SUM(distance)) as masafat_tey_shode
|
||||
// FROM (SELECT
|
||||
// province_id,
|
||||
// province_fa,
|
||||
// distance,
|
||||
// (SELECT COUNT(*) FROM `observed_items` oi WHERE rp.`id`= oi.road_patrol_id) AS tedad_mavarede_moshede_shode,
|
||||
// (SELECT COUNT(*) FROM `observed_items` oii WHERE rp.`id`= oii.road_patrol_id AND oii.road_item_id IS NOT NULL AND priority IS NOT NULL) AS tedad_mavarede_peygiri_shode,
|
||||
// (SELECT COUNT(*) FROM `observed_items` oii WHERE rp.`id`= oii.road_patrol_id AND oii.road_item_id IS NOT NULL AND priority IS NULL) AS tedad_faliyat_sabt_shode
|
||||
// FROM `road_patrols` rp where rp.start_time BETWEEN "'.$from_date.'" AND "'.$date_to.'") temp
|
||||
// union
|
||||
// SELECT
|
||||
// province_fa,
|
||||
// province_id,
|
||||
// COUNT(*) tedade,
|
||||
// SUM(tedad_mavarede_moshede_shode) as tedad_mavarede_moshede_shode,
|
||||
// SUM(tedad_mavarede_peygiri_shode) as tedad_mavarede_peygiri_shode,
|
||||
// SUM(tedad_faliyat_sabt_shode) as tedad_faliyat_sabt_shode,
|
||||
// ROUND(SUM(distance)) as masafat_tey_shode
|
||||
// FROM (SELECT
|
||||
// province_id,
|
||||
// province_fa,
|
||||
// distance,
|
||||
// (SELECT COUNT(*) FROM `observed_items` oi WHERE rp.`id`= oi.road_patrol_id) AS tedad_mavarede_moshede_shode,
|
||||
// (SELECT COUNT(*) FROM `observed_items` oii WHERE rp.`id`= oii.road_patrol_id AND oii.road_item_id IS NOT NULL AND priority IS NOT NULL) AS tedad_mavarede_peygiri_shode,
|
||||
// (SELECT COUNT(*) FROM `observed_items` oii WHERE rp.`id`= oii.road_patrol_id AND oii.road_item_id IS NOT NULL AND priority IS NULL) AS tedad_faliyat_sabt_shode
|
||||
// FROM `road_patrols` rp where rp.start_time BETWEEN "'.$from_date.'" AND "'.$date_to.'") temp
|
||||
// GROUP BY province_id
|
||||
// '
|
||||
// ));
|
||||
return response()->json(
|
||||
$data,
|
||||
$data['status'],
|
||||
);
|
||||
}
|
||||
|
||||
public function CityPatrolData(Request $request)
|
||||
{
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$from_date = $request->from_date;
|
||||
$date_to = $request->date_to;
|
||||
$from_date = $from_date.' 00:00:00';
|
||||
$date_to = $date_to.' 23:59:59';
|
||||
} else {
|
||||
$from_date = Date('Y-m-d');
|
||||
$from_date = $from_date.' 00:00:00';
|
||||
$date_to = Date('Y-m-d');
|
||||
$date_to = $date_to.' 23:59:59';
|
||||
}
|
||||
|
||||
$all = DB::select(DB::raw(
|
||||
'SELECT
|
||||
province_fa,
|
||||
province_id,
|
||||
city_id,
|
||||
city_fa,
|
||||
COUNT(*) tedade,
|
||||
SUM(tedad_mavarede_moshede_shode) as tedad_mavarede_moshede_shode,
|
||||
SUM(tedad_mavarede_peygiri_shode) as tedad_mavarede_peygiri_shode,
|
||||
SUM(tedad_faliyat_sabt_shode) as tedad_faliyat_sabt_shode,
|
||||
ROUND(SUM(distance)) as masafat_tey_shode
|
||||
FROM (SELECT
|
||||
province_id,
|
||||
province_fa,
|
||||
city_id,
|
||||
city_fa,
|
||||
distance,
|
||||
(SELECT COUNT(*) FROM `observed_items` oi WHERE rp.`id`= oi.road_patrol_id) AS tedad_mavarede_moshede_shode,
|
||||
(SELECT COUNT(*) FROM `observed_items` oii WHERE rp.`id`= oii.road_patrol_id AND oii.road_item_id IS NOT NULL AND priority IS NOT NULL) AS tedad_mavarede_peygiri_shode,
|
||||
(SELECT COUNT(*) FROM `observed_items` oii WHERE rp.`id`= oii.road_patrol_id AND oii.road_item_id IS NOT NULL AND priority IS NULL) AS tedad_faliyat_sabt_shode
|
||||
FROM `road_patrols` rp where rp.province_id = "'.$request->province_id.'" AND rp.start_time BETWEEN "'.$from_date.'" AND "'.$date_to.'") temp
|
||||
GROUP BY city_id
|
||||
'
|
||||
));
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $all,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function get_sub_items(Request $request)
|
||||
{
|
||||
$data = InfoItem::all();
|
||||
$items = InfoItem::groupBy('item')->get();
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $data,
|
||||
'items' => $items
|
||||
], 200);
|
||||
}
|
||||
public function get_items(Request $request)
|
||||
{
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$from_date = $request->from_date;
|
||||
$date_to = $request->date_to;
|
||||
$from_date = $from_date.' 00:00:00';
|
||||
$date_to = $date_to.' 23:59:59';
|
||||
} else {
|
||||
$from_date = Date('Y-m-d');
|
||||
$from_date = $from_date.' 00:00:00';
|
||||
$date_to = Date('Y-m-d');
|
||||
$date_to = $date_to.' 23:59:59';
|
||||
}
|
||||
$item = $request->item;
|
||||
$all = array();
|
||||
$all = DB::select(DB::raw(
|
||||
'SELECT 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 FROM road_items_projects WHERE item = '.$item.' AND activity_date_time BETWEEN "'.$from_date.'" AND "'.$date_to.'" and status = 1 GROUP BY p, sub_item'));
|
||||
$country =DB::select(DB::raw(
|
||||
'SELECT 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 FROM road_items_projects WHERE item = '.$item.' AND activity_date_time BETWEEN "'.$from_date.'" AND "'.$date_to.'" and status = 1 GROUP BY sub_item'));
|
||||
$items_fa = InfoItem::where('item', $item)->get();
|
||||
foreach ($all as $value) {
|
||||
foreach ($items_fa as $val) {
|
||||
if ($value->t == $val->sub_item) {
|
||||
$value->u = $val->sub_item_unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $all,
|
||||
'country' =>$country,
|
||||
'items_fa' => $items_fa
|
||||
], 200);
|
||||
}
|
||||
public function get_items_city(Request $request)
|
||||
{
|
||||
$item = $request->item;
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$from_date = $request->from_date.' 00:00:00';
|
||||
$date_to = $request->date_to.' 23:59:59';
|
||||
} else {
|
||||
$from_date = Date('Y-m-d');
|
||||
$from_date = $from_date.' 00:00:00';
|
||||
$date_to = Date('Y-m-d');
|
||||
$date_to = $date_to.' 23:59:59';
|
||||
}
|
||||
$item = $request->item;
|
||||
$province = $request->province_id;
|
||||
$all = array();
|
||||
$all = DB::select(DB::raw(
|
||||
'SELECT 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, city_id AS ci FROM road_items_projects WHERE item = '.$item.' AND province_id = '.$province.' AND activity_date_time BETWEEN "'.$from_date.'" AND "'.$date_to.'" and status = 1 GROUP BY ci, sub_item'));
|
||||
$items_fa = InfoItem::where('item', $item)->get();
|
||||
foreach ($all as $value) {
|
||||
foreach ($items_fa as $val) {
|
||||
if ($value->t == $val->sub_item) {
|
||||
$value->u = $val->sub_item_unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $all,
|
||||
'items_fa' => $items_fa
|
||||
], 200);
|
||||
}
|
||||
public function excel1(Request $request)
|
||||
{
|
||||
if (auth()->user()) {
|
||||
auth()->user()->addActivityComplete(1033);
|
||||
}
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$from_date = $request->from_date;
|
||||
$date_to = $request->date_to;
|
||||
} else {
|
||||
$from_date = Date('Y-m-d');
|
||||
$date_to = Date('Y-m-d');
|
||||
}
|
||||
|
||||
if (Auth::user()->username == 'witel' || Auth::user()->username == 'drdanesh') {
|
||||
$sql = "SELECT COUNT(*) AS s,province_id AS p,item AS i
|
||||
FROM road_items_projects WHERE
|
||||
road_items_projects.status = 1 and road_items_projects.activity_date_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59' GROUP BY province_id,item
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,province_id AS p,77 AS i FROM road_patrols
|
||||
WHERE
|
||||
start_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59' GROUP BY province_id
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,-1 AS p,item AS i FROM road_items_projects
|
||||
WHERE road_items_projects.status = 1 and road_items_projects.activity_date_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59'
|
||||
GROUP BY item
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,-1 AS p,77 AS i FROM road_patrols
|
||||
WHERE start_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59'";
|
||||
} else {
|
||||
|
||||
$province_id = Auth::user()->province_id;
|
||||
$sql = "SELECT COUNT(*) AS s,province_id AS p,item AS i
|
||||
FROM road_items_projects WHERE road_items_projects.status = 1 and road_items_projects.province_id = ".$province_id." and
|
||||
road_items_projects.activity_date_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59' GROUP BY province_id,item
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,province_id AS p,77 AS i FROM road_patrols
|
||||
WHERE road_patrols.province_id = ".$province_id." and
|
||||
road_patrols.start_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59' GROUP BY province_id
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,-1 AS p,item AS i FROM road_items_projects
|
||||
WHERE road_items_projects.status = 1 and road_items_projects.province_id = ".$province_id." and road_items_projects.activity_date_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59'
|
||||
GROUP BY item
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,-1 AS p,77 AS i FROM road_patrols
|
||||
WHERE road_patrols.province_id = ".$province_id." and road_patrols.start_time BETWEEN '".$from_date." 00:00:00' and '".$date_to." 23:59:59'";
|
||||
}
|
||||
// dd($sql);
|
||||
$data = DB::select(DB::raw($sql));
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $data,
|
||||
], 200);
|
||||
}
|
||||
public function excel1_city(Request $request)
|
||||
{
|
||||
$p = $request->province_id;
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$from_date = $request->from_date;
|
||||
$date_to = $request->date_to;
|
||||
} else {
|
||||
$from_date = Date('Y-m-d');
|
||||
$date_to = Date('Y-m-d');
|
||||
}
|
||||
|
||||
$sql = "SELECT COUNT(*) AS s,city_id AS c,item AS i
|
||||
FROM road_items_projects where
|
||||
status = 1 and road_items_projects.activity_date_time between '".$from_date." 00:00:00' and '".$date_to." 23:59:59'
|
||||
and province_id= '".$p."' GROUP BY item,city_id
|
||||
UNION
|
||||
SELECT COUNT(*) AS s,city_id AS c,77 AS i FROM road_patrols
|
||||
where
|
||||
road_patrols.start_time between '".$from_date." 00:00:00' and '".$date_to." 23:59:59'
|
||||
and province_id= '".$p."' GROUP BY city_id";
|
||||
|
||||
$data = DB::select(DB::raw($sql));
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $data,
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,518 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Facades\Sms\Sms;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use App\Facades\Otp\Otp;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use App\Models\RoadPatrol;
|
||||
use App\Models\RoadItemsProject;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\InfoItem;
|
||||
|
||||
use App\Exports\V2\RoadPatrol\OperatorCartableExport;
|
||||
use App\Exports\V2\RoadPatrol\SupervisorCartableExport;
|
||||
|
||||
class RoadPatrolProjectController extends Controller
|
||||
{
|
||||
/**
|
||||
* Supervisor(Begin)
|
||||
*/
|
||||
public function supervisorCartable()
|
||||
{
|
||||
if (!auth()->user()->can('show-road-patrol-supervise-cartable') && !auth()->user()->can('show-road-patrol-supervise-cartable-province')) {
|
||||
abort(403);
|
||||
}
|
||||
auth()->user()->addActivityComplete(1143);
|
||||
|
||||
return view('version2.dashboard_pages.road_patrols.supervise_cartable');
|
||||
}
|
||||
|
||||
public function supervisorShow(Request $request)
|
||||
{
|
||||
$fields = ['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'];
|
||||
|
||||
$aliases = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
|
||||
|
||||
$selectRaw = makeSelectQuery($fields, $aliases);
|
||||
|
||||
if (auth()->user()->can('show-road-patrol-supervise-cartable')) {
|
||||
$query = RoadPatrol::selectRaw($selectRaw);
|
||||
} elseif (auth()->user()->can('show-road-patrol-supervise-cartable-province')) {
|
||||
if (is_null(auth()->user()->province_id)) {
|
||||
return response()->json([
|
||||
'message' => 'استانی برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$query = RoadPatrol::where('province_id', auth()->user()->province_id)
|
||||
// ->where(function ($query) {
|
||||
// $query->where('status', 0)
|
||||
// ->orWhere('supervisor_id', auth()->user()->id);
|
||||
// })
|
||||
->selectRaw($selectRaw);
|
||||
} else {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$road_patrols = processDataTable($request, '', $fields, $query);
|
||||
$road_patrols['data']->map(function ($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(
|
||||
$road_patrols,
|
||||
$road_patrols['status'],
|
||||
);
|
||||
}
|
||||
|
||||
public function delete(Request $request, RoadPatrol $road_patrol)
|
||||
{
|
||||
$request->validate([
|
||||
'type' => 'required|in:1,2' // {1 = > partial , 2 => complete}
|
||||
]);
|
||||
|
||||
if ($request->type == 1) {
|
||||
if (! auth()->user()->can('partial-delete-road-patrol')) {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
try {
|
||||
\DB::transaction(function () use ($road_patrol) {
|
||||
$road_patrol->observedItems()->delete();
|
||||
$road_patrol->delete();
|
||||
});
|
||||
} catch (\Throwable $th) {
|
||||
throw $th;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (! auth()->user()->can('complete-delete-road-patrol')) {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
try {
|
||||
\DB::transaction(function () use ($road_patrol) {
|
||||
if ($road_patrol->observedItems) {
|
||||
foreach ($road_patrol->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);
|
||||
|
||||
$road_patrol->delete();
|
||||
});
|
||||
} catch (\Throwable $th) {
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'succussful'
|
||||
]);
|
||||
}
|
||||
|
||||
public function supervisorCartableReport(Request $request)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supervisor(End)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Operator(Begin)
|
||||
*/
|
||||
public function operatorCartable()
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('add-road-patrol')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
auth()->user()->addActivityComplete(1145);
|
||||
|
||||
return view('version2.dashboard_pages.road_patrols.operation_cartable');
|
||||
}
|
||||
|
||||
public function operatorCreateView()
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('add-road-patrol')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
auth()->user()->addActivityComplete(1146);
|
||||
|
||||
return view('version2.dashboard_pages.road_patrols.operation_create');
|
||||
}
|
||||
|
||||
public function operatorShow(Request $request)
|
||||
{
|
||||
if (!auth()->user()->can('add-road-patrol')) {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$fields = ['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'];
|
||||
|
||||
$aliases = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
|
||||
|
||||
$selectRaw = makeSelectQuery($fields, $aliases);
|
||||
|
||||
$query = RoadPatrol::where('operator_id', auth()->user()->id)
|
||||
->selectRaw($selectRaw);
|
||||
|
||||
$data = processDataTable($request, '', $fields, $query);
|
||||
return response()->json(
|
||||
$data,
|
||||
$data['status'],
|
||||
);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasPermissionTo('add-road-patrol')) {
|
||||
return response()->json([
|
||||
'message' => 'access to the requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
if (Auth::user()->edarate_ostani_id || is_null(Auth::user()->city_id)) {
|
||||
return response()->json([
|
||||
'message' => 'امکان ثبت فعالیت برای ادارات استانی وجود ندارد!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (is_null(Auth::user()->edarate_shahri_id)) {
|
||||
return response()->json([
|
||||
'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'start_point' => 'required',
|
||||
'end_point' => 'required',
|
||||
'distance' => 'numeric',
|
||||
'officer_name' => 'required',
|
||||
'officer_plaque' => 'required',
|
||||
'officer_phone_number' => 'required|digits:11',
|
||||
'start_time' => 'required|date_format:Y-m-d H:i',
|
||||
'end_time' => 'required|date_format:Y-m-d H:i|after:start_time',
|
||||
'description' => 'string',
|
||||
|
||||
'observed_items' => 'array',
|
||||
'observed_items.*.item_id' => 'required|integer',
|
||||
'observed_items.*.sub_item_id' => 'required|integer',
|
||||
'observed_items.*.local_name' => 'required',
|
||||
'observed_items.*.description' => '',
|
||||
'observed_items.*.instant_action' => 'required|in:0,1',
|
||||
|
||||
// road item projects fields
|
||||
'observed_items.*.start_point' => 'required',
|
||||
'observed_items.*.end_point' => '',
|
||||
'observed_items.*.amount' => 'numeric',
|
||||
'observed_items.*.before_image' => 'image|max:4096',
|
||||
'observed_items.*.after_image' => 'image|max:4096',
|
||||
'observed_items.*.priority' => 'integer|in:1,2,3',
|
||||
'observed_items.*.priority_fa' => 'string',
|
||||
], [], [
|
||||
'start_time' => 'ساعت شروع گشت',
|
||||
'end_time' => 'ساعت پایان گشت',
|
||||
])->validate();
|
||||
|
||||
$start_coordinates = explode(',', $request->start_point);
|
||||
$end_coordinates = explode(',', $request->end_point);
|
||||
|
||||
$edare_id = auth()->user()->edarate_shahri_id ?? auth()->user()->edarate_ostani_id;
|
||||
$edare_name = auth()->user()->edarate_shahri_id ? auth()->user()->edarate_shahri_name : auth()->user()->edarate_ostani_name;
|
||||
|
||||
try {
|
||||
$road_patrol = \DB::transaction(function () use ($request, $start_coordinates, $end_coordinates, $edare_id, $edare_name) {
|
||||
if (!$request->observed_items && !$request->description) {
|
||||
throw ValidationException::withMessages([
|
||||
"description" => __('validation.required', ['attribute' => 'description']),
|
||||
]);
|
||||
}
|
||||
|
||||
$road_patrol = RoadPatrol::create([
|
||||
'start_lat' => $start_coordinates[0],
|
||||
'start_lon' => $start_coordinates[1],
|
||||
'end_lat' => $end_coordinates[0],
|
||||
'end_lon' => $end_coordinates[1],
|
||||
'officer_name' => $request->officer_name,
|
||||
'officer_phone_number' => $request->officer_phone_number,
|
||||
'officer_plaque' => $request->officer_plaque,
|
||||
'operator_id' => auth()->user()->id,
|
||||
'operator_name' => auth()->user()->name,
|
||||
'province_id' => auth()->user()->province_id,
|
||||
'province_fa' => auth()->user()->province_fa,
|
||||
'city_id' => auth()->user()->city_id,
|
||||
'city_fa' => auth()->user()->city_fa,
|
||||
'edare_id' => $edare_id,
|
||||
'edare_name' => $edare_name,
|
||||
'start_way_id' => get_way_id_from_nominatim($start_coordinates[0], $start_coordinates[1]),
|
||||
'end_way_id' => get_way_id_from_nominatim($end_coordinates[0], $end_coordinates[1]),
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'distance' => $request->distance,
|
||||
'start_time' => $request->start_time,
|
||||
'end_time' => $request->end_time,
|
||||
'description' => $request->description ?? null,
|
||||
]);
|
||||
|
||||
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) {
|
||||
if (!isset($item['priority'])) {
|
||||
throw ValidationException::withMessages([
|
||||
"observed_items.$index.priority" => __('validation.required', ['attribute' => 'priority']),
|
||||
]);
|
||||
}
|
||||
|
||||
if (!isset($item['priority_fa'])) {
|
||||
throw ValidationException::withMessages([
|
||||
"observed_items.$index.priority_fa" => __('validation.required', ['attribute' => 'priority_fa']),
|
||||
]);
|
||||
}
|
||||
|
||||
$observed_item->priority = $item['priority'];
|
||||
$observed_item->priority_fa = $item['priority_fa'];
|
||||
$observed_item->save();
|
||||
} elseif ($item['instant_action'] == 1) {
|
||||
// $distance = null;
|
||||
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']);
|
||||
|
||||
// if (!isset($item['distance'])) {
|
||||
// throw ValidationException::withMessages([
|
||||
// "observed_items.$index.distance" => __('validation.required', ['attribute' => 'distance']),
|
||||
// ]);
|
||||
// }
|
||||
// $distance = $item['distance'];
|
||||
}
|
||||
|
||||
$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'];
|
||||
}
|
||||
|
||||
if (!isset($item['amount'])) {
|
||||
throw ValidationException::withMessages([
|
||||
"observed_items.$index.amount" => __('validation.required', ['attribute' => 'amount']),
|
||||
]);
|
||||
}
|
||||
|
||||
$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,
|
||||
// 'project_distance' => $distance,
|
||||
'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' => auth()->user()->province_id,
|
||||
'province_fa' => auth()->user()->province_fa,
|
||||
'city_id' => auth()->user()->city_id,
|
||||
'city_fa' => auth()->user()->city_fa,
|
||||
'user_name' => auth()->user()->name,
|
||||
'start_way_id' => get_way_id_from_nominatim($item_start_coordinates[0], $item_start_coordinates[1]),
|
||||
'end_way_id' => $item_end_coordinates ? 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' => auth()->user()->edarate_shahri_id,
|
||||
'edarat_type' => EdarateShahri::class,
|
||||
'edarat_name' => auth()->user()->edarate_shahri_name,
|
||||
'activity_date' => $activity_date->format('Y-m-d'),
|
||||
'activity_time' => $activity_date->format('H:i:s'),
|
||||
];
|
||||
|
||||
$road_item = RoadItemsProject::store(auth()->user(), $attributes, $before_image, $after_image, $observed_item->id);
|
||||
|
||||
if ($road_item == -1) {
|
||||
return response()->json([
|
||||
'message' => 'اقدام مربوطه قبلا رسیدگی شده است.'
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auth()->user()->addActivityComplete(1147);
|
||||
|
||||
// Otp::useOtpToken($request->officer_phone_number, $request->verification_code);
|
||||
|
||||
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;
|
||||
});
|
||||
} catch (\Throwable $th) {
|
||||
throw $th;
|
||||
}
|
||||
|
||||
|
||||
return response()->json([
|
||||
'road_patrol_id' => $road_patrol->id,
|
||||
'message' => 'succussful'
|
||||
]);
|
||||
}
|
||||
|
||||
public function getReport(Request $request, RoadPatrol $road_patrol)
|
||||
{
|
||||
// if (!auth()->user()->hasPermissionTo('add-road-patrol')) {
|
||||
// abort(403);
|
||||
// }
|
||||
|
||||
$data = [
|
||||
'serial_no' => $road_patrol->id,
|
||||
'province_fa' => $road_patrol->province_fa,
|
||||
'edare_name' => $road_patrol->edare_name,
|
||||
'start_time' => $road_patrol->start_time,
|
||||
'end_time' => $road_patrol->end_time,
|
||||
'officer_name' => $road_patrol->officer_name,
|
||||
'officer_plaque' => $road_patrol->officer_plaque,
|
||||
'officer_phone_number' => $road_patrol->officer_phone_number,
|
||||
'created_at' => $road_patrol->created_at
|
||||
];
|
||||
|
||||
$observed_items = array();
|
||||
if($road_patrol->observedItems) {
|
||||
foreach ($road_patrol->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 view('version2.dashboard_pages.road_patrols.report', ['data' => $data]);
|
||||
}
|
||||
|
||||
public function getAllDataToMap(Request $request)
|
||||
{
|
||||
$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::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 response()->json([
|
||||
'status' => 'succeed',
|
||||
'count' => count($data),
|
||||
'message' => '',
|
||||
'data' => $data
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function detail(RoadPatrol $road_patrol)
|
||||
{
|
||||
return response()->json($road_patrol, 200);
|
||||
}
|
||||
|
||||
public function operatorCartableReport(Request $request)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator(End)
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\RoadPatrolProject;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
use App\Exports\V2\RoadPatrol\RoadPatrolTable\AllSheets as RoadPatrolTable;
|
||||
|
||||
class RoadPatrolReportController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('version2.dashboard_pages.road_patrols.by_table_report');
|
||||
}
|
||||
|
||||
public function provincePatrolData(Request $request)
|
||||
{
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$from_date = $request->from_date.' 00:00:00';
|
||||
$date_to = $request->date_to.' 23:59:59';
|
||||
} else {
|
||||
$from_date = Date('Y-m-d').' 00:00:00';
|
||||
$date_to = Date('Y-m-d').' 23:59:59';
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => RoadPatrolProject::provincePatrolData($from_date, $date_to),
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function edarehPatrolData(Request $request)
|
||||
{
|
||||
|
||||
if ($request->from_date && $request->date_to) {
|
||||
$from_date = $request->from_date.' 00:00:00';
|
||||
$date_to = $request->date_to.' 23:59:59';
|
||||
} else {
|
||||
$from_date = Date('Y-m-d').' 00:00:00';
|
||||
$date_to = Date('Y-m-d').' 23:59:59';
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
"province_id" => "required",
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => RoadPatrolProject::edarehPatrolData($from_date, $date_to, $request->province_id),
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function roadPatrolsReportTable(Request $request)
|
||||
{
|
||||
$name = 'گزارش از گشت راهداری و ترابری ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new RoadPatrolTable($request->from_date, $request->date_to), $name);
|
||||
}
|
||||
}
|
||||
339
app/Http/Controllers/V2/Dashboard/SafetyAndPrivacyController.php
Normal file
339
app/Http/Controllers/V2/Dashboard/SafetyAndPrivacyController.php
Normal file
@@ -0,0 +1,339 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\RoadObservationHistory;
|
||||
use App\Models\RoadObserved;
|
||||
use App\Models\City;
|
||||
use App\Models\User;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\Contractor;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Models\SafetyAndPrivacy;
|
||||
use App\Models\InfoItem;
|
||||
|
||||
class SafetyAndPrivacyController extends Controller
|
||||
{
|
||||
public function operatorCartable()
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['show-safety-and-privacy-operator-cartable', 'show-safety-and-privacy-operator-cartable-province', 'show-safety-and-privacy-operator-cartable-edarate-shahri'])) {
|
||||
abort(403);
|
||||
}
|
||||
auth()->user()->addActivityComplete(1133);
|
||||
|
||||
return view('version2.dashboard_pages.safety_and_privacy.operation_cartable');
|
||||
}
|
||||
|
||||
public function operatorShow(Request $request)
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['show-safety-and-privacy-operator-cartable', 'show-safety-and-privacy-operator-cartable-province', 'show-safety-and-privacy-operator-cartable-edarate-shahri'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$fields = ['id','lat','lon','province_id','province_fa','city_id','city_fa','edare_shahri_id','edare_shahri_name',
|
||||
'recognize_picture','action_picture','operator_id','operator_name','way_id','created_at','updated_at','step','judiciary_document',
|
||||
'judiciary_document_upload_date','info_id','info_fa','activity_date_time','judiciary_document_upload_date','action_picture_document_upload_date',
|
||||
'step_fa'];
|
||||
|
||||
$aliases = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '','','','','','','','','',''];
|
||||
|
||||
$selectRaw = makeSelectQuery($fields, $aliases);
|
||||
|
||||
if (auth()->user()->hasPermissionTo('show-safety-and-privacy-operator-cartable')) {
|
||||
$query = SafetyAndPrivacy::selectRaw($selectRaw);
|
||||
} elseif (auth()->user()->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) {
|
||||
if (is_null(auth()->user()->province_id)) {
|
||||
return response()->json([
|
||||
'message' => 'استانی برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$query = SafetyAndPrivacy::where('province_id', auth()->user()->province_id)
|
||||
->selectRaw($selectRaw);
|
||||
} elseif (auth()->user()->hasPermissionTo('show-safety-and-privacy-operator-cartable-edarate-shahri')) {
|
||||
if (is_null(auth()->user()->edarate_shahri_id)) {
|
||||
return response()->json([
|
||||
'message' => 'اداره ای برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$query = SafetyAndPrivacy::where('edare_shahri_id', auth()->user()->edarate_shahri_id)
|
||||
->selectRaw($selectRaw);
|
||||
}
|
||||
|
||||
$data = processDataTable($request, '', $fields, $query);
|
||||
|
||||
return response()->json(
|
||||
$data,
|
||||
);
|
||||
}
|
||||
|
||||
public function operatorFirstStepView()
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['add-safety-and-privacy'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return view('version2.dashboard_pages.safety_and_privacy.operation_create');
|
||||
}
|
||||
|
||||
public function operatorFirstStepStore(Request $request)
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['add-safety-and-privacy'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
if (Auth::user()->edarate_ostani_id || is_null(Auth::user()->city_id)) {
|
||||
return response()->json([
|
||||
'message' => 'امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (is_null(Auth::user()->edarate_shahri_id)) {
|
||||
return response()->json([
|
||||
'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'point' => 'required',
|
||||
'info_id' => 'required',
|
||||
'activity_date' => 'required|date_format:Y-m-d',
|
||||
'activity_time' => 'required|date_format:H:i',
|
||||
'recognize_picture' => 'required|image',
|
||||
|
||||
], [], [
|
||||
'activity_date' => 'تاریخ فعالیت',
|
||||
'activity_time' => 'ساعت فعالیت',
|
||||
])->validate();
|
||||
|
||||
$coordinates = explode(',', $request->point);
|
||||
$item = InfoItem::where('id', $request->info_id)->where('item', 17)->firstOrFail();
|
||||
|
||||
try {
|
||||
$safety_and_privacy = \DB::transaction(function () use ($request, $coordinates, $item) {
|
||||
$safety_and_privacy = SafetyAndPrivacy::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,
|
||||
'info_id' => $item->id,
|
||||
'info_fa' => $item->sub_item_str,
|
||||
'city_id' => auth()->user()->city_id,
|
||||
'city_fa' => auth()->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,
|
||||
'way_id' => get_way_id_from_nominatim($coordinates[0], $coordinates[1]),
|
||||
]);
|
||||
|
||||
if ($request->has('recognize_picture')) {
|
||||
$recognize_picture = $request->file('recognize_picture')->store('safety_and_privacy/'.$safety_and_privacy->id.'/recognize_picture', 'public');
|
||||
$safety_and_privacy->recognize_picture = 'https://rms.rmto.ir/storage/'.$recognize_picture;
|
||||
// \App\Helpers\Compress::resize("/var/www/rms/public/storage/{$recognize_picture}");
|
||||
}
|
||||
|
||||
$safety_and_privacy->goToFirstStep();
|
||||
$safety_and_privacy->save();
|
||||
auth()->user()->addActivityComplete(1134);
|
||||
});
|
||||
} catch (\Throwable $th) {
|
||||
$th->getMessage();
|
||||
throw $th;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'safety_and_privacy_id' => $safety_and_privacy,
|
||||
'message' => 'succussful'
|
||||
]);
|
||||
}
|
||||
|
||||
public function operatorSecondStepStore(SafetyAndPrivacy $safety_and_privacy, Request $request)
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['add-safety-and-privacy'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
if (Auth::user()->edarate_ostani_id || is_null(Auth::user()->city_id)) {
|
||||
return response()->json([
|
||||
'message' => 'امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (is_null(Auth::user()->edarate_shahri_id)) {
|
||||
return response()->json([
|
||||
'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'judiciary_document' => 'required|array',
|
||||
'judiciary_document.*' => 'file',
|
||||
])->validate();
|
||||
|
||||
try {
|
||||
\DB::transaction(function () use ($request, $safety_and_privacy) {
|
||||
$judiciary_document = [];
|
||||
foreach ($request->judiciary_document as $index => $item) {
|
||||
$judiciary_document[] = $temp = $item->store('safety_and_privacy/'.$safety_and_privacy->id.'/judiciary_document', 'public');
|
||||
}
|
||||
$safety_and_privacy->judiciary_document = serialize($judiciary_document);
|
||||
$safety_and_privacy->judiciary_document_upload_date = now();
|
||||
|
||||
$safety_and_privacy->goToSecondStep();
|
||||
$safety_and_privacy->save();
|
||||
|
||||
auth()->user()->addActivityComplete(1135);
|
||||
});
|
||||
} catch (\Throwable $th) {
|
||||
throw $th;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'safety_and_privacy_id' => $safety_and_privacy,
|
||||
'message' => 'succussful'
|
||||
]);
|
||||
}
|
||||
|
||||
public function operatorThirdStepStore(SafetyAndPrivacy $safety_and_privacy, Request $request)
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['add-safety-and-privacy'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
if (Auth::user()->edarate_ostani_id || is_null(Auth::user()->city_id)) {
|
||||
return response()->json([
|
||||
'message' => 'امکان ثبت این مورد برای ادارات استانی و ستادی وجود ندارد!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (is_null(Auth::user()->edarate_shahri_id)) {
|
||||
return response()->json([
|
||||
'message' => 'اداره شهری برای شما در سامانه ثبت نشده است!'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'action_picture' => 'required|image',
|
||||
])->validate();
|
||||
|
||||
try {
|
||||
\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 = 'https://rms.rmto.ir/storage/'.$action_picture;
|
||||
// \App\Helpers\Compress::resize("/var/www/rms/public/storage/{$action_picture}");
|
||||
$safety_and_privacy->action_picture_document_upload_date = now();
|
||||
|
||||
$safety_and_privacy->goToThirdStep();
|
||||
$safety_and_privacy->save();
|
||||
auth()->user()->addActivityComplete(1136);
|
||||
});
|
||||
} catch (\Throwable $th) {
|
||||
throw $th;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'safety_and_privacy_id' => $safety_and_privacy,
|
||||
'message' => 'succussful'
|
||||
]);
|
||||
}
|
||||
|
||||
public function unserialize(SafetyAndPrivacy $safety_and_privacy)
|
||||
{
|
||||
$datas = isset($safety_and_privacy->judiciary_document) ? unserialize($safety_and_privacy->judiciary_document) : [];
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($datas as $data) {
|
||||
$result[] = 'https://rms.rmto.ir/storage/'.$data;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'data' => $result,
|
||||
]);
|
||||
}
|
||||
|
||||
public function subItemList()
|
||||
{
|
||||
return response()->json([
|
||||
'data' => InfoItem::where('item', 17)->select('id', 'item', 'item_str', 'sub_item_str as name', 'sub_item_unit as unit', 'needs_image', 'needs_end_point', 'sub_item')->get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function getAllDataToMap(Request $request)
|
||||
{
|
||||
$province = $request->province_id;
|
||||
$edare_shahri = $request->edare_shahri_id;
|
||||
$step = $request->step;
|
||||
$info_id = $request->info_id;
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
$datass = DB::table('safety_and_privacy')
|
||||
->when($province, function ($query, $province) {
|
||||
return $query->where('province_id', $province);
|
||||
})
|
||||
->when($edare_shahri, function ($query, $edare_shahri) {
|
||||
return $query->where('edare_shahri_id', $edare_shahri);
|
||||
})
|
||||
->when($step, function ($query, $step) {
|
||||
return $query->where('step', $step);
|
||||
})
|
||||
->when($info_id, function ($query, $info_id) {
|
||||
return $query->where('info_id', $info_id);
|
||||
})
|
||||
->whereBetween('created_at', [
|
||||
$date_from,
|
||||
$date_to,
|
||||
])
|
||||
->select('id', 'lat', 'lon', 'step')
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'count' => count($datass),
|
||||
'message' => '',
|
||||
'data' => $datass
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function detail(SafetyAndPrivacy $safety_and_privacy)
|
||||
{
|
||||
return response()->json($safety_and_privacy, 200);
|
||||
}
|
||||
|
||||
public function delete(Request $request, SafetyAndPrivacy $safety_and_privacy)
|
||||
{
|
||||
if (!auth()->user()->can('delete-road-item')) {
|
||||
return response()->json([
|
||||
'message' => 'access to requested resource is forbidden.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
Storage::deleteDirectory('public/' . 'safety_and_privacy/' . $safety_and_privacy->id);
|
||||
|
||||
auth()->user()->addActivityComplete(1155);
|
||||
|
||||
$safety_and_privacy->delete();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\RoadObservationHistory;
|
||||
use App\Models\RoadObserved;
|
||||
use App\Models\City;
|
||||
use App\Models\User;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\Contractor;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Models\SafetyAndPrivacy;
|
||||
use App\Models\InfoItem;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\V2\SafetyAndPrivacy\SafetyAndPrivacyTable\AllSheets as SafetyAndPrivacyTable;
|
||||
|
||||
class SafetyAndPrivacyReportController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('version2.dashboard_pages.safety_and_privacy.report');
|
||||
}
|
||||
|
||||
public function safetyAndPrivacyData(Request $request): JsonResponse
|
||||
{
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => SafetyAndPrivacy::provinceData($request->from_date, $request->date_to),
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
function totalGroupProvinceCity(Request $request) : JsonResponse
|
||||
{
|
||||
return response()->json(SafetyAndPrivacy::EdareData($request->from_date, $request->date_to, $request->province_id), 200);
|
||||
}
|
||||
|
||||
|
||||
public function safetyAndPrivacyExcel(Request $request)
|
||||
{
|
||||
$name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new SafetyAndPrivacyTable($request->from_date, $request->date_to), $name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class UserManagementController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (Auth::user()->can('full-user-managment') || Auth::user()->can('limited-user-management')) {
|
||||
return view('version2.dashboard_pages.user_management.list');
|
||||
}
|
||||
|
||||
abort(403);
|
||||
}
|
||||
|
||||
public function activityReport()
|
||||
{
|
||||
return view('version2.dashboard_pages.user_management.activity_report');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user