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

.partner_deduction(income) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/luca_salary/jp.rb', line 57

def self.partner_deduction(income)
  if income <= 9_000_000
    380_000
  elsif income <= 9_500_000
    260_000
  elsif income <= 10_000_000
    130_000
  else
    0
  end
end

.year_total(payment, date) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/luca_salary/jp.rb', line 34

def self.year_total(payment, date)
  payment.tap do |p|
    p['911'] = JpNationalTax::IncomeTax.basic_deduction(p['1'], date)
    p['916'] = partner_deduction(p['1'])
    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'] - p['911'] - p['912'] - p['916']
    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

Instance Method Details

#calc_payment(profile) ⇒ Object



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

def calc_payment(profile)
  {}.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, true)
    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



69
70
71
# File 'lib/luca_salary/jp.rb', line 69

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

#insurance_rank(dat) ⇒ Object



73
74
75
# File 'lib/luca_salary/jp.rb', line 73

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

#pension_rank(dat) ⇒ Object



77
78
79
# File 'lib/luca_salary/jp.rb', line 77

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

#resident_tax(dat) ⇒ Object



81
82
83
84
# File 'lib/luca_salary/jp.rb', line 81

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