seperate the logic into service reports
This commit is contained in:
@@ -2,10 +2,75 @@
|
||||
|
||||
namespace App\Services\Reports;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Models\RoadPatrol;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RoadPatrolReportService
|
||||
{
|
||||
public function supervisorCartableReport(Request $request)
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'start_lat', 'start_lon', 'end_lat', 'end_lon', 'operator_id', 'created_at',
|
||||
'operator_name', 'officer_plaque', 'officer_phone_number', 'officer_name',
|
||||
'supervisor_description', 'supervising_time', 'supervisor_name', 'status',
|
||||
'status_fa', 'distance', 'province_id', 'province_fa', 'edare_id', 'edare_name',
|
||||
'start_time', 'end_time','description', 'cmmsMachines.machine_code', 'rahdaran.code',
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$user = auth()->user();
|
||||
$query = null;
|
||||
|
||||
if ($user->hasPermissionTo('show-road-patrol-supervise-cartable')) {
|
||||
$query = RoadPatrol::query()
|
||||
->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number']);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-road-patrol-supervise-cartable-province')) {
|
||||
if (is_null($user->province_id)) {
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
$query = RoadPatrol::query()
|
||||
->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])
|
||||
->where('province_id', '=', $user->province_id);
|
||||
}
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function operatorCartableReport(Request $request)
|
||||
{
|
||||
$columns = array(
|
||||
'id', 'start_lat', 'start_lon', 'end_lat', 'end_lon', 'officer_plaque', 'created_at',
|
||||
'officer_phone_number', 'officer_name', 'supervisor_description', 'supervising_time',
|
||||
'supervisor_name', 'status', 'status_fa', 'distance', 'start_time', 'end_time', 'cmmsMachines.machine_code', 'rahdaran.code',
|
||||
);
|
||||
|
||||
$allowedFilters = $columns;
|
||||
$allowedSortings = $columns;
|
||||
|
||||
$query = RoadPatrol::query()
|
||||
->with(['rahdaran:id,name,code', 'cmmsMachines:id,machine_code,car_name,plak_number'])
|
||||
->where('operator_id', '=', auth()->user()->id);
|
||||
|
||||
$data = DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: $allowedFilters,
|
||||
allowedSortings: $allowedSortings);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function countryActivity(string $fromDate, string $toDate): array
|
||||
{
|
||||
$activities = DB::select('SELECT
|
||||
|
||||
Reference in New Issue
Block a user