@ntlab/sipd-agr 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +236 -0
- package/app/configuration.js +153 -0
- package/app/index.js +94 -0
- package/assets/enable-macro.png +0 -0
- package/assets/formating-message.png +0 -0
- package/assets/run-selected-macro.png +0 -0
- package/assets/summarize-confirm.png +0 -0
- package/assets/summarize-finish.png +0 -0
- package/assets/summarize-result.png +0 -0
- package/assets/view-macro.png +0 -0
- package/config/default.json +8 -0
- package/config.json +3 -0
- package/main.js +47 -0
- package/package.json +19 -0
- package/profiles.json +29 -0
- package/sipd/index.js +257 -0
- package/sipd/modules/agr/index.js +229 -0
- package/sipd/modules/agr/writer.js +136 -0
- package/sipd/modules/app.js +161 -0
- package/sipd/modules/ref/keg.js +72 -0
- package/sipd/modules/ref/ref.js +91 -0
- package/sipd/modules/ref/rek.js +38 -0
- package/sipd/modules/refs.js +187 -0
- package/sipd/modules/subkeg.js +221 -0
- package/sipd/script.js +73 -0
- package/sipd/util.js +146 -0
- package/tools/Agr.xlsm +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022-2025 Toha <tohenk@yahoo.com>
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
* this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
* the Software without restriction, including without limitation the rights to
|
|
9
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
10
|
+
* of the Software, and to permit persons to whom the Software is furnished to do
|
|
11
|
+
* so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const { By, until } = require('selenium-webdriver');
|
|
26
|
+
const Sipd = require('..');
|
|
27
|
+
const SipdScript = require('../script');
|
|
28
|
+
|
|
29
|
+
class SipdApp {
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Constructor.
|
|
33
|
+
*
|
|
34
|
+
* @param {Sipd} owner The owner
|
|
35
|
+
*/
|
|
36
|
+
constructor(owner) {
|
|
37
|
+
this.owner = owner;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
login() {
|
|
41
|
+
return this.owner.works([
|
|
42
|
+
[w => this.owner.findElements(By.xpath('//app-login'))],
|
|
43
|
+
[w => w.getRes(0)[0].getRect(), w => w.getRes(0).length],
|
|
44
|
+
[w => this.owner.scrollTo(w.getRes(1).y), w => w.getRes(0).length],
|
|
45
|
+
[w => this.owner.fillInForm([
|
|
46
|
+
{target: By.id('prov-autocomplete'), value: this.owner.provinsi, onfill: (el, value) => {
|
|
47
|
+
return this.owner.works([
|
|
48
|
+
[x => el.sendKeys(value)],
|
|
49
|
+
[x => this.owner.sleep(this.owner.opdelay)],
|
|
50
|
+
[x => el.findElement(By.xpath(`../ngb-typeahead-window/button/ngb-highlight/span[text()="${value}"]/../..`))],
|
|
51
|
+
[x => x.getRes(2).click()],
|
|
52
|
+
]);
|
|
53
|
+
}},
|
|
54
|
+
{target: By.name('email'), value: this.owner.username},
|
|
55
|
+
{target: By.name('password'), value: this.owner.password},
|
|
56
|
+
],
|
|
57
|
+
By.xpath('//form[@id="kt_login_signin_form"]'),
|
|
58
|
+
By.xpath('//button[@type="submit"]')
|
|
59
|
+
), w => w.getRes(0).length],
|
|
60
|
+
[w => this.waitCaptcha(), w => w.getRes(0).length],
|
|
61
|
+
[w => this.owner.sleep(this.owner.opdelay), w => w.getRes(0).length],
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setYear() {
|
|
66
|
+
return this.owner.works([
|
|
67
|
+
[w => this.owner.findElements(By.xpath('//app-tahun-anggaran-list'))],
|
|
68
|
+
[w => this.owner.fillInForm([{target: By.xpath('//select[@formcontrolname="tahun"]'), value: this.owner.year}],
|
|
69
|
+
By.xpath('//form[contains(@class,"form")]'),
|
|
70
|
+
By.xpath('//button[@type="submit"]')
|
|
71
|
+
), w => w.getRes(0).length],
|
|
72
|
+
[w => this.owner.sleep(this.owner.opdelay), w => w.getRes(0).length],
|
|
73
|
+
]);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
clickMenu(menu, options) {
|
|
77
|
+
let i = 0;
|
|
78
|
+
let items = [];
|
|
79
|
+
let menus = menu.split('|');
|
|
80
|
+
menus.forEach(item => {
|
|
81
|
+
switch (i) {
|
|
82
|
+
case 0:
|
|
83
|
+
items.push(By.xpath(`//app-aside-menu/div/span/span[text()="${item.trim()}"]`));
|
|
84
|
+
break;
|
|
85
|
+
case 1:
|
|
86
|
+
items.push(By.xpath(`../../div/div/a/span[text()="${item.trim()}"]/..`));
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
i++;
|
|
90
|
+
});
|
|
91
|
+
return this.navigateMenu(items, options);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
navigateMenu(menu, options) {
|
|
95
|
+
options = options || {};
|
|
96
|
+
if (options.click === undefined) {
|
|
97
|
+
options.click = true;
|
|
98
|
+
}
|
|
99
|
+
let mitem, url, i = 0;
|
|
100
|
+
const menus = Array.isArray(menu) ? menu : [menu];
|
|
101
|
+
const works = [];
|
|
102
|
+
menus.forEach(item => {
|
|
103
|
+
works.push(
|
|
104
|
+
[w => this.owner.findElement(mitem ? {el: mitem, data: item} : item)],
|
|
105
|
+
[w => Promise.resolve(mitem = w.res)],
|
|
106
|
+
[w => mitem.click(),
|
|
107
|
+
w => mitem && options.click],
|
|
108
|
+
[w => this.owner.sleep(this.owner.opdelay),
|
|
109
|
+
w => ++i < menus.length && mitem && options.click],
|
|
110
|
+
[w => mitem.getAttribute('href'),
|
|
111
|
+
w => i === menus.length && mitem && !options.click],
|
|
112
|
+
[w => Promise.resolve(url = w.res),
|
|
113
|
+
w => i === menus.length && mitem && !options.click],
|
|
114
|
+
[w => this.owner.getDriver().get(url + (options.params ? (url.indexOf('?') < 0 ? '?' : '&') + options.params : '')),
|
|
115
|
+
w => i === menus.length && mitem && !options.click],
|
|
116
|
+
[w => Promise.resolve(url),
|
|
117
|
+
w => i === menus.length && mitem && !options.click],
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
return this.owner.works(works);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
waitCaptcha() {
|
|
124
|
+
return this.owner.works([
|
|
125
|
+
[w => this.owner.findElements(By.xpath('//ngx-captcha'))],
|
|
126
|
+
[w => this.solveCaptcha(), w => w.getRes(0).length],
|
|
127
|
+
[w => this.waitSolvedCaptcha(), w => w.getRes(0).length && !w.getRes(1)],
|
|
128
|
+
]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
solveCaptcha() {
|
|
132
|
+
return this.owner.works([
|
|
133
|
+
[w => this.owner.getDriver().executeScript(`return getCode()`)],
|
|
134
|
+
[w => this.owner.fillFormValue({target: By.xpath('//ngx-captcha/div/div/input[@type="text"]'), value: w.getRes(0)}),
|
|
135
|
+
w => w.getRes(0)],
|
|
136
|
+
[w => this.owner.click(By.xpath('//ngx-captcha/div/div/input[@type="button"]')),
|
|
137
|
+
w => w.getRes(0)],
|
|
138
|
+
[w => this.owner.sleep(this.owner.opdelay),
|
|
139
|
+
w => w.getRes(0)],
|
|
140
|
+
[w => Promise.resolve(w.getRes(0))],
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
waitSolvedCaptcha() {
|
|
145
|
+
return this.owner.works([
|
|
146
|
+
[w => Promise.resolve(this.owner.app.showMessage('Captcha', 'Please solve the captcha first!'))],
|
|
147
|
+
[w => this.owner.waitForPresence(By.xpath('//ngx-captcha'))],
|
|
148
|
+
[w => Promise.resolve(console.log('Captcha is solved!'))],
|
|
149
|
+
]);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
showMessage(title, message) {
|
|
153
|
+
if (this.owner._url) {
|
|
154
|
+
this.owner.getDriver().executeScript(SipdScript.bootstrapModal(title, message));
|
|
155
|
+
} else {
|
|
156
|
+
console.log(message);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
module.exports = SipdApp;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022-2025 Toha <tohenk@yahoo.com>
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
* this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
* the Software without restriction, including without limitation the rights to
|
|
9
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
10
|
+
* of the Software, and to permit persons to whom the Software is furnished to do
|
|
11
|
+
* so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const SipdRef = require('./ref');
|
|
26
|
+
|
|
27
|
+
class SipdRefKegiatan extends SipdRef {
|
|
28
|
+
|
|
29
|
+
initialize() {
|
|
30
|
+
this.name = 'M_KEG';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
import(data) {
|
|
34
|
+
SipdRefKegiatan.merge(SipdRefKegiatan.MAPS[SipdRefKegiatan.URUSAN], data, this.items);
|
|
35
|
+
SipdRefKegiatan.merge(SipdRefKegiatan.MAPS[SipdRefKegiatan.BIDANG_URUSAN], data, this.items);
|
|
36
|
+
SipdRefKegiatan.merge(SipdRefKegiatan.MAPS[SipdRefKegiatan.PROGRAM], data, this.items);
|
|
37
|
+
SipdRefKegiatan.merge(SipdRefKegiatan.MAPS[SipdRefKegiatan.KEGIATAN], data, this.items);
|
|
38
|
+
SipdRefKegiatan.merge(SipdRefKegiatan.MAPS[SipdRefKegiatan.SUB_KEGIATAN], data, this.items);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static get URUSAN() {
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static get BIDANG_URUSAN() {
|
|
46
|
+
return 2;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static get PROGRAM() {
|
|
50
|
+
return 3;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static get KEGIATAN() {
|
|
54
|
+
return 4;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static get SUB_KEGIATAN() {
|
|
58
|
+
return 5;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static get MAPS() {
|
|
62
|
+
return {
|
|
63
|
+
[this.URUSAN]: ['id_urusan', 'kode_urusan', 'nama_urusan'],
|
|
64
|
+
[this.BIDANG_URUSAN]: ['id_bidang_urusan', 'kode_bidang_urusan', 'nama_bidang_urusan'],
|
|
65
|
+
[this.PROGRAM]: ['id_program', 'kode_program', 'nama_program'],
|
|
66
|
+
[this.KEGIATAN]: ['id_giat', 'kode_giat', 'nama_giat'],
|
|
67
|
+
[this.SUB_KEGIATAN]: ['id_sub_giat', 'kode_sub_giat', 'nama_sub_giat'],
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = SipdRefKegiatan;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022-2025 Toha <tohenk@yahoo.com>
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
* this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
* the Software without restriction, including without limitation the rights to
|
|
9
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
10
|
+
* of the Software, and to permit persons to whom the Software is furnished to do
|
|
11
|
+
* so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const path = require('path');
|
|
26
|
+
const Excel = require('exceljs');
|
|
27
|
+
const SipdUtil = require('../../util');
|
|
28
|
+
|
|
29
|
+
class SipdRef {
|
|
30
|
+
|
|
31
|
+
name = null
|
|
32
|
+
items = {}
|
|
33
|
+
|
|
34
|
+
constructor() {
|
|
35
|
+
this.initialize();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
initialize() {
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exportXls(outdir) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
try {
|
|
44
|
+
const filename = path.join(outdir, `${this.name}.xlsx`);
|
|
45
|
+
console.log('Creating ref %s...', filename);
|
|
46
|
+
const wb = new Excel.Workbook();
|
|
47
|
+
const sheet = wb.addWorksheet(this.name);
|
|
48
|
+
let row = 0;
|
|
49
|
+
const items = Object.values(this.items)
|
|
50
|
+
.sort((a, b) => a.kode.localeCompare(b.kode));
|
|
51
|
+
for (const item of items) {
|
|
52
|
+
if (row === 0) {
|
|
53
|
+
row++;
|
|
54
|
+
sheet.getRow(row).getCell(1).value = 'ID';
|
|
55
|
+
sheet.getRow(row).getCell(2).value = 'KODE';
|
|
56
|
+
sheet.getRow(row).getCell(3).value = 'NAMA';
|
|
57
|
+
}
|
|
58
|
+
row++;
|
|
59
|
+
sheet.getRow(row).getCell(1).value = item.id;
|
|
60
|
+
sheet.getRow(row).getCell(2).value = item.kode;
|
|
61
|
+
sheet.getRow(row).getCell(3).value = item.nama;
|
|
62
|
+
}
|
|
63
|
+
wb.xlsx.writeFile(filename);
|
|
64
|
+
resolve();
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
reject(err);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
clear() {
|
|
73
|
+
this.items = {};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static merge(cols, data, items) {
|
|
77
|
+
if (Array.isArray(data)) {
|
|
78
|
+
const [colId, colKode, colNama] = cols;
|
|
79
|
+
for (const row of data) {
|
|
80
|
+
const id = row[colId];
|
|
81
|
+
const kode = SipdUtil.cleanKode(row[colKode]);
|
|
82
|
+
const nama = row[colNama];
|
|
83
|
+
if (items[kode] === undefined) {
|
|
84
|
+
items[kode] = {id, kode, nama};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = SipdRef;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022-2025 Toha <tohenk@yahoo.com>
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
* this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
* the Software without restriction, including without limitation the rights to
|
|
9
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
10
|
+
* of the Software, and to permit persons to whom the Software is furnished to do
|
|
11
|
+
* so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const SipdRef = require('./ref');
|
|
26
|
+
|
|
27
|
+
class SipdRefRekening extends SipdRef {
|
|
28
|
+
|
|
29
|
+
initialize() {
|
|
30
|
+
this.name = 'M_KODEREK';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
import(data) {
|
|
34
|
+
SipdRefRekening.merge(['id_akun', 'kode_akun', 'nama_akun'], data, this.items);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = SipdRefRekening;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022-2025 Toha <tohenk@yahoo.com>
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
* this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
* the Software without restriction, including without limitation the rights to
|
|
9
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
10
|
+
* of the Software, and to permit persons to whom the Software is furnished to do
|
|
11
|
+
* so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const { glob } = require('glob');
|
|
27
|
+
const path = require('path');
|
|
28
|
+
const Queue = require('@ntlab/work/queue');
|
|
29
|
+
const Sipd = require('..');
|
|
30
|
+
const SipdRefKegiatan = require('./ref/keg');
|
|
31
|
+
const SipdRefRekening = require('./ref/rek');
|
|
32
|
+
|
|
33
|
+
class SipdRefs {
|
|
34
|
+
|
|
35
|
+
refs = []
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Constructor.
|
|
39
|
+
*
|
|
40
|
+
* @param {Sipd} owner The owner
|
|
41
|
+
*/
|
|
42
|
+
constructor(owner) {
|
|
43
|
+
this.owner = owner;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
download(outdir, skipDownload) {
|
|
47
|
+
if (!fs.existsSync(outdir)) {
|
|
48
|
+
fs.mkdirSync(outdir);
|
|
49
|
+
}
|
|
50
|
+
return this.owner.works([
|
|
51
|
+
[w => this.downloadRefs(outdir), w => !skipDownload],
|
|
52
|
+
[w => this.importRefs(outdir)],
|
|
53
|
+
[w => this.exportXls(outdir)],
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
downloadRefs(outdir) {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
const refs = [
|
|
60
|
+
{page: 'Referensi | Akun', name: 'rek.json', uri: '/api/master/akun/listNew'},
|
|
61
|
+
{page: 'Referensi | Sub Kegiatan', name: 'keg.json', uri: [
|
|
62
|
+
['/api/master/sub_giat/list_table'],
|
|
63
|
+
['/api/master/urusan/find_by_id_urusan_list', 'id_urusan'],
|
|
64
|
+
['/api/master/bidang_urusan/find_by_id_bidang_urusan_list', 'id_bidang_urusan'],
|
|
65
|
+
['/api/master/program/find_by_id_program_list', 'id_program'],
|
|
66
|
+
['/api/master/giat/find_by_id_giat_list', 'id_giat'],
|
|
67
|
+
]},
|
|
68
|
+
{page: 'Standar Harga Satuan | A S B', name: 'asb.json', uri: '/api/master/d_komponen/listAll'},
|
|
69
|
+
{page: 'Standar Harga Satuan | H S P K', name: 'hspk.json', uri: '/api/master/d_komponen/listAll'},
|
|
70
|
+
{page: 'Standar Harga Satuan | S B U', name: 'sbu.json', uri: '/api/master/d_komponen/listAll'},
|
|
71
|
+
{page: 'Standar Harga Satuan | S S H', name: 'ssh.json', uri: '/api/master/d_komponen/listAll'},
|
|
72
|
+
];
|
|
73
|
+
const q = new Queue(refs, ref => {
|
|
74
|
+
this.downloadFromPage(outdir, ref)
|
|
75
|
+
.then(() => q.next())
|
|
76
|
+
.catch(err => reject(err))
|
|
77
|
+
;
|
|
78
|
+
});
|
|
79
|
+
q.once('done', () => resolve());
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
downloadFromPage(outdir, data, page = 1, count = 1000) {
|
|
84
|
+
console.log('Downloading file %s...', data.name);
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const items = [];
|
|
87
|
+
const f = () => {
|
|
88
|
+
const works = [
|
|
89
|
+
[w => this.owner.app.clickMenu(data.page, {click: false, params: `pageIndex=${page}&pageSize=${count}`})]
|
|
90
|
+
];
|
|
91
|
+
const responses = {};
|
|
92
|
+
const uris = Array.isArray(data.uri) ? data.uri : [data.uri];
|
|
93
|
+
for (const uri of uris) {
|
|
94
|
+
const uriId = Array.isArray(uri) ? uri[0] : uri;
|
|
95
|
+
works.push(
|
|
96
|
+
[w => this.owner.waitForResponse(uriId)],
|
|
97
|
+
[w => Promise.resolve(responses[uriId] = w.res)],
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
this.owner.works(works)
|
|
101
|
+
.then(() => {
|
|
102
|
+
let result;
|
|
103
|
+
for (const uri of uris) {
|
|
104
|
+
const uriId = Array.isArray(uri) ? uri[0] : uri;
|
|
105
|
+
// main result
|
|
106
|
+
if (result === undefined) {
|
|
107
|
+
result = responses[uriId];
|
|
108
|
+
} else if (Array.isArray(uri) && uri.length > 1) {
|
|
109
|
+
// merge result
|
|
110
|
+
const subresult = responses[uriId];
|
|
111
|
+
for (const row of result.data) {
|
|
112
|
+
subresult
|
|
113
|
+
.filter(r => r[uri[1]] === row[uri[1]])
|
|
114
|
+
.forEach(r => {
|
|
115
|
+
const kode = 'kode' + uri[1].substr(2);
|
|
116
|
+
const nama = 'nama' + uri[1].substr(2);
|
|
117
|
+
row[kode] = r[kode];
|
|
118
|
+
row[nama] = r[nama];
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
items.push(...result.data);
|
|
124
|
+
const recordsTotal = result.recordsTotal;
|
|
125
|
+
const pages = Math.ceil(recordsTotal / count);
|
|
126
|
+
if (page === pages) {
|
|
127
|
+
fs.writeFileSync(path.join(outdir, data.name), JSON.stringify(items, null, 2));
|
|
128
|
+
resolve();
|
|
129
|
+
} else {
|
|
130
|
+
page++;
|
|
131
|
+
f();
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
.catch(err => reject(err))
|
|
135
|
+
;
|
|
136
|
+
}
|
|
137
|
+
f();
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
importRefs(outdir) {
|
|
142
|
+
return this.owner.works([
|
|
143
|
+
[w => glob(path.join(outdir, '*.json'), {withFileTypes: true, windowsPathsNoEscape: true})],
|
|
144
|
+
[w => new Promise((resolve, reject) => {
|
|
145
|
+
let count = 0;
|
|
146
|
+
const files = w.getRes(0);
|
|
147
|
+
const q = new Queue(files, f => {
|
|
148
|
+
let added = false;
|
|
149
|
+
const filename = path.join(f.path, f.name);
|
|
150
|
+
switch (f.name.toLowerCase()) {
|
|
151
|
+
case 'rek.json':
|
|
152
|
+
const rek = new SipdRefRekening();
|
|
153
|
+
rek.import(JSON.parse(fs.readFileSync(filename)));
|
|
154
|
+
this.refs.push(rek);
|
|
155
|
+
added = true;
|
|
156
|
+
break;
|
|
157
|
+
case 'keg.json':
|
|
158
|
+
const keg = new SipdRefKegiatan();
|
|
159
|
+
keg.import(JSON.parse(fs.readFileSync(filename)));
|
|
160
|
+
this.refs.push(keg);
|
|
161
|
+
added = true;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
if (added) {
|
|
165
|
+
count++;
|
|
166
|
+
}
|
|
167
|
+
q.next();
|
|
168
|
+
});
|
|
169
|
+
q.once('done', () => resolve(count));
|
|
170
|
+
})]
|
|
171
|
+
]);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
exportXls(outdir) {
|
|
175
|
+
return new Promise((resolve, reject) => {
|
|
176
|
+
const q = new Queue(this.refs, ref => {
|
|
177
|
+
ref.exportXls(outdir)
|
|
178
|
+
.then(() => q.next())
|
|
179
|
+
.catch(err => reject(err))
|
|
180
|
+
;
|
|
181
|
+
});
|
|
182
|
+
q.once('done', () => resolve());
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
module.exports = SipdRefs;
|