Instantly share code, notes, and snippets.
Last active
June 21, 2019 08:06
-
Save tbtbt/24aa8975a39c39d2e56b4b632aec56cc to your computer and use it in GitHub Desktop.
社会保険料額表@協会けんぽ(平成30年4月以降分、東京)(Google Cloud Functions用)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 社会保険料率一覧表 | |
const socialInsurancePaymentList = [ | |
[1, 1, 58000, 0, 63000, 5742.00, 2871.00, 6652.60, 3326.30, 16104.00, 8052.00], | |
[2, 1, 68000, 63000, 73000, 6732.00, 3366.00, 7799.60, 3899.80, 16104.00, 8052.00], | |
[3, 1, 78000, 73000, 83000, 7722.00, 3861.00, 8946.60, 4473.30, 16104.00, 8052.00], | |
[4, 1, 88000, 83000, 93000, 8712.00, 4356.00, 10093.60, 5046.80, 16104.00, 8052.00], | |
[5, 2, 98000, 93000, 101000, 9702.00, 4851.00, 11240.60, 5620.30, 17934.00, 8967.00], | |
[6, 3, 104000, 101000, 107000, 10296.00, 5148.00, 11928.80, 5964.40, 19032.00, 9516.00], | |
[7, 4, 110000, 107000, 114000, 10890.00, 5445.00, 12617.00, 6308.50, 20130.00, 10065.00], | |
[8, 5, 118000, 114000, 122000, 11682.00, 5841.00, 13534.60, 6767.30, 21594.00, 10797.00], | |
[9, 6, 126000, 122000, 130000, 12474.00, 6237.00, 14452.20, 7226.10, 23058.00, 11529.00], | |
[10, 7, 134000, 130000, 138000, 13266.00, 6633.00, 15369.80, 7684.90, 24522.00, 12261.00], | |
[11, 8, 142000, 138000, 146000, 14058.00, 7029.00, 16287.40, 8143.70, 25986.00, 12993.00], | |
[12, 9, 150000, 146000, 155000, 14850.00, 7425.00, 17205.00, 8602.50, 27450.00, 13725.00], | |
[13, 10, 160000, 155000, 165000, 15840.00, 7920.00, 18352.00, 9176.00, 29280.00, 14640.00], | |
[14, 11, 170000, 165000, 175000, 16830.00, 8415.00, 19499.00, 9749.50, 31110.00, 15555.00], | |
[15, 12, 180000, 175000, 185000, 17820.00, 8910.00, 20646.00, 10323.00, 32940.00, 16470.00], | |
[16, 13, 190000, 185000, 195000, 18810.00, 9405.00, 21793.00, 10896.50, 34770.00, 17385.00], | |
[17, 14, 200000, 195000, 210000, 19800.00, 9900.00, 22940.00, 11470.00, 36600.00, 18300.00], | |
[18, 15, 220000, 210000, 230000, 21780.00, 10890.00, 25234.00, 12617.00, 40260.00, 20130.00], | |
[19, 16, 240000, 230000, 250000, 23760.00, 11880.00, 27528.00, 13764.00, 43920.00, 21960.00], | |
[20, 17, 260000, 250000, 270000, 25740.00, 12870.00, 29822.00, 14911.00, 47580.00, 23790.00], | |
[21, 18, 280000, 270000, 290000, 27720.00, 13860.00, 32116.00, 16058.00, 51240.00, 25620.00], | |
[22, 19, 300000, 290000, 310000, 29700.00, 14850.00, 34410.00, 17205.00, 54900.00, 27450.00], | |
[23, 20, 320000, 310000, 330000, 31680.00, 15840.00, 36704.00, 18352.00, 58560.00, 29280.00], | |
[24, 21, 340000, 330000, 350000, 33660.00, 16830.00, 38998.00, 19499.00, 62220.00, 31110.00], | |
[25, 22, 360000, 350000, 370000, 35640.00, 17820.00, 41292.00, 20646.00, 65880.00, 32940.00], | |
[26, 23, 380000, 370000, 395000, 37620.00, 18810.00, 43586.00, 21793.00, 69540.00, 34770.00], | |
[27, 24, 410000, 395000, 425000, 40590.00, 20295.00, 47027.00, 23513.50, 75030.00, 37515.00], | |
[28, 25, 440000, 425000, 455000, 43560.00, 21780.00, 50468.00, 25234.00, 80520.00, 40260.00], | |
[29, 26, 470000, 455000, 485000, 46530.00, 23265.00, 53909.00, 26954.50, 86010.00, 43005.00], | |
[30, 27, 500000, 485000, 515000, 49500.00, 24750.00, 57350.00, 28675.00, 91500.00, 45750.00], | |
[31, 28, 530000, 515000, 545000, 52470.00, 26235.00, 60791.00, 30395.50, 96990.00, 48495.00], | |
[32, 29, 560000, 545000, 575000, 55440.00, 27720.00, 64232.00, 32116.00, 102480.00, 51240.00], | |
[33, 30, 590000, 575000, 605000, 58410.00, 29205.00, 67673.00, 33836.50, 107970.00, 53985.00], | |
[34, 31, 620000, 605000, 635000, 61380.00, 30690.00, 71114.00, 35557.00, 113460.00, 56730.00], | |
[35, 31, 650000, 635000, 665000, 64350.00, 32175.00, 74555.00, 37277.50, 113460.00, 56730.00], | |
[36, 31, 680000, 665000, 695000, 67320.00, 33660.00, 77996.00, 38998.00, 113460.00, 56730.00], | |
[37, 31, 710000, 695000, 730000, 70290.00, 35145.00, 81437.00, 40718.50, 113460.00, 56730.00], | |
[38, 31, 750000, 730000, 770000, 74250.00, 37125.00, 86025.00, 43012.50, 113460.00, 56730.00], | |
[39, 31, 790000, 770000, 810000, 78210.00, 39105.00, 90613.00, 45306.50, 113460.00, 56730.00], | |
[40, 31, 830000, 810000, 855000, 82170.00, 41085.00, 95201.00, 47600.50, 113460.00, 56730.00], | |
[41, 31, 880000, 855000, 905000, 87120.00, 43560.00, 100936.00, 50468.00, 113460.00, 56730.00], | |
[42, 31, 930000, 905000, 955000, 92070.00, 46035.00, 106671.00, 53335.50, 113460.00, 56730.00], | |
[43, 31, 980000, 955000, 1005000, 97020.00, 48510.00, 112406.00, 56203.00, 113460.00, 56730.00], | |
[44, 31, 1030000, 1005000, 1055000, 101970.00, 50985.00, 118141.00, 59070.50, 113460.00, 56730.00], | |
[45, 31, 1090000, 1055000, 1115000, 107910.00, 53955.00, 125023.00, 62511.50, 113460.00, 56730.00], | |
[46, 31, 1150000, 1115000, 1175000, 113850.00, 56925.00, 131905.00, 65952.50, 113460.00, 56730.00], | |
[47, 31, 1210000, 1175000, 1235000, 119790.00, 59895.00, 138787.00, 69393.50, 113460.00, 56730.00], | |
[48, 31, 1270000, 1235000, 1295000, 125730.00, 62865.00, 145669.00, 72834.50, 113460.00, 56730.00], | |
[49, 31, 1330000, 1295000, 1355000, 131670.00, 65835.00, 152551.00, 76275.50, 113460.00, 56730.00], | |
[50, 31, 1390000, 1355000, null, 137610.00, 68805.00, 159433.00, 79716.50, 113460.00, 56730.00] | |
]; | |
// 社会保険料を取得する | |
exports.getSocialInsurance201804 = (req, res) => { | |
// check parameters. | |
if (!('salary' in req.query) || !('kaigo' in req.query) || | |
!/[1-9][0-9]*/.test(req.query.salary) || ['0', '1'].indexOf(req.query.kaigo) === -1) { | |
res.status(400).send(`invalid parameters.`); | |
} | |
// format | |
const format = ('format' in req.query && (req.query.format === 'json' || req.query.format === 'xml')) ? req.query.format : 'json'; | |
let salary = parseInt(req.query.salary, 10); | |
for (let i = 0; i < socialInsurancePaymentList.length; i++) { | |
if (salary >= socialInsurancePaymentList[i][3] && (salary === null || salary < socialInsurancePaymentList[i][4])) { | |
let insuranceIndex = (req.query.kaigo === '1') ? 8 : 6; | |
const values = { | |
"standardRemuneration": socialInsurancePaymentList[i][2], | |
"insurance": { | |
"grade": socialInsurancePaymentList[i][0], | |
"payment": Math.round(socialInsurancePaymentList[i][insuranceIndex]), | |
}, | |
"pension": { | |
"grade": socialInsurancePaymentList[i][1], | |
"payment": Math.round(socialInsurancePaymentList[i][10]), | |
} | |
}; | |
if(format === 'xml') { | |
const xml = '<?xml version="1.0" encoding="UTF-8"?>' + | |
'<data><insurance>' + | |
'<grade>' + values['insurance']['grade'] + '</grade>' + | |
'<payment>' + values['insurance']['payment'] + '</payment>' + | |
'</insurance><pension>' + | |
'<grade>' + values['pension']['grade'] + '</grade>' + | |
'<payment>' + values['pension']['payment'] + '</payment>' + | |
'</pension></data>'; | |
res.header('Content-Type','text/xml'); | |
return res.status(200).send(xml); | |
} | |
return res.status(200).send(values); | |
} | |
} | |
res.status(500).send(`ABNORMAL END.`); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment