diff --git a/db/migrations/003_create_invoices_table.sql b/db/migrations/003_create_invoices_table.sql new file mode 100644 index 0000000..8e93969 --- /dev/null +++ b/db/migrations/003_create_invoices_table.sql @@ -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 +); diff --git a/db/migrations/004_create_reports_table.sql b/db/migrations/004_create_reports_table.sql new file mode 100644 index 0000000..be70949 --- /dev/null +++ b/db/migrations/004_create_reports_table.sql @@ -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 +); diff --git a/db/seed.php b/db/seed.php index 4ec4c4b..cb8e0b2 100644 --- a/db/seed.php +++ b/db/seed.php @@ -59,7 +59,80 @@ function seed_plans() { } } +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(); + + diff --git a/invoices.php b/invoices.php index 939dee0..3e2a25a 100644 --- a/invoices.php +++ b/invoices.php @@ -14,10 +14,65 @@ require_once 'templates/header.php'; -
The invoices management page is under construction.
+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', +]; + +?> + +| Invoice # | +Customer | +Amount | +Status | +Due Date | +Created | +Action | +
|---|---|---|---|---|---|---|
+
+ No Invoices Found+There are no invoices to display yet. + |
+ ||||||
| # | ++ | $ | ++ + + + | ++ | + | + + + | +
The reports and analytics page is under construction.
+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; + +?> + +$
+| Report Name | +Type | +Date Generated | +Actions | +
|---|---|---|---|
+
+ No Reports Found+There are no generated reports to display yet. + |
+ |||
| + | + | + | + + | +