crate new repor for machin when they go to the mission and fix bugs in traddod mission

This commit is contained in:
2026-05-25 16:25:56 +03:30
parent 7d7507411d
commit e3b49ebbb3
10 changed files with 271 additions and 7 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Http\Controllers\V3\Dashboard\Mission\Report;
use App\Exports\V3\Mission\Report\Tradod\CountryReport;
use App\Exports\V3\Mission\Report\Tradod\ProvinceReport;
use App\Http\Controllers\Controller;
use App\Http\Traits\ApiResponse;
use App\Models\City;
use App\Models\Mission;
use App\Models\Province;
use App\Services\Cartables\Mission\Report\ReportMachineService;
use App\Services\Cartables\Mission\Report\ReportTradodService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use PhpOffice\PhpSpreadsheet\Exception;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class ReportMachineController extends Controller
{
use ApiResponse;
public function Activity(Request $request, ReportMachineService $reportMachineService): JsonResponse
{
return $this->successResponse([
'activities' => $reportMachineService->Activity($request),
'provinces' => Province::all(['id', 'name_fa']),
'code' => Mission::query()
->where('machine_code', $request->machine_code)
->get()
]);
}
/**
* @throws Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function ExcelActivity(Request $request, ReportMachineService $reportMachineService): BinaryFileResponse
{
$data = $reportMachineService->Activity($request);
$name = 'گزارش کل تردد یک ماشین '.verta()->now()->format('Y-m-d H-i').'.xlsx';
return Excel::download(new CountryReport($data), $name);
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Http\Requests\V3\Mission\ControlUnit;
use App\Enums\MissionStates;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator;
class FinishRequest extends FormRequest
{
@@ -23,9 +24,31 @@ class FinishRequest extends FormRequest
*/
public function rules(): array
{
$mission = $this->route('mission');
return [
'time' => 'required|date',
'end_km' => 'required',
];
}
public function after(): array
{
return [
function (Validator $validator) {
$mission = $this->route('mission');
if (strtotime($this->time) < strtotime($mission->start_time)) {
$validator->errors()->add(
'time',
'زمان پایان ماموریت باید بعد از زمان شروع ماموریت باشد.'
);
}
if ($this->end_km < $mission->km) {
$validator->errors()->add(
'end_km',
'کیلومتر پایان باید بزرگتر از کیلومتر شروع باشد.'
);
}
}
];
}
}