Class: LucaSalary::Jp

Inherits:
Base
  • Object
show all
Defined in:
lib/luca_salary/jp.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir_path, config = nil, date = nil) ⇒ Jp

Returns a new instance of Jp.



8
9
10
11
12
# File 'lib/luca_salary/jp.rb', line 8

def initialize(dir_path, config = nil, date = nil)
  @pjdir = dir_path
  @date = date
  @insurance = InsuranceJP.new(@pjdir, config.dig('jp', 'area'), date)
end

Class Method Details

.country_pathObject

need for local dictionary loading



15
16
17
# File 'lib/luca_salary/jp.rb', line 15

def self.country_path
  __dir__
end

.year_total(profile, payment, date) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/luca_salary/jp.rb', line 36

def self.year_total(profile, payment, date)
  raise '年末調整の対象となりません' if payment['1'] == 0

  payment.tap do |p|
    p['911'] = JpNationalTax::IncomeTax.basic_deduction(p['1'], date)
    p['916'] = 配偶者控除の金額(p['1'], profile['spouse'], date)
    p['917'] = 配偶者特別控除の金額(p['1'], profile['spouse'], date)
    p['918'] = 扶養控除の金額(profile['family'], date)
    p['912'] = ['201', '202', '204', '205'].map{ |cd| p[cd] }.compact.sum
    p['901'] = JpNationalTax::IncomeTax.year_salary_taxable(p['1'], date)
    p['941'] = p['901'] - ['911', '912', '916', '917', '918'].map{ |cd| p[cd] }.compact.sum
    p['961'] = JpNationalTax::IncomeTax.year_tax(p['941'], date)
    diff = p['961'] - p['203']
    if diff.positive?
      p['3A1'] = diff
      p['4A1'] = BigDecimal('0')
    else
      p['4A1'] = diff * -1
      p['3A1'] = BigDecimal('0')
    end
    p.delete '3'
    p.delete '4'
    p['3'] = sum_code(p, '3')
    p['4'] = sum_code(p, '4')
  end
end

.各家族の扶養控除の額(person, date) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/luca_salary/jp.rb', line 133

def self.各家族の扶養控除の額(person, date)
  birth_date = person['birth_date']
  return 0 if birth_date.nil?

  if birth_date > date.prev_year(16)
    0
  elsif birth_date <= date.prev_year(70)
    person['live_with'] ? 580_000 : 480_000 # 老人扶養親族
  elsif birth_date <= date.prev_year(19) and birth_date > date.prev_year(23)
    630_000 # 特定扶養親族
  else
    380_000
  end
end

.扶養控除の金額(family, date) ⇒ Object



127
128
129
130
131
# File 'lib/luca_salary/jp.rb', line 127

def self.扶養控除の金額(family, date)
  return if family.nil?

  family.map { |person| 各家族の扶養控除の額(person, date) }.sum
end

.扶養控除対象者の数(family, date) ⇒ Object



148
149
150
# File 'lib/luca_salary/jp.rb', line 148

def self.扶養控除対象者の数(family, date)
  family.map { |person| 各家族の扶養控除の額(person, date) > 0 ? 1 : 0 }.sum
end

.配偶者控除の金額(income, spouse, date) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/luca_salary/jp.rb', line 63

def self.配偶者控除の金額(income, spouse, date)
  puts spouse
  return nil if spouse.nil?

  puts spouse
  spouse_salary = JpNationalTax::IncomeTax.year_salary_taxable(spouse['income'][date.year.to_s] || 0, date)
  return 0 if spouse_salary > 480_000

  salary = JpNationalTax::IncomeTax.year_salary_taxable(income || 0, date)
  birth_date = spouse['birth_date'] || date
  if salary <= 9_000_000
    birth_date <= date.prev_year(70) ? 480_000 : 380_000
  elsif salary <= 9_500_000
    birth_date <= date.prev_year(70) ? 320_000 : 260_000
  elsif salary <= 10_000_000
    birth_date <= date.prev_year(70) ? 160_000 : 130_000
  else
    0
  end
