seperate machine code from road item table
This commit is contained in:
@@ -39,8 +39,7 @@ class RoadItemsProjectController extends Controller
|
|||||||
'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa',
|
'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa',
|
||||||
'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa',
|
'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa',
|
||||||
'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time',
|
'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time',
|
||||||
'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time',
|
'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time','cmmsMachines.machine_code'
|
||||||
'cmms_machine_code'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$allowedFilters = $columns;
|
$allowedFilters = $columns;
|
||||||
@@ -50,14 +49,14 @@ class RoadItemsProjectController extends Controller
|
|||||||
$query = null;
|
$query = null;
|
||||||
|
|
||||||
if ($user->hasPermissionTo('show-road-item-supervise-cartable')) {
|
if ($user->hasPermissionTo('show-road-item-supervise-cartable')) {
|
||||||
$query = RoadItemsProject::query()->where('is_new', 1)->with(['files', 'rahdaran:id,name,code', 'cmmsMachine:id,machine_code']);
|
$query = RoadItemsProject::query()->where('is_new', 1)->with(['files', 'rahdaran:id,name,code', 'cmmsMachines:id,machine_code']);
|
||||||
}
|
}
|
||||||
elseif ($user->hasPermissionTo('show-road-item-supervise-cartable-province')) {
|
elseif ($user->hasPermissionTo('show-road-item-supervise-cartable-province')) {
|
||||||
if (is_null($user->province_id)) {
|
if (is_null($user->province_id)) {
|
||||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||||
}
|
}
|
||||||
$query = RoadItemsProject::query()->where('is_new', 1)
|
$query = RoadItemsProject::query()->where('is_new', 1)
|
||||||
->with(['files', 'rahdaran:id,name,code', 'cmmsMachine:id,machine_code'])->where('province_id', auth()->user()->province_id);
|
->with(['files', 'rahdaran:id,name,code', 'cmmsMachines:id,machine_code'])->where('province_id', auth()->user()->province_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = DataTableFacade::run(
|
$data = DataTableFacade::run(
|
||||||
@@ -147,14 +146,13 @@ class RoadItemsProjectController extends Controller
|
|||||||
'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa',
|
'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa',
|
||||||
'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa',
|
'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa',
|
||||||
'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time',
|
'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time',
|
||||||
'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time',
|
'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time', 'cmmsMachines.machine_code'
|
||||||
'cmms_machine_code'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$allowedFilters = $columns;
|
$allowedFilters = $columns;
|
||||||
$allowedSortings = $columns;
|
$allowedSortings = $columns;
|
||||||
|
|
||||||
$query = RoadItemsProject::with(['files', 'rahdaran:id,name,code', 'cmmsMachine:id,machine_code'])
|
$query = RoadItemsProject::with(['files', 'rahdaran:id,name,code', 'cmmsMachines:id,machine_code'])
|
||||||
->where('is_new', 1)
|
->where('is_new', 1)
|
||||||
->where('user_id', auth()->user()->id);
|
->where('user_id', auth()->user()->id);
|
||||||
|
|
||||||
@@ -206,7 +204,6 @@ class RoadItemsProjectController extends Controller
|
|||||||
|
|
||||||
$start_coordinates = explode(',', $request->start_point);
|
$start_coordinates = explode(',', $request->start_point);
|
||||||
$end_coordinates = $info_item->needs_end_point ? explode(',', $request->end_point) : null;
|
$end_coordinates = $info_item->needs_end_point ? explode(',', $request->end_point) : null;
|
||||||
$cmmsMachine = CMMSMachine::query()->find($request->cmms_machine_id);
|
|
||||||
|
|
||||||
$attributes = [
|
$attributes = [
|
||||||
'start_lat' => $start_coordinates[0],
|
'start_lat' => $start_coordinates[0],
|
||||||
@@ -235,8 +232,6 @@ class RoadItemsProjectController extends Controller
|
|||||||
'edarat_name' => $user->edarate_shahri_name,
|
'edarat_name' => $user->edarate_shahri_name,
|
||||||
'activity_date' => $request->activity_date,
|
'activity_date' => $request->activity_date,
|
||||||
'activity_time' => $request->activity_time,
|
'activity_time' => $request->activity_time,
|
||||||
'cmms_machine_id' => $cmmsMachine->id,
|
|
||||||
'cmms_machine_code' => $cmmsMachine->machine_code,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$after_image = ($request->has('after_image') && $info_item->needs_image) ?
|
$after_image = ($request->has('after_image') && $info_item->needs_image) ?
|
||||||
@@ -256,6 +251,7 @@ class RoadItemsProjectController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$road_item->rahdaran()->attach($request->rahdaran_id);
|
$road_item->rahdaran()->attach($request->rahdaran_id);
|
||||||
|
$road_item->cmmsMachines()->attach($request->machines_id);
|
||||||
|
|
||||||
auth()->user()->addActivityComplete(1154);
|
auth()->user()->addActivityComplete(1154);
|
||||||
|
|
||||||
@@ -285,8 +281,6 @@ class RoadItemsProjectController extends Controller
|
|||||||
$end_coordinates = explode(',', $request->end_point);
|
$end_coordinates = explode(',', $request->end_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cmmsMachine = CMMSMachine::query()->find($request->cmms_machine_id);
|
|
||||||
|
|
||||||
if ($info_item->needs_image) {
|
if ($info_item->needs_image) {
|
||||||
if ($request->has('after_image')) {
|
if ($request->has('after_image')) {
|
||||||
|
|
||||||
@@ -321,11 +315,10 @@ class RoadItemsProjectController extends Controller
|
|||||||
'sub_item_data' => $request->amount,
|
'sub_item_data' => $request->amount,
|
||||||
'status' => 0,
|
'status' => 0,
|
||||||
'status_fa' => 'در حال بررسی',
|
'status_fa' => 'در حال بررسی',
|
||||||
'cmms_machine_id' => $cmmsMachine->id,
|
|
||||||
'cmms_machine_code' => $cmmsMachine->machine_code,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$roadItemsProject->rahdaran()->sync($request->rahdaran_id);
|
$roadItemsProject->rahdaran()->sync($request->rahdaran_id);
|
||||||
|
$roadItemsProject->cmmsMachines()->sync($request->machines_id);
|
||||||
|
|
||||||
|
|
||||||
auth()->user()->addActivityComplete(1155);
|
auth()->user()->addActivityComplete(1155);
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ class StoreRequest extends FormRequest
|
|||||||
'activity_time' => 'required|date_format:H:i',
|
'activity_time' => 'required|date_format:H:i',
|
||||||
'before_image' => 'image|max:4096',
|
'before_image' => 'image|max:4096',
|
||||||
'after_image' => 'image|max:4096',
|
'after_image' => 'image|max:4096',
|
||||||
'cmms_machine_id' => 'required|exists:cmms_machines,id',
|
'machines_id' => 'required|array',
|
||||||
|
'machines_id.*' => 'required|exists:cmms_machines,id',
|
||||||
'rahdaran_id' => 'required|array',
|
'rahdaran_id' => 'required|array',
|
||||||
'rahdaran_id.*' => 'required|exists:rahdaran,id',
|
'rahdaran_id.*' => 'required|exists:rahdaran,id',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ class UpdateRequest extends FormRequest
|
|||||||
'amount' => 'required|numeric',
|
'amount' => 'required|numeric',
|
||||||
'before_image' => 'image|max:4096',
|
'before_image' => 'image|max:4096',
|
||||||
'after_image' => 'image|max:4096',
|
'after_image' => 'image|max:4096',
|
||||||
'cmms_machine_id' => 'required|exists:cmms_machines,id',
|
'machines_id' => 'required|array',
|
||||||
|
'machines_id.*' => 'required|exists:cmms_machines,id',
|
||||||
'rahdaran_id' => 'required|array',
|
'rahdaran_id' => 'required|array',
|
||||||
'rahdaran_id.*' => 'required|exists:rahdaran,id',
|
'rahdaran_id.*' => 'required|exists:rahdaran,id',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -55,8 +55,6 @@ class RoadItemsProject extends Model
|
|||||||
'activity_date',
|
'activity_date',
|
||||||
'activity_time',
|
'activity_time',
|
||||||
'activity_date_time',
|
'activity_date_time',
|
||||||
'cmms_machine_id',
|
|
||||||
'cmms_machine_code',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,8 +129,6 @@ class RoadItemsProject extends Model
|
|||||||
'activity_time' => $attributes['activity_time'],
|
'activity_time' => $attributes['activity_time'],
|
||||||
'activity_date_time' => $attributes['activity_date']." ".$attributes['activity_time'],
|
'activity_date_time' => $attributes['activity_date']." ".$attributes['activity_time'],
|
||||||
'is_new' => 1,
|
'is_new' => 1,
|
||||||
'cmms_machine_id' => $attributes['cmms_machine_id'] ?? null,
|
|
||||||
'cmms_machine_code' => $attributes['cmms_machine_code'] ?? null,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// if ($info_item->needs_image) {
|
// if ($info_item->needs_image) {
|
||||||
@@ -171,9 +167,9 @@ class RoadItemsProject extends Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cmmsMachine(): HasOne
|
public function cmmsMachines(): BelongsToMany
|
||||||
{
|
{
|
||||||
return $this->hasOne(CMMSMachine::class, 'id', 'cmms_machine_id');
|
return $this->belongsToMany(CMMSMachine::class, 'cmms_machine_road_items_project');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rahdaran(): BelongsToMany
|
public function rahdaran(): BelongsToMany
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::table('road_items_projects', function (Blueprint $table) {
|
|
||||||
$table->foreignId('cmms_machine_id')->nullable()->constrained('cmms_machines');
|
|
||||||
$table->string('cmms_machine_code')->nullable();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('road_items_projects', function (Blueprint $table) {
|
|
||||||
$table->dropForeign(['cmms_machine_id']);
|
|
||||||
$table->dropColumn('cmms_machine_id');
|
|
||||||
$table->dropColumn('cmms_machine_code');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('cmms_machine_road_items_project', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('machine_id')->constrained('cmms_machines')->onDelete('cascade');
|
||||||
|
$table->unsignedBigInteger('road_items_project_id');
|
||||||
|
$table->foreign('road_items_project_id')->references('id')->on('road_items_projects')->onDelete('cascade');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('cmms_machine_road_items_project');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user