create excel for report

This commit is contained in:
faezeh
2026-06-27 17:07:13 +03:30
parent aa468b592b
commit da82c7841b
11 changed files with 635 additions and 130 deletions

View File

@@ -2,14 +2,14 @@
namespace App\Http\Controllers\V3\Dashboard\Mission\Report;
use App\Exports\V3\Mission\Report\Machine\machineDetailsReport;
use App\Exports\V3\Mission\Report\Machine\machineDriverDetailsReport;
use App\Exports\V3\Mission\Report\Machine\machineDriverReport;
use App\Exports\V3\Mission\Report\Machine\machineReport;
use App\Exports\V3\Mission\Report\Machine\machineTypeDetailsReport;
use App\Exports\V3\Mission\Report\Machine\machineTypeReport;
use App\Facades\DataTable\DataTableFacade;
use App\Http\Controllers\Controller;
use App\Http\Traits\ApiResponse;
use App\Models\CMMSMachine;
use App\Models\Mission;
use App\Services\Cartables\Mission\Report\ReportMachineService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -21,113 +21,26 @@ class ReportMachineController extends Controller
{
use ApiResponse;
public function countryMachinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse
public function machineDetailsReport(Request $request, ReportMachineService $reportMachineService,int $machine_id): JsonResponse
{
return $this->successResponse([
'activities' => $reportMachineService->countryMachinesActivity($request),
// 'provinces' => Province::all(['id', 'name_fa']),
]);
$data = $reportMachineService->dataTableMachinesActivity($request,$machine_id);
return response()->json($data);
}
/**
* @throws Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function countryMachinesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse
public function machineDetailsReportExcel(Request $request, int $machine_id, ReportMachineService $reportMachineService): BinaryFileResponse
{
$data = $reportMachineService->countryMachinesActivity($request);
$name = 'گزارش ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx';
$data = $reportMachineService->dataTableMachinesActivity($request,$machine_id);
$name = 'گزارش عملکرد ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx';
return Excel::download(new machineReport($data), $name);
return Excel::download(new machineDetailsReport($data['data']), $name);
}
public function provinceMachinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse
{
return $this->successResponse([
'activities' => $reportMachineService->provinceMachinesActivity($request),
// 'city' => City::query()
// ->where('province_id', $request->province_id)
// ->where(function ($query) {
// $query->where('type_id', 1)
// ->orWhereIn('name_fa', ['اداره ماشين‌آلات', 'اداره نقلیه']);
// })
// ->get(['id', 'name_fa'])
]);
}
/**
* @throws Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function provinceMachinesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse
{
$data = $reportMachineService->provinceMachinesActivity($request);
$name = 'گزارش ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx';
return Excel::download(new machineReport($data), $name);
}
public function countryMachineTypesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse
{
return $this->successResponse([
'activities' => $reportMachineService->countryMachineTypesActivity($request),
// 'provinces' => Province::all(['id', 'name_fa']),
]);
}
/**
* @throws Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function countryMachineTypesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse
{
$data = $reportMachineService->countryMachineTypesActivity($request);
$name = 'گزارش نوع ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx';
return Excel::download(new machineTypeReport($data), $name);
}
public function provinceMachineTypesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse
{
return $this->successResponse([
'activities' => $reportMachineService->provinceMachineTypesActivity($request),
// 'city' => City::query()
// ->where('province_id', $request->province_id)
// ->where(function ($query) {
// $query->where('type_id', 1)
// ->orWhereIn('name_fa', ['اداره ماشين‌آلات', 'اداره نقلیه']);
// })
// ->get(['id', 'name_fa'])
]);
}
public function machineDetailsReport(Request $request, int $machine_id)
{
return DataTableFacade::run(
Mission::query()->where('machine_id', '=', $machine_id),
$request,
allowedFilters: ['*'],
allowedSortings: ['*'],
allowedSelects: [
'id', 'province_id', 'province_name', 'city_id', 'city_name',
'end_km', 'km', 'driver_name', 'state_id', 'station_name'
]
);
}
/**
* @throws Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function provinceMachineTypesActivityExcel(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse
{
$data = $reportMachineService->provinceMachineTypesActivity($request);
$name = 'گزارش نوع ماشین آلات'.verta()->now()->format('Y-m-d H-i').'.xlsx';
return Excel::download(new machineTypeReport($data), $name);
}
public function countryMachineDriversActivity(Request $request, ReportMachineService $reportMachineService)
public function machinesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse
{
return $this->successResponse([
'activities' => $reportMachineService->machinesActivity($request),
@@ -149,19 +62,23 @@ class ReportMachineController extends Controller
}
public function machineTypeDetailsReport(Request $request): array
public function machineTypeDetailsReport(Request $request, ReportMachineService $reportMachineService,int $car_type): JsonResponse
{
$machineIds = CMMSMachine::query()->where('car_type', '=', $request->query('car_type'))->pluck('machine_id');
return DataTableFacade::run(
Mission::query()->whereIn('machine_id', $machineIds),
$request,
allowedFilters: ['*'],
allowedSortings: ['*'],
allowedSelects: [
'id', 'province_id', 'province_name', 'city_id', 'city_name',
'end_km', 'km', 'driver_name', 'state_name', 'station_name'
]
);
$data = $reportMachineService->dataTableMachineTypesActivity($request,$car_type);
return response()->json($data);
}
/**
* @throws Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function machineTypeDetailsReportExcel(Request $request, ReportMachineService $reportMachineService,int $car_type): BinaryFileResponse
{
$data = $reportMachineService->dataTableMachineTypesActivity($request,$car_type);
$name = 'گزارش عملکردیک نوع ماشین'.verta()->now()->format('Y-m-d H-i').'.xlsx';
return Excel::download(new machineTypeDetailsReport($data['data']), $name);
}
public function machineTypesActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse
@@ -184,19 +101,26 @@ class ReportMachineController extends Controller
return Excel::download(new machineTypeReport($data), $name);
}
public function machineDriverDetailsReport(Request $request, int $driver_id): array
public function machineDriverDetailsReport(Request $request, int $driver_id, ReportMachineService $reportMachineService): JsonResponse
{
return DataTableFacade::run(
Mission::query()->where('driver_id', '=', $driver_id),
$request,
allowedFilters: ['*'],
allowedSortings: ['*'],
allowedSelects: [
'id', 'province_id', 'province_name', 'city_id', 'city_name',
'end_km', 'km', 'driver_name', 'state_id', 'station_name'
]
);
$data = $reportMachineService->dataTableMachineDriversActivity($request,$driver_id);
return response()->json($data);
}
/**
* @throws Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function machineDriverDetailsReportExcel(Request $request, int $driver_id, ReportMachineService $reportMachineService): BinaryFileResponse
{
$data = $reportMachineService->dataTableMachineDriversActivity($request,$driver_id);
$name = 'گزارش عملکرد راننده'.verta()->now()->format('Y-m-d H-i').'.xlsx';
return Excel::download(
new machineDriverDetailsReport($data['data']), $name);
}
public function machineDriversActivity(Request $request, ReportMachineService $reportMachineService): JsonResponse
{
return $this->successResponse([
@@ -216,4 +140,4 @@ class ReportMachineController extends Controller
return Excel::download(new machineDriverReport($data), $name);
}
}
}