Added: Stats in dashboard
All checks were successful
Build and Deploy Zola Website / build_and_deploy (push) Successful in 12s
All checks were successful
Build and Deploy Zola Website / build_and_deploy (push) Successful in 12s
This commit is contained in:
@ -34,4 +34,59 @@ class Refuel {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function latest_data($vehicle_id, $record_count) {
|
||||
try {
|
||||
$stmt = $this->db->prepare("
|
||||
SELECT `liters`, `price_per_liter`, `total_price`, `created_at`
|
||||
FROM `refueling_records`
|
||||
WHERE `vehicle_id` = ?
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ?;
|
||||
");
|
||||
|
||||
$stmt->bind_param("ii", $vehicle_id, $record_count);
|
||||
if ($stmt->execute()) {
|
||||
$result = $stmt->get_result();
|
||||
$data = $result->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
return array_reverse($data);
|
||||
} else {
|
||||
return "Error: " . $stmt->error;
|
||||
}
|
||||
} catch (mysqli_sql_exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function latest_one($user_id, $record_count = 1) {
|
||||
try {
|
||||
$stmt = $this->db->prepare("
|
||||
SELECT
|
||||
`r`.`vehicle_id`,
|
||||
`v`.`name` AS `vehicle_name`,
|
||||
`r`.`liters`,
|
||||
`r`.`price_per_liter`,
|
||||
`r`.`total_price`,
|
||||
`r`.`created_at`
|
||||
FROM `refueling_records` AS `r`
|
||||
JOIN `vehicles` AS `v` ON `r`.`vehicle_id` = `v`.`id`
|
||||
WHERE `r`.`user_id` = ?
|
||||
ORDER BY `r`.`created_at` DESC
|
||||
LIMIT ?;
|
||||
");
|
||||
|
||||
$stmt->bind_param("ii", $user_id, $record_count);
|
||||
if ($stmt->execute()) {
|
||||
$result = $stmt->get_result();
|
||||
$data = $result->fetch_all(MYSQLI_ASSOC);
|
||||
$stmt->close();
|
||||
return array_reverse($data);
|
||||
} else {
|
||||
return "Error: " . $stmt->error;
|
||||
}
|
||||
} catch (mysqli_sql_exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ class Vehicle {
|
||||
}
|
||||
}
|
||||
|
||||
public function getVehiclesByUser($userId) {
|
||||
public function getVehiclesByUser($user_id) {
|
||||
$stmt = $this->db->prepare("SELECT id, name, registration_plate, fuel_type, note, created_at FROM vehicles WHERE user_id = ?");
|
||||
$stmt->bind_param("i", $userId);
|
||||
$stmt->bind_param("i", $user_id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
@ -46,4 +46,18 @@ class Vehicle {
|
||||
|
||||
return $vehicles;
|
||||
}
|
||||
|
||||
public function getDefaultVehicle($user_id) {
|
||||
$stmt = $this->db->prepare("
|
||||
SELECT id, name, registration_plate, fuel_type, note, is_default
|
||||
FROM vehicles
|
||||
WHERE user_id = ? AND is_default = TRUE
|
||||
LIMIT 1
|
||||
");
|
||||
$stmt->bind_param("i", $user_id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
return $result->fetch_assoc();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user