seperate the relation loading
This commit is contained in:
@@ -11,31 +11,31 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RoadItemReportService
|
||||
{
|
||||
public function supervisorCartableReport(Request $request)
|
||||
public function supervisorCartableReport(Request $request, $loadRelations = false)
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'user_id', 'start_lat', 'start_lng', 'end_lat',
|
||||
'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa', 'sub_item',
|
||||
'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','cmmsMachines.machine_code', 'rahdaran.code',
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
$allowedFilters = ['*'];
|
||||
$allowedSortings = ['*'];
|
||||
|
||||
$user = auth()->user();
|
||||
$query = null;
|
||||
|
||||
if ($user->hasPermissionTo('show-road-item-supervise-cartable')) {
|
||||
$query = RoadItemsProject::query()->where('is_new', 1)->with(['files', 'rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']);
|
||||
$query = RoadItemsProject::query()
|
||||
->select(['id', 'province_fa', 'edarat_name', 'item_fa', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng',
|
||||
'end_lat', 'end_lng', 'activity_date_time', 'created_at', 'status_fa', 'status'])
|
||||
->where('is_new', 1)
|
||||
->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']));
|
||||
}
|
||||
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', 'cmmsMachines:id,machine_code,car_name,plak_number'])->where('province_id', auth()->user()->province_id);
|
||||
$query = RoadItemsProject::query()
|
||||
->select(['id', 'province_fa', 'edarat_name', 'item_fa', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng',
|
||||
'end_lat', 'end_lng', 'activity_date_time', 'created_at', 'status_fa', 'status'])
|
||||
->where('is_new', 1)
|
||||
->where('province_id', auth()->user()->province_id)
|
||||
->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']));
|
||||
}
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
@@ -47,22 +47,17 @@ class RoadItemReportService
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function operatorCartableReport(Request $request)
|
||||
public function operatorCartableReport(Request $request, $loadRelations = false)
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'user_id', 'start_lat', 'start_lng', 'end_lat',
|
||||
'end_lng', 'project_distance', 'item', 'item_fa', 'sub_item_fa', 'sub_item',
|
||||
'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', 'cmmsMachines.machine_code', 'rahdaran.code',
|
||||
);
|
||||
$allowedFilters = ['*'];
|
||||
$allowedSortings = ['*'];
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$query = RoadItemsProject::with(['files', 'rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])
|
||||
$query = RoadItemsProject::query()
|
||||
->select(['id', 'supervisor_description', 'item_fa', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng',
|
||||
'end_lat', 'end_lng', 'activity_date_time', 'created_at', 'status_fa', 'status'])
|
||||
->where('is_new', 1)
|
||||
->where('user_id', auth()->user()->id);
|
||||
->where('user_id', auth()->user()->id)
|
||||
->when($loadRelations, fn ($query) => $query->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']));;
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
|
||||
Reference in New Issue
Block a user