diff --git a/README.md b/README.md index fbbc475..2e57ad1 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,61 @@ -# Car Sells in Afghanistan - Professional Car Dealership Platform +# Car Sells in Afghanistan -Welcome to the **Car Sells in Afghanistan** web application. This platform is a modern, high-performance solution for car dealerships in Afghanistan. +A modern, responsive car marketplace web application. -## 🚀 Key Features +## Features -- **Modern UI/UX:** Built with a "Mobile-First" approach using Bootstrap 5 and modern design principles. -- **Afghanistan-Specific Listings:** Includes detailed information such as Province, City, and Plate details. -- **Secure Authentication:** Integrated user registration and login system. -- **Advanced Admin Dashboard:** Full control over Users, Cars, Bookings, and Reviews. +* **Car Listings:** Browse approved cars with filters (Make, Province, Price). +* **Sell Your Car:** Users can submit cars for sale (requires Admin approval). +* **Buying System:** Secure "Buy Now" flow with Bank Details capture. +* **Receipts:** Auto-generated printable receipts for sold cars. +* **Admin Dashboard:** + * Analytics (Revenue, Sales, Inventory). + * Approve/Reject Car Requests. + * Manage Users and Inventory. +* **Responsive Design:** Built with Bootstrap 5. -## 🛠️ Step-by-Step Installation +## Local Setup Instructions (XAMPP/LAMP) -1. **Database Setup:** Create a MySQL database and update `db/config.php`. -2. **Initialize:** Run `db/setup_users.php`, `db/setup_cars.php`, and `db/migrate.php` in your browser or CLI. +1. **Clone/Copy** the project files to your web server root (e.g., `htdocs` or `/var/www/html`). +2. **Database Setup:** + * Create a MySQL database named `car_dealership`. + * Import the database structure. You can run the `setup_project.php` script if available, or manually import `db/migrations/*.sql`. + * **Quick Setup:** Access `http://localhost/setup_project.php` in your browser (if deployed). +3. **Configuration:** + * Edit `db/config.php` if your DB credentials differ from the defaults (User: `root`, Pass: empty). +4. **Run the App:** + * Open `http://localhost/` in your browser. -## 🔐 Admin Credentials +## Credentials -To access the admin dashboard, go to the login page and use: +* **Admin User:** + * Username: `admin` + * Password: `123` (or `12345678` if updated manually) -- **Login (Email or Username):** `admin @gmail.com` -- **Password:** `123` +## Usage Guide -*Note: We have updated the system to allow login using the exact format you requested.* +### Selling a Car +1. Register/Login. +2. Click "Sell Your Car" in the navigation. +3. Fill out the form and upload an image. +4. Status will be "Pending" until approved by Admin. ---- +### Buying a Car +1. Login. +2. Click on a car (must be "Approved"). +3. Click "Buy Now". +4. Enter Bank Province and Account Number. +5. Confirm. You will be redirected to the Receipt. -**Site Name:** Car Sells in Afghanistan -**Version:** 2.0 (Modern Edition) \ No newline at end of file +### Admin Panel +1. Login as Admin. +2. Go to "Admin Panel" (dropdown menu). +3. **Sales Requests:** Approve newly submitted cars here. +4. **Sales History:** View all sold cars and revenue. + +## Screenshots + +*(Placeholders)* +* [Home Page] +* [Admin Dashboard] +* [Receipt] diff --git a/admin/bookings.php b/admin/bookings.php index 8d22bd3..912de7b 100644 --- a/admin/bookings.php +++ b/admin/bookings.php @@ -10,50 +10,21 @@ require_once '../db/config.php'; $pdo = db(); -// Handle booking status change -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $bookingId = filter_input(INPUT_POST, 'booking_id', FILTER_VALIDATE_INT); - $carId = filter_input(INPUT_POST, 'car_id', FILTER_VALIDATE_INT); - - if ($bookingId && $carId) { - $pdo->beginTransaction(); - try { - if (isset($_POST['approve'])) { - // Set booking to approved and car to sold - $pdo->prepare("UPDATE bookings SET status = 'approved' WHERE id = ?")->execute([$bookingId]); - $pdo->prepare("UPDATE cars SET status = 'sold' WHERE id = ?")->execute([$carId]); - } elseif (isset($_POST['cancel'])) { - // Set booking to cancelled and car back to for sale (approved) - $pdo->prepare("UPDATE bookings SET status = 'cancelled' WHERE id = ?")->execute([$bookingId]); - $pdo->prepare("UPDATE cars SET status = 'approved' WHERE id = ?")->execute([$carId]); - } - $pdo->commit(); - } catch (Exception $e) { - $pdo->rollBack(); - error_log("Booking status update failed: " . $e->getMessage()); - } - } - header("Location: bookings.php"); - exit(); -} - -// Fetch bookings with user and car details -// Removed email from selection +// Fetch sales with user and car details $bookings = $pdo->query(" - SELECT b.id, b.status, b.booking_date, u.username, c.make, c.model, c.id as car_id + SELECT b.*, u.username, c.make, c.model, c.year FROM bookings b JOIN users u ON b.user_id = u.id JOIN cars c ON b.car_id = c.id ORDER BY b.booking_date DESC ")->fetchAll(PDO::FETCH_ASSOC); -$projectName = 'Manage Bookings'; +$projectName = 'Sales History'; ?> - <?= htmlspecialchars($projectName) ?> @@ -63,62 +34,50 @@ $projectName = 'Manage Bookings';
-
-
-

