billing2/my-account/.hta_slug/stat.php

61 lines
2.5 KiB
PHP

<?php
require('../.hta_config/conf.php');
try {
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$currentMonth = date('Y-m');
$stmt = $db->prepare(" SELECT e.customerId, c.name, e.emiAmount, e.emiDate, e.payStatus, e.outstanding FROM emi e JOIN customers c ON e.customerId = c.customerId WHERE DATE_FORMAT(e.emiDate, '%Y-%m') = :currentMonth ORDER BY e.emiDate ASC");
$stmt->bindParam(':currentMonth', $currentMonth);
$stmt->execute();
$emiPlans = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Calculate total demand amount
$totalDemand = array_sum(array_column($emiPlans, 'emiAmount'));
} catch (PDOException $e) {
die("Database error: " . $e->getMessage());
}
?>
<div class="container mt-5">
<h2 class="mb-4">Pending EMIs for <?php echo date('F Y'); ?></h2>
<table class="table table-bordered table-striped table-hover">
<thead class="bg-primary text-white text-center">
<tr>
<th>Customer Name</th>
<th>EMI Amount</th>
<th>EMI Date</th>
<th>Pay Status</th>
<th>Outstanding</th>
</tr>
</thead>
<tbody>
<?php if (!empty($emiPlans)) : ?>
<?php foreach ($emiPlans as $emi) : ?>
<tr>
<td><?php echo htmlspecialchars($emi['name']); ?></td>
<td>₹<?php echo number_format($emi['emiAmount'], 2); ?></td>
<td><?php echo date('d M Y', strtotime($emi['emiDate'])); ?></td>
<td>
<?php if ($emi['payStatus'] == 0) : ?>
<span class="badge bg-danger">Pending</span>
<?php else : ?>
<span class="badge bg-success">Paid</span>
<?php endif; ?>
</td>
<td>₹<?php echo number_format($emi['outstanding'], 2); ?></td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="5" class="text-center">No pending EMIs this month</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<div class="mt-3">
<h4>Total Demand EMI Amount: ₹<?php echo number_format($totalDemand, 2); ?></h4>
</div>
</div>