end

.配偶者特別控除の金額(income, spouse, date) ⇒ Object



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
# File 'lib/luca_salary/jp.rb', line 84

def self.配偶者特別控除の金額(income, spouse, date)
  return nil if spouse.nil?

  salary = JpNationalTax::IncomeTax.year_salary_taxable(income || 0, date)
  return 0 if salary > 10_000_000

  spouse_salary = JpNationalTax::IncomeTax.year_salary_taxable(spouse['income'][date.year.to_s] || 0, date)
  return 0 if spouse_salary <= 480_000
  return 0 if spouse_salary > 1_330_000

  if salary <= 9_000_000
    return 380_000 if spouse_salary <= 950_000
    return 360_000 if spouse_salary <= 1_000_000
    return 310_000 if spouse_salary <= 1_050_000
    return 260_000 if spouse_salary <= 1_100_000
    return 210_000 if spouse_salary <= 1_150_000
    return 160_000 if spouse_salary <= 1_200_000
    return 110_000 if spouse_salary <= 1_250_000
    return 60_000 if spouse_salary <= 1_300_000
    return 30_000
  elsif salary <= 9_500_000
    return 260_000 if spouse_salary <= 950_000
    return 240_000 if spouse_salary <= 1_000_000
    return 210_000 if spouse_salary <= 1_050_000
    return 180_000 if spouse_salary <= 1_100_000
    return 140_000 if spouse_salary <= 1_150_000
    return 110_000 if spouse_salary <= 1_200_000
    return 80_000 if spouse_salary <= 1_250_000
    return 40_000 if spouse_salary <= 1_300_000
    return 20_000
  else
    return 130_000 if spouse_salary <= 950_000
    return 120_000 if spouse_salary <= 1_000_000
    return 110_000 if spouse_salary <= 1_050_000
    return 90_000 if spouse_salary <= 1_100_000
    return 70_000 if spouse_salary <= 1_150_000
    return 60_000 if spouse_salary <= 1_200_000
    return 40_000 if spouse_salary <= 1_250_000
    return 20_000 if spouse_salary <= 1_300_000
    return 10_000
  end
end

Instance Method Details

#calc_payment(profile, date) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/luca_salary/jp.rb', line 19

def calc_payment(profile, date)
  配偶者控除 = profile.include?('spouse')
  扶養控除 = self.class.扶養控除対象者の数(profile['family'], Date.new(date.year, 12, 31))
  {}.tap do |h|
    select_code(profile, '1').each { |k, v| h[k] = v }
    h['201'] = @insurance.health_insurance_salary(insurance_rank(profile))
    h['202'] = @insurance.pension_salary(pension_rank(profile))
    tax_base = self.class.sum_code(h, '1', income_tax_exception) - h['201'] - h['202']
    h['203'] = JpNationalTax::IncomeTax.calc_kouran(tax_base, Date.today, 配偶者控除, 扶養控除)
    h['211'] = resident_tax(profile)
    select_code(profile, '3').each { |k, v| h[k] = v }
    select_code(profile, '4').each { |k, v| h[k] = v }
    h.merge!(amount_by_code(h))
    h['id'] = profile.dig('id')
  end
end

#income_tax_exceptionObject



152
153
154
# File 'lib/luca_salary/jp.rb', line 152

def income_tax_exception
  %w[116 118 119 11A 11B]
end

#insurance_rank(dat) ⇒ Object



156
157
158
# File 'lib/luca_salary/jp.rb', line 156

def insurance_rank(dat)
  dat.dig('insurance', 'rank')
end

#pension_rank(dat) ⇒ Object



160
161
162
# File 'lib/luca_salary/jp.rb', line 160

def pension_rank(dat)
  dat.dig('pension', 'rank')
end

#resident_tax(dat) ⇒ Object



164
165
166
167
# File 'lib/luca_salary/jp.rb', line 164

def resident_tax(dat)
  attr = @date.month == 6 ? 'extra' : 'ordinal'
  dat.dig('resident', attr)
end