diff --git a/add_shipment_details.php b/add_shipment_details.php
new file mode 100644
index 0000000..3ea76d2
--- /dev/null
+++ b/add_shipment_details.php
@@ -0,0 +1,74 @@
+prepare($sql);
+ $stmt->execute([$request_id, $carrier, $tracking_number, $shipment_date]);
+
+ header('Location: service_request_details.php?id=' . $request_id);
+ exit;
+
+ } catch (PDOException $e) {
+ die("Database error: " . $e->getMessage());
+ }
+}
+
+?>
+
+
+
+
diff --git a/admin/add_dealer.php b/admin/add_dealer.php
new file mode 100644
index 0000000..3d3c979
--- /dev/null
+++ b/admin/add_dealer.php
@@ -0,0 +1,52 @@
+prepare("INSERT INTO dealers (name, email) VALUES (?, ?)");
+ if ($stmt->execute([$name, $email])) {
+ $success = 'Dealer added successfully.';
+ } else {
+ $error = 'Failed to add dealer.';
+ }
+ }
+}
+?>
+
+
+
Add Dealer
+
+
+
+
+
+
+
+
+
+
diff --git a/admin/delete_dealer.php b/admin/delete_dealer.php
new file mode 100644
index 0000000..f756694
--- /dev/null
+++ b/admin/delete_dealer.php
@@ -0,0 +1,47 @@
+prepare("DELETE FROM dealers WHERE id = ?");
+ $stmt->execute([$dealer_id]);
+ }
+ header('Location: manage_dealers.php');
+ exit;
+}
+
+$stmt = $pdo->prepare("SELECT * FROM dealers WHERE id = ?");
+$stmt->execute([$dealer_id]);
+$dealer = $stmt->fetch();
+
+if (!$dealer) {
+ header('Location: manage_dealers.php');
+ exit;
+}
+?>
+
+
+
Delete Dealer
+
Are you sure you want to delete the dealer ""?
+
+
+
+
diff --git a/admin/edit_dealer.php b/admin/edit_dealer.php
new file mode 100644
index 0000000..04a0497
--- /dev/null
+++ b/admin/edit_dealer.php
@@ -0,0 +1,68 @@
+prepare("UPDATE dealers SET name = ?, email = ? WHERE id = ?");
+ if ($stmt->execute([$name, $email, $dealer_id])) {
+ $success = 'Dealer updated successfully.';
+ } else {
+ $error = 'Failed to update dealer.';
+ }
+ }
+}
+
+$stmt = $pdo->prepare("SELECT * FROM dealers WHERE id = ?");
+$stmt->execute([$dealer_id]);
+$dealer = $stmt->fetch();
+
+if (!$dealer) {
+ header('Location: manage_dealers.php');
+ exit;
+}
+?>
+
+
+
Edit Dealer
+
+
+
+
+
+
+
+
+
+
diff --git a/admin/import_products.php b/admin/import_products.php
new file mode 100644
index 0000000..b656e39
--- /dev/null
+++ b/admin/import_products.php
@@ -0,0 +1,61 @@
+beginTransaction();
+
+ try {
+ $stmt = $pdo->prepare("INSERT INTO products (name, model_number, description, image_url, price, category_id, features, sample_type, measurement_parameters, result_speed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+
+ fgetcsv($handle); // Skip header row
+
+ while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
+ //Pad the array with nulls if it doesn't have enough elements
+ $data = array_pad($data, 10, null);
+ $stmt->execute($data);
+ }
+
+ $pdo->commit();
+ $message = "Products imported successfully.
";
+ } catch (Exception $e) {
+ $pdo->rollBack();
+ $message = "Error importing products: " . $e->getMessage() . "
";
+ }
+
+ fclose($handle);
+ } else {
+ $message = "Error opening the CSV file.
";
+ }
+}
+?>
+
+Import Products from CSV
+
+
+
+Upload a CSV file with the following columns: `name`, `model_number`, `description`, `image_url`, `price`, `category_id`, `features`, `sample_type`, `measurement_parameters`, `result_speed`.
+The `category_id` should correspond to an existing ID in the `product_categories` table.
+
+
+
+Back to Admin
+
+
diff --git a/admin/index.php b/admin/index.php
new file mode 100644
index 0000000..bd1bf7d
--- /dev/null
+++ b/admin/index.php
@@ -0,0 +1,23 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/admin/manage_dealers.php b/admin/manage_dealers.php
new file mode 100644
index 0000000..204c6b5
--- /dev/null
+++ b/admin/manage_dealers.php
@@ -0,0 +1,47 @@
+query("SELECT * FROM dealers");
+$dealers = $stmt->fetchAll();
+
+?>
+
+
+
Manage Dealers
+
Add Dealer
+
+
+
+ | ID |
+ Name |
+ Email |
+ Actions |
+
+
+
+
+
+ |
+ |
+ |
+
+ Edit
+ Delete
+ |
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/admin/reports.php b/admin/reports.php
new file mode 100644
index 0000000..6f66c23
--- /dev/null
+++ b/admin/reports.php
@@ -0,0 +1,113 @@
+query("SELECT id, name FROM dealers ORDER BY name ASC");
+$dealers = $stmt_dealers->fetchAll();
+
+// Get filter values
+$status_filter = $_GET['status'] ?? '';
+$dealer_filter = $_GET['dealer_id'] ?? '';
+
+$sql = "SELECT sr.*, p.name as product_name, d.name as dealer_name
+ FROM service_requests sr
+ JOIN products p ON sr.product_id = p.id
+ JOIN dealers d ON sr.dealer_id = d.id";
+
+$where_clauses = [];
+$params = [];
+
+if (!empty($status_filter)) {
+ $where_clauses[] = "sr.status = ?";
+ $params[] = $status_filter;
+}
+
+if (!empty($dealer_filter)) {
+ $where_clauses[] = "sr.dealer_id = ?";
+ $params[] = $dealer_filter;
+}
+
+if (!empty($where_clauses)) {
+ $sql .= " WHERE " . implode(" AND ", $where_clauses);
+}
+
+$sql .= " ORDER BY sr.created_at DESC";
+
+$stmt = $pdo->prepare($sql);
+$stmt->execute($params);
+$service_requests = $stmt->fetchAll();
+
+?>
+
+
+
Service Request Report
+
+
+
+
+
+
+ | ID |
+ Dealer |
+ Product |
+ Serial |
+ Status |
+ Date |
+
+
+
+
+
+ |
+ |
+ |
+ |
+ |
+ |
+
+
+
+
+
+
+
diff --git a/api/get_product_details.php b/api/get_product_details.php
new file mode 100644
index 0000000..19caed5
--- /dev/null
+++ b/api/get_product_details.php
@@ -0,0 +1,32 @@
+prepare(
+ "SELECT p.name, p.model_number, p.part_number, p.description, p.image_url
+ FROM products p
+ JOIN sold_serials ss ON p.id = ss.product_id
+ WHERE ss.id = ?"
+ );
+ $stmt->execute([$sold_serial_id]);
+ $product = $stmt->fetch();
+
+ if ($product) {
+ header('Content-Type: application/json');
+ echo json_encode($product);
+ } else {
+ header("HTTP/1.0 404 Not Found");
+ echo json_encode(['error' => 'Product not found']);
+ }
+ } catch (PDOException $e) {
+ header("HTTP/1.0 500 Internal Server Error");
+ echo json_encode(['error' => 'Database error: ' . $e->getMessage()]);
+ }
+} else {
+ header("HTTP/1.0 400 Bad Request");
+ echo json_encode(['error' => 'No serial ID provided']);
+}
diff --git a/assets/css/custom.css b/assets/css/custom.css
new file mode 100644
index 0000000..508e463
--- /dev/null
+++ b/assets/css/custom.css
@@ -0,0 +1,23 @@
+body {
+ background-color: #f8f9fa;
+}
+
+.navbar {
+ box-shadow: 0 2px 4px rgba(0,0,0,.1);
+}
+
+.card {
+ border-radius: 0.375rem;
+ box-shadow: 0 4px 6px rgba(0,0,0,.05);
+}
+
+.btn-primary {
+ background-color: #0d6efd;
+ border: none;
+}
+
+.footer {
+ position: absolute;
+ bottom: 0;
+ width: 100%;
+}
\ No newline at end of file
diff --git a/assets/vm-shot-2025-12-09T05-39-13-528Z.jpg b/assets/vm-shot-2025-12-09T05-39-13-528Z.jpg
new file mode 100644
index 0000000..c206cea
Binary files /dev/null and b/assets/vm-shot-2025-12-09T05-39-13-528Z.jpg differ
diff --git a/cart.php b/cart.php
new file mode 100644
index 0000000..505ef69
--- /dev/null
+++ b/cart.php
@@ -0,0 +1,180 @@
+ 0) {
+ if (isset($_SESSION['cart'][$product_id])) {
+ $_SESSION['cart'][$product_id] += $quantity;
+ } else {
+ $_SESSION['cart'][$product_id] = $quantity;
+ }
+ }
+ }
+ header('Location: products.php');
+ exit;
+
+ case 'update':
+ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['quantities'])) {
+ foreach ($_POST['quantities'] as $product_id => $quantity) {
+ $quantity = (int)$quantity;
+ if ($quantity > 0) {
+ $_SESSION['cart'][$product_id] = $quantity;
+ } else {
+ unset($_SESSION['cart'][$product_id]);
+ }
+ }
+ }
+ header('Location: cart.php');
+ exit;
+
+ case 'place_order':
+ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_SESSION['cart'])) {
+
+
+ $total_amount = 0;
+ $cart_products = [];
+
+ $product_ids = array_keys($_SESSION['cart']);
+ if (empty($product_ids)) {
+ header('Location: cart.php');
+ exit;
+ }
+
+ $sql = "SELECT * FROM products WHERE id IN (" . implode(',', array_fill(0, count($product_ids), '?')) . ")";
+ $stmt = $pdo->prepare($sql);
+ $stmt->execute($product_ids);
+ $products_array = $stmt->fetchAll(PDO::FETCH_ASSOC);
+ $products = [];
+ foreach ($products_array as $product) {
+ $products[$product['id']] = $product;
+ }
+
+ // Debug: Dump products array
+ // var_dump($products);
+
+ foreach ($_SESSION['cart'] as $product_id => $quantity) {
+ if (isset($products[$product_id])) {
+ $product = $products[$product_id];
+ $price = $product['price'] ?? 0;
+ $total_amount += $price * $quantity;
+ $cart_products[] = ['product' => $product, 'quantity' => $quantity];
+ }
+ }
+
+ // Debug: Dump total amount
+ // var_dump($total_amount);
+
+ if ($total_amount > 0) {
+ $pdo->beginTransaction();
+ try {
+ $sql = 'INSERT INTO orders (user_id, total_amount, status) VALUES (?, ?, ?)';
+ $stmt = $pdo->prepare($sql);
+ $stmt->execute([$_SESSION['user_id'], $total_amount, 'Pending']);
+ $order_id = $pdo->lastInsertId();
+
+ $sql = 'INSERT INTO order_items (order_id, product_id, quantity, price) VALUES (?, ?, ?, ?)';
+ $stmt = $pdo->prepare($sql);
+ foreach ($cart_products as $item) {
+ // Use the price from the database, not the one from the session/cart loop
+ $product_price = $products[$item['product']['id']]['price'] ?? 0;
+ $stmt->execute([$order_id, $item['product']['id'], $item['quantity'], $product_price]);
+ }
+
+ $pdo->commit();
+ $_SESSION['cart'] = [];
+ header('Location: order_details.php?id=' . $order_id);
+ exit;
+ } catch (Exception $e) {
+ $pdo->rollBack();
+ // Debug: Log exception
+ error_log($e->getMessage());
+ header('Location: cart.php?error=place_order_failed');
+ exit;
+ }
+ } else {
+ header('Location: cart.php?error=zero_total');
+ exit;
+ }
+ }
+ header('Location: cart.php');
+ exit;
+}
+
+// Display Cart
+$cart_items = [];
+$total_price = 0;
+
+if (!empty($_SESSION['cart'])) {
+ $product_ids = array_keys($_SESSION['cart']);
+ $sql = "SELECT * FROM products WHERE id IN (" . implode(',', array_fill(0, count($product_ids), '?')) . ")";
+ $stmt = $pdo->prepare($sql);
+ $stmt->execute($product_ids);
+ $products = $stmt->fetchAll();
+
+ foreach ($products as $product) {
+ $product_id = $product['id'];
+ $quantity = $_SESSION['cart'][$product_id];
+ $price = $product['price'] ?? 0;
+ $cart_items[] = ['product' => $product, 'quantity' => $quantity, 'price' => $price];
+ $total_price += $price * $quantity;
+ }
+}
+?>
+
+Shopping Cart
+
+
+ Your cart is empty.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/db/migration_001_warranty.php b/db/migration_001_warranty.php
new file mode 100644
index 0000000..565b482
--- /dev/null
+++ b/db/migration_001_warranty.php
@@ -0,0 +1,19 @@
+exec($sql);
+ echo "Table 'warranty_registrations' created successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("DB ERROR: " . $e->getMessage());
+}
+?>
\ No newline at end of file
diff --git a/db/migration_002_products.php b/db/migration_002_products.php
new file mode 100644
index 0000000..39ebf1f
--- /dev/null
+++ b/db/migration_002_products.php
@@ -0,0 +1,18 @@
+exec($sql);
+ echo "Table 'products' created successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("DB ERROR: " . $e->getMessage());
+}
diff --git a/db/migration_003_dealers.php b/db/migration_003_dealers.php
new file mode 100644
index 0000000..51ac424
--- /dev/null
+++ b/db/migration_003_dealers.php
@@ -0,0 +1,18 @@
+exec($sql);
+ echo "Table 'dealers' created successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("DB ERROR: " . $e->getMessage());
+}
diff --git a/db/migration_004_sold_serials.php b/db/migration_004_sold_serials.php
new file mode 100644
index 0000000..ebfa848
--- /dev/null
+++ b/db/migration_004_sold_serials.php
@@ -0,0 +1,22 @@
+exec($sql);
+ echo "Table 'sold_serials' created successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("DB ERROR: " . $e->getMessage());
+}
diff --git a/db/migration_005_alter_warranty.php b/db/migration_005_alter_warranty.php
new file mode 100644
index 0000000..b6125fd
--- /dev/null
+++ b/db/migration_005_alter_warranty.php
@@ -0,0 +1,22 @@
+exec($sql_add_column);
+
+ // Add foreign key constraint
+ $sql_add_fk = "ALTER TABLE warranty_registrations ADD CONSTRAINT fk_sold_serial FOREIGN KEY (sold_serial_id) REFERENCES sold_serials(id) ON DELETE SET NULL";
+ $pdo->exec($sql_add_fk);
+
+ echo "Table 'warranty_registrations' modified successfully." . PHP_EOL;
+
+} catch (PDOException $e) {
+ // Check if column already exists to avoid fatal error on re-run
+ if (strpos($e->getMessage(), 'Duplicate column name') === false) {
+ die("DB ERROR: " . $e->getMessage());
+ }
+ echo "Column 'sold_serial_id' already exists in 'warranty_registrations'." . PHP_EOL;
+}
diff --git a/db/migration_006_users.php b/db/migration_006_users.php
new file mode 100644
index 0000000..7deea75
--- /dev/null
+++ b/db/migration_006_users.php
@@ -0,0 +1,21 @@
+exec($sql);
+ echo "Migration for users table applied successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("Migration failed: " . $e->getMessage());
+}
diff --git a/db/migration_007_alter_products.php b/db/migration_007_alter_products.php
new file mode 100644
index 0000000..3574772
--- /dev/null
+++ b/db/migration_007_alter_products.php
@@ -0,0 +1,15 @@
+exec($sql);
+ echo "Migration to add description and image_url to products table applied successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("Migration failed: " . $e->getMessage());
+}
diff --git a/db/migration_008_service_requests.php b/db/migration_008_service_requests.php
new file mode 100644
index 0000000..5aa9b12
--- /dev/null
+++ b/db/migration_008_service_requests.php
@@ -0,0 +1,24 @@
+exec($sql);
+ echo "Migration for service_requests table applied successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("Migration failed: " . $e->getMessage());
+}
diff --git a/db/migration_009_service_request_comments.php b/db/migration_009_service_request_comments.php
new file mode 100644
index 0000000..0e8028a
--- /dev/null
+++ b/db/migration_009_service_request_comments.php
@@ -0,0 +1,21 @@
+exec($sql);
+ echo "Migration for service_request_comments table applied successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("Migration failed: " . $e->getMessage());
+}
diff --git a/db/migration_010_add_is_admin_to_users.php b/db/migration_010_add_is_admin_to_users.php
new file mode 100644
index 0000000..68ba199
--- /dev/null
+++ b/db/migration_010_add_is_admin_to_users.php
@@ -0,0 +1,11 @@
+exec($sql);
+ echo "Migration to add is_admin to users table applied successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("Migration failed: " . $e->getMessage());
+}
diff --git a/db/migration_011_add_file_path_to_service_requests.php b/db/migration_011_add_file_path_to_service_requests.php
new file mode 100644
index 0000000..3392ab1
--- /dev/null
+++ b/db/migration_011_add_file_path_to_service_requests.php
@@ -0,0 +1,11 @@
+exec($sql);
+ echo "Migration to add file_path to service_requests table applied successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("Migration failed: " . $e->getMessage());
+}
diff --git a/db/migration_012_create_notifications_table.php b/db/migration_012_create_notifications_table.php
new file mode 100644
index 0000000..9feb3a9
--- /dev/null
+++ b/db/migration_012_create_notifications_table.php
@@ -0,0 +1,22 @@
+exec($sql);
+ echo "Migration for notifications table applied successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("Migration failed: " . $e->getMessage());
+}
diff --git a/db/migration_013_add_user_id_to_service_requests.php b/db/migration_013_add_user_id_to_service_requests.php
new file mode 100644
index 0000000..3e15806
--- /dev/null
+++ b/db/migration_013_add_user_id_to_service_requests.php
@@ -0,0 +1,13 @@
+exec($sql);
+ $sql_fk = "ALTER TABLE service_requests ADD FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE";
+ $pdo->exec($sql_fk);
+ echo "Migration to add user_id to service_requests table applied successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("Migration failed: " . $e->getMessage());
+}
diff --git a/db/migration_014_create_product_categories.php b/db/migration_014_create_product_categories.php
new file mode 100644
index 0000000..f458534
--- /dev/null
+++ b/db/migration_014_create_product_categories.php
@@ -0,0 +1,19 @@
+exec($sql);
+ echo "Table 'product_categories' created successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("Error creating table: " . $e->getMessage());
+}
+?>
\ No newline at end of file
diff --git a/db/migration_015_alter_products_add_details.php b/db/migration_015_alter_products_add_details.php
new file mode 100644
index 0000000..5cad415
--- /dev/null
+++ b/db/migration_015_alter_products_add_details.php
@@ -0,0 +1,20 @@
+exec($sql);
+ echo "Table 'products' altered successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("Error altering table: " . $e->getMessage());
+}
+?>
\ No newline at end of file
diff --git a/db/migration_016_create_orders_table.php b/db/migration_016_create_orders_table.php
new file mode 100644
index 0000000..f23ef7e
--- /dev/null
+++ b/db/migration_016_create_orders_table.php
@@ -0,0 +1,21 @@
+exec($sql);
+ echo "Table 'orders' created successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("Error creating table: " . $e->getMessage());
+}
+?>
\ No newline at end of file
diff --git a/db/migration_017_create_order_items_table.php b/db/migration_017_create_order_items_table.php
new file mode 100644
index 0000000..92350dc
--- /dev/null
+++ b/db/migration_017_create_order_items_table.php
@@ -0,0 +1,23 @@
+exec($sql);
+ echo "Table 'order_items' created successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("Error creating table: " . $e->getMessage());
+}
+?>
\ No newline at end of file
diff --git a/db/migration_018_add_dealer_kpis.php b/db/migration_018_add_dealer_kpis.php
new file mode 100644
index 0000000..3c66cbd
--- /dev/null
+++ b/db/migration_018_add_dealer_kpis.php
@@ -0,0 +1,17 @@
+exec($sql);
+ echo "Table 'dealers' updated successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("DB ERROR: " . $e->getMessage());
+}
diff --git a/db/migration_019_add_paid_amount_to_invoices.php b/db/migration_019_add_paid_amount_to_invoices.php
new file mode 100644
index 0000000..c159ee3
--- /dev/null
+++ b/db/migration_019_add_paid_amount_to_invoices.php
@@ -0,0 +1,14 @@
+exec($sql);
+ echo "Table 'invoices' updated successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("DB ERROR: " . $e->getMessage());
+}
diff --git a/db/migration_020_add_dealer_id_to_orders.php b/db/migration_020_add_dealer_id_to_orders.php
new file mode 100644
index 0000000..5b8e096
--- /dev/null
+++ b/db/migration_020_add_dealer_id_to_orders.php
@@ -0,0 +1,38 @@
+exec("SET FOREIGN_KEY_CHECKS=0;");
+
+ $sql = <<exec($sql);
+
+ $sql_update = <<exec($sql_update);
+
+ $sql_alter = <<exec($sql_alter);
+
+ $sql_fk = <<exec($sql_fk);
+
+ $pdo->exec("SET FOREIGN_KEY_CHECKS=1;");
+
+ echo "Table 'orders' updated successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("DB ERROR: " . $e->getMessage());
+}
diff --git a/db/migration_021_fix_orders_dealer_id.php b/db/migration_021_fix_orders_dealer_id.php
new file mode 100644
index 0000000..8ff1bee
--- /dev/null
+++ b/db/migration_021_fix_orders_dealer_id.php
@@ -0,0 +1,26 @@
+exec("SET FOREIGN_KEY_CHECKS=0;");
+
+ $sql_update = <<exec($sql_update);
+
+ $sql_fk = <<exec($sql_fk);
+
+ $pdo->exec("SET FOREIGN_KEY_CHECKS=1;");
+
+ echo "Table 'orders' fixed successfully." . PHP_EOL;
+} catch (PDOException $e) {
+ die("DB ERROR: " . $e->getMessage());
+}
diff --git a/db/seed_data.php b/db/seed_data.php
new file mode 100644
index 0000000..7bfc366
--- /dev/null
+++ b/db/seed_data.php
@@ -0,0 +1,74 @@
+exec("SET FOREIGN_KEY_CHECKS = 0;");
+ $pdo->exec("TRUNCATE TABLE order_items;");
+ $pdo->exec("TRUNCATE TABLE orders;");
+ $pdo->exec("TRUNCATE TABLE notifications;");
+ $pdo->exec("TRUNCATE TABLE service_request_comments;");
+ $pdo->exec("TRUNCATE TABLE service_requests;");
+ $pdo->exec("TRUNCATE TABLE sold_serials;");
+ $pdo->exec("TRUNCATE TABLE warranty_registrations;");
+ $pdo->exec("TRUNCATE TABLE users;");
+ $pdo->exec("TRUNCATE TABLE dealers;");
+ $pdo->exec("TRUNCATE TABLE products;");
+ $pdo->exec("TRUNCATE TABLE product_categories;");
+ $pdo->exec("SET FOREIGN_KEY_CHECKS = 1;");
+
+ echo "Tables truncated successfully.\n";
+
+ // Seed Dealers
+ $dealers = [
+ ['Dealer One', 'contact1@dealerone.com'],
+ ['Dealer Two', 'contact2@dealertwo.com'],
+ ];
+ $stmt = $pdo->prepare("INSERT INTO dealers (name, email) VALUES (?, ?)");
+ foreach ($dealers as $dealer) {
+ $stmt->execute($dealer);
+ }
+ echo "Dealers seeded successfully.\n";
+
+ // Get Dealer One ID
+ $stmt = $pdo->prepare("SELECT id FROM dealers WHERE name = ?");
+ $stmt->execute(['Dealer One']);
+ $dealer1_id = $stmt->fetchColumn();
+
+ // Seed Users
+ $users = [
+ ['dealer', password_hash('password', PASSWORD_DEFAULT), $dealer1_id, 0],
+ ['admin', password_hash('admin', PASSWORD_DEFAULT), null, 1],
+ ];
+ $stmt = $pdo->prepare("INSERT INTO users (username, password_hash, dealer_id, is_admin) VALUES (?, ?, ?, ?)");
+ foreach ($users as $user) {
+ $stmt->execute($user);
+ }
+ echo "Users seeded successfully.\n";
+
+ // Seed Product Categories
+ $categories = ['Analyzers', 'Reagents', 'Consumables'];
+ $stmt = $pdo->prepare("INSERT INTO product_categories (name) VALUES (?)");
+ foreach ($categories as $category) {
+ $stmt->execute([$category]);
+ }
+ echo "Product categories seeded successfully.\n";
+
+ // Seed Products
+ $products = [
+ ['Sensa-100 Analyzer', 'SENSA-100', 'Advanced blood gas analyzer.', 'assets/images/products/sensa-100.jpg', 1, 15000.00, 'features of Sensa-100'],
+ ['Sensa-200 Electrolyte Analyzer', 'SENSA-200', 'Automated electrolyte analysis.', 'assets/images/products/sensa-200.jpg', 1, 25000.00, 'features of Sensa-200'],
+ ['Blood Gas Reagent Kit', 'REAGENT-BG', 'Reagent kit for Sensa-100.', 'assets/images/products/reagent-bg.jpg', 2, 500.00, 'features of Reagent-BG'],
+ ['Replacement Electrode', 'CONSUME-ELECTRODE', 'Replacement electrode for analyzers.', 'assets/images/products/electrode.jpg', 3, 250.00, 'features of Electrode']
+ ];
+ $stmt = $pdo->prepare("INSERT INTO products (name, model_number, description, image_url, category_id, price, features) VALUES (?, ?, ?, ?, ?, ?, ?)");
+ foreach ($products as $product) {
+ $stmt->execute($product);
+ }
+ echo "Products seeded successfully.\n";
+
+} catch (PDOException $e) {
+ die("DB ERROR: " . $e->getMessage());
+}
diff --git a/db/seed_invoices.php b/db/seed_invoices.php
new file mode 100644
index 0000000..26e00c7
--- /dev/null
+++ b/db/seed_invoices.php
@@ -0,0 +1,59 @@
+query("SELECT id, dealer_id FROM users WHERE dealer_id IS NOT NULL AND dealer_id != 0 LIMIT 1");
+ $user = $stmt->fetch();
+
+ if (!$user) {
+ // Create a dealer
+ $stmt = $pdo->prepare("INSERT INTO dealers (name, email) VALUES (?, ?)");
+ $stmt->execute(['Dummy Dealer', 'dummy@dealer.com']);
+ $dealer_id = $pdo->lastInsertId();
+
+ // Create a user
+ $stmt = $pdo->prepare("INSERT INTO users (dealer_id, username, password_hash) VALUES (?, ?, ?)");
+ $stmt->execute([$dealer_id, 'dummyuser', password_hash('password', PASSWORD_DEFAULT)]);
+ $user_id = $pdo->lastInsertId();
+ } else {
+ $user_id = $user['id'];
+ $dealer_id = $user['dealer_id'];
+ }
+
+ // Check for orders
+ $stmt = $pdo->prepare("SELECT id FROM orders WHERE user_id = ? LIMIT 5");
+ $stmt->execute([$user_id]);
+ $orders = $stmt->fetchAll(PDO::FETCH_COLUMN);
+
+ if (count($orders) < 5) {
+ // Create some orders if there aren't enough
+ $stmt = $pdo->prepare("INSERT INTO orders (user_id, dealer_id, total_amount, status) VALUES (?, ?, ?, ?)");
+ for ($i = 0; $i < 5; $i++) {
+ $total_amount = rand(100, 1000);
+ $stmt->execute([$user_id, $dealer_id, $total_amount, 'Completed']);
+ }
+ $stmt = $pdo->prepare("SELECT id FROM orders WHERE user_id = ? LIMIT 5");
+ $stmt->execute([$user_id]);
+ $orders = $stmt->fetchAll(PDO::FETCH_COLUMN);
+ }
+
+ $stmt = $pdo->prepare("INSERT INTO invoices (dealer_id, order_id, invoice_date, due_date, total_amount, status, paid_amount) VALUES (?, ?, ?, ?, ?, ?, ?)");
+
+ foreach ($orders as $order_id) {
+ $invoice_date = date('Y-m-d', strtotime('-' . rand(1, 30) . ' days'));
+ $due_date = date('Y-m-d', strtotime($invoice_date . ' +30 days'));
+ $total_amount = rand(100, 1000);
+ $paid_amount = rand(0, $total_amount);
+ $status = ($paid_amount == $total_amount) ? 'paid' : 'pending';
+
+ $stmt->execute([$dealer_id, $order_id, $invoice_date, $due_date, $total_amount, $status, $paid_amount]);
+ }
+
+ echo "Dummy invoices created successfully." . PHP_EOL;
+
+} catch (PDOException $e) {
+ die("DB ERROR: " . $e->getMessage());
+}
\ No newline at end of file
diff --git a/delete_shipment_details.php b/delete_shipment_details.php
new file mode 100644
index 0000000..5085278
--- /dev/null
+++ b/delete_shipment_details.php
@@ -0,0 +1,36 @@
+prepare("SELECT service_request_id FROM shipment_details WHERE id = ?");
+ $stmt_get_id->execute([$shipment_id]);
+ $service_request_id = $stmt_get_id->fetchColumn();
+
+ if ($service_request_id) {
+ $stmt_delete = $pdo->prepare("DELETE FROM shipment_details WHERE id = ?");
+ $stmt_delete->execute([$shipment_id]);
+ header("Location: service_request_details.php?id=$service_request_id");
+ } else {
+ header('Location: service_requests.php');
+ }
+ exit;
+
+} catch (PDOException $e) {
+ die("Database error: " . $e->getMessage());
+}
diff --git a/edit_shipment_details.php b/edit_shipment_details.php
new file mode 100644
index 0000000..cca2574
--- /dev/null
+++ b/edit_shipment_details.php
@@ -0,0 +1,87 @@
+prepare("SELECT * FROM shipment_details WHERE id = ?");
+ $stmt->execute([$shipment_id]);
+ $shipment = $stmt->fetch();
+
+ if (!$shipment) {
+ header('Location: service_requests.php');
+ exit;
+ }
+
+ $service_request_id = $shipment['service_request_id'];
+
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ $carrier = trim($_POST['carrier']);
+ $tracking_number = trim($_POST['tracking_number']);
+ $shipment_date = trim($_POST['shipment_date']);
+
+ if (empty($carrier) || empty($tracking_number) || empty($shipment_date)) {
+ $error_message = "All fields are required.";
+ } else {
+ $stmt_update = $pdo->prepare(
+ "UPDATE shipment_details SET carrier = ?, tracking_number = ?, shipment_date = ? WHERE id = ?"
+ );
+ $stmt_update->execute([$carrier, $tracking_number, $shipment_date, $shipment_id]);
+
+ header("Location: service_request_details.php?id=$service_request_id");
+ exit;
+ }
+ }
+} catch (PDOException $e) {
+ die("Database error: " . $e->getMessage());
+}
+?>
+
+
+
+
diff --git a/includes/footer.php b/includes/footer.php
new file mode 100644
index 0000000..68fbc16
--- /dev/null
+++ b/includes/footer.php
@@ -0,0 +1,11 @@
+
+
+
+
+
+