s22
This commit is contained in:
@@ -11,39 +11,86 @@
|
||||
<th>Name</th>
|
||||
<th>Mobile</th>
|
||||
<th>Email</th>
|
||||
<th>Invoice Id</th>
|
||||
<th>Invoice Date</th>
|
||||
<th>Amount</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
try {
|
||||
// Connect to the database
|
||||
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
// Fetch customer data
|
||||
$stmt = $db->prepare("SELECT * FROM customers ORDER BY regDate DESC");
|
||||
$stmt->execute();
|
||||
$content = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$customerSerial = 1; // Moved outside loop
|
||||
// Fetch invoice data
|
||||
$stmt2 = $db->prepare("SELECT * FROM invoice");
|
||||
$stmt2->execute();
|
||||
$invoiceContent = $stmt2->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Loop through each customer
|
||||
$customerSerial = 1;
|
||||
foreach ($content as $customer) {
|
||||
// Find all invoices for the current customer
|
||||
$matchingInvoices = array_filter($invoiceContent, function ($invoice) use ($customer) {
|
||||
return $invoice['customerId'] === $customer['customerId'];
|
||||
});
|
||||
|
||||
// If there are matching invoices, loop through them
|
||||
if (!empty($matchingInvoices)) {
|
||||
foreach ($matchingInvoices as $invoice) {
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $customerSerial++; ?></td>
|
||||
<td><?php echo htmlspecialchars($customer['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($customer['mobile']); ?></td>
|
||||
<td><?php echo htmlspecialchars($customer['email']); ?></td>
|
||||
<td>
|
||||
<a href="/customers/edit/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Edit</a>
|
||||
<a href="/customers/generate-invoice/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Invoice</a>
|
||||
<a href="/customers/billing-details/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Installment Details</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php echo $customerSerial++; ?></td>
|
||||
<td><?php echo htmlspecialchars($customer['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($customer['mobile']); ?></td>
|
||||
<td><?php echo htmlspecialchars($customer['email']); ?></td>
|
||||
|
||||
<!-- Invoice Data -->
|
||||
<td><?php echo htmlspecialchars($invoice['invoiceId']); ?></td>
|
||||
<td><?php echo htmlspecialchars($invoice['invoiceDate']); ?></td>
|
||||
<td><?php echo htmlspecialchars($invoice['totalAmount']); ?></td>
|
||||
|
||||
<td>
|
||||
<a href="/customers/edit/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Edit</a>
|
||||
<a href="/customers/generate-invoice/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Create Invoice</a>
|
||||
<a href="/customers/billing-details/?customerId=<?php echo $customer['customerId'] . '&invoiceId=' . $invoice['invoiceId']; ?>" class="btn btn-primary btn-sm">EMI Details</a>
|
||||
<a href="/customers/print-invoice/?customerId=<?php echo $customer['customerId'] . '&invoiceId=' . $invoice['invoiceId']; ?>" class="btn btn-primary btn-sm">Print</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
// For customers without an invoice, you can still display their info but leave invoice data empty
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $customerSerial++; ?></td>
|
||||
<td><?php echo htmlspecialchars($customer['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($customer['mobile']); ?></td>
|
||||
<td><?php echo htmlspecialchars($customer['email']); ?></td>
|
||||
<td colspan="3">No invoice available</td>
|
||||
<td>
|
||||
<a href="/customers/edit/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Edit</a>
|
||||
<a href="/customers/generate-invoice/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Create Invoice</a>
|
||||
<a href="/customers/billing-details/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">EMI Details</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo '<tr><td colspan="5" class="text-danger text-center">Error: ' . $e->getMessage() . '</td></tr>';
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user