Manage Bookings

-
+

Sales History

-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - -
CustomerCarBooking DateStatusActions
No bookings found.
-
-
- - - - - -
- - - - -
- - No actions - -
-
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
DateCustomerCar DetailsPriceBank DetailsStatus
No sales records found.
+
+
$ + Prov: + Acc: + + SOLD +
- + \ No newline at end of file diff --git a/admin/index.php b/admin/index.php index adb3671..560cba8 100644 --- a/admin/index.php +++ b/admin/index.php @@ -14,26 +14,16 @@ $pdo = db(); $stats = [ 'users' => $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn(), 'cars' => $pdo->query("SELECT COUNT(*) FROM cars")->fetchColumn(), - 'bookings' => $pdo->query("SELECT COUNT(*) FROM bookings WHERE status = 'approved'")->fetchColumn(), - 'pending_bookings' => $pdo->query("SELECT COUNT(*) FROM bookings WHERE status = 'pending'")->fetchColumn(), + 'sales_count' => $pdo->query("SELECT COUNT(*) FROM bookings WHERE status = 'approved'")->fetchColumn(), + 'revenue' => $pdo->query("SELECT SUM(sale_price) FROM bookings WHERE status = 'approved'")->fetchColumn(), + 'pending_requests' => $pdo->query("SELECT COUNT(*) FROM cars WHERE status = 'pending'")->fetchColumn(), ]; // Chart Data: Sales over the last 30 days -$sales_data = $pdo->query("SELECT DATE(booking_date) as date, COUNT(*) as count FROM bookings WHERE status = 'approved' AND booking_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) GROUP BY DATE(booking_date) ORDER BY date ASC")->fetchAll(PDO::FETCH_ASSOC); +$sales_data = $pdo->query("SELECT DATE(booking_date) as date, COUNT(*) as count, SUM(sale_price) as total FROM bookings WHERE status = 'approved' AND booking_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) GROUP BY DATE(booking_date) ORDER BY date ASC")->fetchAll(PDO::FETCH_ASSOC); -// Chart Data: Bookings status distribution -$bookings_status_data = $pdo->query("SELECT status, COUNT(*) as count FROM bookings GROUP BY status")->fetchAll(PDO::FETCH_ASSOC); - -// Top Selling Cars (based on approved bookings) -$top_selling_cars = $pdo->query(" - SELECT c.make, c.model, COUNT(b.id) as sales - FROM cars c - JOIN bookings b ON c.id = b.car_id - WHERE b.status = 'approved' - GROUP BY c.id, c.make, c.model - ORDER BY sales DESC - LIMIT 5 -")->fetchAll(PDO::FETCH_ASSOC); +// Chart Data: Car Status Distribution +$car_status_data = $pdo->query("SELECT status, COUNT(*) as count FROM cars GROUP BY status")->fetchAll(PDO::FETCH_ASSOC); $projectName = 'Admin Dashboard'; ?> @@ -60,37 +50,50 @@ $projectName = 'Admin Dashboard';
-

Total Users

-

Listed Cars

-

Completed Sales

-

Pending Bookings

+
+
+
Total Users
+

+
+
+
+
+
Total Revenue
+

$

+
+
+
+
+
Cars Sold
+

+
+
+
+
+
Pending Requests
+

+
+
-
Sales Over Time (Last 30 Days)
+
+
+
Sales Trend (Last 30 Days)
+ +
+
-
Bookings Distribution
-
-
- - -
-
Top 5 Selling Cars
-
-
- -
No sales data available yet.
- - -
- - sales +
+
+
Inventory Status
+
+
- - +
@@ -99,37 +102,36 @@ $projectName = 'Admin Dashboard';
diff --git a/admin/partials/sidebar.php b/admin/partials/sidebar.php index 09d5643..cae9f5f 100644 --- a/admin/partials/sidebar.php +++ b/admin/partials/sidebar.php @@ -2,36 +2,79 @@ // This is a new file: admin/partials/sidebar.php $current_page = basename($_SERVER['PHP_SELF']); ?> -