Suvodip 2025-03-19 16:57:39 +05:30
parent 97d120a1b5
commit 6e69bf9f35
3 changed files with 59 additions and 40 deletions

View File

@ -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,16 +183,25 @@
<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){ ?>
<?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'; ?>
@ -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>

View File

@ -112,7 +112,7 @@
<div class="w-100">
<div class="mb-3">
<label for="invoiceId" class="form-label">Invoice Id:</label>
<input type="text" class="form-control bg-white" id="invoiceId" name="invoiceId" value="<?= $invoiceData['invoiceId']; ?>">
<input type="text" class="form-control bg-white" id="invoiceId" name="invoiceId" value="<?= $invoiceData['invoiceId']; ?>" readonly>
</div>
<div class="mb-3">
<label for="name" class="form-label">Customer:</label>
@ -125,11 +125,11 @@
<div class="mb-3">
<label for="frequency" class="form-label">Frequency:</label>
<select name="frequency" class="form-control" required>
<option value="">-Select-</option>
<select name="frequency" class="form-control" disabled>
<option value="Weekly" <?php echo ($invoiceData['frequency'] === 'Weekly') ? 'selected' : ''; ?>>Weekly</option>
<option value="Monthly" <?php echo ($invoiceData['frequency'] === 'Monthly') ? 'selected' : ''; ?>>Monthly</option>
</select>
<input type="hidden" name="frequency" value="<?php echo htmlspecialchars($invoiceData['frequency']); ?>">
</div>
<div class="d-flex w-100 gap-2">
<div class="mb-3 w-100">
@ -185,7 +185,7 @@
<div class="mb-3">
<label for="tenure" class="form-label">Total Cycles:</label>
<select onchange="changeTenureField();" id="tenureAuto" name="tenure" class="form-control" required>
<select id="tenureAuto" name="tenure" class="form-control" disabled>
<option value="">-Select-</option>
<?php
foreach ($tenureOptions as $value => $label) {
@ -194,6 +194,8 @@
}
?>
</select>
<input type="hidden" name="tenure" value="<?php echo htmlspecialchars($selectedTenure); ?>">
<input type="text" name="tenure" id="tenureCustom" class="form-control visually-hidden"
placeholder="Enter custom value" disabled onblur="restoreDropdown(this)" />
</div>
@ -223,17 +225,17 @@
<input type="text" class="form-control w-100" name="item" id="item" value="<?= htmlspecialchars($invoiceData['item']); ?>" />
</td>
<td>
<input type="text" class="form-control w-100" name="description" id="description" value="<?= htmlspecialchars($invoiceData['description']); ?>"/>
<input type="text" class="form-control w-100" name="description" id="description" value="<?= htmlspecialchars($invoiceData['description']); ?>" />
</td>
<td>
<input class="form-control w-100" name="quantity" id="quantity" value="<?= htmlspecialchars($invoiceData['qty']); ?>"/>
<input class="form-control w-100" name="quantity" id="quantity" value="<?= htmlspecialchars($invoiceData['qty']); ?>" readonly/>
</td>
<td>
<input class="form-control w-100" name="rate" id="rate" value="<?= htmlspecialchars($invoiceData['rate']); ?>"/>
<input class="form-control w-100" name="rate" id="rate" value="<?= htmlspecialchars($invoiceData['rate']); ?>" readonly/>
</td>
<td>
<select name="discount" id="discount" class="form-control">
<option value="0">No Discount</option>
<select name="discount" id="discount" class="form-control" disabled>
<option value="0" <?php echo ($invoiceData['discount'] === "0") ? 'selected' : ''; ?>>No Discount</option>
<?php
$discountOptions = ["5", "10", "12", "18"];
foreach ($discountOptions as $discountItems) {
@ -242,6 +244,8 @@
}
?>
</select>
<input type="hidden" name="discount" value="<?php echo htmlspecialchars($invoiceData['discount']); ?>">
</td>
<td>
<input readonly class="form-control" name="discountAmount" id="discountAmount" value="<?= htmlspecialchars($invoiceData['discountAmount']); ?>" />

View File

@ -122,7 +122,7 @@
<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 flex-wrap gap-1">
<td class="d-inline-flex gap-1">
<a href="/customers/generate-invoice/?customerId=<?php echo $customer['customerId']; ?>" class="btn btn-primary btn-sm" style="font-size: 13px;">New</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</a>
<a href="/customers/print-invoice/?customerId=<?php echo $customer['customerId'].'&invoiceId='.$invoice['invoiceId']; ?>" class="btn btn-primary btn-sm" style="font-size: 13px;">Print</a>