Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
991c9b924e | ||
|
|
7fd4fb5808 | ||
|
|
b8ab420fdd | ||
|
|
6236799760 | ||
|
|
8daee549e1 | ||
|
|
4f6f10c21f | ||
|
|
c1d245a403 | ||
|
|
61ba3ccfbc |
90
assets/css/custom.css
Normal file
90
assets/css/custom.css
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/* System Font Stack */
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
color: #212529;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 240px;
|
||||||
|
background-color: #ffffff;
|
||||||
|
border-right: 1px solid #e7e7e7;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar h4 {
|
||||||
|
color: #007bff;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .nav-link {
|
||||||
|
color: #6c757d;
|
||||||
|
font-size: 1rem;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .nav-link:hover, .sidebar .nav-link.active {
|
||||||
|
color: #007bff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .nav-link .bi {
|
||||||
|
margin-right: 0.8rem;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
margin-left: 240px;
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kpi-card {
|
||||||
|
background-color: #ffffff;
|
||||||
|
border: 1px solid #e7e7e7;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
padding: 1.5rem;
|
||||||
|
color: #212529;
|
||||||
|
transition: box-shadow 0.2s ease-in-out, transform 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kpi-card:hover {
|
||||||
|
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.kpi-card h5 {
|
||||||
|
color: #6c757d;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kpi-card .value {
|
||||||
|
font-size: 2.2rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #212529;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kpi-card .icon {
|
||||||
|
font-size: 2.8rem;
|
||||||
|
color: #007bff;
|
||||||
|
opacity: 0.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
border: 1px solid #e7e7e7;
|
||||||
|
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
|
||||||
|
}
|
||||||
|
|
||||||
|
.table {
|
||||||
|
color: #212529;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table thead th {
|
||||||
|
font-weight: 600;
|
||||||
|
color: #495057;
|
||||||
|
}
|
||||||
1
assets/js/main.js
Normal file
1
assets/js/main.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
// Add any custom javascript here in the future
|
||||||
109
create_customer.php
Normal file
109
create_customer.php
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
require_once 'templates/header.php';
|
||||||
|
|
||||||
|
$name = $email = $phone = $address = $plan_id = "";
|
||||||
|
$errors = [];
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$name = trim($_POST["name"]);
|
||||||
|
$email = trim($_POST["email"]);
|
||||||
|
$phone = trim($_POST["phone"]);
|
||||||
|
$address = trim($_POST["address"]);
|
||||||
|
$plan_id = trim($_POST["plan_id"]);
|
||||||
|
|
||||||
|
if (empty($name)) {
|
||||||
|
$errors[] = "Name is required.";
|
||||||
|
}
|
||||||
|
if (empty($email)) {
|
||||||
|
$errors[] = "Email is required.";
|
||||||
|
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$errors[] = "Invalid email format.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$sql = "INSERT INTO customers (name, email, phone, address, plan_id, created_at) VALUES (?, ?, ?, ?, ?, NOW())";
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->execute([$name, $email, $phone, $address, $plan_id]);
|
||||||
|
header("Location: customers.php");
|
||||||
|
exit;
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$errors[] = "Database error: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch plans for the dropdown
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->query("SELECT id, name FROM plans");
|
||||||
|
$plans = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$plans = [];
|
||||||
|
$errors[] = "Could not fetch plans.";
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container-fluid px-4">
|
||||||
|
<h1 class="mt-4">Create New Customer</h1>
|
||||||
|
<ol class="breadcrumb mb-4">
|
||||||
|
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
|
||||||
|
<li class="breadcrumb-item"><a href="customers.php">Customers</a></li>
|
||||||
|
<li class="breadcrumb-item active">Create</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-header">
|
||||||
|
<i class="fas fa-user-plus me-1"></i>
|
||||||
|
New Customer Details
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<?php if (!empty($errors)): ?>
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($errors as $error): ?>
|
||||||
|
<li><?php echo htmlspecialchars($error); ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form action="create_customer.php" method="post">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="name" class="form-label">Full Name</label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($name); ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="email" class="form-label">Email Address</label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="phone" class="form-label">Phone</label>
|
||||||
|
<input type="text" class="form-control" id="phone" name="phone" value="<?php echo htmlspecialchars($phone); ?>">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="address" class="form-label">Address</label>
|
||||||
|
<textarea class="form-control" id="address" name="address" rows="3"><?php echo htmlspecialchars($address); ?></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="plan_id" class="form-label">Subscription Plan</label>
|
||||||
|
<select class="form-select" id="plan_id" name="plan_id">
|
||||||
|
<option value="">Select a plan</option>
|
||||||
|
<?php foreach ($plans as $plan): ?>
|
||||||
|
<option value="<?php echo htmlspecialchars($plan['id']); ?>" <?php echo ($plan_id == $plan['id']) ? 'selected' : ''; ?>>
|
||||||
|
<?php echo htmlspecialchars($plan['name']); ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Create Customer</button>
|
||||||
|
<a href="customers.php" class="btn btn-secondary">Cancel</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php require_once 'templates/footer.php'; ?>
|
||||||
122
create_invoice.php
Normal file
122
create_invoice.php
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
require_once 'templates/header.php';
|
||||||
|
|
||||||
|
$customer_id = $plan_id = $amount = $status = "";
|
||||||
|
$errors = [];
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$customer_id = trim($_POST["customer_id"]);
|
||||||
|
$plan_id = trim($_POST["plan_id"]);
|
||||||
|
$amount = trim($_POST["amount"]);
|
||||||
|
$status = trim($_POST["status"]);
|
||||||
|
|
||||||
|
if (empty($customer_id)) {
|
||||||
|
$errors[] = "Customer is required.";
|
||||||
|
}
|
||||||
|
if (empty($plan_id)) {
|
||||||
|
$errors[] = "Plan is required.";
|
||||||
|
}
|
||||||
|
if (empty($amount) || !is_numeric($amount)) {
|
||||||
|
$errors[] = "A valid amount is required.";
|
||||||
|
}
|
||||||
|
if (empty($status)) {
|
||||||
|
$errors[] = "Status is required.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$sql = "INSERT INTO invoices (customer_id, plan_id, amount, status, created_at) VALUES (?, ?, ?, ?, NOW())";
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->execute([$customer_id, $plan_id, $amount, $status]);
|
||||||
|
header("Location: invoices.php");
|
||||||
|
exit;
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$errors[] = "Database error: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch customers and plans for dropdowns
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$customer_stmt = $pdo->query("SELECT id, name FROM customers ORDER BY name");
|
||||||
|
$customers = $customer_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
$plan_stmt = $pdo->query("SELECT id, name FROM plans ORDER BY name");
|
||||||
|
$plans = $plan_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$customers = [];
|
||||||
|
$plans = [];
|
||||||
|
$errors[] = "Could not fetch data for form.";
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container-fluid px-4">
|
||||||
|
<h1 class="mt-4">Create New Invoice</h1>
|
||||||
|
<ol class="breadcrumb mb-4">
|
||||||
|
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
|
||||||
|
<li class="breadcrumb-item"><a href="invoices.php">Invoices</a></li>
|
||||||
|
<li class="breadcrumb-item active">Create</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-header">
|
||||||
|
<i class="fas fa-file-invoice-dollar me-1"></i>
|
||||||
|
New Invoice Details
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<?php if (!empty($errors)): ?>
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($errors as $error): ?>
|
||||||
|
<li><?php echo htmlspecialchars($error); ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form action="create_invoice.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 htmlspecialchars($customer['id']); ?>" <?php echo ($customer_id == $customer['id']) ? 'selected' : ''; ?>>
|
||||||
|
<?php echo htmlspecialchars($customer['name']); ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="plan_id" class="form-label">Plan</label>
|
||||||
|
<select class="form-select" id="plan_id" name="plan_id" required>
|
||||||
|
<option value="">Select a plan</option>
|
||||||
|
<?php foreach ($plans as $plan): ?>
|
||||||
|
<option value="<?php echo htmlspecialchars($plan['id']); ?>" <?php echo ($plan_id == $plan['id']) ? 'selected' : ''; ?>>
|
||||||
|
<?php echo htmlspecialchars($plan['name']); ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="amount" class="form-label">Amount ($)</label>
|
||||||
|
<input type="number" step="0.01" class="form-control" id="amount" name="amount" value="<?php echo htmlspecialchars($amount); ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="status" class="form-label">Status</label>
|
||||||
|
<select class="form-select" id="status" name="status" required>
|
||||||
|
<option value="paid" <?php echo ($status == 'paid') ? 'selected' : ''; ?>>Paid</option>
|
||||||
|
<option value="pending" <?php echo ($status == 'pending') ? 'selected' : ''; ?>>Pending</option>
|
||||||
|
<option value="overdue" <?php echo ($status == 'overdue') ? 'selected' : ''; ?>>Overdue</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Create Invoice</button>
|
||||||
|
<a href="invoices.php" class="btn btn-secondary">Cancel</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php require_once 'templates/footer.php'; ?>
|
||||||
80
create_plan.php
Normal file
80
create_plan.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
require_once 'templates/header.php';
|
||||||
|
|
||||||
|
$name = $price = $features = "";
|
||||||
|
$errors = [];
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$name = trim($_POST["name"]);
|
||||||
|
$price = trim($_POST["price"]);
|
||||||
|
$features = trim($_POST["features"]);
|
||||||
|
|
||||||
|
if (empty($name)) {
|
||||||
|
$errors[] = "Plan name is required.";
|
||||||
|
}
|
||||||
|
if (empty($price) || !is_numeric($price)) {
|
||||||
|
$errors[] = "A valid price is required.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($errors)) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$sql = "INSERT INTO plans (name, price, features, created_at) VALUES (?, ?, ?, NOW())";
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->execute([$name, $price, $features]);
|
||||||
|
header("Location: plans.php");
|
||||||
|
exit;
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$errors[] = "Database error: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container-fluid px-4">
|
||||||
|
<h1 class="mt-4">Create New Plan</h1>
|
||||||
|
<ol class="breadcrumb mb-4">
|
||||||
|
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
|
||||||
|
<li class="breadcrumb-item"><a href="plans.php">Plans</a></li>
|
||||||
|
<li class="breadcrumb-item active">Create</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-header">
|
||||||
|
<i class="fas fa-award me-1"></i>
|
||||||
|
New Plan Details
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<?php if (!empty($errors)): ?>
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($errors as $error): ?>
|
||||||
|
<li><?php echo htmlspecialchars($error); ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form action="create_plan.php" method="post">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="name" class="form-label">Plan Name</label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($name); ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="price" class="form-label">Price ($ per month)</label>
|
||||||
|
<input type="number" step="0.01" class="form-control" id="price" name="price" value="<?php echo htmlspecialchars($price); ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="features" class="form-label">Features (comma-separated)</label>
|
||||||
|
<textarea class="form-control" id="features" name="features" rows="3"><?php echo htmlspecialchars($features); ?></textarea>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Create Plan</button>
|
||||||
|
<a href="plans.php" class="btn btn-secondary">Cancel</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php require_once 'templates/footer.php'; ?>
|
||||||
81
customers.php
Normal file
81
customers.php
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$title = 'Customers - Billing';
|
||||||
|
$page = 'customers';
|
||||||
|
require_once 'templates/header.php';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->query('SELECT id, name, email, status, created_at FROM customers ORDER BY created_at DESC');
|
||||||
|
$customers = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$customers = [];
|
||||||
|
$error_message = "Error: Could not fetch customer data.";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="h2">Customers</h1>
|
||||||
|
<div class="btn-toolbar mb-2 mb-md-0">
|
||||||
|
<a href="create_customer.php" class="btn btn-sm btn-primary">
|
||||||
|
<i class="bi bi-plus-circle"></i>
|
||||||
|
Add New Customer
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if (isset($error_message)): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">#</th>
|
||||||
|
<th scope="col">Name</th>
|
||||||
|
<th scope="col">Email</th>
|
||||||
|
<th scope="col">Status</th>
|
||||||
|
<th scope="col">Registered</th>
|
||||||
|
<th scope="col">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($customers)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="6" class="text-center">No customers found.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($customers as $customer): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($customer['id']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($customer['name']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($customer['email']); ?></td>
|
||||||
|
<td>
|
||||||
|
<?php
|
||||||
|
$status = htmlspecialchars($customer['status']);
|
||||||
|
$badge_class = 'bg-secondary';
|
||||||
|
if ($status === 'active') {
|
||||||
|
$badge_class = 'bg-success';
|
||||||
|
} elseif ($status === 'inactive') {
|
||||||
|
$badge_class = 'bg-danger';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<span class="badge <?php echo $badge_class; ?>"><?php echo ucfirst($status); ?></span>
|
||||||
|
</td>
|
||||||
|
<td><?php echo htmlspecialchars(date('M d, Y', strtotime($customer['created_at']))); ?></td>
|
||||||
|
<td>
|
||||||
|
<a href="edit_customer.php?id=<?php echo $customer['id']; ?>" class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil"></i></a>
|
||||||
|
<a href="delete_customer.php?id=<?php echo $customer['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this customer?');"><i class="bi bi-trash"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'templates/footer.php';
|
||||||
|
?>
|
||||||
31
db/migrate.php
Normal file
31
db/migrate.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/config.php';
|
||||||
|
|
||||||
|
function run_migrations() {
|
||||||
|
$pdo = db();
|
||||||
|
$migrationsDir = __DIR__ . '/migrations';
|
||||||
|
$files = glob($migrationsDir . '/*.sql');
|
||||||
|
|
||||||
|
if (empty($files)) {
|
||||||
|
echo "No migration files found.\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sort($files);
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
|
echo "Running migration: " . basename($file) . "...\n";
|
||||||
|
try {
|
||||||
|
$sql = file_get_contents($file);
|
||||||
|
$pdo->exec($sql);
|
||||||
|
echo "Success.\n";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Error running migration " . basename($file) . ": " . $e->getMessage() . "\n";
|
||||||
|
// Exit on first error
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run_migrations();
|
||||||
|
|
||||||
9
db/migrations/001_create_customers_table.sql
Normal file
9
db/migrations/001_create_customers_table.sql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `customers` (
|
||||||
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
`name` VARCHAR(255) NOT NULL,
|
||||||
|
`email` VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
`plan` VARCHAR(100),
|
||||||
|
`status` VARCHAR(50) DEFAULT 'active',
|
||||||
|
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
8
db/migrations/002_create_plans_table.sql
Normal file
8
db/migrations/002_create_plans_table.sql
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `plans` (
|
||||||
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
`name` VARCHAR(255) NOT NULL,
|
||||||
|
`price` DECIMAL(10, 2) NOT NULL,
|
||||||
|
`billing_cycle` VARCHAR(50) NOT NULL,
|
||||||
|
`features` TEXT,
|
||||||
|
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
9
db/migrations/003_create_invoices_table.sql
Normal file
9
db/migrations/003_create_invoices_table.sql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS invoices (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
customer_id INT NOT NULL,
|
||||||
|
amount DECIMAL(10, 2) NOT NULL,
|
||||||
|
status VARCHAR(20) NOT NULL DEFAULT 'pending',
|
||||||
|
due_date DATE,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
8
db/migrations/004_create_reports_table.sql
Normal file
8
db/migrations/004_create_reports_table.sql
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS reports (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
type VARCHAR(100) NOT NULL,
|
||||||
|
data TEXT,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
138
db/seed.php
Normal file
138
db/seed.php
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/config.php';
|
||||||
|
|
||||||
|
function seed_customers() {
|
||||||
|
$pdo = db();
|
||||||
|
$customers = [
|
||||||
|
['name' => 'John Doe', 'email' => 'john.doe@example.com', 'plan' => 'Premium HD', 'status' => 'Active'],
|
||||||
|
['name' => 'Jane Smith', 'email' => 'jane.smith@example.com', 'plan' => 'Basic', 'status' => 'Active'],
|
||||||
|
['name' => 'Mike Johnson', 'email' => 'mike.j@example.com', 'plan' => 'Premium HD', 'status' => 'Suspended'],
|
||||||
|
['name' => 'Sarah Williams', 'email' => 'sarah.w@example.com', 'plan' => 'Family Pack', 'status' => 'Deactivated'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO customers (name, email, plan, status) VALUES (:name, :email, :plan, :status) ON DUPLICATE KEY UPDATE name=VALUES(name), plan=VALUES(plan), status=VALUES(status)");
|
||||||
|
|
||||||
|
foreach ($customers as $customer) {
|
||||||
|
echo "Seeding customer: " . $customer['name'] . "...\n";
|
||||||
|
try {
|
||||||
|
$stmt->execute($customer);
|
||||||
|
echo "Success.\n";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Error seeding customer " . $customer['name'] . ": " . $e->getMessage() . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function seed_plans() {
|
||||||
|
$pdo = db();
|
||||||
|
$plans = [
|
||||||
|
[
|
||||||
|
'name' => 'Basic Cable',
|
||||||
|
'price' => 29.99,
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'features' => json_encode(['50+ Channels', 'Standard Definition', '1 TV Connection'])
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Premium HD',
|
||||||
|
'price' => 49.99,
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'features' => json_encode(['150+ Channels', 'High Definition', 'Includes Sports Pack', '2 TV Connections'])
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Ultimate Fiber',
|
||||||
|
'price' => 79.99,
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'features' => json_encode(['300+ Channels', '4K Ultra HD', 'All Premium Channels', 'Up to 5 TV Connections', 'On-Demand Library'])
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO plans (name, price, billing_cycle, features) VALUES (:name, :price, :billing_cycle, :features) ON DUPLICATE KEY UPDATE name=VALUES(name), price=VALUES(price), billing_cycle=VALUES(billing_cycle), features=VALUES(features)");
|
||||||
|
|
||||||
|
foreach ($plans as $plan) {
|
||||||
|
echo "Seeding plan: " . $plan['name'] . "...\n";
|
||||||
|
try {
|
||||||
|
$stmt->execute($plan);
|
||||||
|
echo "Success.\n";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Error seeding plan " . $plan['name'] . ": " . $e->getMessage() . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function seed_invoices() {
|
||||||
|
$pdo = db();
|
||||||
|
$customer_stmt = $pdo->query('SELECT id FROM customers');
|
||||||
|
$customer_ids = $customer_stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
|
if (empty($customer_ids)) {
|
||||||
|
echo "No customers found to create invoices for.\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$invoices = [];
|
||||||
|
$statuses = ['Paid', 'Pending', 'Overdue'];
|
||||||
|
foreach ($customer_ids as $customer_id) {
|
||||||
|
for ($i = 0; $i < 3; $i++) {
|
||||||
|
$invoices[] = [
|
||||||
|
'customer_id' => $customer_id,
|
||||||
|
'amount' => rand(2000, 10000) / 100,
|
||||||
|
'status' => $statuses[array_rand($statuses)],
|
||||||
|
'due_date' => date('Y-m-d', strtotime('+' . rand(-30, 30) . ' days')),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO invoices (customer_id, amount, status, due_date) VALUES (:customer_id, :amount, :status, :due_date)");
|
||||||
|
|
||||||
|
foreach ($invoices as $invoice) {
|
||||||
|
echo "Seeding invoice for customer ID: " . $invoice['customer_id'] . "...\n";
|
||||||
|
try {
|
||||||
|
$stmt->execute($invoice);
|
||||||
|
echo "Success.\n";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Error seeding invoice: " . $e->getMessage() . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function seed_reports() {
|
||||||
|
$pdo = db();
|
||||||
|
$reports = [
|
||||||
|
[
|
||||||
|
'name' => 'Monthly Revenue',
|
||||||
|
'type' => 'Financial',
|
||||||
|
'data' => json_encode(['month' => 'October 2025', 'revenue' => 12345.67])
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Active Customers',
|
||||||
|
'type' => 'User',
|
||||||
|
'data' => json_encode(['active_customers' => 123])
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Plan Distribution',
|
||||||
|
'type' => 'Subscription',
|
||||||
|
'data' => json_encode(['Basic' => 50, 'Premium HD' => 50, 'Family Pack' => 23])
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO reports (name, type, data) VALUES (:name, :type, :data)");
|
||||||
|
|
||||||
|
foreach ($reports as $report) {
|
||||||
|
echo "Seeding report: " . $report['name'] . "...\n";
|
||||||
|
try {
|
||||||
|
$stmt->execute($report);
|
||||||
|
echo "Success.\n";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Error seeding report " . $report['name'] . ": " . $e->getMessage() . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
seed_customers();
|
||||||
|
seed_plans();
|
||||||
|
seed_invoices();
|
||||||
|
seed_reports();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
19
delete_customer.php
Normal file
19
delete_customer.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$customer_id = $_GET['id'] ?? null;
|
||||||
|
|
||||||
|
if ($customer_id) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare('DELETE FROM customers WHERE id = ?');
|
||||||
|
$stmt->execute([$customer_id]);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
// Optional: Log the error or show a generic error message
|
||||||
|
// For simplicity, we redirect without an error message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Location: customers.php');
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
19
delete_invoice.php
Normal file
19
delete_invoice.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$invoice_id = $_GET['id'] ?? null;
|
||||||
|
|
||||||
|
if ($invoice_id) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare('DELETE FROM invoices WHERE id = ?');
|
||||||
|
$stmt->execute([$invoice_id]);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
// Optional: Log the error or show a generic error message
|
||||||
|
// For simplicity, we redirect without an error message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Location: invoices.php');
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
19
delete_plan.php
Normal file
19
delete_plan.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$plan_id = $_GET['id'] ?? null;
|
||||||
|
|
||||||
|
if ($plan_id) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare('DELETE FROM plans WHERE id = ?');
|
||||||
|
$stmt->execute([$plan_id]);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
// Optional: Log the error or show a generic error message
|
||||||
|
// For simplicity, we redirect without an error message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Location: plans.php');
|
||||||
|
exit;
|
||||||
|
?>
|
||||||
89
edit_customer.php
Normal file
89
edit_customer.php
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$title = 'Edit Customer - Billing';
|
||||||
|
$page = 'customers';
|
||||||
|
require_once 'templates/header.php';
|
||||||
|
|
||||||
|
$customer_id = $_GET['id'] ?? null;
|
||||||
|
$error_message = '';
|
||||||
|
$success_message = '';
|
||||||
|
$customer = null;
|
||||||
|
|
||||||
|
if (!$customer_id) {
|
||||||
|
header('Location: customers.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$name = trim($_POST['name']);
|
||||||
|
$email = trim($_POST['email']);
|
||||||
|
$status = trim($_POST['status']);
|
||||||
|
|
||||||
|
if (empty($name) || empty($email) || empty($status)) {
|
||||||
|
$error_message = 'Please fill in all required fields.';
|
||||||
|
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$error_message = 'Invalid email format.';
|
||||||
|
} else {
|
||||||
|
$stmt = $pdo->prepare('UPDATE customers SET name = ?, email = ?, status = ? WHERE id = ?');
|
||||||
|
$stmt->execute([$name, $email, $status, $customer_id]);
|
||||||
|
$success_message = 'Customer updated successfully!';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare('SELECT id, name, email, status FROM customers WHERE id = ?');
|
||||||
|
$stmt->execute([$customer_id]);
|
||||||
|
$customer = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$customer) {
|
||||||
|
header('Location: customers.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error_message = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="h2">Edit Customer</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if ($error_message): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($success_message): ?>
|
||||||
|
<div class="alert alert-success"><?php echo htmlspecialchars($success_message); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($customer): ?>
|
||||||
|
<form action="edit_customer.php?id=<?php echo htmlspecialchars($customer_id); ?>" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="name" class="form-label">Name</label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($customer['name']); ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="email" class="form-label">Email</label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($customer['email']); ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="status" class="form-label">Status</label>
|
||||||
|
<select class="form-select" id="status" name="status" required>
|
||||||
|
<option value="active" <?php echo ($customer['status'] === 'active') ? 'selected' : ''; ?>>Active</option>
|
||||||
|
<option value="inactive" <?php echo ($customer['status'] === 'inactive') ? 'selected' : ''; ?>>Inactive</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||||
|
<a href="customers.php" class="btn btn-secondary">Cancel</a>
|
||||||
|
</form>
|
||||||
|
<?php else: ?>
|
||||||
|
<p>Customer not found.</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'templates/footer.php';
|
||||||
|
?>
|
||||||
122
edit_invoice.php
Normal file
122
edit_invoice.php
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$title = 'Edit Invoice - Billing';
|
||||||
|
$page = 'invoices';
|
||||||
|
require_once 'templates/header.php';
|
||||||
|
|
||||||
|
$invoice_id = $_GET['id'] ?? null;
|
||||||
|
$error_message = '';
|
||||||
|
$success_message = '';
|
||||||
|
$invoice = null;
|
||||||
|
|
||||||
|
if (!$invoice_id) {
|
||||||
|
header('Location: invoices.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$customer_id = trim($_POST['customer_id']);
|
||||||
|
$plan_id = trim($_POST['plan_id']);
|
||||||
|
$amount = trim($_POST['amount']);
|
||||||
|
$status = trim($_POST['status']);
|
||||||
|
$due_date = trim($_POST['due_date']);
|
||||||
|
|
||||||
|
if (empty($customer_id) || empty($plan_id) || empty($amount) || empty($status) || empty($due_date)) {
|
||||||
|
$error_message = 'Please fill in all required fields.';
|
||||||
|
} elseif (!is_numeric($amount)) {
|
||||||
|
$error_message = 'Amount must be a number.';
|
||||||
|
} else {
|
||||||
|
$stmt = $pdo->prepare('UPDATE invoices SET customer_id = ?, plan_id = ?, amount = ?, status = ?, due_date = ? WHERE id = ?');
|
||||||
|
$stmt->execute([$customer_id, $plan_id, $amount, $status, $due_date, $invoice_id]);
|
||||||
|
$success_message = 'Invoice updated successfully!';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare('SELECT * FROM invoices WHERE id = ?');
|
||||||
|
$stmt->execute([$invoice_id]);
|
||||||
|
$invoice = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$invoice) {
|
||||||
|
header('Location: invoices.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$customers_stmt = $pdo->query('SELECT id, name FROM customers');
|
||||||
|
$customers = $customers_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$plans_stmt = $pdo->query('SELECT id, name FROM plans');
|
||||||
|
$plans = $plans_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error_message = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="h2">Edit Invoice #<?php echo htmlspecialchars($invoice_id); ?></h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if ($error_message): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($success_message): ?>
|
||||||
|
<div class="alert alert-success"><?php echo htmlspecialchars($success_message); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($invoice): ?>
|
||||||
|
<form action="edit_invoice.php?id=<?php echo htmlspecialchars($invoice_id); ?>" method="POST">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="customer_id" class="form-label">Customer</label>
|
||||||
|
<select class="form-select" id="customer_id" name="customer_id" required>
|
||||||
|
<?php foreach ($customers as $customer): ?>
|
||||||
|
<option value="<?php echo $customer['id']; ?>" <?php echo ($invoice['customer_id'] == $customer['id']) ? 'selected' : ''; ?>><?php echo htmlspecialchars($customer['name']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="plan_id" class="form-label">Plan</label>
|
||||||
|
<select class="form-select" id="plan_id" name="plan_id" required>
|
||||||
|
<?php foreach ($plans as $plan): ?>
|
||||||
|
<option value="<?php echo $plan['id']; ?>" <?php echo ($invoice['plan_id'] == $plan['id']) ? 'selected' : ''; ?>><?php echo htmlspecialchars($plan['name']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4 mb-3">
|
||||||
|
<label for="amount" class="form-label">Amount</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-text">$</span>
|
||||||
|
<input type="number" step="0.01" class="form-control" id="amount" name="amount" value="<?php echo htmlspecialchars($invoice['amount']); ?>" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4 mb-3">
|
||||||
|
<label for="status" class="form-label">Status</label>
|
||||||
|
<select class="form-select" id="status" name="status" required>
|
||||||
|
<option value="Pending" <?php echo ($invoice['status'] === 'Pending') ? 'selected' : ''; ?>>Pending</option>
|
||||||
|
<option value="Paid" <?php echo ($invoice['status'] === 'Paid') ? 'selected' : ''; ?>>Paid</option>
|
||||||
|
<option value="Overdue" <?php echo ($invoice['status'] === 'Overdue') ? 'selected' : ''; ?>>Overdue</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4 mb-3">
|
||||||
|
<label for="due_date" class="form-label">Due Date</label>
|
||||||
|
<input type="date" class="form-control" id="due_date" name="due_date" value="<?php echo htmlspecialchars($invoice['due_date']); ?>" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||||
|
<a href="invoices.php" class="btn btn-secondary">Cancel</a>
|
||||||
|
</form>
|
||||||
|
<?php else: ?>
|
||||||
|
<p>Invoice not found.</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'templates/footer.php';
|
||||||
|
?>
|
||||||
100
edit_plan.php
Normal file
100
edit_plan.php
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$title = 'Edit Plan - Billing';
|
||||||
|
$page = 'plans';
|
||||||
|
require_once 'templates/header.php';
|
||||||
|
|
||||||
|
$plan_id = $_GET['id'] ?? null;
|
||||||
|
$error_message = '';
|
||||||
|
$success_message = '';
|
||||||
|
$plan = null;
|
||||||
|
|
||||||
|
if (!$plan_id) {
|
||||||
|
header('Location: plans.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$name = trim($_POST['name']);
|
||||||
|
$price = trim($_POST['price']);
|
||||||
|
$billing_cycle = trim($_POST['billing_cycle']);
|
||||||
|
$features = trim($_POST['features']);
|
||||||
|
|
||||||
|
if (empty($name) || empty($price) || empty($billing_cycle)) {
|
||||||
|
$error_message = 'Please fill in all required fields.';
|
||||||
|
} elseif (!is_numeric($price)) {
|
||||||
|
$error_message = 'Price must be a number.';
|
||||||
|
} else {
|
||||||
|
$features_json = json_encode(array_map('trim', explode("\n", $features)));
|
||||||
|
$stmt = $pdo->prepare('UPDATE plans SET name = ?, price = ?, billing_cycle = ?, features = ? WHERE id = ?');
|
||||||
|
$stmt->execute([$name, $price, $billing_cycle, $features_json, $plan_id]);
|
||||||
|
$success_message = 'Plan updated successfully!';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare('SELECT * FROM plans WHERE id = ?');
|
||||||
|
$stmt->execute([$plan_id]);
|
||||||
|
$plan = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$plan) {
|
||||||
|
header('Location: plans.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error_message = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="h2">Edit Plan</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if ($error_message): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($success_message): ?>
|
||||||
|
<div class="alert alert-success"><?php echo htmlspecialchars($success_message); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($plan): ?>
|
||||||
|
<form action="edit_plan.php?id=<?php echo htmlspecialchars($plan_id); ?>" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="name" class="form-label">Plan Name</label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($plan['name']); ?>" required>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="price" class="form-label">Price</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-text">$</span>
|
||||||
|
<input type="number" step="0.01" class="form-control" id="price" name="price" value="<?php echo htmlspecialchars($plan['price']); ?>" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="billing_cycle" class="form-label">Billing Cycle</label>
|
||||||
|
<select class="form-select" id="billing_cycle" name="billing_cycle" required>
|
||||||
|
<option value="monthly" <?php echo ($plan['billing_cycle'] === 'monthly') ? 'selected' : ''; ?>>Monthly</option>
|
||||||
|
<option value="yearly" <?php echo ($plan['billing_cycle'] === 'yearly') ? 'selected' : ''; ?>>Yearly</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="features" class="form-label">Features (one per line)</label>
|
||||||
|
<textarea class="form-control" id="features" name="features" rows="5" required><?php echo htmlspecialchars(implode("\n", json_decode($plan['features'], true))); ?></textarea>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||||
|
<a href="plans.php" class="btn btn-secondary">Cancel</a>
|
||||||
|
</form>
|
||||||
|
<?php else: ?>
|
||||||
|
<p>Plan not found.</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'templates/footer.php';
|
||||||
|
?>
|
||||||
191
index.php
191
index.php
@ -1,150 +1,47 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
$title = 'Dashboard - Billing';
|
||||||
@ini_set('display_errors', '1');
|
$page = 'dashboard';
|
||||||
@error_reporting(E_ALL);
|
require_once 'templates/header.php';
|
||||||
@date_default_timezone_set('UTC');
|
?>
|
||||||
|
|
||||||
$phpVersion = PHP_VERSION;
|
<h1 class="h2">Dashboard</h1>
|
||||||
$now = date('Y-m-d H:i:s');
|
<p class="text-muted">Here's an overview of your billing status.</p>
|
||||||
?>
|
|
||||||
<!doctype html>
|
<div class="row">
|
||||||
<html lang="en">
|
<div class="col-md-3 mb-4">
|
||||||
<head>
|
<div class="card">
|
||||||
<meta charset="utf-8" />
|
<div class="card-body">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<h5 class="card-title text-muted">Active Subscribers</h5>
|
||||||
<title>New Style</title>
|
<p class="card-text fs-2 fw-bold">1,234</p>
|
||||||
<?php
|
</div>
|
||||||
// Read project preview data from environment
|
</div>
|
||||||
$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>
|
|
||||||
</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>
|
</div>
|
||||||
</main>
|
<div class="col-md-3 mb-4">
|
||||||
<footer>
|
<div class="card">
|
||||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
<div class="card-body">
|
||||||
</footer>
|
<h5 class="card-title text-muted">MRR</h5>
|
||||||
</body>
|
<p class="card-text fs-2 fw-bold">$54,321</p>
|
||||||
</html>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 mb-4">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title text-muted">Overdue Amount</h5>
|
||||||
|
<p class="card-text fs-2 fw-bold">$5,678</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 mb-4">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title text-muted">Collection Rate</h5>
|
||||||
|
<p class="card-text fs-2 fw-bold">92%</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'templates/footer.php';
|
||||||
|
?>
|
||||||
|
|||||||
81
invoices.php
Normal file
81
invoices.php
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
$title = 'Invoices - Billing';
|
||||||
|
$page = 'invoices';
|
||||||
|
require_once 'templates/header.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="h2">Invoices</h1>
|
||||||
|
<div class="btn-toolbar mb-2 mb-md-0">
|
||||||
|
<a href="create_invoice.php" class="btn btn-sm btn-primary">
|
||||||
|
<i class="bi bi-plus-circle"></i>
|
||||||
|
Create New Invoice
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->query('SELECT invoices.*, customers.name AS customer_name FROM invoices LEFT JOIN customers ON invoices.customer_id = customers.id ORDER BY invoices.created_at DESC');
|
||||||
|
$invoices = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$status_colors = [
|
||||||
|
'Paid' => 'success',
|
||||||
|
'Pending' => 'warning',
|
||||||
|
'Overdue' => 'danger',
|
||||||
|
];
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Invoice #</th>
|
||||||
|
<th>Customer</th>
|
||||||
|
<th>Amount</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Due Date</th>
|
||||||
|
<th>Created</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($invoices)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="7" class="text-center py-5">
|
||||||
|
<i class="bi bi-journal-text" style="font-size: 3rem; color: #ccc;"></i>
|
||||||
|
<h2 class="mt-3">No Invoices Found</h2>
|
||||||
|
<p class="text-muted">There are no invoices to display yet.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($invoices as $invoice): ?>
|
||||||
|
<tr>
|
||||||
|
<td>#<?php echo htmlspecialchars($invoice['id']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($invoice['customer_name']); ?></td>
|
||||||
|
<td>$<?php echo number_format($invoice['amount'], 2); ?></td>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-<?php echo $status_colors[$invoice['status']] ?? 'secondary'; ?>">
|
||||||
|
<?php echo htmlspecialchars($invoice['status']); ?>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td><?php echo date('M d, Y', strtotime($invoice['due_date'])); ?></td>
|
||||||
|
<td><?php echo date('M d, Y', strtotime($invoice['created_at'])); ?></td>
|
||||||
|
<td>
|
||||||
|
<a href="view_invoice.php?id=<?php echo $invoice['id']; ?>" class="btn btn-sm btn-outline-secondary"><i class="bi bi-eye"></i></a>
|
||||||
|
<a href="edit_invoice.php?id=<?php echo $invoice['id']; ?>" class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil"></i></a>
|
||||||
|
<a href="delete_invoice.php?id=<?php echo $invoice['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this invoice?');"><i class="bi bi-trash"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'templates/footer.php';
|
||||||
|
?>
|
||||||
63
plans.php
Normal file
63
plans.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->query('SELECT * FROM plans ORDER BY price ASC');
|
||||||
|
$plans = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="h2">Subscription Plans</h1>
|
||||||
|
<div class="btn-toolbar mb-2 mb-md-0">
|
||||||
|
<a href="create_plan.php" class="btn btn-sm btn-primary">
|
||||||
|
<i class="bi bi-plus-circle"></i>
|
||||||
|
Add New Plan
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<?php if (empty($plans)): ?>
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="text-center py-5">
|
||||||
|
<i class="bi bi-tags" style="font-size: 4rem; color: #ccc;"></i>
|
||||||
|
<h2 class="mt-4">No Plans Found</h2>
|
||||||
|
<p class="text-muted">Please add subscription plans to see them here.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($plans as $plan): ?>
|
||||||
|
<div class="col-md-4 mb-4">
|
||||||
|
<div class="card h-100 shadow-sm">
|
||||||
|
<div class="card-header text-center">
|
||||||
|
<h4 class="my-0 fw-normal"><?php echo htmlspecialchars($plan['name']); ?></h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body d-flex flex-column">
|
||||||
|
<h1 class="card-title pricing-card-title text-center">$<?php echo number_format($plan['price'], 2); ?><small class="text-muted fw-light">/<?php echo htmlspecialchars($plan['billing_cycle']); ?></small></h1>
|
||||||
|
<ul class="list-unstyled mt-3 mb-4 flex-grow-1">
|
||||||
|
<?php
|
||||||
|
$features = json_decode($plan['features'], true);
|
||||||
|
if ($features) {
|
||||||
|
foreach ($features as $feature) {
|
||||||
|
echo '<li><i class="bi bi-check-circle-fill text-success me-2"></i>' . htmlspecialchars($feature) . '</li>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
<div class="mt-auto">
|
||||||
|
<div class="d-flex justify-content-center gap-2">
|
||||||
|
<a href="edit_plan.php?id=<?php echo $plan['id']; ?>" class="btn btn-sm btn-outline-secondary w-100"><i class="bi bi-pencil"></i> Edit</a>
|
||||||
|
<a href="delete_plan.php?id=<?php echo $plan['id']; ?>" class="btn btn-sm btn-outline-danger w-100" onclick="return confirm('Are you sure you want to delete this plan?');"><i class="bi bi-trash"></i> Delete</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'templates/footer.php';
|
||||||
|
?>
|
||||||
172
reports.php
Normal file
172
reports.php
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
<?php
|
||||||
|
$title = 'Reports - Billing';
|
||||||
|
$page = 'reports';
|
||||||
|
require_once 'templates/header.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="h2">Reports</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$pdo = db();
|
||||||
|
|
||||||
|
// Fetch stats
|
||||||
|
$total_customers = $pdo->query('SELECT COUNT(*) FROM customers')->fetchColumn();
|
||||||
|
$active_customers = $pdo->query("SELECT COUNT(*) FROM customers WHERE status = 'Active'")->fetchColumn();
|
||||||
|
$total_plans = $pdo->query('SELECT COUNT(*) FROM plans')->fetchColumn();
|
||||||
|
$total_revenue = $pdo->query("SELECT SUM(amount) FROM invoices WHERE status = 'Paid'")->fetchColumn();
|
||||||
|
|
||||||
|
$invoice_status_stmt = $pdo->query("SELECT status, COUNT(*) as count FROM invoices GROUP BY status");
|
||||||
|
$invoice_statuses = $invoice_status_stmt->fetchAll(PDO::FETCH_KEY_PAIR);
|
||||||
|
|
||||||
|
$total_invoices = array_sum($invoice_statuses);
|
||||||
|
$paid_invoices = $invoice_statuses['Paid'] ?? 0;
|
||||||
|
$pending_invoices = $invoice_statuses['Pending'] ?? 0;
|
||||||
|
$overdue_invoices = $invoice_statuses['Overdue'] ?? 0;
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3 mb-4">
|
||||||
|
<div class="card text-white bg-primary">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title"><i class="bi bi-people-fill"></i> Total Customers</h5>
|
||||||
|
<p class="card-text fs-4"><?php echo $total_customers; ?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 mb-4">
|
||||||
|
<div class="card text-white bg-success">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title"><i class="bi bi-person-check-fill"></i> Active Customers</h5>
|
||||||
|
<p class="card-text fs-4"><?php echo $active_customers; ?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 mb-4">
|
||||||
|
<div class="card text-white bg-info">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title"><i class="bi bi-tags-fill"></i> Available Plans</h5>
|
||||||
|
<p class="card-text fs-4"><?php echo $total_plans; ?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 mb-4">
|
||||||
|
<div class="card text-white bg-dark">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title"><i class="bi bi-cash-stack"></i> Total Revenue</h5>
|
||||||
|
<p class="card-text fs-4">$<?php echo number_format($total_revenue, 2); ?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mt-4">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<i class="bi bi-journal-text"></i> Invoice Status Distribution
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<canvas id="invoiceStatusChart"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mt-4">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<i class="bi bi-journal-text"></i> Generated Reports
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Report Name</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Date Generated</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
$stmt = $pdo->query('SELECT * FROM reports ORDER BY created_at DESC');
|
||||||
|
$reports = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
if (empty($reports)):
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" class="text-center py-5">
|
||||||
|
<i class="bi bi-journal-x" style="font-size: 3rem; color: #ccc;"></i>
|
||||||
|
<h2 class="mt-3">No Reports Found</h2>
|
||||||
|
<p class="text-muted">There are no generated reports to display yet.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($reports as $report): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($report['name']); ?></td>
|
||||||
|
<td><span class="badge bg-secondary"><?php echo htmlspecialchars($report['type']); ?></span></td>
|
||||||
|
<td><?php echo date('M d, Y H:i A', strtotime($report['created_at'])); ?></td>
|
||||||
|
<td>
|
||||||
|
<a href="view_report.php?id=<?php echo $report['id']; ?>" class="btn btn-sm btn-outline-primary"><i class="bi bi-eye"></i> View</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
const ctx = document.getElementById('invoiceStatusChart').getContext('2d');
|
||||||
|
new Chart(ctx, {
|
||||||
|
type: 'doughnut',
|
||||||
|
data: {
|
||||||
|
labels: ['Paid', 'Pending', 'Overdue'],
|
||||||
|
datasets: [{
|
||||||
|
label: 'Invoice Status',
|
||||||
|
data: [<?php echo $paid_invoices; ?>, <?php echo $pending_invoices; ?>, <?php echo $overdue_invoices; ?>],
|
||||||
|
backgroundColor: [
|
||||||
|
'rgba(25, 135, 84, 0.7)',
|
||||||
|
'rgba(255, 193, 7, 0.7)',
|
||||||
|
'rgba(220, 53, 69, 0.7)'
|
||||||
|
],
|
||||||
|
borderColor: [
|
||||||
|
'rgba(25, 135, 84, 1)',
|
||||||
|
'rgba(255, 193, 7, 1)',
|
||||||
|
'rgba(220, 53, 69, 1)'
|
||||||
|
],
|
||||||
|
borderWidth: 1
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
position: 'top',
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
display: false,
|
||||||
|
text: 'Invoice Status Distribution'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'templates/footer.php';
|
||||||
|
?>
|
||||||
9
templates/footer.php
Normal file
9
templates/footer.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
// templates/footer.php
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
71
templates/header.php
Normal file
71
templates/header.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
// templates/header.php
|
||||||
|
$page = $page ?? '';
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title><?php echo htmlspecialchars($title ?? 'Billing'); ?></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">
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="d-flex">
|
||||||
|
<div class="sidebar d-flex flex-column flex-shrink-0 p-3">
|
||||||
|
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-decoration-none">
|
||||||
|
<i class="bi bi-receipt-cutoff me-2"></i>
|
||||||
|
<span class="fs-4">Billing</span>
|
||||||
|
</a>
|
||||||
|
<hr>
|
||||||
|
<ul class="nav nav-pills flex-column mb-auto">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a href="/" class="nav-link <?php echo ($page === 'dashboard') ? 'active' : ''; ?>" aria-current="page">
|
||||||
|
<i class="bi bi-speedometer2 me-2"></i>
|
||||||
|
Dashboard
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="customers.php" class="nav-link <?php echo ($page === 'customers') ? 'active' : ''; ?>">
|
||||||
|
<i class="bi bi-people me-2"></i>
|
||||||
|
Customers
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="invoices.php" class="nav-link <?php echo ($page === 'invoices') ? 'active' : ''; ?>">
|
||||||
|
<i class="bi bi-journal-text me-2"></i>
|
||||||
|
Invoices
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="plans.php" class="nav-link <?php echo ($page === 'plans') ? 'active' : ''; ?>">
|
||||||
|
<i class="bi bi-tags me-2"></i>
|
||||||
|
Plans
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="reports.php" class="nav-link <?php echo ($page === 'reports') ? 'active' : ''; ?>">
|
||||||
|
<i class="bi bi-graph-up me-2"></i>
|
||||||
|
Reports
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<hr>
|
||||||
|
<div class="dropdown">
|
||||||
|
<a href="#" class="d-flex align-items-center text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
|
<img src="https://github.com/mdo.png" alt="" width="32" height="32" class="rounded-circle me-2">
|
||||||
|
<strong>mdo</strong>
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
|
||||||
|
<li><a class="dropdown-item" href="#">New project...</a></li>
|
||||||
|
<li><a class="dropdown-item" href="#">Settings</a></li>
|
||||||
|
<li><a class="dropdown-item" href="#">Profile</a></li>
|
||||||
|
<li><hr class="dropdown-divider"></li>
|
||||||
|
<li><a class="dropdown-item" href="#">Sign out</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="main-content flex-grow-1 p-4">
|
||||||
123
view_invoice.php
Normal file
123
view_invoice.php
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
$title = 'View Invoice - Billing';
|
||||||
|
$page = 'invoices';
|
||||||
|
require_once 'templates/header.php';
|
||||||
|
|
||||||
|
$invoice_id = $_GET['id'] ?? null;
|
||||||
|
$invoice = null;
|
||||||
|
|
||||||
|
if (!$invoice_id) {
|
||||||
|
header('Location: invoices.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare('
|
||||||
|
SELECT
|
||||||
|
i.*,
|
||||||
|
c.name AS customer_name, c.email AS customer_email,
|
||||||
|
p.name AS plan_name
|
||||||
|
FROM invoices i
|
||||||
|
JOIN customers c ON i.customer_id = c.id
|
||||||
|
JOIN plans p ON i.plan_id = p.id
|
||||||
|
WHERE i.id = ?
|
||||||
|
');
|
||||||
|
$stmt->execute([$invoice_id]);
|
||||||
|
$invoice = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$invoice) {
|
||||||
|
header('Location: invoices.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$error_message = 'Database error: ' . $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
$status_colors = [
|
||||||
|
'Paid' => 'success',
|
||||||
|
'Pending' => 'warning',
|
||||||
|
'Overdue' => 'danger',
|
||||||
|
];
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="h2">Invoice #<?php echo htmlspecialchars($invoice['id']); ?></h1>
|
||||||
|
<div class="btn-toolbar mb-2 mb-md-0">
|
||||||
|
<a href="edit_invoice.php?id=<?php echo $invoice['id']; ?>" class="btn btn-sm btn-outline-secondary me-2">
|
||||||
|
<i class="bi bi-pencil"></i> Edit
|
||||||
|
</a>
|
||||||
|
<button class="btn btn-sm btn-outline-primary" onclick="window.print();">
|
||||||
|
<i class="bi bi-printer"></i> Print
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if (isset($error_message)): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col-6">
|
||||||
|
<h5 class="mb-0">Invoice Details</h5>
|
||||||
|
</div>
|
||||||
|
<div class="col-6 text-end">
|
||||||
|
Status:
|
||||||
|
<span class="badge bg-<?php echo $status_colors[$invoice['status']] ?? 'secondary'; ?>">
|
||||||
|
<?php echo htmlspecialchars($invoice['status']); ?>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row mb-4">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h6>Billed To:</h6>
|
||||||
|
<p class="mb-1"><?php echo htmlspecialchars($invoice['customer_name']); ?></p>
|
||||||
|
<p class="mb-0"><?php echo htmlspecialchars($invoice['customer_email']); ?></p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 text-md-end mt-3 mt-md-0">
|
||||||
|
<h6>Invoice Info:</h6>
|
||||||
|
<p class="mb-1"><strong>Invoice #:</strong> <?php echo htmlspecialchars($invoice['id']); ?></p>
|
||||||
|
<p class="mb-1"><strong>Created Date:</strong> <?php echo date('M d, Y', strtotime($invoice['created_at'])); ?></p>
|
||||||
|
<p class="mb-0"><strong>Due Date:</strong> <?php echo date('M d, Y', strtotime($invoice['due_date'])); ?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Description</th>
|
||||||
|
<th scope="col" class="text-end">Amount</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Subscription: <?php echo htmlspecialchars($invoice['plan_name']); ?></td>
|
||||||
|
<td class="text-end">$<?php echo number_format($invoice['amount'], 2); ?></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
<tfoot class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th scope="row" class="text-end">Total:</th>
|
||||||
|
<th class="text-end">$<?php echo number_format($invoice['amount'], 2); ?></th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="text-center mt-4">
|
||||||
|
<a href="invoices.php" class="btn btn-secondary">Back to Invoices</a>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'templates/footer.php';
|
||||||
|
?>
|
||||||
111
view_report.php
Normal file
111
view_report.php
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
require_once 'templates/header.php';
|
||||||
|
|
||||||
|
$report = null;
|
||||||
|
$errors = [];
|
||||||
|
|
||||||
|
if (isset($_GET['id']) && !empty(trim($_GET['id']))) {
|
||||||
|
$report_id = trim($_GET['id']);
|
||||||
|
|
||||||
|
if (filter_var($report_id, FILTER_VALIDATE_INT) === false) {
|
||||||
|
$errors[] = "Invalid report ID.";
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$sql = "SELECT * FROM reports WHERE id = ?";
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->execute([$report_id]);
|
||||||
|
$report = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if ($report === false) {
|
||||||
|
$errors[] = "Report not found.";
|
||||||
|
$report = null;
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$errors[] = "Database error: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$errors[] = "Report ID is missing.";
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container-fluid px-4">
|
||||||
|
<?php if ($report): ?>
|
||||||
|
<h1 class="mt-4">Report: <?php echo htmlspecialchars($report['name']); ?></h1>
|
||||||
|
<ol class="breadcrumb mb-4">
|
||||||
|
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
|
||||||
|
<li class="breadcrumb-item"><a href="reports.php">Reports</a></li>
|
||||||
|
<li class="breadcrumb-item active">View</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-header">
|
||||||
|
<i class="fas fa-chart-area me-1"></i>
|
||||||
|
Report Details
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p><strong>Report Type:</strong> <?php echo htmlspecialchars($report['type']); ?></p>
|
||||||
|
<p><strong>Date Generated:</strong> <?php echo htmlspecialchars(date("F j, Y, g:i a", strtotime($report['created_at']))); ?></p>
|
||||||
|
|
||||||
|
<h5 class="mt-4">Report Data</h5>
|
||||||
|
<?php
|
||||||
|
$report_data = json_decode($report['data'], true);
|
||||||
|
if (json_last_error() === JSON_ERROR_NONE && is_array($report_data)):
|
||||||
|
?>
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th>Key</th>
|
||||||
|
<th>Value</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($report_data as $key => $value): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($key); ?></td>
|
||||||
|
<td>
|
||||||
|
<?php
|
||||||
|
if (is_array($value) || is_object($value)) {
|
||||||
|
echo '<pre>' . htmlspecialchars(json_encode($value, JSON_PRETTY_PRINT)) . '</pre>';
|
||||||
|
} else {
|
||||||
|
echo htmlspecialchars($value);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="alert alert-warning">Could not decode report data or data is empty.</div>
|
||||||
|
<pre><?php echo htmlspecialchars($report['data']); ?></pre>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php else: ?>
|
||||||
|
<h1 class="mt-4">Error</h1>
|
||||||
|
<ol class="breadcrumb mb-4">
|
||||||
|
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
|
||||||
|
<li class="breadcrumb-item"><a href="reports.php">Reports</a></li>
|
||||||
|
<li class="breadcrumb-item active">Error</li>
|
||||||
|
</ol>
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($errors as $error): ?>
|
||||||
|
<li><?php echo htmlspecialchars($error); ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<a href="reports.php" class="btn btn-secondary">
|
||||||
|
<i class="fas fa-arrow-left me-1"></i>
|
||||||
|
Back to Reports
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php require_once 'templates/footer.php'; ?>
|
||||||
Loading…
x
Reference in New Issue
Block a user