-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstock-final.html
444 lines (403 loc) · 23.3 KB
/
stock-final.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/website/images/stock/favicon.ico">
<link rel="apple-touch-icon" sizes="180x180" href="/website/images/stock/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/website/images/stock/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/website/images/stock/favicon-16x16.png">
<title>Stock Pro - TienPD3</title>
<!-- spreadjs -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2014-11-29/FileSaver.min.js"></script>
<link rel="stylesheet" type="text/css" href="website/css/common/function.spreadjs.css">
<link rel="stylesheet" type="text/css" href="website/css/spreadjs/gc.spread.sheets.excel2013white.16.0.2.css">
<script type="text/javascript" src="website/scripts/spreadjs/gc.spread.sheets.all.16.0.2.min.latest.js"></script>
<script type="text/javascript" src="website/scripts/spreadjs/interop/gc.spread.excelio.16.0.2.min.latest.js"></script>
<script type="text/javascript" src="website/license/spreadjs/license-grapecity.js"></script>
<!-- / spreadjs -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<!-- aui.atlassian.com -->
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/aui/9.5.1/aui/aui-prototyping.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/sinon.js/15.0.1/sinon.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/aui/9.5.1/aui/aui-prototyping.min.js"></script>
<!-- / aui.atlassian.com -->
<!-- momentjs -->
<script type="text/javascript" src="website/scripts/momentjs/moment.min.js"></script>
<!-- / momentjs -->
<!-- common -->
<script type="text/javascript" src="website/common/VersionUtils.js"></script>
<script type="text/javascript" src="website/common/DatetimeUtils.js"></script>
<script>
const plugins = [
'/website/common/function.finpath.js',
'/website/common/StringUtils.js',
'/website/common/BusinessRuleUtils.js'
];
plugins.forEach(plugin => VersionUtils.importPlugin(plugin));
</script>
<script>document.write('<script src="/website/common/const.js?version=' + DatetimeUtils.getSystemDateTime() + '"><\/script>');</script>
<script type="text/javascript" src="website/common/function.common.js"></script>
<script type="text/javascript" src="website/common/function.spreadjs.js"></script>
<script type="text/javascript" src="website/common/function.update.js"></script>
<script type="text/javascript" src="website/common/function.simplize.js"></script>
<script type="text/javascript" src="website/common/function.vietstock.js"></script>
<script type="text/javascript" src="website/common/function.fireant.trend.js"></script>
<script type="text/javascript" src="website/common/function.fireant.valuation.js"></script>
<!-- / common -->
<!-- site -->
<script type="text/javascript" src="https://e.cafef.vn/kby.ashx"></script>
<!-- / site -->
<script>
$(document).ready(function() {
localStorage.removeStorageExpires();
buildUrlSimplize();
var firstValue = buildDropdownStockList();
initBuildDropdownStockCode(firstValue.id, firstValue.rules);
$('#drpdStockList').on('change', function() {
const selectedOption = $(this).find('option:selected');
const id = selectedOption.attr('id');
const rules = selectedOption.attr('rules');
initBuildDropdownStockCode(id, rules);
var drpdSelected = JSON.parse(localStorage.getStorage('drpdSelected')) || {};
drpdSelected.stockListSelected = id;
localStorage.setStorage('drpdSelected', JSON.stringify(drpdSelected));
});
$('#drpdStockCode').on('change', onChangeStockCode);
$('#btnNext').on('click', saveWhiteList);
$('#idWarning').text(stockListSimplizeNewData);
});
function saveWhiteList() {
const selectedOption = $('#drpdStockCode').find('option:selected');
const tmpSymbol = selectedOption.attr('id');
const tmpTickerStockExchange = selectedOption.text();
saveGoodStock(tmpSymbol, tmpTickerStockExchange);
doNext();
}
function doNext() {
const last = $("#drpdStockCode > option").last();
const current = $("#drpdStockCode > option:selected");
if (last[0] !== current[0]) {
if (!$('#chkAutoStockNoValue').is(":checked")) {
$('#btnNext').prop('disabled', false);
}
current.prop("selected", false).next().prop("selected", true);
} else {
$('#btnNext').prop('disabled', true);
}
onChangeStockCode();
}
function isCheckElementStockCodeLast() {
const last = $("#drpdStockCode > option").last();
const current = $("#drpdStockCode > option:selected");
return last[0] === current[0];
}
function initBuildDropdownStockCode(pId, pRules) {
buildDropdownStockCode(pId, pRules);
AJS.$("#drpdStockCode").auiSelect2();
onChangeStockCode();
}
function onChangeStockCode() {
AJS.$("#drpdStockCode").auiSelect2();
const pSymbol = $('#drpdStockCode').find('option:selected').attr('id');
const filter = oc.find(elm => elm.c === pSymbol);
if (filter) {
loadData(filter.c, filter.m, filter.san);
}
const drpdSelected = JSON.parse(localStorage.getStorage('drpdSelected')) || {};
drpdSelected.stockCodeSelected = pSymbol;
localStorage.setStorage('drpdSelected', JSON.stringify(drpdSelected));
}
$(document).on('change', '#chkAutoStockNoValue', function() {
if (this.checked) {
saveWhiteList();
}
});
</script>
<script>
var spread, excelIO, loadingStatus;
function loadData(pSymbol, pName, pExchange) {
setParameter(pSymbol, pName, pExchange);
loadFile(pExchange, pSymbol, pName);
}
function loadFile(pExchange, pSymbol, pName) {
const isYear = true;
getFinancial(pExchange, pSymbol, pName, isYear).then(() => {
excelIo = new GC.Spread.Excel.IO();
const excelUrl = `${document.getElementById('importUrl').value}?cache=${uuidv4()}`;
if (loadingStatus) {
loadingStatus.updateText("Đang xử lý");
$('.gc-play-loading').removeClass('hide');
}
const oReq = new XMLHttpRequest();
oReq.open('get', excelUrl, true);
oReq.responseType = 'blob';
oReq.onload = function () {
const blob = oReq.response;
excelIo.open(blob, function (json) {
let jsonExcel = JSON.stringify(json);
// Chuyển mã chứng khoán
jsonExcel = jsonExcel.replaceExcel('#SYMBOL', `${pSymbol}: ${pName}`);
// Tạo Sheet Định giá
// Tạo Sheet chi tiết
const mpDataQSortDESC = new Map([...mpYearMonthData].sort().reverse());
const mpDataQSort = new Map([...mpYearMonthData].sort());
// Xóa phần tử thừa Quý
let mpDataYSortDESC = new Map([...mpYearData].sort().reverse());
mpDataYSortDESC = new Map([...mpDataYSortDESC].splice(0, 5));
const mpDataYSortASC = new Map([...mpDataYSortDESC].sort());
// Theo quý
let idxQ = 0;
const clazzNetRevenue = new BusinessRuleUtils();
const clazzGrossProfit = new BusinessRuleUtils();
const clazzOwnerEquity = new BusinessRuleUtils();
const clazzNetIncomeStatement = new BusinessRuleUtils();
const arrNetRevenue = [];
const arrGrossProfit = [];
const arrOwnerEquity = [];
mpDataQSortDESC.forEach((data, keys) => {
// Title quý
jsonExcel = jsonExcel.replaceExcel(`#DGQ${idxQ}`, keys);
// LNST theo Quý
jsonExcel = jsonExcel.replaceExcel(`#DGLNSTValQ${idxQ}`, StringUtils.formatCashBillion(data.LNST?.new));
// VCSH theo Quý
jsonExcel = jsonExcel.replaceExcel(`#DGVCSHValQ${idxQ}`, StringUtils.formatCashBillion(data.ownerEquity?.new));
// Nợ/LNST
const NDHLNST = data.longTermDebt?.new ? (data.longTermDebt?.new / data.LNST?.new) : '';
jsonExcel = jsonExcel.replaceExcel(`#DGNDHLNSTValQ${idxQ}`, NDHLNST);
jsonExcel = jsonExcel.replaceExcel(`#DGNDHValQ${idxQ}`, StringUtils.formatCashBillionComma(data.longTermDebt?.new));
// Tính toán doanh thu tăng đều
clazzNetRevenue.isGrowUp(data.netRevenue?.new);
if (arrNetRevenue.length <= 4) {
arrNetRevenue.push(StringUtils.formatCashBillionComma(data.netRevenue?.new));
}
// Tính toán lợi nhuận gộp tăng đều
clazzGrossProfit.isGrowUp(data.grossProfit?.new);
if (arrGrossProfit.length <= 4) {
arrGrossProfit.push(StringUtils.formatCashBillionComma(data.grossProfit?.new));
}
// Tính toán vốn chủ sở hữu tăng đều
clazzOwnerEquity.isGrowUp(data.ownerEquity?.new);
if (arrOwnerEquity.length <= 4) {
arrOwnerEquity.push(StringUtils.formatCashBillionComma(data.ownerEquity?.new));
}
// Tính toán dòng tiền dương từ HĐKD dương
clazzNetIncomeStatement.isPositiveCashFlow(data.netIncomeStatement?.new);
idxQ++;
});
// Thị giá cổ phiếu
jsonExcel = jsonExcel.replaceExcel('#DGTGCPVal', dataFACurrent.priceClose);
// Tổng số lượng cổ phiếu
jsonExcel = jsonExcel.replaceExcel('#DGTSLCPVal', dataFACurrent.sharesOutstanding);
// Tỷ lệ cổ tức
jsonExcel = jsonExcel.replaceExcel('#DGTLCTVal', dataFACurrent.dividendPercent);
jsonExcel = jsonExcel.replaceExcel('#DGCT', dataFACurrent.dividend);
// Doanh thu tăng đều
jsonExcel = jsonExcel.replaceExcel('#DGDTTUpVal', clazzNetRevenue.varObj.isGrowUp);
jsonExcel = jsonExcel.replaceExcel('#DGArrayDTTVal', arrNetRevenue.join(', '));
// Lợi nhuận gộp tăng đều
jsonExcel = jsonExcel.replaceExcel('#DGLNGUpVal', clazzGrossProfit.varObj.isGrowUp);
jsonExcel = jsonExcel.replaceExcel('#DGArrayLNGVal', arrGrossProfit.join(', '));
// Vốn chủ sở hữu tăng đều
jsonExcel = jsonExcel.replaceExcel('#DGVCSHUpVal', clazzOwnerEquity.varObj.isGrowUp);
jsonExcel = jsonExcel.replaceExcel('#DGArrayVCSHVal', arrOwnerEquity.join(', '));
// Tỷ lệ lãi gộp
jsonExcel = jsonExcel.replaceExcel('#DGGOSVal', dataFACurrent.grossMargin);
// Tỷ lệ lãi ròng
jsonExcel = jsonExcel.replaceExcel('#DGNPMVal', dataFACurrent.netProfitMargin);
// ROA
jsonExcel = jsonExcel.replaceExcel('#DGROAVal', dataFACurrent.ROA);
// ROE
jsonExcel = jsonExcel.replaceExcel('#DGROEVal', dataFACurrent.ROE);
// ROIC
jsonExcel = jsonExcel.replaceExcel('#DGROICVal', dataFACurrent.ROIC);
// Nợ/VCSH
jsonExcel = jsonExcel.replaceExcel('#DGDOEVal', dataFACurrent.debtOnEquity);
// PE
jsonExcel = jsonExcel.replaceExcel('#DGPEVal', dataFACurrent.PE);
// PB
jsonExcel = jsonExcel.replaceExcel('#DGPBVal', dataFACurrent.PB);
// Dòng tiền từ HĐKD dương
jsonExcel = jsonExcel.replaceExcel('#DGHDKDVal', clazzNetIncomeStatement.varObj.isPositiveCashFlow);
// Theo năm
let idxY = 0;
mpDataYSortASC.forEach((data, keys) => {
jsonExcel = jsonExcel.replaceExcel(`#HY${idxY}`, keys);
jsonExcel = jsonExcel.replaceExcel(`#HLNSTValY${idxY}`, data.LNST?.new / 1000000000);
idxY++;
});
let idxFYQ = 0;
let mpDataFYQ = mpDataQSortDESC;
if (isYear) {
mpDataFYQ = mpDataYSortDESC;
}
jsonExcel = jsonExcel.replaceExcel('#EPSTitle', isYear ? 'NĂM' : 'QUÝ');
mpDataFYQ.forEach((data, keys) => {
// 1. CÁC CHỈ SỐ TÀI CHÍNH:
jsonExcel = jsonExcel.replaceExcel(`#FYQ${idxFYQ}`, keys);
jsonExcel = jsonExcel.replaceExcel(`#EPSVal${idxFYQ}`, data.EPS?.new);
jsonExcel = jsonExcel.replaceExcel(`#PBVal${idxFYQ}`, data.PB?.new);
jsonExcel = jsonExcel.replaceExcel(`#PEVal${idxFYQ}`, data.PE?.new);
jsonExcel = jsonExcel.replaceExcel(`#ROAVal${idxFYQ}`, data.ROA?.new);
jsonExcel = jsonExcel.replaceExcel(`#ROEVal${idxFYQ}`, data.ROE?.new);
// 2. BCTC
// TÀI SẢN
jsonExcel = jsonExcel.replaceExcel(`#TTSVal${idxFYQ}`, data.TTS?.new);
jsonExcel = jsonExcel.replaceExcel(`#TTSOldVal${idxFYQ}`, data.TTS?.old);
// NỢ
jsonExcel = jsonExcel.replaceExcel(`#NOVal${idxFYQ}`, data.NO?.new);
jsonExcel = jsonExcel.replaceExcel(`#NOOldVal${idxFYQ}`, data.NO?.old);
// VCSH
jsonExcel = jsonExcel.replaceExcel(`#VCSHVal${idxFYQ}`, data.ownerEquity?.new);
jsonExcel = jsonExcel.replaceExcel(`#VCSHOldVal${idxFYQ}`, data.ownerEquity?.old);
// DOANH THU
jsonExcel = jsonExcel.replaceExcel(`#DTTVal${idxFYQ}`, data.netRevenue?.new);
jsonExcel = jsonExcel.replaceExcel(`#DTTOldVal${idxFYQ}`, data.netRevenue?.old);
// LNG
jsonExcel = jsonExcel.replaceExcel(`#LNGVal${idxFYQ}`, data.grossProfit?.new);
jsonExcel = jsonExcel.replaceExcel(`#LNGOldVal${idxFYQ}`, data.grossProfit?.old);
// LNST
jsonExcel = jsonExcel.replaceExcel(`#LNSTVal${idxFYQ}`, data.LNST?.new);
jsonExcel = jsonExcel.replaceExcel(`#LNSTOldVal${idxFYQ}`, data.LNST?.old);
idxFYQ++;
});
jsonExcel = jsonExcel.replaceExcel('#Symbol', pSymbol);
jsonExcel = JSON.parse(jsonExcel);
if (!spread) {
spread = new GC.Spread.Sheets.Workbook(document.getElementById("spreadSheet"));
const statusBar = initStatusBar(spread);
loadingStatus = new LoadingStatus('LoadingStatus', { tipText: 'Đang xử lý' });
statusBar.add(loadingStatus);
}
spread.fromJSON(jsonExcel, {
incrementalLoading: {
loading: (progress, args) => loadingStatus.updateProgress(progress, args),
loaded: () => {
loadingStatus.updateText(`Lấy dữ liệu ${pSymbol} thành công`);
$('.gc-play-loading').addClass('hide');
autoNextStock();
}
}
});
activeSheet(spread, 'Định giá');
spread.options.scrollbarAppearance = GC.Spread.Sheets.ScrollbarAppearance.mobile;
spread.options.showVerticalScrollbar = false;
spread.options.scrollbarShowMax = false;
spread.options.tabEditable = true;
spread.options.newTabVisible = true;
spread.options.tabNavigationVisible = false;
spread.options.tabStripPosition = GC.Spread.Sheets.TabStripPosition.top;
}, console.log);
};
oReq.send(null);
});
}
let sleepNext = null;
function autoNextStock() {
clearInterval(sleepNext);
const sheet = spread.getActiveSheet();
const cellValue = sheet.getText(13, 3);
const tempIsGoodStock = cellValue === 'YES';
if ($('#chkAutoStockNoValue').is(":checked")) {
if ($('#chkSaveWhitelist').is(":checked")) {
let idx = 5;
sleepNext = setInterval(() => {
if (idx <= 0) {
clearInterval(sleepNext);
if (isCheckElementStockCodeLast()) {
$('#btnNext').prop('disabled', true).text('Kiểm tra mã tiếp theo');
} else {
saveWhiteList();
}
}
$('#btnNext').prop('disabled', true).text(tempIsGoodStock ? `Cổ phiếu cần đánh giá, tiếp tục sau ${idx} giây` : `Cổ phiếu không tốt, tiếp tục sau ${idx} giây`);
idx--;
}, 1000);
} else {
if (!tempIsGoodStock) {
let idx = 5;
sleepNext = setInterval(() => {
if (idx <= 0) {
clearInterval(sleepNext);
if (isCheckElementStockCodeLast()) {
$('#btnNext').prop('disabled', true).text('Kiểm tra mã tiếp theo');
} else {
saveWhiteList();
}
}
$('#btnNext').prop('disabled', true).text(`Cổ phiếu không tốt, tiếp tục sau ${idx} giây`);
idx--;
}, 1000);
} else {
$('#btnNext').prop('disabled', isCheckElementStockCodeLast()).text('Kiểm tra mã tiếp theo');
}
}
} else {
$('#btnNext').prop('disabled', isCheckElementStockCodeLast()).text('Kiểm tra mã tiếp theo');
}
}
function saveGoodStock(pSymbol, tickerStockExchange) {
const sheet = spread.getActiveSheet();
const cellValue = sheet.getText(13, 3);
let tmpStockValueList = localStorage.getStorage('stockValue');
tmpStockValueList = tmpStockValueList ? JSON.parse(tmpStockValueList) : [];
if (cellValue === 'NO') {
tmpStockValueList = tmpStockValueList.filter(row => row.ticker !== pSymbol);
localStorage.setStorage('stockValue', JSON.stringify(tmpStockValueList), UNLIMITED);
return false;
} else {
if (!tmpStockValueList.some(row => row.ticker === pSymbol)) {
tmpStockValueList.push({ ticker: pSymbol, stockExchange: tickerStockExchange });
}
localStorage.setStorage('stockValue', JSON.stringify(tmpStockValueList), UNLIMITED);
return true;
}
}
</script>
</head>
<body>
<form class="aui">
<i class="red" id="idWarning" for="warning"></i>
<div></div>
<label for="drpdStockList">Bộ lọc chứng khoán</label>
<div id="idStockList">
<select class="select" id="drpdStockList" name="drpdStockList"></select>
<input type="checkbox" name="chkAutoStockNoValue" id="chkAutoStockNoValue">
<label for="chkAutoStockNoValue">Tự động bỏ qua cổ phiếu không giá trị</label>
</div>
<label for="drpdStockCode">Mã chứng khoán</label>
<div id="idStockCode">
<select class="select" id="drpdStockCode" name="drpdStockCode" placeholder="Vui lòng chọn mã chứng khoán"></select>
<input type="checkbox" name="chkSaveWhitelist" id="chkSaveWhitelist">
<label for="chkSaveWhitelist">Tự động lưu Whitelist</label>
</div>
<legend><span>Radio buttons</span></legend>
<div class="radio">
<input type="radio" checked="checked" name="radiobuttons" id="radioButtonOne">
<label for="radioButtonOne">Quý</label>
</div>
<div class="radio">
<input type="radio" name="radiobuttons" id="radioButtonTwo">
<label for="radioButtonTwo">Năm</label>
</div>
</form>
<!-- Spinner -->
<div class="gc-playground_view">
<div id="spreadSheet" style="width: 100%; height: 550px;"></div>
<div class="gc-play-loading">
<div class="indicator-wrapper gcim_hidden">
<div class="loading-ring" style="height: 30px; width: 30px;">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
</div>
</div>
<div id="statusBar"></div>
<!-- / Spinner -->
<input type="hidden" id="importUrl" value="website/file/template_final.xlsx" />
<button id="btnNext" class="aui-button aui-button-primary">Kiểm tra mã tiếp theo</button>
</body>
</html>