回答編集履歴
1
追加
test
CHANGED
@@ -42,323 +42,465 @@
|
|
42
42
|
|
43
43
|
|
44
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
|
-
|
45
|
+
|
46
|
+
|
47
|
+
```JS
|
48
|
+
|
49
|
+
/**
|
50
|
+
|
51
|
+
* エレメントの属性値
|
52
|
+
|
53
|
+
*/
|
54
|
+
|
55
|
+
var elementId = {
|
56
|
+
|
57
|
+
downpayment: "downpayment", // 頭金
|
58
|
+
|
59
|
+
amount: "amount", // 製品料金
|
60
|
+
|
61
|
+
cb_amount: "cb_amount", // ボーナス併用払い
|
62
|
+
|
63
|
+
years: "years" // yearsコンボボックス
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
/**
|
70
|
+
|
71
|
+
* yearsコンボボックス要素
|
72
|
+
|
73
|
+
*/
|
74
|
+
|
75
|
+
var yearsElement = {
|
76
|
+
|
77
|
+
blank: {
|
78
|
+
|
79
|
+
value: "",
|
80
|
+
|
81
|
+
dispName: "select payment yeart",
|
82
|
+
|
83
|
+
intValue: 0,
|
84
|
+
|
85
|
+
interest: 0
|
86
|
+
|
87
|
+
},
|
88
|
+
|
89
|
+
aa1: {
|
90
|
+
|
91
|
+
value: "aa1",
|
92
|
+
|
93
|
+
dispName: "1 year payment",
|
94
|
+
|
95
|
+
intValue: 1,
|
96
|
+
|
97
|
+
interest: 1.5
|
98
|
+
|
99
|
+
},
|
100
|
+
|
101
|
+
bb2: {
|
102
|
+
|
103
|
+
value: "bb2",
|
104
|
+
|
105
|
+
dispName: "2 year payment",
|
106
|
+
|
107
|
+
intValue: 2,
|
108
|
+
|
109
|
+
interest: 2.5
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
/**
|
118
|
+
|
119
|
+
* DOMLoaded
|
120
|
+
|
121
|
+
*/
|
122
|
+
|
123
|
+
document.addEventListener("DOMContentLoaded", function(e) {
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
// submit
|
128
|
+
|
129
|
+
document.loanform.addEventListener('submit', function(e) {
|
130
|
+
|
131
|
+
onSubmit(e);
|
132
|
+
|
133
|
+
});
|
134
|
+
|
135
|
+
// yearsコンボボックス要素設定
|
136
|
+
|
137
|
+
setSelectboxValue(elementId.years, yearsElement);
|
138
|
+
|
139
|
+
}, false)
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
/**
|
144
|
+
|
145
|
+
* サブミットイベント
|
146
|
+
|
147
|
+
*/
|
148
|
+
|
149
|
+
function onSubmit(e) {
|
150
|
+
|
151
|
+
// 入力チェック通過後、calculateResultsを実行する
|
152
|
+
|
153
|
+
if (checkValue()) {
|
154
|
+
|
155
|
+
// 活性制御
|
156
|
+
|
157
|
+
document.getElementById('results').style.display = 'none';
|
158
|
+
|
159
|
+
document.getElementById('loading').style.display = 'block';
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
// calculateResults実行
|
164
|
+
|
165
|
+
setTimeout(calculateResults, 3500);
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
e.preventDefault();
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
/**
|
176
|
+
|
177
|
+
* セレクトボックス要素設定
|
178
|
+
|
179
|
+
* @param id セットするセレクトボックスのid
|
180
|
+
|
181
|
+
* @param object セットするオブジェクト
|
182
|
+
|
183
|
+
* セットするオブジェクトはkey.valueの形式であること
|
184
|
+
|
185
|
+
*/
|
186
|
+
|
187
|
+
function setSelectboxValue(id, object) {
|
188
|
+
|
189
|
+
let selectBox = document.getElementById(id);
|
190
|
+
|
191
|
+
let loopCnt = 1;
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
// 要素数分ループ
|
196
|
+
|
197
|
+
Object.keys(object).forEach(function(key) {
|
198
|
+
|
199
|
+
let element = document.createElement("option");
|
200
|
+
|
201
|
+
element.value = object[key].value;
|
202
|
+
|
203
|
+
element.innerHTML = object[key].dispName;
|
204
|
+
|
205
|
+
if (loopCnt == 1) {
|
206
|
+
|
207
|
+
element.selected = true;
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
selectBox.appendChild(element);
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
loopCnt++;
|
216
|
+
|
217
|
+
});
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
/**
|
224
|
+
|
225
|
+
* 計算前チェック処理
|
226
|
+
|
227
|
+
* @return チェックOK:true, チェックNG:false
|
228
|
+
|
229
|
+
*/
|
230
|
+
|
231
|
+
function checkValue() {
|
232
|
+
|
233
|
+
let rtn = true; // 返却用
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
let downpayment = document.getElementById(elementId.downpayment).value; // 頭金
|
238
|
+
|
239
|
+
let amount = document.getElementById(elementId.amount).value; // 製品料金
|
240
|
+
|
241
|
+
let cb_amount = document.getElementById(elementId.cb_amount).value; // ボーナス支払い金額
|
242
|
+
|
243
|
+
let selectedYears = document.getElementById(elementId.years).value; // yearsコンボボックス
|
244
|
+
|
245
|
+
// 必須チェック
|
246
|
+
|
247
|
+
if (!amount) {
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
// amountが未設定の場合エラー
|
252
|
+
|
253
|
+
showError("Please check amount");
|
254
|
+
|
255
|
+
rtn = false;
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
} else if (!downpayment) {
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
// downpaymentが未設定の場合エラー
|
264
|
+
|
265
|
+
showError("Please check downpayment.");
|
266
|
+
|
267
|
+
rtn = false;
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
} else if (!cb_amount) {
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
// cb_amountが未設定の場合エラー
|
276
|
+
|
277
|
+
showError("Please check cb_amount.");
|
278
|
+
|
279
|
+
rtn = false;
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
} else if (!selectedYears) {
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
// yearsが未選択の場合エラー
|
288
|
+
|
289
|
+
showError("Please check selectbox of years.");
|
290
|
+
|
291
|
+
rtn = false;
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
// 必須チェックがtrueの場合、相関チェックを行う
|
300
|
+
|
301
|
+
if (rtn) {
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
if (cb_amount >= ( amount - downpayment ) / 2 ) {
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
// ボーナス併用払い金額 >= 商品代金と頭金の差額 / 2の場合エラー
|
310
|
+
|
311
|
+
showError("正しい金額を入力してください");
|
312
|
+
|
313
|
+
rtn = false;
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
// チェック通過
|
322
|
+
|
323
|
+
return rtn;
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
/**
|
330
|
+
|
331
|
+
* 金利の算出
|
332
|
+
|
333
|
+
*/
|
334
|
+
|
335
|
+
function calculateResults(e) {
|
336
|
+
|
337
|
+
let downpayment = document.getElementById(elementId.downpayment).value; // 頭金
|
338
|
+
|
339
|
+
let amount = document.getElementById(elementId.amount).value; // 製品料金
|
340
|
+
|
341
|
+
let cb_amount = document.getElementById(elementId.cb_amount).value; // ボーナス支払い金額
|
342
|
+
|
343
|
+
let years, interest;
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
// yearsコンボボックス内選択値に応じて、years, interestをENUMから設定
|
348
|
+
|
349
|
+
let selectedYears = document.getElementById(elementId.years).value; // yearsコンボボックス
|
350
|
+
|
351
|
+
years = yearsElement[selectedYears].intValue;
|
352
|
+
|
353
|
+
interest = yearsElement[selectedYears].interest;
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
// 算出
|
358
|
+
|
359
|
+
console.log('Calculating...');
|
360
|
+
|
361
|
+
console.log('downpayment = ' + downpayment);
|
362
|
+
|
363
|
+
console.log('amount = ' + amount);
|
364
|
+
|
365
|
+
console.log('cb_amount = ' + cb_amount);
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
const difference = amount - downpayment; // 商品代金と頭金の差額
|
372
|
+
|
373
|
+
const cbTimes = years * 2; // ボーナス支払いの回数
|
374
|
+
|
375
|
+
const cbEveryPayment = cb_amount / cbTimes; // ボーナス一回あたりに支払う金額
|
376
|
+
|
377
|
+
const paymentTimes = years * 12; // 支払い回数(ボーナス除く)
|
378
|
+
|
379
|
+
const interestMod = 1 + (interest / 100); // 手を加えた金利を算出
|
380
|
+
|
381
|
+
// const amountWithoutBns = difference * interestMod;
|
382
|
+
|
383
|
+
const totalPayment = (difference - cb_amount) * interestMod; // ボーナス支払い以外の支払金額を算出
|
384
|
+
|
385
|
+
const justDevideMonthlyPayment = totalPayment / paymentTimes; // ひと月辺りの支払額を一度算出
|
386
|
+
|
387
|
+
const secondToLastMonthlyPayment = (Math.floor(justDevideMonthlyPayment / 100) * 100); // 10円単位の切り捨て
|
388
|
+
|
389
|
+
const firstMonthlyPayment = totalPayment - (secondToLastMonthlyPayment * (paymentTimes - 1)); // 切り捨て額を1ヶ月目の支払額に集約
|
390
|
+
|
391
|
+
const totalInterest = (difference * interestMod) - difference; // 商品にかかる金利
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
// 各項目にセット
|
398
|
+
|
399
|
+
document.getElementById('monthly-payment1').value = comma(parseInt(firstMonthlyPayment));
|
400
|
+
|
401
|
+
document.getElementById('monthly-payment2').value = comma(parseInt(secondToLastMonthlyPayment));
|
402
|
+
|
403
|
+
document.getElementById('total-payment').value = comma(parseInt(interestMod));
|
404
|
+
|
405
|
+
document.getElementById('total_interest').value = comma(parseInt(totalInterest));
|
406
|
+
|
407
|
+
document.getElementById('showyears').value = years;
|
408
|
+
|
409
|
+
document.getElementById('showinterest').value = interest / 100;
|
410
|
+
|
411
|
+
document.getElementById('showdiffrence').value = comma(parseInt(difference));
|
412
|
+
|
413
|
+
document.getElementById('cb_num').value = cbTimes;
|
414
|
+
|
415
|
+
document.getElementById('cb_input').value = comma(parseInt(cb_amount));
|
416
|
+
|
417
|
+
document.getElementById('cb_everypayment').value = comma(parseInt(cbEveryPayment));
|
418
|
+
|
419
|
+
}
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
/**
|
424
|
+
|
425
|
+
* 金額をカンマ編集する
|
426
|
+
|
427
|
+
* @param num 金額
|
428
|
+
|
429
|
+
* @return カンマ編集後の金額
|
430
|
+
|
431
|
+
*/
|
432
|
+
|
433
|
+
function comma(num) {
|
434
|
+
|
435
|
+
return String(num).replace( /(\d)(?=(\d\d\d)+(?!\d))/g, '$1,');
|
436
|
+
|
437
|
+
}
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
/*
|
442
|
+
|
443
|
+
* エラーハンドラ
|
444
|
+
|
445
|
+
*/
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
// Error message
|
450
|
+
|
451
|
+
function showError(error){
|
452
|
+
|
453
|
+
console.log("Error ..." + error);
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
// create a div
|
458
|
+
|
459
|
+
const errorDiv = document.createElement("div");
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
// get element
|
464
|
+
|
465
|
+
const card = document.querySelector(".card");
|
466
|
+
|
467
|
+
const heading = document.querySelector(".heading");
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
// add class
|
472
|
+
|
473
|
+
errorDiv.className = "alert alert-danger";
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
// create text node and append div
|
478
|
+
|
479
|
+
errorDiv.appendChild(document.createTextNode(error));
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
// Insert error above heading
|
484
|
+
|
485
|
+
card.insertBefore(errorDiv, heading);
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
// clear error after 3 secs.
|
490
|
+
|
491
|
+
setTimeout(clearError, 3000);
|
492
|
+
|
493
|
+
}
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
// clear error function
|
498
|
+
|
499
|
+
function clearError() {
|
500
|
+
|
501
|
+
document.querySelector(".alert").remove();
|
502
|
+
|
503
|
+
}
|
362
504
|
|
363
505
|
```
|
364
506
|
|