prepare("INSERT INTO prices (tank_id, price, effective_date) VALUES (?, ?, ?)"); $stmt->execute([$tank_id, $price, $effective_date]); $_SESSION['notification'] = ['text' => 'Price added successfully!', 'type' => 'success']; } catch (PDOException $e) { $_SESSION['notification'] = ['text' => 'Error adding price: ' . $e->getMessage(), 'type' => 'danger']; } } else { $_SESSION['notification'] = ['text' => 'All fields are required.', 'type' => 'warning']; } } // Edit Price elseif (isset($_POST['edit_price'])) { $id = $_POST['price_id']; $tank_id = $_POST['tank_id']; $price = $_POST['price']; $effective_date = $_POST['effective_date']; if (!empty($tank_id) && !empty($price) && !empty($effective_date) && !empty($id)) { try { $stmt = $db->prepare("UPDATE prices SET tank_id = ?, price = ?, effective_date = ? WHERE id = ?"); $stmt->execute([$tank_id, $price, $effective_date, $id]); $_SESSION['notification'] = ['text' => 'Price updated successfully!', 'type' => 'success']; } catch (PDOException $e) { $_SESSION['notification'] = ['text' => 'Error updating price: ' . $e->getMessage(), 'type' => 'danger']; } } else { $_SESSION['notification'] = ['text' => 'All fields and ID are required.', 'type' => 'warning']; } } header("Location: prices.php"); exit; } // Soft Delete Price if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) { try { $db = db(); $stmt = $db->prepare("UPDATE prices SET deleted_at = NOW() WHERE id = ?"); $stmt->execute([$_GET['id']]); $_SESSION['notification'] = ['text' => 'Price deleted successfully!', 'type' => 'success']; } catch (PDOException $e) { $_SESSION['notification'] = ['text' => 'Error deleting price: ' . $e->getMessage(), 'type' => 'danger']; } header("Location: prices.php"); exit; } if (isset($_SESSION['notification'])) { $notification = $_SESSION['notification']; unset($_SESSION['notification']); } $db = db(); $prices = $db->query("SELECT pr.*, t.name as tank_name, ft.name as fuel_type_name FROM prices pr JOIN tanks t ON pr.tank_id = t.id JOIN fuel_types ft ON t.fuel_type_id = ft.id WHERE pr.deleted_at IS NULL ORDER BY pr.effective_date DESC")->fetchAll(PDO::FETCH_ASSOC); $tanks = $db->query("SELECT t.id, t.name, ft.name as fuel_type_name FROM tanks t JOIN fuel_types ft ON t.fuel_type_id = ft.id WHERE t.deleted_at IS NULL")->fetchAll(PDO::FETCH_ASSOC); $page_title = "Price Management"; ?>
| Tank | Price | Effective Date | Actions |
|---|---|---|---|
| = htmlspecialchars($price['tank_name'] . ' (' . $price['fuel_type_name'] . ')') ?> | ₹ = htmlspecialchars(number_format($price['price'], 2)) ?> | = date('d M, Y', strtotime($price['effective_date'])) ?> |