-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer.php
More file actions
270 lines (245 loc) · 13.3 KB
/
Copy pathcustomer.php
File metadata and controls
270 lines (245 loc) · 13.3 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Include your db connection script
include('db.php');
// Fetch customer ID from URL
$customer_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
// If no customer ID is provided, redirect to customers list
if ($customer_id === 0) {
header('Location: customers.php');
exit();
}
// Fetch customer details from database
$sql = "SELECT * FROM customers WHERE id = $customer_id AND deleted_at IS NULL";
$result = $conn->query($sql);
if ($result->num_rows == 0) {
echo "Customer not found!";
exit();
}
$customer = $result->fetch_assoc();
// Fetch quotes for this customer
$account_number = $customer['account_number'];
$quotes_sql = "SELECT q.id, q.company_name, q.created_at,
(SELECT SUM(total_price) FROM quote_items WHERE quote_id = q.id) AS total_price,
q.status
FROM quotes q
WHERE q.account_number = '$account_number'";
$quotes_result = $conn->query($quotes_sql);
// Include header
include 'header.php';
?>
<title><?= htmlspecialchars($customer['company_name']) ?> - <?= htmlspecialchars($customer['contact_name']) ?></title>
<style>
.card-header {
background-color: #007bff; /* Blue background for header */
color: white; /* White text for contrast */
}
.card-body {
text-align: left;
background-color: #f8f9fa; /* Light background for card body */
color: #333; /* Dark text color for body */
}
.card {
margin-bottom: 1rem; /* Space between cards */
}
.status-pending { color: orange; }
.status-approved { color: green; }
.status-rejected { color: red; }
.status-completed { color: blue; }
</style>
<?php include 'nav.php'; ?>
<body>
<div class="container mt-5">
<h2 class="mb-4"><i class="fas fa-building"></i> Customer: <?= htmlspecialchars($customer['company_name']) ?></h2>
<!-- Customer Added Date -->
<div class="alert alert-info mb-4">
<i class="fas fa-calendar-alt"></i> <strong>Customer Added:</strong> <?= date('F j, Y, g:i a', strtotime($customer['created_at'])) ?>
</div>
<!-- Nav tabs -->
<ul class="nav nav-tabs mb-4" id="customerTabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="info-tab" data-bs-toggle="tab" href="#info" role="tab" aria-controls="info" aria-selected="true"><i class="fas fa-info-circle"></i> Info</a>
</li>
<li class="nav-item">
<a class="nav-link" id="quotes-tab" data-bs-toggle="tab" href="#quotes" role="tab" aria-controls="quotes" aria-selected="false"><i class="fas fa-file-alt"></i> Quotes</a>
</li>
<li class="nav-item">
<a class="nav-link" id="invoices-tab" data-bs-toggle="tab" href="#invoices" role="tab" aria-controls="invoices" aria-selected="false"><i class="fas fa-file-invoice"></i> Invoices</a>
</li>
</ul>
<!-- Tab content -->
<div class="tab-content">
<!-- Info Tab -->
<div class="tab-pane fade show active" id="info" role="tabpanel" aria-labelledby="info-tab">
<div class="row">
<!-- Customer Info Card -->
<div class="col-md-4 mb-3">
<div class="card shadow-sm">
<div class="card-header">
<i class="fas fa-building"></i> Customer Info
</div>
<div class="card-body">
<p class="mb-1"><strong>Account:</strong> <?= htmlspecialchars($customer['account_number']) ?></p>
<p class="mb-1"><strong>Company:</strong> <?= htmlspecialchars($customer['company_name']) ?></p>
<p class="mb-1"><strong>Address:</strong> <?= htmlspecialchars($customer['address']) ?>, <?= htmlspecialchars($customer['city']) ?>, <?= htmlspecialchars($customer['state']) ?>, <?= htmlspecialchars($customer['zip']) ?>, <?= htmlspecialchars($customer['country']) ?></p>
</div>
</div>
</div>
<!-- Contact Info Card -->
<div class="col-md-4 mb-3">
<div class="card shadow-sm">
<div class="card-header">
<i class="fas fa-user"></i> Contact Info
</div>
<div class="card-body">
<p class="mb-1"><strong>Name:</strong> <?= htmlspecialchars($customer['contact_name']) ?></p>
<p class="mb-1"><strong>Position:</strong> <?= htmlspecialchars($customer['contact_position']) ?></p>
<p class="mb-1"><strong>Email:</strong> <a href="mailto:<?= htmlspecialchars($customer['contact_email']) ?>"><?= htmlspecialchars($customer['contact_email']) ?></a></p>
<p class="mb-1"><strong>Phone:</strong> <a href="tel:<?= htmlspecialchars($customer['contact_phone']) ?>"><?= htmlspecialchars($customer['contact_phone']) ?></a></p>
</div>
</div>
</div>
<!-- Options Card -->
<div class="col-md-4 mb-3">
<div class="card shadow-sm">
<div class="card-header">
<i class="fas fa-cogs"></i> Options
</div>
<div class="card-body">
<p class="mb-1"><strong>Features:</strong></p>
<p>
<?php
$options = explode(',', $customer['options']);
foreach ($options as $option) {
echo '<span class="badge bg-secondary me-1">' . htmlspecialchars(trim($option)) . '</span>';
}
?>
</p>
</div>
</div>
</div>
</div>
<div class="row">
<!-- Reference Card -->
<div class="col-md-6 mb-3">
<div class="card shadow-sm">
<div class="card-header">
<i class="fas fa-sticky-note"></i> Reference
</div>
<div class="card-body">
<p><?= htmlspecialchars($customer['reference']) ?></p>
</div>
</div>
</div>
<!-- Communication Card -->
<div class="col-md-6 mb-3">
<div class="card shadow-sm">
<div class="card-header">
<i class="fas fa-envelope"></i> Communication
</div>
<div class="card-body">
<p class="mb-1"><strong>Email:</strong> <a href="mailto:<?= htmlspecialchars($customer['email']) ?>"><?= htmlspecialchars($customer['email']) ?></a></p>
<p class="mb-1"><strong>Landline:</strong> <a href="tel:<?= htmlspecialchars($customer['landline']) ?>"><?= htmlspecialchars($customer['landline']) ?></a></p>
<p class="mb-1"><strong>Mobile:</strong> <a href="tel:<?= htmlspecialchars($customer['mobile']) ?>"><?= htmlspecialchars($customer['mobile']) ?></a></p>
<p class="mb-1"><strong>Website:</strong> <a href="<?= htmlspecialchars($customer['website']) ?>" target="_blank"><?= htmlspecialchars($customer['website']) ?></a></p>
</div>
</div>
</div>
</div>
</div>
<!-- Quotes Tab -->
<div class="tab-pane fade" id="quotes" role="tabpanel" aria-labelledby="quotes-tab">
<div class="card shadow-sm">
<div class="card-header">
<i class="fas fa-file-alt"></i> Quotes
</div>
<div class="card-body">
<?php if ($quotes_result->num_rows > 0): ?>
<table class="table table-striped">
<thead>
<tr>
<th style="width: 5%;">QTE #</th>
<th style="width: 50%;">Products</th>
<th style="width: 10%;">Quote Total</th>
<th style="width: 15%;">Quote Date</th>
<th style="width: 10%;">Status</th>
</tr>
</thead>
<tbody>
<?php while ($quote = $quotes_result->fetch_assoc()): ?>
<tr>
<td>
<center><a href="quote_details.php?id=<?= $quote['id'] ?>"><?= htmlspecialchars($quote['id']) ?></a></center>
</td>
<td>
<?php
// Fetch quote items for this quote
$quote_items_sql = "SELECT product_name, quantity, total_price FROM quote_items WHERE quote_id = " . $quote['id'];
$quote_items_result = $conn->query($quote_items_sql);
if ($quote_items_result->num_rows > 0) {
$products = [];
while ($item = $quote_items_result->fetch_assoc()) {
$products[] = htmlspecialchars($item['product_name']) . " (Qty: " . $item['quantity'] . ", Total: $" . number_format($item['total_price'], 2) . ")";
}
echo implode('<br>', $products);
} else {
echo "No products found.";
}
?>
</td>
<td>$<?= number_format($quote['total_price'], 2) ?></td>
<td><?= date('F j, Y', strtotime($quote['created_at'])) ?></td>
<td>
<?php
$statusClass = '';
$icon = '';
switch ($quote['status']) {
case 'Pending':
$statusClass = 'status-pending';
$icon = '<i class="fas fa-clock"></i>';
break;
case 'Approved':
$statusClass = 'status-approved';
$icon = '<i class="fas fa-check-circle"></i>';
break;
case 'Rejected':
$statusClass = 'status-rejected';
$icon = '<i class="fas fa-times-circle"></i>';
break;
case 'Completed':
$statusClass = 'status-completed';
$icon = '<i class="fas fa-clipboard-check"></i>';
break;
}
?>
<span class="<?= $statusClass ?>">
<?= $icon ?> <?= htmlspecialchars($quote['status']) ?>
</span>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php else: ?>
<p>No quotes available for this customer.</p>
<?php endif; ?>
</div>
</div>
</div>
<!-- Invoices Tab -->
<div class="tab-pane fade" id="invoices" role="tabpanel" aria-labelledby="invoices-tab">
<div class="card shadow-sm">
<div class="card-header">
<i class="fas fa-file-invoice"></i> Invoices
</div>
<div class="card-body">
<p>Here, we will display customer-related invoices in the future.</p>
</div>
</div>
</div>
</div>
</div>
<?php include 'footer.php'; ?>
<?php $conn->close(); ?>