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,43 @@
<?php
namespace App\Services\Cartables\Mission\Report;
use App\Facades\DataTable\DataTableFacade;
use App\Models\MissionViolation;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ReportMachineService
{
public function activity(Request $request): array
{
$code = $request->machine_code;
$from = $request->from_date ?? today()->startOfDay();
$to = $request->date_to ? Carbon::parse($request->date_to)->endOfDay() : today()->endOfDay();
$sql = "
SELECT*
m.city_name AS c.name,
m.city_id AS c_id,
m.province_name AS p_name,
m.province_id AS p_id,
COUNT(m.machine_code) As m_c_code,
SUM(m.end_km)-sum(m.km) AS distance
FROM missions m
WHERE m.machine_code = :machineCode
AND m.created_at >= :from
AND m.created_at <= :to
GROUP BY m.city_id, m.city_name,m.province_id, m.province_name;
";
return DB::select($sql, [
'from' => $from,
'to' => $to,
'machineCode' => $code,
]);
}
}