tax_jp 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/tax_jp/application.js +3 -0
  3. data/app/assets/stylesheets/tax_jp/application.css.scss +3 -0
  4. data/app/controllers/tax_jp/bonus_withheld_taxes_controller.rb +27 -0
  5. data/app/models/tax_jp/finder.rb +5 -0
  6. data/app/views/layouts/tax_jp/_nav.html.erb +1 -0
  7. data/app/views/tax_jp/bonus_withheld_taxes/index.html.erb +80 -0
  8. data/config/routes.rb +1 -0
  9. data/data//346/272/220/346/263/211/345/276/264/345/217/216/347/250/216/schema_bonus.sql +23 -0
  10. data/data//346/272/220/346/263/211/345/276/264/345/217/216/347/250/216/{schema.sql → schema_monthly.sql} +0 -0
  11. data/data//346/272/220/346/263/211/345/276/264/345/217/216/347/250/216/{20070101-20121231.tsv → /346/272/220/346/263/211/345/276/264/345/217/216/347/250/216/346/234/210/351/241/215-20070101-20121231.tsv} +0 -0
  12. data/data//346/272/220/346/263/211/345/276/264/345/217/216/347/250/216/{20130101-20151231.tsv → /346/272/220/346/263/211/345/276/264/345/217/216/347/250/216/346/234/210/351/241/215-20130101-20151231.tsv} +0 -0
  13. data/data//346/272/220/346/263/211/345/276/264/345/217/216/347/250/216/{20160101-20161231.tsv → /346/272/220/346/263/211/345/276/264/345/217/216/347/250/216/346/234/210/351/241/215-20160101-20161231.tsv} +0 -0
  14. data/data//346/272/220/346/263/211/345/276/264/345/217/216/347/250/216/{20170101-20181231.tsv → /346/272/220/346/263/211/345/276/264/345/217/216/347/250/216/346/234/210/351/241/215-20170101-20181231.tsv} +0 -0
  15. data/data//346/272/220/346/263/211/345/276/264/345/217/216/347/250/216//346/272/220/346/263/211/345/276/264/345/217/216/347/250/216/350/263/236/344/270/216-20180101-20181231.tsv +40 -0
  16. data/data//346/272/220/346/263/211/345/276/264/345/217/216/347/250/{216.db → 216/346/234/210/351/241/215.db} +0 -0
  17. data/data//346/272/220/346/263/211/345/276/264/345/217/216/347/250/216/350/263/236/344/270/216.db +0 -0
  18. data/lib/build_tasks/build.rake +6 -3
  19. data/lib/tax_jp/engine.rb +3 -0
  20. data/lib/tax_jp/utils.rb +17 -0
  21. data/lib/tax_jp/version.rb +1 -1
  22. data/lib/tax_jp/withheld_tax.rb +4 -14
  23. data/lib/tax_jp/withheld_taxes/bonus.rb +81 -0
  24. data/lib/tax_jp/withheld_taxes/bonus_db_builder.rb +40 -0
  25. data/lib/tax_jp/withheld_taxes/monthly_db_builder.rb +42 -0
  26. metadata +45 -9
  27. data/lib/tax_jp/withheld_taxes/db_builder.rb +0 -61
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c11165d503a1396f1478d1e3089fa5bba9802ac8f6f3a51cd197902acc15e7ca
4
- data.tar.gz: 0d03dbf53ce8a99e9f3bf63d0cd1a4c4cab7a568c7d76a82b4405b4c14862004
3
+ metadata.gz: 4c9e2cab9304a1a1473c7f935bb22bd3161a2786614d02e9182892a8caa561f2
4
+ data.tar.gz: 1e80555ca7fb62868bc442416431a52e73ee87703c27230bd8e1ade3637fd237
5
5
  SHA512:
