diff --git a/db/database.sql b/db/database.sql index 5e6c449..bc7444a 100644 --- a/db/database.sql +++ b/db/database.sql @@ -1,7 +1,7 @@ /*M!999999\- enable the sandbox mode */ -- MariaDB dump 10.19 Distrib 10.11.14-MariaDB, for debian-linux-gnu (x86_64) -- --- Host: localhost Database: app_38703 +-- Host: 127.0.0.1 Database: app_38703 -- ------------------------------------------------------ -- Server version 10.11.14-MariaDB-0+deb12u2 @@ -104,9 +104,14 @@ CREATE TABLE `cars` ( `is_hot_deal` tinyint(1) DEFAULT 0, `created_at` timestamp NULL DEFAULT current_timestamp(), `deleted_at` timestamp NULL DEFAULT NULL, + `reserved_by` int(11) DEFAULT NULL, + `reserved_at` timestamp NULL DEFAULT NULL, + `reservation_expires_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), - CONSTRAINT `cars_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE + KEY `fk_cars_reserved_by` (`reserved_by`), + CONSTRAINT `cars_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE, + CONSTRAINT `fk_cars_reserved_by` FOREIGN KEY (`reserved_by`) REFERENCES `users` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -117,50 +122,50 @@ CREATE TABLE `cars` ( LOCK TABLES `cars` WRITE; /*!40000 ALTER TABLE `cars` DISABLE KEYS */; INSERT INTO `cars` VALUES -(1,1,'Toyota','Land Cruiser',2023,85000.00,'Kabul','Brand new armored Land Cruiser.','approved',1,'2026-02-23 08:30:42',NULL), -(2,1,'Mercedes-Benz','G-Wagon',2022,120000.00,'Kabul','Luxury performance SUV.','approved',1,'2026-02-23 08:30:42',NULL), -(3,1,'Lexus','LX570',2021,95000.00,'Herat','Full option premium SUV.','approved',1,'2026-02-23 08:30:42',NULL), -(4,1,'Toyota','Corolla',2020,15000.00,'Mazar-i-Sharif','Reliable and fuel efficient.','approved',1,'2026-02-23 08:30:42',NULL), -(5,1,'Honda','CR-V',2023,108176.00,'Ghazni','Luxury interior, premium sound system, and smooth ride.','approved',1,'2026-02-23 08:38:51',NULL), -(6,1,'Honda','CR-V',2020,92260.00,'Kunduz','Very clean inside and out, low mileage.','approved',0,'2026-02-23 08:38:51',NULL), -(7,1,'Hyundai','Elantra',2018,106805.00,'Mazar-i-Sharif','Powerful engine, off-road capabilities, and spacious.','approved',0,'2026-02-23 08:38:51',NULL), -(8,1,'Lexus','RX350',2022,113917.00,'Jalalabad','Fuel efficient, perfect for city driving.','approved',0,'2026-02-23 08:38:51',NULL), -(9,1,'Toyota','4Runner',2019,9825.00,'Kandahar','Recently imported, custom cleared, and plate registered.','approved',0,'2026-02-23 08:38:51',NULL), -(10,1,'Ford','Mustang',2015,73007.00,'Balkh','Powerful engine, off-road capabilities, and spacious.','approved',1,'2026-02-23 08:38:51',NULL), -(11,1,'Lexus','GX460',2019,55171.00,'Kunduz','Fuel efficient, perfect for city driving.','approved',1,'2026-02-23 08:38:51',NULL), -(12,1,'Mercedes-Benz','E-Class',2021,32368.00,'Balkh','Very clean inside and out, low mileage.','approved',0,'2026-02-23 08:38:51',NULL), -(13,1,'Lexus','GX460',2016,113113.00,'Jalalabad','Top of the line model with all modern features.','approved',0,'2026-02-23 08:38:51',NULL), -(14,1,'Honda','CR-V',2024,47994.00,'Kabul','Top of the line model with all modern features.','approved',1,'2026-02-23 08:38:51',NULL), -(15,1,'BMW','X6',2023,47523.00,'Kunduz','Very clean inside and out, low mileage.','approved',0,'2026-02-23 08:38:51',NULL), -(16,1,'Lexus','LX570',2024,16004.00,'Balkh','Excellent condition, very well maintained.','approved',1,'2026-02-23 08:38:51',NULL), -(17,1,'Ford','F-150',2017,94685.00,'Mazar-i-Sharif','Very clean inside and out, low mileage.','approved',0,'2026-02-23 08:38:51',NULL), -(18,1,'Hyundai','Elantra',2018,72033.00,'Jalalabad','Very clean inside and out, low mileage.','approved',1,'2026-02-23 08:38:51',NULL), -(19,1,'Lexus','RX350',2019,22049.00,'Kabul','Powerful engine, off-road capabilities, and spacious.','approved',0,'2026-02-23 08:38:51',NULL), -(20,1,'Toyota','Corolla',2015,46604.00,'Kunduz','Very clean inside and out, low mileage.','approved',0,'2026-02-23 08:38:51',NULL), -(21,1,'Mercedes-Benz','E-Class',2022,122658.00,'Kandahar','Full option, armored, and ready for any terrain.','approved',1,'2026-02-23 08:38:51',NULL), -(22,1,'BMW','X5',2023,129562.00,'Balkh','Powerful engine, off-road capabilities, and spacious.','approved',0,'2026-02-23 08:38:51',NULL), -(23,1,'Ford','Explorer',2019,83940.00,'Kandahar','Recently imported, custom cleared, and plate registered.','approved',0,'2026-02-23 08:38:51',NULL), -(24,1,'Toyota','Hilux',2018,93171.00,'Mazar-i-Sharif','Fuel efficient, perfect for city driving.','approved',0,'2026-02-23 08:38:51',NULL), -(25,1,'Toyota','Camry',2022,25000.00,'Kabul','Excellent condition, low mileage, full options.','approved',1,'2026-02-23 09:39:14',NULL), -(26,1,'Honda','Accord',2021,22000.00,'Herat','Well maintained, fuel efficient, clean interior.','approved',0,'2026-02-23 09:39:14',NULL), -(27,1,'Ford','F-150',2023,45000.00,'Kandahar','Powerful truck, brand new, ready for heavy duty.','approved',1,'2026-02-23 09:39:14',NULL), -(28,1,'BMW','3 Series',2020,32000.00,'Mazar-i-Sharif','Luxury sedan, premium sound system, sunroof.','approved',0,'2026-02-23 09:39:14',NULL), -(29,1,'Mercedes-Benz','C-Class',2021,38000.00,'Jalalabad','Elegant design, smooth ride, advanced safety features.','approved',1,'2026-02-23 09:39:14',NULL), -(30,1,'Audi','A4',2022,35000.00,'Kabul','Quattro all-wheel drive, leather seats, virtual cockpit.','approved',0,'2026-02-23 09:39:14',NULL), -(31,1,'Tesla','Model 3',2023,40000.00,'Kabul','Electric car, long range, autopilot enabled.','approved',1,'2026-02-23 09:39:14',NULL), -(32,1,'Hyundai','Elantra',2021,18000.00,'Herat','Reliable daily driver, great gas mileage.','approved',0,'2026-02-23 09:39:14',NULL), -(33,1,'Kia','Forte',2022,19500.00,'Kandahar','Sporty look, modern technology, long warranty.','approved',0,'2026-02-23 09:39:14',NULL), -(34,1,'Mazda','3',2021,21000.00,'Mazar-i-Sharif','Fun to drive, stylish exterior, high-quality materials.','approved',0,'2026-02-23 09:39:14',NULL), -(35,1,'Volkswagen','Jetta',2020,17500.00,'Kabul','German engineering, spacious cabin, comfortable ride.','approved',0,'2026-02-23 09:39:14',NULL), -(36,1,'Chevrolet','Malibu',2022,23000.00,'Herat','Smooth performance, quiet interior, spacious trunk.','approved',0,'2026-02-23 09:39:14',NULL), -(37,1,'Nissan','Altima',2021,20000.00,'Jalalabad','All-wheel drive, comfortable seats, good fuel economy.','approved',0,'2026-02-23 09:39:14',NULL), -(38,1,'Subaru','Impreza',2022,21500.00,'Kabul','Standard AWD, great safety ratings, durable build.','approved',0,'2026-02-23 09:39:14',NULL), -(39,1,'Lexus','IS',2021,36000.00,'Kandahar','Refined luxury, excellent reliability, sharp handling.','approved',1,'2026-02-23 09:39:14',NULL), -(40,1,'Volvo','S60',2022,39000.00,'Mazar-i-Sharif','Award-winning safety, Scandinavian design, powerful engine.','approved',0,'2026-02-23 09:39:14',NULL), -(41,1,'Cadillac','CT4',2021,33000.00,'Kabul','American luxury, sporty performance, advanced tech.','approved',0,'2026-02-23 09:39:14',NULL), -(42,1,'Genesis','G70',2022,37000.00,'Herat','Premium interior, athletic handling, great value.','approved',1,'2026-02-23 09:39:14',NULL), -(43,1,'Infiniti','Q50',2020,28000.00,'Kandahar','Dynamic performance, twin-turbo engine, stylish looks.','approved',0,'2026-02-23 09:39:14',NULL), -(44,1,'Acura','TLX',2021,31000.00,'Jalalabad','Precision crafted performance, comfortable and tech-focused.','approved',0,'2026-02-23 09:39:14',NULL); +(1,1,'Toyota','Land Cruiser',2023,85000.00,'Kabul','Brand new armored Land Cruiser.','approved',1,'2026-02-23 08:30:42',NULL,NULL,NULL,NULL), +(2,1,'Mercedes-Benz','G-Wagon',2022,120000.00,'Kabul','Luxury performance SUV.','approved',1,'2026-02-23 08:30:42',NULL,NULL,NULL,NULL), +(3,1,'Lexus','LX570',2021,95000.00,'Herat','Full option premium SUV.','approved',1,'2026-02-23 08:30:42',NULL,NULL,NULL,NULL), +(4,1,'Toyota','Corolla',2020,15000.00,'Mazar-i-Sharif','Reliable and fuel efficient.','approved',1,'2026-02-23 08:30:42',NULL,NULL,NULL,NULL), +(5,1,'Honda','CR-V',2023,108176.00,'Ghazni','Luxury interior, premium sound system, and smooth ride.','approved',1,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(6,1,'Honda','CR-V',2020,92260.00,'Kunduz','Very clean inside and out, low mileage.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(7,1,'Hyundai','Elantra',2018,106805.00,'Mazar-i-Sharif','Powerful engine, off-road capabilities, and spacious.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(8,1,'Lexus','RX350',2022,113917.00,'Jalalabad','Fuel efficient, perfect for city driving.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(9,1,'Toyota','4Runner',2019,9825.00,'Kandahar','Recently imported, custom cleared, and plate registered.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(10,1,'Ford','Mustang',2015,73007.00,'Balkh','Powerful engine, off-road capabilities, and spacious.','approved',1,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(11,1,'Lexus','GX460',2019,55171.00,'Kunduz','Fuel efficient, perfect for city driving.','approved',1,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(12,1,'Mercedes-Benz','E-Class',2021,32368.00,'Balkh','Very clean inside and out, low mileage.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(13,1,'Lexus','GX460',2016,113113.00,'Jalalabad','Top of the line model with all modern features.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(14,1,'Honda','CR-V',2024,47994.00,'Kabul','Top of the line model with all modern features.','approved',1,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(15,1,'BMW','X6',2023,47523.00,'Kunduz','Very clean inside and out, low mileage.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(16,1,'Lexus','LX570',2024,16004.00,'Balkh','Excellent condition, very well maintained.','approved',1,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(17,1,'Ford','F-150',2017,94685.00,'Mazar-i-Sharif','Very clean inside and out, low mileage.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(18,1,'Hyundai','Elantra',2018,72033.00,'Jalalabad','Very clean inside and out, low mileage.','approved',1,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(19,1,'Lexus','RX350',2019,22049.00,'Kabul','Powerful engine, off-road capabilities, and spacious.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(20,1,'Toyota','Corolla',2015,46604.00,'Kunduz','Very clean inside and out, low mileage.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(21,1,'Mercedes-Benz','E-Class',2022,122658.00,'Kandahar','Full option, armored, and ready for any terrain.','approved',1,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(22,1,'BMW','X5',2023,129562.00,'Balkh','Powerful engine, off-road capabilities, and spacious.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(23,1,'Ford','Explorer',2019,83940.00,'Kandahar','Recently imported, custom cleared, and plate registered.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(24,1,'Toyota','Hilux',2018,93171.00,'Mazar-i-Sharif','Fuel efficient, perfect for city driving.','approved',0,'2026-02-23 08:38:51',NULL,NULL,NULL,NULL), +(25,1,'Toyota','Camry',2022,25000.00,'Kabul','Excellent condition, low mileage, full options.','approved',1,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(26,1,'Honda','Accord',2021,22000.00,'Herat','Well maintained, fuel efficient, clean interior.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(27,1,'Ford','F-150',2023,45000.00,'Kandahar','Powerful truck, brand new, ready for heavy duty.','approved',1,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(28,1,'BMW','3 Series',2020,32000.00,'Mazar-i-Sharif','Luxury sedan, premium sound system, sunroof.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(29,1,'Mercedes-Benz','C-Class',2021,38000.00,'Jalalabad','Elegant design, smooth ride, advanced safety features.','approved',1,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(30,1,'Audi','A4',2022,35000.00,'Kabul','Quattro all-wheel drive, leather seats, virtual cockpit.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(31,1,'Tesla','Model 3',2023,40000.00,'Kabul','Electric car, long range, autopilot enabled.','approved',1,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(32,1,'Hyundai','Elantra',2021,18000.00,'Herat','Reliable daily driver, great gas mileage.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(33,1,'Kia','Forte',2022,19500.00,'Kandahar','Sporty look, modern technology, long warranty.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(34,1,'Mazda','3',2021,21000.00,'Mazar-i-Sharif','Fun to drive, stylish exterior, high-quality materials.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(35,1,'Volkswagen','Jetta',2020,17500.00,'Kabul','German engineering, spacious cabin, comfortable ride.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(36,1,'Chevrolet','Malibu',2022,23000.00,'Herat','Smooth performance, quiet interior, spacious trunk.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(37,1,'Nissan','Altima',2021,20000.00,'Jalalabad','All-wheel drive, comfortable seats, good fuel economy.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(38,1,'Subaru','Impreza',2022,21500.00,'Kabul','Standard AWD, great safety ratings, durable build.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(39,1,'Lexus','IS',2021,36000.00,'Kandahar','Refined luxury, excellent reliability, sharp handling.','approved',1,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(40,1,'Volvo','S60',2022,39000.00,'Mazar-i-Sharif','Award-winning safety, Scandinavian design, powerful engine.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(41,1,'Cadillac','CT4',2021,33000.00,'Kabul','American luxury, sporty performance, advanced tech.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(42,1,'Genesis','G70',2022,37000.00,'Herat','Premium interior, athletic handling, great value.','approved',1,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(43,1,'Infiniti','Q50',2020,28000.00,'Kandahar','Dynamic performance, twin-turbo engine, stylish looks.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL), +(44,1,'Acura','TLX',2021,31000.00,'Jalalabad','Precision crafted performance, comfortable and tech-focused.','approved',0,'2026-02-23 09:39:14',NULL,NULL,NULL,NULL); /*!40000 ALTER TABLE `cars` ENABLE KEYS */; UNLOCK TABLES; @@ -201,6 +206,9 @@ DROP TABLE IF EXISTS `purchases`; /*!40101 SET character_set_client = utf8mb4 */; CREATE TABLE `purchases` ( `id` int(11) NOT NULL AUTO_INCREMENT, + `transaction_id` char(36) DEFAULT NULL, + `reference_number` varchar(50) DEFAULT NULL, + `verification_token` varchar(64) DEFAULT NULL, `car_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `buyer_name` varchar(100) DEFAULT NULL, @@ -208,8 +216,15 @@ CREATE TABLE `purchases` ( `buyer_phone` varchar(20) DEFAULT NULL, `bank_id` varchar(100) DEFAULT NULL, `personal_info` text DEFAULT NULL, - `status` enum('pending','completed','cancelled','approved','rejected') DEFAULT 'pending', + `status` enum('initiated','processing','paid','failed','refunded','chargeback','reserved','completed','cancelled','pending','approved','rejected') DEFAULT 'initiated', `created_at` timestamp NULL DEFAULT current_timestamp(), + `base_price` decimal(10,2) NOT NULL DEFAULT 0.00, + `marketplace_fee` decimal(10,2) NOT NULL DEFAULT 0.00, + `tax` decimal(10,2) NOT NULL DEFAULT 0.00, + `total_amount` decimal(10,2) NOT NULL DEFAULT 0.00, + `payment_method` enum('card','bank_transfer','wallet') DEFAULT NULL, + `escrow_status` enum('awaiting_verification','held_in_escrow','released','cancelled') DEFAULT 'awaiting_verification', + `expires_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), KEY `car_id` (`car_id`), KEY `user_id` (`user_id`), @@ -259,6 +274,33 @@ LOCK TABLES `reviews` WRITE; /*!40000 ALTER TABLE `reviews` ENABLE KEYS */; UNLOCK TABLES; +-- +-- Table structure for table `settings` +-- + +DROP TABLE IF EXISTS `settings`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `settings` ( + `key` varchar(50) NOT NULL, + `value` varchar(255) NOT NULL, + `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + PRIMARY KEY (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `settings` +-- + +LOCK TABLES `settings` WRITE; +/*!40000 ALTER TABLE `settings` DISABLE KEYS */; +INSERT INTO `settings` VALUES +('marketplace_fee_percentage','5','2026-02-23 15:37:03'), +('tax_percentage','10','2026-02-23 15:37:03'); +/*!40000 ALTER TABLE `settings` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Table structure for table `users` -- @@ -270,9 +312,9 @@ CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `email` varchar(100) NOT NULL, - `password` varchar(255) NOT NULL, `phone` varchar(20) DEFAULT NULL, `address` text DEFAULT NULL, + `password` varchar(255) NOT NULL, `role` enum('guest','user','admin') DEFAULT 'user', `status` enum('active','inactive') DEFAULT 'active', `created_at` timestamp NULL DEFAULT current_timestamp(), @@ -289,7 +331,7 @@ CREATE TABLE `users` ( LOCK TABLES `users` WRITE; /*!40000 ALTER TABLE `users` DISABLE KEYS */; INSERT INTO `users` VALUES -(1,'Admin','admin@gmail.com','$2y$10$JCXfZuRFtFozIdO.r40iQeueUsqIWutBjlAS/8hkL/7rVbPd2JOhu',NULL,NULL,'admin','active','2026-02-23 08:29:20',NULL); +(1,'Admin','admin@gmail.com',NULL,NULL,'$2y$10$JCXfZuRFtFozIdO.r40iQeueUsqIWutBjlAS/8hkL/7rVbPd2JOhu','admin','active','2026-02-23 08:29:20',NULL); /*!40000 ALTER TABLE `users` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -302,4 +344,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2026-02-23 9:40:16 +-- Dump completed on 2026-02-23 15:59:42 diff --git a/db/setup.php b/db/setup.php index 445fa0c..788cf83 100644 --- a/db/setup.php +++ b/db/setup.php @@ -30,9 +30,13 @@ try { description TEXT, status ENUM('pending', 'approved', 'rejected', 'sold') DEFAULT 'pending', is_hot_deal BOOLEAN DEFAULT FALSE, + reserved_by INT NULL, + reserved_at TIMESTAMP NULL, + reservation_expires_at TIMESTAMP NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, deleted_at TIMESTAMP NULL DEFAULT NULL, - FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + CONSTRAINT fk_cars_reserved_by FOREIGN KEY (reserved_by) REFERENCES users(id) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); // Car Images Table @@ -57,9 +61,12 @@ try { FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); - // Purchases (Simulation) + // Purchases Table (Enterprise Module) $pdo->exec("CREATE TABLE IF NOT EXISTS purchases ( id INT AUTO_INCREMENT PRIMARY KEY, + transaction_id CHAR(36) NULL, + reference_number VARCHAR(50) NULL, + verification_token VARCHAR(64) NULL, car_id INT NOT NULL, user_id INT NOT NULL, buyer_name VARCHAR(100), @@ -67,7 +74,14 @@ try { buyer_phone VARCHAR(20), bank_id VARCHAR(100), personal_info TEXT, - status ENUM('pending', 'completed', 'cancelled', 'approved', 'rejected') DEFAULT 'pending', + base_price DECIMAL(10,2) NOT NULL DEFAULT 0.00, + marketplace_fee DECIMAL(10,2) NOT NULL DEFAULT 0.00, + tax DECIMAL(10,2) NOT NULL DEFAULT 0.00, + total_amount DECIMAL(10,2) NOT NULL DEFAULT 0.00, + payment_method ENUM('card', 'bank_transfer', 'wallet') NULL, + escrow_status ENUM('awaiting_verification', 'held_in_escrow', 'released', 'cancelled') DEFAULT 'awaiting_verification', + expires_at TIMESTAMP NULL, + status ENUM('initiated', 'processing', 'paid', 'failed', 'refunded', 'chargeback', 'reserved', 'completed', 'cancelled', 'pending', 'approved', 'rejected') DEFAULT 'initiated', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (car_id) REFERENCES cars(id) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE @@ -84,6 +98,18 @@ try { created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); + // Settings Table + $pdo->exec("CREATE TABLE IF NOT EXISTS settings ( + `key` VARCHAR(50) PRIMARY KEY, + `value` VARCHAR(255) NOT NULL, + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); + + // Seed Settings + $pdo->exec("INSERT IGNORE INTO settings (`key`, `value`) VALUES + ('marketplace_fee_percentage', '5'), + ('tax_percentage', '10');"); + // Seed Admin User $adminEmail = 'admin@gmail.com'; $stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?"); @@ -97,4 +123,4 @@ try { echo "Database setup successfully."; } catch (PDOException $e) { die("Database error: " . $e->getMessage()); -} +} \ No newline at end of file