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()); + } +} + +?> + +
+
+
+
+

Add Shipment Details

+
+
+
+ +
+ + +
+
+ + +
+
+ + +
+ + Cancel +
+
+
+
+
+ + 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 ""?

+
+ + No, Cancel +
+
+ + 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 @@ + + +
+

Admin Panel

+

Welcome to the admin panel. Here you can manage users, products, and other settings.

+ Manage Dealers + Reports + Import Products +
+ + \ 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 + + + + + + + + + + + + + + + + + + + +
IDNameEmailActions
+ 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

+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
IDDealerProductSerialStatusDate
+
+ + 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.
+ +
+ + + + + + + + + + + + + + + + + + + +
ProductPriceQuantityTotal
$ + + $
+
+ +

Total: $

+
+
+
+ +
+ + + \ 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()); +} +?> + +
+
+
+
+

Edit Shipment Details

+
+
+ + + +
+
+ + +
+
+ + +
+
+ + +
+ + Cancel +
+
+
+
+
+ + 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 @@ + + +
+
+ © 2025 Sensa Core. All rights reserved. +
+
+ + + + \ No newline at end of file diff --git a/includes/header.php b/includes/header.php new file mode 100644 index 0000000..c49265b --- /dev/null +++ b/includes/header.php @@ -0,0 +1,100 @@ + + + + + + + Sensa Core Dealer Portal + + + + + + + + +
diff --git a/index.php b/index.php index 7205f3d..0a96ed4 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,114 @@ prepare("SELECT COUNT(*) FROM service_requests WHERE dealer_id = ? AND status = 'pending'"); + $stmt_pending_requests->execute([$dealer_id]); + $pending_requests_count = $stmt_pending_requests->fetchColumn(); + + // Fetch unactivated warranties + $stmt_unactivated_warranties = $pdo->prepare("SELECT COUNT(*) FROM sold_serials WHERE dealer_id = ? AND is_activated = FALSE"); + $stmt_unactivated_warranties->execute([$dealer_id]); + $unactivated_warranties_count = $stmt_unactivated_warranties->fetchColumn(); + + // Fetch total products + $stmt_products = $pdo->query("SELECT COUNT(*) FROM products"); + $products_count = $stmt_products->fetchColumn(); + +} catch (PDOException $e) { + // For simplicity, we'll just display 0 if there's a db error. + $pending_requests_count = 0; + $unactivated_warranties_count = 0; + $products_count = 0; + $open_invoices_count = 0; + $total_due = 0; +} + +// Fetch open invoices summary +try { + $user_id = $_SESSION['user_id']; + $is_admin = $_SESSION['is_admin'] ?? false; + + $sql = "SELECT COUNT(*) as count, SUM(total_amount) as total FROM invoices WHERE status = 'open'"; + $params = []; + + if (!$is_admin) { + $sql .= " AND dealer_id = ?"; + $params[] = $user_id; + } + + $stmt_invoices = $pdo->prepare($sql); + $stmt_invoices->execute($params); + $invoices_summary = $stmt_invoices->fetch(); + $open_invoices_count = $invoices_summary['count'] ?? 0; + $total_due = $invoices_summary['total'] ?? 0; +} catch (PDOException $e) { + $open_invoices_count = 0; + $total_due = 0; +} -$phpVersion = PHP_VERSION; -$now = date('Y-m-d H:i:s'); ?> - - - - - - New Style - - - - - - - - - - - - - - - - - - - - - -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+ +
+
+
+
+
Pending Service Requests
+

+ View Details +
+
-
-
- Page updated: (UTC) -
- - +
+
+
+
Unactivated Warranties
+

+ Register Now +
+
+
+
+
+
+
Total Products
+

+ Browse Catalog +
+
+
+
+
+
+
Open Invoices
+

+

Total Due: $

+ View Invoices +
+
+
+
+ + +
+
+

Sensa Core Dealer Portal

+

Welcome to the central hub for sales, service, and finance operations. Manage your orders, register warranties, and track service requests all in one place.

+
+
+ + + \ No newline at end of file diff --git a/invoice_details.php b/invoice_details.php new file mode 100644 index 0000000..5c48dac --- /dev/null +++ b/invoice_details.php @@ -0,0 +1,105 @@ +prepare($sql); + $stmt->execute([$invoice_id]); + $invoice = $stmt->fetch(); + + if (!$invoice) { + die('Invoice not found.'); + } + +} catch (PDOException $e) { + die("Database error: " . $e->getMessage()); +} +?> + +