6
- metadata.gz: 199bcb5713fc6f35960c1165b380fa98a9d00d5d043ae5cb98a0cd89b1c094ad7cb7ee726dc6914a822971214cae83cab458fd166333bdbe1cc4a76a11991875
7
- data.tar.gz: 573d942ffb70d7546524f5eb05ded417df60adcb0aac6de2e1adca2734d6d7d3ef84fe3802faaecd6efb3236579aa1780a2b67e8864819f8e800bdd0e26402be
6
+ metadata.gz: 6947dad826bcf7d274906b320c220627358058f1ab62dc0bd566b40caf12cbbc46ba119f015a83e21a39e3e7257e4967dffe694279c1a2d07c5e6e1216eec556
7
+ data.tar.gz: 457dc98a3f9676a12f9a5d082e0d733588e992efff487fe3caf5b490a57dc51956aa380e619222f59f4e82b9d8c3926d96cda104195a1e49f7177b9ad466cc3c
@@ -15,4 +15,7 @@
15
15
  //= require jquery3
16
16
  //= require popper
17
17
  //= require bootstrap
18
+ //= require moment
19
+ //= require moment/ja.js
20
+ //= require tempusdominus-bootstrap-4.js
18
21
  //= require_tree .
@@ -10,8 +10,11 @@
10
10
  * files in this directory. Styles in this file should be added after the last require_* statement.
11
11
  * It is generally better to create a new file per style scope.
12
12
  *
13
+ *= require font-awesome
13
14
  *= require_tree .
14
15
  *= require_self
15
16
  */
16
17
 
17
18
  @import "bootstrap";
19
+ @import "font-awesome";
20
+ @import "tempusdominus-bootstrap-4";
@@ -0,0 +1,27 @@
1
+ require_dependency "tax_jp/application_controller"
2
+
3
+ module TaxJp
4
+ class BonusWithheldTaxesController < ApplicationController
5
+ before_action :preload_finder
6
+
7
+ def index
8
+ @withheld_taxes = TaxJp::WithheldTaxes::Bonus.find_all_by_date(@finder.from)
9
+ end
10
+
11
+ private
12
+
13
+ def preload_finder
14
+ @finder = TaxJp::Finder.new(finder_params)
15
+ @finder.from ||= Date.today.strftime('%Y-%m-%d')
16
+ end
17
+
18
+ def finder_params
19
+ if params[:finder].present?
20
+ params.require(:finder).permit(:from)
21
+ else
22
+ {}
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ class TaxJp::Finder
2
+ include ActiveModel::Model
3
+
4
+ attr_accessor :from
5
+ end
@@ -1,4 +1,5 @@
1
1
  <nav class="nav justify-content-center">
2
+ <%= link_to '源泉徴収税(賞与)', bonus_withheld_taxes_path, class: "nav-link #{controller_name == 'bonus_withheld_taxes' ? 'active' : nil}" %>
2
3
  <%= link_to '雇用保険料', employment_insurances_path, class: "nav-link #{controller_name == 'employment_insurances' ? 'active' : nil}" %>
3
4
  <%= link_to '減価償却率', depreciation_rates_path, class: "nav-link #{controller_name == 'depreciation_rates' ? 'active' : nil}" %>
4
5
  </nav>
