prepare("DELETE FROM quotations WHERE id = ?"); $stmt->execute([$delete_id]); header("Location: quotations.php"); exit; } // Handle form submission for adding a new quotation if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['add_quotation'])) { $customer_id = $_POST['customer_id']; $quotation_number = $_POST['quotation_number']; $quotation_date = $_POST['quotation_date']; $total_amount = $_POST['total_amount']; if (!empty($customer_id) && !empty($quotation_number) && !empty($quotation_date) && !empty($total_amount)) { $pdo = db(); $stmt = $pdo->prepare("INSERT INTO quotations (customer_id, quotation_number, quotation_date, total_amount) VALUES (?, ?, ?, ?)"); $stmt->execute([$customer_id, $quotation_number, $quotation_date, $total_amount]); } header("Location: quotations.php"); exit(); } // Handle form submission for updating a quotation if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_quotation'])) { $id = $_POST['quotation_id']; $customer_id = $_POST['customer_id']; $quotation_number = $_POST['quotation_number']; $quotation_date = $_POST['quotation_date']; $total_amount = $_POST['total_amount']; $status = $_POST['status']; if (!empty($id)) { $pdo = db(); $stmt = $pdo->prepare("UPDATE quotations SET customer_id = ?, quotation_number = ?, quotation_date = ?, total_amount = ?, status = ? WHERE id = ?"); $stmt->execute([$customer_id, $quotation_number, $quotation_date, $total_amount, $status, $id]); header("Location: quotations.php"); exit; } } // Fetch all customers for the dropdown $pdo = db(); $customers_stmt = $pdo->query("SELECT id, companyName FROM customers ORDER BY companyName ASC"); $customers = $customers_stmt->fetchAll(PDO::FETCH_ASSOC); // Fetch all quotations with customer names $quotations_stmt = $pdo->query(" SELECT q.id, q.customer_id, q.quotation_number, q.quotation_date, q.total_amount, q.status, c.companyName AS customer_name FROM quotations q JOIN customers c ON q.customer_id = c.id ORDER BY q.quotation_date DESC "); $quotations = $quotations_stmt->fetchAll(PDO::FETCH_ASSOC); include 'includes/header.php'; ?>