document.addEventListener('DOMContentLoaded', function () { // --- Toggle for Layover Section --- const layoverToggle = document.getElementById('layoverToggle'); const layoverDetails = document.getElementById('layoverDetails'); if (layoverToggle) { layoverToggle.addEventListener('change', function () { layoverDetails.style.display = this.checked ? 'block' : 'none'; }); } // --- Auto-calculation for Fares --- const passengersInput = document.getElementById('passengers'); const fareInput = document.getElementById('fare'); const totalFareInput = document.getElementById('totalFare'); const infantsInput = document.getElementById('infants'); const infantFareInput = document.getElementById('infantFare'); const totalInfantFareInput = document.getElementById('totalInfantFare'); const extraChargePriceInput = document.getElementById('extraChargePrice'); const grandTotalInput = document.getElementById('grandTotal'); const calculationFields = [passengersInput, fareInput, infantsInput, infantFareInput, extraChargePriceInput]; function calculateTotals() { const passengers = parseFloat(passengersInput.value) || 0; const fare = parseFloat(fareInput.value) || 0; const infants = parseFloat(infantsInput.value) || 0; const infantFare = parseFloat(infantFareInput.value) || 0; const extraCharges = parseFloat(extraChargePriceInput.value) || 0; const totalFare = passengers * fare; const totalInfantFare = infants * infantFare; const grandTotal = totalFare + totalInfantFare + extraCharges; totalFareInput.value = totalFare.toFixed(3); totalInfantFareInput.value = totalInfantFare.toFixed(3); grandTotalInput.value = grandTotal.toFixed(3) + ' OMR'; } calculationFields.forEach(field => { if (field) { field.addEventListener('input', calculateTotals); } }); // Initial calculation on page load calculateTotals(); // --- Preview Modal Logic --- const previewButton = document.getElementById('previewButton'); const previewModal = new bootstrap.Modal(document.getElementById('previewModal')); const previewContent = document.getElementById('previewContent'); if (previewButton) { previewButton.addEventListener('click', function () { // Helper to get form values const getValue = (id) => document.getElementById(id).value || 'N/A'; // Collect data from form fields const customerName = getValue('customerName'); const phoneNumber = getValue('phoneNumber'); const email = getValue('email'); const passengers = getValue('passengers'); const departureAirport = getValue('departureAirport'); const arrivalAirport = getValue('arrivalAirport'); const departureDate = getValue('departureDate'); const returnDate = getValue('returnDate'); const airline = getValue('airline'); const cabinClass = getValue('cabinClass'); let layoverInfo = ''; if (layoverToggle.checked) { const layoverAirport = getValue('layoverAirport'); const layoverDuration = getValue('layoverDuration'); layoverInfo = `
Layover Details

Layover Airport: ${layoverAirport}

Duration: ${layoverDuration}

`; } const fare = parseFloat(getValue('fare')).toFixed(3) || '0.000'; const totalFare = getValue('totalFare'); const infants = getValue('infants'); const infantFare = parseFloat(getValue('infantFare')).toFixed(3) || '0.000'; const totalInfantFare = getValue('totalInfantFare'); const infantBaggage = getValue('infantBaggage'); const checkedBaggage = getValue('checkedBaggage'); const weightPerPiece = getValue('weightPerPiece'); const handBaggage = getValue('handBaggage'); const baggageNotes = getValue('baggageNotes'); const extraChargeDescription = getValue('extraChargeDescription'); const extraChargePrice = parseFloat(getValue('extraChargePrice')).toFixed(3) || '0.000'; const grandTotal = getValue('grandTotal'); const otherRequests = getValue('otherRequests'); // Construct HTML for preview previewContent.innerHTML = `
Customer Details

Name: ${customerName}

Phone: ${phoneNumber}

Email: ${email}

Flight Information

From: ${departureAirport}

To: ${arrivalAirport}

Departure: ${departureDate}

Return: ${returnDate || 'One-way'}

Airline: ${airline}

Class: ${cabinClass}

${layoverInfo}
Passenger & Infant Details

No. of Passengers: ${passengers}

No. of Infants: ${infants}

Infant Baggage: ${infantBaggage}

Adult Baggage Details

Checked Pieces: ${checkedBaggage}

Weight per Piece: ${weightPerPiece} kg

Hand Baggage: ${handBaggage} kg

Notes: ${baggageNotes}


Fare Summary (OMR)
Fare per Passenger ${fare}
Total Passenger Fare ${totalFare}
Infant Fare ${infantFare}
Total Infant Fare ${totalInfantFare}
${extraChargeDescription || 'Extra Charges'} ${extraChargePrice}
Grand Total ${grandTotal}
Additional Comments

${otherRequests}

`; // Show the modal previewModal.show(); }); } // --- Reset Form Logic --- const resetButton = document.getElementById('resetButton'); const airfareForm = document.getElementById('airfareForm'); if (resetButton) { resetButton.addEventListener('click', function() { airfareForm.reset(); // Manually hide the layover section if it was open if (layoverToggle.checked) { layoverDetails.style.display = 'none'; } // Recalculate totals to reset them to 0 calculateTotals(); }); } });