jp-national-tax 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34f7e3a70f29027703ea652bde0cdb5a60dfa40aed3461114fb401898562f74e
4
- data.tar.gz: a2878e533db8d5f04467dee5e89bae243c8ef141e4e864589e2ae36ea2188fdc
3
+ metadata.gz: c8aa134083bb93f5a7a31d8dd1593d0281a4cea993f560605aa6515afceab823
4
+ data.tar.gz: 510666c3b3005caf8c1bab5070e6f678bd866052e422c4f4f5bb327b4894f1e6
5
5
  SHA512:
6
- metadata.gz: f992aeb909c4105bfe0ccd353cabd76fcb9403d2331cb06d969cc6fbf0ecac158800be544f14e2152f6fa0544fd90c8e0a996f5d40805faf899f1d4768919dce
7
- data.tar.gz: d68a46393f88546a73a054475090438c837484773e35e82205421a6b67e9a014fd0f1991cddff1a6e70d7d9c1a6dbf5b298744f689cf58bed968b00008bf6d7e
6
+ metadata.gz: 2974fb0084b12e51c8c455efc67a3159104a98b4e02e0323164276aa2d7e1e1c2f6809aca4baeb22f1d4982ecde855b6d26065328582128682d03700f905bba8
7
+ data.tar.gz: 56ac46121279307a27b78a561e5db9cffa47b7a87b21d0610c83f7a33c475bb37d71715399e80e44cee19f1b3f5414f18c1dd65faec72b36a108b244c9b7575a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## master
2
+
3
+ * eTax仕様のXML構造設計書を解析するツールを追加
4
+
1
5
  ## 0.1.1
2
6
 
3
7
  * 年末調整(2020年)の関数を実装
@@ -85,19 +85,19 @@ module JpNationalTax
85
85
 
86
86
  case その月の課税給与所得金額
87
87
  when 0 .. 162_500
88
- (その月の課税給与所得金額 * BigDecimal("0.05105")).round(0, BigDecimal::ROUND_HALF_UP)
88
+ (その月の課税給与所得金額 * BigDecimal("0.05105")).round(-1, BigDecimal::ROUND_HALF_UP)
89
89
  when 162_501 .. 275_000
90
- (その月の課税給与所得金額 * BigDecimal("0.10210")).round(0, BigDecimal::ROUND_HALF_UP) - 8_296
90
+ (その月の課税給与所得金額 * BigDecimal("0.10210") - 8_296).round(-1, BigDecimal::ROUND_HALF_UP)
91
91
  when 275_001 .. 579_166
92
- (その月の課税給与所得金額 * BigDecimal("0.20420")).round(0, BigDecimal::ROUND_HALF_UP) - 36_374
92
+ (その月の課税給与所得金額 * BigDecimal("0.20420") - 36_374).round(-1, BigDecimal::ROUND_HALF_UP)
93
93
  when 579_001 .. 750_000
94
- (その月の課税給与所得金額 * BigDecimal("0.23483")).round(0, BigDecimal::ROUND_HALF_UP) - 54_113
94
+ (その月の課税給与所得金額 * BigDecimal("0.23483") - 54_113).round(-1, BigDecimal::ROUND_HALF_UP)
95
95
  when 750_001 .. 1_500_000
96
- (その月の課税給与所得金額 * BigDecimal("0.33693")).round(0, BigDecimal::ROUND_HALF_UP) - 130_688
96
+ (その月の課税給与所得金額 * BigDecimal("0.33693") - 130_688).round(-1, BigDecimal::ROUND_HALF_UP)
97
97
  when 1_500_001 .. 3_333_333
98
- (その月の課税給与所得金額 * BigDecimal("0.40840")).round(0, BigDecimal::ROUND_HALF_UP) - 237_893
98
+ (その月の課税給与所得金額 * BigDecimal("0.40840") - 237_893).round(-1, BigDecimal::ROUND_HALF_UP)
99
99
  else
100
- (その月の課税給与所得金額 * BigDecimal("0.45945")).round(0, BigDecimal::ROUND_HALF_UP) - 408_061
100
+ (その月の課税給与所得金額 * BigDecimal("0.45945") - 408_061).round(-1, BigDecimal::ROUND_HALF_UP)
101
101
  end
102
102
 
103
103
  end
