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



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

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

  給与等の金額 = JpNationalTax::IncomeTax.year_salary_taxable(payment['1'], date)
  payment.tap do |p|
    p['901'] = 給与等の金額
    p['911'] = JpNationalTax::IncomeTax.basic_deduction(給与等の金額, date)
    p['916'] = 配偶者控除の金額(給与等の金額, profile['spouse'], date)
    p['917'] = 配偶者特別控除の金額(給与等の金額, profile['spouse'], date)
    p['918'] = 扶養控除の金額(profile['family'], date)
    p['912'] = ['201', '202', '204', '205'].map{ |cd| p[cd] }.compact.sum
    課税給与所得金額 = 給与等の金額 - ['911', '912', '916', '917', '918'].map{ |cd| p[cd] }.compact.sum
    p['941'] = (課税給与所得金額 / 1000).floor * 1000
    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



93
94
95
96
97
98
99
# File 'lib/luca_salary/jp.rb', line 93

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

  salary = JpNationalTax::IncomeTax.year_salary_taxable(person.dig('income', date.year.to_s) || 0, date)
  JpNationalTax::IncomeTax.family_deduction(birth_date, date, salary, live_with: person['live_with'])
end

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



87
88
89
90
91
# File 'lib/luca_salary/jp.rb', line 87

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

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

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



101
102
103
# File 'lib/luca_salary/jp.rb', line 101

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

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



68
69
70
71
72
73
74
75
# File 'lib/luca_salary/jp.rb', line 68

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

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

  JpNationalTax::IncomeTax.spouse_deduction(salary, spouse_salary, date, spouse['birth_date'])
end

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



77
78
79
80
81
82
83
84
85
# File 'lib/luca_salary/jp.rb', line 77

def self.配偶者特別控除の金額(salary, spouse, date)
  return nil if spouse.nil?
  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 <= 580_000

  JpNationalTax::IncomeTax.spouse_deduction(salary, spouse_salary, date, spouse['birth_date'])
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
35
36
37
# 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),
      介護保険?(profile['birth_date'])
    )
    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.fetch('id')
  end
end