Suvodip 2025-03-07 17:49:48 +05:30
parent 881c48d5bb
commit e97d30ce72
1 changed files with 45 additions and 32 deletions

View File

@ -1,11 +1,11 @@
<?php <?php
require('../.hta_config/conf.php'); require('../.hta_config/conf.php');
?> ?>
<div class="container mt-4"> <div class="container-xxl mt-4">
<h2 class="mb-3 text-center">Customer List</h2> <h3 class="mb-3 ">Customer List</h3><hr>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-bordered table-striped table-hover"> <table class="table table-bordered table-striped table-hover w-100" style="font-size: 12px;">
<thead class="bg-primary text-white text-center" style="font-size: 12px;"> <thead class="bg-primary text-white text-center" >
<tr> <tr>
<th>Sl No</th> <th>Sl No</th>
<th>Name</th> <th>Name</th>
@ -14,7 +14,7 @@
<th>Number of Installments</th> <th>Number of Installments</th>
<th>Monthly Payment Date</th> <th>Monthly Payment Date</th>
<th>Monthly Payment Amount</th> <th>Monthly Payment Amount</th>
<th>Totoal Amount</th> <th>Total Amount</th>
<th>Action</th> <th>Action</th>
</tr> </tr>
</thead> </thead>
@ -30,6 +30,11 @@
$stmt->execute(); $stmt->execute();
$content = $stmt->fetchAll(PDO::FETCH_ASSOC); $content = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch EMI data
$stmt = $db->prepare("SELECT * FROM emi ORDER BY invoiceId ASC");
$stmt->execute();
$emiContent = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch invoice data // Fetch invoice data
$stmt2 = $db->prepare("SELECT * FROM invoice"); $stmt2 = $db->prepare("SELECT * FROM invoice");
$stmt2->execute(); $stmt2->execute();
@ -46,25 +51,42 @@
// If there are matching invoices, loop through them // If there are matching invoices, loop through them
if (!empty($matchingInvoices)) { if (!empty($matchingInvoices)) {
foreach ($matchingInvoices as $invoice) { foreach ($matchingInvoices as $invoice) {
// Find corresponding EMI records for this invoice
$matchingEMIs = array_filter($emiContent, function ($emi) use ($invoice) {
return $emi['invoiceId'] === $invoice['invoiceId'];
});
// If EMI exists, use its data; otherwise, display empty fields
// $emi = reset($matchingEMIs) ?: [];
$matchingEmis = array_filter($emiContent, function ($emi) use ($invoice) {
return $emi['invoiceId'] === $invoice['invoiceId'];
});
if (!empty($matchingEmis)) {
$emi = reset($matchingEmis); // Get the first matching EMI record safely
} else {
$emi = [];
}
?> ?>
<tr> <tr>
<td><?php echo $customerSerial++; ?></td> <td><?php echo $customerSerial++; ?></td>
<td><a href="/customers/billing-details/?customerId=<?php echo $customer['customerId'] . '&invoiceId=' . $invoice['invoiceId']; ?>"><?php echo htmlspecialchars($customer['name']); ?></a></td>
<td>$<?php echo htmlspecialchars($invoice['totalAmount']); ?></td>
<td><?php echo htmlspecialchars($invoice['tenure']); ?></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> <td>
<!-- <a href="/customers/edit/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Edit</a> --> <a href="/customers/billing-details/?customerId=<?php echo $customer['customerId'] . '&invoiceId=' . $invoice['invoiceId']; ?>">
<a href="/customers/generate-invoice/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">New Invoice</a> <?php echo htmlspecialchars($customer['name']); ?>
<a href="/customers/edit-invoice/?customerId=<?php echo $customer['customerId'].'&invoiceId='.$invoice['invoiceId']; ?>" class="btn btn-primary btn-sm">Edit Invoice</a> </a>
<!-- <a href="/customers/billing-details/?customerId=<?php echo $customer['customerId'] . '&invoiceId=' . $invoice['invoiceId']; ?>" class="btn btn-primary btn-sm">EMI Details</a> --> </td>
<!-- <a href="/customers/print-invoice/?customerId=<?php echo $customer['customerId'] . '&invoiceId=' . $invoice['invoiceId']; ?>" class="btn btn-primary btn-sm">Print</a> --> <td><?php echo isset($emi['bookingDate']) ? date('d-m-Y', strtotime($emi['bookingDate'])) : 'N/A'; ?></td>
<a href="/customers/additional-payment/?customerId=<?php echo $customer['customerId'].'&invoiceId='.$invoice['invoiceId']; ?>" class="btn btn-primary btn-sm">Payment</a> <td><?php echo isset($emi['bookingDate']) ? (new DateTime($emi['bookingDate']))->modify('+'.$emi['tenure']-'1'.'months')->format('d-m-Y') : 'N/A'; ?></td>
<td><?php echo isset($emi['tenure']) ? htmlspecialchars($emi['tenure']) : 'N/A'; ?></td>
<td><?php echo isset($emi['bookingDate']) ? date('d', strtotime($emi['bookingDate'])) .' Each Month': 'N/A'; ?></td>
<td>$<?php echo isset($emi['emiAmount']) ? htmlspecialchars($emi['emiAmount']) : '0.00'; ?></td>
<td>$<?php echo isset($emi['totalAmount']) ? htmlspecialchars($emi['totalAmount']) : '0.00'; ?></td>
<td class="d-flex gap-1">
<a href="/customers/generate-invoice/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm" style="font-size: 13px;">New Invoice</a>
<a href="/customers/edit-invoice/?customerId=<?php echo $customer['customerId'].'&invoiceId='.$invoice['invoiceId']; ?>" class="btn btn-primary btn-sm" style="font-size: 13px;">Edit Invoice</a>
<a href="/customers/additional-payment/?customerId=<?php echo $customer['customerId'].'&invoiceId='.$invoice['invoiceId']; ?>" class="btn btn-primary btn-sm" style="font-size: 13px;">Payment</a>
</td> </td>
</tr> </tr>
<?php <?php
@ -75,28 +97,19 @@
<tr> <tr>
<td><?php echo $customerSerial++; ?></td> <td><?php echo $customerSerial++; ?></td>
<td><?php echo htmlspecialchars($customer['name']); ?></td> <td><?php echo htmlspecialchars($customer['name']); ?></td>
<td><?php echo htmlspecialchars($customer['mobile']); ?></td> <td colspan="6" class="text-center">No EMI or Invoice Data</td>
<td><?php echo htmlspecialchars($customer['email']); ?></td>
<td colspan="3">No invoice available</td>
<td> <td>
<!-- <a href="/customers/edit/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm">Edit Invoice</a> -->
<!-- <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/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> -->
<a href="" class="btn btn-primary btn-sm">Additional Payment</a>
</td> </td>
</tr> </tr>
<?php <?php
} }
} }
} catch (PDOException $e) { } catch (PDOException $e) {
echo '<tr><td colspan="5" class="text-danger text-center">Error: ' . $e->getMessage() . '</td></tr>'; echo '<tr><td colspan="9" class="text-danger text-center">Error: ' . $e->getMessage() . '</td></tr>';
} }
?> ?>
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>