@@ -0,0 +1,80 @@
1
+ <div class="container">
2
+ <%= form_with model: @finder, url: {action: 'index'}, method: 'get', class: 'form form-vertical', local: true do |f| %>
3
+ <div class="row">
4
+ <div class="col-sm-3 form-group">
5
+ <div class="input-group date" id="datetimepicker4" data-target-input="nearest">
6
+ <label for="datetimepicker1" class="pt-2 pr-2">年月日:</label>
7
+ <%= f.text_field :from, class: 'form-control datetimepicker-input', data: {target: '#datetimepicker4'} %>
8
+ <div class="input-group-append" data-target="#datetimepicker4" data-toggle="datetimepicker">
9
+ <div class="input-group-text"><i class="fa fa-calendar"></i></div>
10
+ </div>
11
+ </div>
12
+ </div>
13
+ <div class="col">
14
+ <%= f.submit '表示', class: 'btn btn-sm btn-default mt-1' %>
15
+ </div>
16
+ </div>
17
+ <script>
18
+ $(function () {
19
+ $('#datetimepicker4').datetimepicker({
20
+ format: 'YYYY-MM-DD',
21
+ locale: 'ja',
22
+ buttons: {
23
+ showClose: true
24
+ }
25
+ });
26
+ });
27
+ </script>
28
+ <% end %>
29
+ </div>
30
+ <div class="pl-4 pr-4">
31
+ <table class="table table-striped table-bordered table-hover table-sm">
32
+ <thead class="thead-light">
33
+ <tr>
34
+ <th rowspan="5" class="align-middle text-center">賞与の金額に乗ずべき率(%)</th>
35
+ <th colspan="16" class="align-middle text-center">甲</th>
36
+ <th rowspan="3" colspan="2" class="align-middle text-center">乙</th>
37
+ </tr>
38
+ <tr>
39
+ <th colspan="16" class="align-middle text-center">扶養親族等の数</th>
40
+ </tr>
41
+ <tr>
42
+ <% 8.times do |i| %>
43
+ <th colspan="2" class="align-middle text-center"><%= i %> 人<%= '以上' if i == 7 %></th>
44
+ <% end %>
45
+ </tr>
46
+ <tr>
47
+ <th colspan="18" class="align-middle text-center">前月の社会保険料等控除後の給与等の金額</th>
48
+ </tr>
49
+ <tr>
50
+ <% 9.times do |i| %>
51
+ <th class="align-middle text-center">以上</th>
52
+ <th class="align-middle text-center">未満</th>
53
+ <% end %>
54
+ </tr>
55
+ </thead>
56
+ <tbody>
57
+ <% @withheld_taxes.each do |wt| %>
58
+ <tr>
59
+ <td class="text-center"><%= wt.tax_ratio_percent %></td>
60
+ <% 8.times do |i| %>
61
+ <%
62
+ from = wt.__send__("dependent_#{i}_salary_from")
63
+ to = wt.__send__("dependent_#{i}_salary_to")
64
+ infinite = to == 2147483647
65
+ %>
66
+ <td class="text-right"><%= from == 2147483647 ? '-' : from.to_s(:delimited) %></td>
67
+ <td class="<%= infinite ? 'text-center' : 'text-right' %>"><%= infinite ? '-' : to.to_s(:delimited) %></td>
68
+ <% end %>
69
+ <%
70
+ from = wt.sub_salary_from
71
+ to = wt.sub_salary_to
72
+ infinite = to == 2147483647
73
+ %>
74
+ <td class="text-right"><%= from.to_s(:delimited) unless from == 0 && to == 0 %></td>
75
+ <td class="<%= infinite ? 'text-center' : 'text-right' %>"><%= infinite ? '-' : to.to_s(:delimited) unless from == 0 && to == 0 %></td>
76
+ </tr>
77
+ <% end %>
78
+ </tbody>
79
+ </table>
80
+ </div>
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  TaxJp::Engine.routes.draw do
2
+ resources :bonus_withheld_taxes, only: 'index'
2
3
  resources :depreciation_rates, only: 'index'
3
4
  resources :employment_insurances, only: 'index'
4
5
 