Invoice Details #

+ +
+
Invoice Information
+
+

Invoice ID:

+

Order ID:

+

Invoice Date:

+

Due Date:

+

Total Amount: $

+

Status:

+
+
+ +
+
Payments
+
+ + + + + + + + + + prepare($sql); + $stmt->execute([$invoice_id]); + $payments = $stmt->fetchAll(); + $total_paid = 0; + foreach ($payments as $payment) { + $total_paid += $payment['amount']; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + ?> + +
Payment DateAmountPayment Method
' . htmlspecialchars($payment['payment_date']) . '$' . htmlspecialchars(number_format($payment['amount'], 2)) . '' . htmlspecialchars($payment['payment_method']) . '
+

Total Paid: $

+

Amount Due: $

+
+
+ + +
+
Post a Payment
+
+
+ +
+ + +
+
+ + +
+ +
+
+
+ + + \ No newline at end of file diff --git a/invoices.php b/invoices.php new file mode 100644 index 0000000..bccaa73 --- /dev/null +++ b/invoices.php @@ -0,0 +1,80 @@ +prepare($sql); + $stmt->execute($params); + $invoices = $stmt->fetchAll(); + +} catch (PDOException $e) { + die("Database error: " . $e->getMessage()); +} +?> + +

Invoices

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Invoice IDOrder IDInvoice DateDue DateTotal AmountPaid AmountBalanceAge of InvoiceStatusActions
$$$diff($invoice_date)->days; + echo $age . ' days'; + ?> + View Details +
+ + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..0870a7a --- /dev/null +++ b/login.php @@ -0,0 +1,58 @@ +prepare("SELECT * FROM users WHERE username = ?"); + $stmt->execute([$username]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password_hash'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['dealer_id'] = $user['dealer_id']; + $_SESSION['is_admin'] = $user['is_admin']; + header('Location: index.php'); + exit; + } else { + $error = 'Invalid username or password.'; + } + } +} +?> + +
+
+
+
+
+

Dealer Login

+ +
+ +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+ + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..95db42c --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ +prepare("UPDATE notifications SET is_read = 1 WHERE user_id = ?"); + $stmt->execute([$user_id]); + header('Location: notifications.php'); + exit; +} + +$stmt = $pdo->prepare("SELECT * FROM notifications WHERE user_id = ? ORDER BY created_at DESC"); +$stmt->execute([$user_id]); +$notifications = $stmt->fetchAll(); + +?> + +
+

Notifications

+
+ +
+
    + +
  • + +

    + +
    +
  • + + +
  • You have no notifications.
  • + +
+
+ + diff --git a/order_details.php b/order_details.php new file mode 100644 index 0000000..b794ff8 --- /dev/null +++ b/order_details.php @@ -0,0 +1,78 @@ +prepare($sql); +$stmt->execute([$order_id, $_SESSION['user_id']]); +$order = $stmt->fetch(); + +if (!$order) { + header('Location: orders.php'); + exit; +} + +// Fetch order items +$sql = " + SELECT oi.*, p.name as product_name + FROM order_items oi + JOIN products p ON oi.product_id = p.id + WHERE oi.order_id = ? +"; +$stmt = $pdo->prepare($sql); +$stmt->execute([$order_id]); +$order_items = $stmt->fetchAll(); + +?> + +

Order Details #

+ +
+
+
Order Summary
+

Total Amount: $

+

Status:

+

Date:

+
+
+ +

Items in this Order

+ + + + + + + + + + + + + + + + + + + + +
ProductQuantityPriceTotal
$$
+ +Back to Orders + + diff --git a/orders.php b/orders.php new file mode 100644 index 0000000..1a8abfb --- /dev/null +++ b/orders.php @@ -0,0 +1,72 @@ +prepare($sql); +$stmt->execute($params); +$orders = $stmt->fetchAll(); + +?> + +

My Orders

