function calculateSmartBill() {
const totalAmount = parseFloat(document.getElementById(‘totalAmount’).value);
const discountPercentage = parseFloat(document.getElementById(‘discountPercentage’).value);
const lateFee = parseFloat(document.getElementById(‘lateFee’).value);
if (isNaN(totalAmount) || totalAmount <= 0) {
alert("Please enter a valid total bill amount.");
return;
}
if (isNaN(discountPercentage) || discountPercentage < 0) {
alert("Please enter a valid discount percentage.");
return;
}
if (isNaN(lateFee) || lateFee < 0) {
alert("Please enter a valid late fee.");
return;
}
// Calculate discount and final bill
const discountAmount = (totalAmount * discountPercentage) / 100;
const totalAfterDiscount = totalAmount – discountAmount;
const finalAmountDue = totalAfterDiscount + lateFee;
// Update results
document.getElementById('totalPayment').value = totalAfterDiscount.toFixed(2);
document.getElementById('finalDue').value = finalAmountDue.toFixed(2);
}
function resetCalculator() {
document.getElementById('totalAmount').value = '';
document.getElementById('discountPercentage').value = '';
document.getElementById('lateFee').value = '';
document.getElementById('dueDate').value = '';
document.getElementById('totalPayment').value = '';
document.getElementById('finalDue').value = '';
}
.calculator-container {
background-color: #f7f7f7;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: auto;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.calculator-header {
text-align: center;
margin-bottom: 20px;
}
.form-label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-input {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
.btn-calculate, .btn-reset {
background-color: #007bff;
color: white;
padding: 12px;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
width: 48%;
}
.btn-reset {
background-color: #6c757d;
}
.btn-calculate:hover, .btn-reset:hover {
opacity: 0.9;
}
.result-section {
margin-top: 20px;
}
.result-section .form-label {
margin-top: 10px;
}