-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer_master.php
More file actions
96 lines (90 loc) · 4.62 KB
/
customer_master.php
File metadata and controls
96 lines (90 loc) · 4.62 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
93
94
95
96
<?php
// customer_master.php
include 'header.php';
include 'sidebar.php';
// --- Search Logic ---
$search_term = isset($_GET['search']) ? trim($_GET['search']) : '';
$sql = "SELECT * FROM customers";
if (!empty($search_term)) {
$search_like = "%" . $search_term . "%";
// Search by customer name or contact number
$sql .= " WHERE customer_name LIKE ? OR contact_no LIKE ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $search_like, $search_like);
$stmt->execute();
$result = $stmt->get_result();
} else {
$sql .= " ORDER BY id DESC";
$result = $conn->query($sql);
}
?>
<!-- Main Content -->
<div class="bg-white p-8 rounded-lg shadow-md w-full">
<div class="flex justify-between items-center mb-6">
<h4 class="text-2xl font-bold text-gray-700">Customer Master</h4>
<?php if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'customer'): ?>
<a href="customer_add.php"
class="bg-pink-600 hover:bg-pink-700 text-white font-bold py-2 px-4 rounded flex items-center">
<i class="fas fa-plus mr-2"></i> Add Customer
</a>
<?php endif; ?>
</div>
<!-- Search Form -->
<div class="mb-6 flex justify-end">
<form action="customer_master.php" method="GET" class="flex items-center">
<label for="search" class="mr-2 text-gray-600">Search:</label>
<input type="text" name="search" id="search" value="<?php echo htmlspecialchars($search_term); ?>"
class="shadow-sm border rounded py-2 px-3 text-gray-700 focus:outline-none focus:ring-2 focus:ring-pink-500"
placeholder="Search...">
<button type="submit" class="ml-2 bg-pink-600 hover:bg-pink-700 text-white font-bold py-2 px-4 rounded">
<i class="fas fa-search"></i>
</button>
</form>
</div>
<!-- Data Table -->
<div class="overflow-x-auto">
<table class="min-w-full bg-white">
<thead class="bg-gray-200 text-gray-600 uppercase text-sm leading-normal">
<tr>
<th class="py-3 px-6 text-left">SRNO</th>
<th class="py-3 px-6 text-left">Customer</th>
<th class="py-3 px-6 text-left">Contact No</th>
<th class="py-3 px-6 text-center">Status</th>
<th class="py-3 px-6 text-center">Actions</th>
</tr>
</thead>
<tbody class="text-gray-600 text-sm font-light">
<?php
if ($result && $result->num_rows > 0) {
$sr_no = 1;
while ($row = $result->fetch_assoc()) {
$status_color = $row['status'] == 'Enable' ? 'bg-green-200 text-green-800' : 'bg-red-200 text-red-800';
echo "<tr class='border-b border-gray-200 hover:bg-gray-100'>";
echo "<td class='py-3 px-6 text-left'>" . $sr_no++ . "</td>";
echo "<td class='py-3 px-6 text-left'>" . htmlspecialchars($row["customer_name"]) . "</td>";
echo "<td class='py-3 px-6 text-left'>" . htmlspecialchars($row["contact_no"]) . "</td>";
echo "<td class='py-3 px-6 text-center'><span class='py-1 px-3 rounded-full text-xs " . $status_color . "'>" . htmlspecialchars($row["status"]) . "</span></td>";
echo "<td class='py-3 px-6 text-center'>";
echo "<div class='flex item-center justify-center'>";
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'customer') {
echo "<a href='customer_edit.php?id=" . $row['id'] . "' class='w-4 mr-2 transform hover:text-purple-500 hover:scale-110' title='Edit'><i class='fas fa-pencil-alt'></i></a>";
echo "<a href='customer_delete.php?id=" . $row['id'] . "' onclick='return confirm(\"Are you sure you want to delete this customer?\");' class='w-4 mr-2 transform hover:text-red-500 hover:scale-110' title='Delete'><i class='fas fa-trash-alt'></i></a>";
} else {
echo "<a href='#' class='w-4 mr-2 text-gray-400' title='View only'><i class='fas fa-eye'></i></a>";
}
echo "</div>";
echo "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='5' class='text-center py-4'>No customers found.</td></tr>";
}
$conn->close();
?>
</tbody>
</table>
</div>
</div>
<?php
include 'footer.php';
?>