+ + + + +
+ You have no orders with the status ''. +
+ + + + + + + + + + + + + + + + + + + + + + +
Order IDTotal AmountStatusDate
#$View Details
+ + + diff --git a/post_payment.php b/post_payment.php new file mode 100644 index 0000000..bb666ca --- /dev/null +++ b/post_payment.php @@ -0,0 +1,46 @@ +prepare($sql); + $stmt->execute([$invoice_id, $payment_date, $amount, $payment_method]); + + // Update invoice status if fully paid + $sql = "SELECT i.total_amount, SUM(p.amount) as total_paid FROM invoices i LEFT JOIN payments p ON i.id = p.invoice_id WHERE i.id = ? GROUP BY i.id"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$invoice_id]); + $invoice_data = $stmt->fetch(); + + if ($invoice_data['total_paid'] >= $invoice_data['total_amount']) { + $sql = "UPDATE invoices SET status = 'paid' WHERE id = ?"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$invoice_id]); + } + + header('Location: invoice_details.php?id=' . $invoice_id); + exit; + + } catch (PDOException $e) { + die("Database error: " . $e->getMessage()); + } +} else { + header('Location: invoices.php'); + exit; +} +?> \ No newline at end of file diff --git a/products.php b/products.php new file mode 100644 index 0000000..0dd3884 --- /dev/null +++ b/products.php @@ -0,0 +1,122 @@ +query("SELECT * FROM product_categories ORDER BY name ASC"); + $categories = $category_stmt->fetchAll(); + + // Get filter parameters + $search = $_GET['search'] ?? ''; + $selected_category = $_GET['category'] ?? ''; + + // Build product query + $sql = "SELECT p.*, c.name AS category_name FROM products p LEFT JOIN product_categories c ON p.category_id = c.id"; + $params = []; + $where_clauses = []; + + if ($search) { + $where_clauses[] = "(p.name LIKE ? OR p.model_number LIKE ?)"; + $params[] = '%' . $search . '%'; + $params[] = '%' . $search . '%'; + } + + if ($selected_category) { + $where_clauses[] = "p.category_id = ?"; + $params[] = $selected_category; + } + + if (!empty($where_clauses)) { + $sql .= " WHERE " . implode(" AND ", $where_clauses); + } + + $sql .= " ORDER BY p.name ASC"; + + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + $products = $stmt->fetchAll(); + +} catch (PDOException $e) { + die("Database error: " . $e->getMessage()); +} +?> + +

Product Catalog

+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+

No products found.

+
+ + +
+
+ <?php echo htmlspecialchars($product['name']); ?> +
+
+

Price: $

+
Model:
+ +
Category:
+ +

+ + +

Features:

+ + +

Sample Type:

+ + +

Parameters:

+ + +

Result Speed:

+ +
+
+ +
+ + +
+
+
+
+
+
+ + +
+ + diff --git a/profile.php b/profile.php new file mode 100644 index 0000000..618fe01 --- /dev/null +++ b/profile.php @@ -0,0 +1,95 @@ +prepare("SELECT password_hash FROM users WHERE id = ?"); + $stmt->execute([$user_id]); + $user = $stmt->fetch(); + + if ($user && password_verify($current_password, $user['password_hash'])) { + $password_hash = password_hash($new_password, PASSWORD_DEFAULT); + $stmt = $pdo->prepare("UPDATE users SET password_hash = ? WHERE id = ?"); + if ($stmt->execute([$password_hash, $user_id])) { + $success = 'Password updated successfully.'; + } else { + $error = 'Failed to update password.'; + } + } else { + $error = 'Incorrect current password.'; + } + } +} + +$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?"); +$stmt->execute([$user_id]); +$user = $stmt->fetch(); + +?> + +
+

Profile

+
+
+
Your Information
+

Username:

+ + prepare("SELECT * FROM dealers WHERE id = ?"); + $stmt_dealer->execute([$user['dealer_id']]); + $dealer = $stmt_dealer->fetch(); + ?> +

Dealer:

+

Email:

