inital commit
This commit is contained in:
1201
app/Http/Controllers/Api/BiController.php
Normal file
1201
app/Http/Controllers/Api/BiController.php
Normal file
File diff suppressed because it is too large
Load Diff
642
app/Http/Controllers/Api/CMMSController.php
Normal file
642
app/Http/Controllers/Api/CMMSController.php
Normal file
@@ -0,0 +1,642 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CMMS_Form;
|
||||
use App\Models\CMMS_Forms_histories;
|
||||
use App\Models\CMMS_Province;
|
||||
use App\Models\CmmsDemo;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
|
||||
class CMMSController extends Controller
|
||||
{
|
||||
public function getVehicleActivity(Request $request)
|
||||
{
|
||||
|
||||
if (!$request->machineCode || !$request->startDT || !$request->endDT || !$request->minStopDuration) {
|
||||
return response()->json([
|
||||
'message' => 'error'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$r = $request->machineCode;
|
||||
$s = $request->startDT;
|
||||
$e = $request->endDT;
|
||||
$d = $request->minStopDuration;
|
||||
$url = 'http://fms.141.ir/api/RMS/GetVehicleActivity?';
|
||||
$query = "username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}&minStopDuration={$d}";
|
||||
$full_url = $url . $query;
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $full_url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS,
|
||||
"username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}&minStopDuration={$d}");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$server_output = curl_exec($ch);
|
||||
|
||||
$d = json_decode($server_output, true);
|
||||
|
||||
if ($d['ResultCode'] != 0) {
|
||||
return response()->json([
|
||||
'message' => 'failed',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $d
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function getVehicleLastPoints(Request $request)
|
||||
{
|
||||
|
||||
if (!$request->machineCode) {
|
||||
return response()->json([
|
||||
'message' => 'error'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$r = $request->machineCode;
|
||||
$url = 'http://fms.141.ir/api/RMS/GetVehicleLastPoints?';
|
||||
$query = "username=RMS&password=XSW@1qaz&machineCodes={$r}";
|
||||
$full_url = $url . $query;
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $full_url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS,
|
||||
"username=RMS&password=XSW@1qaz&machineCode={$r}");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$server_output = curl_exec($ch);
|
||||
|
||||
$d = json_decode($server_output, true);
|
||||
return $d;
|
||||
if ($d['ResultCode'] != 0) {
|
||||
return response()->json([
|
||||
'message' => 'failed',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $d
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function getVehicleActivitySummary(Request $request)
|
||||
{
|
||||
|
||||
if (!$request->machineCode || !$request->startDT || !$request->endDT) {
|
||||
return response()->json([
|
||||
'message' => 'error'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$r = $request->machineCode;
|
||||
$s = $request->startDT;
|
||||
$e = $request->endDT;
|
||||
$url = 'http://fms.141.ir/api/RMS/GetVehicleActivitySummary?';
|
||||
$query = "username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}";
|
||||
$full_url = $url . $query;
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $full_url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS,
|
||||
"username=RMS&password=XSW@1qaz&machineCode={$r}&startDT={$s}&endDT={$e}");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$server_output = curl_exec($ch);
|
||||
|
||||
$d = json_decode($server_output, true);
|
||||
|
||||
if ($d['ResultCode'] != 0) {
|
||||
return response()->json([
|
||||
'message' => 'failed',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $d
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getVehicleData(Request $request)
|
||||
{
|
||||
$r = $request->machine;
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL,"http://fms.141.ir/api/RMS/GetVehicleLastPoints?username=RMS&password=XSW@1qaz&machineCodes={$r}");
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS,
|
||||
"username=RMS&password=XSW@1qaz&machineCodes={$r}");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$server_output = curl_exec($ch);
|
||||
|
||||
$d = json_decode($server_output);
|
||||
|
||||
if ($d[0]->ResultCode != 0) {
|
||||
return response()->json([
|
||||
'message' => 'failed',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $d[0]
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function publicIndex()
|
||||
{
|
||||
$fms = CMMS_Form::all();
|
||||
|
||||
return response()->json([
|
||||
'data' => $fms
|
||||
]);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if (Auth::user()->hasRole('superadmin')) {
|
||||
$fms = CMMS_Form::all();
|
||||
} else {
|
||||
$fms = CMMS_Form::where('user_id', Auth::user()->id)->get();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'data' => $fms
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$cmms = CMMS_Form::where('id', $id)->first();
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $cmms
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$uuid = \Uuid::generate();
|
||||
|
||||
foreach (CMMS_Province::where('province_id', $request->only('province_id'))->get() as $prov_item) {
|
||||
$province_fa = $prov_item->province_fa;
|
||||
}
|
||||
foreach (CMMS_Province::where('province_id', $request->only('province_id'))->get() as $item) {
|
||||
$area_code = $item->area_code;
|
||||
}
|
||||
$hasMachine = CMMS_Form::where('car_type', $request->car_type)
|
||||
->where('province_id', $request->province_id)
|
||||
->orderBy('created_at', 'DESC')->first();
|
||||
|
||||
|
||||
if (strlen($request->province_id) == '1') {
|
||||
$province_id = '0' . $request->province_id;
|
||||
} else {
|
||||
$province_id = $request->province_id;
|
||||
}
|
||||
|
||||
if ($hasMachine) {
|
||||
$latestItem = CMMS_Form::where('province_id', $request->province_id)
|
||||
->where('car_type', $request->car_type)
|
||||
->orderBy('created_at', 'desc')
|
||||
->first();
|
||||
|
||||
|
||||
// add counter
|
||||
$getThreeLastChar = substr($hasMachine->form_number, -3);
|
||||
$temp = intval($getThreeLastChar);
|
||||
$temp++;
|
||||
if (strlen($temp) == '3') {
|
||||
$new = $temp;
|
||||
} elseif (strlen($temp) == '2') {
|
||||
$new = '0' . $temp;
|
||||
} else {
|
||||
$new = '00' . $temp;
|
||||
}
|
||||
|
||||
$form_number = 'F:H-' . $request->car_type . $area_code . $province_id . $new;
|
||||
} else {
|
||||
$form_number = 'F:H-' . $request->car_type . $area_code . $province_id . '001';
|
||||
}
|
||||
|
||||
|
||||
$city = \App\Models\City::where('id', $request->city_id)
|
||||
->select('id', 'name_fa')->first();
|
||||
|
||||
$city_fa = $city->name_fa;
|
||||
|
||||
switch ($request->car_type) {
|
||||
case "B":
|
||||
$car_type_fa = 'بلدوزر';
|
||||
break;
|
||||
case "L":
|
||||
$car_type_fa = 'لودر';
|
||||
break;
|
||||
case "G":
|
||||
$car_type_fa = 'گریدر';
|
||||
break;
|
||||
case "Ex":
|
||||
$car_type_fa = 'بیل مکانیکی';
|
||||
break;
|
||||
}
|
||||
|
||||
$create_form = CMMS_Form::create([
|
||||
'dedicated_number' => $request->dedicated_number,
|
||||
'chassis_number' => $request->chassis_number,
|
||||
'province_id' => $request->province_id,
|
||||
'province_fa' => $province_fa,
|
||||
'city_id' => $request->city_id,
|
||||
'city_fa' => $city_fa,
|
||||
'total_points' => $request->total_points,
|
||||
'device_name' => $request->device_name,
|
||||
'gps_code' => $request->gps_code,
|
||||
'operator_phone' => $request->operator_phone,
|
||||
'operator_name' => $request->operator_name,
|
||||
'operator_nationalcode' => $request->operator_nationalcode,
|
||||
'form_number' => $form_number,
|
||||
'car_type' => $request->car_type,
|
||||
'motor' => $request->motor,
|
||||
'motor_description' => $request->motor_description,
|
||||
'motor_score' => $request->motor_score,
|
||||
'power' => $request->power,
|
||||
'power_description' => $request->power_description,
|
||||
'power_score' => $request->power_score,
|
||||
'zirbandi' => $request->zirbandi,
|
||||
'zirbandi_description' => $request->zirbandi_description,
|
||||
'zirbandi_score' => $request->zirbandi_score,
|
||||
'chassis' => $request->chassis,
|
||||
'chassis_description' => $request->chassis_description,
|
||||
'chassis_score' => $request->chassis_score,
|
||||
'electrical' => $request->electrical,
|
||||
'electrical_description' => $request->electrical_description,
|
||||
'electrical_score' => $request->electrical_score,
|
||||
'safety' => $request->safety,
|
||||
'safety_description' => $request->safety_description,
|
||||
'safety_score' => $request->safety_score,
|
||||
'gps' => $request->gps,
|
||||
'gps_description' => $request->gps_description,
|
||||
'gps_score' => $request->gps_score,
|
||||
'color' => $request->color,
|
||||
'color_description' => $request->color_description,
|
||||
'color_score' => $request->color_score,
|
||||
'bucket' => $request->bucket,
|
||||
'bucket_description' => $request->bucket_description,
|
||||
'bucket_score' => $request->bucket_score,
|
||||
'hydraulic' => $request->hydraulic,
|
||||
'hydraulic_description' => $request->hydraulic_description,
|
||||
'hydraulic_score' => $request->hydraulic_score,
|
||||
'jolobandi' => $request->jolobandi,
|
||||
'jolobandi_description' => $request->jolobandi_description,
|
||||
'jolobandi_score' => $request->jolobandi_score,
|
||||
'ripper' => $request->ripper,
|
||||
'ripper_description' => $request->ripper_description,
|
||||
'ripper_score' => $request->ripper_score,
|
||||
'service_status' => $request->service_status,
|
||||
'service_description' => $request->service_description,
|
||||
'fuel_form' => $request->fuel_form,
|
||||
'fuel_description' => $request->fuel_description,
|
||||
'question1' => $request->question1,
|
||||
'question2' => $request->question2,
|
||||
'question3' => $request->question3,
|
||||
'question4' => $request->question4,
|
||||
'question5' => $request->question5,
|
||||
'auditor_name' => $request->auditor_name,
|
||||
'auditor_position' => $request->auditor_position,
|
||||
'member1_name' => $request->member1_name,
|
||||
'member1_position' => $request->member1_position,
|
||||
'member2_name' => $request->member2_name,
|
||||
'member2_position' => $request->member2_position,
|
||||
'member3_name' => $request->member3_name,
|
||||
'member3_position' => $request->member3_position,
|
||||
'user_id' => Auth::user()->id,
|
||||
'car_type_fa' => $car_type_fa,
|
||||
'created_at_fa' => Verta::now(),
|
||||
'updated_at_fa' => Verta::now(),
|
||||
]);
|
||||
|
||||
$machineData = CmmsDemo::where('machine_code', $request->dedicated_number)->first();
|
||||
|
||||
CMMS_Forms_histories::create([
|
||||
'user_id' => Auth::user()->id,
|
||||
'cmms_form_id' => $create_form->id,
|
||||
'previous_chassis_number' => $machineData->body_number ?? null,
|
||||
'previous_province_id' => null,
|
||||
'previous_province_fa' => $machineData->unit_group_fa ?? null,
|
||||
'previous_city_id' => null,
|
||||
'previous_city_fa' => $machineData->unit_name ?? null,
|
||||
'previous_device_name' => $machineData->car_name ?? null,
|
||||
'previous_gps_code' => $machineData->gps_code ?? null,
|
||||
'previous_operator_name' => $machineData->driver_name ?? null,
|
||||
'previous_operator_nationalcode' => null,
|
||||
'previous_operator_phone' => $machineData->mobile ?? null,
|
||||
]);
|
||||
|
||||
if ($request->has('image1')) {
|
||||
$image1 = $request->file('image1');
|
||||
$destinationPath1 = 'storage/cmms/' . now()->year . '/' . now()->month . '/';
|
||||
$filename1 = $uuid . '-imageOne.' . $image1->getClientOriginalExtension();
|
||||
$image1->move($destinationPath1, $filename1);
|
||||
$create_form->update(['image1' => $destinationPath1 . $filename1]);
|
||||
}
|
||||
if ($request->has('image2')) {
|
||||
$image2 = $request->file('image2');
|
||||
$destinationPath2 = 'storage/cmms/' . now()->year . '/' . now()->month . '/';
|
||||
$filename2 = $uuid . '-imageTwo.' . $image2->getClientOriginalExtension();
|
||||
$image2->move($destinationPath2, $filename2);
|
||||
$create_form->update(['image2' => $destinationPath2 . $filename2]);
|
||||
}
|
||||
if ($request->has('image3')) {
|
||||
$image3 = $request->file('image3');
|
||||
$destinationPath3 = 'storage/cmms/' . now()->year . '/' . now()->month . '/';
|
||||
$filename3 = $uuid . '-imageThree.' . $image3->getClientOriginalExtension();
|
||||
$image3->move($destinationPath3, $filename3);
|
||||
$create_form->update(['image3' => $destinationPath3 . $filename3]);
|
||||
}
|
||||
if ($request->has('file1')) {
|
||||
$file1 = $request->file('file1');
|
||||
$destinationPath4 = 'storage/cmms/' . now()->year . '/' . now()->month . '/';
|
||||
$filename4 = $uuid . '-Form.' . $file1->getClientOriginalExtension();
|
||||
$file1->move($destinationPath4, $filename4);
|
||||
$create_form->update(['file1' => $destinationPath4 . $filename4]);
|
||||
}
|
||||
$machineData->proccessed = 1;
|
||||
$machineData->save();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'data' => $create_form
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$uuid = \Uuid::generate();
|
||||
|
||||
foreach (CMMS_Province::where('province_id', $request->only('province_id'))->get() as $prov_item) {
|
||||
$province_fa = $prov_item->province_fa;
|
||||
}
|
||||
foreach (CMMS_Province::where('province_id', $request->only('province_id'))->get() as $item) {
|
||||
$area_code = $item->area_code;
|
||||
}
|
||||
$hasMachine = CMMS_Form::where('car_type', $request->car_type)
|
||||
->where('province_id', $request->province_id)
|
||||
->orderBy('created_at', 'DESC')->first();
|
||||
|
||||
|
||||
if (strlen($request->province_id) == '1') {
|
||||
$province_id = '0' . $request->province_id;
|
||||
} else {
|
||||
$province_id = $request->province_id;
|
||||
}
|
||||
|
||||
if ($hasMachine) {
|
||||
$latestItem = CMMS_Form::where('province_id', $request->province_id)
|
||||
->where('car_type', $request->car_type)
|
||||
->orderBy('created_at', 'desc')
|
||||
->first();
|
||||
|
||||
// add counter
|
||||
$getThreeLastChar = substr($hasMachine->form_number, -3);
|
||||
$temp = intval($getThreeLastChar);
|
||||
$temp++;
|
||||
if (strlen($temp) == '3') {
|
||||
$new = $temp;
|
||||
} elseif (strlen($temp) == '2') {
|
||||
$new = '0' . $temp;
|
||||
} else {
|
||||
$new = '00' . $temp;
|
||||
}
|
||||
|
||||
$form_number = 'F:H-' . $request->car_type . $area_code . $province_id . $new;
|
||||
} else {
|
||||
$form_number = 'F:H-' . $request->car_type . $area_code . $province_id . '001';
|
||||
}
|
||||
|
||||
|
||||
$city = \App\Models\City::where('id', $request->city_id)
|
||||
->select('id', 'name_fa')->first();
|
||||
|
||||
$city_fa = $city->name_fa;
|
||||
|
||||
switch ($request->car_type) {
|
||||
case "B":
|
||||
$car_type_fa = 'بلدوزر';
|
||||
break;
|
||||
case "L":
|
||||
$car_type_fa = 'لودر';
|
||||
break;
|
||||
case "G":
|
||||
$car_type_fa = 'گریدر';
|
||||
break;
|
||||
case "Ex":
|
||||
$car_type_fa = 'بیل مکانیکی';
|
||||
break;
|
||||
}
|
||||
$cmms = CMMS_Form::find($id);
|
||||
$cmms->update([
|
||||
'dedicated_number' => $request->dedicated_number,
|
||||
'chassis_number' => $request->chassis_number,
|
||||
'province_id' => $request->province_id,
|
||||
'province_fa' => $province_fa,
|
||||
'city_id' => $request->city_id,
|
||||
'city_fa' => $city_fa,
|
||||
'total_points' => $request->total_points,
|
||||
'device_name' => $request->device_name,
|
||||
'gps_code' => $request->gps_code,
|
||||
'operator_phone' => $request->operator_phone,
|
||||
'operator_name' => $request->operator_name,
|
||||
'operator_nationalcode' => $request->operator_nationalcode,
|
||||
'form_number' => $form_number,
|
||||
'car_type' => $request->car_type,
|
||||
'motor' => $request->motor,
|
||||
'motor_description' => $request->motor_description,
|
||||
'motor_score' => $request->motor_score,
|
||||
'power' => $request->power,
|
||||
'power_description' => $request->power_description,
|
||||
'power_score' => $request->power_score,
|
||||
'zirbandi' => $request->zirbandi,
|
||||
'zirbandi_description' => $request->zirbandi_description,
|
||||
'zirbandi_score' => $request->zirbandi_score,
|
||||
'chassis' => $request->chassis,
|
||||
'chassis_description' => $request->chassis_description,
|
||||
'chassis_score' => $request->chassis_score,
|
||||
'electrical' => $request->electrical,
|
||||
'electrical_description' => $request->electrical_description,
|
||||
'electrical_score' => $request->electrical_score,
|
||||
'safety' => $request->safety,
|
||||
'safety_description' => $request->safety_description,
|
||||
'safety_score' => $request->safety_score,
|
||||
'gps' => $request->gps,
|
||||
'gps_description' => $request->gps_description,
|
||||
'gps_score' => $request->gps_score,
|
||||
'color' => $request->color,
|
||||
'color_description' => $request->color_description,
|
||||
'color_score' => $request->color_score,
|
||||
'bucket' => $request->bucket,
|
||||
'bucket_description' => $request->bucket_description,
|
||||
'bucket_score' => $request->bucket_score,
|
||||
'hydraulic' => $request->hydraulic,
|
||||
'hydraulic_description' => $request->hydraulic_description,
|
||||
'hydraulic_score' => $request->hydraulic_score,
|
||||
'jolobandi' => $request->jolobandi,
|
||||
'jolobandi_description' => $request->jolobandi_description,
|
||||
'jolobandi_score' => $request->jolobandi_score,
|
||||
'ripper' => $request->ripper,
|
||||
'ripper_description' => $request->ripper_description,
|
||||
'ripper_score' => $request->ripper_score,
|
||||
'service_status' => $request->service_status,
|
||||
'service_description' => $request->service_description,
|
||||
'fuel_form' => $request->fuel_form,
|
||||
'fuel_description' => $request->fuel_description,
|
||||
'question1' => $request->question1,
|
||||
'question2' => $request->question2,
|
||||
'question3' => $request->question3,
|
||||
'question4' => $request->question4,
|
||||
'question5' => $request->question5,
|
||||
'auditor_name' => $request->auditor_name,
|
||||
'auditor_position' => $request->auditor_position,
|
||||
'member1_name' => $request->member1_name,
|
||||
'member1_position' => $request->member1_position,
|
||||
'member2_name' => $request->member2_name,
|
||||
'member2_position' => $request->member2_position,
|
||||
'member3_name' => $request->member3_name,
|
||||
'member3_position' => $request->member3_position,
|
||||
'user_id' => Auth::user()->id,
|
||||
'car_type_fa' => $car_type_fa,
|
||||
'updated_at_fa' => Verta::now(),
|
||||
]);
|
||||
|
||||
if ($request->has('image1')) {
|
||||
$image1 = $request->file('image1');
|
||||
$destinationPath1 = 'storage/cmms/' . now()->year . '/' . now()->month . '/';
|
||||
$filename1 = $uuid . '-imageOne.' . $image1->getClientOriginalExtension();
|
||||
$image1->move($destinationPath1, $filename1);
|
||||
$cmms->update(['image1' => $destinationPath1 . $filename1]);
|
||||
}
|
||||
if ($request->has('image2')) {
|
||||
$image2 = $request->file('image2');
|
||||
$destinationPath2 = 'storage/cmms/' . now()->year . '/' . now()->month . '/';
|
||||
$filename2 = $uuid . '-imageTwo.' . $image2->getClientOriginalExtension();
|
||||
$image2->move($destinationPath2, $filename2);
|
||||
$cmms->update(['image2' => $destinationPath2 . $filename2]);
|
||||
}
|
||||
if ($request->has('image3')) {
|
||||
$image3 = $request->file('image3');
|
||||
$destinationPath3 = 'storage/cmms/' . now()->year . '/' . now()->month . '/';
|
||||
$filename3 = $uuid . '-imageThree.' . $image3->getClientOriginalExtension();
|
||||
$image3->move($destinationPath3, $filename3);
|
||||
$cmms->update(['image3' => $destinationPath3 . $filename3]);
|
||||
}
|
||||
if ($request->has('file1')) {
|
||||
$file1 = $request->file('file1');
|
||||
$destinationPath4 = 'storage/cmms/' . now()->year . '/' . now()->month . '/';
|
||||
$filename4 = $uuid . '-Form.' . $file1->getClientOriginalExtension();
|
||||
$file1->move($destinationPath4, $filename4);
|
||||
$cmms->update(['file1' => $destinationPath4 . $filename4]);
|
||||
}
|
||||
|
||||
$history = CMMS_Forms_histories::create([
|
||||
'user_id' => Auth::user()->id,
|
||||
'cmms_form_id' => $id,
|
||||
'previous_chassis_number' => $cmms->chassis_number,
|
||||
'previous_province_id' => $cmms->province_id,
|
||||
'previous_province_fa' => $cmms->province_name,
|
||||
'previous_city_id' => $cmms->city_id,
|
||||
'previous_city_fa' => $cmms->city_name,
|
||||
'previous_device_name' => $cmms->device_name,
|
||||
'previous_gps_code' => $cmms->gps_code,
|
||||
'previous_operator_name' => $cmms->operator_name,
|
||||
'previous_operator_nationalcode' => $cmms->operator_nationalcode,
|
||||
'previous_operator_phone' => $cmms->operator_phone,
|
||||
'previous_image1' => $cmms->image1 ?? null,
|
||||
'previous_image2' => $cmms->image2 ?? null,
|
||||
'previous_image3' => $cmms->image3 ?? null,
|
||||
'previous_file1' => $cmms->file1 ?? null,
|
||||
'previous_form_number' => $cmms->form_number
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $cmms,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getProvinces()
|
||||
{
|
||||
$provinces = CMMS_Province::all();
|
||||
|
||||
return response()->json([
|
||||
'data' => $provinces
|
||||
]);
|
||||
}
|
||||
|
||||
public function getByMachineCode(Request $request)
|
||||
{
|
||||
$machineData = CmmsDemo::where('machine_code', $request->dedicated_number)->first();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'data' => $machineData
|
||||
]);
|
||||
}
|
||||
public function search(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'data' => 'required'
|
||||
]);
|
||||
$sql = "SELECT machine_code FROM cmms_demos
|
||||
WHERE LOCATE('".$request->data."', cmms_demos.machine_code) > 0 and proccessed = 0
|
||||
limit 5";
|
||||
$data = DB::select($sql);
|
||||
$arr = [];
|
||||
foreach ($data as $value) {
|
||||
$arr[] = $value->machine_code;
|
||||
}
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => 'yes',
|
||||
'status_bool' => 1,
|
||||
'data' => $arr,
|
||||
], 200);
|
||||
}
|
||||
public function get_cities(Request $request){
|
||||
$request->validate([
|
||||
'id' => 'required|integer|exists:cmms_province,id'
|
||||
]);
|
||||
$p_id = CMMS_Province::where('province_id', $request->id)->first();
|
||||
$p_id = $p_id->rms_code;
|
||||
$cities = \App\Models\City::where('province_id', $p_id)->select('id', 'name_fa')->get();
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $cities
|
||||
], 200);
|
||||
}
|
||||
|
||||
}
|
||||
998
app/Http/Controllers/Api/ContractSubItemsController.php
Normal file
998
app/Http/Controllers/Api/ContractSubItemsController.php
Normal file
@@ -0,0 +1,998 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\City;
|
||||
use App\Models\Contracts;
|
||||
use App\Models\ContractSubItems;
|
||||
use App\Models\ContractSubItemsHistory;
|
||||
use App\Models\Province;
|
||||
use App\Models\RoadDangerPrevention;
|
||||
use App\Models\RoadMaintenanceProject;
|
||||
use App\Models\RoadTechnicalBuilding;
|
||||
use App\Models\RoadTollhouseManagement;
|
||||
use App\Models\RoadUpgradeSafety;
|
||||
use Illuminate\Http\Request;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use SoapClient;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Carbon\Carbon;
|
||||
use App\Facades\Sms\Sms;
|
||||
|
||||
class ContractSubItemsController extends Controller
|
||||
{
|
||||
public function getMaintenanceProject($id)
|
||||
{
|
||||
$roadProject = RoadMaintenanceProject::find($id);
|
||||
$roadProjectHistories = $roadProject->projectHistories;
|
||||
|
||||
$roadProjectHistoriesFiles = [];
|
||||
$imagesIndex = 0;
|
||||
|
||||
foreach ($roadProjectHistories as $key => $roadProjectHistory) {
|
||||
foreach ($roadProjectHistory->files as $keyPath => $file) {
|
||||
$roadProjectHistoriesFiles[$imagesIndex] = asset('storage' . substr($file->path, 6));
|
||||
$imagesIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
$cities = [];
|
||||
$citiesIndex = 0;
|
||||
|
||||
foreach ($roadProject->cities_id as $cityKey => $value) {
|
||||
$getCity = \App\Models\City::find($cityKey);
|
||||
|
||||
$cities[$citiesIndex] = [
|
||||
'id' => $getCity->id,
|
||||
'name' => $getCity->name_fa,
|
||||
'value' => $value
|
||||
];
|
||||
|
||||
$citiesIndex++;
|
||||
}
|
||||
|
||||
$roadProjectArray = [
|
||||
'id' => $roadProject->id,
|
||||
'province' => [
|
||||
'id' => ($roadProject->province) ? $roadProject->province->id : null,
|
||||
'name' => ($roadProject->province) ? $roadProject->province->name_fa : '-',
|
||||
'lat_lng' => [
|
||||
$roadProject->province->center_lat,
|
||||
$roadProject->province->center_long
|
||||
]
|
||||
],
|
||||
'cities' => $cities,
|
||||
'axis_name' => ($roadProject->axis_name) ? $roadProject->axis_name : '-',
|
||||
'axis_type' => ($roadProject->axis_type) ?: 0,
|
||||
'project_name' => ($roadProject->project_name) ? $roadProject->project_name : '-',
|
||||
'contractor_name' => ($roadProject->contractor_name) ? $roadProject->contractor_name : '-',
|
||||
'consultant_name' => ($roadProject->consultant_name) ? $roadProject->consultant_name : '-',
|
||||
'contract_date' => ($roadProject->contract_date) ? $roadProject->contract_date : '-',
|
||||
'contract_credit' => ($roadProject->contract_credit) ? $roadProject->contract_credit : '-',
|
||||
'submited_at' => ($roadProject->submited_at) ?
|
||||
verta($roadProject->submited_at)->format('Y/n/j - H:i') : '-',
|
||||
'last_updated_at' => ($roadProject->last_updated_at) ?
|
||||
verta($roadProject->last_updated_at)->format('Y/n/j - H:i') : '-',
|
||||
'start_latlng' => $roadProject->start_latlng,
|
||||
'end_latlng' => $roadProject->end_latlng,
|
||||
'project_distance' => $roadProject->project_distance,
|
||||
'project_distance_update' => $roadProject->project_distance_update,
|
||||
'physical_progress' => $roadProject->physical_progress,
|
||||
'images' => $roadProjectHistoriesFiles,
|
||||
'project_status' => $roadProject->project_status
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => [
|
||||
$roadProjectArray
|
||||
]
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function ContractSubItemsList()
|
||||
{
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => ContractSubItems::all()
|
||||
]);
|
||||
}
|
||||
|
||||
public function storeForDevelop(Request $request)
|
||||
{
|
||||
|
||||
if ($request->has('operation_type_id1') && $request->operation_type_progress1 == null) {
|
||||
return response()->json(['message' => 'Operation type progress1 is NULL'], 400);
|
||||
}
|
||||
|
||||
if ($request->has('operation_type_id2') && $request->operation_type_progress2 == null) {
|
||||
return response()->json(['message' => 'Operation type progress2 is NULL'], 400);
|
||||
}
|
||||
|
||||
if ($request->has('operation_type_id3') && $request->operation_type_progress3 == null) {
|
||||
return response()->json(['message' => 'Operation type progress3 is NULL'], 400);
|
||||
}
|
||||
|
||||
if ($request->has('operation_type_id4') && $request->operation_type_progress4 == null) {
|
||||
return response()->json(['message' => 'Operation type progress4 is NULL'], 400);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$data = $this->getOperationType($request, $request->project_type_id);
|
||||
|
||||
if ($request->operation_type_id1) {
|
||||
$operation1 = $data[$request->operation_type_id1];
|
||||
}
|
||||
if ($request->operation_type_id2) {
|
||||
$operation2 = $data[$request->operation_type_id2];
|
||||
}
|
||||
if ($request->operation_type_id3) {
|
||||
$operation3 = $data[$request->operation_type_id3];
|
||||
}
|
||||
|
||||
|
||||
$contract = Contracts::where('id', $request->contract_id)->first();
|
||||
|
||||
$parent_contract_date = explode('-', $contract->contract_date);
|
||||
$parent_contract_date = Verta::getGregorian($parent_contract_date[0], $parent_contract_date[1], $parent_contract_date[2]);
|
||||
|
||||
$city_fa = City::where('id', $request->city_id)->first();
|
||||
$province_fa = Province::where('id', $request->province_id)->first();
|
||||
|
||||
|
||||
/// switches
|
||||
$progress_project = ContractSubItems::checkProgressProjectCondition($request->last_status_id, $request->progress_project);
|
||||
|
||||
$contractSubItem = new ContractSubItems();
|
||||
$contractSubItem->project_title = $request->project_title;
|
||||
$contractSubItem->project_type_id = $request->project_type_id;
|
||||
$contractSubItem->setProjectTypeFa($request->project_type_id);
|
||||
$contractSubItem->operation_type_id1 = $request->operation_type_id1 ?? null;
|
||||
$contractSubItem->operation_type_fa1 = $operation1['farsi'] ?? null;
|
||||
$contractSubItem->operation_type_unit1 = $operation1['unit'] ?? null;
|
||||
$contractSubItem->operation_type_amount1 = $request->operation_type_amount1 ?? null;
|
||||
$contractSubItem->operation_type_progress1 = $request->operation_type_progress1;
|
||||
$contractSubItem->operation_type_tonaj1 = $request->operation_type_tonaj1 ?? null;
|
||||
$contractSubItem->operation_type_id2 = $request->operation_type_id2 ?? null;
|
||||
$contractSubItem->operation_type_fa2 = $operation2['farsi'] ?? null;
|
||||
$contractSubItem->operation_type_unit2 = $operation2['unit'] ?? null;
|
||||
$contractSubItem->operation_type_amount2 = $request->operation_type_amount2 ?? null;
|
||||
$contractSubItem->operation_type_progress2 = $request->operation_type_progress2;
|
||||
$contractSubItem->operation_type_tonaj2 = $request->operation_type_tonaj2 ?? null;
|
||||
$contractSubItem->operation_type_id3 = $request->operation_type_id3 ?? null;
|
||||
$contractSubItem->operation_type_fa3 = $operation3['farsi'] ?? null;
|
||||
$contractSubItem->operation_type_unit3 = $operation3['unit'] ?? null;
|
||||
$contractSubItem->operation_type_amount3 = $request->operation_type_amount3 ?? null;
|
||||
$contractSubItem->operation_type_progress3 = $request->operation_type_progress3;
|
||||
$contractSubItem->operation_type_tonaj3 = $request->operation_type_tonaj3 ?? null;
|
||||
$contractSubItem->operation_type_id4 = $request->operation_type_id4 ?? null;
|
||||
$contractSubItem->operation_type_fa4 = $operation4['farsi'] ?? null;
|
||||
$contractSubItem->operation_type_unit4 = $operation4['unit'] ?? null;
|
||||
$contractSubItem->operation_type_amount4 = $request->operation_type_amount4 ?? null;
|
||||
$contractSubItem->operation_type_progress4 = $request->operation_type_progress4;
|
||||
$contractSubItem->operation_type_tonaj4 = $request->operation_type_tonaj4 ?? null;
|
||||
$contractSubItem->city_id = $request->city_id;
|
||||
$contractSubItem->city_fa = $city_fa->name_fa;
|
||||
$contractSubItem->province_id = $request->province_id;
|
||||
$contractSubItem->province_fa = $province_fa->name_fa;
|
||||
$contractSubItem->axis_type_id = $request->axis_type_id;
|
||||
$contractSubItem->setAxisTypeFa($request->axis_type_id);
|
||||
$contractSubItem->axis_name_fa = $request->axis_name_fa;
|
||||
$contractSubItem->start_lat = $request->start_lat;
|
||||
$contractSubItem->end_lat = $request->end_lat;
|
||||
$contractSubItem->start_lng = $request->start_lng;
|
||||
$contractSubItem->end_lng = $request->end_lng;
|
||||
$contractSubItem->followup_priority_project_id = $request->followup_priority_project_id;
|
||||
$contractSubItem->setFollowupPriorityProjectFa($request->followup_priority_project_id);
|
||||
$contractSubItem->priority_project = $request->priority_project;
|
||||
$contractSubItem->setPriorityProjectFa($request->priority_project);
|
||||
$contractSubItem->operator_name = $request->operator_name;
|
||||
$contractSubItem->operator_phone = $request->operator_phone;
|
||||
$contractSubItem->progress_project = $progress_project;
|
||||
$contractSubItem->last_status_id = $request->last_status_id;
|
||||
$contractSubItem->setLastStatusFa($request->last_status_id);
|
||||
$contractSubItem->last_digit_project = $request->last_digit_project;
|
||||
$contractSubItem->last_function_operator = $request->last_function_operator;
|
||||
$contractSubItem->last_payable_operator = $request->last_payable_operator;
|
||||
$contractSubItem->complete_payable = $request->complete_payable;
|
||||
$contractSubItem->contract_id = $request->contract_id;
|
||||
$contractSubItem->contract_date_from_parent_contract = $parent_contract_date[0].'-'.$parent_contract_date[1].'-'.$parent_contract_date[2];
|
||||
$contractSubItem->created_at_fa = Verta::instance(Verta::now());
|
||||
$contractSubItem->updated_at_fa = Verta::instance(Verta::now());
|
||||
$contractSubItem->start_way_id = self::get_way_id_from_nominatim($request->start_lat, $request->start_lng);
|
||||
$contractSubItem->end_way_id = self::get_way_id_from_nominatim($request->end_lat, $request->end_lng);
|
||||
$contractSubItem->user_id = Auth::user()->id;
|
||||
$contractSubItem->contract_moshaver_tarahi = $contract->contract_moshaver_tarahi;
|
||||
$contractSubItem->contract_moshaver_nezarat = $contract->contract_moshaver_nezarat;
|
||||
$contractSubItem->last_date_update = Carbon::now();
|
||||
|
||||
$contractSubItem->required_bitumen = $request->required_bitumen ?? null;
|
||||
$contractSubItem->used_bitumen = $request->used_bitumen ?? null;
|
||||
|
||||
$contractSubItem->bridge_number = $request->bridge_number ?? null;
|
||||
|
||||
$contractSubItem->save();
|
||||
|
||||
/// Generate Unique Code for this Contract Subitem
|
||||
$contractSubItem->unique_code = $contract->unique_id . '/' . $contractSubItem->id;
|
||||
$contractSubItem->save();
|
||||
|
||||
if ($request->addNewSubitemStatus == 'false') {
|
||||
$projectQuery = ContractSubItems::getProjectQuery($request->project_type_id);
|
||||
$roadProject = $projectQuery->find($request->projectData_id);
|
||||
$roadProjectHistories = $roadProject->projectHistories;
|
||||
$roadProjectHistoriesFiles = [];
|
||||
$imagesIndex = 0;
|
||||
foreach ($roadProjectHistories as $key => $roadProjectHistory) {
|
||||
foreach ($roadProjectHistory->files as $keyPath => $file) {
|
||||
$roadProjectHistoriesFiles[$imagesIndex] = asset('storage' . substr($file->path, 6));
|
||||
$imagesIndex++;
|
||||
}
|
||||
}
|
||||
$roadProjectHistoriesFiles;
|
||||
$countRoadFiles = count($roadProjectHistoriesFiles);
|
||||
}
|
||||
|
||||
$uuid = \Uuid::generate();
|
||||
if ($request->has('image1')) {
|
||||
$file1 = $request->file('image1');
|
||||
$destinationPath1 = 'storage/contract_subitems/' . now()->year . '/' . now()->month . '/';
|
||||
$filename1 = $uuid . '-one.' . $file1->getClientOriginalExtension();
|
||||
$file1->move($destinationPath1, $filename1);
|
||||
$contractSubItem->update(['image_path1' => $destinationPath1 . $filename1]);
|
||||
} elseif (! $request->has('image1') && $request->addNewSubitemStatus == 'false') {
|
||||
if ($countRoadFiles == 1) {
|
||||
$countRoadFiles = 2;
|
||||
}
|
||||
|
||||
$imageUrl = $roadProjectHistoriesFiles[$countRoadFiles - 2];
|
||||
if (strpos($imageUrl, "https://rms.rmto.ir/") == 0) {
|
||||
$imageUrl = str_replace("https://rms.rmto.ir/", "", $imageUrl);
|
||||
}
|
||||
|
||||
$contractSubItem->update(['image_path1' => $imageUrl ?? null ]);
|
||||
}
|
||||
|
||||
if ($request->has('image2')) {
|
||||
$file2 = $request->file('image2');
|
||||
$destinationPath2 = 'storage/contract_subitems/' . now()->year . '/' . now()->month . '/';
|
||||
$filename2 = $uuid . '-two.' . $file2->getClientOriginalExtension();
|
||||
$file2->move($destinationPath2, $filename2);
|
||||
$contractSubItem->update(['image_path2' => $destinationPath2 . $filename2]);
|
||||
} elseif (! $request->has('image2') && $request->addNewSubitemStatus == 'false') {
|
||||
$contractSubItem->update(['image_path2' => $roadProjectHistoriesFiles[$countRoadFiles - 1] ?? null ]);
|
||||
}
|
||||
if ($request->addNewSubitemStatus == 'false') {
|
||||
$projectQuery->find($request->projectData_id)->projectHistories()->delete();
|
||||
$projectQuery->find($request->projectData_id)->delete();
|
||||
}
|
||||
|
||||
$changeStatusRelInContracts = Contracts::find($request->contract_id);
|
||||
$changeStatusRelInContracts->status_rel = 2;
|
||||
$changeStatusRelInContracts->save();
|
||||
DB::commit();
|
||||
|
||||
// send msg
|
||||
$msg = "سلام،\n پروژه راهداری با کد یکتای {$contractSubItem->unique_code} با مسئولیت شما در سامانه جامع راهداری ثبت شده است. لطفا به روز رسانی دقیق و به موقع پیشرفت پروژه در سامانه اولویت قرار گیرد.\n rms.rmto.ir";
|
||||
|
||||
Sms::sendSms($contractSubItem->operator_phone, $msg);
|
||||
|
||||
// self::sms_sender($contractSubItem->operator_phone, $msg);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $contractSubItem
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
return response()->json([
|
||||
'message' => $e->getMessage(),
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateForDevelop(Request $request, $id)
|
||||
{
|
||||
if ($request->operation_type_id1 != 0 && $request->operation_type_progress1 == null) {
|
||||
return response()->json(['message' => 'Operation type progress1 is NULL'], 400);
|
||||
}
|
||||
if ($request->operation_type_id2 != 0 && $request->operation_type_progress2 == null) {
|
||||
return response()->json(['message' => 'Operation type progress2 is NULL'], 400);
|
||||
}
|
||||
if ($request->operation_type_id3 != 0 && $request->operation_type_progress3 == null) {
|
||||
return response()->json(['message' => 'Operation type progress3 is NULL'], 400);
|
||||
}
|
||||
if ($request->operation_type_id4 != 0 && $request->operation_type_progress4 == null) {
|
||||
return response()->json(['message' => 'Operation type progress4 is NULL'], 400);
|
||||
}
|
||||
|
||||
$contractSubItem = ContractSubItems::find($id);
|
||||
|
||||
$history = ContractSubItemsHistory::create([
|
||||
|
||||
'project_title' => $contractSubItem->project_title,
|
||||
'project_type_id' => $contractSubItem->project_type_id,
|
||||
'project_type_fa' => $contractSubItem->project_type_fa,
|
||||
|
||||
'operation_type_id1' => $contractSubItem->operation_type_id1 ?? null,
|
||||
'operation_type_fa1' => $contractSubItem->operation_type_fa1 ?? null,
|
||||
'operation_type_unit1' => $contractSubItem->operation_type_unit1 ?? null,
|
||||
'operation_type_amount1' => $contractSubItem->operation_type_amount1 ?? null,
|
||||
'operation_type_progress1' => $contractSubItem->operation_type_progress1 ?? null,
|
||||
'operation_type_tonaj1' => $contractSubItem->operation_type_tonaj1 ?? null,
|
||||
|
||||
'operation_type_id2' => $contractSubItem->operation_type_id2 ?? null,
|
||||
'operation_type_fa2' => $contractSubItem->operation_type_fa2 ?? null,
|
||||
'operation_type_unit2' => $contractSubItem->operation_type_unit2 ?? null,
|
||||
'operation_type_amount2' => $contractSubItem->operation_type_amount2 ?? null,
|
||||
'operation_type_progress2' => $contractSubItem->operation_type_progress2 ?? null,
|
||||
'operation_type_tonaj2' => $contractSubItem->operation_type_tonaj2 ?? null,
|
||||
|
||||
'operation_type_id3' => $contractSubItem->operation_type_id3 ?? null,
|
||||
'operation_type_fa3' => $contractSubItem->operation_type_fa3 ?? null,
|
||||
'operation_type_unit3' => $contractSubItem->operation_type_unit3 ?? null,
|
||||
'operation_type_amount3' => $contractSubItem->operation_type_amount3 ?? null,
|
||||
'operation_type_progress3' => $contractSubItem->operation_type_progress3 ?? null,
|
||||
'operation_type_tonaj3' => $contractSubItem->operation_type_tonaj3 ?? null,
|
||||
|
||||
'operation_type_id4' => $contractSubItem->operation_type_id4 ?? null,
|
||||
'operation_type_fa4' => $contractSubItem->operation_type_fa4 ?? null,
|
||||
'operation_type_unit4' => $contractSubItem->operation_type_unit4 ?? null,
|
||||
'operation_type_amount4' => $contractSubItem->operation_type_amount4 ?? null,
|
||||
'operation_type_progress4' => $contractSubItem->operation_type_progress4 ?? null,
|
||||
'operation_type_tonaj4' => $contractSubItem->operation_type_tonaj4 ?? null,
|
||||
|
||||
'city_id' => $contractSubItem->city_id,
|
||||
'city_fa' => $contractSubItem->city_fa,
|
||||
'province_id' => $contractSubItem->province_id,
|
||||
'province_fa' => $contractSubItem->province_fa,
|
||||
'axis_type_id' => $contractSubItem->axis_type_id,
|
||||
'axis_type_fa' => $contractSubItem->axis_type_fa,
|
||||
'axis_name_fa' => $contractSubItem->axis_name_fa,
|
||||
'start_lat' => $contractSubItem->start_lat,
|
||||
'end_lat' => $contractSubItem->end_lat,
|
||||
'start_lng' => $contractSubItem->start_lng,
|
||||
'end_lng' => $contractSubItem->end_lng,
|
||||
'followup_priority_project' => $contractSubItem->followup_priority_project,
|
||||
'priority_project' => $contractSubItem->priority_project,
|
||||
'operator_name' => $contractSubItem->operator_name,
|
||||
'operator_phone' => $contractSubItem->operator_phone,
|
||||
|
||||
'progress_project' => $contractSubItem->progress_project,
|
||||
'last_status_id' => $contractSubItem->last_status_id,
|
||||
'last_status_fa' => $contractSubItem->last_status_fa,
|
||||
'subitem_id' => $contractSubItem->id,
|
||||
'operation_type_progress1' => $contractSubItem->operation_type_progress1,
|
||||
'operation_type_progress2' => $contractSubItem->operation_type_progress2,
|
||||
'operation_type_progress3' => $contractSubItem->operation_type_progress3,
|
||||
'operation_type_progress4' => $contractSubItem->operation_type_progress4,
|
||||
'last_digit_project' => $contractSubItem->last_digit_project,
|
||||
'last_function_operator' => $contractSubItem->last_function_operator,
|
||||
'last_payable_operator' => $contractSubItem->last_payable_operator,
|
||||
'complete_payable' => $contractSubItem->complete_payable,
|
||||
'image_path1' => $contractSubItem->image_path1,
|
||||
'image_path2' => $contractSubItem->image_path2,
|
||||
'unique_code' => $contractSubItem->unique_code,
|
||||
'required_bitumen' => $contractSubItem->required_bitumen,
|
||||
'used_bitumen' => $contractSubItem->used_bitumen,
|
||||
'bridge_number' => $contractSubItem->bridge_number,
|
||||
'is_corrected' => 1,
|
||||
'updated_at_fa' => $contractSubItem->updated_at_fa,
|
||||
'last_date_update' => $contractSubItem->last_date_update,
|
||||
'created_at_fa' => Verta::instance(Verta::now()),
|
||||
]);
|
||||
|
||||
$data = $this->getOperationType($request, $request->project_type_id);
|
||||
|
||||
if ($request->operation_type_id1) {
|
||||
$operation1 = $data[$request->operation_type_id1];
|
||||
}
|
||||
if ($request->operation_type_id2) {
|
||||
$operation2 = $data[$request->operation_type_id2];
|
||||
}
|
||||
if ($request->operation_type_id3) {
|
||||
$operation3 = $data[$request->operation_type_id3];
|
||||
}
|
||||
if ($request->operation_type_id4) {
|
||||
$operation4 = $data[$request->operation_type_id4];
|
||||
}
|
||||
|
||||
$contract = Contracts::where('id', $request->contract_id)->first();
|
||||
|
||||
$city_fa = City::where('id', $request->city_id)->first();
|
||||
$province_fa = Province::where('id', $request->province_id)->first();
|
||||
$progress_project = ContractSubItems::checkProgressProjectCondition($request->last_status_id, $request->progress_project);
|
||||
|
||||
$contractSubItem->setProjectTypeFa($request->project_type_id);
|
||||
$contractSubItem->setAxisTypeFa($request->axis_type_id);
|
||||
$contractSubItem->setFollowupPriorityProjectFa($request->followup_priority_project_id);
|
||||
$contractSubItem->setPriorityProjectFa($request->priority_project);
|
||||
$contractSubItem->setLastStatusFa($request->last_status_id);
|
||||
|
||||
$contractSubItem->project_title = $request->project_title;
|
||||
$contractSubItem->project_type_id = $request->project_type_id;
|
||||
$contractSubItem->operation_type_id1 = $request->operation_type_id1 ?? null;
|
||||
$contractSubItem->operation_type_fa1 = $operation1['farsi'] ?? null;
|
||||
$contractSubItem->operation_type_unit1 = $operation1['unit'] ?? null;
|
||||
$contractSubItem->operation_type_amount1 = $request->operation_type_amount1 ?? null;
|
||||
$contractSubItem->operation_type_progress1 = $request->operation_type_progress1 ?? null;
|
||||
$contractSubItem->operation_type_tonaj1 = $request->operation_type_tonaj1 ?? null;
|
||||
$contractSubItem->operation_type_id2 = $request->operation_type_id2 ?? null;
|
||||
$contractSubItem->operation_type_fa2 = $operation2['farsi'] ?? null;
|
||||
$contractSubItem->operation_type_unit2 = $operation2['unit'] ?? null;
|
||||
$contractSubItem->operation_type_amount2 = $request->operation_type_amount2 ?? null;
|
||||
$contractSubItem->operation_type_progress2 = $request->operation_type_progress2 ?? null;
|
||||
$contractSubItem->operation_type_tonaj2 = $request->operation_type_tonaj2 ?? null;
|
||||
$contractSubItem->operation_type_id3 = $request->operation_type_id3 ?? null;
|
||||
$contractSubItem->operation_type_fa3 = $operation3['farsi'] ?? null;
|
||||
$contractSubItem->operation_type_unit3 = $operation3['unit'] ?? null;
|
||||
$contractSubItem->operation_type_amount3 = $request->operation_type_amount3 ?? null;
|
||||
$contractSubItem->operation_type_progress3 = $request->operation_type_progress3 ?? null;
|
||||
$contractSubItem->operation_type_tonaj3 = $request->operation_type_tonaj3 ?? null;
|
||||
$contractSubItem->operation_type_id4 = $request->operation_type_id4 ?? null;
|
||||
$contractSubItem->operation_type_fa4 = $operation4['farsi'] ?? null;
|
||||
$contractSubItem->operation_type_unit4 = $operation4['unit'] ?? null;
|
||||
$contractSubItem->operation_type_amount4 = $request->operation_type_amount4 ?? null;
|
||||
$contractSubItem->operation_type_progress4 = $request->operation_type_progress4 ?? null;
|
||||
$contractSubItem->operation_type_tonaj4 = $request->operation_type_tonaj4 ?? null;
|
||||
|
||||
$contractSubItem->operator_phone = $request->operator_phone;
|
||||
$contractSubItem->operator_name = $request->operator_name;
|
||||
|
||||
$contractSubItem->city_id = $request->city_id;
|
||||
$contractSubItem->city_fa = $city_fa->name_fa;
|
||||
$contractSubItem->province_id = $request->province_id;
|
||||
$contractSubItem->province_fa = $province_fa->name_fa;
|
||||
$contractSubItem->axis_type_id = $request->axis_type_id;
|
||||
$contractSubItem->axis_name_fa = $request->axis_name_fa;
|
||||
$contractSubItem->start_lat = $request->start_lat;
|
||||
$contractSubItem->end_lat = $request->end_lat;
|
||||
$contractSubItem->start_lng = $request->start_lng;
|
||||
$contractSubItem->end_lng = $request->end_lng;
|
||||
$contractSubItem->followup_priority_project_id = $request->followup_priority_project_id;
|
||||
$contractSubItem->priority_project = $request->priority_project;
|
||||
$contractSubItem->progress_project = $progress_project;
|
||||
$contractSubItem->last_status_id = $request->last_status_id;
|
||||
$contractSubItem->last_digit_project = $request->last_digit_project;
|
||||
$contractSubItem->last_function_operator = $request->last_function_operator;
|
||||
$contractSubItem->last_payable_operator = $request->last_payable_operator;
|
||||
$contractSubItem->complete_payable = $request->complete_payable;
|
||||
$contractSubItem->start_way_id = self::get_way_id_from_nominatim($request->start_lat, $request->start_lng);
|
||||
$contractSubItem->end_way_id = self::get_way_id_from_nominatim($request->end_lat, $request->end_lng);
|
||||
$contractSubItem->updated_at_fa = Verta::instance(Verta::now());
|
||||
$contractSubItem->user_id = Auth::user()->id;
|
||||
$contractSubItem->last_date_update = Carbon::now();
|
||||
|
||||
$contractSubItem->required_bitumen = $request->required_bitumen ?? null;
|
||||
$contractSubItem->used_bitumen = $request->used_bitumen ?? null;
|
||||
$contractSubItem->bridge_number = $request->bridge_number ?? null;
|
||||
|
||||
$contractSubItem->save();
|
||||
|
||||
$uuid = \Uuid::generate();
|
||||
if ($request->has('image1')) {
|
||||
$file1 = $request->file('image1');
|
||||
$destinationPath1 = 'storage/contract_subitems/' . now()->year . '/' . now()->month . '/';
|
||||
$filename1 = $uuid . '-one.' . $file1->getClientOriginalExtension();
|
||||
$file1->move($destinationPath1, $filename1);
|
||||
$contractSubItem->update(['image_path1' => $destinationPath1 . $filename1]);
|
||||
}
|
||||
|
||||
if ($request->has('image2')) {
|
||||
$file2 = $request->file('image2');
|
||||
$destinationPath2 = 'storage/contract_subitems/' . now()->year . '/' . now()->month . '/';
|
||||
$filename2 = $uuid . '-two.' . $file2->getClientOriginalExtension();
|
||||
$file2->move($destinationPath2, $filename2);
|
||||
$contractSubItem->update(['image_path2' => $destinationPath2 . $filename2]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $contractSubItem,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$csi = ContractSubItems::find($request->id);
|
||||
$contract = $csi->Contracts;
|
||||
if (! $csi) {
|
||||
return response()->json([
|
||||
'message' => '404 Not Found'
|
||||
], 404);
|
||||
}
|
||||
|
||||
ContractSubItemsHistory::where('subitem_id', $request->id)->delete();
|
||||
$csi->delete();
|
||||
if (count($contract->subitems) <= 0) {
|
||||
$contract->status_rel = 1;
|
||||
$contract->save();
|
||||
}
|
||||
return response()->json([
|
||||
'message' => 'success'
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function showHistory(Request $request, $id)
|
||||
{
|
||||
$history = ContractSubItemsHistory::where('subitem_id', $id)->get();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($history as $key => $value) {
|
||||
$data[] = array(
|
||||
'axis_name_fa' => $value->axis_name_fa,
|
||||
'axis_type_fa' => $value->axis_type_fa,
|
||||
'axis_type_id' => $value->axis_type_id,
|
||||
'city_fa' => $value->city_fa,
|
||||
'city_id' => $value->city_id,
|
||||
'complete_payable' => $value->complete_payable,
|
||||
'contract_date_from_parent_contract' => $value->contract_date_from_parent_contract,
|
||||
'contract_id' => $value->contract_id,
|
||||
'contract_moshaver_nezarat' => $value->contract_moshaver_nezarat,
|
||||
'contract_moshaver_tarahi' => $value->contract_moshaver_tarahi,
|
||||
'created_at' => $value->created_at,
|
||||
'created_at_fa' => $value->created_at_fa,
|
||||
'end_lat' => $value->end_lat,
|
||||
'end_lng' => $value->end_lng,
|
||||
'end_way_id' => $value->end_way_id,
|
||||
'followup_priority_project' => $value->followup_priority_project,
|
||||
'followup_priority_project_id' => $value->followup_priority_project_id,
|
||||
'id' => $value->id,
|
||||
'image_path1' => $value->image_path1,
|
||||
'image_path2' => $value->image_path2,
|
||||
'last_date_update' => $value->last_date_update,
|
||||
'last_digit_project' => $value->last_digit_project,
|
||||
'last_function_operator' => $value->last_function_operator,
|
||||
'last_payable_operator' => $value->last_payable_operator,
|
||||
'last_status_fa' => $value->last_status_fa,
|
||||
'last_status_fa_for_chart' => $value->last_status_fa_for_chart,
|
||||
'last_status_id' => $value->last_status_id,
|
||||
'operation_type_amount1' => $value->operation_type_amount1,
|
||||
'operation_type_amount2' => $value->operation_type_amount2,
|
||||
'operation_type_amount3' => $value->operation_type_amount3,
|
||||
'operation_type_amount4' => $value->operation_type_amount4,
|
||||
'operation_type_fa1' => $value->operation_type_fa1,
|
||||
'operation_type_fa2' => $value->operation_type_fa2,
|
||||
'operation_type_fa3' => $value->operation_type_fa3,
|
||||
'operation_type_fa4' => $value->operation_type_fa4,
|
||||
'operation_type_id1' => $value->operation_type_id1,
|
||||
'operation_type_id2' => $value->operation_type_id2,
|
||||
'operation_type_id3' => $value->operation_type_id3,
|
||||
'operation_type_id4' => $value->operation_type_id4,
|
||||
'operation_type_progress1' => $value->operation_type_progress1,
|
||||
'operation_type_progress2' => $value->operation_type_progress2,
|
||||
'operation_type_progress3' => $value->operation_type_progress3,
|
||||
'operation_type_progress4' => $value->operation_type_progress4,
|
||||
'operation_type_tonaj1' => $value->operation_type_tonaj1,
|
||||
'operation_type_tonaj2' => $value->operation_type_tonaj2,
|
||||
'operation_type_tonaj3' => $value->operation_type_tonaj3,
|
||||
'operation_type_tonaj4' => $value->operation_type_tonaj4,
|
||||
'operation_type_unit1' => $value->operation_type_unit1,
|
||||
'operation_type_unit2' => $value->operation_type_unit2,
|
||||
'operation_type_unit3' => $value->operation_type_unit3,
|
||||
'operation_type_unit4' => $value->operation_type_unit4,
|
||||
'contract_number' => $value->contract_number,
|
||||
'operator_name' => $value->operator_name,
|
||||
'operator_phone' => $value->operator_phone,
|
||||
'priority_project' => $value->priority_project,
|
||||
'priority_project_fa' => $value->priority_project_fa,
|
||||
'progress_project' => $value->progress_project,
|
||||
'project_title' => $value->project_title,
|
||||
'project_type_fa' => $value->project_type_fa,
|
||||
'project_type_fa_for_chart' => $value->project_type_fa_for_chart,
|
||||
'project_type_id' => $value->project_type_id,
|
||||
'province_fa' => $value->province_fa,
|
||||
'province_id' => $value->province_id,
|
||||
'start_lat' => $value->start_lat,
|
||||
'start_lng' => $value->start_lng,
|
||||
'start_way_id' => $value->start_way_id,
|
||||
'unique_code' => $value->unique_code,
|
||||
'required_bitumen' => $value->required_bitumen,
|
||||
'used_bitumen' => $value->used_bitumen,
|
||||
'bridge_number' => $value->bridge_number,
|
||||
'updated_at' => $value->updated_at,
|
||||
'updated_at_fa' => $value->updated_at_fa,
|
||||
'user_id' => $value->user_id,
|
||||
);
|
||||
}
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public function sms_sender($mobile, $msg)
|
||||
{
|
||||
$client=new SoapClient("http://sms1000.ir/webservice/smspro.asmx?WSDL");
|
||||
$result=$client->doSendSMS(
|
||||
array(
|
||||
'uUsername' => 'rmto',
|
||||
'uPassword' => 'Rahdari8
|
||||
',
|
||||
'uNumber' => '1000141',
|
||||
'uCellphones' => $mobile,
|
||||
'uMessage' => $msg,
|
||||
'uFarsi' => true,
|
||||
'uTopic' => false,
|
||||
'uFlash' => false
|
||||
)
|
||||
);
|
||||
$x = $result->doSendSMSResult;
|
||||
return $x;
|
||||
}
|
||||
|
||||
public function get_way_id_from_nominatim($lat, $lng)
|
||||
{
|
||||
$url = "https://testmap.141.ir/nominatim/reverse?format=jsonv2&lat=".$lat."&lon=".$lng."&zoom=16&addressdetails=16";
|
||||
$arrContextOptions=array(
|
||||
"ssl"=>array(
|
||||
"verify_peer"=>false,
|
||||
"verify_peer_name"=>false,
|
||||
),
|
||||
);
|
||||
|
||||
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
|
||||
$result = json_decode($result);
|
||||
if (isset($result->osm_type)) {
|
||||
if ($result->osm_type == 'way') {
|
||||
return $result->osm_id;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getAllOperationList()
|
||||
{
|
||||
return $response = [
|
||||
'1' => [
|
||||
'id' => 1,
|
||||
'farsi' => 'روکش آسفالت(نگهداری رویه راه)',
|
||||
'en_name' => 'maintanance',
|
||||
'chart' => 'روکش آسفالت',
|
||||
'is_line' => 0,
|
||||
'color' => "#ff0000ff",
|
||||
|
||||
],
|
||||
'2' => [
|
||||
'id' => 2,
|
||||
'farsi' => 'رفع نقاط حادثه خیز',
|
||||
'en_name' => 'dangerpoint',
|
||||
'chart' => 'نقاط حادثه خیز',
|
||||
'is_line' => 0,
|
||||
'color' => "#ff0dff",
|
||||
],
|
||||
'3' => [
|
||||
'id' => 3,
|
||||
'farsi' => 'ارتقای ایمنی راه',
|
||||
'en_name' => 'upgradesaifty',
|
||||
'chart' => 'ایمنی راه',
|
||||
'is_line' => 0,
|
||||
'color' => "#5900ff",
|
||||
|
||||
],
|
||||
'4' => [
|
||||
'id' => 4,
|
||||
'farsi' => 'ابنیه فنی(تعمیر و بازسازی)',
|
||||
'en_name' => 'technical',
|
||||
'chart' => 'ابنیه فنی',
|
||||
'is_line' => 0,
|
||||
'color' => "#0099ff",
|
||||
],
|
||||
'5' => [
|
||||
'id' => 5,
|
||||
'farsi' => 'راهدارخانه ها',
|
||||
'en_name' => 'tollhouse',
|
||||
'chart' => 'راهدارخانه',
|
||||
'is_line' => 0,
|
||||
'color' => "#0c4e17",
|
||||
|
||||
],
|
||||
'6' => [
|
||||
'id' => 6,
|
||||
'farsi' => 'ساخت راه روستایی',
|
||||
'en_name' => 'village',
|
||||
'chart' => 'راه روستایی',
|
||||
'is_line' => 1,
|
||||
'color' => "#bfa30a",
|
||||
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getOperationType(Request $request, $id)
|
||||
{
|
||||
switch ($id) {
|
||||
case "1":
|
||||
$response = [
|
||||
'101' => [
|
||||
'farsi' => 'روکش آسفالت گرم',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'102' => [
|
||||
'farsi' => 'ماسه آسفالت',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'103' => [
|
||||
'farsi' => 'بازیافت سرد و گرم',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'104' => [
|
||||
'farsi' => 'میکروسرفیسینگ',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'105' => [
|
||||
'farsi' => 'چیپ سیل',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'106' => [
|
||||
'farsi' => 'اسلاری سیل',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'107' => [
|
||||
'farsi' => 'اسکراب سیل',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'108' => [
|
||||
'farsi' => 'فوگ سیل',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'109' => [
|
||||
'farsi' => 'سیل کت',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'110' => [
|
||||
'farsi' => 'کیپ سیل',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'111' => [
|
||||
'farsi' => 'آسفالت سرد/ردمیکس',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'112' => [
|
||||
'farsi' => 'لکه گیری',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'113' => [
|
||||
'farsi' => 'درزگیری',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
];
|
||||
break;
|
||||
case "2":
|
||||
$response = [
|
||||
"201" => [
|
||||
'farsi' => 'تعریض راه',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
"202" => [
|
||||
'farsi' => 'اصلاح قوس',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
"203" => [
|
||||
'farsi' => 'ترانشه برداری',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
"204" => [
|
||||
'farsi' => 'اصلاح یا احداث میدان',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
"205" => [
|
||||
'farsi' => 'احداث تقاطع غیرهمسطح یا همسطح',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
"206" => [
|
||||
'farsi' => 'ایمن سازی با علائم و حفاظ',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
"207" => [
|
||||
'farsi' => 'اصلاح ورودی و خروجی',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
"208" => [
|
||||
'farsi' => 'احداث تونل',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
"209" => [
|
||||
'farsi' => 'احداث واربانت',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
"210" => [
|
||||
'farsi' => 'تعریض ابنیه فنی',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
"211" => [
|
||||
'farsi' => 'ساخت دیوار حایل',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
"212" => [
|
||||
'farsi' => 'سایر اقدامات',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
]
|
||||
];
|
||||
break;
|
||||
case "3":
|
||||
$response = [
|
||||
'301' => [
|
||||
'farsi' => 'نصب حفاظ بتنی',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'302' => [
|
||||
'farsi' => 'نصب حفاظ فلزی/گاردریل',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'303' => [
|
||||
'farsi' => 'اجرای روشنایی طولی',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'304' => [
|
||||
'farsi' => 'اجرای روشنایی نقطه ای',
|
||||
'unit' => 'تعداد',
|
||||
'amountable' => 1
|
||||
],
|
||||
'305' => [
|
||||
'farsi' => 'نصب علائم ایمنی',
|
||||
'unit' => 'تعداد',
|
||||
'amountable' => 1
|
||||
],
|
||||
'306' => [
|
||||
'farsi' => 'خط کشی',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'307' => [
|
||||
'farsi' => 'اصلاح شیب شیروانی',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'308' => [
|
||||
'farsi' => 'سایر اقدامات',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
'309' => [
|
||||
'farsi' => 'اجرای شیار لرزاننده طولی',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'310' => [
|
||||
'farsi' => 'اجرای شیار لرزاننده عرضی',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
]
|
||||
];
|
||||
break;
|
||||
case "4":
|
||||
$response = [
|
||||
'401' => [
|
||||
'farsi' => 'تعریض پل/آبرو',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
'402' => [
|
||||
'farsi' => 'تعمیرات اساسی پل',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
'403' => [
|
||||
'farsi' => 'تعمیرات تونل',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
'404' => [
|
||||
'farsi' => 'تعمیر یا احداث دیوار حائل',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
'405' => [
|
||||
'farsi' => 'احداث پل جدید',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
'406' => [
|
||||
'farsi' => 'احداث کنارگذر پل/تونل',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
'407' => [
|
||||
'farsi' => 'سایر اقدامات',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
]
|
||||
];
|
||||
break;
|
||||
case "5":
|
||||
$response = [
|
||||
'501' => [
|
||||
'farsi' => 'احداث راهدارخانه جدید',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
'502' => [
|
||||
'farsi' => 'احداث انبار شن و نمک',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
'503' => [
|
||||
'farsi' => 'نوسازی و بهسازی راهدارخانه',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
'504' => [
|
||||
'farsi' => 'احداث آشیانه ماشین آلات',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
'505' => [
|
||||
'farsi' => 'محوطه سازی / دیوار کشی',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
],
|
||||
'506' => [
|
||||
'farsi' => 'سایر اقدامات',
|
||||
'unit' => '',
|
||||
'amountable' => 0
|
||||
]
|
||||
];
|
||||
break;
|
||||
case "6":
|
||||
$response = [
|
||||
'601' => [
|
||||
'farsi' => 'عملیات خاکی و زیرسازی',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'602' => [
|
||||
'farsi' => 'روسازی',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
],
|
||||
'603' => [
|
||||
'farsi' => 'ابنیه فنی',
|
||||
'unit' => 'دستگاه',
|
||||
'amountable' => 1
|
||||
],
|
||||
'604' => [
|
||||
'farsi' => 'آسفالت',
|
||||
'unit' => 'کیلومتر',
|
||||
'amountable' => 1
|
||||
]
|
||||
];
|
||||
break;
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
430
app/Http/Controllers/Api/Excel/ReportController.php
Normal file
430
app/Http/Controllers/Api/Excel/ReportController.php
Normal file
@@ -0,0 +1,430 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Excel;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Exports\Maintanance\allSheet as MaintananceSheets;
|
||||
use App\Exports\RoadDanger\allSheet as RoadDangerSheets;
|
||||
use App\Exports\RoadUpgrade\allSheet as RoadUpgradeSheets;
|
||||
use App\Exports\Technical\allSheet as TechnicalSheets;
|
||||
use App\Exports\Tollhouse\allSheet as TollhouseSheets;
|
||||
use App\Exports\Village\allSheet as VillageSheets;
|
||||
use App\Exports\AxisReport\AllSheet as AxisReportsSheets;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Exports\Activities\One\AllSheets as OneSheet;
|
||||
use App\Exports\Activities\Two\AllSheets as TwoSheet;
|
||||
use App\Exports\Activities\Three\Activity as ActivitySheet;
|
||||
|
||||
use App\Exports\Activities\Two\Alaem\AllSheets as AlaemSheet;
|
||||
use App\Exports\Activities\Two\Paksazi\AllSheets as PaksaziSheet;
|
||||
use App\Exports\Activities\Two\Hefaz\AllSheets as HefazSheet;
|
||||
use App\Exports\Activities\Two\Roshanaei\AllSheets as RoshanaeiSheet;
|
||||
use App\Exports\Activities\Two\Khatkeshi\AllSheets as KhatkeshiSheet;
|
||||
use App\Exports\Activities\Two\Zemestani\AllSheets as ZemestaniSheet;
|
||||
use App\Exports\Activities\Two\Rangamizi\AllSheets as RangamiziSheet;
|
||||
use App\Exports\Activities\Two\Shosteshoo\AllSheets as ShosteshooSheet;
|
||||
use App\Exports\Activities\Two\Imensazi\AllSheets as ImensaziSheet;
|
||||
use App\Exports\Activities\Two\Harim\AllSheets as HarimSheet;
|
||||
use App\Exports\Activities\Two\Pol\AllSheets as PolSheet;
|
||||
use App\Exports\Activities\Two\Toonel\AllSheets as ToonelSheet;
|
||||
use App\Exports\Activities\Two\Mashinalat\AllSheets as MashinalatSheet;
|
||||
use App\Exports\Activities\Two\Rahdar\AllSheets as RahdarSheet;
|
||||
use App\Exports\Activities\Two\Ezterari\AllSheets as EzterariSheet;
|
||||
use App\Exports\Activities\Two\Bazrasi\AllSheets as BazrasiSheet;
|
||||
use App\Exports\Receipts\AllSheets as ReceiptSheet;
|
||||
use App\Exports\User\AllSheets as UserList;
|
||||
use App\Exports\UserActivity\AllSheet as UserActivity;
|
||||
use App\Exports\DailyAccident\AllSheets as DailyAccident;
|
||||
use App\Exports\RoadItems\AllSheets as RoadItems;
|
||||
use App\Exports\RoadPatrol\AllSheets as RoadPatrol;
|
||||
use App\Exports\SafetyAndPrivacy\AllSheets as SafetyAndPrivacy;
|
||||
|
||||
use App\Exports\ContractsExport;
|
||||
use App\Exports\LawmakersExport;
|
||||
use App\Exports\ProposalExport;
|
||||
|
||||
|
||||
use App\Exports\FastNewReactPendingExport;
|
||||
use App\Exports\FastNewReactDoneExport;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
public function downloadContracts(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1010);
|
||||
// $name = 'گزارش لیست قراردادها ' . verta(Carbon::now())->format('Y-m-d H-i') . '.xlsx';
|
||||
$name = 'گزارش لیست قراردادها ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new ContractsExport(
|
||||
$request->fromDate,
|
||||
$request->toDate,
|
||||
$request->province,
|
||||
$request->status,
|
||||
$request->projectType,
|
||||
$request->status_rel
|
||||
), $name);
|
||||
}
|
||||
|
||||
public function downloadLawmakers(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1093);
|
||||
$name = 'گزارش مکاتبات نمایندگان مجلس ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new LawmakersExport(
|
||||
$request->constituency,
|
||||
$request->province,
|
||||
), $name);
|
||||
}
|
||||
|
||||
public function downloadProposal(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1094);
|
||||
$name = 'گزارش پروژه های پیشنهادی ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new ProposalExport(
|
||||
$request->province,
|
||||
), $name);
|
||||
}
|
||||
|
||||
|
||||
public function downloadMaintanance(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1087);
|
||||
$name = 'گزارش از پروژه ها - جمع بندی روکش آسفالت ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new MaintananceSheets($request->fromDate, $request->toDate, $request->province, $request->last_status_id), $name);
|
||||
}
|
||||
|
||||
public function downloadVillage(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1088);
|
||||
$name = 'گزارش از پروژه ها - جمع بندی ساخت راه های روستایی ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new VillageSheets($request->fromDate, $request->toDate, $request->province, $request->last_status_id), $name);
|
||||
}
|
||||
|
||||
public function downloadRoadDanger(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1089);
|
||||
$name = 'گزارش از پروژه ها - جمع بندی نقاط حادثه خیز ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new RoadDangerSheets($request->fromDate, $request->toDate, $request->province, $request->last_status_id), $name);
|
||||
}
|
||||
|
||||
public function downloadRoadUpgrade(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1090);
|
||||
$name = 'گزارش از پروژه ها - جمع بندی ارتقای ایمنی راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new RoadUpgradeSheets($request->fromDate, $request->toDate, $request->province, $request->last_status_id), $name);
|
||||
}
|
||||
|
||||
public function downloadTechnical(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1091);
|
||||
$name = 'گزارش از پروژه ها - جمع بندی ابنیه فنی ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new TechnicalSheets($request->fromDate, $request->toDate, $request->province, $request->last_status_id), $name);
|
||||
}
|
||||
|
||||
public function downloadTollhouse(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1092);
|
||||
$name = 'گزارش از پروژه ها - جمع بندی راهدارخانه ها ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new TollhouseSheets($request->fromDate, $request->toDate, $request->province, $request->last_status_id), $name);
|
||||
}
|
||||
|
||||
|
||||
public function downloadActivitiesOne(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1034);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری - جدول 1 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new OneSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadActivitiesThree(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1035);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری - جدول 3 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new ActivitySheet($request->fromDate, $request->toDate, $request->province, $request->last_status_id), $name);
|
||||
}
|
||||
|
||||
|
||||
public function downloadFastNewReactPending(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1095);
|
||||
$name = 'گزارش از واکنش سریع ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new FastNewReactPendingExport($request->fromDate, $request->toDate, $request->province, $request->last_status_id), $name);
|
||||
}
|
||||
|
||||
public function downloadFastNewReactDone(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1095);
|
||||
$name = 'گزارش از واکنش سریع ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new FastNewReactDoneExport($request->fromDate, $request->toDate, $request->province, $request->last_status_id), $name);
|
||||
}
|
||||
|
||||
public function downloadAxisReports(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1096);
|
||||
$patrols = $request->patrol ?? null;
|
||||
$activities = $request->activity ?? null;
|
||||
$projects = $request->project ?? null;
|
||||
$observeds = $request->observed ?? null;
|
||||
$name = 'گزارش محوری ' . verta()->now()->format('Y-m-d H-i') .'.xlsx';
|
||||
return Excel::download(new AxisReportsSheets($patrols, $activities, $projects, $observeds), $name);
|
||||
}
|
||||
|
||||
public function downloadMaremat(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1097);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(مرمت رویه) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new TwoSheet($request->fromDate, $request->toDate, $request->province, $request->last_status_id), $name);
|
||||
}
|
||||
|
||||
public function downloadPaksazi(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1098);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(پاکسازی) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new PaksaziSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadAlaem(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1099);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(علائم) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new AlaemSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
|
||||
public function downloadHefaz(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1100);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(حفاظ) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new HefazSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadRoshanaei(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1101);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(روشنایی) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new RoshanaeiSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadKhatkeshi(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1102);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(خطکشی) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new KhatkeshiSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadZemestani(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1103);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری( زمستانی) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new ZemestaniSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadRangamizi(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1104);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(رنگ آمیزی) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new RangamiziSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadShosteshoo(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1105);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(شستشو) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new ShosteshooSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadImensazi(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1106);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(ایمن سازی) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new ImensaziSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadHarim(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1107);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(حریم) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new HarimSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadPol(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1108);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(پل) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new PolSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadToonel(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1109);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(تونل) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new ToonelSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadMashinalat(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1110);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(ماشین آلات) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new MashinalatSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadRahdar(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1111);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(راهدارخانه) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new RahdarSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
public function downloadEzterari(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1112);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(اظطراری) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new EzterariSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadbazrasi(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1113);
|
||||
$name = 'گزارش از فعالیت روزانه و جاری(بازرسی) - جدول 2 ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new BazrasiSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadUserActivityReport(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1116);
|
||||
$name = 'گزارش از فعالیت کاربران ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new UserActivity($request->group_id, $request->fromDate, $request->toDate), $name);
|
||||
}
|
||||
|
||||
public function downloadReceiptReport(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1126);
|
||||
$name = 'گزارش از خسارات وارده به ابنیه فنی و تاسیسات راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new ReceiptSheet($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadUserReport(Request $request)
|
||||
{
|
||||
auth()->user()->addActivityComplete(1127);
|
||||
$name = 'گزارش از کاربران سایت ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new UserList($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadDailyAccidentReport(Request $request)
|
||||
{
|
||||
$name = 'گزارش از تصادفات روزانه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new DailyAccident($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadRoadItemsReport(Request $request)
|
||||
{
|
||||
$name = 'گزارش از فعالیت روزانه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new RoadItems($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
|
||||
public function downloadRoadPatrolsReport(Request $request)
|
||||
{
|
||||
$name = 'گزارش از گشت راهداری روزانه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new RoadPatrol($request->fromDate, $request->toDate, $request->province), $name);
|
||||
}
|
||||
|
||||
public function downloadSafetyAndPrivacyReport(Request $request)
|
||||
{
|
||||
$name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
// return Excel::download(new SafetyAndPrivacy($request->fromDate, $request->toDate, $request->province), $name);
|
||||
return Excel::download(new SafetyAndPrivacy($request->id, $request->info_id, $request->step, $request->fromDate,
|
||||
$request->toDate, $request->province_id), $name);
|
||||
|
||||
}
|
||||
|
||||
public function redirect(Request $request)
|
||||
{
|
||||
if ($request->province) {
|
||||
$url_correction = "&province={$request->province}";
|
||||
}else {
|
||||
$url_correction = "";
|
||||
}
|
||||
|
||||
switch ($request->type) {
|
||||
case 1:
|
||||
return redirect("/reports/two/maremat?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
return redirect("/reports/two/paksazi?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
return redirect("/reports/two/alaem?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
return redirect("/reports/two/hefaz?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
return redirect("/reports/two/roshanaei?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
return redirect("/reports/two/khatkeshi?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
return redirect("/reports/two/rangamizi?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
return redirect("/reports/two/shosteshoo?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
return redirect("/reports/two/imensazi?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
|
||||
case 10:
|
||||
return redirect("/reports/two/harim?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
|
||||
case 11:
|
||||
return redirect("/reports/two/pol?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 12:
|
||||
return redirect("/reports/two/toonel?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 13:
|
||||
return redirect("/reports/two/zemestani?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 14:
|
||||
return redirect("/reports/two/mashinalat?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 15:
|
||||
return redirect("/reports/two/rahdar?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 16:
|
||||
return redirect("/reports/two/ezterari?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
case 20:
|
||||
return redirect("/reports/two/bazrasi?fromDate={$request->fromDate}&toDate={$request->toDate}".$url_correction);
|
||||
break;
|
||||
|
||||
default:
|
||||
return response()->json([
|
||||
'error' => '404'
|
||||
], 404);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
483
app/Http/Controllers/Api/FinanceProjectController.php
Normal file
483
app/Http/Controllers/Api/FinanceProjectController.php
Normal file
@@ -0,0 +1,483 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Contracts;
|
||||
use App\Models\RoadMaintenanceProject;
|
||||
use App\Models\RoadUpgradeSafety;
|
||||
use App\Models\RoadDangerPrevention;
|
||||
use App\Models\RoadTechnicalBuilding;
|
||||
use App\Models\RoadTollhouseManagement;
|
||||
|
||||
class FinanceProjectController extends Controller
|
||||
{
|
||||
public function getMaintenanceProjectList(Request $request)
|
||||
{
|
||||
if ($request->has('project_id')) {
|
||||
$getProvinceID = Contracts::where('id', $request->project_id)->first();
|
||||
$roadProjects = RoadMaintenanceProject::with('latestHistory')
|
||||
->where('province_id', $getProvinceID->province_id)
|
||||
->get();
|
||||
} else {
|
||||
$roadProjects = RoadMaintenanceProject::with('latestHistory')->get();
|
||||
}
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $roadProjects,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function showMaintenanceProjectData(Request $request)
|
||||
{
|
||||
$roadProject = RoadMaintenanceProject::find($request->id);
|
||||
$roadProjectHistories = $roadProject->projectHistories;
|
||||
|
||||
$roadProjectHistoriesFiles = [];
|
||||
$imagesIndex = 0;
|
||||
|
||||
foreach ($roadProjectHistories as $key => $roadProjectHistory) {
|
||||
foreach ($roadProjectHistory->files as $keyPath => $file) {
|
||||
$roadProjectHistoriesFiles[$imagesIndex] = asset('storage' . substr($file->path, 6));
|
||||
$imagesIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
$cities = [];
|
||||
$citiesIndex = 0;
|
||||
|
||||
foreach ($roadProject->cities_id as $cityKey => $value) {
|
||||
$getCity = \App\Models\City::find($cityKey);
|
||||
|
||||
$cities[$citiesIndex] = [
|
||||
'id' => $getCity->id,
|
||||
'name' => $getCity->name_fa,
|
||||
'value' => $value
|
||||
];
|
||||
|
||||
$citiesIndex++;
|
||||
}
|
||||
|
||||
$roadProjectArray = [
|
||||
'id' => $roadProject->id,
|
||||
'province' => [
|
||||
'id' => ($roadProject->province) ? $roadProject->province->id : null,
|
||||
'name' => ($roadProject->province) ? $roadProject->province->name_fa : '-',
|
||||
'lat_lng' => [
|
||||
$roadProject->province->center_lat,
|
||||
$roadProject->province->center_long
|
||||
]
|
||||
],
|
||||
'cities' => $cities,
|
||||
'axis_name' => ($roadProject->axis_name) ? $roadProject->axis_name : '-',
|
||||
'axis_type' => ($roadProject->axis_type) ? : 0,
|
||||
'project_name' => ($roadProject->project_name) ? $roadProject->project_name : '-',
|
||||
'contractor_name' => ($roadProject->contractor_name) ? $roadProject->contractor_name : '-',
|
||||
'consultant_name' => ($roadProject->consultant_name) ? $roadProject->consultant_name : '-',
|
||||
'contract_date' => ($roadProject->contract_date) ? $roadProject->contract_date : '-',
|
||||
'contract_credit' => ($roadProject->contract_credit) ? $roadProject->contract_credit : '-',
|
||||
'submited_at' => ($roadProject->submited_at) ?
|
||||
verta($roadProject->submited_at)->format('Y/n/j - H:i') : '-',
|
||||
'last_updated_at' => ($roadProject->last_updated_at) ?
|
||||
verta($roadProject->last_updated_at)->format('Y/n/j - H:i') : '-',
|
||||
'start_latlng' => $roadProject->start_latlng,
|
||||
'end_latlng' => $roadProject->end_latlng,
|
||||
'project_distance' => $roadProject->project_distance,
|
||||
'project_distance_update' => $roadProject->project_distance_update,
|
||||
'physical_progress' => $roadProject->physical_progress,
|
||||
'images' => $roadProjectHistoriesFiles,
|
||||
'project_status' => $roadProject->project_status,
|
||||
'rate' => ($roadProject->rate)? $roadProject->rate:null,
|
||||
'rate_desc' => ($roadProject->rate_desc)? $roadProject->rate_desc:null
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => [
|
||||
$roadProjectArray
|
||||
]
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
||||
public function getUpgradeSafetyList(Request $request)
|
||||
{
|
||||
if ($request->has('project_id')) {
|
||||
$getProvinceID = Contracts::where('id', $request->project_id)->first();
|
||||
$roadProjects = RoadUpgradeSafety::with('latestHistory')
|
||||
->where('province_id', $getProvinceID->province_id)
|
||||
->get();
|
||||
} else {
|
||||
$roadProjects = RoadUpgradeSafety::with('latestHistory')->get();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $roadProjects,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function showUpgradeSafetyData(Request $request)
|
||||
{
|
||||
$roadProject = RoadUpgradeSafety::find($request->id);
|
||||
$roadProjectHistories = $roadProject->projectHistories;
|
||||
|
||||
$roadProjectHistoriesFiles = [];
|
||||
$imagesIndex = 0;
|
||||
|
||||
foreach ($roadProjectHistories as $key => $roadProjectHistory) {
|
||||
foreach ($roadProjectHistory->files as $keyPath => $file) {
|
||||
$roadProjectHistoriesFiles[$imagesIndex] = asset('storage' . substr($file->path, 6));
|
||||
$imagesIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
$cities = [];
|
||||
$citiesIndex = 0;
|
||||
|
||||
foreach ($roadProject->cities_id as $cityKey => $value) {
|
||||
$getCity = \App\Models\City::find($cityKey);
|
||||
|
||||
$cities[$citiesIndex] = [
|
||||
'id' => $getCity->id,
|
||||
'name' => $getCity->name_fa,
|
||||
'value' => $value
|
||||
];
|
||||
|
||||
$citiesIndex++;
|
||||
}
|
||||
|
||||
$roadProjectArray = [
|
||||
'id' => $roadProject->id,
|
||||
'province' => [
|
||||
'id' => ($roadProject->province) ? $roadProject->province->id : null,
|
||||
'name' => ($roadProject->province) ? $roadProject->province->name_fa : '-',
|
||||
'lat_lng' => [
|
||||
$roadProject->province->center_lat,
|
||||
$roadProject->province->center_long
|
||||
]
|
||||
],
|
||||
'cities' => $cities,
|
||||
'axis_name' => ($roadProject->axis_name) ? $roadProject->axis_name : '-',
|
||||
'axis_type' => ($roadProject->axis_type) ? : 0,
|
||||
'project_name' => ($roadProject->project_name) ? $roadProject->project_name : '-',
|
||||
'contractor_name' => ($roadProject->contractor_name) ? $roadProject->contractor_name : '-',
|
||||
'consultant_name' => ($roadProject->consultant_name) ? $roadProject->consultant_name : '-',
|
||||
'contract_date' => ($roadProject->contract_date) ? $roadProject->contract_date : '-',
|
||||
'contract_credit' => ($roadProject->contract_credit) ? $roadProject->contract_credit : '-',
|
||||
'submited_at' => ($roadProject->submited_at) ?
|
||||
verta($roadProject->submited_at)->format('Y/n/j - H:i') : '-',
|
||||
'last_updated_at' => ($roadProject->last_updated_at) ?
|
||||
verta($roadProject->last_updated_at)->format('Y/n/j - H:i') : '-',
|
||||
'start_latlng' => $roadProject->start_latlng,
|
||||
'end_latlng' => $roadProject->end_latlng,
|
||||
'project_distance' => $roadProject->project_distance,
|
||||
'project_distance_update' => $roadProject->project_distance_update,
|
||||
'physical_progress' => $roadProject->physical_progress,
|
||||
// 'credit_progress' => ((($roadProject->contract_credit - $roadProject->contractor_credit)
|
||||
// / $roadProject->contract_credit) * 100),
|
||||
'images' => $roadProjectHistoriesFiles,
|
||||
'project_status' => $roadProject->project_status,
|
||||
'project_description' => $roadProject->project_description,
|
||||
'rate' => ($roadProject->rate)? $roadProject->rate:null,
|
||||
'rate_desc' => ($roadProject->rate_desc)? $roadProject->rate_desc:null
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => [
|
||||
$roadProjectArray
|
||||
]
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
||||
public function getDangerPreventionList(Request $request)
|
||||
{
|
||||
if ($request->has('project_id')) {
|
||||
$getProvinceID = Contracts::where('id', $request->project_id)->first();
|
||||
$roadProjects = RoadDangerPrevention::with('latestHistory')
|
||||
->where('province_id', $getProvinceID->province_id)
|
||||
->get();
|
||||
} else {
|
||||
$roadProjects = RoadDangerPrevention::with('latestHistory')->get();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $roadProjects,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function showDangerPreventionData(Request $request)
|
||||
{
|
||||
$roadProject = RoadDangerPrevention::find($request->id);
|
||||
$roadProjectHistories = $roadProject->projectHistories;
|
||||
|
||||
$roadProjectHistoriesFiles = [];
|
||||
$imagesIndex = 0;
|
||||
|
||||
foreach ($roadProjectHistories as $key => $roadProjectHistory) {
|
||||
foreach ($roadProjectHistory->files as $keyPath => $file) {
|
||||
$roadProjectHistoriesFiles[$imagesIndex] = asset('storage' . substr($file->path, 6));
|
||||
$imagesIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
$cities = [];
|
||||
$citiesIndex = 0;
|
||||
|
||||
foreach ($roadProject->cities_id as $cityKey => $value) {
|
||||
$getCity = \App\Models\City::find($cityKey);
|
||||
|
||||
$cities[$citiesIndex] = [
|
||||
'id' => $getCity->id,
|
||||
'name' => $getCity->name_fa,
|
||||
'value' => $value
|
||||
];
|
||||
|
||||
$citiesIndex++;
|
||||
}
|
||||
|
||||
$roadProjectArray = [
|
||||
'id' => $roadProject->id,
|
||||
'province' => [
|
||||
'id' => ($roadProject->province) ? $roadProject->province->id : null,
|
||||
'name' => ($roadProject->province) ? $roadProject->province->name_fa : '-',
|
||||
'lat_lng' => [
|
||||
$roadProject->province->center_lat,
|
||||
$roadProject->province->center_long
|
||||
]
|
||||
],
|
||||
'cities' => $cities,
|
||||
'axis_name' => ($roadProject->axis_name) ? $roadProject->axis_name : '-',
|
||||
'axis_type' => ($roadProject->axis_type) ? : 0,
|
||||
'project_name' => ($roadProject->project_name) ? $roadProject->project_name : '-',
|
||||
'contractor_name' => ($roadProject->contractor_name) ? $roadProject->contractor_name : '-',
|
||||
'consultant_name' => ($roadProject->consultant_name) ? $roadProject->consultant_name : '-',
|
||||
'contract_date' => ($roadProject->contract_date) ? $roadProject->contract_date : '-',
|
||||
'contract_credit' => ($roadProject->contract_credit) ? $roadProject->contract_credit : '-',
|
||||
'submited_at' => ($roadProject->submited_at) ?
|
||||
verta($roadProject->submited_at)->format('Y/n/j - H:i') : '-',
|
||||
'last_updated_at' => ($roadProject->last_updated_at) ?
|
||||
verta($roadProject->last_updated_at)->format('Y/n/j - H:i') : '-',
|
||||
'start_latlng' => $roadProject->start_latlng,
|
||||
'end_latlng' => $roadProject->end_latlng,
|
||||
'project_distance' => $roadProject->project_distance,
|
||||
'project_distance_update' => $roadProject->project_distance_update,
|
||||
'physical_progress' => $roadProject->physical_progress,
|
||||
// 'credit_progress' => ((($roadProject->contract_credit - $roadProject->contractor_credit)
|
||||
// / $roadProject->contract_credit) * 100),
|
||||
'images' => $roadProjectHistoriesFiles,
|
||||
'project_status' => $roadProject->project_status,
|
||||
'project_description' => $roadProject->project_description,
|
||||
'rate' => ($roadProject->rate)? $roadProject->rate:null,
|
||||
'rate_desc' => ($roadProject->rate_desc)? $roadProject->rate_desc:null
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => [
|
||||
$roadProjectArray
|
||||
]
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function getTechnicalBuildingList(Request $request)
|
||||
{
|
||||
if ($request->has('project_id')) {
|
||||
$getProvinceID = Contracts::where('id', $request->project_id)->first();
|
||||
$roadProjects = RoadTechnicalBuilding::with('latestHistory')
|
||||
->where('province_id', $getProvinceID->province_id)
|
||||
->get();
|
||||
} else {
|
||||
$roadProjects = RoadTechnicalBuilding::with('latestHistory')->get();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $roadProjects,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function showTechnicalBuildingData(Request $request)
|
||||
{
|
||||
$roadProject = RoadTechnicalBuilding::find($request->id);
|
||||
$roadProjectHistories = $roadProject->projectHistories;
|
||||
|
||||
$roadProjectHistoriesFiles = [];
|
||||
$imagesIndex = 0;
|
||||
|
||||
foreach ($roadProjectHistories as $key => $roadProjectHistory) {
|
||||
foreach ($roadProjectHistory->files as $keyPath => $file) {
|
||||
$roadProjectHistoriesFiles[$imagesIndex] = asset('storage' . substr($file->path, 6));
|
||||
$imagesIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
$cities = [];
|
||||
$citiesIndex = 0;
|
||||
|
||||
foreach ($roadProject->cities_id as $cityKey => $value) {
|
||||
$getCity = \App\Models\City::find($cityKey);
|
||||
|
||||
$cities[$citiesIndex] = [
|
||||
'id' => $getCity->id,
|
||||
'name' => $getCity->name_fa,
|
||||
'value' => $value
|
||||
];
|
||||
|
||||
$citiesIndex++;
|
||||
}
|
||||
|
||||
$roadProjectArray = [
|
||||
'id' => $roadProject->id,
|
||||
'province' => [
|
||||
'id' => ($roadProject->province) ? $roadProject->province->id : null,
|
||||
'name' => ($roadProject->province) ? $roadProject->province->name_fa : '-',
|
||||
'lat_lng' => [
|
||||
$roadProject->province->center_lat,
|
||||
$roadProject->province->center_long
|
||||
]
|
||||
],
|
||||
'cities' => $cities,
|
||||
'axis_name' => ($roadProject->axis_name) ? $roadProject->axis_name : '-',
|
||||
'axis_type' => ($roadProject->axis_type) ? : 0,
|
||||
'project_name' => ($roadProject->project_name) ? $roadProject->project_name : '-',
|
||||
'contractor_name' => ($roadProject->contractor_name) ? $roadProject->contractor_name : '-',
|
||||
'consultant_name' => ($roadProject->consultant_name) ? $roadProject->consultant_name : '-',
|
||||
'contract_date' => ($roadProject->contract_date) ? $roadProject->contract_date : '-',
|
||||
'contract_credit' => ($roadProject->contract_credit) ? $roadProject->contract_credit : '-',
|
||||
'submited_at' => ($roadProject->submited_at) ?
|
||||
verta($roadProject->submited_at)->format('Y/n/j - H:i') : '-',
|
||||
'last_updated_at' => ($roadProject->last_updated_at) ?
|
||||
verta($roadProject->last_updated_at)->format('Y/n/j - H:i') : '-',
|
||||
'start_latlng' => $roadProject->start_latlng,
|
||||
'end_latlng' => $roadProject->end_latlng,
|
||||
'project_distance' => $roadProject->project_distance,
|
||||
'project_distance_update' => $roadProject->project_distance_update,
|
||||
'physical_progress' => $roadProject->physical_progress,
|
||||
// 'credit_progress' => ((($roadProject->contract_credit - $roadProject->contractor_credit)
|
||||
// / $roadProject->contract_credit) * 100),
|
||||
'images' => $roadProjectHistoriesFiles,
|
||||
'project_status' => $roadProject->project_status,
|
||||
'project_description' => $roadProject->project_description,
|
||||
'rate' => ($roadProject->rate)? $roadProject->rate:null,
|
||||
'rate_desc' => ($roadProject->rate_desc)? $roadProject->rate_desc:null
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => [
|
||||
$roadProjectArray
|
||||
]
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
||||
public function getTollhouseManagementListPublic(Request $request)
|
||||
{
|
||||
if ($request->has('project_id')) {
|
||||
$getProvinceID = Contracts::where('id', $request->project_id)->first();
|
||||
$roadProjects = RoadTollhouseManagement::with('latestHistory')
|
||||
->where('province_id', $getProvinceID->province_id)
|
||||
->get();
|
||||
} else {
|
||||
$roadProjects = RoadTollhouseManagement::with('latestHistory')->get();
|
||||
}
|
||||
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => $roadProjects,
|
||||
'can_submit' => 1
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function showTollhouseManagementData(Request $request)
|
||||
{
|
||||
$roadProject = RoadTollhouseManagement::find($request->id);
|
||||
$roadProjectHistories = $roadProject->projectHistories;
|
||||
|
||||
$roadProjectHistoriesFiles = [];
|
||||
$imagesIndex = 0;
|
||||
|
||||
foreach ($roadProjectHistories as $key => $roadProjectHistory) {
|
||||
foreach ($roadProjectHistory->files as $keyPath => $file) {
|
||||
$roadProjectHistoriesFiles[$imagesIndex] = asset('storage' . substr($file->path, 6));
|
||||
$imagesIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
$cities = [];
|
||||
$citiesIndex = 0;
|
||||
|
||||
foreach ($roadProject->cities_id as $cityKey => $value) {
|
||||
$getCity = \App\Models\City::find($cityKey);
|
||||
|
||||
$cities[$citiesIndex] = [
|
||||
'id' => $getCity->id,
|
||||
'name' => $getCity->name_fa,
|
||||
'value' => $value
|
||||
];
|
||||
|
||||
$citiesIndex++;
|
||||
}
|
||||
|
||||
$roadProjectArray = [
|
||||
'id' => $roadProject->id,
|
||||
'province' => [
|
||||
'id' => ($roadProject->province) ? $roadProject->province->id : null,
|
||||
'name' => ($roadProject->province) ? $roadProject->province->name_fa : '-',
|
||||
'lat_lng' => [
|
||||
$roadProject->province->center_lat,
|
||||
$roadProject->province->center_long
|
||||
]
|
||||
],
|
||||
'cities' => $cities,
|
||||
'axis_name' => ($roadProject->axis_name) ? $roadProject->axis_name : '-',
|
||||
'axis_type' => ($roadProject->axis_type) ? : 0,
|
||||
'project_name' => ($roadProject->project_name) ? $roadProject->project_name : '-',
|
||||
'contractor_name' => ($roadProject->contractor_name) ? $roadProject->contractor_name : '-',
|
||||
'consultant_name' => ($roadProject->consultant_name) ? $roadProject->consultant_name : '-',
|
||||
'contract_date' => ($roadProject->contract_date) ? $roadProject->contract_date : '-',
|
||||
'contract_credit' => ($roadProject->contract_credit) ? $roadProject->contract_credit : '-',
|
||||
'submited_at' => ($roadProject->submited_at) ?
|
||||
verta($roadProject->submited_at)->format('Y/n/j - H:i') : '-',
|
||||
'last_updated_at' => ($roadProject->last_updated_at) ?
|
||||
verta($roadProject->last_updated_at)->format('Y/n/j - H:i') : '-',
|
||||
'start_latlng' => $roadProject->start_latlng,
|
||||
'end_latlng' => $roadProject->end_latlng,
|
||||
'project_distance' => $roadProject->project_distance,
|
||||
'project_distance_update' => $roadProject->project_distance_update,
|
||||
'physical_progress' => $roadProject->physical_progress,
|
||||
// 'credit_progress' => ((($roadProject->contract_credit - $roadProject->contractor_credit)
|
||||
// / $roadProject->contract_credit) * 100),
|
||||
'images' => $roadProjectHistoriesFiles,
|
||||
'project_status' => $roadProject->project_status,
|
||||
'project_description' => $roadProject->project_description,
|
||||
'rate' => ($roadProject->rate)? $roadProject->rate:null,
|
||||
'rate_desc' => ($roadProject->rate_desc)? $roadProject->rate_desc:null
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'status' => 'succeed',
|
||||
'message' => '',
|
||||
'data' => [
|
||||
$roadProjectArray
|
||||
]
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
178
app/Http/Controllers/Api/ForgotPasswordController.php
Normal file
178
app/Http/Controllers/Api/ForgotPasswordController.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\PasswordReset;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use SoapClient;
|
||||
use App\Facades\Sms\Sms;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('throttle:3,1');
|
||||
}
|
||||
|
||||
/*
|
||||
* Send Reset Code to Mobile methods
|
||||
*/
|
||||
public function sendResetCodeMobile(Request $request)
|
||||
{
|
||||
$user = User::where('username', $request->username)->first();
|
||||
if ( !$user ) {
|
||||
return response()->json(['message' => 'کاربری با این نام کاربری وجود ندارد.'], 402);
|
||||
}
|
||||
|
||||
if (PasswordReset::where('username', $request->username)->where('expired_at' ,'>=', Carbon::now())->first()) {
|
||||
return response()->json(['message' => 'دو دقیقه دیگر امتحان کنید.'], 402);
|
||||
}
|
||||
|
||||
$create = PasswordReset::create([
|
||||
'username' => $request->username,
|
||||
'token' => Str::random(32),
|
||||
'code' => mt_rand(100000, 999999), //TODO: replace -> mt_rand(100000, 999999)
|
||||
'code_status' => 0,
|
||||
'expired_at' => Carbon::now()->addMinutes(2)
|
||||
]);
|
||||
|
||||
/// Send SMS
|
||||
$msg = 'کد اعتبار سنجی فراموشی رمز عبور: ' . $create->code . "\n سامانه جامع راهداری";
|
||||
Sms::sendSms($user->mobile, $msg);
|
||||
|
||||
// $this->sms_sender($this->userMobile($request->username), $msg);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'token' => $create->token,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function userMobile($username)
|
||||
{
|
||||
$user = User::where('username', $username)->first();
|
||||
return $user->mobile;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get And Validate Code
|
||||
*/
|
||||
|
||||
public function getCodeMobile($token, Request $request)
|
||||
{
|
||||
$findWithToken = PasswordReset::where('token', $token)->get();
|
||||
|
||||
foreach ($findWithToken as $item) {
|
||||
$validCode = $item->code;
|
||||
}
|
||||
|
||||
if ($request->code == $validCode) {
|
||||
PasswordReset::where('token', $token)
|
||||
->where('expired_at', '>=' ,Carbon::now())
|
||||
->update(['code_status' => 1]);
|
||||
return response()->json([
|
||||
'message' => 'کد وارد شده درست میباشد',
|
||||
'token' => $token
|
||||
]);
|
||||
}
|
||||
return response()->json([
|
||||
'message' => 'کد اشتباه میباشد.',
|
||||
'token' => $token
|
||||
], 422);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Change Password Methods
|
||||
*
|
||||
*/
|
||||
|
||||
public function changePassword(Request $request, $token)
|
||||
{
|
||||
$this->validateCode($token);
|
||||
|
||||
$request->validate($this->rules());
|
||||
|
||||
$response = $this->resetPassword($this->getUser($token), $request->password);
|
||||
|
||||
return $response
|
||||
? $this->sendResetResponse($request, $response)
|
||||
: $this->sendResetFailedResponse($request, $response);
|
||||
}
|
||||
|
||||
protected function resetPassword($userID, $password)
|
||||
{
|
||||
$user = User::find($userID);
|
||||
$user->password = Hash::make($password);
|
||||
return $user->save();
|
||||
}
|
||||
|
||||
protected function rules()
|
||||
{
|
||||
return [
|
||||
'password' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
protected function getUser($token)
|
||||
{
|
||||
$getDataFromToken = PasswordReset::where('token', $token)->first();
|
||||
$user = User::where('username', $getDataFromToken->username)->first();
|
||||
return $user->id;
|
||||
}
|
||||
|
||||
protected function validateCode($token)
|
||||
{
|
||||
if (PasswordReset::where('token', $token)->where('code_status', 0)->first()) {
|
||||
return response()->json(['message' => 'کد را وارد نکردید'], 402);
|
||||
} else {
|
||||
return PasswordReset::where('token', $token)
|
||||
->where('code_status', 1)
|
||||
->first();
|
||||
}
|
||||
}
|
||||
|
||||
protected function sendResetResponse(Request $request, $response)
|
||||
{
|
||||
return response()->json([
|
||||
'success' => $response,
|
||||
'message' => 'پسورد با موفقیت تغییر یافت.'
|
||||
], 200);
|
||||
}
|
||||
|
||||
protected function sendResetFailedResponse(Request $request, $response)
|
||||
{
|
||||
return response()->json([
|
||||
'error' => $response
|
||||
]);
|
||||
}
|
||||
|
||||
// function sms_sender($mobile, $msg)
|
||||
// {
|
||||
// $client=new SoapClient("http://sms1000.ir/webservice/smspro.asmx?WSDL");
|
||||
// $result=$client->doSendSMS(
|
||||
// array(
|
||||
// 'uUsername' => 'rmto',
|
||||
// 'uPassword' => 'Rahdari89',
|
||||
// 'uNumber' => '1000141',
|
||||
// 'uCellphones' => $mobile,
|
||||
// 'uMessage' => $msg,
|
||||
// 'uFarsi' => true,
|
||||
// 'uTopic' => false,
|
||||
// 'uFlash' => false
|
||||
// )
|
||||
// );
|
||||
|
||||
// //print_r($result);
|
||||
// $x = $result->doSendSMSResult;
|
||||
// return $x;
|
||||
// }
|
||||
}
|
||||
113
app/Http/Controllers/Api/Front/UserController.php
Normal file
113
app/Http/Controllers/Api/Front/UserController.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Front;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\City;
|
||||
use App\Models\Province;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
// public function profile() {
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => User::where('id', Auth::user()->id)->with(['roles', 'permissions'])->get()
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// public function edit(Request $request) {
|
||||
// $user = User::find(auth()->user()->id);
|
||||
|
||||
// $validData = $request->validate([
|
||||
// 'name' => ['string'],
|
||||
// 'first_name' => ['string'],
|
||||
// 'last_name' => 'string',
|
||||
// 'position' => 'string',
|
||||
// 'mobile' => 'digits:11|regex:/^09[0-9]{9}$/i',
|
||||
// 'degree' => 'string',
|
||||
// ]);
|
||||
|
||||
// if ($request->has('username')) {
|
||||
// $request->validate([
|
||||
// 'username' => 'unique:users'
|
||||
// ]);
|
||||
// $validData['username'] = $request->username;
|
||||
// }
|
||||
|
||||
|
||||
// // Upload user avatar [For create user by Super admin is not required]
|
||||
// if ($request->has('avatar')) {
|
||||
// $file = $request->file('avatar');
|
||||
// $destinationPath = 'storage/avatar/' . now()->year . '/' . now()->month . '/';
|
||||
// // return $destinationPath;
|
||||
// $filename = $user->username . '-updated.' . $file->getClientOriginalExtension();
|
||||
// $file->move(public_path($destinationPath), $filename);
|
||||
// $user->update(['avatar' => $destinationPath . $filename]);
|
||||
// }
|
||||
|
||||
// if( $request->has('password')) {
|
||||
// $request->validate([
|
||||
// 'password' => ['string', 'min:6']
|
||||
// ]);
|
||||
|
||||
// $validData['password'] = Hash::make($request->password);
|
||||
// }
|
||||
|
||||
// $user->update($validData);
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'user is updated successfuly.',
|
||||
// 'data' => $user
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// public function storeInformation(Request $request, $id) {
|
||||
// $user = User::find($id);
|
||||
|
||||
// $validData = $request->validate([
|
||||
// 'username' => 'string|unique:users',
|
||||
// 'password' => 'min:3',
|
||||
// 'mobile' => 'digits:11|regex:/^09[0-9]{9}$/i',
|
||||
// ]);
|
||||
|
||||
|
||||
|
||||
// $user->first_name = $request->first_name;
|
||||
// $user->last_name = $request->last_name;
|
||||
// $user->position = $request->position;
|
||||
// $user->mobile = $request->mobile;
|
||||
// $user->password = Hash::make($request->password);
|
||||
// $user->confirmed = 1;
|
||||
// $user->save();
|
||||
|
||||
// // Upload user avatar [For create user by Super admin is not required]
|
||||
// if ($request->has('avatar')) {
|
||||
// $file = $request->file('avatar');
|
||||
// $destinationPath = 'storage/avatar/' . now()->year . '/' . now()->month . '/';
|
||||
// $filename = $user->username . '-updated.' . $file->getClientOriginalExtension();
|
||||
// $file->move(public_path($destinationPath), $filename);
|
||||
// $user->photo = $destinationPath . $filename;
|
||||
// $user->save();
|
||||
// }
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => $user,
|
||||
// ]);
|
||||
// }
|
||||
|
||||
|
||||
// public function getMyData()
|
||||
// {
|
||||
// $user = User::find(Auth::user()->id);
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => $user
|
||||
// ]);
|
||||
// }
|
||||
}
|
||||
84
app/Http/Controllers/Api/PermissionsController.php
Normal file
84
app/Http/Controllers/Api/PermissionsController.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Spatie\Permission\Guard;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class PermissionsController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$permissions = Permission::getPermissions();
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $permissions
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'guard_name' => [
|
||||
'web', 'auth', 'cors:api'
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validData = $request->validate([
|
||||
'name' => 'required',
|
||||
'guard_name' => 'required'
|
||||
]);
|
||||
|
||||
$permission = Permission::create([
|
||||
'name' => $request->name,
|
||||
'guard_name' => $request->guard_name,
|
||||
]);
|
||||
|
||||
return $permission;
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$perm = Permission::findById($id);
|
||||
return response()->json([
|
||||
'data' => $perm
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$perm = Permission::findById($id);
|
||||
|
||||
$validData = $request->validate([
|
||||
'name' => 'required',
|
||||
]);
|
||||
|
||||
$perm->update($validData);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $perm
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete(Request $request, $id)
|
||||
{
|
||||
$permission = Permission::find($id);
|
||||
$permission->delete();
|
||||
// Artisan::call('optimize:clear');
|
||||
return response()->json([
|
||||
'message' => 'permission has been deleted.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
101
app/Http/Controllers/Api/RandDVoting/AdminVoterController.php
Normal file
101
app/Http/Controllers/Api/RandDVoting/AdminVoterController.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\RandDVoting;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\RandDVoting;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\NewRandD;
|
||||
use App\Models\RandDVotingPaperAnswer;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\User;
|
||||
|
||||
class AdminVoterController extends Controller
|
||||
{
|
||||
public function startVoting($id)
|
||||
{
|
||||
if (auth()->user()) {
|
||||
auth()->user()->addActivityComplete(1063);
|
||||
}
|
||||
if (RandDVoting::where('project_id', $id)->where('status', '2')->first()) {
|
||||
return response()->json([
|
||||
'status' => 'failed',
|
||||
'message' => 'this voting was starting'
|
||||
]);
|
||||
}
|
||||
|
||||
$create = RandDVoting::create([
|
||||
'project_id' => $id,
|
||||
'description' => null,
|
||||
'status' => '2',
|
||||
'user_id' => Auth::user()->id
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $create,
|
||||
'url' => 'https://rms.rmto.ir/randd/voting/' . $create->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function endVoting($id)
|
||||
{
|
||||
if (auth()->user()) {
|
||||
auth()->user()->addActivityComplete(1064);
|
||||
}
|
||||
if (RandDVoting::where('project_id' ,$id)->where('status', '!=' , '2')->first()) {
|
||||
return response()->json([
|
||||
'status' => 'failed',
|
||||
'message' => 'you cant access this route!'
|
||||
]);
|
||||
}
|
||||
|
||||
$vote = RandDVoting::where('project_id' ,$id)
|
||||
->where('status', '2')
|
||||
->update([
|
||||
'status' => '4'
|
||||
]);
|
||||
NewRandD::find($id)
|
||||
->update([
|
||||
'project_status' => '2'
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success'
|
||||
]);
|
||||
}
|
||||
|
||||
public function showResult($id)
|
||||
{
|
||||
$vote = RandDVoting::find($id);
|
||||
|
||||
// if vote has not finished, result is 403 forbidden
|
||||
if ($vote->status != '4') {
|
||||
abort(403);
|
||||
}
|
||||
/// get users data
|
||||
$participants = [];
|
||||
foreach ($vote->answers as $answer) {
|
||||
$participants[] = $answer->user;
|
||||
}
|
||||
|
||||
// General voting information
|
||||
$data = [
|
||||
'project_name' => $vote->project->title,
|
||||
'description' => $vote->description,
|
||||
'status' => $vote->status,
|
||||
'participants_number' => count($vote->answers),
|
||||
'participants' => $participants,
|
||||
'voterـstarter' => $vote->user->first_name . ' ' . $vote->user->last_name,
|
||||
'average' => $vote->answers->sum('score') / count($vote->answers),
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
}
|
||||
173
app/Http/Controllers/Api/RandDVoting/VoterController.php
Normal file
173
app/Http/Controllers/Api/RandDVoting/VoterController.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\RandDVoting;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\RandDVoting;
|
||||
use App\Models\RandDVotingPaperAnswer;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use App\Models\NewRandD;
|
||||
|
||||
class VoterController extends Controller
|
||||
{
|
||||
public function storeVoting(Request $request, $id)
|
||||
{
|
||||
if (auth()->user()) {
|
||||
auth()->user()->addActivityComplete(1066);
|
||||
}
|
||||
if (RandDVoting::where('id', $id)->where('status', '4')->first()) {
|
||||
return response()->json([
|
||||
'endVoting' => true,
|
||||
'message' => 'زمان امتیازدهی این پروژه به پایان رسیده است.',
|
||||
]);
|
||||
} elseif (RandDVoting::where('id', $id)->where('status', '2')->first()) {
|
||||
$all = $request->all();
|
||||
$questions = json_decode($request->questions);
|
||||
foreach ($questions as $value) {
|
||||
$new = new RandDVotingPaperAnswer();
|
||||
$new->vote_id = $id;
|
||||
$new->score = $value->score;
|
||||
$new->score_type = $value->type;
|
||||
$new->description = $all['desc'];
|
||||
$new->q_id = $value->q_id;
|
||||
$new->q_fa = $value->q_fa;
|
||||
$new->user_id = Auth::user()->id;
|
||||
$new->fullname = $all['fullname'];
|
||||
$new->save();
|
||||
}
|
||||
return response()->json([
|
||||
'endVoting' => false,
|
||||
'message' => 'success'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function showResult($id)
|
||||
{
|
||||
$project = NewRandD::find($id);
|
||||
if($project->project_status == 3)
|
||||
{
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => [
|
||||
'id' => $project->id,
|
||||
'project_status' => $project->project_status,
|
||||
'project_name' => $project->title,
|
||||
'reject_description' => $project->reject_description,
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
$vote = RandDVoting::where('project_id', $id)->first();
|
||||
// if vote has not finished, result is 403 forbidden
|
||||
if ($vote->status != '4') {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// get users data
|
||||
$participants = DB::table('randd_voting_paper_answers')
|
||||
->where('vote_id', $vote->id)
|
||||
->join('users', 'randd_voting_paper_answers.user_id', 'users.id')
|
||||
->groupBy('user_id')
|
||||
->get();
|
||||
|
||||
$getScores = RandDVotingPaperAnswer::where('score_type', 1)
|
||||
->where('vote_id', $vote->id)
|
||||
->get();
|
||||
$countScoresNumber = count($getScores);
|
||||
|
||||
$average = round(RandDVotingPaperAnswer::where('vote_id', $vote->id)
|
||||
->where('score_type', 1)
|
||||
->sum('score') / count($participants),1);
|
||||
|
||||
$typePercentsNumber = RandDVotingPaperAnswer::where('vote_id', $vote->id)
|
||||
->where('score_type', 2)
|
||||
->count();
|
||||
|
||||
$typeOneScore = RandDVotingPaperAnswer::where('vote_id', $vote->id)
|
||||
->where('score_type', 2)
|
||||
->where('score', '1')
|
||||
->count();
|
||||
|
||||
$typeTwoScore = RandDVotingPaperAnswer::where('vote_id', $vote->id)
|
||||
->where('score_type', 2)
|
||||
->where('score', '2')
|
||||
->count();
|
||||
|
||||
$typeThreeScore = RandDVotingPaperAnswer::where('vote_id', $vote->id)
|
||||
->where('score_type', 2)
|
||||
->where('score', '3')
|
||||
->count();
|
||||
|
||||
|
||||
|
||||
// General voting information
|
||||
$data = [
|
||||
'id' => $vote->id,
|
||||
'project_type' => $vote->project->status,
|
||||
'project_name' => $vote->project->title,
|
||||
'project_status' => $vote->project->project_status,
|
||||
'description' => $vote->description,
|
||||
'status' => $vote->status,
|
||||
'participants_number' => count($participants),
|
||||
'participants' => $participants,
|
||||
'voterـstarter' => $vote->user->first_name . ' ' . $vote->user->last_name,
|
||||
'average' => $average,
|
||||
'typeOne' => $typeOneScore / $typePercentsNumber * 100,
|
||||
'typeTwo' => $typeTwoScore / $typePercentsNumber * 100,
|
||||
'typeThree' => $typeThreeScore / $typePercentsNumber * 100,
|
||||
];
|
||||
|
||||
$data['votingUsersResult'] = false;
|
||||
if (Auth::user()->can('member-RandD')) {
|
||||
$data['votingUsersResult'] = true;
|
||||
} else {
|
||||
if (Auth::user()->can('staff-RandD')) {
|
||||
$data['votingUsersResult'] = true;
|
||||
} else {
|
||||
// permission for ostani users
|
||||
if (Auth::user()->province_id) {
|
||||
$data['votingUsersResult'] = false;
|
||||
} else {
|
||||
// permission for setadi users
|
||||
$data['votingUsersResult'] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public function showUserPaper(Request $request)
|
||||
{
|
||||
$r = RandDVotingPaperAnswer::where('vote_id', $request->vote)
|
||||
->where('user_id', $request->user)
|
||||
->get();
|
||||
$ar = [];
|
||||
foreach ($r as $item) {
|
||||
$ar['questions'][] = [
|
||||
'question_id' => $item->q_id,
|
||||
'question_fa' => $item->q_fa,
|
||||
'score' => $item->score,
|
||||
'score_type' => $item->score_type,
|
||||
];
|
||||
$ar['sum_score'] = RandDVotingPaperAnswer::where('vote_id', $request->vote)
|
||||
->where('user_id', $request->user)
|
||||
->where('score_type', 1)
|
||||
->sum('score');
|
||||
$ar['fullname'] = $item->fullname;
|
||||
$ar['description'] = $item->description;
|
||||
$ar['created_at'] = Verta::instance($item->created_at);
|
||||
}
|
||||
return $ar;
|
||||
}
|
||||
}
|
||||
479
app/Http/Controllers/Api/UserController.php
Normal file
479
app/Http/Controllers/Api/UserController.php
Normal file
@@ -0,0 +1,479 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Api\UserResource;
|
||||
use App\Models\City;
|
||||
use App\Models\Province;
|
||||
use App\Models\User;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\EdarateOstani;
|
||||
use Cache;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\HttpErorrsList;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
// public function index(Request $request)
|
||||
// {
|
||||
// if (auth()->user()) {
|
||||
// auth()->user()->addActivityComplete(1038);
|
||||
// }
|
||||
|
||||
// $province = $request->province ?? null;
|
||||
// $city = $request->city ?? null;
|
||||
// $province_office = $request->province_office ?? null;
|
||||
|
||||
// if (Auth::user()->checkUserHasPermission('full-user-management')) {
|
||||
// $users = User::when($province, function ($query, $province) {
|
||||
// return $query->where('province_id', $province);
|
||||
// })
|
||||
// ->when($city, function ($query, $city) {
|
||||
// return $query->where('city_id', $city);
|
||||
// })
|
||||
// ->when($province_office, function ($query, $province_office) {
|
||||
// if ($province_office == -1) {
|
||||
// return $query->where('edarate_ostani_id', null)->whereNotNull('edarate_shahri_id');
|
||||
// } else {
|
||||
// return $query->where('edarate_ostani_id', $province_office);
|
||||
// }
|
||||
// })
|
||||
// ->with(['roles' => function ($query) {
|
||||
// $query->where('for_report', 1);
|
||||
// }])
|
||||
// ->get();
|
||||
// } elseif (Auth::user()->checkUserHasPermission('limited-user-management')) {
|
||||
// $users = User::when($province, function ($query, $province) {
|
||||
// return $query->where('province_id', $province);
|
||||
// })
|
||||
// ->where('province_id',Auth::user()->province_id)
|
||||
// ->when($city, function ($query, $city) {
|
||||
// return $query->where('city_id', $city);
|
||||
// })
|
||||
// ->when($province_office, function ($query, $province_office) {
|
||||
// if ($province_office == -1) {
|
||||
// return $query->where('edarate_ostani_id', null)->whereNotNull('edarate_shahri_id');
|
||||
// } else {
|
||||
// return $query->where('edarate_ostani_id', $province_office);
|
||||
// }
|
||||
// })
|
||||
// ->with(['roles' => function ($query) {
|
||||
// $query->where('for_report', 1);
|
||||
// }])
|
||||
// ->get();
|
||||
// } else {
|
||||
// return response()->json([
|
||||
// 'message' => 'Forbidden'
|
||||
// ], 403);
|
||||
// }
|
||||
|
||||
// return response()->json([
|
||||
// 'status' => '200',
|
||||
// 'message' => 'success',
|
||||
// 'data' => $users,
|
||||
// ], 200);
|
||||
// }
|
||||
|
||||
// public function store(Request $request)
|
||||
// {
|
||||
// $validData = $request->validate([
|
||||
// 'username' => 'string|unique:users',
|
||||
// 'national_code' => 'required|unique:users,national_code',
|
||||
// 'mobile' => 'digits:11|regex:/^09[0-9]{9}$/i',
|
||||
// ]);
|
||||
|
||||
// $createUser = new User();
|
||||
|
||||
// $createUser->province_id = $request->province_id == 0 ? null : $request->province_id;
|
||||
// $createUser->province_fa = ($request->province_id == 0) ? 'اداره کل' : Province::find($request->province_id)->name_fa;
|
||||
|
||||
// $createUser->city_id = $request->city_id == 0 ? null : $request->city_id;
|
||||
// $createUser->city_fa = ($request->city_id == 0) ? null : City::find($request->city_id)->name_fa ;
|
||||
|
||||
// if ($request->edarate_ostani_id != 'null') {
|
||||
// $temp = EdarateOstani::find($request->edarate_ostani_id)->name_fa;
|
||||
// $createUser->edarate_ostani_id = $request->edarate_ostani_id;
|
||||
// $createUser->edarate_ostani_name = $temp;
|
||||
// if ($request->province_id == 0) {
|
||||
// $createUser->name = $temp .' '. $createUser->province_fa;
|
||||
// } else {
|
||||
// $createUser->name = $temp .' استان '. $createUser->province_fa;
|
||||
// }
|
||||
// } else {
|
||||
// $temp = EdarateShahri::find($request->edarate_shahri_id)->name_fa;
|
||||
// $createUser->edarate_shahri_id = $request->edarate_shahri_id;
|
||||
// $createUser->edarate_shahri_name = $temp;
|
||||
|
||||
// if ($request->province_id == 0) {
|
||||
// $createUser->name = $temp .' '. $createUser->province_fa;
|
||||
// } else {
|
||||
// $createUser->name = $temp .' استان '. $createUser->province_fa;
|
||||
// }
|
||||
// }
|
||||
|
||||
// $createUser->username = $request->username;
|
||||
// $createUser->password = Hash::make($request->password);
|
||||
// $createUser->first_name = $request->first_name;
|
||||
// $createUser->last_name = $request->last_name;
|
||||
// $createUser->position = $request->position;
|
||||
// $createUser->mobile = $request->mobile;
|
||||
// $createUser->degree = $request->degree;
|
||||
// $createUser->major = $request->major;
|
||||
// $createUser->national_code = $request->national_code;
|
||||
|
||||
// $createUser->save();
|
||||
|
||||
// if (! $request->permissions == null) {
|
||||
// $createUser->syncPermissions(explode(",", $request->permissions));
|
||||
// }
|
||||
|
||||
// $roles = $request->only('roles');
|
||||
// if (! $roles == null) {
|
||||
// $createUser->syncRoles($roles);
|
||||
// }
|
||||
|
||||
// if ($request->has('avatar')) {
|
||||
// $destinationPath = 'avatar/' . $request->username;
|
||||
// $filename = time() .".". $request->file('avatar')->getClientOriginalExtension();
|
||||
// $request->file('avatar')->storeAs($destinationPath, $filename, 'public');
|
||||
// $createUser->update(['avatar' => 'storage/'.$destinationPath ."/". $filename]);
|
||||
// }
|
||||
|
||||
// if (auth()->user()) {
|
||||
// auth()->user()->addActivityComplete(1039, $createUser);
|
||||
// }
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => $createUser
|
||||
// ], 200);
|
||||
// }
|
||||
|
||||
// public function simpleAddUser(Request $request)
|
||||
// {
|
||||
// $request->validate([
|
||||
// 'province_id' => 'required',
|
||||
// 'username' => 'required|unique:users,username',
|
||||
// 'national_code' => 'required|unique:users,national_code',
|
||||
// 'password' => 'required'
|
||||
// ]);
|
||||
|
||||
// $user = new User();
|
||||
// $user->username = $request->username;
|
||||
|
||||
// $user->province_id = $request->province_id == 0 ? null : $request->province_id;
|
||||
// $user->province_fa = ($request->province_id == 0) ? 'اداره کل' : Province::find($request->province_id)->name_fa;
|
||||
|
||||
// $user->city_id = $request->city_id == 0 ? null : $request->city_id;
|
||||
// $user->city_fa = ($request->city_id == 0) ? null : City::find($request->city_id)->name_fa ;
|
||||
|
||||
// if ($request->edarate_ostani_id != 'null') {
|
||||
// $temp = EdarateOstani::find($request->edarate_ostani_id)->name_fa;
|
||||
// $user->edarate_ostani_id = $request->edarate_ostani_id;
|
||||
// $user->edarate_ostani_name = $temp;
|
||||
// if ($request->province_id == 0) {
|
||||
// $user->name = $temp .' '. $user->province_fa;
|
||||
// } else {
|
||||
// $user->name = $temp .' استان '. $user->province_fa;
|
||||
// }
|
||||
// } else {
|
||||
// $temp = EdarateShahri::find($request->edarate_shahri_id)->name_fa;
|
||||
// $user->edarate_shahri_id = $request->edarate_shahri_id;
|
||||
// $user->edarate_shahri_name = $temp;
|
||||
|
||||
// if ($request->province_id == 0) {
|
||||
// $user->name = $temp .' '. $user->province_fa;
|
||||
// } else {
|
||||
// $user->name = $temp .' استان '. $user->province_fa;
|
||||
// }
|
||||
// }
|
||||
|
||||
// $user->password = Hash::make($request->password);
|
||||
// $user->national_code = $request->national_code;
|
||||
// $user->save();
|
||||
|
||||
// if (auth()->user()) {
|
||||
// auth()->user()->addActivityComplete(1039, $user);
|
||||
// }
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => $user
|
||||
// ], 200);
|
||||
// }
|
||||
|
||||
// public function show($id)
|
||||
// {
|
||||
// $user = User::where('id', $id)->with(['roles', 'permissions'])->get();
|
||||
// return response()->json([
|
||||
// 'status' => '200',
|
||||
// 'message' => 'success',
|
||||
// 'data' => $user
|
||||
// ], 200);
|
||||
// }
|
||||
|
||||
// public function update(Request $request, User $user)
|
||||
// {
|
||||
// $request->validate([
|
||||
// 'national_code' => 'required|unique:users,national_code,'.$user->id,
|
||||
// ]);
|
||||
|
||||
// if ($request->has('avatar')) {
|
||||
// Storage::delete('public/' . $user->avatar);
|
||||
// $destinationPath = 'avatar/' . $request->username;
|
||||
// $filename = time() .".". $request->file('avatar')->getClientOriginalExtension();
|
||||
// $request->file('avatar')->storeAs($destinationPath, $filename, 'public');
|
||||
// $user->update(['avatar' => 'storage/'.$destinationPath ."/". $filename]);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// $user->province_id = $request->province_id == 0 ? null : $request->province_id;
|
||||
// $user->province_fa = ($request->province_id == 0) ? 'اداره کل' : Province::find($request->province_id)->name_fa;
|
||||
|
||||
// $user->city_id = $request->city_id == 0 ? null : $request->city_id;
|
||||
// $user->city_fa = ($request->city_id == 0) ? null : City::find($request->city_id)->name_fa ;
|
||||
|
||||
// if ($request->edarate_ostani_id != 'null') {
|
||||
// $temp = EdarateOstani::find($request->edarate_ostani_id)->name_fa;
|
||||
// $user->edarate_ostani_id = $request->edarate_ostani_id;
|
||||
// $user->edarate_ostani_name = $temp;
|
||||
|
||||
// $user->edarate_shahri_id = null;
|
||||
// $user->edarate_shahri_name = null;
|
||||
|
||||
// if ($request->province_id == 0) {
|
||||
// $user->name = $temp .' '. $user->province_fa;
|
||||
// } else {
|
||||
// $user->name = $temp .' استان '. $user->province_fa;
|
||||
// }
|
||||
// } else {
|
||||
// $temp = EdarateShahri::find($request->edarate_shahri_id)->name_fa;
|
||||
// $user->edarate_shahri_id = $request->edarate_shahri_id;
|
||||
// $user->edarate_shahri_name = $temp;
|
||||
// $user->edarate_ostani_id = null;
|
||||
// $user->edarate_ostani_name = null;
|
||||
// if ($request->province_id == 0) {
|
||||
// $user->name = $temp .' '. $user->province_fa;
|
||||
// } else {
|
||||
// $user->name = $temp .' استان '. $user->province_fa;
|
||||
// }
|
||||
// }
|
||||
|
||||
// $user->first_name = $request->first_name;
|
||||
// $user->last_name = $request->last_name;
|
||||
// $user->position = $request->position;
|
||||
// $user->mobile = $request->mobile;
|
||||
// $user->degree = $request->degree;
|
||||
// $user->major = $request->major;
|
||||
// $user->national_code = $request->national_code;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// if (!is_null($request->password)) {
|
||||
// $request->validate([
|
||||
// 'password' => ['string']
|
||||
// ]);
|
||||
// $user->password = Hash::make($request->password);
|
||||
// }
|
||||
|
||||
// if (! $request->permissions == null) {
|
||||
// $user->syncPermissions(explode(",", $request->permissions));
|
||||
// }
|
||||
|
||||
// $roles = $request->only('roles');
|
||||
// if (! $roles == null) {
|
||||
// $user->syncRoles($roles);
|
||||
// }
|
||||
|
||||
// $user->save();
|
||||
|
||||
// if (auth()->user()) {
|
||||
// auth()->user()->addActivityComplete(1040, $user);
|
||||
// }
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => $user
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// public function destroy(User $user)
|
||||
// {
|
||||
// if (auth()->user()) {
|
||||
// auth()->user()->addActivityComplete(1041, $user);
|
||||
// }
|
||||
|
||||
// $user->delete();
|
||||
// return response()->json([
|
||||
// 'status' => 'success',
|
||||
// 'message' => 'user has been deleted.'
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// For user
|
||||
|
||||
// public function getAllPermissions()
|
||||
// {
|
||||
// $permissions = Permission::select('id', 'name', 'name_fa', 'description', 'type')
|
||||
// ->orderBy('type')
|
||||
// // ->where('id', '>', 9)
|
||||
// ->get();
|
||||
|
||||
// return response()->json([
|
||||
// 'Permissions' => $permissions,
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// public function userPermission($id)
|
||||
// {
|
||||
// $user = User::find($id);
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => $user->permissions,
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// public function assignPermission(Request $request, User $user)
|
||||
// {
|
||||
// if (auth()->user()) {
|
||||
// auth()->user()->addActivityComplete(1042);
|
||||
// }
|
||||
// $permissions = explode(",", $request->permissions);
|
||||
// if (! $permissions == null) {
|
||||
// $user->syncPermissions($permissions);
|
||||
// }
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'status',
|
||||
// 'data' => User::where('id', $user->id)->with(['permissions'])->get()
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// public function createRole(Request $request)
|
||||
// {
|
||||
// $request->validate([
|
||||
// 'role_name' => 'required|string',
|
||||
// 'permissions' => 'required'
|
||||
// ], [
|
||||
// 'permissions.required' => 'انتخاب دسترسیها الزامی است.',
|
||||
// 'role_name.required' => 'نام نقش الزامی است.'
|
||||
// ]);
|
||||
|
||||
// if (auth()->user()) {
|
||||
// auth()->user()->addActivityComplete(1043);
|
||||
// }
|
||||
|
||||
// $role = Role::create([
|
||||
// 'name' => time(),
|
||||
// 'name_fa' => $request->role_name,
|
||||
// 'description' => $request->description
|
||||
// ]);
|
||||
|
||||
// $permissions = $request->permissions;
|
||||
|
||||
// // $permissions = explode(",", $request->permissions);
|
||||
// $role->givePermissionTo($permissions);
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => $role
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// public function showAllRoles(Request $request)
|
||||
// {
|
||||
// $roles = Role::where('for_report', 0)->get();
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => $roles
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// public function showRole($id, Request $request)
|
||||
// {
|
||||
// $role = Role::where('id', $id)->with('permissions:id,name,name_fa,description')->first();
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => [
|
||||
// 'role' => Role::whereId($id)->first(),
|
||||
// 'permissions' => $role->permissions
|
||||
// ]
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// public function editRole(Request $request, $id)
|
||||
// {
|
||||
// $request->validate([
|
||||
// 'role_name' => 'required|string',
|
||||
// 'permissions' => 'required'
|
||||
// ], [
|
||||
// 'permissions.required' => 'انتخاب دسترسیها الزامی است.',
|
||||
// 'role_name.required' => 'نام نقش الزامی است.'
|
||||
// ]);
|
||||
|
||||
// if (auth()->user()) {
|
||||
// auth()->user()->addActivityComplete(1044);
|
||||
// }
|
||||
// $role = Role::find($id);
|
||||
|
||||
|
||||
// $updateRole = $role->update([
|
||||
// 'name_fa' => $request->role_name,
|
||||
// 'description' => $request->description
|
||||
// ]);
|
||||
|
||||
// $permissions = $request->permissions;
|
||||
// // $permissions = explode(",", $request->permissions);
|
||||
|
||||
// $role->syncPermissions($permissions);
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => $role
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// public function deleteRole(Request $request, $id)
|
||||
// {
|
||||
// if (auth()->user()) {
|
||||
// auth()->user()->addActivityComplete(1045);
|
||||
// }
|
||||
// $role = Role::find($id)->delete();
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => 1
|
||||
// ]);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get user permissions
|
||||
*/
|
||||
// public function getUserPermissions()
|
||||
// {
|
||||
// $userPermissions = Auth::user()->getUserPermissions();
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'success',
|
||||
// 'data' => $userPermissions
|
||||
// ]);
|
||||
// }
|
||||
|
||||
}
|
||||
43
app/Http/Controllers/Api/UserDataController.php
Normal file
43
app/Http/Controllers/Api/UserDataController.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Province;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class UserDataController extends Controller
|
||||
{
|
||||
|
||||
public function getUserProvince()
|
||||
{
|
||||
if (Auth::user()->hasRole('superadmin')|| Auth::user()->hasRole('management') || Auth::user()->hasRole('setadi')) {
|
||||
// $data = Province::orderBy('id','desc')->get();
|
||||
$data = Province::all();
|
||||
} else {
|
||||
$data = Province::where('id', Auth::user()->province_id)->get();
|
||||
}
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => [
|
||||
'province_id' => $data
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function getUserProvinceAfterPermission(Request $request)
|
||||
{
|
||||
if ($request->type == 'all') {
|
||||
$data = Province::all();
|
||||
} else {
|
||||
$data = Province::where('id', Auth::user()->province_id)->get();
|
||||
}
|
||||
return response()->json([
|
||||
'message' => 'success',
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user