Title:
Vehicle Maintenance & Expense Tracker
Name:
Mehak Thakur
Reg No.:
24MCA0146
Faculty Name:
Dr. Kumaresan P
Problem Statement:
Managing a fleet or individual vehicle maintenance and expenses is often done manually or
without structure. This application aims to provide a simple desktop-based solution to track
vehicles, maintenance logs, expenses, reminders, and generate reports using a local SQLite
database.
Test Environment:
● Operating System: Windows 10 / Linux / macOS
● Python Version: Python 3.10+
● Libraries:
○ sqlite3
○ tabulate
○ datetime
○ csv
● Database: SQLite (vehicles.db)
Code:
# python -m pip install --upgrade --user pip
import sqlite3
from tabulate import tabulate
from datetime import datetime
import csv
def init_db():
conn = sqlite3.connect("vehicles.db")
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS vehicles (
id INTEGER PRIMARY KEY AUTOINCREMENT,
make TEXT, model TEXT, year INTEGER, vin TEXT, reg_number TEXT,
mileage INTEGER, fuel_efficiency REAL)''')
cursor.execute('''CREATE TABLE IF NOT EXISTS maintenance (
id INTEGER PRIMARY KEY AUTOINCREMENT,
vehicle_id INTEGER, service TEXT, cost REAL, date TEXT, mileage INTEGER,
FOREIGN KEY(vehicle_id) REFERENCES vehicles(id))''')
cursor.execute('''CREATE TABLE IF NOT EXISTS expenses (
id INTEGER PRIMARY KEY AUTOINCREMENT,
vehicle_id INTEGER, category TEXT, amount REAL, date TEXT,
FOREIGN KEY(vehicle_id) REFERENCES vehicles(id))''')
cursor.execute('''CREATE TABLE IF NOT EXISTS reminders (
id INTEGER PRIMARY KEY AUTOINCREMENT,
vehicle_id INTEGER, description TEXT, due_date TEXT,
FOREIGN KEY(vehicle_id) REFERENCES vehicles(id))''')
conn.commit()
conn.close()
def add_vehicle():
conn = sqlite3.connect("vehicles.db")
cursor = conn.cursor()
make = input("Enter Vehicle Make: ")
model = input("Enter Vehicle Model: ")
year = int(input("Enter Vehicle Year: "))
vin = input("Enter VIN: ")
reg_number = input("Enter Registration Number: ")
mileage = int(input("Enter Mileage: "))
fuel_efficiency = float(input("Enter Fuel Efficiency (km/l): "))
cursor.execute("INSERT INTO vehicles (make, model, year, vin, reg_number, mileage,
fuel_efficiency) VALUES (?, ?, ?, ?, ?, ?, ?)",
(make, model, year, vin, reg_number, mileage, fuel_efficiency))
conn.commit()
conn.close()
print("Vehicle added successfully!")
def log_maintenance():
conn = sqlite3.connect("vehicles.db")
cursor = conn.cursor()
cursor.execute("SELECT id, make, model FROM vehicles;")
vehicles = cursor.fetchall()
print("\nAvailable Vehicles:")
print(tabulate(vehicles, headers=["ID", "Make", "Model"]))
vehicle_id = int(input("Enter Vehicle ID from the list: "))
service = input("Enter Service Description: ")
cost = float(input("Enter Service Cost: "))
date = datetime.today().strftime('%Y-%m-%d')
mileage = int(input("Enter Current Mileage: "))
cursor.execute("INSERT INTO maintenance (vehicle_id, service, cost, date, mileage)
VALUES (?, ?, ?, ?, ?)",
(vehicle_id, service, cost, date, mileage))
conn.commit()
conn.close()
print("Maintenance record added successfully!")
def log_expense():
conn = sqlite3.connect("vehicles.db")
cursor = conn.cursor()
vehicle_id = int(input("Enter Vehicle ID: "))
category = input("Enter Expense Category (Fuel, Repair, etc.): ")
amount = float(input("Enter Expense Amount: "))
date = datetime.today().strftime('%Y-%m-%d')
cursor.execute("INSERT INTO expenses (vehicle_id, category, amount, date) VALUES (?, ?,
?, ?)",
(vehicle_id, category, amount, date))
conn.commit()
conn.close()
print("Expense recorded successfully!")
def add_reminder():
conn = sqlite3.connect("vehicles.db")
cursor = conn.cursor()
vehicle_id = int(input("Enter Vehicle ID: "))
description = input("Enter Reminder Description: ")
due_date = input("Enter Due Date (YYYY-MM-DD): ")
cursor.execute("INSERT INTO reminders (vehicle_id, description, due_date) VALUES
(?, ?, ?)",
(vehicle_id, description, due_date))
conn.commit()
conn.close()
print("Reminder added successfully!")
def view_reports():
conn = sqlite3.connect("vehicles.db")
cursor = conn.cursor()
print("\n--- Vehicle Summary Report ---")
cursor.execute("SELECT id, make, model, year, mileage, fuel_efficiency FROM vehicles")
print(tabulate(cursor.fetchall(), headers=["ID", "Make", "Model", "Year", "Mileage", "Fuel
Efficiency"]))
print("\n--- Maintenance History ---")
cursor.execute("SELECT vehicle_id, service, cost, date, mileage FROM maintenance
ORDER BY date DESC")
print(tabulate(cursor.fetchall(), headers=["Vehicle ID", "Service", "Cost", "Date", "Mileage"]))
print("\n--- Expense Report ---")
cursor.execute("SELECT category, SUM(amount) FROM expenses GROUP BY category")
print(tabulate(cursor.fetchall(), headers=["Category", "Total Amount"]))
conn.close()
def export_data():
conn = sqlite3.connect("vehicles.db")
cursor = conn.cursor()
with open("vehicle_data.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["ID", "Make", "Model", "Year", "VIN", "Reg Number", "Mileage", "Fuel
Efficiency"])
cursor.execute("SELECT * FROM vehicles")
writer.writerows(cursor.fetchall())
with open("maintenance_data.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["ID", "Vehicle ID", "Service", "Cost", "Date", "Mileage"])
cursor.execute("SELECT * FROM maintenance")
writer.writerows(cursor.fetchall())
with open("expense_data.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["ID", "Vehicle ID", "Category", "Amount", "Date"])
cursor.execute("SELECT * FROM expenses")
writer.writerows(cursor.fetchall())
print("Data exported successfully!")
conn.close()
def upcoming_maintenance():
conn = sqlite3.connect("vehicles.db")
cursor = conn.cursor()
cursor.execute("SELECT id, vehicle_id, description, due_date FROM reminders ORDER BY
due_date ASC")
reminders = cursor.fetchall()
if not reminders:
print("\nNo upcoming maintenance reminders.")
else:
print("\n--- Upcoming Maintenance & Reminders ---")
print(tabulate(reminders, headers=["ID", "Vehicle ID", "Description", "Due Date"]))
conn.close()
def main():
init_db()
while True:
print("\nVehicle Maintenance & Expense Tracker")
print("1. Add Vehicle")
print("2. Log Maintenance")
print("3. Log Expense")
print("4. Add Reminder")
print("5. View Reports")
print("6. Export Data")
print("7. View Upcoming Maintenance")
print("8. Exit")
choice = input("Enter choice: ")
if choice == '1':
add_vehicle()
elif choice == '2':
log_maintenance()
elif choice == '3':
log_expense()
elif choice == '4':
add_reminder()
elif choice == '5':
view_reports()
elif choice == '6':
export_data()
elif choice == '7':
upcoming_maintenance()
elif choice == '8':
print("Goodbye!")
break
else:
print("Invalid choice, try again.")
if __name__ == "__main__":
main()
Sample Input/Output:
Input Example:
● Add Vehicle:
○ Make: Toyota
○ Model: Corolla
○ Year: 2020
○ VIN: ABC123456XYZ7890
○ Reg Number: MH12AB1234
○ Mileage: 15000
○ Fuel Efficiency: 18.5
Output Example:
Vehicle added successfully!
Test Case Descriptions:
1. Test Case ID: TC001
● Description: Add new vehicle details to the system
● Preconditions: Application and database initialized
● Test Steps:
1. Run application
2. Select option to add a vehicle
3. Enter all required fields
● Expected Result: Vehicle should be added to the database
● Actual Result: Vehicle added successfully
● Status: Pass
2. Test Case ID: TC002
● Description: Log maintenance for a vehicle
● Preconditions: At least one vehicle exists in the system
● Test Steps:
1. Run application
2. Select log maintenance
3. Choose vehicle and enter service details
● Expected Result: Maintenance record saved
● Actual Result: Maintenance record added successfully
● Status: Pass
3. Test Case ID: TC003
● Description: Export all data to CSV files
● Preconditions: Vehicle, maintenance, and expense data exist
● Test Steps:
1. Run application
2. Select export option
● Expected Result: Data should be saved as CSV files
● Actual Result: Data exported successfully
● Status: Pass
Conclusion:
● Summary of test outcomes: All key features tested and passed successfully.
● Met Objective: Yes
● Further Improvement Required:
○ GUI integration for ease of use
○ Scheduling background alerts for reminders
○ Data backup and cloud sync support