Auto commit: 2025-10-26T16:34:12.063Z

This commit is contained in:
Flatlogic Bot 2025-10-26 16:34:12 +00:00
parent c1d245a403
commit 4f6f10c21f
9 changed files with 336 additions and 218 deletions

View File

@ -1,112 +1,73 @@
<?php <?php
require_once 'db/config.php'; require_once 'db/config.php';
$title = 'Customers - Billing';
$page = 'customers';
require_once 'templates/header.php';
try { try {
$pdo = db(); $pdo = db();
$stmt = $pdo->query('SELECT id, name, email, plan, status FROM customers ORDER BY id'); $stmt = $pdo->query('SELECT id, name, email, status, created_at FROM customers ORDER BY created_at DESC');
$customers = $stmt->fetchAll(); $customers = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) { } catch (PDOException $e) {
// For development, you might want to log this error or display a generic message $customers = [];
// For production, log the error and show a user-friendly message. $error_message = "Error: Could not fetch customer data.";
error_log('Database error: ' . $e->getMessage());
$customers = []; // Ensure $customers is an empty array on error
// Optionally, set an error message to display to the user
$errorMessage = 'Could not retrieve customer data. Please try again later.';
}
function getStatusBadgeClass($status) {
switch (strtolower($status)) {
case 'active':
return 'bg-success';
case 'suspended':
return 'bg-warning text-dark';
case 'deactivated':
return 'bg-danger';
default:
return 'bg-secondary';
}
} }
?> ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Customers - CableCRM</title>
<meta name="description" content="Customer Management for CableCRM">
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<div class="sidebar"> <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h4 class="p-2 mb-4">CableCRM</h4> <h1 class="h2">Customers</h1>
<ul class="nav flex-column"> <div class="btn-toolbar mb-2 mb-md-0">
<li class="nav-item"> <button type="button" class="btn btn-sm btn-primary">
<a class="nav-link" href="index.php"><i class="bi bi-grid-1x2-fill"></i> Dashboard</a> <i class="bi bi-plus-circle"></i>
</li> Add New Customer
<li class="nav-item"> </button>
<a class="nav-link active" href="customers.php"><i class="bi bi-people-fill"></i> Customers</a> </div>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="bi bi-receipt"></i> Invoices</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="bi bi-box-seam"></i> Plans</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="bi bi-bar-chart-fill"></i> Reports</a>
</li>
</ul>
</div> </div>
<div class="main-content"> <?php if (isset($error_message)): ?>
<div class="container-fluid"> <div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Customers</h1>
<button class="btn btn-primary"><i class="bi bi-plus-circle-fill me-2"></i>Add Customer</button>
</div>
<?php if (isset($errorMessage)): ?>
<div class="alert alert-danger" role="alert">
<?php echo htmlspecialchars($errorMessage); ?>
</div>
<?php endif; ?> <?php endif; ?>
<div class="card">
<div class="card-body">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
<thead> <thead>
<tr> <tr>
<th>ID</th> <th scope="col">#</th>
<th>Name</th> <th scope="col">Name</th>
<th>Email</th> <th scope="col">Email</th>
<th>Plan</th> <th scope="col">Status</th>
<th>Status</th> <th scope="col">Registered</th>
<th>Actions</th> <th scope="col">Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php if (empty($customers) && !isset($errorMessage)): ?> <?php if (empty($customers)): ?>
<tr> <tr>
<td colspan="6" class="text-center">No customers found.</td> <td colspan="6" class="text-center">No customers found.</td>
</tr> </tr>
<?php else: ?> <?php else: ?>
<?php foreach ($customers as $customer): ?> <?php foreach ($customers as $customer): ?>
<tr> <tr>
<td>CUST-<?php echo str_pad($customer['id'], 3, '0', STR_PAD_LEFT); ?></td> <td><?php echo htmlspecialchars($customer['id']); ?></td>
<td><?php echo htmlspecialchars($customer['name']); ?></td> <td><?php echo htmlspecialchars($customer['name']); ?></td>
<td><?php echo htmlspecialchars($customer['email']); ?></td> <td><?php echo htmlspecialchars($customer['email']); ?></td>
<td><?php echo htmlspecialchars($customer['plan']); ?></td>
<td><span class="badge <?php echo getStatusBadgeClass($customer['status']); ?>"><?php echo htmlspecialchars(ucfirst($customer['status'])); ?></span></td>
<td> <td>
<button class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil-fill"></i></button> <?php
<button class="btn btn-sm btn-outline-danger"><i class="bi bi-trash-fill"></i></button> $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>
<button class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil"></i></button>
<button class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
@ -114,14 +75,7 @@ function getStatusBadgeClass($status) {
</tbody> </tbody>
</table> </table>
</div> </div>
</div>
</div>
</div>
</div>
<!-- Bootstrap 5 JS --> <?php
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> require_once 'templates/footer.php';
<!-- Custom JS --> ?>
<script src="assets/js/main.js"></script>
</body>
</html>

View 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
);

View File

@ -23,5 +23,43 @@ function seed_customers() {
} }
} }
seed_customers(); 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";
}
}
}
seed_customers();
seed_plans();

125
index.php
View File

