terter
This commit is contained in:
@@ -195,7 +195,9 @@ async function openQuoteModal(quoteId = null) {
|
||||
document.getElementById('quote-id').value = quote.id;
|
||||
document.getElementById('quote-customer').value = quote.customer_id;
|
||||
document.getElementById('quote-number').value = quote.quote_number;
|
||||
document.getElementById('quote-date').value = quote.quote_date;
|
||||
// Convert date from YYYY-MM-DD format (may include time)
|
||||
const dateOnly = quote.quote_date.split('T')[0];
|
||||
document.getElementById('quote-date').value = dateOnly;
|
||||
document.getElementById('quote-tax-exempt').checked = quote.tax_exempt;
|
||||
document.getElementById('quote-tbd-note').value = quote.tbd_note || '';
|
||||
|
||||
@@ -280,7 +282,29 @@ function addQuoteItem(item = null) {
|
||||
|
||||
itemsDiv.appendChild(itemDiv);
|
||||
|
||||
// Add event listeners
|
||||
// Get references to inputs for auto-calculation
|
||||
const qtyInput = itemDiv.querySelector('[data-field="quantity"]');
|
||||
const rateInput = itemDiv.querySelector('[data-field="rate"]');
|
||||
const amountInput = itemDiv.querySelector('[data-field="amount"]');
|
||||
const tbdCheckbox = itemDiv.querySelector('[data-field="is_tbd"]');
|
||||
|
||||
// Auto-calculate amount when qty or rate changes
|
||||
const calculateAmount = () => {
|
||||
if (!tbdCheckbox.checked && qtyInput.value && rateInput.value) {
|
||||
const qty = parseFloat(qtyInput.value) || 0;
|
||||
// Extract numeric value from rate (handles "125.00/hr" format)
|
||||
const rateValue = parseFloat(rateInput.value.replace(/[^0-9.]/g, '')) || 0;
|
||||
const amount = qty * rateValue;
|
||||
amountInput.value = amount.toFixed(2);
|
||||
}
|
||||
updateTotals();
|
||||
};
|
||||
|
||||
// Add event listeners for auto-calculation
|
||||
qtyInput.addEventListener('input', calculateAmount);
|
||||
rateInput.addEventListener('input', calculateAmount);
|
||||
|
||||
// Add event listeners for totals update
|
||||
itemDiv.querySelectorAll('.item-input, .item-amount').forEach(input => {
|
||||
input.addEventListener('input', updateTotals);
|
||||
});
|
||||
@@ -294,6 +318,7 @@ function addQuoteItem(item = null) {
|
||||
} else {
|
||||
if (amountInput.value === 'TBD') {
|
||||
amountInput.value = '';
|
||||
calculateAmount(); // Recalculate when unchecking TBD
|
||||
}
|
||||
amountInput.readOnly = false;
|
||||
amountInput.classList.remove('bg-gray-100');
|
||||
@@ -461,4 +486,4 @@ function setDefaultDate() {
|
||||
function formatDate(dateString) {
|
||||
const date = new Date(dateString);
|
||||
return `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user