s11
parent
e5a54e6c5d
commit
3d7ac1ba3b
|
@ -234,13 +234,15 @@
|
||||||
<input class="form-control w-100" name="rate" id="rate" />
|
<input class="form-control w-100" name="rate" id="rate" />
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<select name="discount" id="discount" class="form-control">
|
<select onchange="changeDiscountField();" id="discountAuto" name="discount" class="form-control" required>
|
||||||
<option value="0">No Discount</option>
|
<option value="">-Select-</option>
|
||||||
<option value="5">5 %</option>
|
<option value="5">5%</option>
|
||||||
<option value="10">10 %</option>
|
<option value="10">10%</option>
|
||||||
<option value="12">12 %</option>
|
<option value="12">12%</option>
|
||||||
<option value="18">18 %</option>
|
<option value="18">18%</option>
|
||||||
</select>
|
<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>
|
||||||
<td>
|
<td>
|
||||||
<input readonly class="form-control" name="discountAmount" id="discountAmount" />
|
<input readonly class="form-control" name="discountAmount" id="discountAmount" />
|
||||||
|
@ -252,9 +254,9 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex justify-content-end align-items-center">
|
<div class="d-flex justify-content-end align-items-center mt-2">
|
||||||
<div>
|
<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>
|
<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>
|
<a href="/customers/print-invoice/?customerId=<?= $_GET['customerId'] . '&invoiceId='. $lastInvoicePrint['invoiceId']; ?>" id="printBtn" class="btn btn-primary visually-">Print Invoice</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -267,6 +269,8 @@
|
||||||
const formattedDate = today.toISOString().split('T')[0];
|
const formattedDate = today.toISOString().split('T')[0];
|
||||||
document.getElementById('bookingDate').value = formattedDate;
|
document.getElementById('bookingDate').value = formattedDate;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function changeTenureField() {
|
function changeTenureField() {
|
||||||
const tenureAuto = document.getElementById('tenureAuto');
|
const tenureAuto = document.getElementById('tenureAuto');
|
||||||
const tenureCustom = document.getElementById('tenureCustom');
|
const tenureCustom = document.getElementById('tenureCustom');
|
||||||
|
@ -298,28 +302,72 @@
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
const quantityInput = document.getElementById("quantity");
|
const quantityInput = document.getElementById("quantity");
|
||||||
const rateInput = document.getElementById("rate");
|
const rateInput = document.getElementById("rate");
|
||||||
const taxSelect = document.getElementById("discount");
|
const discountSelect = document.getElementById("discountAuto");
|
||||||
const taxAmountInput = document.getElementById("discountAmount");
|
const discountInput = document.getElementById("discountCustom");
|
||||||
|
const discountAmountInput = document.getElementById("discountAmount");
|
||||||
const totalAmountInput = document.getElementById("totalAmount");
|
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() {
|
function calculateTotal() {
|
||||||
const quantity = parseFloat(quantityInput.value) || 0;
|
const quantity = parseFloat(quantityInput.value) || 0;
|
||||||
const rate = parseFloat(rateInput.value) || 0;
|
const rate = parseFloat(rateInput.value) || 0;
|
||||||
const tax = parseFloat(taxSelect.value) || 0;
|
const discount = getDiscountValue();
|
||||||
|
|
||||||
let subtotal = quantity * rate;
|
let subtotal = quantity * rate;
|
||||||
let taxAmount = (subtotal * tax) / 100;
|
let discountAmount = (subtotal * discount) / 100;
|
||||||
let grandTotal = subtotal - taxAmount;
|
let grandTotal = subtotal - discountAmount;
|
||||||
|
|
||||||
taxAmountInput.value = taxAmount.toFixed(2); // Format Tax Amount
|
discountAmountInput.value = discountAmount.toFixed(2);
|
||||||
totalAmountInput.value = grandTotal.toFixed(2); // Format Total Amount
|
totalAmountInput.value = grandTotal.toFixed(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event listeners for real-time calculation
|
// Event listeners for real-time calculation
|
||||||
quantityInput.addEventListener("input", calculateTotal);
|
quantityInput.addEventListener("input", calculateTotal);
|
||||||
rateInput.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>
|
</script>
|
Loading…
Reference in New Issue