Current File : /home/kelaby89/public_html/software/cam-price-calculator/script.js |
// Sample data from the Excel file
const data = {
"5MP Model 520A": [
{ quantity: 1, unitPrice: 470, defaultMarkup: 752 },
{ quantity: 2, unitPrice: 560, defaultMarkup: 896 },
{ quantity: 3, unitPrice: 650, defaultMarkup: 1040 },
{ quantity: 4, unitPrice: 720, defaultMarkup: 1152 },
{ quantity: 5, unitPrice: 830, defaultMarkup: 1328 },
{ quantity: 6, unitPrice: 900, defaultMarkup: 1450 },
{ quantity: 7, unitPrice: 970, defaultMarkup: 1550 },
{ quantity: 8, unitPrice: 1040, defaultMarkup: 1650 }
],
"8MP Model 820A": [
{ quantity: 1, unitPrice: 494, defaultMarkup: 790.4 },
{ quantity: 2, unitPrice: 627, defaultMarkup: 1003.2 },
{ quantity: 3, unitPrice: 760, defaultMarkup: 1216 },
{ quantity: 4, unitPrice: 900, defaultMarkup: 1440 },
{ quantity: 5, unitPrice: 1026, defaultMarkup: 1641.6 },
{ quantity: 6, unitPrice: 1140, defaultMarkup: 1800 },
{ quantity: 7, unitPrice: 1260, defaultMarkup: 1950 },
{ quantity: 8, unitPrice: 1380, defaultMarkup: 2100 }
]
};
const defaultMarkupPercent = 160; // Default markup percent
document.getElementById('price-form').addEventListener('submit', function (e) {
e.preventDefault();
const quantity = parseInt(document.getElementById('quantity').value);
const model = document.getElementById('model').value;
const houseType = document.getElementById('story').value;
if (quantity > 8) {
const emailSubject = "Price of Selected Options";
const emailBody = `
Hi, I would like to know how much it would cost for the following options:\n
Model: ${model}\n
Quantity: ${quantity}\n
House Type: ${houseType === 'single' ? 'Single Story' : 'Double Story'}\n
Thank you.
`;
const mailtoLink = `mailto:[email protected]?subject=${encodeURIComponent(emailSubject)}&body=${encodeURIComponent(emailBody)}`;
window.location.href = mailtoLink;
return;
}
const modelData = data[model].find(item => item.quantity === quantity);
if (modelData) {
const unitPrice = modelData.unitPrice;
const markup = unitPrice * (defaultMarkupPercent / 100);
let totalPrice = unitPrice + markup;
if (houseType === 'double') {
totalPrice += 200;
}
document.getElementById('total-price').textContent = `Total Price (with installation): $${totalPrice.toFixed(2)}`;
// Update image based on quantity
const imagePath = `/public_html/software/cam-price-calculator/images/${quantity}.jpg`;
const cameraImage = document.getElementById('camera-image');
cameraImage.src = imagePath;
cameraImage.style.display = 'block';
} else {
document.getElementById('total-price').textContent = "Total Price (with installation): Data not available";
document.getElementById('camera-image').style.display = 'none';
}
});
document.getElementById('toggle-mode').addEventListener('click', function () {
document.body.classList.toggle('dark-mode');
document.body.classList.toggle('light-mode');
document.querySelector('.container').classList.toggle('dark-mode');
document.querySelector('.container').classList.toggle('light-mode');
document.querySelectorAll('h1, h2').forEach(el => {
el.classList.toggle('dark-mode');
el.classList.toggle('light-mode');
});
document.querySelectorAll('input, select, button, label').forEach(el => {
el.classList.toggle('dark-mode');
el.classList.toggle('light-mode');
});
const isDarkMode = document.body.classList.contains('dark-mode');
this.textContent = isDarkMode ? 'Switch to Light Mode' : 'Switch to Dark Mode';
});
// Help modal
const modal = document.getElementById('help-modal');
const btn = document.getElementById('help-button