@@ -0,0 +1,23 @@
1
+ create table bonus_withheld_taxes (
2
+ valid_from date not null,
3
+ valid_until date not null,
4
+ tax_ratio decimal(6,5) not null,
5
+ dependent_0_salary_from integer not null,
6
+ dependent_0_salary_to integer not null,
7
+ dependent_1_salary_from integer not null,
8
+ dependent_1_salary_to integer not null,
9
+ dependent_2_salary_from integer not null,
10
+ dependent_2_salary_to integer not null,
11
+ dependent_3_salary_from integer not null,
12
+ dependent_3_salary_to integer not null,
13
+ dependent_4_salary_from integer not null,
14
+ dependent_4_salary_to integer not null,
15
+ dependent_5_salary_from integer not null,
16
+ dependent_5_salary_to integer not null,
17
+ dependent_6_salary_from integer not null,
18
+ dependent_6_salary_to integer not null,
19
+ dependent_7_salary_from integer not null,
20
+ dependent_7_salary_to integer not null,
21
+ sub_salary_from integer not null,
22
+ sub_salary_to integer not null
23
+ );
@@ -0,0 +1,40 @@
1
+ "賞与の金額に乗ずべき率" "扶養親族等の数(0人)
2
+ 前月の社会保険料等控除後の給与等の金額(以上)" "扶養親族等の数(0人)
3
+ 前月の社会保険料等控除後の給与等の金額(未満)" "扶養親族等の数(1人)
4
+ 前月の社会保険料等控除後の給与等の金額(以上)" "扶養親族等の数(1人)
5
+ 前月の社会保険料等控除後の給与等の金額(未満)" "扶養親族等の数(2人)
6
+ 前月の社会保険料等控除後の給与等の金額(以上)" "扶養親族等の数(2人)
7
+ 前月の社会保険料等控除後の給与等の金額(未満)" "扶養親族等の数(3人)
8
+ 前月の社会保険料等控除後の給与等の金額(以上)" "扶養親族等の数(3人)
9
+ 前月の社会保険料等控除後の給与等の金額(未満)" "扶養親族等の数(4人)
10
+ 前月の社会保険料等控除後の給与等の金額(以上)" "扶養親族等の数(4人)
11
+ 前月の社会保険料等控除後の給与等の金額(未満)" "扶養親族等の数(5人)
12
+ 前月の社会保険料等控除後の給与等の金額(以上)" "扶養親族等の数(5人)
13
+ 前月の社会保険料等控除後の給与等の金額(未満)" "扶養親族等の数(6人)
14
+ 前月の社会保険料等控除後の給与等の金額(以上)" "扶養親族等の数(6人)
15
+ 前月の社会保険料等控除後の給与等の金額(未満)" "扶養親族等の数(7人)
16
+ 前月の社会保険料等控除後の給与等の金額(以上)" "扶養親族等の数(7人)
17
+ 前月の社会保険料等控除後の給与等の金額(未満)" "乙
18
+ 前月の社会保険料等控除後の給与等の金額(以上)" "乙
19
+ 前月の社会保険料等控除後の給与等の金額(未満)"
20
+ 0 0 68000 0 94000 0 133000 0 171000 0 210000 0 243000 0 275000 0 308000
21
+ 0.02042 68000 79000 94000 243000 133000 269000 171000 295000 210000 300000 243000 300000 275000 333000 308000 372000
22
+ 0.04084 79000 252000 243000 282000 269000 312000 295000 345000 300000 378000 300000 406000 333000 431000 372000 456000
23
+ 0.06126 252000 300000 282000 338000 312000 369000 345000 398000 378000 424000 406000 450000 431000 476000 456000 502000
24
+ 0.08168 300000 334000 338000 365000 369000 393000 398000 417000 424000 444000 450000 472000 476000 499000 502000 527000
25
+ 0.1021 334000 363000 365000 394000 393000 420000 417000 445000 444000 470000 472000 496000 499000 525000 527000 553000 0 239000
26
+ 0.12252 363000 395000 394000 422000 420000 450000 445000 477000 470000 504000 496000 531000 525000 559000 553000 588000
27
+ 0.14294 395000 426000 422000 455000 450000 484000 477000 513000 504000 543000 531000 574000 559000 602000 588000 627000
28
+ 0.16336 426000 550000 455000 550000 484000 550000 513000 557000 543000 591000 574000 618000 602000 645000 627000 671000
29
+ 0.18378 550000 647000 550000 663000 550000 678000 557000 693000 591000 708000 618000 723000 645000 739000 671000 754000
30
+ 0.2042 647000 699000 663000 720000 678000 741000 693000 762000 708000 783000 723000 804000 739000 825000 754000 848000 239000 296000
31
+ 0.22462 699000 730000 720000 752000 741000 774000 762000 796000 783000 818000 804000 841000 825000 865000 848000 890000
32
+ 0.24504 730000 764000 752000 787000 774000 810000 796000 833000 818000 859000 841000 885000 865000 911000 890000 937000
33
+ 0.26546 764000 804000 787000 826000 810000 852000 833000 879000 859000 906000 885000 934000 911000 961000 937000 988000
34
+ 0.28588 804000 857000 826000 885000 852000 914000 879000 942000 906000 970000 934000 998000 961000 1026000 988000 1054000
35
+ 0.3063 857000 926000 885000 956000 914000 987000 942000 1017000 970000 1048000 998000 1078000 1026000 1108000 1054000 1139000 296000 528000
36
+ 0.32672 926000 1321000 956000 1346000 987000 1370000 1017000 1394000 1048000 1419000 1078000 1443000 1108000 1468000 1139000 1492000
37
+ 0.35735 1321000 1532000 1346000 1560000 1370000 1589000 1394000 1617000 1419000 1645000 1443000 1674000 1468000 1702000 1492000 1730000
38
+ 0.38798 1532000 2661000 1560000 2685000 1589000 2708000 1617000 2732000 1645000 2756000 1674000 2780000 1702000 2803000 1730000 2827000 528000 1135000
39
+ 0.41861 2661000 3548000 2685000 3580000 2708000 3611000 2732000 3643000 2756000 3675000 2780000 3706000 2803000 3738000 2827000 3770000
40
+ 0.45945 3548000 - 3580000 - 3611000 - 3643000 - 3675000 - 3706000 - 3738000 - 3770000 - 1135000 -
@@ -6,7 +6,8 @@ require 'tax_jp/corporate_taxes/db_builder'
6
6
  require 'tax_jp/depreciation_rates/db_builder'
