Updated: Improved vehicle and refuel data handling on dashboard
All checks were successful
Build and Deploy Zola Website / build_and_deploy (push) Successful in 14s
All checks were successful
Build and Deploy Zola Website / build_and_deploy (push) Successful in 14s
Updated: - DashboardController now fetches latest refuel record only for the default vehicle - VehicleController - first created vehicle is now set as default automatically - Refuel model - latest_one() now accepts vehicle_id instead of user_id - Dashboard view - improved handling when no vehicles or refuel records exist - CSS styles - adjusted dashboard layout and global action padding
This commit is contained in:
@ -60,7 +60,7 @@ class Refuel {
|
||||
}
|
||||
}
|
||||
|
||||
public function latest_one($user_id, $record_count = 1) {
|
||||
public function latest_one($vehicle_id, $record_count = 1) {
|
||||
try {
|
||||
$stmt = $this->db->prepare("
|
||||
SELECT
|
||||
@ -70,15 +70,16 @@ class Refuel {
|
||||
`r`.`price_per_liter`,
|
||||
`r`.`total_price`,
|
||||
`r`.`mileage`,
|
||||
`r`.`note`,
|
||||
`r`.`created_at`
|
||||
FROM `refueling_records` AS `r`
|
||||
JOIN `vehicles` AS `v` ON `r`.`vehicle_id` = `v`.`id`
|
||||
WHERE `r`.`user_id` = ?
|
||||
WHERE `r`.`vehicle_id` = ?
|
||||
ORDER BY `r`.`created_at` DESC
|
||||
LIMIT ?;
|
||||
");
|
||||
|
||||
$stmt->bind_param("ii", $user_id, $record_count);
|
||||
$stmt->bind_param("ii", $vehicle_id, $record_count);
|
||||
if ($stmt->execute()) {
|
||||
$result = $stmt->get_result();
|
||||
$data = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
@ -10,17 +10,18 @@ class Vehicle {
|
||||
public function create($data) {
|
||||
try{
|
||||
$stmt = $this->db->prepare("
|
||||
INSERT INTO vehicles (user_id, name, registration_plate, fuel_type, note, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, NOW())
|
||||
INSERT INTO vehicles (user_id, name, registration_plate, fuel_type, note, is_default, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, NOW())
|
||||
");
|
||||
|
||||
$stmt->bind_param(
|
||||
"issss",
|
||||
"issssi",
|
||||
$data['user_id'],
|
||||
$data['name'],
|
||||
$data['registration_plate'],
|
||||
$data['fuel_type'],
|
||||
$data['note'],
|
||||
$data['is_default'],
|
||||
);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
|
Reference in New Issue
Block a user