41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?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.id) As missions,
|
|
(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;
|
|
";
|
|
|
|
return DB::select($sql, [
|
|
'from' => $from,
|
|
'to' => $to,
|
|
'machineCode' => $code,
|
|
]);
|
|
}
|
|
}
|