7
7
  require 'tax_jp/labor_insurances/employment_insurance_db_builder'
8
8
  require 'tax_jp/social_insurances/db_builder'
9
- require 'tax_jp/withheld_taxes/db_builder'
9
+ require 'tax_jp/withheld_taxes/bonus_db_builder'
10
+ require 'tax_jp/withheld_taxes/monthly_db_builder'
10
11
 
11
12
  namespace :taxjp do
12
13
  namespace :build do
@@ -44,8 +45,10 @@ namespace :taxjp do
44
45
 
45
46
  desc '源泉徴収税DBを構築します。'
46
47
  task :withheld_tax do
47
- puts '源泉徴収税'
48
- TaxJp::WithheldTaxes::DbBuilder.new.run
48
+ puts '源泉徴収税月額'
49
+ TaxJp::WithheldTaxes::MonthlyDbBuilder.new.run
50
+ puts '源泉徴収税賞与'
51
+ TaxJp::WithheldTaxes::BonusDbBuilder.new.run
49
52
  end
50
53
 
51
54
  desc '法人税-区分番号DBを構築します。'
data/lib/tax_jp/engine.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'bootstrap4-datetime-picker-rails'
2
+ require 'font-awesome-rails'
3
+
1
4
  module TaxJp
2
5
  class Engine < ::Rails::Engine
3
6
  isolate_namespace TaxJp
data/lib/tax_jp/utils.rb CHANGED
@@ -69,6 +69,23 @@ module TaxJp
69
69
  [valid_from.strftime('%Y-%m-%d'), valid_until.strftime('%Y-%m-%d')]
70
70
  end
71
71
 
72
+ def normalize_amount(amount, options = {})
73
+ ret = amount.to_s
74
+
75
+ if ret == '-'
76
+ ret = 2147483647
77
+ else
78
+ ret = ret.gsub(',', '')
79
+ if ret.index('.')
80
+ ret = ret.to_f
81
+ else
82
+ ret = ret.to_i
83
+ end
84
+ end
85
+
86
+ ret
87
+ end
88
+
72
89
  end
73
90
  end
74
91
  end
@@ -1,3 +1,3 @@
1
1
  module TaxJp
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
@@ -1,9 +1,10 @@
1
1
  module TaxJp
2
2
  module WithheldTaxes
3
+ require_relative 'withheld_taxes/bonus'
3
4
  end
4
5
 
5
6
  class WithheldTax
6
- DB_PATH = File.join(TaxJp::Utils.data_dir, '源泉徴収税.db')
7
+ MONTHLY_DB_PATH = File.join(TaxJp::Utils.data_dir, '源泉徴収税月額.db')
7
8
 
8
9
  attr_reader :valid_from, :valid_until
9
10
  attr_reader :salary_range_from, :salary_range_to
@@ -28,7 +29,7 @@ module TaxJp
28
29
 
29
30
  def self.find_by_date_and_salary(date, salary)
30
31
  date = date.strftime('%Y-%m-%d') if date.is_a?(Date)
31
- with_database do |db|
32
+ TaxJp::Utils.with_database(MONTHLY_DB_PATH) do |db|
32
33
  sql = 'select * from withheld_taxes where valid_from <= ? and valid_until >= ? and salary_range_from <= ? and salary_range_to > ?'
