s11
parent
e5a54e6c5d
commit
3d7ac1ba3b
|
@ -102,7 +102,7 @@
|
|||
if ($stmt->execute()) {
|
||||
$customerAddress = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
|
||||
// Generate new Invoice Id
|
||||
$stmt = $db->query("SELECT id FROM invoice WHERE DATE(invoiceDate) = CURDATE() ORDER BY id DESC LIMIT 1");
|
||||
$lastInvoice = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
@ -234,13 +234,15 @@
|
|||
<input class="form-control w-100" name="rate" id="rate" />
|
||||
</td>
|
||||
<td>
|
||||
<select name="discount" id="discount" class="form-control">
|
||||
<option value="0">No Discount</option>
|
||||
<option value="5">5 %</option>
|
||||
<option value="10">10 %</option>
|
||||
<option value="12">12 %</option>
|
||||
<option value="18">18 %</option>
|
||||
</select>
|
||||
<select onchange="changeDiscountField();" id="discountAuto" name="discount" class="form-control" required>
|
||||
<option value="">-Select-</option>
|
||||
<option value="5">5%</option>
|
||||
<option value="10">10%</option>
|
||||
<option value="12">12%</option>
|
||||
<option value="18">18%</option>
|
||||
<option value="0">Custom</option>
|
||||
</select>
|
||||
<input type="text" name="discount" id="discountCustom" class="form-control visually-hidden" placeholder="Enter custom discount" disabled onblur="restoreDiscounDropdown(this)" />
|
||||
</td>
|
||||
<td>
|
||||
<input readonly class="form-control" name="discountAmount" id="discountAmount" />
|
||||
|
@ -252,9 +254,9 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="d-flex justify-content-end align-items-center">
|
||||
<div class="d-flex justify-content-end align-items-center mt-2">
|
||||
<div>
|
||||
<button class="btn btn-secondary">Discard</button>
|
||||
<a href="/customers/list" class="btn btn-secondary">Discard</a>
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
<a href="/customers/print-invoice/?customerId=<?= $_GET['customerId'] . '&invoiceId='. $lastInvoicePrint['invoiceId']; ?>" id="printBtn" class="btn btn-primary visually-">Print Invoice</a>
|
||||
</div>
|
||||
|
@ -267,6 +269,8 @@
|
|||
const formattedDate = today.toISOString().split('T')[0];
|
||||
document.getElementById('bookingDate').value = formattedDate;
|
||||
|
||||
|
||||
|
||||
function changeTenureField() {
|
||||
const tenureAuto = document.getElementById('tenureAuto');
|
||||
const tenureCustom = document.getElementById('tenureCustom');
|
||||
|
@ -298,28 +302,72 @@
|
|||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const quantityInput = document.getElementById("quantity");
|
||||
const rateInput = document.getElementById("rate");
|
||||
const taxSelect = document.getElementById("discount");
|
||||
const taxAmountInput = document.getElementById("discountAmount");
|
||||
const discountSelect = document.getElementById("discountAuto");
|
||||
const discountInput = document.getElementById("discountCustom");
|
||||
const discountAmountInput = document.getElementById("discountAmount");
|
||||
const totalAmountInput = document.getElementById("totalAmount");
|
||||
|
||||
function getDiscountValue() {
|
||||
// Use the visible element's value (dropdown or input)
|
||||
if (!discountSelect.disabled) {
|
||||
return parseFloat(discountSelect.value) || 0;
|
||||
} else {
|
||||
return parseFloat(discountInput.value) || 0;
|
||||
}
|
||||
}
|
||||
|
||||
function calculateTotal() {
|
||||
const quantity = parseFloat(quantityInput.value) || 0;
|
||||
const rate = parseFloat(rateInput.value) || 0;
|
||||
const tax = parseFloat(taxSelect.value) || 0;
|
||||
const discount = getDiscountValue();
|
||||
|
||||
let subtotal = quantity * rate;
|
||||
let taxAmount = (subtotal * tax) / 100;
|
||||
let grandTotal = subtotal - taxAmount;
|
||||
let discountAmount = (subtotal * discount) / 100;
|
||||
let grandTotal = subtotal - discountAmount;
|
||||
|
||||
taxAmountInput.value = taxAmount.toFixed(2); // Format Tax Amount
|
||||
totalAmountInput.value = grandTotal.toFixed(2); // Format Total Amount
|
||||
discountAmountInput.value = discountAmount.toFixed(2);
|
||||
totalAmountInput.value = grandTotal.toFixed(2);
|
||||
}
|
||||
|
||||
// Event listeners for real-time calculation
|
||||
quantityInput.addEventListener("input", calculateTotal);
|
||||
rateInput.addEventListener("input", calculateTotal);
|
||||
taxSelect.addEventListener("change", calculateTotal);
|
||||
discountSelect.addEventListener("change", calculateTotal);
|
||||
discountInput.addEventListener("input", calculateTotal);
|
||||
});
|
||||
|
||||
|
||||
function changeDiscountField() {
|
||||
const discountAuto = document.getElementById('discountAuto');
|
||||
const discountCustom = document.getElementById('discountCustom');
|
||||
|
||||
if (discountAuto.value === "0") { // "Custom" option selected
|
||||
discountAuto.classList.add('visually-hidden');
|
||||
discountAuto.removeAttribute('name');
|
||||
discountAuto.setAttribute('disabled', 'true');
|
||||
|
||||
discountCustom.classList.remove('visually-hidden');
|
||||
discountCustom.setAttribute('name', 'discount');
|
||||
discountCustom.removeAttribute('disabled');
|
||||
discountCustom.focus();
|
||||
}
|
||||
}
|
||||
|
||||
function restoreDiscounDropdown(input) {
|
||||
const discountAuto = document.getElementById('discountAuto');
|
||||
|
||||
if (input.value.trim() === "") { // If input is empty, restore the dropdown
|
||||
discountAuto.classList.remove('visually-hidden');
|
||||
discountAuto.removeAttribute('disabled');
|
||||
discountAuto.setAttribute('name', 'discount');
|
||||
discountAuto.value = "";
|
||||
|
||||
input.classList.add('visually-hidden');
|
||||
input.removeAttribute('name');
|
||||
input.setAttribute('disabled', 'true');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
Loading…
Reference in New Issue