From 3d7ac1ba3b6177823367cd3732dad3aaf808462c Mon Sep 17 00:00:00 2001 From: Suvodip Date: Wed, 19 Mar 2025 11:41:37 +0530 Subject: [PATCH] s11 --- customers/.hta_slug/generate-invoice.php | 84 +++++++++++++++++++----- 1 file changed, 66 insertions(+), 18 deletions(-) diff --git a/customers/.hta_slug/generate-invoice.php b/customers/.hta_slug/generate-invoice.php index fee4fa9..1b9742a 100644 --- a/customers/.hta_slug/generate-invoice.php +++ b/customers/.hta_slug/generate-invoice.php @@ -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 @@ - + + @@ -252,9 +254,9 @@ -
+
- + Discard Print Invoice
@@ -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