/
index.html
220 lines (189 loc) · 7.76 KB
/
index.html
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<html>
<head>
<title>BMW Lease Offer Decoder</title>
<style>
body {
color:#414141;
font-family: Helvetica Neue,-apple-system,"system-ui",serif;
margin-left: 20%;
margin-right: 20%;
}
textarea {
color:rgb(28,105,211);
font-family: Helvetica Neue,-apple-system,"system-ui",serif;
width:80%;
}
hr {
unicode-bidi: isolate;
margin-block-start: 0.5em;
margin-block-end: 0.5em;
margin-inline-start: auto;
margin-inline-end: auto;
overflow: hidden;
}
input {
margin: 10px;
border:1px solid transparent;
color: rgb(255,255,255);
background-color: rgb(28,105,211);
width: 30%;
}
dl {
line-height: px2em(27px);
}
dl, dt {
margin: 0;
padding: 0;
font-size: px2em(12px);
}
dt {
width: 60%;
font-weight: bold;
text-align: right;
}
dd {
width: 25%;
float: left;
clear: left;
}
#errorMsg {
color: rgb(255,0,0)
}
</style>
</head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-1GGNXE17FG"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-1GGNXE17FG');
</script>
<script type="text/javascript">
function showError(msg) {
const errorMsg =document.getElementById('errorMsg');
errorMsg.innerHTML = msg;
errorMsg.style.display = 'block';
return true;
}
function setValue(elementId, text) {
document.getElementById(elementId).innerHTML = text;
}
function hide(elementId){
document.getElementById(elementId).style.display = 'none';
}
function onDecode () {
hide('errorMsg');
hide('resultDiv');
const dealInfo = document.getElementById('dealInfo').value;
const moneyFormat = Intl.NumberFormat('en-US',{style:'currency', currency:'USD', maximumFractionDigits:0});
const msrpMatch = dealInfo.match(/MSRP of ([\$\d\,]+)/i);
if (!msrpMatch)
{
return showError('MSRP was not found.');
}
const msrp = Number(msrpMatch[1].replace(/[\$,]/g,''));
setValue('resultMSRP', moneyFormat.format(msrp));
const capCostMatch = dealInfo.match(/adjusted capitalized cost of ([\$\d,]+)/i);
if (!capCostMatch)
{
return showError('Adjusted capitalized cost was not found.');
}
const capCost = Number(capCostMatch[1].replace(/[\$,]/g,''));
setValue('resultCapCost', moneyFormat.format(capCost));
const rvMatch = dealInfo.match(/Purchase option price at lease end is ([\$\d,]+)/i);
if (!rvMatch)
{
return showError('Residual value was not found.');
}
const rv = Number(rvMatch[1].replace(/[\$,]/g,''));
setValue('resultResidual', moneyFormat.format(rv));
const monthlyMatch = dealInfo.match(/Monthly lease payments of ([\$\d,]+)/i);
if (!monthlyMatch)
{
return showError('Monthly payment amount was not found.');
}
const monthly = Number(monthlyMatch[1].replace(/[\$,]/g,''));
setValue('resultMonthly', moneyFormat.format(monthly));
const termMatch = dealInfo.match(/for ([\d]+) months/i);
if (!termMatch)
{
return showError('Lease term was not found.');
}
const term = Number(termMatch[1]);
setValue('resultTerm', term + ' months');
const milesMatch = dealInfo.match(/mile over ([\d,]+) miles/i);
if (milesMatch)
{
setValue('resultMiles', milesMatch[1]);
}
const mf = Math.round(((monthly * term - (capCost - rv))/((capCost + rv) * term)) * 100000) / 100000;
setValue('resultMF', mf);
setValue('resultAPR', Math.round(mf*2400 * 100)/100+'%');
const residualPercent = Math.round(100 * rv / msrp);
setValue('resultResidualPercent', residualPercent + '%');
const monthlyDepreciation = Math.round(((capCost-rv)/term)* 100) /100;
setValue('resultMonthlyDepreciation', moneyFormat.format(monthlyDepreciation));
const monthlyRent = monthly - monthlyDepreciation;
setValue('resultMonthlyRent', moneyFormat.format(monthlyRent));
const totalDepreciation = capCost-rv;
setValue('resultTotalDepreciation', moneyFormat.format(totalDepreciation));
const totalRent = monthlyRent * term;
setValue('resultTotalRent', moneyFormat.format(totalRent));
const totalCost = monthly * term;
setValue('resultTotalCost', moneyFormat.format(totalCost));
document.getElementById('resultDiv').style.display = 'block';
return true;
}
</script>
<body>
<h1>BMW Lease Offer Decoder</h1>
<hr/>
<form action="javascript:void(0);" >
<p>
Paste the Important Information paragraph of the advertised lease offer: <a href="https://g80.bimmerpost.com/forums/showthread.php?t=2033843" target="_blank" style="text-decoration:none">ⓘ</a>
</p>
<textarea rows="10" id="dealInfo" name="dealInfo" placeholder="Monthly lease payments of ..."></textarea>
<input type="submit" value="Decode" onclick="onDecode()"/>
</form>
<div style="clear:both"></div>
<div id="errorMsg" style="display:none"></div>
<div id="resultDiv" style="display:none">
<hr>
<div>
<dl>
<dd>Money Factor</dd>
<dt id="resultMF"></dt>
<dd>Equivalent APR</dd>
<dt id="resultAPR"></dt>
<dd>Residual</dd>
<dt id="resultResidualPercent"></dt>
<hr>
<dd>Monthly Payment</dd>
<dt id="resultMonthly"></dt>
<dd>Term</dd>
<dt id="resultTerm"></dt>
<dd>Miles</dd>
<dt id="resultMiles"></dt>
<dd>MSRP</dd>
<dt id="resultMSRP"></dt>
<dd>Adjusted Cap Cost</dd>
<dt id="resultCapCost"></dt>
<dd>Residual Value</dd>
<dt id="resultResidual"></dt>
<hr>
<dd>Total Cost</dd>
<dt id="resultTotalCost"></dt>
<dd>Total Depreciation</dd>
<dt id="resultTotalDepreciation"></dt>
<dd>Total Rent</dd>
<dt id="resultTotalRent"></dt>
<dd>Monthly Depreciation</dd>
<dt id="resultMonthlyDepreciation"></dt>
<dd>Monthly Rent</dd>
<dt id="resultMonthlyRent"></dt>
</dl>
</div>
</div>
</body>
</html>