Merge branch 'feature/MachineIdObjectReturned' into 'develop'

Feature/machine id object returned

See merge request witelgroup/rms_v2!47
This commit is contained in:
2024-12-23 12:35:08 +00:00
4 changed files with 26 additions and 12 deletions

View File

@@ -40,7 +40,7 @@ class RoadItemsProjectController extends Controller
'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa',
'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time',
'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time',
'cmms_machine_id', 'cmms_machine_code'
'cmms_machine_code'
);
$allowedFilters = $columns;
@@ -50,14 +50,14 @@ class RoadItemsProjectController extends Controller
$query = null;
if ($user->hasPermissionTo('show-road-item-supervise-cartable')) {
$query = RoadItemsProject::query()->where('is_new', 1)->with('files', 'rahdaran:id,name,code');
$query = RoadItemsProject::query()->where('is_new', 1)->with(['files', 'rahdaran:id,name,code', 'cmmsMachine:id,machine_code']);
}
elseif ($user->hasPermissionTo('show-road-item-supervise-cartable-province')) {
if (is_null($user->province_id)) {
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
}
$query = RoadItemsProject::query()->where('is_new', 1)
->with('files', 'rahdaran:id,name,code')->where('province_id', auth()->user()->province_id);
->with(['files', 'rahdaran:id,name,code', 'cmmsMachine:id,machine_code'])->where('province_id', auth()->user()->province_id);
}
$data = DataTableFacade::run(
@@ -148,13 +148,13 @@ class RoadItemsProjectController extends Controller
'sub_item_data', 'created_at', 'updated_at', 'province_id', 'province_fa',
'unit_fa', 'status', 'status_fa', 'supervisor_description', 'supervising_time',
'supervisor_name', 'edarat_id', 'edarat_name', 'activity_date_time',
'cmms_machine_id', 'cmms_machine_code'
'cmms_machine_code'
);
$allowedFilters = $columns;
$allowedSortings = $columns;
$query = RoadItemsProject::with(['files', 'rahdaran:id,name,code'])
$query = RoadItemsProject::with(['files', 'rahdaran:id,name,code', 'cmmsMachine:id,machine_code'])
->where('is_new', 1)
->where('user_id', auth()->user()->id);
@@ -298,7 +298,7 @@ class RoadItemsProjectController extends Controller
]);
// $roadItemsProject->files()->create(['path' => $after]);
$urlAfter = "/var/www/rms/public/storage/{$after}";
\App\Helpers\Compress::resize($urlAfter);
// \App\Helpers\Compress::resize($urlAfter);
}
if ($request->has('before_image')) {
Storage::delete('public/'. $roadItemsProject->files[1]->path);
@@ -309,7 +309,7 @@ class RoadItemsProjectController extends Controller
]);
// $roadItemsProject->files()->create(['path' => $before]);
$urlBefore = "/var/www/rms/public/storage/{$before}";
\App\Helpers\Compress::resize($urlBefore);
// \App\Helpers\Compress::resize($urlBefore);
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Http\UploadedFile;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
@@ -170,6 +171,11 @@ class RoadItemsProject extends Model
}
}
public function cmmsMachine(): HasOne
{
return $this->hasOne(CMMSMachine::class, 'id', 'cmms_machine_id');
}
public function rahdaran(): BelongsToMany
{
return $this->belongsToMany(Rahdaran::class,'rahdaran_road_items_project');

View File

@@ -57,12 +57,17 @@ class DataTableInput
}
/**
* @return Sort|null
* @return array
*/
public function getSorting(): ?Sort
public function getSorting(): ?array
{
return !empty($this->sorting) ?
new Sort($this->sorting[0]->id, $this->sorting[0]->desc, $this->allowedSortings) : null;
$sorts = [];
if (!empty($this->sorting)){
foreach ($this->sorting as $sort) {
$sorts[] = new Sort($sort->id, $sort->desc, $this->allowedSortings);
}
}
return $sorts;
}
public function getRelations(): array

View File

@@ -83,7 +83,10 @@ class DataTableService
}
$sorting = $this->dataTableInput->getSorting();
$query = (new ApplySort($query, $sorting))->apply();
foreach ($sorting as $sort){
$query = (new ApplySort($query, $sort))->apply();
}
return $query;
}