62 lines
2.1 KiB
PHP
62 lines
2.1 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\V3\Dashboard\Mission;
|
||
|
||
use App\Exports\V3\Mission\Report\CountryReport;
|
||
use App\Exports\V3\Mission\Report\ProvinceReport;
|
||
use App\Http\Controllers\Controller;
|
||
use App\Http\Traits\ApiResponse;
|
||
use App\Models\City;
|
||
use App\Models\Province;
|
||
use App\Services\Cartables\Mission\ReportService;
|
||
use Illuminate\Http\JsonResponse;
|
||
use Illuminate\Http\Request;
|
||
use Maatwebsite\Excel\Facades\Excel;
|
||
use PhpOffice\PhpSpreadsheet\Exception;
|
||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||
|
||
class ReportController extends Controller
|
||
{
|
||
use ApiResponse;
|
||
|
||
public function countryActivity(Request $request, ReportService $reportService): JsonResponse
|
||
{
|
||
return $this->successResponse([
|
||
'activities' => $reportService->countryActivity($request),
|
||
'provinces' => Province::all(['id', 'name_fa']),
|
||
]);
|
||
}
|
||
|
||
public function provinceActivity(Request $request, ReportService $reportService): JsonResponse
|
||
{
|
||
return $this->successResponse([
|
||
'activities' =>$reportService->provinceActivity($request),
|
||
'city' => City::query()->where('province_id', $request->province_id)->get(['id', 'name_fa']),
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* @throws Exception
|
||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||
*/
|
||
public function countryExcelActivity(Request $request, ReportService $reportService): BinaryFileResponse
|
||
{
|
||
$data = $reportService->countryActivity($request);
|
||
$name = 'گزارش تخلفات ماموریت ها '.verta()->now()->format('Y-m-d H-i').'.xlsx';
|
||
|
||
return Excel::download(new CountryReport($data), $name);
|
||
}
|
||
|
||
/**
|
||
* @throws Exception
|
||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||
*/
|
||
public function provinceExcelActivity(Request $request, ReportService $reportService): BinaryFileResponse
|
||
{
|
||
$data = $reportService->provinceActivity($request);
|
||
$name = 'گزارش تخلفات ماموریت ها '.verta()->now()->format('Y-m-d H-i').'.xlsx';
|
||
|
||
return Excel::download(new ProvinceReport($data), $name);
|
||
}
|
||
}
|