@@ -1,3 +1,3 @@
1
1
  module JpNationalTax
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+ require "csv"
3
+ require "roo"
4
+
5
+ #
6
+ # eTax仕様のXML構造設計書をTSV変換するツール
7
+ #
8
+
9
+ TARGET_COLUMNS = {
10
+ origin: ["タグ名", "レベル", "共通ボキャブラリまたはデータ型", "項番", "備考"],
11
+ dest: ["version", "tag", "level", "struct", "order", "note", "label"],
12
+ }
13
+
14
+ def search_columns(xlsx)
15
+ [].tap do |columns|
16
+ xlsx.each_row_streaming do |row|
17
+ next if row[0].value != "項番"
18
+
19
+ TARGET_COLUMNS[:origin].each do |label|
20
+ columns.push row.find_index { |cell| cell.value == label }
21
+ end
22
+ break
23
+ end
24
+ end
25
+ end
26
+
27
+ def collect_rows(xlsx, columns)
28
+ [].tap do |res|
29
+ xlsx.each_row_streaming do |row|
30
+ next unless row[0].value.to_s =~ /^[0-9]+$/
31
+
32
+ label = extract_label(row, columns[1], columns[2])
33
+ res.push(columns.map{ |col| row[col].value }.push(label))
34
+ end
35
+ end
36
+ end
37
+
38
+ def extract_label(row, prev, subs)
39
+ (prev+1...subs).map { |idx| row[idx].value }.join("")
40
+ end
41
+
42
+ def sheet_defs(xlsx)
43
+ columns = []
44
+ xlsx.each_row_streaming do |row|
45
+ next if row[0].value != "帳票名称"
46
+
47
+ ["様式ID", "帳票名称", "バージョン"].each do |label|
48
+ columns.push row.find_index { |cell| cell.value == label }
49
+ end
50
+ break
51
+ end
52
+
53
+ [].tap { |res|
54
+ xlsx.each_row_streaming do |row|
55
+ next if row[0].value == "帳票名称"
56
+
57
+ res.push columns.map { |i| row[i].value }
58
+ break
59
+ end
60
+ }.flatten
61
+ end
62
+
63
+ # ARGV[0]にはExcelファイルのpathを指定
64
+ xlsx = Roo::Excelx.new(ARGV[0])
65
+ xlsx.each_with_pagename do |name, sheet|
66
+ id, name, version = sheet_defs(xlsx)
67
+ filename = "#{id}-#{version}-#{name.gsub(/\//, '=')[0, 80]}.tsv"
68
+ columns = search_columns(sheet)
69
+
70
+ CSV.open(filename, "w", col_sep: "\t") do |csv|
71
+ csv << TARGET_COLUMNS[:dest]
72
+ collect_rows(xlsx, columns).each do |row|
73
+ csv << row.unshift(version)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ require "csv"
3
+
4
+ #
5
+ # eTax仕様を変換したTSVを集計して、タグの有効バージョンをリストするツール
6
+ #
7
+
8
+ def accumulate_versions(attr, csv)
9
+ csv.each do |row|
10
+ attr[row['tag']] ||= { versions: [] }
11
+ attr[row['tag']][:versions].push(row['version'])
12
+ attr[row['tag']][:label] = row['label']
13
+ attr[row['tag']][:level] = row['level']
14
+ attr[row['tag']][:order] = row['order']
15
+ attr[row['tag']][:struct] = row['struct']
16
+ attr[row['tag']][:note] = row['note']
17
+ end
18
+ end
19
+
20
+ # ARGV[0]には申請書コード(ファイル名の一部)を指定
21
+ attr = {}
22
+ Dir.glob("#{ARGV[0]}*.tsv").each do |path|
23
+ CSV.open(path, "r", col_sep: "\t", headers: true) do |csv|
24
+ accumulate_versions(attr, csv)
25
+ end
26
+ end
27
+ output = "stats-#{ARGV[0]}.tsv"
28
+ CSV.open(output, "w", col_sep: "\t") do |csv|
29
+ csv << ["tag", "count", "level", "versions", "order", "label", "struct", "note"]
30
+ attr.each do |k, v|
31
+ csv << [k, v[:versions].length, v[:level], v[:versions].join(', '), v[:order], v[:label], v[:struct], v[:note]]
32
+ end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jp-national-tax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuma Takahiro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-06 00:00:00.000000000 Z
11
+ date: 2025-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,6 +75,8 @@ files:
75
75
  - lib/jp_national_tax/income_tax/income_kouran_2020.rb
76
76
  - lib/jp_national_tax/income_tax/income_nenmatsu_2020.rb
77
77
  - lib/jp_national_tax/version.rb
78
+ - tools/parse-etax-spec.rb
79
+ - tools/stats-etax-spec.rb
78
80
  homepage: https://github.com/chumaltd/jp-national-tax
79
81
  licenses: []
80
82
  metadata: