add mission id to road item
This commit is contained in:
@@ -4,20 +4,25 @@ namespace App\Http\Controllers\V3\Dashboard\RoadItem;
|
||||
|
||||
use App\Exceptions\ProhibitedAction;
|
||||
use App\Exports\V3\RoadItemsProjects\OperatorCartableReport;
|
||||
use App\Facades\File\FileFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\RoadItem\Operator\StoreRequest;
|
||||
use App\Http\Requests\V3\RoadItem\Operator\UpdateRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\EdarateShahri;
|
||||
use App\Models\InfoItem;
|
||||
use App\Models\ObservedItem;
|
||||
use App\Models\RoadItemsProject;
|
||||
use App\Services\Cartables\RoadItem\OperatorService;
|
||||
use App\Services\Cartables\RoadItemTableService;
|
||||
use App\Services\NominatimService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Throwable;
|
||||
|
||||
class OperatorController extends Controller
|
||||
{
|
||||
@@ -40,12 +45,10 @@ class OperatorController extends Controller
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @throws \Throwable
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function store(Request $request, NominatimService $nominatimService): JsonResponse
|
||||
public function store(StoreRequest $request, NominatimService $nominatimService): JsonResponse
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$info_item = InfoItem::query()->where('item', $request->item_id)
|
||||
->where('sub_item', $request->sub_item_id)
|
||||
->firstOrFail();
|
||||
@@ -66,51 +69,63 @@ class OperatorController extends Controller
|
||||
$start_coordinates = explode(',', $request->start_point);
|
||||
$end_coordinates = $info_item->needs_end_point ? explode(',', $request->end_point) : null;
|
||||
|
||||
$attributes = [
|
||||
'start_lat' => $start_coordinates[0],
|
||||
'start_lng' => $start_coordinates[1],
|
||||
'end_lat' => $end_coordinates ? $end_coordinates[0] : null,
|
||||
'end_lng' => $end_coordinates ? $end_coordinates[1] : null,
|
||||
'item' => $info_item->item,
|
||||
'item_fa' => $info_item->item_str,
|
||||
'sub_item' => $info_item->sub_item,
|
||||
'sub_item_fa' => $info_item->sub_item_str,
|
||||
'sub_item_data' => $request->amount,
|
||||
'province_id' => $user->province_id,
|
||||
'province_fa' => $user->province_fa,
|
||||
'city_id' => $user->city_id,
|
||||
'city_fa' => $user->city_fa,
|
||||
'user_name' => $user->name,
|
||||
'start_way_id' => $nominatimService->get_way_id_from_nominatim($start_coordinates[0], $start_coordinates[1]),
|
||||
'end_way_id' => $end_coordinates ? $nominatimService->get_way_id_from_nominatim($end_coordinates[0], $end_coordinates[1]) : null,
|
||||
'unit_fa' => $info_item->sub_item_unit,
|
||||
'created_at_fa' => verta(\Carbon\Carbon::now())->format('Y-m-d H:i:s'),
|
||||
'info_id' => $info_item->id,
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'edarat_id' => $user->edarate_shahri_id,
|
||||
'edarat_type' => EdarateShahri::class,
|
||||
'edarat_name' => $user->edarate_shahri_name,
|
||||
'activity_date' => $request->activity_date,
|
||||
'activity_time' => $request->activity_time,
|
||||
];
|
||||
DB::transaction(function () use ($request, $nominatimService, $start_coordinates, $end_coordinates, $info_item) {
|
||||
$user = auth()->user();
|
||||
$road_item = RoadItemsProject::query()->create([
|
||||
'user_id' => $user->id,
|
||||
'mission_id' => $request->mission_id,
|
||||
'start_lat' => $start_coordinates[0],
|
||||
'start_lng' => $start_coordinates[1],
|
||||
'end_lat' => $end_coordinates ? $end_coordinates[0] : null,
|
||||
'end_lng' => $end_coordinates ? $end_coordinates[1] : null,
|
||||
'item' => $info_item->item,
|
||||
'item_fa' => $info_item->item_str,
|
||||
'sub_item' => $info_item->sub_item,
|
||||
'sub_item_fa' => $info_item->sub_item_str,
|
||||
'sub_item_data' => $request->amount,
|
||||
'province_id' => $user->province_id,
|
||||
'province_fa' => $user->province_fa,
|
||||
'city_id' => $user->city_id,
|
||||
'city_fa' => $user->city_fa,
|
||||
'user_name' => $user->name,
|
||||
'start_way_id' => $nominatimService->get_way_id_from_nominatim($start_coordinates[0], $start_coordinates[1]),
|
||||
'end_way_id' => $end_coordinates ? $nominatimService->get_way_id_from_nominatim($end_coordinates[0], $end_coordinates[1]) : null,
|
||||
'unit_fa' => $info_item->sub_item_unit,
|
||||
'created_at_fa' => verta(\Carbon\Carbon::now())->format('Y-m-d H:i:s'),
|
||||
'info_id' => $info_item->id,
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
'edarat_id' => $user->edarate_shahri_id,
|
||||
'edarat_type' => EdarateShahri::class,
|
||||
'edarat_name' => $user->edarate_shahri_name,
|
||||
'activity_date' => $request->activity_date,
|
||||
'activity_time' => $request->activity_time,
|
||||
'activity_date_time' => $request->activity_date." ".$request->activity_time,
|
||||
'is_new' => 1,
|
||||
]);
|
||||
|
||||
$after_image = ($request->has('after_image') && $info_item->needs_image) ?
|
||||
$request->file('after_image') :
|
||||
null;
|
||||
if ($request->has('after_image')) {
|
||||
$road_item->files()->create([
|
||||
'path' => FileFacade::save($request->file('after_image'),
|
||||
"/road_items_projects_new/{$road_item->id}/after")
|
||||
]);
|
||||
}
|
||||
if ($request->has('before_image')) {
|
||||
$road_item->files()->create([
|
||||
'path' => FileFacade::save($request->file('before_image'),
|
||||
"/road_items_projects_new/{$road_item->id}/before")
|
||||
]);
|
||||
}
|
||||
|
||||
$before_image = ($request->has('before_image') && $info_item->needs_image) ?
|
||||
$request->file('before_image') :
|
||||
null;
|
||||
throw_if(ObservedItem::query()->where('id', $request->observed_item_id)->whereNotNull('road_item_id')->exists(),
|
||||
new ProhibitedAction('اقدام مربوطه قبلا رسیدگی شده است.')
|
||||
);
|
||||
|
||||
$road_item = RoadItemsProject::store($user, $attributes, $before_image, $after_image, $request->observed_item_id);
|
||||
$road_item->rahdaran()->attach($request->rahdaran_id);
|
||||
$road_item->cmmsMachines()->attach($request->machines_id);
|
||||
|
||||
throw_if($road_item === -1, new ProhibitedAction('اقدام مربوطه قبلا رسیدگی شده است.'));
|
||||
|
||||
$road_item->rahdaran()->attach($request->rahdaran_id);
|
||||
$road_item->cmmsMachines()->attach($request->machines_id);
|
||||
|
||||
auth()->user()->addActivityComplete(1154);
|
||||
$user->addActivityComplete(1154);
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
@@ -126,7 +141,7 @@ class OperatorController extends Controller
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, RoadItemsProject $roadItemsProject): JsonResponse
|
||||
public function update(UpdateRequest $request, RoadItemsProject $roadItemsProject): JsonResponse
|
||||
{
|
||||
$info_item = InfoItem::query()->where('item', $roadItemsProject->item)
|
||||
->where('sub_item', $roadItemsProject->sub_item)
|
||||
@@ -147,45 +162,39 @@ class OperatorController extends Controller
|
||||
|
||||
if ($info_item->needs_image) {
|
||||
if ($request->has('after_image')) {
|
||||
|
||||
Storage::delete('public/'. $roadItemsProject->files[0]->path);
|
||||
|
||||
$after = $request->file('after_image')->store('road_items_projects_new/after', 'public');
|
||||
FileFacade::delete($roadItemsProject->files[0]->path, true);
|
||||
$roadItemsProject->files[0]->update([
|
||||
'path' => $after
|
||||
'path' => FileFacade::save($request->file('after_image'),
|
||||
"/road_items_projects_new/{$roadItemsProject->id}/after")
|
||||
]);
|
||||
// $roadItemsProject->files()->create(['path' => $after]);
|
||||
$urlAfter = "/var/www/rms/public/storage/{$after}";
|
||||
// \App\Helpers\Compress::resize($urlAfter);
|
||||
}
|
||||
if ($request->has('before_image')) {
|
||||
Storage::delete('public/'. $roadItemsProject->files[1]->path);
|
||||
|
||||
$before = $request->file('before_image')->store('/road_items_projects_new/before', 'public');
|
||||
FileFacade::delete($roadItemsProject->files[1]->path, true);
|
||||
$roadItemsProject->files[1]->update([
|
||||
'path' => $before
|
||||
'path' => FileFacade::save($request->file('before_image'),
|
||||
"/road_items_projects_new/{$roadItemsProject->id}/before")
|
||||
]);
|
||||
// $roadItemsProject->files()->create(['path' => $before]);
|
||||
$urlBefore = "/var/www/rms/public/storage/{$before}";
|
||||
// \App\Helpers\Compress::resize($urlBefore);
|
||||
}
|
||||
}
|
||||
|
||||
$roadItemsProject->update([
|
||||
'start_lat' => $start_coordinates[0],
|
||||
'start_lng' => $start_coordinates[1],
|
||||
'end_lat' => $end_coordinates ? $end_coordinates[0] : null,
|
||||
'end_lng' => $end_coordinates ? $end_coordinates[1] : null,
|
||||
'sub_item_data' => $request->amount,
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
]);
|
||||
DB::transaction(function () use ($roadItemsProject, $start_coordinates, $end_coordinates, $request) {
|
||||
$roadItemsProject->update([
|
||||
'mission_id' => $request->mission_id,
|
||||
'start_lat' => $start_coordinates[0],
|
||||
'start_lng' => $start_coordinates[1],
|
||||
'end_lat' => $end_coordinates ? $end_coordinates[0] : null,
|
||||
'end_lng' => $end_coordinates ? $end_coordinates[1] : null,
|
||||
'sub_item_data' => $request->amount,
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
]);
|
||||
|
||||
$roadItemsProject->rahdaran()->sync($request->rahdaran_id);
|
||||
$roadItemsProject->cmmsMachines()->sync($request->machines_id);
|
||||
$roadItemsProject->rahdaran()->sync($request->rahdaran_id);
|
||||
$roadItemsProject->cmmsMachines()->sync($request->machines_id);
|
||||
|
||||
|
||||
auth()->user()->addActivityComplete(1155);
|
||||
auth()->user()->addActivityComplete(1155);
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
@@ -195,14 +204,15 @@ class OperatorController extends Controller
|
||||
*/
|
||||
public function destroy(RoadItemsProject $roadItemsProject): JsonResponse
|
||||
{
|
||||
if ($roadItemsProject->files()->exists()) {
|
||||
Storage::delete('public/'. $roadItemsProject->files[0]->path);
|
||||
Storage::delete('public/'. $roadItemsProject->files[1]->path);
|
||||
$roadItemsProject->files()->delete();
|
||||
}
|
||||
auth()->user()->addActivityComplete(1151);
|
||||
DB::transaction(function () use ($roadItemsProject) {
|
||||
if ($roadItemsProject->files()->exists()) {
|
||||
FileFacade::deleteDirectory("/road_items_projects_new/{$roadItemsProject->id}");
|
||||
$roadItemsProject->files()->delete();
|
||||
}
|
||||
auth()->user()->addActivityComplete(1151);
|
||||
|
||||
$roadItemsProject->delete();
|
||||
$roadItemsProject->delete();
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
51
app/Http/Requests/V3/RoadItem/Operator/StoreRequest.php
Normal file
51
app/Http/Requests/V3/RoadItem/Operator/StoreRequest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\RoadItem\Operator;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'mission_id' => 'required|integer|exists:missions,id',
|
||||
'start_point' => 'required',
|
||||
'item_id' => 'required|integer',
|
||||
'sub_item_id' => 'required|integer',
|
||||
'amount' => 'required|numeric',
|
||||
'observed_item_id' => 'integer|exists:observed_items,id',
|
||||
'activity_date' => 'required|date_format:Y-m-d',
|
||||
'activity_time' => 'required|date_format:H:i',
|
||||
'before_image' => 'image|max:4096',
|
||||
'after_image' => 'image|max:4096',
|
||||
'machines_id' => 'required|array',
|
||||
'machines_id.*' => 'required|exists:cmms_machines,id',
|
||||
'rahdaran_id' => 'required|array',
|
||||
'rahdaran_id.*' => 'required|exists:rahdaran,id',
|
||||
];
|
||||
}
|
||||
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'activity_date' => 'تاریخ فعالیت',
|
||||
'activity_time' => 'ساعت فعالیت',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\RoadItem;
|
||||
namespace App\Http\Requests\V3\RoadItem\Operator;
|
||||
|
||||
use App\Models\InfoItem;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Symfony\Component\Finder\Exception\AccessDeniedException;
|
||||
|
||||
class UpdateRequest extends FormRequest
|
||||
{
|
||||
@@ -16,19 +13,25 @@ class UpdateRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return !($this->roadItemsProject->user_id != auth()->user()->id || $this->roadItemsProject->status != 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'mission_id' => 'required|integer|exists:missions,id',
|
||||
'start_point' => 'required',
|
||||
'item_id' => 'required|integer',
|
||||
'sub_item_id' => 'required|integer',
|
||||
'amount' => 'required|numeric',
|
||||
'observed_item_id' => 'integer|exists:observed_items,id',
|
||||
'activity_date' => 'required|date_format:Y-m-d',
|
||||
'activity_time' => 'required|date_format:H:i',
|
||||
'before_image' => 'image|max:4096',
|
||||
'after_image' => 'image|max:4096',
|
||||
'machines_id' => 'required|array',
|
||||
@@ -37,4 +40,12 @@ class UpdateRequest extends FormRequest
|
||||
'rahdaran_id.*' => 'required|exists:rahdaran,id',
|
||||
];
|
||||
}
|
||||
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'activity_date' => 'تاریخ فعالیت',
|
||||
'activity_time' => 'ساعت فعالیت',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\RoadItem;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class StoreRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'start_point' => 'required',
|
||||
'item_id' => 'required|integer',
|
||||
'sub_item_id' => 'required|integer',
|
||||
'amount' => 'required|numeric',
|
||||
'observed_item_id' => 'integer|exists:observed_items,id',
|
||||
'activity_date' => 'required|date_format:Y-m-d',
|
||||
'activity_time' => 'required|date_format:H:i',
|
||||
'before_image' => 'image|max:4096',
|
||||
'after_image' => 'image|max:4096',
|
||||
'machines_id' => 'required|array',
|
||||
'machines_id.*' => 'required|exists:cmms_machines,id',
|
||||
'rahdaran_id' => 'required|array',
|
||||
'rahdaran_id.*' => 'required|exists:rahdaran,id',
|
||||
];
|
||||
}
|
||||
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'activity_date' => 'تاریخ فعالیت',
|
||||
'activity_time' => 'ساعت فعالیت',
|
||||
];
|
||||
}
|
||||
|
||||
// public function after(): array
|
||||
// {
|
||||
// return [
|
||||
// function (Validator $validator) {
|
||||
// if ($this->has(['item_id', 'sub_item_id'])) {
|
||||
//
|
||||
// $info_item = InfoItem::query()
|
||||
// ->where('item', $this->item_id)
|
||||
// ->where('sub_item', $this->sub_item_id)
|
||||
// ->firstOrFail();
|
||||
//
|
||||
// if ($info_item->needs_end_point && !$this->filled('end_point')) {
|
||||
// $validator->errors()->add('end_point', __('validation.required'));
|
||||
// }
|
||||
//
|
||||
// if ($info_item->needs_image) {
|
||||
// if (!$this->hasFile('before_image')) {
|
||||
// $validator->errors()->add('before_image', __('validation.required'));
|
||||
// }
|
||||
// if (!$this->hasFile('after_image')) {
|
||||
// $validator->errors()->add('after_image', __('validation.required'));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ];
|
||||
// }
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\RoadItem;
|
||||
|
||||
use App\Models\InfoItem;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Symfony\Component\Finder\Exception\AccessDeniedException;
|
||||
|
||||
class VerifyBySupervisorRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return Gate::allows('gate-supervise-road-item', $this->roadItemsProject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'verify' => 'required|in:1,2',
|
||||
'description' => 'nullable|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ return new class extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('road_items_projects', function (Blueprint $table) {
|
||||
$table->foreignId('mission_id')->constrained('missions');
|
||||
$table->foreignId('mission_id')->nullable()->constrained('missions');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -111,9 +111,7 @@ Route::post('logout', LogoutController::class)->name('logout');
|
||||
|
||||
Route::prefix('road_items')
|
||||
->name('road_items.')
|
||||
->controller(RoadItemsProjectController::class)
|
||||
->group(function () {
|
||||
|
||||
Route::prefix('operator')
|
||||
->name('operator.')
|
||||
->controller(\App\Http\Controllers\V3\Dashboard\RoadItem\OperatorController::class)
|
||||
@@ -128,7 +126,6 @@ Route::prefix('road_items')
|
||||
Route::post('/{roadItemsProject}', 'update')->name('update');
|
||||
Route::delete('/{roadItemsProject}', 'destroy')->middleware('permission:delete-road-item')->name('destroy');
|
||||
});
|
||||
|
||||
Route::prefix('supervisor')
|
||||
->name('supervisor.')
|
||||
->controller(\App\Http\Controllers\V3\Dashboard\RoadItem\SupervisorController::class)
|
||||
@@ -140,7 +137,6 @@ Route::prefix('road_items')
|
||||
Route::post('/reject/{roadItemsProject}', 'reject')->name('reject');
|
||||
Route::post('/restore/{roadItemsProject}', 'restore')->middleware('permission:restore-road-item')->name('restore');
|
||||
});
|
||||
|
||||
Route::prefix('details')
|
||||
->name('details.')
|
||||
->controller(\App\Http\Controllers\V3\Dashboard\RoadItem\DetailController::class)
|
||||
|
||||
Reference in New Issue
Block a user