forked from mbradyliu/noble-mortgage-calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.js
161 lines (133 loc) · 6.16 KB
/
func.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*begin button functions*/
function secondNext(pg1,pg2) {
changePage(pg1,pg2);
upDateVars();
}
/*end button functions*/
/*begin radio button check function*/
function getRadioValue(theRadioGroup) {
var elements = document.getElementsByName(theRadioGroup);
for (var i = 0, l = elements.length; i < l; i++)
{
if (elements[i].checked)
{
return elements[i].value;
}
}
}
/*end radio button check function*/
/*begin variable function*/
function upDateVars() {
/*begin defining input variables*/
purchasePrice= eval(document.getElementsByName("price")[0].value);
rehabCost= eval(document.getElementsByName("cost")[0].value);
ARV= eval(document.getElementsByName("ARV")[0].value);
percentArvVar = getRadioValue('percentArvVar');
period = getRadioValue('period');
nameVar= document.getElementsByName("nameVar")[0].value;
addressVar= document.getElementsByName("addressVar")[0].value;
emailVar= document.getElementsByName("emailVar")[0].value;
phoneVar= document.getElementsByName("phoneVar")[0].value;
/*end defining input variables*/
/*begin defining output variables*/
loanAmount = ARV * percentArvVar;
lendersFees = (loanAmount * period) + 750;
if (loanAmount <= 100000){
otherClosingCosts = loanAmount * 0.03;
console.log("closing costs: option 1");
} else if (loanAmount > 100000 && loanAmount <= 200000){
otherClosingCosts = loanAmount * 0.025;
console.log("closing costs: option 2");
} else if (loanAmount > 200000){
otherClosingCosts = loanAmount * 0.02;
console.log("closing costs: option 3");
}
totalClosingCosts = lendersFees + otherClosingCosts;
estimatedFundsDueAtClosing = purchasePrice + rehabCost + totalClosingCosts - loanAmount;
monthlyLoanPayments = loanAmount * 0.01;
profitForFlip = ARV - (purchasePrice + rehabCost + totalClosingCosts) - (ARV * 0.04);
equityCaptureWithRental = ARV - (purchasePrice + rehabCost + totalClosingCosts);
/*end defining output variables*/
/* DEBUG */
console.log("Monthly loan payment: " + monthlyLoanPayments);
console.log("Loan amount: " + loanAmount);
console.log("Lenders fees: " + lendersFees);
console.log("Purchase price: " + purchasePrice);
console.log("Rehab cost: " + rehabCost);
console.log("ARV: " + ARV);
console.log("Precent ARV: " + percentArvVar);
console.log("Period: " + period);
console.log("Other closing costs: " + otherClosingCosts);
console.log("Total closing costs: " + totalClosingCosts);
console.log("Estimated funds due at closing: " + estimatedFundsDueAtClosing);
console.log("Profit for flip: " + profitForFlip);
console.log("Equity capture with rental: " + equityCaptureWithRental);
console.log("Lender's Fees*: $" + lendersFees);
/* GUBED */
/*begin output variable printing*/
document.getElementsByName('out1')[0].innerHTML = "Lender's Fees*: $" +lendersFees.toFixed(2);
document.getElementsByName('out2')[0].innerHTML = "Other Closing Costs**: $" +otherClosingCosts.toFixed(2);
document.getElementsByName('out3')[0].innerHTML = "Total Closing Costs: $" +totalClosingCosts.toFixed(2);
if (estimatedFundsDueAtClosing <= 0){
document.getElementsByName('out4')[0].innerHTML = "Estimated Funds Due at Closing: $0";
} else {
document.getElementsByName('out4')[0].innerHTML = "Estimated Funds Due at Closing: $" +estimatedFundsDueAtClosing.toFixed(2);
}
document.getElementsByName('out5')[0].innerHTML = "Monthly Loan Payments: $" +monthlyLoanPayments.toFixed(2);
/* N/A block */
if (percentArvVar == 0.7){
document.getElementsByName('out6')[0].innerHTML = "Profit for Flip***: $" +profitForFlip.toFixed(2);
document.getElementsByName('out7')[0].innerHTML = "Equity Capture with Rental: N/A";
} else if (percentArvVar == 0.75){
document.getElementsByName('out6')[0].innerHTML = "Profit for Flip***: N/A";
document.getElementsByName('out7')[0].innerHTML = "Equity Capture with Rental: $" +equityCaptureWithRental.toFixed(2);
}
/* N/A block */
/*end output variable printing*/
}
/*end variable function*/
/*begin loan calculator*/
function calculateLoanAmount(){
ARV = eval(document.getElementsByName("ARV")[0].value);
percentArvVar = getRadioValue('percentArvVar');
loanAmount = (ARV * percentArvVar).toFixed(2); // JJH cut down to two digits after the decimal point
document.getElementById("loanVar").innerHTML="Loan Amount: $" + loanAmount;
}
/*end loan calculator*/
/*Begin additional options hide/unhide*/
function unhide(inner_add) {
var item = document.getElementById(inner_add);
if (item) {
item.className=(item.className=='hidden')?'unhidden':'hidden';
}
}
function emailForm(){
var src = document.referrer;
var email = "[email protected],[email protected]";
// var b1 = '%3Cb%3E';
// var b2 = '%3C%2Fb%3E';
// var br = '%3Cbr%3E';
var b1 = ''; // bold on, remove
var b2 = ''; // bold off, remove
var br = '%0D%0A'; // carriage return is now \r\n
br = b1+br;
var email_body = b1+'Purchase Price: $'+b2+purchasePrice.toFixed(2)+
br+'Rehab Cost: $'+b2+rehabCost.toFixed(2)+
br+'ARV: $'+b2+ARV.toFixed(2)+
br+'Loan Amount: $'+b2+loanAmount.toFixed(2)+
br+"Lender's Fees: $'"+b2+lendersFees.toFixed(2)+
br+'Other Closing Costs: $'+b2+otherClosingCosts.toFixed(2)+
br+'Total Closing Costs: $'+b2+totalClosingCosts.toFixed(2)+
br+'Estimated Funds Due at Closing: $'+b2+estimatedFundsDueAtClosing.toFixed(2)+
br+'Monthly Loan Payments: $'+b2+monthlyLoanPayments.toFixed(2)+
br+'Profit for Flip: $'+b2+profitForFlip.toFixed(2)+
br+'Equity Capture with Rental: $'+b2+equityCaptureWithRental.toFixed(2)+
br+'****Additional Information****'+b2+
br+'Name: '+b2+nameVar+
br+'Address:'+b2+addressVar+
br+'Email: '+b2+emailVar+
br+'Phone: '+b2+phoneVar;
var mailTo = 'mailto: '+email+'?subject=Noble App&body='+email_body;
win = window.open(mailTo,'emailWindow');
if (win && win.open &&!win.closed) win.close();
}