@@ -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');
+ }
+ }
+
+
+
\ No newline at end of file