tax_jp 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/data//347/244/276/344/274/232/344/277/235/351/231/272/346/226/231.db +0 -0
- data/data//347/244/276/344/274/232/344/277/235/351/231/272/346/226/231/schema_grades.sql +10 -0
- data/data//347/244/276/344/274/232/344/277/235/351/231/272/346/226/231/schema_health_insurances.sql +8 -0
- data/data//347/244/276/344/274/232/344/277/235/351/231/272/346/226/231/schema_welfare_pensions.sql +7 -0
- data/data//347/244/276/344/274/232/344/277/235/351/231/272/346/226/231//345/201/245/345/272/267/344/277/235/351/231/272-20140301-20150331.tsv +48 -0
- data/data//347/244/276/344/274/232/344/277/235/351/231/272/346/226/231//345/201/245/345/272/267/344/277/235/351/231/272-20150401-20991231.tsv +48 -0
- data/data//347/244/276/344/274/232/344/277/235/351/231/272/346/226/231//345/216/232/347/224/237/345/271/264/351/207/221.tsv +2 -0
- data/data//347/244/276/344/274/232/344/277/235/351/231/272/346/226/231//347/255/211/347/264/232-20090901-20991231.tsv +48 -0
- data/lib/build_tasks/build.rake +9 -4
- data/lib/tax_jp.rb +3 -0
- data/lib/tax_jp/health_insurance.rb +44 -0
- data/lib/tax_jp/prefecture.rb +10 -4
- data/lib/tax_jp/social_insurance.rb +138 -0
- data/lib/tax_jp/social_insurances/db_builder.rb +115 -0
- data/lib/tax_jp/version.rb +1 -1
- data/lib/tax_jp/welfare_pension.rb +35 -0
- data/lib/tax_jp/withheld_taxes/db_builder.rb +24 -14
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f16da7a03b1366e9eafe72db8a78fbc1385182f
|
4
|
+
data.tar.gz: cb1a337823ce91d335b715317139b3ff15450b1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 827c978c46a68a24cfc9b7d3db2316857e2318b4572525ed298b88f6e3682afaa522141373f43bbee942af2f67ba34ea27387f1ef68588c6337e85d36137b890
|
7
|
+
data.tar.gz: e294e606c71498fa9605c332f52d26f6c129c47a91f57b78a4a14c1006716fa9422f9651da0c3fdc361aa99196277a5ae2ad0ac6dbab38cc0107855413b6fe17
|
@@ -0,0 +1,10 @@
|
|
1
|
+
create table grades (
|
2
|
+
valid_from date not null,
|
3
|
+
valid_until date not null,
|
4
|
+
grade integer not null,
|
5
|
+
pension_grade integer not null,
|
6
|
+
monthly_standard integer not null,
|
7
|
+
daily_standard integer not null,
|
8
|
+
salary_from integer not null,
|
9
|
+
salary_to integer not null
|
10
|
+
);
|
@@ -0,0 +1,48 @@
|
|
1
|
+
都道府県 一般保険料率(%) 特定保険料率(%) 基本保険料率(%)
|
2
|
+
北海道 10.12 4.07 6.05
|
3
|
+
青森県 10.00 4.07 5.93
|
4
|
+
岩手県 9.93 4.07 5.86
|
5
|
+
宮城県 10.01 4.07 5.94
|
6
|
+
秋田県 10.02 4.07 5.95
|
7
|
+
山形県 9.96 4.07 5.89
|
8
|
+
福島県 9.96 4.07 5.89
|
9
|
+
茨城県 9.93 4.07 5.86
|
10
|
+
栃木県 9.95 4.07 5.88
|
11
|
+
群馬県 9.95 4.07 5.88
|
12
|
+
埼玉県 9.94 4.07 5.87
|
13
|
+
千葉県 9.93 4.07 5.86
|
14
|
+
東京都 9.97 4.07 5.90
|
15
|
+
神奈川県 9.98 4.07 5.91
|
16
|
+
新潟県 9.90 4.07 5.83
|
17
|
+
富山県 9.93 4.07 5.86
|
18
|
+
石川県 10.03 4.07 5.96
|
19
|
+
福井県 10.02 4.07 5.95
|
20
|
+
山梨県 9.94 4.07 5.87
|
21
|
+
長野県 9.85 4.07 5.78
|
22
|
+
岐阜県 9.99 4.07 5.92
|
23
|
+
静岡県 9.92 4.07 5.85
|
24
|
+
愛知県 9.97 4.07 5.90
|
25
|
+
三重県 9.94 4.07 5.87
|
26
|
+
滋賀県 9.97 4.07 5.90
|
27
|
+
京都府 9.98 4.07 5.91
|
28
|
+
大阪府 10.06 4.07 5.99
|
29
|
+
兵庫県 10.00 4.07 5.93
|
30
|
+
奈良県 10.02 4.07 5.95
|
31
|
+
和歌山県 10.02 4.07 5.95
|
32
|
+
鳥取県 9.98 4.07 5.91
|
33
|
+
島根県 10.00 4.07 5.93
|
34
|
+
岡山県 10.06 4.07 5.99
|
35
|
+
広島県 10.03 4.07 5.96
|
36
|
+
山口県 10.03 4.07 5.96
|
37
|
+
徳島県 10.08 4.07 6.01
|
38
|
+
香川県 10.09 4.07 6.02
|
39
|
+
愛媛県 10.03 4.07 5.96
|
40
|
+
高知県 10.04 4.07 5.97
|
41
|
+
福岡県 10.12 4.07 6.05
|
42
|
+
佐賀県 10.16 4.07 6.09
|
43
|
+
長崎県 10.06 4.07 5.99
|
44
|
+
熊本県 10.07 4.07 6.00
|
45
|
+
大分県 10.08 4.07 6.01
|
46
|
+
宮崎県 10.01 4.07 5.94
|
47
|
+
鹿児島県 10.03 4.07 5.96
|
48
|
+
沖縄県 10.03 4.07 5.96
|
@@ -0,0 +1,48 @@
|
|
1
|
+
都道府県 一般保険料率(%) 特定保険料率(%) 基本保険料率(%)
|
2
|
+
北海道 10.14 3.83 6.31
|
3
|
+
青森県 9.98 3.83 6.15
|
4
|
+
岩手県 9.97 3.83 6.14
|
5
|
+
宮城県 9.96 3.83 6.13
|
6
|
+
秋田県 10.06 3.83 6.23
|
7
|
+
山形県 9.97 3.83 6.14
|
8
|
+
福島県 9.92 3.83 6.09
|
9
|
+
茨城県 9.92 3.83 6.09
|
10
|
+
栃木県 9.95 3.83 6.12
|
11
|
+
群馬県 9.92 3.83 6.09
|
12
|
+
埼玉県 9.93 3.83 6.1
|
13
|
+
千葉県 9.97 3.83 6.14
|
14
|
+
東京都 9.97 3.83 6.14
|
15
|
+
神奈川県 9.98 3.83 6.15
|
16
|
+
新潟県 9.86 3.83 6.03
|
17
|
+
富山県 9.91 3.83 6.08
|
18
|
+
石川県 9.99 3.83 6.16
|
19
|
+
福井県 9.93 3.83 6.1
|
20
|
+
山梨県 9.96 3.83 6.13
|
21
|
+
長野県 9.91 3.83 6.08
|
22
|
+
岐阜県 9.98 3.83 6.15
|
23
|
+
静岡県 9.92 3.83 6.09
|
24
|
+
愛知県 9.97 3.83 6.14
|
25
|
+
三重県 9.94 3.83 6.11
|
26
|
+
滋賀県 9.94 3.83 6.11
|
27
|
+
京都府 10.02 3.83 6.19
|
28
|
+
大阪府 10.04 3.83 6.21
|
29
|
+
兵庫県 10.04 3.83 6.21
|
30
|
+
奈良県 9.98 3.83 6.15
|
31
|
+
和歌山県 9.97 3.83 6.14
|
32
|
+
鳥取県 9.96 3.83 6.13
|
33
|
+
島根県 10.06 3.83 6.23
|
34
|
+
岡山県 10.09 3.83 6.26
|
35
|
+
広島県 10.03 3.83 6.2
|
36
|
+
山口県 10.1 3.83 6.27
|
37
|
+
徳島県 10.1 3.83 6.27
|
38
|
+
香川県 10.11 3.83 6.28
|
39
|
+
愛媛県 10.03 3.83 6.2
|
40
|
+
高知県 10.05 3.83 6.22
|
41
|
+
福岡県 10.09 3.83 6.26
|
42
|
+
佐賀県 10.21 3.83 6.38
|
43
|
+
長崎県 10.07 3.83 6.24
|
44
|
+
熊本県 10.09 3.83 6.26
|
45
|
+
大分県 10.03 3.83 6.2
|
46
|
+
宮崎県 9.98 3.83 6.15
|
47
|
+
鹿児島県 10.02 3.83 6.19
|
48
|
+
沖縄県 9.96 3.83 6.13
|
@@ -0,0 +1,48 @@
|
|
1
|
+
等級(健康保険) 等級(厚生年金) 標準報酬月額 標準報酬日額 報酬月額(以上) 報酬月額(未満)
|
2
|
+
1 0 58000 1930 0 63000
|
3
|
+
2 0 68000 2270 63000 73000
|
4
|
+
3 0 78000 2600 73000 83000
|
5
|
+
4 0 88000 2930 83000 93000
|
6
|
+
5 1 98000 3270 93000 101000
|
7
|
+
6 2 104000 3470 101000 107000
|
8
|
+
7 3 110000 3670 107000 114000
|
9
|
+
8 4 118000 3930 114000 122000
|
10
|
+
9 5 126000 4200 122000 130000
|
11
|
+
10 6 134000 4470 130000 138000
|
12
|
+
11 7 142000 4730 138000 146000
|
13
|
+
12 8 150000 5000 146000 155000
|
14
|
+
13 9 160000 5330 155000 165000
|
15
|
+
14 10 170000 5670 165000 175000
|
16
|
+
15 11 180000 6000 175000 185000
|
17
|
+
16 12 190000 6330 185000 195000
|
18
|
+
17 13 200000 6670 195000 210000
|
19
|
+
18 14 220000 7330 210000 230000
|
20
|
+
19 15 240000 8000 230000 250000
|
21
|
+
20 16 260000 8670 250000 270000
|
22
|
+
21 17 280000 9330 270000 290000
|
23
|
+
22 18 300000 10000 290000 310000
|
24
|
+
23 19 320000 10670 310000 330000
|
25
|
+
24 20 340000 11330 330000 350000
|
26
|
+
25 21 360000 12000 350000 370000
|
27
|
+
26 22 380000 12670 370000 395000
|
28
|
+
27 23 410000 13670 395000 425000
|
29
|
+
28 24 440000 14670 425000 455000
|
30
|
+
29 25 470000 15670 455000 485000
|
31
|
+
30 26 500000 16670 485000 515000
|
32
|
+
31 27 530000 17670 515000 545000
|
33
|
+
32 28 560000 18670 545000 575000
|
34
|
+
33 29 590000 19670 575000 605000
|
35
|
+
34 30 620000 20670 605000 635000
|
36
|
+
35 30 650000 21670 635000 665000
|
37
|
+
36 30 680000 22670 665000 695000
|
38
|
+
37 30 710000 23670 695000 730000
|
39
|
+
38 30 750000 25000 730000 770000
|
40
|
+
39 30 790000 26330 770000 810000
|
41
|
+
40 30 830000 27670 810000 855000
|
42
|
+
41 30 880000 29330 855000 905000
|
43
|
+
42 30 930000 31000 905000 955000
|
44
|
+
43 30 980000 32670 955000 1005000
|
45
|
+
44 30 1030000 34330 1005000 1055000
|
46
|
+
45 30 1090000 36330 1055000 1115000
|
47
|
+
46 30 1150000 38330 1115000 1175000
|
48
|
+
47 30 1210000 40330 1175000 -
|
data/lib/build_tasks/build.rake
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'tax_jp'
|
3
|
+
require 'tax_jp/social_insurances/db_builder'
|
3
4
|
require 'tax_jp/withheld_taxes/db_builder'
|
4
5
|
|
5
6
|
namespace :taxjp do
|
6
7
|
task :build do
|
7
8
|
Rake::Task["taxjp:build:consumption_tax"].invoke
|
9
|
+
Rake::Task["taxjp:build:social_insurance"].invoke
|
8
10
|
Rake::Task["taxjp:build:withheld_tax"].invoke
|
9
11
|
end
|
10
12
|
|
@@ -19,11 +21,14 @@ namespace :taxjp do
|
|
19
21
|
desc '源泉徴収税DBを構築します。'
|
20
22
|
task :withheld_tax do
|
21
23
|
puts '源泉徴収税'
|
24
|
+
TaxJp::WithheldTaxes::DbBuilder.new.run
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
TaxJp::
|
27
|
+
desc '社会保険料DBを構築します。'
|
28
|
+
task :social_insurance do
|
29
|
+
puts '社会保険料'
|
30
|
+
TaxJp::SocialInsurances::DbBuilder.new.run
|
27
31
|
end
|
32
|
+
|
28
33
|
end
|
29
34
|
end
|
data/lib/tax_jp.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
module TaxJp
|
2
|
+
|
3
|
+
# 健康年金
|
4
|
+
class HealthInsurance
|
5
|
+
attr_reader :valid_from, :valid_until
|
6
|
+
attr_reader :monthly_standard
|
7
|
+
attr_reader :prefecture
|
8
|
+
attr_reader :general, :particular, :basic
|
9
|
+
|
10
|
+
def initialize(attrs = {})
|
11
|
+
@valid_from = attrs[:valid_from]
|
12
|
+
@valid_until = attrs[:valid_until]
|
13
|
+
@monthly_standard = attrs[:monthly_standard]
|
14
|
+
@prefecture = attrs[:prefecture]
|
15
|
+
@general= attrs[:general]
|
16
|
+
@particular= attrs[:particular]
|
17
|
+
@basic = attrs[:basic]
|
18
|
+
end
|
19
|
+
|
20
|
+
def general_amount
|
21
|
+
floor_amount(monthly_standard * general)
|
22
|
+
end
|
23
|
+
|
24
|
+
def general_amount_half
|
25
|
+
floor_amount(monthly_standard * general / 2)
|
26
|
+
end
|
27
|
+
|
28
|
+
def general_amount_care
|
29
|
+
floor_amount(monthly_standard * (general + 0.0158))
|
30
|
+
end
|
31
|
+
|
32
|
+
def general_amount_care_half
|
33
|
+
floor_amount(monthly_standard * (general + 0.0158) / 2)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def floor_amount(amount)
|
39
|
+
(amount * 10).floor * 0.1
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/tax_jp/prefecture.rb
CHANGED
@@ -9,18 +9,24 @@ module TaxJp
|
|
9
9
|
@name = name
|
10
10
|
end
|
11
11
|
|
12
|
-
@@
|
12
|
+
@@prefectures_by_code = {}
|
13
|
+
@@prefectures_by_name = {}
|
13
14
|
TaxJp::Utils.load_yaml('都道府県.yml').each do |key, value|
|
14
15
|
code = "%02d" % key.to_i
|
15
|
-
|
16
|
+
p = Prefecture.new(code, value)
|
17
|
+
@@prefectures_by_code[p.code] = @@prefectures_by_name[p.name] = p
|
16
18
|
end
|
17
19
|
|
18
20
|
def self.all
|
19
|
-
@@
|
21
|
+
@@prefectures_by_code.values
|
20
22
|
end
|
21
23
|
|
22
24
|
def self.find_by_code(code)
|
23
|
-
@@
|
25
|
+
@@prefectures_by_code["%02d" % code.to_i]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.find_by_name(name)
|
29
|
+
@@prefectures_by_name[name]
|
24
30
|
end
|
25
31
|
|
26
32
|
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'sqlite3'
|
2
|
+
require_relative 'health_insurance'
|
3
|
+
require_relative 'welfare_pension'
|
4
|
+
|
5
|
+
module TaxJp
|
6
|
+
module SocialInsurances
|
7
|
+
end
|
8
|
+
|
9
|
+
# 社会保険
|
10
|
+
class SocialInsurance
|
11
|
+
DB_PATH = File.join(TaxJp::Utils.data_dir, '社会保険料.db')
|
12
|
+
|
13
|
+
# 等級
|
14
|
+
attr_reader :valid_from, :valid_until
|
15
|
+
attr_reader :grade, :pension_grade
|
16
|
+
attr_reader :monthly_standard, :daily_standard
|
17
|
+
attr_reader :salary_from, :salary_to
|
18
|
+
|
19
|
+
# 健康保険
|
20
|
+
attr_reader :health_insurance
|
21
|
+
# 厚生年金
|
22
|
+
attr_reader :welfare_pension
|
23
|
+
|
24
|
+
def initialize(row)
|
25
|
+
@valid_from = row[0]
|
26
|
+
@valid_until = row[1]
|
27
|
+
@grade = row[2]
|
28
|
+
@pension_grade = row[3]
|
29
|
+
@monthly_standard = row[4]
|
30
|
+
@daily_standard = row[5]
|
31
|
+
@salary_from = row[6]
|
32
|
+
@salary_to = row[7]
|
33
|
+
|
34
|
+
@health_insurance = TaxJp::HealthInsurance.new(
|
35
|
+
:valid_from => row[8], :valid_until => row[9],
|
36
|
+
:monthly_standard => row[4],
|
37
|
+
:prefecture => Prefecture.find_by_code(row[10]),
|
38
|
+
:general => row[11], :particular => row[12],
|
39
|
+
:basic => row[13])
|
40
|
+
|
41
|
+
@welfare_pension = TaxJp::WelfarePension.new(
|
42
|
+
:valid_from => row[14], :valid_until => row[15],
|
43
|
+
:monthly_standard => row[4],
|
44
|
+
:general => row[16], :particular => row[17],
|
45
|
+
:child_support => row[18])
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.find_grade_by_date_and_salary(date, salary)
|
49
|
+
date = date.strftime('%Y-%m-%d') if date.is_a?(Date)
|
50
|
+
|
51
|
+
with_database do |db|
|
52
|
+
sql = 'select * from grades where valid_from <= ? and valid_until >= ? and salary_from <= ? and salary_to > ?'
|
53
|
+
|
54
|
+
ret = nil
|
55
|
+
db.execute(sql, [date, date, salary, salary]) do |row|
|
56
|
+
if ret
|
57
|
+
raise "等級が重複して登録されています。date=#{date}, salary=#{salary}"
|
58
|
+
else
|
59
|
+
ret = TaxJp::SocialInsurance.new(row)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
ret
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.find_grades_by_date(date)
|
67
|
+
date = date.strftime('%Y-%m-%d') if date.is_a?(Date)
|
68
|
+
|
69
|
+
with_database do |db|
|
70
|
+
sql = 'select * from grades where valid_from <= ? and valid_until >= ?'
|
71
|
+
|
72
|
+
ret = []
|
73
|
+
db.execute(sql, [date, date]) do |row|
|
74
|
+
ret << TaxJp::SocialInsurance.new(row)
|
75
|
+
end
|
76
|
+
|
77
|
+
ret.sort{|a, b| a.grade <=> b.grade }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.find_by_date_and_prefecture_and_grade(date, prefecture, grade)
|
82
|
+
if date.is_a?(Date)
|
83
|
+
date = date.strftime('%Y-%m-%d')
|
84
|
+
elsif date.is_a?(String)
|
85
|
+
else
|
86
|
+
raise TypeError.new(date.class)
|
87
|
+
end
|
88
|
+
|
89
|
+
if prefecture.is_a?(TaxJp::Prefecture)
|
90
|
+
prefecture_code = prefecture.code
|
91
|
+
elsif prefecture.to_s =~ /[0-9]{2}/
|
92
|
+
prefecture_code = prefecture
|
93
|
+
else
|
94
|
+
p = Prefecture.find_by_name(prefecture.to_s)
|
95
|
+
if p
|
96
|
+
prefecture_code = p.code
|
97
|
+
else
|
98
|
+
raise TypeError.new(prefecture.class)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
if grade.is_a?(TaxJp::SocialInsurance)
|
103
|
+
grade = grade.grade
|
104
|
+
elsif grade.is_a?(Fixnum)
|
105
|
+
grade = grade.to_i
|
106
|
+
else
|
107
|
+
raise TypeError.new("#{grade.class} は等級として不正です。")
|
108
|
+
end
|
109
|
+
|
110
|
+
with_database do |db|
|
111
|
+
sql = 'select g.*, hi.*, wp.* from grades g '
|
112
|
+
sql << 'inner join health_insurances hi on (hi.valid_from <= ? and hi.valid_until >= ? and hi.prefecture_code = ?) '
|
113
|
+
sql << 'inner join welfare_pensions wp on (wp.valid_from <= ? and wp.valid_until >= ?) '
|
114
|
+
sql << 'where g.valid_from <= ? and g.valid_until >= ? and g.grade = ? '
|
115
|
+
|
116
|
+
ret = nil
|
117
|
+
db.execute(sql, [date, date, prefecture_code, date, date, date, date, grade]) do |row|
|
118
|
+
if ret
|
119
|
+
raise "健康保険が重複して登録されています。date=#{date}, prefecture_code=#{prefecture_code}, grade=#{grade}"
|
120
|
+
else
|
121
|
+
ret = TaxJp::SocialInsurance.new(row)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
ret
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.with_database
|
129
|
+
db = SQLite3::Database.new(DB_PATH)
|
130
|
+
begin
|
131
|
+
yield db
|
132
|
+
ensure
|
133
|
+
db.close
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
class TaxJp::SocialInsurances::DbBuilder
|
5
|
+
|
6
|
+
def initialize(db_path = nil)
|
7
|
+
@db_path = db_path || TaxJp::SocialInsurance::DB_PATH
|
8
|
+
end
|
9
|
+
|
10
|
+
def run(options = {})
|
11
|
+
with_database(options) do |db|
|
12
|
+
Dir.glob(File.join(TaxJp::Utils.data_dir, '社会保険料', '等級-*.tsv')).each do |filename|
|
13
|
+
valid_from, valid_until = filename_to_date(filename)
|
14
|
+
|
15
|
+
CSV.foreach(filename, :col_sep => "\t") do |row|
|
16
|
+
next if row[0].to_i == 0
|
17
|
+
db.execute(insert_sql_grade, [valid_from, valid_until] + row.map{|col| normalize_amount(col)})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Dir.glob(File.join(TaxJp::Utils.data_dir, '社会保険料', '健康保険-*.tsv')).each do |filename|
|
22
|
+
valid_from, valid_until = filename_to_date(filename)
|
23
|
+
|
24
|
+
CSV.foreach(filename, :col_sep => "\t") do |row|
|
25
|
+
next unless row[1].to_f > 0
|
26
|
+
values = [valid_from, valid_until]
|
27
|
+
values << TaxJp::Prefecture.find_by_name(row.shift).code
|
28
|
+
values += row.map{|col| (col.to_f * 0.01).round(4) }
|
29
|
+
db.execute(insert_sql_health_insurance, values)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Dir.glob(File.join(TaxJp::Utils.data_dir, '社会保険料', '厚生年金.tsv')).each do |filename|
|
34
|
+
CSV.foreach(filename, :col_sep => "\t") do |row|
|
35
|
+
next unless row[2].to_f > 0
|
36
|
+
values = []
|
37
|
+
values << row.shift
|
38
|
+
values << row.shift
|
39
|
+
values += row.map{|col| (col.to_f * 0.01).round(5) }
|
40
|
+
db.execute(insert_sql_welfare_pensions, values)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def with_database(options = {})
|
50
|
+
if options.fetch(:recreate, true)
|
51
|
+
FileUtils.rm_f(@db_path)
|
52
|
+
db = SQLite3::Database.new(@db_path)
|
53
|
+
db.execute(TaxJp::Utils.load_file(File.join('社会保険料', 'schema_grades.sql')))
|
54
|
+
db.execute(TaxJp::Utils.load_file(File.join('社会保険料', 'schema_health_insurances.sql')))
|
55
|
+
db.execute(TaxJp::Utils.load_file(File.join('社会保険料', 'schema_welfare_pensions.sql')))
|
56
|
+
else
|
57
|
+
db = SQLite3::Database.new(@db_path)
|
58
|
+
end
|
59
|
+
|
60
|
+
begin
|
61
|
+
yield db
|
62
|
+
ensure
|
63
|
+
db.close
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def insert_sql_grade
|
68
|
+
columns = %w{valid_from valid_until grade pension_grade monthly_standard daily_standard salary_from salary_to}
|
69
|
+
|
70
|
+
ret = 'insert into grades ( '
|
71
|
+
ret << columns.join(',')
|
72
|
+
ret << ') values ('
|
73
|
+
ret << columns.map{|c| '?' }.join(',')
|
74
|
+
ret << ')'
|
75
|
+
ret
|
76
|
+
end
|
77
|
+
|
78
|
+
def insert_sql_health_insurance
|
79
|
+
columns = %w{valid_from valid_until prefecture_code general particular basic}
|
80
|
+
|
81
|
+
ret = 'insert into health_insurances ( '
|
82
|
+
ret << columns.join(',')
|
83
|
+
ret << ') values ('
|
84
|
+
ret << columns.map{|c| '?' }.join(',')
|
85
|
+
ret << ')'
|
86
|
+
ret
|
87
|
+
end
|
88
|
+
|
89
|
+
def insert_sql_welfare_pensions
|
90
|
+
columns = %w{valid_from valid_until general particular child_support}
|
91
|
+
|
92
|
+
ret = 'insert into welfare_pensions ( '
|
93
|
+
ret << columns.join(',')
|
94
|
+
ret << ') values ('
|
95
|
+
ret << columns.map{|c| '?' }.join(',')
|
96
|
+
ret << ')'
|
97
|
+
ret
|
98
|
+
end
|
99
|
+
|
100
|
+
def normalize_amount(amount, options = {})
|
101
|
+
if amount.to_s == '-'
|
102
|
+
ret = 2147483647
|
103
|
+
else
|
104
|
+
ret = amount.to_s.gsub(',', '').to_i
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def filename_to_date(filename)
|
109
|
+
title, valid_from, valid_until = File.basename(filename).split('.').first.split('-')
|
110
|
+
valid_from = Date.strptime(valid_from, '%Y%m%d')
|
111
|
+
valid_until = Date.strptime(valid_until, '%Y%m%d')
|
112
|
+
[valid_from.strftime('%Y-%m-%d'), valid_until.strftime('%Y-%m-%d')]
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
data/lib/tax_jp/version.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
module TaxJp
|
2
|
+
|
3
|
+
# 厚生年金
|
4
|
+
class WelfarePension
|
5
|
+
attr_reader :valid_from, :valid_until
|
6
|
+
attr_reader :monthly_standard
|
7
|
+
attr_reader :general, :particular
|
8
|
+
attr_reader :child_support
|
9
|
+
|
10
|
+
def initialize(attrs = {})
|
11
|
+
@valid_from = attrs[:valid_from]
|
12
|
+
@valid_until = attrs[:valid_until]
|
13
|
+
@monthly_standard = attrs[:monthly_standard]
|
14
|
+
@general= attrs[:general]
|
15
|
+
@particular= attrs[:particular]
|
16
|
+
@child_support = attrs[:child_support]
|
17
|
+
end
|
18
|
+
|
19
|
+
def general_amount
|
20
|
+
floor_amount(monthly_standard * general)
|
21
|
+
end
|
22
|
+
|
23
|
+
def general_amount_half
|
24
|
+
floor_amount(monthly_standard * general / 2)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def floor_amount(amount)
|
30
|
+
(amount * 10).floor * 0.1
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -3,31 +3,41 @@ require 'date'
|
|
3
3
|
|
4
4
|
class TaxJp::WithheldTaxes::DbBuilder
|
5
5
|
|
6
|
-
def initialize(db_path)
|
7
|
-
@db_path = db_path
|
6
|
+
def initialize(db_path = nil)
|
7
|
+
@db_path = db_path || TaxJp::WithheldTax::DB_PATH
|
8
8
|
end
|
9
9
|
|
10
10
|
def run(options = {})
|
11
|
-
|
11
|
+
with_database(options) do |db|
|
12
|
+
Dir.glob(File.join(TaxJp::Utils.data_dir, '源泉徴収税', '*.tsv')).each do |filename|
|
13
|
+
valid_from, valid_until = filename_to_date(filename)
|
14
|
+
|
15
|
+
CSV.foreach(filename, :col_sep => "\t") do |row|
|
16
|
+
next if row[0].nil?
|
17
|
+
db.execute(insert_sql, [valid_from.to_s, valid_until.to_s] + row.map{|col| normalize_amount(col)})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
12
24
|
|
25
|
+
def with_database(options = {})
|
13
26
|
if options.fetch(:recreate, true)
|
27
|
+
FileUtils.rm_f(@db_path)
|
28
|
+
db = SQLite3::Database.new(@db_path)
|
14
29
|
db.execute(TaxJp::Utils.load_file(File.join('源泉徴収税', 'schema.sql')))
|
30
|
+
else
|
31
|
+
db = SQLite3::Database.new(@db_path)
|
15
32
|
end
|
16
33
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
next if row[0].nil?
|
22
|
-
db.execute(insert_sql, [valid_from.to_s, valid_until.to_s] + row.map{|col| normalize_amount(col)})
|
23
|
-
end
|
34
|
+
begin
|
35
|
+
yield db
|
36
|
+
ensure
|
37
|
+
db.close
|
24
38
|
end
|
25
|
-
|
26
|
-
db.close
|
27
39
|
end
|
28
40
|
|
29
|
-
private
|
30
|
-
|
31
41
|
def insert_sql
|
32
42
|
ret = 'insert into withheld_taxes (valid_from, valid_until, salary_range_from, salary_range_to, '
|
33
43
|
8.times do |i|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tax_jp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ichylinux
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-07-
|
12
|
+
date: 2015-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sqlite3
|
@@ -108,6 +108,14 @@ files:
|
|
108
108
|
- data/源泉徴収税/20070101-20121231.tsv
|
109
109
|
- data/源泉徴収税/20130101-20371231.tsv
|
110
110
|
- data/源泉徴収税/schema.sql
|
111
|
+
- data/社会保険料.db
|
112
|
+
- data/社会保険料/schema_grades.sql
|
113
|
+
- data/社会保険料/schema_health_insurances.sql
|
114
|
+
- data/社会保険料/schema_welfare_pensions.sql
|
115
|
+
- data/社会保険料/健康保険-20140301-20150331.tsv
|
116
|
+
- data/社会保険料/健康保険-20150401-20991231.tsv
|
117
|
+
- data/社会保険料/厚生年金.tsv
|
118
|
+
- data/社会保険料/等級-20090901-20991231.tsv
|
111
119
|
- data/都道府県.yml
|
112
120
|
- features/.gitignore
|
113
121
|
- features/01.都道府県.feature
|
@@ -120,11 +128,15 @@ files:
|
|
120
128
|
- lib/tax_jp.rb
|
121
129
|
- lib/tax_jp/const.rb
|
122
130
|
- lib/tax_jp/consumption_tax.rb
|
131
|
+
- lib/tax_jp/health_insurance.rb
|
123
132
|
- lib/tax_jp/prefecture.rb
|
124
133
|
- lib/tax_jp/rails/engine.rb
|
125
134
|
- lib/tax_jp/rails/railtie.rb
|
135
|
+
- lib/tax_jp/social_insurance.rb
|
136
|
+
- lib/tax_jp/social_insurances/db_builder.rb
|
126
137
|
- lib/tax_jp/utils.rb
|
127
138
|
- lib/tax_jp/version.rb
|
139
|
+
- lib/tax_jp/welfare_pension.rb
|
128
140
|
- lib/tax_jp/withheld_tax.rb
|
129
141
|
- lib/tax_jp/withheld_taxes/db_builder.rb
|
130
142
|
- tax_jp.gemspec
|