crate new repor for machin when they go to the mission and fix bugs in traddod mission
This commit is contained in:
@@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user