33
34
 
34
35
  ret = nil
@@ -45,7 +46,7 @@ module TaxJp
45
46
 
46
47
  def self.find_all_by_date(date)
47
48
  date = date.strftime('%Y-%m-%d') if date.is_a?(Date)
48
- with_database do |db|
49
+ TaxJp::Utils.with_database(MONTHLY_DB_PATH) do |db|
49
50
  sql = 'select * from withheld_taxes where valid_from <= ? and valid_until >= ?'
50
51
 
51
52
  ret = []
@@ -57,16 +58,5 @@ module TaxJp
57
58
  end
58
59
  end
59
60
 
60
- private
61
-
62
- def self.with_database
63
- db = SQLite3::Database.new(DB_PATH)
64
- begin
65
- yield db
66
- ensure
67
- db.close
68
- end
69
- end
70
-
71
61
  end
72
62
  end
@@ -0,0 +1,81 @@
1
+ module TaxJp
2
+ module WithheldTaxes
3
+
4
+ class Bonus
5
+ DB_PATH = File.join(TaxJp::Utils.data_dir, '源泉徴収税賞与.db')
6
+
7
+ attr_reader :valid_from, :valid_until
8
+ attr_reader :tax_ratio
9
+ attr_reader :dependent_0_salary_from, :dependent_0_salary_to
10
+ attr_reader :dependent_1_salary_from, :dependent_1_salary_to
11
+ attr_reader :dependent_2_salary_from, :dependent_2_salary_to
12
+ attr_reader :dependent_3_salary_from, :dependent_3_salary_to
13
+ attr_reader :dependent_4_salary_from, :dependent_4_salary_to
14
+ attr_reader :dependent_5_salary_from, :dependent_5_salary_to
15
+ attr_reader :dependent_6_salary_from, :dependent_6_salary_to
16
+ attr_reader :dependent_7_salary_from, :dependent_7_salary_to
17
+ attr_reader :sub_salary_from, :sub_salary_to
18
+
19
+ def initialize(row)
20
+ @valid_from = row[0]
21
+ @valid_until = row[1]
22
+ @tax_ratio = row[2]
23
+ @dependent_0_salary_from = row[3]
24
+ @dependent_0_salary_to = row[4]
25
+ @dependent_1_salary_from = row[5]
26
+ @dependent_1_salary_to = row[6]
27
+ @dependent_2_salary_from = row[7]
28
+ @dependent_2_salary_to = row[8]
29
+ @dependent_3_salary_from = row[9]
30
+ @dependent_3_salary_to = row[10]
31
+ @dependent_4_salary_from = row[11]
32
+ @dependent_4_salary_to = row[12]
33
+ @dependent_5_salary_from = row[13]
34
+ @dependent_5_salary_to = row[14]
35
+ @dependent_6_salary_from = row[15]
36
+ @dependent_6_salary_to = row[16]
37
+ @dependent_7_salary_from = row[17]
38
+ @dependent_7_salary_to = row[18]
39
+ @sub_salary_from = row[19]
40
+ @sub_salary_to = row[20]
41
+ end
42
+
43
+ def tax_ratio_percent
44
+ (tax_ratio * 100).round(3)
45
+ end
46
+
47
+ def self.find_all_by_date(date)
48
+ date = date.strftime('%Y-%m-%d') if date.is_a?(Date)
49
+ TaxJp::Utils.with_database(DB_PATH) do |db|
50
+ sql = 'select * from bonus_withheld_taxes where valid_from <= ? and valid_until >= ? order by tax_ratio'
51
+
52
+ ret = []
53
+ db.execute(sql, [date, date]) do |row|
54
+ ret << TaxJp::WithheldTaxes::Bonus.new(row)
55
+ end
56
+
57
+ ret
58
+ end
59
+ end
60
+
61
+ def self.find_by_date_and_dependent_and_salary(date, dependent, salary)
62
+ date = date.strftime('%Y-%m-%d') if date.is_a?(Date)
63
+ dependent = dependent.to_i
64
+
65
+ TaxJp::Utils.with_database(DB_PATH) do |db|
66
+ sql = "select * from bonus_withheld_taxes "
67
+ sql << "where valid_from <= ? and valid_until >= ? "
68
+ sql << " and dependent_#{dependent}_salary_from >= ? and dependent_#{dependent}_salary_to < ?"
69
+
70
+ ret = nil
71
+ db.execute(sql, [date, date, salary, salary]) do |row|
72
+ ret = TaxJp::WithheldTaxes::Bonus.new(row)
73
+ end
74
+
75
+ ret
76
+ end
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,40 @@
1
+ require 'csv'
2
+ require 'date'
3
+
4
+ class TaxJp::WithheldTaxes::BonusDbBuilder < TaxJp::DbBuilder
5
+
6
+ def initialize(db_path = nil)
7
+ @db_path = db_path || TaxJp::WithheldTaxes::Bonus::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 = TaxJp::Utils.filename_to_date(filename)
14
+
15
+ CSV.foreach(filename, col_sep: "\t") do |row|
16
+ next if row[1].to_i == 0 && row[2].to_i == 0
17
+ db.execute(insert_sql, [valid_from.to_s, valid_until.to_s] + row.map{|col| TaxJp::Utils.normalize_amount(col)})
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def recreate_schema(db)
26
+ db.execute(TaxJp::Utils.load_file(File.join('源泉徴収税', 'schema_bonus.sql')))
27
+ end
28
+
29
+ def insert_sql
30
+ ret = 'insert into bonus_withheld_taxes (valid_from, valid_until, tax_ratio, '
31
+ 8.times do |i|
32
+ ret << "dependent_#{i}_salary_from, dependent_#{i}_salary_to, "
33
+ end
34
+ ret << 'sub_salary_from, sub_salary_to) values (?, ?, ?, '
35
+ ret << '?, ' * 16
36
+ ret << '?, ?)'
37
+ ret
38
+ end
39
+
40
+ end
@@ -0,0 +1,42 @@
1
+ require 'csv'
2
+ require 'date'
3
+
4
+ class TaxJp::WithheldTaxes::MonthlyDbBuilder < TaxJp::DbBuilder
5
+
6
+ def initialize(db_path = nil)
7
+ @db_path = db_path || TaxJp::WithheldTax::MONTHLY_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 = TaxJp::Utils.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, [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
24
+
25
+ def recreate_schema(db)
26
+ db.execute(TaxJp::Utils.load_file(File.join('源泉徴収税', 'schema_monthly.sql')))
27
+ end
28
+
29
+ def insert_sql
30
+ ret = 'insert into withheld_taxes (valid_from, valid_until, salary_range_from, salary_range_to, '
31
+ 8.times do |i|
32
+ ret << "dependent_#{i}, "
33
+ end
34
+ ret << 'sub_salary) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
35
+ ret
36
+ end
37
+
38
+ def normalize_amount(amount)
39
+ amount.to_s.gsub(',', '').to_i
40
+ end
41
+
42
+ end
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.5.1
4
+ version: 0.5.2
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: 2018-09-21 00:00:00.000000000 Z
12
+ date: 2018-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bootstrap
@@ -25,6 +25,34 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: 4.1.3
28
+ - !ruby/object:Gem::Dependency
29
+ name: bootstrap4-datetime-picker-rails
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: font-awesome-rails
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
28
56
  - !ruby/object:Gem::Dependency
29
57
  name: jquery-rails
30
58
  requirement: !ruby/object:Gem::Requirement
@@ -83,6 +111,7 @@ files:
83
111
  - app/assets/javascripts/tax_jp/application.js
84
112
  - app/assets/stylesheets/tax_jp/application.css.scss
85
113
  - app/controllers/tax_jp/application_controller.rb
114
+ - app/controllers/tax_jp/bonus_withheld_taxes_controller.rb
86
115
  - app/controllers/tax_jp/depreciation_rates_controller.rb
87
116
  - app/controllers/tax_jp/employment_insurances_controller.rb
88
117
  - app/controllers/tax_jp/top_controller.rb
@@ -90,8 +119,10 @@ files:
90
119
  - app/jobs/tax_jp/application_job.rb
91
120
  - app/mailers/tax_jp/application_mailer.rb
92
121
  - app/models/tax_jp/application_record.rb
122
+ - app/models/tax_jp/finder.rb
93
123
  - app/views/layouts/tax_jp/_nav.html.erb
94
124
  - app/views/layouts/tax_jp/application.html.erb
125
+ - app/views/tax_jp/bonus_withheld_taxes/index.html.erb
95
126
  - app/views/tax_jp/depreciation_rates/index.html.erb
96
127
  - app/views/tax_jp/employment_insurances/index.html.erb
97
128
  - app/views/tax_jp/top/index.html.erb
@@ -110,12 +141,15 @@ files:
110
141
  - data/減価償却率/schema_depreciation_rates.sql
111
142
  - data/減価償却率/減価償却率-20070401-20120331.tsv
112
143
  - data/減価償却率/減価償却率-20120401-20991231.tsv
113
- - data/源泉徴収税.db
114
- - data/源泉徴収税/20070101-20121231.tsv
115
- - data/源泉徴収税/20130101-20151231.tsv
116
- - data/源泉徴収税/20160101-20161231.tsv
117
- - data/源泉徴収税/20170101-20181231.tsv
118
- - data/源泉徴収税/schema.sql
144
+ - data/源泉徴収税/schema_bonus.sql
145
+ - data/源泉徴収税/schema_monthly.sql
146
+ - data/源泉徴収税/源泉徴収税月額-20070101-20121231.tsv
147
+ - data/源泉徴収税/源泉徴収税月額-20130101-20151231.tsv
148
+ - data/源泉徴収税/源泉徴収税月額-20160101-20161231.tsv
149
+ - data/源泉徴収税/源泉徴収税月額-20170101-20181231.tsv
150
+ - data/源泉徴収税/源泉徴収税賞与-20180101-20181231.tsv
151
+ - data/源泉徴収税月額.db
152
+ - data/源泉徴収税賞与.db
119
153
  - data/社会保険料.db
120
154
  - data/社会保険料/schema_grades.sql
121
155
  - data/社会保険料/schema_health_insurances.sql
@@ -165,7 +199,9 @@ files:
165
199
  - lib/tax_jp/utils.rb
166
200
  - lib/tax_jp/version.rb
167
201
  - lib/tax_jp/withheld_tax.rb
168
- - lib/tax_jp/withheld_taxes/db_builder.rb
202
+ - lib/tax_jp/withheld_taxes/bonus.rb
203
+ - lib/tax_jp/withheld_taxes/bonus_db_builder.rb
204
+ - lib/tax_jp/withheld_taxes/monthly_db_builder.rb
169
205
  homepage: https://github.com/hybitz/tax_jp
170
206
  licenses:
171
207
  - MIT
@@ -1,61 +0,0 @@
1
- require 'csv'
2
- require 'date'
3
-
4
- class TaxJp::WithheldTaxes::DbBuilder
5
-
6
- def initialize(db_path = nil)
7
- @db_path = db_path || TaxJp::WithheldTax::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, [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
24
-
25
- def with_database(options = {})
26
- if options.fetch(:recreate, true)
27
- FileUtils.rm_f(@db_path)
28
- db = SQLite3::Database.new(@db_path)
29
- db.execute(TaxJp::Utils.load_file(File.join('源泉徴収税', 'schema.sql')))
30
- else
31
- db = SQLite3::Database.new(@db_path)
32
- end
33
-
34
- begin
35
- yield db
36
- ensure
37
- db.close
38
- end
39
- end
40
-
41
- def insert_sql
42
- ret = 'insert into withheld_taxes (valid_from, valid_until, salary_range_from, salary_range_to, '
43
- 8.times do |i|
44
- ret << "dependent_#{i}, "
45
- end
46
- ret << 'sub_salary) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
47
- ret
48
- end
49
-
50
- def normalize_amount(amount)
51
- amount.to_s.gsub(',', '').to_i
52
- end
53
-
54
- def filename_to_date(filename)
55
- valid_from, valid_until = File.basename(filename).split('.').first.split('-')
56
- valid_from = Date.strptime(valid_from, '%Y%m%d')
57
- valid_until = Date.strptime(valid_until, '%Y%m%d')
58
- [valid_from.to_s, valid_until.to_s]
59
- end
60
-
61
- end