Your Savings Calculator
Investment Payback Period
Investment Payback Period
/* Bar chart Start */
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
// labels: ["Before", "After"],
// datasets: [{
// label: '# Monthly Bills',
// data: [20, 10, 3, 5, 2, 3],
// backgroundColor: [
// 'rgba(255, 99, 132, 0.2)',
// 'rgba(54, 162, 235, 0.2)'
// ],
// borderColor: [
// 'rgba(255,99,132,1)',
// 'rgba(54, 162, 235, 1)',
// ],
// borderWidth: 1
// }]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
/* chart end */
/* Line Chart Start */
var ctx = document.getElementById("mylineChart").getContext('2d');
var mylineChart = new Chart(ctx, {
type: 'line',
data: {
labels: [
"2018",
"2019",
"2020",
"2021",
"2022",
"2023",
"2024",
"2025",
"2026",
"2027",
"2028",
"2029",
"2030",
"2031",
"2032",
"2033",
"2034",
"2035",
"2036",
"2037"
],
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
/* Line Chart End */
function calculateBills() {
var state = [];
var tarrif = [];
selPinCode = $("#pincode").val();
var connectionType = $('.connectionType:checked').val();
debugger;
state = jQuery.grep(pinCodes, function(pin, i) {
return pin.Pincode == selPinCode;
});
if (state != undefined && state != null) {
alert(state[0].State);
}
tarrif = jQuery.grep(tarrifs, function(tarrif, i) {
return tarrif.stateName == state[0].State;
});
if (connectionType != undefined && connectionType != null) {
for (var i = 0; i < tarrif.length; i++) {
if (tarrif[i].connectionType == connectionType) {
CalulateLoad(tarrif[i].tarrif, selPinCode, connectionType, state[0].State)
}
}
}
}
function CalulateLoad(tarrif, selPinCode, connectionType, State) {
var monthlyBill = Number($("#monthlyBill").val());
var roofTopArea = Number($("#roofTopArea").val());
var calc1 = parseFloat((roofTopArea * .95) / 100).toFixed(1);
var calc2 = parseFloat((.95 * monthlyBill / (tarrif * 4 * 30)).toFixed(1));
var min = calc1 < calc2 ? calc1 : calc2;
// min*tarrif*4*30
var saving = parseInt(min * tarrif * 4 * 30);
// monthlyBill - saving
var newMonthlyBill = monthlyBill - saving;
// saving / monthyBill
var perSaving = parseInt((saving * 100) / monthlyBill);
// min*100/rooftoparea
var areaUsed = parseInt(((min * 100) / roofTopArea) * 100);
var costInLakh = parseFloat(42000 * min / 100000).toFixed(1);
var simplePayBack = parseFloat(costInLakh / (saving / 100000 * 12)).toFixed(1);
var co2Avoid = parseFloat((0.6 * min * 4 * 30 * 12) / 1000).toFixed(1);
var nper = parseFloat(Interest(0.099 / 12, saving * 0.9, -(costInLakh) * 100000 * 0.95) / 12).toFixed(1);
$("#min_calculation").html(min);
$("#spn_area").html(roofTopArea);
$("#spn_areaused").html(areaUsed);
$("#spn_cost").html(costInLakh);
$("#spn_savings").html(saving);
$("#spn_savingPer").html(perSaving);
$("#spn_npr").html(nper);
$("#spn_co2").html(co2Avoid);
$("#spn_payback").html(simplePayBack);
graphData(monthlyBill, newMonthlyBill, saving, nper);
}
function graphData(monthlyBill, newMonthlyBill, saving, nper) {
var withoutSolar = new Array();
var withSolar = new Array();
var annualbill = monthlyBill * 12;
var newAnnualBill = newMonthlyBill * 12;
for (var i = 0; i < 20; i++) {
if (i == 0) {
withoutSolar.push(annualbill);
} else {
annualbill += parseInt(annualbill * 0.005);
withoutSolar.push(annualbill);
}
}
for (var i = 0; i < 20; i++) {
if (i == 0) {
withSolar.push(newAnnualBill);
} else {
newAnnualBill += parseInt(newAnnualBill * 0.005);
withSolar.push(newAnnualBill);
}
}
myChart.data.datasets.push({
label: 'Bill Without Solar (Year)',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
data: withoutSolar
});
myChart.update();
myChart.data.datasets.push({
label: 'Bill With Solar (Year)',
backgroundColor: 'rgba(54, 162, 235, 0.2)',
data: withSolar
});
myChart.update();
mylineChart.data.datasets.push({
label: 'Bills Without Solar',
backgroundColor: 'rgba(54, 162, 235, 0.2)',
data: withoutSolar
});
mylineChart.update();
annuaLoan(saving, nper, withSolar);
}
function annuaLoan(saving, nper, withSolar) {
var loanArray = new Array();
var annualSSaving = saving * 12;
var initialValue;
for (var i = 0; i < 20; i++) {
if (i == 0) {
initialValue = (annualSSaving * 0.9) + withSolar[0]
}
if (i Math.floor(nper)) {
loanArray.push(withSolar[i]);
}
}
mylineChart.data.datasets.push({
label: 'Annual Loan Payment',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
data: loanArray
});
mylineChart.update();
}
function Interest(rate, payment, present, future, type) {
// Initialize type
var type = (typeof type === 'undefined') ? 0 : type;
// Initialize future value
var future = (typeof future === 'undefined') ? 0 : future;
// Evaluate rate and periods (TODO: replace with secure expression evaluator)
rate = eval(rate);
// Return number of periods
var num = payment * (1 + rate * type) - future * rate;
var den = (present * rate + payment * (1 + rate * type));
return Math.log(num / den) / Math.log(1 + rate);
}