53 lines
2.0 KiB
JavaScript
53 lines
2.0 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function () {
|
|
const amountInput = document.getElementById('amount');
|
|
const rateInput = document.getElementById('rate');
|
|
const agreementInput = document.getElementById('agreement');
|
|
const vatAmountOutput = document.getElementById('vatAmount');
|
|
const totalAmountOutput = document.getElementById('totalAmount');
|
|
const netAmountOutput = document.getElementById('netAmount');
|
|
|
|
function updateCalculator() {
|
|
const amount = parseFloat(amountInput.value) || 0;
|
|
const rate = parseFloat(rateInput.value) || 0;
|
|
let tax = 0;
|
|
|
|
if (amount > 0 && rate > 0) {
|
|
const vatAmount = (amount * rate) / 100;
|
|
const totalAmount = amount + vatAmount;
|
|
|
|
vatAmountOutput.textContent = vatAmount.toFixed(2);
|
|
totalAmountOutput.textContent = totalAmount.toFixed(2);
|
|
|
|
if (totalAmount > 0) {
|
|
if (totalAmount <= 1000) {
|
|
tax = totalAmount * 0.10;
|
|
} else if (totalAmount <= 3000) {
|
|
tax = (1000 * 0.10) + ((totalAmount - 1000) * 0.20);
|
|
} else {
|
|
tax = (1000 * 0.10) + (2000 * 0.20) + ((totalAmount - 3000) * 0.30);
|
|
}
|
|
const netAmount = totalAmount - tax;
|
|
netAmountOutput.textContent = netAmount.toFixed(2);
|
|
} else {
|
|
netAmountOutput.textContent = '0.00';
|
|
}
|
|
|
|
} else {
|
|
vatAmountOutput.textContent = '0.00';
|
|
totalAmountOutput.textContent = '0.00';
|
|
netAmountOutput.textContent = '0.00';
|
|
}
|
|
}
|
|
|
|
window.setRate = function(rate) {
|
|
rateInput.value = rate;
|
|
updateCalculator();
|
|
}
|
|
|
|
amountInput.addEventListener('input', updateCalculator);
|
|
rateInput.addEventListener('input', updateCalculator);
|
|
agreementInput.addEventListener('change', updateCalculator);
|
|
|
|
// Initial calculation
|
|
updateCalculator();
|
|
}); |