s11
This commit is contained in:
@@ -61,7 +61,6 @@
|
||||
$stmt3->bindParam(':adPaymentSource', $adPaymentSource);
|
||||
$stmt3->bindParam(':adPaymentTran', $adPaymentTran);
|
||||
$stmt3->bindParam(':adPaymentRemarks', $adPaymentRemarks);
|
||||
|
||||
if ($stmt3->execute()) {
|
||||
echo '<div class="alert alert-success">Additional Payment <strong>' . htmlspecialchars($_POST['adPaymentAmount']) . '</strong> applied successfully.</div>';
|
||||
} else {
|
||||
@@ -92,14 +91,15 @@
|
||||
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['emiId'], $_POST['payStatus'])) {
|
||||
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 = $db->prepare("UPDATE emi SET payStatus = :payStatus, paymentDate = :paymentDate 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->bindParam(':paymentDate', $_POST['paymentDate']);
|
||||
$stmt->execute();
|
||||
|
||||
// Ensure no previous output before JSON
|
||||
@@ -183,28 +183,37 @@
|
||||
<th>Number of EMI</th>
|
||||
<th>EMI Amount</th>
|
||||
<th>EMI Date</th>
|
||||
<th>EMI Payment Date</th>
|
||||
<th>Payment Status</th>
|
||||
<th>Action</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('d-m-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>
|
||||
<select class="form-select paymentStatus" data-emi-id="<?= $emi['id']; ?>">
|
||||
<option value="1" <?= $emi['payStatus'] == 1 ? 'selected' : ''; ?>>Paid</option>
|
||||
<option value="0" <?= $emi['payStatus'] == 0 ? 'selected' : ''; ?>>Unpaid</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?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('d-m-Y', strtotime($emi['emiDate'])); ?></td>
|
||||
<td>
|
||||
<?php if (!empty($emi['paymentDate'])) { ?>
|
||||
<?= date('d-m-Y', strtotime($emi['paymentDate'])); ?>
|
||||
<?php } else { ?>
|
||||
<input value="<?= date('Y-m-d', strtotime($emi['emiDate'])); ?>" id="paymentDateId" class="form-control" type="date" />
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td>
|
||||
<span id="status-<?= $emi['id']; ?>" class="badge <?= $emi['payStatus'] == 0 ? 'bg-danger' : 'bg-success'; ?>">
|
||||
<?= $emi['payStatus'] == 0 ? 'Unpaid' : 'Paid'; ?>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<select class="form-select paymentStatus" data-emi-id="<?= $emi['id']; ?>">
|
||||
<option value="1" <?= $emi['payStatus'] == 1 ? 'selected' : ''; ?>>Paid</option>
|
||||
<option value="0" <?= $emi['payStatus'] == 0 ? 'selected' : ''; ?>>Unpaid</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -264,7 +273,7 @@
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-success btn-block mt-2">Save Payment</button>
|
||||
<button type="submit" name="additional-payment" class="btn btn-success btn-block mt-2">Save Payment</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -278,13 +287,16 @@
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.querySelectorAll(".paymentStatus").forEach(select => {
|
||||
select.addEventListener("change", function () {
|
||||
let row = this.closest("tr");
|
||||
let emiId = this.getAttribute("data-emi-id");
|
||||
let newStatus = this.value;
|
||||
let paymentDateInput = row.querySelector("#paymentDateId");
|
||||
let paymentDate = paymentDateInput ? paymentDateInput.value : "";
|
||||
|
||||
fetch(window.location.href, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
body: `emiId=${emiId}&payStatus=${newStatus}`
|
||||
body: `emiId=${emiId}&payStatus=${newStatus}&paymentDate=${paymentDate}`
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
@@ -303,6 +315,7 @@
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function addAutoAddRemarks() {
|
||||
const emiAmount = <?= json_encode($emiData['emiAmount']); ?>;
|
||||
const addPayAmount = parseFloat(document.getElementById('adPaymentAmount').value) || 0;
|
||||
@@ -312,6 +325,8 @@
|
||||
`EMI Amount: ${emiAmount}. Extra ${extraAmount > 0 ? extraAmount.toFixed(2) : "0.00"} Settled in last EMI `;
|
||||
}
|
||||
|
||||
// document.getElementById('paymentDateId').value = new Date();
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user