-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
254 lines (234 loc) · 8.51 KB
/
index.js
File metadata and controls
254 lines (234 loc) · 8.51 KB
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
/*
* INTER-Mediator
* Copyright (c) INTER-Mediator Directive Committee (http://inter-mediator.org)
* This project started at the end of 2009 by Masayuki Nii msyk@msyk.net.
*
* INTER-Mediator is supplied under MIT License.
* Please see the full license for details:
* https://github.com/INTER-Mediator/INTER-Mediator/blob/master/dist-docs/License.txt
*/
INTERMediatorOnPage.doBeforeConstruct = function () {
INTERMediator.alwaysAddOperationExchange = true;
INTERMediatorLog.suppressDebugMessageOnPage = true;
INTERMediatorOnPage.buttonClassCopy = "btn btn-info"
INTERMediatorOnPage.buttonClassDelete = "btn btn-warning"
INTERMediatorOnPage.buttonClassInsert = "btn btn-success"
INTERMediatorOnPage.buttonClassMaster = "btn btn-primary"
INTERMediatorOnPage.buttonClassBackNavi = "btn btn-primary"
INTERMediator.lcConditionsOP1AND = false
INTERMediator.lcConditionsOP2AND = true
INTERMediator.lcConditionsOP3AND = 'AND'
const dataSource = INTERMediatorOnPage.getDataSources()
for (const key in dataSource) {
if (dataSource[key].name === "account_list" && copyDetail) {
dataSource[key]["repeat-control"] = "confirm-insert confirm-delete confirm-copy-detail_copy"
}
}
INTERMediatorOnPage.getDataSources = () => {
return dataSource
}
};
INTERMediatorOnPage.doAfterConstruct = function () {
document.getElementById("panelcontent").addEventListener('click', (event) => {
event.stopPropagation()
})
document.getElementById("panelcontent2").addEventListener('click', (event) => {
event.stopPropagation()
})
document.getElementById("option-clear").addEventListener('click', (event) => {
event.stopPropagation()
})
document.getElementById('container').style.display = 'block'
stickyHeaderTableAdjust()
INTERMediator.scrollBack(-125 - 157, document.querySelector(".sticky-header-table"))
}
INTERMediatorOnPage.doAfterValueChange = (idValue) => {
const targetNode = document.getElementById(idValue)
const targetSpec = targetNode.getAttribute('data-im')
if (targetSpec.indexOf('preference@copy_detail') === 0) {
INTERMediator.constructMain();
}
}
INTERMediatorOnPage.doAfterCreateRecord = (newId, contextName) => {
if (contextName === 'account_list') {
INTERMediator.moveAnotherURL(`index_detail.html?id=${newId}`)
}
}
function clearConditions() {
IMLibLocalContext.clearAllConditions()
INTERMediator.clearCondition('account_list')
INTERMediator.constructMain(IMLibContextPool.contextFromName('account_list'))
}
function exportAccount() {
INTERMediator.moveAnotherURL('index_contexts.php?media=class://AccountCSV/account_all')
}
function moveDetailPage(aid) {
aid = parseInt(aid)
INTERMediator.prepareToScrollBack('account_list', aid)
INTERMediator.moveAnotherURL(`index_detail.html?id=${aid}`)
}
function setCondition(n) {
if (parseInt(n) > 0 && parseInt(n) < 3) {
const y = (new Date()).getFullYear() - parseInt(n) + 1
IMLibLocalContext.setValue('condition:account_list:issued_date:>=', `${y}-01-01`)
IMLibLocalContext.setValue('condition:account_list:issued_date:<=', `${y}-12-31`)
INTERMediator.constructMain()
} else if (parseInt(n) === 3) {
const start = new Date()
start.setMonth(start.getMonth() - 2)
start.setDate(1)
start.setHours(start.getHours() + 9)
const end = new Date()
end.setMonth(end.getMonth() + 2)
end.setDate(0)
end.setHours(end.getHours() + 9)
IMLibLocalContext.setValue('condition:account_list:issued_date:>=', start.toISOString().substring(0, 10))
IMLibLocalContext.setValue('condition:account_list:issued_date:<=', end.toISOString().substring(0, 10))
INTERMediator.constructMain()
}
}
function showPanel() {
document.getElementById('funcpanel').style.display = 'block'
}
function hidePanel() {
document.getElementById('funcpanel').style.display = 'none'
}
function showPanel2() {
document.getElementById('funcpanel2').style.display = 'block'
}
function hidePanel2() {
document.getElementById('funcpanel2').style.display = 'none'
}
function csvReadSMBC() {
csvReadBankImpl(0, 1, 2, 3, 1)
}
function csvReadMuzuho() {
csvReadBankImpl(1, 2, 3, 4, 10)
}
function csvReadPayPay() {
csvReadBankImpl(10000, 8, 9, 7, 1)
}
function csvReadRakuten() {
csvReadBankImpl(20000, 1, 1, 3, 1)
}
let accountId = -1
function csvReadBankImpl(dateCol, outCol, inCol, descCol, skipLine) {
if (!(dateCol >= 0) || !(outCol >= 0) || !(inCol >= 0) || !(descCol >= 0) || !(skipLine >= 0)) {
console.log('why!?')
return
}
let is8DigitDate = false
let isSepDate = false
if (dateCol > 19999) {
is8DigitDate = true
dateCol = dateCol % 20000
} else if (dateCol > 9999) {
isSepDate = true
dateCol = dateCol % 10000
}
const src = document.getElementById('csv_data').value
var srcTemp = src
if (src.indexOf("\"") !== -1) {
srcTemp = src.replace(/\"/g, "")
}
const lines = srcTemp.split('\n')
let count = 0
for (const line of lines) {
const items = line.split(',')
if (count >= skipLine && items.length > 3) {
let dateComps
if (is8DigitDate) {
dateComps = [items[dateCol].substring(0, 4), items[dateCol].substring(4, 6), items[dateCol].substring(6, 8)]
} else if (isSepDate) {
dateComps = [items[dateCol], items[dateCol + 1], items[dateCol + 2]]
} else {
if (items[dateCol].indexOf('/') > 0) {
dateComps = items[dateCol].split('/')
} else if (items[dateCol].indexOf('.') > 0) {
dateComps = items[dateCol].split('.')
}
if (items[dateCol].indexOf('-') > 0) {
dateComps = items[dateCol].split('-')
}
}
dateComps[1] = `0${dateComps[1]}`
dateComps[2] = `0${dateComps[2]}`
const dateValue = dateComps[0] + "-" + dateComps[1].substring(dateComps[1].length - 2)
+ "-" + dateComps[2].substring(dateComps[2].length - 2)
IMLibQueue.setTask((complete) => {
const data = [
{field: 'description', value: items[descCol]},
{field: 'issued_date', value: dateValue},
{field: 'assort_pattern_id', value: ""},
{field: 'debit_id', value: (items[inCol] > 0) ? 115 : 2},
{field: 'credit_id', value: (items[inCol] > 0) ? 2 : 115},
{field: 'company', value: items[descCol]}
]
INTERMediator_DBAdapter.db_createRecord_async({name: 'account_add', dataset: data}, (result) => {
accountId = result.dbresult[0]['account_id']
INTERMediatorLog.flushMessage()
complete()
}, () => {
INTERMediatorLog.flushMessage()
complete()
})
})
IMLibQueue.setTask((complete) => {
if (!(parseInt(accountId) > 0)) {
complete()
return
}
const data = [
{field: 'account_id', value: accountId},
{field: 'description', value: items[descCol]},
{field: 'unit_price', value: Math.abs(outCol === inCol ? items[outCol] : items[outCol] + items[inCol])},
{field: 'qty', value: 1}
]
INTERMediator_DBAdapter.db_createRecord_async({name: 'detail_add', dataset: data}, (result) => {
INTERMediatorLog.flushMessage()
complete()
}, () => {
INTERMediatorLog.flushMessage()
complete()
})
})
}
count += 1
}
IMLibQueue.setTask((complete) => {
complete()
INTERMediator.constructMain()
})
}
function uiIdSearch(id) {
id = parseInt(id)
if (id > 0) {
INTERMediator.clearCondition('account_list')
IMLibLocalContext.clearAllConditions()
IMLibLocalContext.setValue('condition:account_list:account_id,parent_account_id:=', id)
INTERMediator.constructMain(IMLibContextPool.contextFromName('account_list'))
}
}
function codeSearch(debit, credit, mode = null) {
hidePanel2()
if (document.getElementById("option-clear").checked) {
IMLibLocalContext.clearAllConditions()
}
INTERMediator.clearCondition('account_list')
if (debit) {
INTERMediator.addCondition('account_list', {field: 'debit_id', value: debit})
}
if (credit) {
INTERMediator.addCondition('account_list', {field: 'credit_id', value: credit})
}
if (mode === "typeA") {
INTERMediator.addCondition('account_list', {field: 'parent_account_id', operator: "IS NULL"})
}
if (mode === "typeB") {
INTERMediator.addCondition('account_list', {field: 'parent_account_id', operator: "IS NOT NULL"})
}
if (mode === "typeC") {
INTERMediator.addCondition('account_list', {field: 'item_total', operator: "<>", value: "@parent_total@"})
}
INTERMediator.constructMain(IMLibContextPool.contextFromName('account_list'))
}