Auto commit: 2025-10-26T16:47:49.778Z

This commit is contained in:
Flatlogic Bot 2025-10-26 16:47:49 +00:00
parent 8daee549e1
commit 6236799760
6 changed files with 317 additions and 6 deletions

109
create_customer.php Normal file
View 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
View 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
View 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'; ?>

View File

@ -18,10 +18,10 @@ try {
<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">
<button type="button" class="btn btn-sm btn-primary">
<a href="create_customer.php" class="btn btn-sm btn-primary">
<i class="bi bi-plus-circle"></i>
Add New Customer
</button>
</a>
</div>
</div>

View File

@ -7,10 +7,10 @@ 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">
<a href="create_invoice.php" class="btn btn-sm btn-primary">
<i class="bi bi-plus-circle"></i>
Create New Invoice
</button>
</a>
</div>
</div>

View File

@ -10,10 +10,10 @@ $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">
<a href="create_plan.php" class="btn btn-sm btn-primary">
<i class="bi bi-plus-circle"></i>
Add New Plan
</button>
</a>
</div>
</div>