@ -1,110 +1,47 @@
<!DOCTYPE html> <?php
<html lang="en"> $title = 'Dashboard - Billing';
<head> $page = 'dashboard';
<meta charset="UTF-8"> require_once 'templates/header.php';
<meta name="viewport" content="width=device-width, initial-scale=1.0"> ?>
<title>Cablecrm</title>
<meta name="description" content="Built with Flatlogic Generator">
<meta name="keywords" content="cable tv billing, crm, subscription management, invoice generator, customer management, billing dashboard, postpaid billing, revenue reporting, flatlogic generator">
<meta property="og:title" content="Cablecrm">
<meta property="og:description" content="Built with Flatlogic Generator">
<meta property="og:image" content="">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="">
<!-- Bootstrap 5 CSS --> <h1 class="h2">Dashboard</h1>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> <p class="text-muted">Here's an overview of your billing status.</p>
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<div class="sidebar"> <div class="row">
<h4 class="p-2 mb-4">CableCRM</h4> <div class="col-md-3 mb-4">
<ul class="nav flex-column"> <div class="card">
<li class="nav-item"> <div class="card-body">
<a class="nav-link active" href="index.php"><i class="bi bi-grid-1x2-fill"></i> Dashboard</a> <h5 class="card-title text-muted">Active Subscribers</h5>
</li> <p class="card-text fs-2 fw-bold">1,234</p>
<li class="nav-item">
<a class="nav-link" href="customers.php"><i class="bi bi-people-fill"></i> Customers</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="bi bi-receipt"></i> Invoices</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="bi bi-box-seam"></i> Plans</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="bi bi-bar-chart-fill"></i> Reports</a>
</li>
</ul>
</div>
<div class="main-content">
<div class="container-fluid">
<h1 class="mb-4">Dashboard Overview</h1>
<div class="row g-4">
<!-- KPI Card: Active Subscribers -->
<div class="col-md-6 col-xl-3">
<div class="kpi-card d-flex justify-content-between align-items-center">
<div>
<h5>Active Subscribers</h5>
<span class="value">1,425</span>
</div>
<div class="icon">
<i class="bi bi-person-check-fill"></i>
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-3 mb-4">
<!-- KPI Card: Monthly Recurring Revenue (MRR) --> <div class="card">
<div class="col-md-6 col-xl-3"> <div class="card-body">
<div class="kpi-card d-flex justify-content-between align-items-center"> <h5 class="card-title text-muted">MRR</h5>
<div> <p class="card-text fs-2 fw-bold">$54,321</p>
<h5>MRR</h5>
<span class="value">$25,800</span>
</div>
<div class="icon">
<i class="bi bi-cash-stack"></i>
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-3 mb-4">
<!-- KPI Card: Overdue Amount --> <div class="card">
<div class="col-md-6 col-xl-3"> <div class="card-body">
<div class="kpi-card d-flex justify-content-between align-items-center"> <h5 class="card-title text-muted">Overdue Amount</h5>
<div> <p class="card-text fs-2 fw-bold">$5,678</p>
<h5>Overdue Amount</h5>
<span class="value">$1,240</span>
</div>
<div class="icon">
<i class="bi bi-exclamation-triangle-fill"></i>
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-3 mb-4">
<!-- KPI Card: Collection Rate --> <div class="card">
<div class="col-md-6 col-xl-3"> <div class="card-body">
<div class="kpi-card d-flex justify-content-between align-items-center"> <h5 class="card-title text-muted">Collection Rate</h5>
<div> <p class="card-text fs-2 fw-bold">92%</p>
<h5>Collection Rate</h5>
<span class="value">95.4%</span>
</div>
<div class="icon">
<i class="bi bi-pie-chart-fill"></i>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- Bootstrap 5 JS --> <?php
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> require_once 'templates/footer.php';
<!-- Custom JS --> ?>
<script src="assets/js/main.js"></script>
</body>
</html>

25
invoices.php Normal file
View File

@ -0,0 +1,25 @@
<?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">
<button type="button" class="btn btn-sm btn-primary">
<i class="bi bi-plus-circle"></i>
Create New Invoice
</button>
</div>
</div>
<div class="text-center py-5">
<i class="bi bi-journal-text" style="font-size: 4rem; color: #ccc;"></i>
<h2 class="mt-4">Coming Soon</h2>
<p class="text-muted">The invoices management page is under construction.</p>
</div>
<?php
require_once 'templates/footer.php';
?>

58
plans.php Normal file
View File

@ -0,0 +1,58 @@
<?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">
<button type="button" class="btn btn-sm btn-primary">
<i class="bi bi-plus-circle"></i>
Add New Plan
</button>
</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>
<button type="button" class="w-100 btn btn-lg btn-outline-primary">Sign up</button>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php
require_once 'templates/footer.php';
?>

19
reports.php Normal file
View File

@ -0,0 +1,19 @@
<?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>
<div class="text-center py-5">
<i class="bi bi-graph-up" style="font-size: 4rem; color: #ccc;"></i>
<h2 class="mt-4">Coming Soon</h2>
<p class="text-muted">The reports and analytics page is under construction.</p>
</div>
<?php
require_once 'templates/footer.php';
?>

9
templates/footer.php Normal file
View 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>

70
templates/header.php Normal file
View File

@ -0,0 +1,70 @@
<?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">
<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">