v1
This commit is contained in:
parent
28a6b3ca28
commit
e428ea4534
51
assets/css/style.css
Normal file
51
assets/css/style.css
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
background-color: #F8F9FA;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.hero-section {
|
||||
padding: 4rem 0;
|
||||
background: linear-gradient(45deg, #0D6EFD, #4D8BFD);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.hero-section h1 {
|
||||
font-weight: 700;
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
|
||||
.hero-section p {
|
||||
font-size: 1.1rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.login-section {
|
||||
padding: 4rem 0;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
border: none;
|
||||
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: #0D6EFD;
|
||||
border-color: #0D6EFD;
|
||||
}
|
||||
|
||||
.footer {
|
||||
padding: 2rem 0;
|
||||
background-color: #FFFFFF;
|
||||
border-top: 1px solid #DEE2E6;
|
||||
font-size: 0.9rem;
|
||||
color: #6C757D;
|
||||
}
|
||||
7
auth.php
Normal file
7
auth.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: index.php?error=You must be logged in to view this page');
|
||||
exit;
|
||||
}
|
||||
94
bunks.php
Normal file
94
bunks.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
$pdo = db();
|
||||
$message = '';
|
||||
|
||||
// Handle form submission for adding a new bunk
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_bunk'])) {
|
||||
$name = trim($_POST['name']);
|
||||
$owner = trim($_POST['owner']);
|
||||
$contact = trim($_POST['contact']);
|
||||
$location = trim($_POST['location']);
|
||||
|
||||
if (!empty($name) && !empty($owner) && !empty($contact) && !empty($location)) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO bunks (name, owner, contact, location) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$name, $owner, $contact, $location]);
|
||||
$message = '<div class="alert alert-success">Bunk added successfully!</div>';
|
||||
} catch (PDOException $e) {
|
||||
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
}
|
||||
} else {
|
||||
$message = '<div class="alert alert-warning">Please fill in all fields.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch all bunks to display
|
||||
$stmt = $pdo->query("SELECT * FROM bunks ORDER BY name");
|
||||
$bunks = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h2>Manage Bunks</h2>
|
||||
<p>List of all petrol bunks registered in the system.</p>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Owner</th>
|
||||
<th>Contact</th>
|
||||
<th>Location</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($bunks)): ?>
|
||||
<tr>
|
||||
<td colspan="4" class="text-center">No bunks found. Add one to get started.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($bunks as $bunk): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($bunk['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($bunk['owner']); ?></td>
|
||||
<td><?php echo htmlspecialchars($bunk['contact']); ?></td>
|
||||
<td><?php echo htmlspecialchars($bunk['location']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Add New Bunk</h5>
|
||||
<?php echo $message; ?>
|
||||
<form action="bunks.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Bunk Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="owner" class="form-label">Owner Name</label>
|
||||
<input type="text" class="form-control" id="owner" name="owner" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="contact" class="form-label">Contact Number</label>
|
||||
<input type="text" class="form-control" id="contact" name="contact" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="location" class="form-label">Location / Address</label>
|
||||
<textarea class="form-control" id="location" name="location" rows="3" required></textarea>
|
||||
</div>
|
||||
<button type="submit" name="add_bunk" class="btn btn-primary">Add Bunk</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
168
credit_customers.php
Normal file
168
credit_customers.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
$pdo = db();
|
||||
$message = '';
|
||||
$customer_message = '';
|
||||
$vehicle_message = '';
|
||||
|
||||
// Handle form submission for adding a new customer
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_customer'])) {
|
||||
$name = trim($_POST['name']);
|
||||
$contact = trim($_POST['contact']);
|
||||
$address = trim($_POST['address']);
|
||||
$credit_limit = trim($_POST['credit_limit']);
|
||||
|
||||
if (!empty($name)) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO credit_customers (name, contact, address, credit_limit) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$name, $contact, $address, $credit_limit]);
|
||||
$customer_message = '<div class="alert alert-success">Customer added successfully!</div>';
|
||||
} catch (PDOException $e) {
|
||||
$customer_message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
}
|
||||
} else {
|
||||
$customer_message = '<div class="alert alert-warning">Customer name is required.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Handle form submission for adding a new vehicle
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_vehicle'])) {
|
||||
$customer_id = $_POST['customer_id'];
|
||||
$vehicle_number = trim($_POST['vehicle_number']);
|
||||
|
||||
if (!empty($customer_id) && !empty($vehicle_number)) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO vehicles (customer_id, vehicle_number) VALUES (?, ?)");
|
||||
$stmt->execute([$customer_id, $vehicle_number]);
|
||||
$vehicle_message = '<div class="alert alert-success">Vehicle added successfully!</div>';
|
||||
} catch (PDOException $e) {
|
||||
$vehicle_message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
}
|
||||
} else {
|
||||
$vehicle_message = '<div class="alert alert-warning">Vehicle number is required.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fetch all customers
|
||||
$customers_stmt = $pdo->query("SELECT * FROM credit_customers ORDER BY name");
|
||||
$customers = $customers_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Fetch all vehicles and group by customer
|
||||
$vehicles_stmt = $pdo->query("SELECT * FROM vehicles ORDER BY vehicle_number");
|
||||
$all_vehicles = $vehicles_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$vehicles_by_customer = [];
|
||||
foreach ($all_vehicles as $vehicle) {
|
||||
$vehicles_by_customer[$vehicle['customer_id']][] = $vehicle;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<!-- Customer Management -->
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4>Manage Credit Customers</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h5>Existing Customers</h5>
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Contact</th>
|
||||
<th>Address</th>
|
||||
<th>Credit Limit</th>
|
||||
<th>Vehicles</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($customers)): ?>
|
||||
<tr>
|
||||
<td colspan="5" class="text-center">No customers found.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($customers as $customer): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($customer['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($customer['contact']); ?></td>
|
||||
<td><?php echo htmlspecialchars($customer['address']); ?></td>
|
||||
<td><?php echo htmlspecialchars($customer['credit_limit']); ?></td>
|
||||
<td>
|
||||
<?php
|
||||
$vehicles = $vehicles_by_customer[$customer['id']] ?? [];
|
||||
if (!empty($vehicles)) {
|
||||
foreach ($vehicles as $vehicle) {
|
||||
echo htmlspecialchars($vehicle['vehicle_number']) . '<br>';
|
||||
}
|
||||
} else {
|
||||
echo 'No vehicles';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Add New Customer</h5>
|
||||
<?php echo $customer_message; ?>
|
||||
<form action="credit_customers.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Customer Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="contact" class="form-label">Contact</label>
|
||||
<input type="text" class="form-control" id="contact" name="contact">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="address" class="form-label">Address</label>
|
||||
<textarea class="form-control" id="address" name="address" rows="2"></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="credit_limit" class="form-label">Credit Limit</label>
|
||||
<input type="number" step="0.01" class="form-control" id="credit_limit" name="credit_limit">
|
||||
</div>
|
||||
<button type="submit" name="add_customer" class="btn btn-primary">Add Customer</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Add Vehicle to Customer</h5>
|
||||
<?php echo $vehicle_message; ?>
|
||||
<form action="credit_customers.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="customer_id" class="form-label">Customer</label>
|
||||
<select class="form-select" id="customer_id" name="customer_id" required>
|
||||
<option value="">Select a Customer</option>
|
||||
<?php foreach ($customers as $customer): ?>
|
||||
<option value="<?php echo $customer['id']; ?>"><?php echo htmlspecialchars($customer['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="vehicle_number" class="form-label">Vehicle Number</label>
|
||||
<input type="text" class="form-control" id="vehicle_number" name="vehicle_number" required>
|
||||
</div>
|
||||
<button type="submit" name="add_vehicle" class="btn btn-info">Add Vehicle</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
213
credit_sales.php
Normal file
213
credit_sales.php
Normal file
@ -0,0 +1,213 @@
|
||||
<?php
|
||||
require_once 'includes/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
$pdoconn = db();
|
||||
|
||||
// Handle form submission for adding a new credit sale
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_credit_sale'])) {
|
||||
$bunk_id = trim($_POST['bunk_id']);
|
||||
$customer_id = trim($_POST['customer_id']);
|
||||
$date = trim($_POST['date']);
|
||||
$fuel_type_id = trim($_POST['fuel_type_id']);
|
||||
$quantity = trim($_POST['quantity']);
|
||||
$rate = trim($_POST['rate']);
|
||||
$amount = $quantity * $rate;
|
||||
|
||||
if (!empty($bunk_id) && !empty($customer_id) && !empty($date) && !empty($fuel_type_id) && !empty($quantity) && !empty($rate)) {
|
||||
try {
|
||||
$pdoconn->beginTransaction();
|
||||
|
||||
// Insert into credit_sales
|
||||
$sql = "INSERT INTO credit_sales (bunk_id, customer_id, date, fuel_type_id, quantity, rate, amount) VALUES (:bunk_id, :customer_id, :date, :fuel_type_id, :quantity, :rate, :amount)";
|
||||
$stmt = $pdoconn->prepare($sql);
|
||||
$stmt->execute([
|
||||
':bunk_id' => $bunk_id,
|
||||
':customer_id' => $customer_id,
|
||||
':date' => $date,
|
||||
':fuel_type_id' => $fuel_type_id,
|
||||
':quantity' => $quantity,
|
||||
':rate' => $rate,
|
||||
':amount' => $amount
|
||||
]);
|
||||
|
||||
// Update customer's outstanding balance
|
||||
$update_sql = "UPDATE credit_customers SET outstanding_balance = outstanding_balance + :amount WHERE id = :customer_id";
|
||||
$update_stmt = $pdoconn->prepare($update_sql);
|
||||
$update_stmt->execute([':amount' => $amount, ':customer_id' => $customer_id]);
|
||||
|
||||
$pdoconn->commit();
|
||||
$success_message = "Credit sale recorded successfully!";
|
||||
} catch (PDOException $e) {
|
||||
$pdoconn->rollBack();
|
||||
$error_message = "Error recording sale: " . $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$error_message = "All fields are required.";
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch master data for dropdowns
|
||||
try {
|
||||
$bunks_stmt = $pdoconn->query("SELECT id, name FROM bunks ORDER BY name");
|
||||
$bunks = $bunks_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$customers_stmt = $pdoconn->query("SELECT id, name, bunk_id FROM credit_customers ORDER BY name");
|
||||
$customers = $customers_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$fuel_types_stmt = $pdoconn->query("SELECT id, name FROM fuel_types ORDER BY name");
|
||||
$fuel_types = $fuel_types_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
$bunks = [];
|
||||
$customers = [];
|
||||
$fuel_types = [];
|
||||
$page_error = "Error fetching master data: " . $e->getMessage();
|
||||
}
|
||||
|
||||
// Fetch recent credit sales
|
||||
try {
|
||||
$sales_stmt = $pdoconn->query("
|
||||
SELECT cs.*, c.name as customer_name, b.name as bunk_name, ft.name as fuel_type_name
|
||||
FROM credit_sales cs
|
||||
JOIN credit_customers c ON cs.customer_id = c.id
|
||||
JOIN bunks b ON cs.bunk_id = b.id
|
||||
JOIN fuel_types ft ON cs.fuel_type_id = ft.id
|
||||
ORDER BY cs.date DESC, cs.id DESC
|
||||
LIMIT 20
|
||||
");
|
||||
$sales = $sales_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
$sales = [];
|
||||
$page_error = "Error fetching sales: " . $e->getMessage();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title">Record Credit Sale</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (isset($success_message)): ?>
|
||||
<div class="alert alert-success"><?php echo $success_message; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($error_message)): ?>
|
||||
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($page_error)): ?>
|
||||
<div class="alert alert-danger"><?php echo $page_error; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<h5>New Sale Entry</h5>
|
||||
<form method="POST" action="credit_sales.php" id="credit_sale_form">
|
||||
<div class="mb-3">
|
||||
<label for="date" class="form-label">Date</label>
|
||||
<input type="date" class="form-control" id="date" name="date" value="<?php echo date('Y-m-d'); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="bunk_id" class="form-label">Bunk</label>
|
||||
<select class="form-select" id="bunk_id" name="bunk_id" required>
|
||||
<option value="">Select Bunk</option>
|
||||
<?php foreach ($bunks as $bunk): ?>
|
||||
<option value="<?php echo htmlspecialchars($bunk['id']); ?>"><?php echo htmlspecialchars($bunk['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="customer_id" class="form-label">Customer</label>
|
||||
<select class="form-select" id="customer_id" name="customer_id" required>
|
||||
<option value="">Select Customer</option>
|
||||
<?php foreach ($customers as $customer): ?>
|
||||
<option value="<?php echo htmlspecialchars($customer['id']); ?>" data-bunk-id="<?php echo $customer['bunk_id']; ?>">
|
||||
<?php echo htmlspecialchars($customer['name']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="fuel_type_id" class="form-label">Fuel Type</label>
|
||||
<select class="form-select" id="fuel_type_id" name="fuel_type_id" required>
|
||||
<option value="">Select Fuel Type</option>
|
||||
<?php foreach ($fuel_types as $fuel_type): ?>
|
||||
<option value="<?php echo htmlspecialchars($fuel_type['id']); ?>"><?php echo htmlspecialchars($fuel_type['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="quantity" class="form-label">Quantity (Ltr)</label>
|
||||
<input type="number" step="0.01" class="form-control" id="quantity" name="quantity" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="rate" class="form-label">Rate</label>
|
||||
<input type="number" step="0.01" class="form-control" id="rate" name="rate" required>
|
||||
</div>
|
||||
<button type="submit" name="add_credit_sale" class="btn btn-primary">Record Sale</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<h5>Recent Credit Sales</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Customer</th>
|
||||
<th>Bunk</th>
|
||||
<th>Fuel</th>
|
||||
<th>Qty</th>
|
||||
<th>Rate</th>
|
||||
<th>Amount</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($sales)): ?>
|
||||
<tr>
|
||||
<td colspan="7" class="text-center">No credit sales recorded yet.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($sales as $sale): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($sale['date']); ?></td>
|
||||
<td><?php echo htmlspecialchars($sale['customer_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($sale['bunk_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($sale['fuel_type_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($sale['quantity']); ?></td>
|
||||
<td><?.php echo htmlspecialchars(number_format($sale['rate'], 2)); ?></td>
|
||||
<td><?php echo htmlspecialchars(number_format($sale['amount'], 2)); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const bunkSelect = document.getElementById('bunk_id');
|
||||
const customerSelect = document.getElementById('customer_id');
|
||||
const customerOptions = Array.from(customerSelect.options);
|
||||
|
||||
bunkSelect.addEventListener('change', function() {
|
||||
const selectedBunkId = this.value;
|
||||
// Clear current options
|
||||
customerSelect.innerHTML = '<option value="">Select Customer</option>';
|
||||
|
||||
// Filter and add relevant customers
|
||||
customerOptions.forEach(function(option) {
|
||||
if (option.value && option.dataset.bunkId === selectedBunkId) {
|
||||
customerSelect.add(option.cloneNode(true));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
||||
11
dashboard.php
Normal file
11
dashboard.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php require_once __DIR__ . '/includes/header.php'; ?>
|
||||
|
||||
<div class="px-4 py-5 my-5 text-center">
|
||||
<h1 class="display-5 fw-bold">Welcome, <?php echo htmlspecialchars($_SESSION['user_name']); ?>!</h1>
|
||||
<div class="col-lg-6 mx-auto">
|
||||
<p class="lead mb-4">This is your central dashboard. From here, you can manage all aspects of your petrol bunk operations. Use the navigation bar above to get started.</p>
|
||||
<p>Your role is: <strong><?php echo htmlspecialchars($_SESSION['user_role']); ?></strong></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
253
daybook.php
Normal file
253
daybook.php
Normal file
@ -0,0 +1,253 @@
|
||||
<?php
|
||||
require_once 'includes/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
$message = '';
|
||||
$error = '';
|
||||
|
||||
// Handle form submission
|
||||
if (isset($_POST['save_readings'])) {
|
||||
$date = $_POST['date'];
|
||||
$prices = $_POST['prices'];
|
||||
$readings = $_POST['readings'];
|
||||
|
||||
$pdo = db();
|
||||
$pdo->beginTransaction();
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare(
|
||||
"INSERT INTO daybook_readings (date, nozzle_id, opening_reading, closing_reading, price)
|
||||
VALUES (?, ?, ?, ?, ?)"
|
||||
);
|
||||
|
||||
// Fetch fuel types for nozzles
|
||||
$nozzle_fuel_types = [];
|
||||
$nozzles_stmt = $pdo->query("
|
||||
SELECT n.id, ft.fuel_name
|
||||
FROM nozzles n
|
||||
JOIN pumps p ON n.pump_id = p.id
|
||||
JOIN tanks t ON p.tank_id = t.id
|
||||
JOIN fuel_types ft ON t.fuel_type_id = ft.id
|
||||
");
|
||||
while ($row = $nozzles_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$nozzle_fuel_types[$row['id']] = $row['fuel_name'];
|
||||
}
|
||||
|
||||
foreach ($readings as $reading) {
|
||||
$nozzle_id = $reading['nozzle_id'];
|
||||
$opening = $reading['opening'];
|
||||
$closing = $reading['closing'];
|
||||
|
||||
if ($closing < $opening) {
|
||||
throw new Exception("Closing reading cannot be less than opening reading for one of the nozzles.");
|
||||
}
|
||||
|
||||
$fuel_name = $nozzle_fuel_types[$nozzle_id] ?? null;
|
||||
if (!$fuel_name || !isset($prices[$fuel_name])) {
|
||||
throw new Exception("Could not determine price for nozzle ID: $nozzle_id");
|
||||
}
|
||||
$price = $prices[$fuel_name];
|
||||
|
||||
$stmt->execute([$date, $nozzle_id, $opening, $closing, $price]);
|
||||
}
|
||||
|
||||
$pdo->commit();
|
||||
$message = "Daybook readings saved successfully!";
|
||||
} catch (PDOException $e) {
|
||||
$pdo->rollBack();
|
||||
if ($e->errorInfo[1] == 1062) { // Duplicate entry
|
||||
$error = "Error: Daybook readings for this date and nozzle already exist.";
|
||||
} else {
|
||||
$error = "Database error: " . $e->getMessage();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
$error = "Error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fetch previous day's closing readings to suggest as opening readings
|
||||
$previous_day_readings = [];
|
||||
if (isset($_GET['date'])) {
|
||||
$current_date = $_GET['date'];
|
||||
$previous_date = date('Y-m-d', strtotime($current_date . ' -1 day'));
|
||||
$stmt = db()->prepare("SELECT nozzle_id, closing_reading FROM daybook_readings WHERE date = ?");
|
||||
$stmt->execute([$previous_date]);
|
||||
$readings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
foreach ($readings as $reading) {
|
||||
$previous_day_readings[$reading['nozzle_id']] = $reading['closing_reading'];
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch nozzles and their associated fuel types
|
||||
$nozzles_stmt = db()->query("
|
||||
SELECT n.id, n.nozzle_number, ft.fuel_name
|
||||
FROM nozzles n
|
||||
JOIN pumps p ON n.pump_id = p.id
|
||||
JOIN tanks t ON p.tank_id = t.id
|
||||
JOIN fuel_types ft ON t.fuel_type_id = ft.id
|
||||
ORDER BY n.id
|
||||
");
|
||||
$nozzles = $nozzles_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Group nozzles by fuel type
|
||||
$nozzles_by_fuel = [];
|
||||
foreach ($nozzles as $nozzle) {
|
||||
$nozzles_by_fuel[$nozzle['fuel_name']][] = $nozzle;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="container-fluid">
|
||||
<h1 class="h3 mb-4 text-gray-800">Daily Daybook</h1>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div class="alert alert-success"><?php echo $message; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="card shadow mb-4">
|
||||
<div class="card-header py-3">
|
||||
<h6 class="m-0 font-weight-bold text-primary">Enter Readings</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="GET" action="daybook.php" class="form-inline mb-4">
|
||||
<div class="form-group mr-2">
|
||||
<label for="date" class="mr-2">Date:</label>
|
||||
<input type="date" class="form-control" id="date" name="date" value="<?php echo isset($_GET['date']) ? htmlspecialchars($_GET['date']) : date('Y-m-d'); ?>" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Load Readings</button>
|
||||
</form>
|
||||
|
||||
<?php if (isset($_GET['date'])): ?>
|
||||
<form method="POST" action="daybook.php">
|
||||
<input type="hidden" name="date" value="<?php echo htmlspecialchars($_GET['date']); ?>">
|
||||
|
||||
<?php foreach ($nozzles_by_fuel as $fuel_name => $fuel_nozzles): ?>
|
||||
<h5 class="mt-4"><?php echo htmlspecialchars($fuel_name); ?></h5>
|
||||
<div class="form-group row">
|
||||
<label for="price_<?php echo strtolower($fuel_name); ?>" class="col-sm-2 col-form-label">Price (per Ltr)</label>
|
||||
<div class="col-sm-4">
|
||||
<input type="number" step="0.01" class="form-control" id="price_<?php echo strtolower($fuel_name); ?>" name="prices[<?php echo htmlspecialchars($fuel_name); ?>]" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered" width="100%" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nozzle</th>
|
||||
<th>Opening Reading</th>
|
||||
<th>Closing Reading</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($fuel_nozzles as $nozzle): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($nozzle['nozzle_number']); ?></td>
|
||||
<td>
|
||||
<input type="hidden" name="readings[<?php echo $nozzle['id']; ?>][nozzle_id]" value="<?php echo $nozzle['id']; ?>">
|
||||
<input type="number" step="0.01" class="form-control" name="readings[<?php echo $nozzle['id']; ?>][opening]" value="<?php echo $previous_day_readings[$nozzle['id']] ?? '0.00'; ?>" required>
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" step="0.01" class="form-control" name="readings[<?php echo $nozzle['id']; ?>][closing]" required>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<button type="submit" name="save_readings" class="btn btn-success">Save Readings</button>
|
||||
</form>
|
||||
|
||||
<div id="sales_summary" class="mt-4"></div>
|
||||
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const form = document.querySelector('form[method="POST"]');
|
||||
if (!form) return;
|
||||
|
||||
const summaryContainer = document.getElementById('sales_summary');
|
||||
|
||||
function calculateSales() {
|
||||
let totalSalesByFuel = {};
|
||||
let grandTotalAmount = 0;
|
||||
|
||||
const readingInputs = form.querySelectorAll('input[name^="readings["]');
|
||||
const prices = {};
|
||||
document.querySelectorAll('input[name^="prices["]').forEach(priceInput => {
|
||||
const fuelName = priceInput.name.match(/prices\[(.*)\]/)[1];
|
||||
prices[fuelName] = parseFloat(priceInput.value) || 0;
|
||||
});
|
||||
|
||||
const nozzlesByFuel = <?php echo json_encode($nozzles_by_fuel); ?>;
|
||||
let salesSummaryHtml = '<h5 class="mt-4">Live Sales Summary</h5>';
|
||||
|
||||
for (const fuelName in nozzlesByFuel) {
|
||||
if (nozzlesByFuel.hasOwnProperty(fuelName)) {
|
||||
let fuelTotalSaleQty = 0;
|
||||
let fuelTotalSaleAmount = 0;
|
||||
|
||||
nozzlesByFuel[fuelName].forEach(nozzle => {
|
||||
const openingInput = form.querySelector(`input[name="readings[${nozzle.id}][opening]"]`);
|
||||
const closingInput = form.querySelector(`input[name="readings[${nozzle.id}][closing]"]`);
|
||||
|
||||
const openingReading = parseFloat(openingInput.value) || 0;
|
||||
const closingReading = parseFloat(closingInput.value) || 0;
|
||||
const price = prices[fuelName] || 0;
|
||||
|
||||
if (closingReading >= openingReading) {
|
||||
const saleQty = closingReading - openingReading;
|
||||
const saleAmount = saleQty * price;
|
||||
|
||||
fuelTotalSaleQty += saleQty;
|
||||
fuelTotalSaleAmount += saleAmount;
|
||||
}
|
||||
});
|
||||
|
||||
totalSalesByFuel[fuelName] = {
|
||||
qty: fuelTotalSaleQty,
|
||||
amount: fuelTotalSaleAmount
|
||||
};
|
||||
|
||||
grandTotalAmount += fuelTotalSaleAmount;
|
||||
}
|
||||
}
|
||||
|
||||
salesSummaryHtml += '<div class="table-responsive"><table class="table table-bordered">' +
|
||||
'<thead><tr><th>Fuel Type</th><th>Total Sale Qty (Ltr)</th><th>Total Sale Amount</th></tr></thead><tbody>';
|
||||
|
||||
for (const fuelName in totalSalesByFuel) {
|
||||
if (totalSalesByFuel.hasOwnProperty(fuelName)) {
|
||||
salesSummaryHtml += `<tr>
|
||||
<td>${fuelName}</td>
|
||||
<td>${totalSalesByFuel[fuelName].qty.toFixed(2)}</td>
|
||||
<td>${totalSalesByFuel[fuelName].amount.toFixed(2)}</td>
|
||||
</tr>`;
|
||||
}
|
||||
}
|
||||
|
||||
salesSummaryHtml += `</tbody><tfoot><tr>
|
||||
<th colspan="2" class="text-right">Grand Total</th>
|
||||
<th>${grandTotalAmount.toFixed(2)}</th>
|
||||
</tr></tfoot></table></div>`;
|
||||
|
||||
summaryContainer.innerHTML = salesSummaryHtml;
|
||||
}
|
||||
|
||||
form.addEventListener('input', calculateSales);
|
||||
calculateSales(); // Initial calculation
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
||||
41
db/migrate.php
Normal file
41
db/migrate.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
// Create migrations table if it doesn't exist
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS `migrations` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`migration` VARCHAR(255) NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);");
|
||||
|
||||
// Get all executed migrations
|
||||
$executed_migrations = $pdo->query("SELECT migration FROM migrations")->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
// Get all migration files
|
||||
$migration_files = glob(__DIR__ . '/migrations/*.sql');
|
||||
|
||||
foreach ($migration_files as $file) {
|
||||
$migration_name = basename($file);
|
||||
if (!in_array($migration_name, $executed_migrations)) {
|
||||
// Execute the migration
|
||||
$sql = file_get_contents($file);
|
||||
$pdo->exec($sql);
|
||||
|
||||
// Record the migration
|
||||
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)");
|
||||
$stmt->execute([$migration_name]);
|
||||
|
||||
echo "Executed migration: {$migration_name}\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "Database migrations completed successfully!\n";
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("Database migration failed: " . $e->getMessage() . "\n");
|
||||
}
|
||||
|
||||
188
db/migrations/001_initial_schema.sql
Normal file
188
db/migrations/001_initial_schema.sql
Normal file
@ -0,0 +1,188 @@
|
||||
-- Initial Schema for Petrol Bunk Management System
|
||||
|
||||
-- Users and Roles
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(100) NOT NULL,
|
||||
`email` VARCHAR(100) NOT NULL UNIQUE,
|
||||
`password` VARCHAR(255) NOT NULL,
|
||||
`role` ENUM('Superadmin', 'Manager', 'Attendant', 'Accountant') NOT NULL,
|
||||
`bunk_id` INT,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Master Data
|
||||
CREATE TABLE IF NOT EXISTS `bunks` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`owner` VARCHAR(255),
|
||||
`contact` VARCHAR(50),
|
||||
`location` TEXT,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `fuel_types` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(50) NOT NULL UNIQUE,
|
||||
`unit` VARCHAR(20) DEFAULT 'Litre'
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `tanks` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(100) NOT NULL,
|
||||
`bunk_id` INT NOT NULL,
|
||||
`fuel_type_id` INT NOT NULL,
|
||||
`capacity` DECIMAL(10, 2) NOT NULL,
|
||||
FOREIGN KEY (`bunk_id`) REFERENCES `bunks`(`id`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`fuel_type_id`) REFERENCES `fuel_types`(`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `pumps` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(100) NOT NULL,
|
||||
`bunk_id` INT NOT NULL,
|
||||
FOREIGN KEY (`bunk_id`) REFERENCES `bunks`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `nozzles` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(100) NOT NULL,
|
||||
`pump_id` INT NOT NULL,
|
||||
`tank_id` INT NOT NULL,
|
||||
FOREIGN KEY (`pump_id`) REFERENCES `pumps`(`id`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`tank_id`) REFERENCES `tanks`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `price_history` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`fuel_type_id` INT NOT NULL,
|
||||
`bunk_id` INT NOT NULL,
|
||||
`price` DECIMAL(10, 2) NOT NULL,
|
||||
`date` DATE NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY `bunk_fuel_date` (`bunk_id`, `fuel_type_id`, `date`),
|
||||
FOREIGN KEY (`fuel_type_id`) REFERENCES `fuel_types`(`id`),
|
||||
FOREIGN KEY (`bunk_id`) REFERENCES `bunks`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Daily Operations
|
||||
CREATE TABLE IF NOT EXISTS `daybook` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`bunk_id` INT NOT NULL,
|
||||
`nozzle_id` INT NOT NULL,
|
||||
`date` DATE NOT NULL,
|
||||
`opening_reading` DECIMAL(10, 2) NOT NULL,
|
||||
`closing_reading` DECIMAL(10, 2),
|
||||
`testing` DECIMAL(10, 2) DEFAULT 0,
|
||||
`sale` DECIMAL(10, 2) GENERATED ALWAYS AS (closing_reading - opening_reading - testing) STORED,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY `bunk_nozzle_date` (`bunk_id`, `nozzle_id`, `date`),
|
||||
FOREIGN KEY (`bunk_id`) REFERENCES `bunks`(`id`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`nozzle_id`) REFERENCES `nozzles`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Credit Sales
|
||||
CREATE TABLE IF NOT EXISTS `credit_customers` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`contact` VARCHAR(50),
|
||||
`bunk_id` INT NOT NULL,
|
||||
`credit_limit` DECIMAL(10, 2) DEFAULT 0,
|
||||
`outstanding_balance` DECIMAL(10, 2) DEFAULT 0,
|
||||
FOREIGN KEY (`bunk_id`) REFERENCES `bunks`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `credit_sales` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`bunk_id` INT NOT NULL,
|
||||
`customer_id` INT NOT NULL,
|
||||
`date` DATE NOT NULL,
|
||||
`fuel_type_id` INT NOT NULL,
|
||||
`quantity` DECIMAL(10, 2) NOT NULL,
|
||||
`rate` DECIMAL(10, 2) NOT NULL,
|
||||
`amount` DECIMAL(10, 2) NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`bunk_id`) REFERENCES `bunks`(`id`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`customer_id`) REFERENCES `credit_customers`(`id`),
|
||||
FOREIGN KEY (`fuel_type_id`) REFERENCES `fuel_types`(`id`)
|
||||
);
|
||||
|
||||
-- Receipts and Expenses
|
||||
CREATE TABLE IF NOT EXISTS `fuel_receipts` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`bunk_id` INT NOT NULL,
|
||||
`supplier` VARCHAR(255),
|
||||
`invoice_number` VARCHAR(100),
|
||||
`fuel_type_id` INT NOT NULL,
|
||||
`quantity` DECIMAL(10, 2) NOT NULL,
|
||||
`rate` DECIMAL(10, 2) NOT NULL,
|
||||
`amount` DECIMAL(10, 2) NOT NULL,
|
||||
`date` DATE NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`bunk_id`) REFERENCES `bunks`(`id`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`fuel_type_id`) REFERENCES `fuel_types`(`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `expenses` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`bunk_id` INT NOT NULL,
|
||||
`category` VARCHAR(100) NOT NULL,
|
||||
`amount` DECIMAL(10, 2) NOT NULL,
|
||||
`description` TEXT,
|
||||
`payment_mode` VARCHAR(50),
|
||||
`date` DATE NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`bunk_id`) REFERENCES `bunks`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Product & Stock
|
||||
CREATE TABLE IF NOT EXISTS `products` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`category` VARCHAR(100),
|
||||
`price` DECIMAL(10, 2) NOT NULL,
|
||||
`bunk_id` INT NOT NULL,
|
||||
FOREIGN KEY (`bunk_id`) REFERENCES `bunks`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `stock` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`product_id` INT NOT NULL,
|
||||
`date` DATE NOT NULL,
|
||||
`opening_stock` INT NOT NULL,
|
||||
`sales` INT DEFAULT 0,
|
||||
`closing_stock` INT GENERATED ALWAYS AS (opening_stock - sales) STORED,
|
||||
`bunk_id` INT NOT NULL,
|
||||
UNIQUE KEY `bunk_product_date` (`bunk_id`, `product_id`, `date`),
|
||||
FOREIGN KEY (`product_id`) REFERENCES `products`(`id`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`bunk_id`) REFERENCES `bunks`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Accounts
|
||||
CREATE TABLE IF NOT EXISTS `accounts` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`type` ENUM('Owner', 'Bank', 'OD', 'Supplier', 'Customer', 'Cash') NOT NULL,
|
||||
`bunk_id` INT NOT NULL,
|
||||
`balance` DECIMAL(12, 2) DEFAULT 0,
|
||||
FOREIGN KEY (`bunk_id`) REFERENCES `bunks`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `transactions` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`bunk_id` INT NOT NULL,
|
||||
`date` DATE NOT NULL,
|
||||
`account_id` INT NOT NULL,
|
||||
`type` ENUM('Debit', 'Credit') NOT NULL,
|
||||
`amount` DECIMAL(10, 2) NOT NULL,
|
||||
`description` TEXT,
|
||||
`related_entity_type` VARCHAR(50), -- e.g., 'credit_sale', 'expense', 'fuel_receipt'
|
||||
`related_entity_id` INT,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`bunk_id`) REFERENCES `bunks`(`id`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`)
|
||||
);
|
||||
|
||||
-- Add a superadmin user
|
||||
INSERT IGNORE INTO `users` (`name`, `email`, `password`, `role`) VALUES
|
||||
('Superadmin', 'admin@example.com', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Superadmin'); -- password is "password"
|
||||
1
db/migrations/002_add_vehicle_to_customers.sql
Normal file
1
db/migrations/002_add_vehicle_to_customers.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE `credit_customers` ADD `vehicle_mapping` TEXT COMMENT 'JSON encoded array of vehicle numbers';
|
||||
4
db/migrations/003_add_fields_to_bunks.sql
Normal file
4
db/migrations/003_add_fields_to_bunks.sql
Normal file
@ -0,0 +1,4 @@
|
||||
ALTER TABLE `bunks`
|
||||
ADD COLUMN `owner` VARCHAR(255) NULL,
|
||||
ADD COLUMN `location` VARCHAR(255) NULL,
|
||||
ADD COLUMN `contact` VARCHAR(255) NULL;
|
||||
11
db/migrations/004_create_daybook_table.sql
Normal file
11
db/migrations/004_create_daybook_table.sql
Normal file
@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS `daybook_readings` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`date` DATE NOT NULL,
|
||||
`nozzle_id` INT NOT NULL,
|
||||
`opening_reading` DECIMAL(10, 2) NOT NULL,
|
||||
`closing_reading` DECIMAL(10, 2) NOT NULL,
|
||||
`price` DECIMAL(10, 2) NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`nozzle_id`) REFERENCES `nozzles`(`id`),
|
||||
UNIQUE KEY `date_nozzle` (`date`, `nozzle_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
1
db/migrations/005_add_tank_to_pumps.sql
Normal file
1
db/migrations/005_add_tank_to_pumps.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE `pumps` ADD COLUMN `tank_id` INT NULL, ADD FOREIGN KEY (`tank_id`) REFERENCES `tanks`(`id`);
|
||||
35
db/migrations/006_create_credit_management_tables.sql
Normal file
35
db/migrations/006_create_credit_management_tables.sql
Normal file
@ -0,0 +1,35 @@
|
||||
CREATE TABLE IF NOT EXISTS `credit_customers` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`contact` VARCHAR(255) NULL,
|
||||
`address` TEXT NULL,
|
||||
`credit_limit` DECIMAL(10, 2) DEFAULT 0.00,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `vehicles` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`customer_id` INT NOT NULL,
|
||||
`vehicle_number` VARCHAR(255) NOT NULL,
|
||||
`make` VARCHAR(255) NULL,
|
||||
`model` VARCHAR(255) NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`customer_id`) REFERENCES `credit_customers`(`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `credit_sales` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`date` DATE NOT NULL,
|
||||
`customer_id` INT NOT NULL,
|
||||
`vehicle_id` INT NULL,
|
||||
`fuel_type_id` INT NOT NULL,
|
||||
`quantity` DECIMAL(10, 2) NOT NULL,
|
||||
`rate` DECIMAL(10, 2) NOT NULL,
|
||||
`amount` DECIMAL(10, 2) NOT NULL,
|
||||
`is_settled` BOOLEAN DEFAULT FALSE,
|
||||
`settled_at` DATETIME NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`customer_id`) REFERENCES `credit_customers`(`id`),
|
||||
FOREIGN KEY (`vehicle_id`) REFERENCES `vehicles`(`id`),
|
||||
FOREIGN KEY (`fuel_type_id`) REFERENCES `fuel_types`(`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
177
fuel_receipts.php
Normal file
177
fuel_receipts.php
Normal file
@ -0,0 +1,177 @@
|
||||
<?php
|
||||
require_once 'includes/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
$pdoconn = db();
|
||||
|
||||
// Handle form submission for adding a new fuel receipt
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_receipt'])) {
|
||||
$bunk_id = trim($_POST['bunk_id']);
|
||||
$supplier = trim($_POST['supplier']);
|
||||
$invoice_number = trim($_POST['invoice_number']);
|
||||
$fuel_type_id = trim($_POST['fuel_type_id']);
|
||||
$quantity = trim($_POST['quantity']);
|
||||
$rate = trim($_POST['rate']);
|
||||
$date = trim($_POST['date']);
|
||||
$amount = $quantity * $rate;
|
||||
|
||||
if (!empty($bunk_id) && !empty($fuel_type_id) && !empty($quantity) && !empty($rate) && !empty($date)) {
|
||||
try {
|
||||
$sql = "INSERT INTO fuel_receipts (bunk_id, supplier, invoice_number, fuel_type_id, quantity, rate, amount, date) VALUES (:bunk_id, :supplier, :invoice_number, :fuel_type_id, :quantity, :rate, :amount, :date)";
|
||||
$stmt = $pdoconn->prepare($sql);
|
||||
$stmt->execute([
|
||||
':bunk_id' => $bunk_id,
|
||||
':supplier' => $supplier,
|
||||
':invoice_number' => $invoice_number,
|
||||
':fuel_type_id' => $fuel_type_id,
|
||||
':quantity' => $quantity,
|
||||
':rate' => $rate,
|
||||
':amount' => $amount,
|
||||
':date' => $date
|
||||
]);
|
||||
$success_message = "Fuel receipt recorded successfully!";
|
||||
} catch (PDOException $e) {
|
||||
$error_message = "Error recording receipt: " . $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$error_message = "Bunk, fuel type, quantity, rate, and date are required.";
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch master data for dropdowns
|
||||
try {
|
||||
$bunks_stmt = $pdoconn->query("SELECT id, name FROM bunks ORDER BY name");
|
||||
$bunks = $bunks_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$fuel_types_stmt = $pdoconn->query("SELECT id, name FROM fuel_types ORDER BY name");
|
||||
$fuel_types = $fuel_types_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
$bunks = [];
|
||||
$fuel_types = [];
|
||||
$page_error = "Error fetching master data: " . $e->getMessage();
|
||||
}
|
||||
|
||||
// Fetch recent fuel receipts
|
||||
try {
|
||||
$receipts_stmt = $pdoconn->query("
|
||||
SELECT fr.*, b.name as bunk_name, ft.name as fuel_type_name
|
||||
FROM fuel_receipts fr
|
||||
JOIN bunks b ON fr.bunk_id = b.id
|
||||
JOIN fuel_types ft ON fr.fuel_type_id = ft.id
|
||||
ORDER BY fr.date DESC, fr.id DESC
|
||||
LIMIT 20
|
||||
");
|
||||
$receipts = $receipts_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
$receipts = [];
|
||||
$page_error = "Error fetching receipts: " . $e->getMessage();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title">Record Fuel Receipt</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (isset($success_message)): ?>
|
||||
<div class="alert alert-success"><?php echo $success_message; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($error_message)): ?>
|
||||
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($page_error)): ?>
|
||||
<div class="alert alert-danger"><?php echo $page_error; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<h5>New Receipt Entry</h5>
|
||||
<form method="POST" action="fuel_receipts.php">
|
||||
<div class="mb-3">
|
||||
<label for="date" class="form-label">Date</label>
|
||||
<input type="date" class="form-control" id="date" name="date" value="<?php echo date('Y-m-d'); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="bunk_id" class="form-label">Bunk</label>
|
||||
<select class="form-select" id="bunk_id" name="bunk_id" required>
|
||||
<option value="">Select Bunk</option>
|
||||
<?php foreach ($bunks as $bunk): ?>
|
||||
<option value="<?php echo htmlspecialchars($bunk['id']); ?>"><?php echo htmlspecialchars($bunk['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="supplier" class="form-label">Supplier (e.g., IOCL)</label>
|
||||
<input type="text" class="form-control" id="supplier" name="supplier">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="invoice_number" class="form-label">Invoice Number</label>
|
||||
<input type="text" class="form-control" id="invoice_number" name="invoice_number">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="fuel_type_id" class="form-label">Fuel Type</label>
|
||||
<select class="form-select" id="fuel_type_id" name="fuel_type_id" required>
|
||||
<option value="">Select Fuel Type</option>
|
||||
<?php foreach ($fuel_types as $fuel_type): ?>
|
||||
<option value="<?php echo htmlspecialchars($fuel_type['id']); ?>"><?php echo htmlspecialchars($fuel_type['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="quantity" class="form-label">Quantity (Ltr)</label>
|
||||
<input type="number" step="0.01" class="form-control" id="quantity" name="quantity" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="rate" class="form-label">Rate</label>
|
||||
<input type="number" step="0.01" class="form-control" id="rate" name="rate" required>
|
||||
</div>
|
||||
<button type="submit" name="add_receipt" class="btn btn-primary">Record Receipt</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<h5>Recent Fuel Receipts</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Bunk</th>
|
||||
<th>Supplier</th>
|
||||
<th>Invoice #</th>
|
||||
<th>Fuel</th>
|
||||
<th>Qty</th>
|
||||
<th>Rate</th>
|
||||
<th>Amount</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($receipts)): ?>
|
||||
<tr>
|
||||
<td colspan="8" class="text-center">No fuel receipts recorded yet.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($receipts as $receipt): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($receipt['date']); ?></td>
|
||||
<td><?php echo htmlspecialchars($receipt['bunk_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($receipt['supplier']); ?></td>
|
||||
<td><?php echo htmlspecialchars($receipt['invoice_number']); ?></td>
|
||||
<td><?php echo htmlspecialchars($receipt['fuel_type_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($receipt['quantity']); ?></td>
|
||||
<td><?php echo htmlspecialchars(number_format($receipt['rate'], 2)); ?></td>
|
||||
<td><?php echo htmlspecialchars(number_format($receipt['amount'], 2)); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
||||
82
fuel_types.php
Normal file
82
fuel_types.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
$pdo = db();
|
||||
$message = '';
|
||||
|
||||
// Handle form submission for adding a new fuel type
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_fuel_type'])) {
|
||||
$name = trim($_POST['name']);
|
||||
|
||||
if (!empty($name)) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO fuel_types (name) VALUES (?)");
|
||||
$stmt->execute([$name]);
|
||||
$message = '<div class="alert alert-success">Fuel type added successfully!</div>';
|
||||
} catch (PDOException $e) {
|
||||
if ($e->errorInfo[1] == 1062) { // Duplicate entry
|
||||
$message = '<div class="alert alert-danger">Error: A fuel type with this name already exists.</div>';
|
||||
} else {
|
||||
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$message = '<div class="alert alert-warning">Please enter a fuel type name.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch all fuel types to display
|
||||
$stmt = $pdo->query("SELECT * FROM fuel_types ORDER BY name");
|
||||
$fuel_types = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h2>Manage Fuel Types</h2>
|
||||
<p>List of all fuel types available in the system (e.g., MS, HSD, Power).</p>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Fuel Type Name</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($fuel_types)): ?>
|
||||
<tr>
|
||||
<td colspan="2" class="text-center">No fuel types found. Add one to get started.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($fuel_types as $fuel_type): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($fuel_type['name']); ?></td>
|
||||
<td>
|
||||
<a href="#" class="btn btn-sm btn-outline-primary disabled">Edit</a>
|
||||
<a href="#" class="btn btn-sm btn-outline-danger disabled">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Add New Fuel Type</h5>
|
||||
<?php echo $message; ?>
|
||||
<form action="fuel_types.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Fuel Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required placeholder="e.g., MS (Petrol)">
|
||||
</div>
|
||||
<button type="submit" name="add_fuel_type" class="btn btn-primary">Add Fuel Type</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
5
includes/footer.php
Normal file
5
includes/footer.php
Normal file
@ -0,0 +1,5 @@
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
62
includes/header.php
Normal file
62
includes/header.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../auth.php';
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Petrol Bunk Management</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="/assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/dashboard.php">Petrol Bunk</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/dashboard.php">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/daybook.php">Daybook</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Master Data
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
<li><a class="dropdown-item" href="/bunks.php">Bunks</a></li>
|
||||
<li><a class="dropdown-item" href="/fuel_types.php">Fuel Types</a></li>
|
||||
<li><a class="dropdown-item" href="/tanks.php">Tanks</a></li>
|
||||
<li><a class="dropdown-item" href="/pumps.php">Pumps</a></li>
|
||||
<li><a class="dropdown-item" href="/nozzles.php">Nozzles</a></li>
|
||||
<li><a class="dropdown-item" href="/price_history.php">Price History</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="creditDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Credit Management
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="creditDropdown">
|
||||
<li><a class="dropdown-item" href="/credit_customers.php">Credit Customers</a></li>
|
||||
<li><a class="dropdown-item" href="/credit_sales.php">Record Credit Sale</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/logout.php">Logout</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container mt-4">
|
||||
221
index.php
221
index.php
@ -1,150 +1,81 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
?>
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Petrol Bunk Management</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/style.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
|
||||
<!-- Header -->
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="#">
|
||||
<i class="bi bi-fuel-pump-fill text-primary"></i>
|
||||
Petrol Bunk MS
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Hero Section -->
|
||||
<header class="hero-section text-center">
|
||||
<div class="container">
|
||||
<h1 class="display-4">Efficient Fuel Management</h1>
|
||||
<p class="lead">The all-in-one solution for managing your petrol bunk operations seamlessly.</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Login Section -->
|
||||
<main id="login" class="login-section">
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6 col-lg-5">
|
||||
<div class="card login-card p-4">
|
||||
<div class="card-body">
|
||||
<h3 class="card-title text-center mb-4">Secure Login</h3>
|
||||
<?php if (isset($_GET['error'])): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo htmlspecialchars($_GET['error']); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_GET['message'])): ?>
|
||||
<div class="alert alert-success" role="alert">
|
||||
<?php echo htmlspecialchars($_GET['message']); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="login.php" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary btn-lg">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- Footer -->
|
||||
<footer class="footer text-center">
|
||||
<div class="container">
|
||||
<p>© <?php echo date("Y"); ?> Petrol Bunk Management System. All Rights Reserved.</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
34
login.php
Normal file
34
login.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = $_POST['email'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
if (empty($email) || empty($password)) {
|
||||
header('Location: index.php?error=Please fill in all fields');
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = ?');
|
||||
$stmt->execute([$email]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['user_name'] = $user['name'];
|
||||
$_SESSION['user_role'] = $user['role'];
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
} else {
|
||||
header('Location: index.php?error=Invalid email or password');
|
||||
exit;
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
// In a real app, log this error instead of showing it to the user
|
||||
die('Database error: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
6
logout.php
Normal file
6
logout.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_unset();
|
||||
session_destroy();
|
||||
header('Location: index.php?message=You have been logged out');
|
||||
exit;
|
||||
134
nozzles.php
Normal file
134
nozzles.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
require_once 'includes/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Handle form submission for adding a new nozzle
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_nozzle'])) {
|
||||
$nozzle_name = trim($_POST['nozzle_name']);
|
||||
$pump_id = trim($_POST['pump_id']);
|
||||
|
||||
if (!empty($nozzle_name) && !empty($pump_id)) {
|
||||
try {
|
||||
$pdoconn = db();
|
||||
$pdoconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$sql = "INSERT INTO nozzles (nozzle_name, pump_id) VALUES (:nozzle_name, :pump_id)";
|
||||
$stmt = $pdoconn->prepare($sql);
|
||||
$stmt->bindParam(':nozzle_name', $nozzle_name);
|
||||
$stmt->bindParam(':pump_id', $pump_id);
|
||||
$stmt->execute();
|
||||
$success_message = "Nozzle added successfully!";
|
||||
} catch (PDOException $e) {
|
||||
$error_message = "Error adding nozzle: " . $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$error_message = "Nozzle name and pump are required.";
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch pumps for the dropdown
|
||||
try {
|
||||
$pdoconn = db();
|
||||
$pumps_stmt = $pdoconn->query("SELECT id, pump_number FROM pumps ORDER BY pump_number");
|
||||
$pumps = $pumps_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
$pumps = [];
|
||||
$page_error = "Error fetching pumps: " . $e->getMessage();
|
||||
}
|
||||
|
||||
// Fetch existing nozzles with their pump and bunk
|
||||
try {
|
||||
$pdoconn = db();
|
||||
$nozzles_stmt = $pdoconn->query("
|
||||
SELECT n.id, n.nozzle_name, p.pump_number, b.name as bunk_name
|
||||
FROM nozzles n
|
||||
JOIN pumps p ON n.pump_id = p.id
|
||||
JOIN bunks b ON p.bunk_id = b.id
|
||||
ORDER BY b.name, p.pump_number, n.nozzle_name
|
||||
");
|
||||
$nozzles = $nozzles_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
$nozzles = [];
|
||||
$page_error = "Error fetching nozzles: " . $e->getMessage();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title">Manage Nozzles</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (isset($success_message)): ?>
|
||||
<div class="alert alert-success"><?php echo $success_message; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($error_message)): ?>
|
||||
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($page_error)): ?>
|
||||
<div class="alert alert-danger"><?php echo $page_error; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<h5>Add New Nozzle</h5>
|
||||
<form method="POST" action="nozzles.php">
|
||||
<div class="mb-3">
|
||||
<label for="nozzle_name" class="form-label">Nozzle Name</label>
|
||||
<input type="text" class="form-control" id="nozzle_name" name="nozzle_name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="pump_id" class="form-label">Assign to Pump</label>
|
||||
<select class="form-select" id="pump_id" name="pump_id" required>
|
||||
<option value="">Select Pump</option>
|
||||
<?php foreach ($pumps as $pump): ?>
|
||||
<option value="<?php echo htmlspecialchars($pump['id']); ?>">
|
||||
<?php echo htmlspecialchars($pump['pump_number']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" name="add_nozzle" class="btn btn-primary">Add Nozzle</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<h5>Existing Nozzles</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Nozzle Name</th>
|
||||
<th>Pump</th>
|
||||
<th>Bunk</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($nozzles)): ?>
|
||||
<tr>
|
||||
<td colspan="4" class="text-center">No nozzles found.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($nozzles as $nozzle): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($nozzle['id']); ?></td>
|
||||
<td><?php echo htmlspecialchars($nozzle['nozzle_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($nozzle['pump_number']); ?></td>
|
||||
<td><?php echo htmlspecialchars($nozzle['bunk_name']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
||||
100
price_history.php
Normal file
100
price_history.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
$pdo = db();
|
||||
$message = '';
|
||||
|
||||
// Handle form submission for adding a new price
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_price'])) {
|
||||
$fuel_type_id = $_POST['fuel_type_id'];
|
||||
$price = trim($_POST['price']);
|
||||
$date = $_POST['date'];
|
||||
|
||||
if (!empty($fuel_type_id) && !empty($price) && !empty($date)) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO price_history (fuel_type_id, price, date) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$fuel_type_id, $price, $date]);
|
||||
$message = '<div class="alert alert-success">Price added successfully!</div>';
|
||||
} catch (PDOException $e) {
|
||||
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
}
|
||||
} else {
|
||||
$message = '<div class="alert alert-warning">Please fill in all fields.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch related data for forms
|
||||
$fuel_types = $pdo->query("SELECT id, name FROM fuel_types ORDER BY name")->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Fetch all price history with fuel type name
|
||||
$stmt = $pdo->query("
|
||||
SELECT ph.id, ph.price, ph.date, ft.name AS fuel_type_name
|
||||
FROM price_history ph
|
||||
JOIN fuel_types ft ON ph.fuel_type_id = ft.id
|
||||
ORDER BY ph.date DESC, ft.name
|
||||
");
|
||||
$price_history = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h2>Price History</h2>
|
||||
<p>History of fuel prices.</p>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Fuel Type</th>
|
||||
<th>Price</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($price_history)): ?>
|
||||
<tr>
|
||||
<td colspan="3" class="text-center">No price history found. Add one to get started.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($price_history as $price_entry): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($price_entry['date']); ?></td>
|
||||
<td><?php echo htmlspecialchars($price_entry['fuel_type_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($price_entry['price']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Add New Price</h5>
|
||||
<?php echo $message; ?>
|
||||
<form action="price_history.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="date" class="form-label">Date</label>
|
||||
<input type="date" class="form-control" id="date" name="date" value="<?php echo date('Y-m-d'); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="fuel_type_id" class="form-label">Fuel Type</label>
|
||||
<select class="form-select" id="fuel_type_id" name="fuel_type_id" required>
|
||||
<option value="">Select a Fuel Type</option>
|
||||
<?php foreach ($fuel_types as $fuel_type): ?>
|
||||
<option value="<?php echo $fuel_type['id']; ?>"><?php echo htmlspecialchars($fuel_type['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="price" class="form-label">Price</label>
|
||||
<input type="number" step="0.01" class="form-control" id="price" name="price" required placeholder="e.g., 102.50">
|
||||
</div>
|
||||
<button type="submit" name="add_price" class="btn btn-primary">Add Price</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
117
pumps.php
Normal file
117
pumps.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
$pdo = db();
|
||||
$message = '';
|
||||
|
||||
// Handle form submission for adding a new pump
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_pump'])) {
|
||||
$bunk_id = $_POST['bunk_id'];
|
||||
$tank_id = $_POST['tank_id'];
|
||||
$pump_number = trim($_POST['pump_number']);
|
||||
|
||||
if (!empty($bunk_id) && !empty($tank_id) && !empty($pump_number)) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO pumps (bunk_id, tank_id, pump_number) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$bunk_id, $tank_id, $pump_number]);
|
||||
$message = '<div class="alert alert-success">Pump added successfully!</div>';
|
||||
} catch (PDOException $e) {
|
||||
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
}
|
||||
} else {
|
||||
$message = '<div class="alert alert-warning">Please fill in all fields.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch related data for forms
|
||||
$bunks = $pdo->query("SELECT id, name FROM bunks ORDER BY name")->fetchAll(PDO::FETCH_ASSOC);
|
||||
$tanks = $pdo->query("
|
||||
SELECT t.id, t.name as tank_name, b.name as bunk_name, ft.name as fuel_type_name
|
||||
FROM tanks t
|
||||
JOIN bunks b ON t.bunk_id = b.id
|
||||
JOIN fuel_types ft ON t.fuel_type_id = ft.id
|
||||
ORDER BY b.name, t.name
|
||||
")->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
|
||||
// Fetch all pumps with their bunk and tank name
|
||||
$stmt = $pdo->query("
|
||||
SELECT p.id, p.pump_number, b.name AS bunk_name, t.name as tank_name, ft.name as fuel_type_name
|
||||
FROM pumps p
|
||||
JOIN bunks b ON p.bunk_id = b.id
|
||||
LEFT JOIN tanks t ON p.tank_id = t.id
|
||||
LEFT JOIN fuel_types ft ON t.fuel_type_id = ft.id
|
||||
ORDER BY b.name, p.pump_number
|
||||
");
|
||||
$pumps = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h2>Manage Pumps</h2>
|
||||
<p>List of all fuel pumps and their assigned tanks.</p>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Pump Number</th>
|
||||
<th>Bunk</th>
|
||||
<th>Tank</th>
|
||||
<th>Fuel Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($pumps)): ?>
|
||||
<tr>
|
||||
<td colspan="4" class="text-center">No pumps found. Add one to get started.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($pumps as $pump): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($pump['pump_number']); ?></td>
|
||||
<td><?php echo htmlspecialchars($pump['bunk_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($pump['tank_name'] ?? 'N/A'); ?></td>
|
||||
<td><?php echo htmlspecialchars($pump['fuel_type_name'] ?? 'N/A'); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Add New Pump</h5>
|
||||
<?php echo $message; ?>
|
||||
<form action="pumps.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="bunk_id" class="form-label">Bunk</label>
|
||||
<select class="form-select" id="bunk_id" name="bunk_id" required>
|
||||
<option value="">Select a Bunk</option>
|
||||
<?php foreach ($bunks as $bunk): ?>
|
||||
<option value="<?php echo $bunk['id']; ?>"><?php echo htmlspecialchars($bunk['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="tank_id" class="form-label">Tank</label>
|
||||
<select class="form-select" id="tank_id" name="tank_id" required>
|
||||
<option value="">Select a Tank</option>
|
||||
<?php foreach ($tanks as $tank): ?>
|
||||
<option value="<?php echo $tank['id']; ?>">(<?php echo htmlspecialchars($tank['bunk_name']); ?>) <?php echo htmlspecialchars($tank['tank_name']); ?> - <?php echo htmlspecialchars($tank['fuel_type_name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="pump_number" class="form-label">Pump Number</label>
|
||||
<input type="text" class="form-control" id="pump_number" name="pump_number" required placeholder="e.g., P-01">
|
||||
</div>
|
||||
<button type="submit" name="add_pump" class="btn btn-primary">Add Pump</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
119
tanks.php
Normal file
119
tanks.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
$pdo = db();
|
||||
$message = '';
|
||||
|
||||
// Handle form submission for adding a new tank
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_tank'])) {
|
||||
$bunk_id = $_POST['bunk_id'];
|
||||
$fuel_type_id = $_POST['fuel_type_id'];
|
||||
$name = trim($_POST['name']);
|
||||
$capacity = $_POST['capacity'];
|
||||
|
||||
if (!empty($bunk_id) && !empty($fuel_type_id) && !empty($name) && !empty($capacity)) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO tanks (bunk_id, fuel_type_id, name, capacity) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$bunk_id, $fuel_type_id, $name, $capacity]);
|
||||
$message = '<div class="alert alert-success">Tank added successfully!</div>';
|
||||
} catch (PDOException $e) {
|
||||
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
}
|
||||
} else {
|
||||
$message = '<div class="alert alert-warning">Please fill in all fields.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch related data for forms and listing
|
||||
$bunks = $pdo->query("SELECT id, name FROM bunks ORDER BY name")->fetchAll(PDO::FETCH_ASSOC);
|
||||
$fuel_types = $pdo->query("SELECT id, name FROM fuel_types ORDER BY name")->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Fetch all tanks with their related bunk and fuel type names
|
||||
$stmt = $pdo->query("
|
||||
SELECT
|
||||
t.id,
|
||||
t.name AS tank_name,
|
||||
t.capacity,
|
||||
b.name AS bunk_name,
|
||||
ft.name AS fuel_type_name
|
||||
FROM tanks t
|
||||
JOIN bunks b ON t.bunk_id = b.id
|
||||
JOIN fuel_types ft ON t.fuel_type_id = ft.id
|
||||
ORDER BY b.name, t.name
|
||||
");
|
||||
$tanks = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h2>Manage Tanks</h2>
|
||||
<p>List of all fuel tanks, associated with a bunk and fuel type.</p>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Tank Name</th>
|
||||
<th>Bunk</th>
|
||||
<th>Fuel Type</th>
|
||||
<th>Capacity (L)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($tanks)): ?>
|
||||
<tr>
|
||||
<td colspan="4" class="text-center">No tanks found. Add one to get started.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($tanks as $tank): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($tank['tank_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($tank['bunk_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($tank['fuel_type_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars(number_format($tank['capacity'])); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Add New Tank</h5>
|
||||
<?php echo $message; ?>
|
||||
<form action="tanks.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Tank Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required placeholder="e.g., Tank 1 - MS">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="bunk_id" class="form-label">Bunk</label>
|
||||
<select class="form-select" id="bunk_id" name="bunk_id" required>
|
||||
<option value="">Select a Bunk</option>
|
||||
<?php foreach ($bunks as $bunk): ?>
|
||||
<option value="<?php echo $bunk['id']; ?>"><?php echo htmlspecialchars($bunk['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="fuel_type_id" class="form-label">Fuel Type</label>
|
||||
<select class="form-select" id="fuel_type_id" name="fuel_type_id" required>
|
||||
<option value="">Select a Fuel Type</option>
|
||||
<?php foreach ($fuel_types as $fuel_type): ?>
|
||||
<option value="<?php echo $fuel_type['id']; ?>"><?php echo htmlspecialchars($fuel_type['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="capacity" class="form-label">Capacity (in Liters)</label>
|
||||
<input type="number" class="form-control" id="capacity" name="capacity" required placeholder="e.g., 20000">
|
||||
</div>
|
||||
<button type="submit" name="add_tank" class="btn btn-primary">Add Tank</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
Loading…
x
Reference in New Issue
Block a user