-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer_select.php
More file actions
92 lines (83 loc) · 4.08 KB
/
Copy pathcustomer_select.php
File metadata and controls
92 lines (83 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
require_once 'includes/config.php';
require_once 'includes/functions.php';
require_login();
try {
$pdo = new PDO(
"mysql:host=" . DB_HOST . ";dbname=" . DB_NAME,
DB_USER,
DB_PASS
);
// Get all customers
$stmt = $pdo->query("SELECT * FROM customers ORDER BY company_name");
$customers = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$error = "Could not retrieve customers";
}
$page_title = 'Select Customer';
require_once 'includes/header.php';
require_once 'includes/topbar.php';
require_once 'includes/sidebar.php';
?>
<div class="page-wrapper">
<div class="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="page-title-box d-md-flex justify-content-md-between align-items-center">
<h4 class="page-title">Select Customer for New Invoice</h4>
<div class="">
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a>
</li><!--end nav-item-->
<li class="breadcrumb-item active">Invoices</li>
</ol>
</div>
</div><!--end page-title-box-->
<?php if (isset($error)): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php else: ?>
<div class="card">
<div class="card-header">
<div class="row align-items-center">
<div class="col">
<input type="text" class="form-control" id="customerSearch"
placeholder="Search customers..." autofocus>
</div>
<div class="col-auto">
<a href="customer_add.php" class="btn btn-primary">Add New Customer</a>
</div>
</div>
</div>
<div class="list-group list-group-flush" id="customerList">
<?php foreach ($customers as $customer): ?>
<a href="invoice_create.php?customer_id=<?php echo $customer['id']; ?>"
class="list-group-item list-group-item-action customer-item">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1"><?php echo htmlspecialchars($customer['company_name']); ?></h5>
<small><?php echo htmlspecialchars($customer['city']); ?></small>
</div>
<p class="mb-1"><?php echo htmlspecialchars($customer['contact_name']); ?></p>
<small><?php echo htmlspecialchars($customer['email']); ?></small>
</a>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<script>
// Live search functionality
document.getElementById('customerSearch').addEventListener('keyup', function() {
const searchText = this.value.toLowerCase();
const customers = document.getElementsByClassName('customer-item');
Array.from(customers).forEach(function(customer) {
const text = customer.textContent.toLowerCase();
customer.style.display = text.includes(searchText) ? '' : 'none';
});
});
</script>
<?php require_once 'includes/footer.php'; ?>