+ +
+
+ +
+
+
Change Password
+ +
+ + +
+ +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+ + diff --git a/service_request_details.php b/service_request_details.php new file mode 100644 index 0000000..5850fdb --- /dev/null +++ b/service_request_details.php @@ -0,0 +1,249 @@ +prepare( + "SELECT sr.* + FROM service_requests sr + WHERE sr.id = ? AND (sr.dealer_id = ? OR ?)" + ); + $stmt->execute([$request_id, $dealer_id, $_SESSION['is_admin']]); + $request = $stmt->fetch(); + + if (!$request) { + // Request not found or doesn't belong to the dealer + header('Location: service_requests.php'); + exit; + } + + // Fetch service request items + $stmt_items = $pdo->prepare( + "SELECT sri.serial_number, sri.issue_description, p.name as product_name + FROM service_request_items sri + JOIN products p ON sri.product_id = p.id + WHERE sri.service_request_id = ?" + ); + $stmt_items->execute([$request_id]); + $request_items = $stmt_items->fetchAll(); + + + // Handle comment submission + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['comment'])) { + $comment = trim($_POST['comment']); + if (!empty($comment)) { + $stmt_insert_comment = $pdo->prepare( + "INSERT INTO service_request_comments (service_request_id, user_id, comment) VALUES (?, ?, ?)" + ); + $stmt_insert_comment->execute([$request_id, $_SESSION['user_id'], $comment]); + + // Create a notification + $current_user_id = $_SESSION['user_id']; + $request_owner_id = $request['user_id']; + + $message = "A new comment has been added to your service request #{$request_id}."; + + if ($current_user_id != $request_owner_id) { + // Notify the request owner + $stmt_notify = $pdo->prepare("INSERT INTO notifications (user_id, service_request_id, message) VALUES (?, ?, ?)"); + $stmt_notify->execute([$request_owner_id, $request_id, $message]); + } else { + // Notify all admins + $stmt_admins = $pdo->query("SELECT id FROM users WHERE is_admin = 1"); + $admins = $stmt_admins->fetchAll(PDO::FETCH_COLUMN); + $stmt_notify = $pdo->prepare("INSERT INTO notifications (user_id, service_request_id, message) VALUES (?, ?, ?)"); + foreach ($admins as $admin_id) { + if($admin_id != $current_user_id) { + $stmt_notify->execute([$admin_id, $request_id, $message]); + } + } + } + + // Redirect to the same page to prevent form resubmission + header("Location: service_request_details.php?id=$request_id"); + exit; + } + } + + // Fetch comments for the service request + $stmt_comments = $pdo->prepare( + "SELECT c.*, u.username + FROM service_request_comments c + JOIN users u ON c.user_id = u.id + WHERE c.service_request_id = ? + ORDER BY c.created_at ASC" + ); + $stmt_comments->execute([$request_id]); + $comments = $stmt_comments->fetchAll(); + +} catch (PDOException $e) { + die("Database error: " . $e->getMessage()); +} + +?> + + + +

Service Request Details

+ +
+
+
Request #
+ +
+
+
+
+

Submitted At:

+

Last Updated:

+
+
+
+
Products
+ + + + + + + + + + + + + + + + + +
Product NameSerial NumberIssue Description
+ +
+
Attached File
+

View Attached File

+ + + +
+
Update Status
+
+ +
+ + +
+
+ +
+
+ +
+
+
Shipment Details
+
+
+ prepare("SELECT * FROM shipment_details WHERE service_request_id = ?"); + $stmt_shipment->execute([$request_id]); + $shipments = $stmt_shipment->fetchAll(); + ?> + +

No shipment details available.

+ +

Only administrators and dealers can add shipment details.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
CarrierTracking NumberShipment DateActions
+ Edit + Delete +
+ + +
+ + Add Shipment + +
+
+
+ +
+
+
Comments
+
+
+ +
+
+ +
+
+
+ +
+
+
+ + +

No comments yet.

+ +
+ +
+ + diff --git a/service_requests.php b/service_requests.php new file mode 100644 index 0000000..092ddc6 --- /dev/null +++ b/service_requests.php @@ -0,0 +1,227 @@ +query("SELECT id, name, model_number FROM products ORDER BY name ASC"); + $products = $stmt_products->fetchAll(); + + // Handle form submission + if ($_SERVER["REQUEST_METHOD"] == "POST") { + $submitted_products = $_POST['products'] ?? []; + $file_path = null; + + if (isset($_FILES['file_upload']) && $_FILES['file_upload']['error'] == UPLOAD_ERR_OK) { + $upload_dir = __DIR__ . '/uploads/'; + if (!is_dir($upload_dir)) { + mkdir($upload_dir, 0777, true); + } + + $file_name = uniqid('file_') . '_' . basename($_FILES['file_upload']['name']); + $target_file = $upload_dir . $file_name; + + if (move_uploaded_file($_FILES['file_upload']['tmp_name'], $target_file)) { + $file_path = 'uploads/' . $file_name; + } else { + $error_message = "Sorry, there was an error uploading your file."; + } + } + + if (empty($submitted_products)) { + $error_message = "Please add at least one product and provide an issue description."; + } else { + try { + $pdo->beginTransaction(); + + // Create the main service request + $sql_request = "INSERT INTO service_requests (dealer_id, user_id, file_path) VALUES (?, ?, ?)"; + $stmt_request = $pdo->prepare($sql_request); + $stmt_request->execute([$dealer_id, $_SESSION['user_id'], $file_path]); + $service_request_id = $pdo->lastInsertId(); + + // Add each product to the service_request_items table + $sql_item = "INSERT INTO service_request_items (service_request_id, product_id, serial_number, issue_description) VALUES (?, ?, ?, ?)"; + $stmt_item = $pdo->prepare($sql_item); + + foreach ($submitted_products as $product_data) { + $product_id = trim($product_data['product_id']); + $serial_number = trim($product_data['serial_number']); + $issue_description = trim($product_data['issue_description']); + if (!empty($product_id) && !empty($serial_number) && !empty($issue_description)) { + $stmt_item->execute([$service_request_id, $product_id, $serial_number, $issue_description]); + } + } + + $pdo->commit(); + $success_message = "Service request submitted successfully!"; + + } catch (PDOException $e) { + $pdo->rollBack(); + $error_message = "Failed to submit service request: " . $e->getMessage(); + } + } + } + + // Fetch existing service requests for the dealer + $stmt_requests = $pdo->prepare( + "SELECT sr.id, sr.status, sr.created_at, + GROUP_CONCAT(p.name SEPARATOR ', ') as product_names, + GROUP_CONCAT(sri.serial_number SEPARATOR ', ') as serial_numbers + FROM service_requests sr + LEFT JOIN service_request_items sri ON sr.id = sri.service_request_id + LEFT JOIN products p ON sri.product_id = p.id + WHERE sr.dealer_id = ? + GROUP BY sr.id + ORDER BY sr.created_at DESC" + ); + $stmt_requests->execute([$dealer_id]); + $service_requests = $stmt_requests->fetchAll(); + +} catch (PDOException $e) { + $error_message = "Database error: " . $e->getMessage(); +} + +?> + +
+
+
+
+

Submit a Service Request

+
+
+ +
+ + +
+ + +
+
+
+
+
+ + +
+
+ + +
+
+
+ + +
+
+
+ + +
+ + +
+ +
+
+
+
+
+
+
+

Your Service Requests

+
+
+ +

You have not submitted any service requests yet.

+ + + + + + + + + + + + + + + + + + + + + + + + +
Request IDProductsSerialsStatusDateActions
+ View Details +
+ +
+
+
+
+ + + + diff --git a/targets.php b/targets.php new file mode 100644 index 0000000..a34d3e8 --- /dev/null +++ b/targets.php @@ -0,0 +1,74 @@ +No dealer ID found in session."; + include_once 'includes/footer.php'; + exit(); +} + +$pdo = db(); +$stmt = $pdo->prepare("SELECT * FROM dealers WHERE id = ?"); +$stmt->execute([$dealer_id]); +$dealer = $stmt->fetch(); + +if (!$dealer) { + echo "
Dealer not found.
"; + include_once 'includes/footer.php'; + exit(); +} + +$target = $dealer['target'] ?? 0; +$achievement = $dealer['achievement'] ?? 0; +$credit_limit = $dealer['credit_limit'] ?? 0; +$credit_limit_utilisation = $dealer['credit_limit_utilisation'] ?? 0; + +$achievement_percentage = $target > 0 ? ($achievement / $target) * 100 : 0; +$credit_utilisation_percentage = $credit_limit > 0 ? ($credit_limit_utilisation / $credit_limit) * 100 : 0; +?> + +
+

Targets and Achievements

+
+
+
Targets
+

Your sales target for the current quarter is: $

+
+
+
+
+
Achievements
+

Your sales so far this quarter: $

+
+
%
+
+
+
+
+
+
Credit Limit
+

Your credit limit is: $

+
+
+
+
+
Credit Limit Utilisation
+

You have used: $

+
+
%
+
+
+
+
+ + \ No newline at end of file diff --git a/update_service_request_status.php b/update_service_request_status.php new file mode 100644 index 0000000..eb8d558 --- /dev/null +++ b/update_service_request_status.php @@ -0,0 +1,30 @@ +prepare($sql); + $stmt->execute([$status, $request_id]); + + header('Location: service_request_details.php?id=' . $request_id); + exit; + + } catch (PDOException $e) { + die("Database error: " . $e->getMessage()); + } +} else { + header('Location: service_requests.php'); + exit; +} +?> \ No newline at end of file diff --git a/warranty_registration.php b/warranty_registration.php new file mode 100644 index 0000000..012b932 --- /dev/null +++ b/warranty_registration.php @@ -0,0 +1,226 @@ +prepare( + "SELECT ss.id, ss.serial_number, p.name as product_name + FROM sold_serials ss + JOIN products p ON ss.product_id = p.id + WHERE ss.dealer_id = ? AND ss.is_activated = FALSE" + ); + $stmt->execute([$dealer_id]); + $unactivated_serials = $stmt->fetchAll(); + +} catch (PDOException $e) { + die("Database error: " . $e->getMessage()); +} + +$success_message = ''; +$error_message = ''; + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $sold_serial_id = trim($_POST['sold_serial_id']); + $end_customer_name = trim($_POST['end_customer_name']); + $end_customer_address = trim($_POST['end_customer_address']); + $dealer_invoice_date = trim($_POST['dealer_invoice_date']); + $dealer_invoice_no = trim($_POST['dealer_invoice_no']); + $installation_date = trim($_POST['installation_date']); + + if (empty($sold_serial_id) || empty($end_customer_name) || empty($end_customer_address) || empty($dealer_invoice_date) || empty($dealer_invoice_no) || empty($installation_date)) { + $error_message = "All fields are required."; + } else { + $target_dir = "uploads/invoices/"; + if (!is_dir($target_dir)) { + mkdir($target_dir, 0777, true); + } + $target_file = $target_dir . basename($_FILES["dealer_invoice"]["name"]); + $uploadOk = 1; + $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); + + // Check if file already exists + if (file_exists($target_file)) { + $error_message = "Sorry, file already exists."; + $uploadOk = 0; + } + + // Check file size + if ($_FILES["dealer_invoice"]["size"] > 500000) { + $error_message = "Sorry, your file is too large."; + $uploadOk = 0; + } + + // Allow certain file formats + if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" + && $imageFileType != "gif" && $imageFileType != "pdf" ) { + $error_message = "Sorry, only JPG, JPEG, PNG, GIF & PDF files are allowed."; + $uploadOk = 0; + } + + if ($uploadOk == 0) { + $error_message = "Sorry, your file was not uploaded."; + // if everything is ok, try to upload file + } else { + if (move_uploaded_file($_FILES["dealer_invoice"]["tmp_name"], $target_file)) { + try { + $pdo = db(); + $pdo->beginTransaction(); + + // 1. Insert warranty registration + $sql = "INSERT INTO warranty_registrations (sold_serial_id, end_customer_name, end_customer_address, dealer_invoice_date, dealer_invoice_no, dealer_invoice_path, installation_date, serial_number) + SELECT ?, ?, ?, ?, ?, ?, ?, serial_number FROM sold_serials WHERE id = ?"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$sold_serial_id, $end_customer_name, $end_customer_address, $dealer_invoice_date, $dealer_invoice_no, $target_file, $installation_date, $sold_serial_id]); + + // 2. Mark serial as activated + $sql_update = "UPDATE sold_serials SET is_activated = TRUE WHERE id = ?"; + $stmt_update = $pdo->prepare($sql_update); + $stmt_update->execute([$sold_serial_id]); + + $pdo->commit(); + + // Fetch serial number for display message + $stmt_sn = $pdo->prepare("SELECT serial_number FROM sold_serials WHERE id = ?"); + $stmt_sn->execute([$sold_serial_id]); + $serial_number = $stmt_sn->fetchColumn(); + + $success_message = "Warranty for serial number " . htmlspecialchars($serial_number) . " registered successfully!"; + + } catch (PDOException $e) { + $pdo->rollBack(); + $error_message = "Database error: " . $e->getMessage(); + } + } else { + $error_message = "Sorry, there was an error uploading your file."; + } + } + } +} + +require_once 'includes/header.php'; +?> + +
+
+
+
+

Device Warranty Registration

+
+
+

Register a device installation to activate the warranty. Please select a device serial number, enter the end customer's name, and the installation date.

+ + + + + + + + +
+
+ + + +
No devices are pending warranty activation.
+ +
+ + + +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+ + + +