137 lines
5.5 KiB
PHP
137 lines
5.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);
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['emiId'], $_POST['payStatus'])) {
|
|
header('Content-Type: application/json');
|
|
ob_end_clean(); // Clears any accidental HTML output
|
|
|
|
try {
|
|
$stmt = $db->prepare("UPDATE emi SET payStatus = :payStatus WHERE customerId = :customerId AND id = :emiId");
|
|
$stmt->bindParam(':customerId', $_GET['customerId']);
|
|
$stmt->bindParam(':payStatus', $_POST['payStatus'], PDO::PARAM_INT);
|
|
$stmt->bindParam(':emiId', $_POST['emiId'], PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
echo json_encode(['status' => 'success']);
|
|
} catch (PDOException $e) {
|
|
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
|
}
|
|
|
|
exit;
|
|
}
|
|
|
|
// Fetch EMI data
|
|
$stmt = $db->prepare("SELECT * FROM emi WHERE customerId = :customerId AND invoiceId = :invoiceId ORDER BY emiDate ASC");
|
|
$stmt->bindParam(':customerId', $_GET['customerId']);
|
|
$stmt->bindParam(':invoiceId', $_GET['invoiceId']);
|
|
$stmt->execute();
|
|
$emiPlans = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
// var_dump($emiPlans);
|
|
|
|
$stmt = $db->prepare("SELECT * FROM customers WHERE customerId = :customerId");
|
|
$stmt->bindParam(':customerId', $_GET['customerId']);
|
|
$stmt->execute();
|
|
$customer = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
// var_dump($customer);
|
|
|
|
} catch (PDOException $e) {
|
|
die('<div class="alert alert-danger text-center">Error: ' . $e->getMessage() . '</div>');
|
|
}
|
|
?>
|
|
<?php
|
|
$currentOutstanding = 0;
|
|
$totalAmount = 0;
|
|
$bookingDate = null;
|
|
$currentOutstanding = 0;
|
|
$totalAmount = 0;
|
|
$bookingDate = null;
|
|
$tenure = null;
|
|
$frequency = null;
|
|
foreach ($emiPlans as $emi) {
|
|
$totalAmount = $emi['totalAmount'];
|
|
if ($bookingDate === null && !empty($emi['bookingDate'])) {
|
|
$bookingDate = $emi['bookingDate'];
|
|
}
|
|
if ($emi['payStatus'] == 0) {
|
|
$currentOutstanding += $emi['emiAmount'];
|
|
}
|
|
if ($tenure === null && isset($emi['tenure'])) {
|
|
$tenure = $emi['tenure'];
|
|
}
|
|
if ($frequency === null && isset($emi['frequency'])) {
|
|
$frequency = $emi['frequency'];
|
|
}
|
|
}
|
|
$currentOutstanding = round($currentOutstanding);
|
|
$tenure = $tenure !== null ? $tenure : 0;
|
|
$frequency = $frequency !== null ? $frequency : 0;
|
|
?>
|
|
<div class="container mt-4">
|
|
<h2 class="mb-3">Installment Details</h2>
|
|
<div class="d-flex justify-content-between">
|
|
<div>
|
|
<p>Customer Name: <strong><?php echo $customer['name']; ?></strong></p>
|
|
<p>Mobile Number: <strong><?php echo $customer['mobile']; ?></strong></p>
|
|
<p>Installment Start Date: <strong><?php echo $bookingDate ? date('m/d/Y', strtotime($bookingDate)) : 'N/A'; ?></strong></p>
|
|
<p>Invoice Id: <strong><?php echo $emiPlans[0]['invoiceId']; ?></strong></p>
|
|
</div>
|
|
<div>
|
|
<p>Total Amount: <strong>$<?php echo $totalAmount; ?></strong></p>
|
|
<p>Outstanding: <strong>$<?php echo round($currentOutstanding); ?></strong></p>
|
|
<p>Tenure: <strong><?php echo $tenure; ?></strong></p>
|
|
<p>Frequency: <strong><?php echo $frequency; ?></strong></p>
|
|
</div>
|
|
|
|
</div>
|
|
<table class="table table-striped table-bordered">
|
|
<thead class="text-white text-center" style="background-color: #374151;">
|
|
<tr>
|
|
<th>Installment</th>
|
|
<th>Amount</th>
|
|
<th>Date</th>
|
|
<th>Payment Status</th>
|
|
<th>Outstanding</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($emiPlans as $emi) {
|
|
if ($emi['emiAmount'] !== null) { ?>
|
|
<tr id="row-<?= $emi['id']; ?>">
|
|
<td><?= $emi['emiNumber']; ?></td>
|
|
<td>$<?= number_format($emi['emiAmount'], 2); ?></td>
|
|
<td><?= date('m/d/Y', strtotime($emi['emiDate'])); ?></td>
|
|
<td>
|
|
<span id="status-<?= $emi['id']; ?>" class="badge <?= $emi['payStatus'] == 0 ? 'bg-danger' : 'bg-success'; ?>">
|
|
<?= $emi['payStatus'] == 0 ? 'Unpaid' : 'Paid'; ?>
|
|
</span>
|
|
</td>
|
|
<td>$<?= number_format($emi['outstanding'], 2); ?></td>
|
|
</tr>
|
|
<?php } } ?>
|
|
</tbody>
|
|
</table>
|
|
<h3 class="mb-3">Additional Payment Details</h3>
|
|
<table class="table table-striped table-bordered">
|
|
<thead class="text-white text-center" style="background-color: #374151;">
|
|
<tr>
|
|
<th>Amount</th>
|
|
<th>Payment Date</th>
|
|
<th>Transaction Id</th>
|
|
<th>Remarks</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($emiPlans as $emi) { if($emi['adPaymentAmount'] !== null) { ?>
|
|
<tr id="row-<?= $emi['id']; ?>">
|
|
<td>$<?= $emi['adPaymentAmount']; ?></td>
|
|
<td><?= date('m/d/Y', strtotime($emi['adPaymentDate'])); ?></td>
|
|
<td><?= $emi['adPaymentTran']; ?></td>
|
|
<td><?= $emi['adPaymentRemarks']; ?></td>
|
|
</tr>
|
|
<?php } }?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|