$(function() {
function resize() { $(".row").each(function(a) { var max_height = 0;
// Reset element heights $(this).find("p").height("auto");
// Find the maximum element height $(this).find("p").each(function(a) { if($(this).height() > max_height) max_height = $(this).height(); });
// Set all elements height to be max_height $(this).find("p").height(max_height) }) } $(window).resize(resize); resize();
$("select").on("change", function () { $(this).removeClass("initial"); })
function calculate() {
let sale_price = Number($("input").eq(0).val()); let closing_costs = Number($("input").eq(1).val()); let current_debt = Number($("input").eq(2).val());
let c_replacement_val = sale_price - closing_costs; let c_cash_down = c_replacement_val - current_debt;
$("input:disabled").eq(0).val(format_usd(c_replacement_val)); $("input:disabled").eq(1).val(format_usd(c_cash_down)); $("input:disabled").eq(2).val(format_usd(current_debt));
// let sale_price = Number($("input").eq(0).val()); // let closing_costs = Number($("input").eq(1).val()); // let state_tax_perc = Number($("select option:selected").val());
// let c_net_sale = sale_price - closing_costs; // let c_sale_tax_total = ((15 + 3.8 + state_tax_perc) / 100) * c_net_sale; // let c_reinv_sale = c_net_sale; // let c_reinv_exchange = c_net_sale;
// $("input:disabled").eq(0).val(format_usd(c_net_sale)); // $("input:disabled").eq(1).val(format_usd(c_sale_tax_total)); // $("input:disabled").eq(2).val(format_usd(c_net_sale - c_sale_tax_total));
// $("input:disabled").eq(3).val(format_usd(c_net_sale)); // $("input:disabled").eq(4).val(format_usd(0)); // $("input:disabled").eq(5).val(format_usd(c_net_sale)); }
// function calculate() { // $(".value").html("-") // let percentage_arr = [ // [67,null,17,1,15], // Apartment // [null,75,10,5,10], // Office // [null,68,19,1,12], // Hotel // [73,null,18,1,8], // Residential // [null,73,15,0,12], // Retail // [null,67,23,0,10], // Restaurant // [null,78,5,5,12], // [null,69,11,1,19], // [null,71,19,5,5] // ];
// let property_value = Number($("input").eq(0).val()); // let land_value = Number($("input").eq(1).val()); // if(land_value > 50) { // $("input").eq(1).val(50); // land_value = 50; // } // if(property_value == 0 || land_value == 0) return false;
// var property_perc = percentage_arr[$("select").prop("selectedIndex")];
// var val_5_7_15 = []; // for(let i = 0; i < 6; i++) { // if(property_perc[i] == null && i != 5) { // $(".value").eq(i).html("-") // }else{ // let val = 0; // if(i == 0) { // val = ((property_value - (property_value * (land_value / 100))) * (property_perc[i] / 100)) / 27.5; // }else if(i == 1) { // val = ((property_value - (property_value * (land_value / 100))) * (property_perc[i] / 100)) / 39; // }else if(i == 5) { // val = val_5_7_15.reduce((a, b) => a + b, 0); // }else{ // val = (property_value - (property_value * (land_value / 100))) * (property_perc[i] / 100); // val_5_7_15.push(val); // } // $(".value").eq(i).html(format_usd(val)) // } // }
// // Inputs // var market_value = parseInt($("input[name='market-value']").val()); // var purchase_price = parseInt($("input[name='purchase-price']").val()); // var down_payment = parseInt($("input[name='down-payment']").val()); // var closing_costs = parseInt($("input[name='closing-costs']").val()); // var interest_rate = parseFloat($("input[name='interest-rate']").val()); // var monthly_rent = parseInt($("input[name='monthly-rent']").val()); // var annual_property_taxes = parseInt($("input[name='annual-property-tax']").val()); // var annual_utilities = parseInt($("input[name='annual-utilities']").val()); // var annual_landscaping = parseInt($("input[name='annual-landscaping']").val()); // var annual_insurance_premium = parseInt($("input[name='annual-insurance']").val()); // var vacancy_rate = parseFloat($("input[name='vacancy-rate']").val()); // var maintenance_rate = parseFloat($("input[name='maintenance-rate']").val()); // var management_rate = parseFloat($("input[name='management-rate']").val());
// // Interest calculations // var a_12 = interest_rate / (12 * 100) // var a_13 = Math.pow(1 + a_12, 360); // var a_14 = (a_12 * a_13) / (a_13 - 1);
// // Calculations // var initial_equity = market_value - purchase_price; // var amount_financed = purchase_price * ((100 - down_payment) / 100); // var down_payment_amount = purchase_price * (down_payment / 100); // var total_cash_investment = down_payment_amount + closing_costs; // var debt_service_monthly = a_14 * amount_financed; // var debt_service_yearly = debt_service_monthly * 12; // var gross_scheduled_income = monthly_rent * 12; // var less_vacancy_amount = -gross_scheduled_income * (vacancy_rate / 100); // var gross_operating_income = gross_scheduled_income + less_vacancy_amount; // var property_management = -gross_operating_income * (management_rate / 100); // annual_property_taxes = -annual_property_taxes; // annual_utilities = -annual_utilities; // annual_landscaping = -annual_landscaping; // annual_insurance_premium = -annual_insurance_premium; // var repairs_maintenance = -gross_operating_income * (maintenance_rate / 100); // var total_operating_expenses = property_management + annual_property_taxes + annual_utilities + annual_landscaping + annual_insurance_premium + repairs_maintenance; // var net_operating_income = gross_operating_income + total_operating_expenses; // var less_debt_service = -debt_service_yearly; // var before_tax_cash_flow = net_operating_income + less_debt_service; // var cash_on_cash_roi = (before_tax_cash_flow / total_cash_investment) * 100;
// // Result printing // $(".results").find("input").eq(0).val(format_usd(initial_equity)); // $(".results").find("input").eq(1).val(format_usd(amount_financed)); // $(".results").find("input").eq(2).val(format_usd(down_payment_amount)); // $(".results").find("input").eq(3).val(format_usd(total_cash_investment)); // $(".results").find("input").eq(4).val(format_usd(debt_service_monthly)); // $(".results").find("input").eq(5).val(format_usd(debt_service_yearly)); // $(".results").find("input").eq(6).val(format_usd(gross_scheduled_income)); // $(".results").find("input").eq(7).val(format_usd(less_vacancy_amount)); // $(".results").find("input").eq(8).val(format_usd(gross_operating_income)); // $(".results").find("input").eq(9).val(format_usd(property_management)); // $(".results").find("input").eq(10).val(format_usd(annual_property_taxes)); // $(".results").find("input").eq(11).val(format_usd(annual_utilities)); // $(".results").find("input").eq(12).val(format_usd(annual_landscaping)); // $(".results").find("input").eq(13).val(format_usd(annual_insurance_premium)); // $(".results").find("input").eq(14).val(format_usd(repairs_maintenance)); // $(".results").find("input").eq(15).val(format_usd(total_operating_expenses)); // $(".results").find("input").eq(16).val(format_usd(net_operating_income)); // $(".results").find("input").eq(17).val(format_usd(less_debt_service)); // $(".results").find("input").eq(18).val(format_usd(before_tax_cash_flow)); // $(".results").find("input").eq(19).val(cash_on_cash_roi ? cash_on_cash_roi.toFixed(2) + "%" : "Wrong input");
$("input").on("input", calculate); $("select").on("change", calculate); calculate();
function format_usd(num) { if(isNaN(num)) return "Wrong input" var p = num.toFixed(2).split("."); return (num < 0 ? "-" : "") + "$" + p[0].split("").reverse().reduce(function(acc, num, i, orig) { return num == "-" ? acc : num + (i && !(i % 3) ? "," : "") + acc; }, "") + (p[1] == "00" ? "" : "." + p[1]); } });