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(':adPaymentSource', $adPaymentSource);
$stmt3->bindParam(':adPaymentTran', $adPaymentTran); $stmt3->bindParam(':adPaymentTran', $adPaymentTran);
$stmt3->bindParam(':adPaymentRemarks', $adPaymentRemarks); $stmt3->bindParam(':adPaymentRemarks', $adPaymentRemarks);
if ($stmt3->execute()) { if ($stmt3->execute()) {
echo '<div class="alert alert-success">Additional Payment <strong>' . htmlspecialchars($_POST['adPaymentAmount']) . '</strong> applied successfully.</div>'; echo '<div class="alert alert-success">Additional Payment <strong>' . htmlspecialchars($_POST['adPaymentAmount']) . '</strong> applied successfully.</div>';
} else { } else {
@ -92,14 +91,15 @@
echo '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>'; 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'); header('Content-Type: application/json');
ob_end_clean(); // Clears any accidental HTML output ob_end_clean(); // Clears any accidental HTML output
try { 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(':customerId', $_GET['customerId']);
$stmt->bindParam(':payStatus', $_POST['payStatus'], PDO::PARAM_INT); $stmt->bindParam(':payStatus', $_POST['payStatus'], PDO::PARAM_INT);
$stmt->bindParam(':emiId', $_POST['emiId'], PDO::PARAM_INT); $stmt->bindParam(':emiId', $_POST['emiId'], PDO::PARAM_INT);
$stmt->bindParam(':paymentDate', $_POST['paymentDate']);
$stmt->execute(); $stmt->execute();
// Ensure no previous output before JSON // Ensure no previous output before JSON
@ -183,28 +183,37 @@
<th>Number of EMI</th> <th>Number of EMI</th>
<th>EMI Amount</th> <th>EMI Amount</th>
<th>EMI Date</th> <th>EMI Date</th>
<th>EMI Payment Date</th>
<th>Payment Status</th> <th>Payment Status</th>
<th>Action</th> <th>Action</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($emiPlans as $emi) { if($emi['emiAmount'] !== null){ ?> <?php foreach ($emiPlans as $emi) {
<tr id="row-<?= $emi['id']; ?>"> if ($emi['emiAmount'] !== null) { ?>
<td><?= $emi['emiNumber']; ?></td> <tr id="row-<?= $emi['id']; ?>">
<td>$<?= number_format($emi['emiAmount'], 2); ?></td> <td><?= $emi['emiNumber']; ?></td>
<td><?= date('d-m-Y', strtotime($emi['emiDate'])); ?></td> <td>$<?= number_format($emi['emiAmount'], 2); ?></td>
<td> <td><?= date('d-m-Y', strtotime($emi['emiDate'])); ?></td>
<span id="status-<?= $emi['id']; ?>" class="badge <?= $emi['payStatus'] == 0 ? 'bg-danger' : 'bg-success'; ?>"> <td>
<?= $emi['payStatus'] == 0 ? 'Unpaid' : 'Paid'; ?> <?php if (!empty($emi['paymentDate'])) { ?>
</span> <?= date('d-m-Y', strtotime($emi['paymentDate'])); ?>
</td> <?php } else { ?>
<td> <input value="<?= date('Y-m-d', strtotime($emi['emiDate'])); ?>" id="paymentDateId" class="form-control" type="date" />
<select class="form-select paymentStatus" data-emi-id="<?= $emi['id']; ?>"> <?php } ?>
<option value="1" <?= $emi['payStatus'] == 1 ? 'selected' : ''; ?>>Paid</option> </td>
<option value="0" <?= $emi['payStatus'] == 0 ? 'selected' : ''; ?>>Unpaid</option> <td>
</select> <span id="status-<?= $emi['id']; ?>" class="badge <?= $emi['payStatus'] == 0 ? 'bg-danger' : 'bg-success'; ?>">
</td> <?= $emi['payStatus'] == 0 ? 'Unpaid' : 'Paid'; ?>
</tr> </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 } } ?> <?php } } ?>
</tbody> </tbody>
</table> </table>
@ -264,7 +273,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <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> </div>
</form> </form>
</div> </div>
@ -278,13 +287,16 @@
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll(".paymentStatus").forEach(select => { document.querySelectorAll(".paymentStatus").forEach(select => {
select.addEventListener("change", function () { select.addEventListener("change", function () {
let row = this.closest("tr");
let emiId = this.getAttribute("data-emi-id"); let emiId = this.getAttribute("data-emi-id");
let newStatus = this.value; let newStatus = this.value;
let paymentDateInput = row.querySelector("#paymentDateId");
let paymentDate = paymentDateInput ? paymentDateInput.value : "";
fetch(window.location.href, { fetch(window.location.href, {
method: "POST", method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" }, 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(response => response.json())
.then(data => { .then(data => {
@ -303,6 +315,7 @@
}); });
}); });
}); });
function addAutoAddRemarks() { function addAutoAddRemarks() {
const emiAmount = <?= json_encode($emiData['emiAmount']); ?>; const emiAmount = <?= json_encode($emiData['emiAmount']); ?>;
const addPayAmount = parseFloat(document.getElementById('adPaymentAmount').value) || 0; 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 `; `EMI Amount: ${emiAmount}. Extra ${extraAmount > 0 ? extraAmount.toFixed(2) : "0.00"} Settled in last EMI `;
} }
// document.getElementById('paymentDateId').value = new Date();
</script> </script>

View File

@ -112,7 +112,7 @@
<div class="w-100"> <div class="w-100">
<div class="mb-3"> <div class="mb-3">
<label for="invoiceId" class="form-label">Invoice Id:</label> <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>
<div class="mb-3"> <div class="mb-3">
<label for="name" class="form-label">Customer:</label> <label for="name" class="form-label">Customer:</label>
@ -125,11 +125,11 @@
<div class="mb-3"> <div class="mb-3">
<label for="frequency" class="form-label">Frequency:</label> <label for="frequency" class="form-label">Frequency:</label>
<select name="frequency" class="form-control" required> <select name="frequency" class="form-control" disabled>
<option value="">-Select-</option>
<option value="Weekly" <?php echo ($invoiceData['frequency'] === 'Weekly') ? 'selected' : ''; ?>>Weekly</option> <option value="Weekly" <?php echo ($invoiceData['frequency'] === 'Weekly') ? 'selected' : ''; ?>>Weekly</option>
<option value="Monthly" <?php echo ($invoiceData['frequency'] === 'Monthly') ? 'selected' : ''; ?>>Monthly</option> <option value="Monthly" <?php echo ($invoiceData['frequency'] === 'Monthly') ? 'selected' : ''; ?>>Monthly</option>
</select> </select>
<input type="hidden" name="frequency" value="<?php echo htmlspecialchars($invoiceData['frequency']); ?>">
</div> </div>
<div class="d-flex w-100 gap-2"> <div class="d-flex w-100 gap-2">
<div class="mb-3 w-100"> <div class="mb-3 w-100">
@ -185,7 +185,7 @@
<div class="mb-3"> <div class="mb-3">
<label for="tenure" class="form-label">Total Cycles:</label> <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> <option value="">-Select-</option>
<?php <?php
foreach ($tenureOptions as $value => $label) { foreach ($tenureOptions as $value => $label) {
@ -194,6 +194,8 @@
} }
?> ?>
</select> </select>
<input type="hidden" name="tenure" value="<?php echo htmlspecialchars($selectedTenure); ?>">
<input type="text" name="tenure" id="tenureCustom" class="form-control visually-hidden" <input type="text" name="tenure" id="tenureCustom" class="form-control visually-hidden"
placeholder="Enter custom value" disabled onblur="restoreDropdown(this)" /> placeholder="Enter custom value" disabled onblur="restoreDropdown(this)" />
</div> </div>
@ -223,25 +225,27 @@
<input type="text" class="form-control w-100" name="item" id="item" value="<?= htmlspecialchars($invoiceData['item']); ?>" /> <input type="text" class="form-control w-100" name="item" id="item" value="<?= htmlspecialchars($invoiceData['item']); ?>" />
</td> </td>
<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>
<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>
<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>
<td> <td>
<select name="discount" id="discount" class="form-control"> <select name="discount" id="discount" class="form-control" disabled>
<option value="0">No Discount</option> <option value="0" <?php echo ($invoiceData['discount'] === "0") ? 'selected' : ''; ?>>No Discount</option>
<?php <?php
$discountOptions = ["5", "10", "12", "18"]; $discountOptions = ["5", "10", "12", "18"];
foreach ($discountOptions as $discountItems) { foreach ($discountOptions as $discountItems) {
$selected = ($invoiceData['discount'] === $discountItems) ? 'selected' : ''; $selected = ($invoiceData['discount'] === $discountItems) ? 'selected' : '';
echo "<option value=\"$discountItems\" $selected> $discountItems%</option>"; echo "<option value=\"$discountItems\" $selected> $discountItems%</option>";
} }
?> ?>
</select> </select>
<input type="hidden" name="discount" value="<?php echo htmlspecialchars($invoiceData['discount']); ?>">
</td> </td>
<td> <td>
<input readonly class="form-control" name="discountAmount" id="discountAmount" value="<?= htmlspecialchars($invoiceData['discountAmount']); ?>" /> <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['emiAmount']) ? htmlspecialchars($emi['emiAmount']) : '0.00'; ?></td>
<td>$<?php echo isset($emi['totalAmount']) ? htmlspecialchars($emi['totalAmount']) : '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/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/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> <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>