This repository has been archived by the owner on Oct 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
218 lines (204 loc) · 9.77 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.2.1/css/flag-icon.min.css" />
<title>XP Investments - Bonds Report</title>
</head>
<body>
<nav class="navbar navbar-light bg-light mb-2">
<a class="navbar-brand h1" href="#">
<img src="https://www.xpi.us/1cdf6aa129184658f19c5fcceb695cd7.svg" alt="XP Investments">
<span class="ml-3 align-bottom">Bonds Report</span>
</a>
</nav>
<div class="container-fluid">
<form id="form" class="mb-4">
<div class="form-group">
<label for="reportLink">Report Link</label>
<input type="text" name="reportLink" id="reportLink" class="form-control" aria-describedby="reportLinkHelp" placeholder="Enter report link" required>
<small id="reportLinkHelp" class="form-text text-muted">Add the report link received by e-mail from XP Investments.</small>
</div>
<button type="submit" class="btn btn-primary" id="sendReport">Submit</button>
</form>
<form>
<div class="form-check">
<input type="checkbox" id="showAllFields" class="form-check-input">
<label for="showAllFields" class="form-check-label">Show all fields</label>
</div>
</form>
<table class="table table-striped table-hover table-bordered" id="result">
<thead>
<tr>
<th class="align-middle" scope="col" rowspan="2">Name</th>
<th class="align-middle" scope="col" rowspan="2">Security</th>
<th class="align-middle" scope="col" rowspan="2">Coupon</th>
<th class="align-middle" scope="col" rowspan="2">Yield</th>
<th class="align-middle" scope="col" rowspan="2">Maturity</th>
<th class="align-middle" scope="col" rowspan="2">Last Price</th>
<th class="align-middle" scope="col" rowspan="2">Current Price</th>
<th class="align-middle" scope="col" rowspan="2">Duration</th>
<th class="align-middle" scope="col" rowspan="2">Years to Maturity</th>
<th class="align-middle" scope="col" rowspan="2">Minimum Piece</th>
<th class="align-middle" scope="col" rowspan="2">Country</th>
<th class="align-middle" scope="col" colspan="3"><a href="https://en.wikipedia.org/wiki/Credit_rating#Corporate_credit_ratings">Risk</a></th>
<th class="align-middle" scope="col" rowspan="2">Code</th>
</tr>
<tr>
<th class="align-middle" scope="col"><a href="https://www.standardandpoors.com">S&P</a></th>
<th class="align-middle" scope="col"><a href="https://www.moodys.com">Moody's</a></th>
<th class="align-middle" scope="col"><a href="https://www.fitchratings.com">Fitch</a></th>
</tr>
</thead>
</table>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/plug-ins/1.10.19/dataRender/datetime.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"></script>
<script lang="text/javascript">
$(document).ready(function() {
var datatable = $("#result").DataTable({
columns: [
{ data: "name" },
{
data: "security",
visible: false
},
{ data: "coupon" },
{
data: "yield",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
var yield = parseFloat(oData.yield);
var coupon = parseFloat(oData.coupon);
var percentage = (yield*100/coupon)-100;
if (yield < coupon) {
$(nTd).html("<span class='text-success'>"+oData.yield+" (<i class='fas fa-arrow-down'></i> " + percentage.toFixed(2) + "%)</span>");
} else if (yield > coupon) {
$(nTd).html("<span class='text-danger'>"+oData.yield+" (<i class='fas fa-arrow-up'></i> " + percentage.toFixed(2) + "%)</span>");
} else {
$(nTd).html(oData.yield);
}
}
},
{ data: "maturity" },
{
data: "lastPrice",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
$(nTd).html(numeral(oData.lastPrice).format("$0,0.00"));
}
},
{
data: "currentPrice",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
if (oData.currentPriceURL !== null && oData.currentPrice !== null) {
var currentPrice = parseFloat(oData.currentPrice);
var currentPriceStr = numeral(oData.currentPrice).format("$0,0.00");
var lastPrice = parseFloat(oData.lastPrice);
var percentage = (currentPrice*100/lastPrice)-100;
if (currentPrice < lastPrice) {
$(nTd).html("<a class='text-success' href='"+oData.currentPriceURL+"'>"+currentPriceStr+" (<i class='fas fa-arrow-down'></i> " + percentage.toFixed(2) + "%)</a>");
} else if (currentPrice > lastPrice) {
$(nTd).html("<a class='text-danger' href='"+oData.currentPriceURL+"'>"+currentPriceStr+" (<i class='fas fa-arrow-up'></i> " + percentage.toFixed(2) + "%)</a>");
} else {
$(nTd).html("<a href='"+oData.currentPriceURL+"'>"+currentPriceStr+"</a>");
}
} else if (oData.currentPriceURL !== null) {
$(nTd).html("<a href='"+oData.currentPriceURL+"'>reference</a>");
} else {
$(nTd).html("-");
}
}
},
{
data: "duration",
visible: false
},
{
data: "yearsToMaturity",
visible: false
},
{
data: "minimumPiece",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
$(nTd).html(numeral(oData.minimumPiece).format("$0,0.00"));
}
},
{
data: "country",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
$(nTd).addClass("text-center");
$(nTd).html("<span class='flag-icon flag-icon-" + oData.country.toLowerCase() + "'></span>");
}
},
{ data: "risk.standardPoor" },
{ data: "risk.moody" },
{ data: "risk.fitch" },
{
data: "code",
visible: false
}
],
columnDefs: [{
targets: 4,
render: $.fn.dataTable.render.moment("YYYY-MM-DDTHH:mm:ssZ", "YYYY-MM-DD")
}],
"order": [[ 2, "desc" ]],
"paging": false
});
$("#form").on("submit", function(e) {
e.preventDefault();
$("#sendReport").addClass("disabled");
$("#sendReport").html("<i class='fa fa-cog fa-spin'></i> Processing");
// ATTENTION
// ---------
//
// url configured for localhost testing, please replace for the AWS API
// route or your webserver address
$.ajax({
url: "http://localhost:8090/",
method: "post",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
location: $("#reportLink").val()
}),
dataType: "json",
success: function(data, textStatus, jqXHR) {
datatable.clear().draw();
datatable.rows.add(data);
datatable.columns.adjust().draw();
$("#sendReport").removeClass("disabled");
$("#sendReport").html("Submit");
},
error: function(jqXHR, textStatus, errorThrown) {
console.info(jqXHR);
alert("Request failed");
$("#sendReport").removeClass("disabled");
$("#sendReport").html("Submit");
}
});
});
$("#showAllFields").on("click", function(e) {
if (this.checked) {
datatable.column(1).visible(true);
datatable.column(7).visible(true);
datatable.column(8).visible(true);
datatable.column(14).visible(true);
} else {
datatable.column(1).visible(false);
datatable.column(7).visible(false);
datatable.column(8).visible(false);
datatable.column(14).visible(false);
}
});
});
</script>
</body>
</html>