Sha256: 4b35a1a413965bf46f939e7568b551c204de8bfed7763e416a5dcf2ef37e0461

Contents?: true

Size: 782 Bytes

Versions: 5

Compression:

Stored size: 782 Bytes

Contents

require "date"
Dir[File.expand_path("income-tax/income*.rb", __dir__)].each{|f| require_relative(f)}

module JP
  module IncomeTax
  MOD = [Kouran2020]

    module_function

    def calc_kouran(pay_amount, pay_date, partner = false, dependent = 0)
      responsible_module(pay_date)
        .send(:monthly_kouran, pay_amount, partner, dependent)
        .to_i
    end

    def responsible_module(date = nil)
      if date.nil?
        raise UndefinedDateError
      elsif date.class.name == "String"
        date = Date.parse(date)
      end

      rules = MOD.map{|mod| [mod.send(:effective_date), mod] }.filter{|a| date >= a[0]}

      if rules.length > 0
        rules.sort_by{|a| a[0]}.reverse!.first[1]
      else
        raise NoValidModuleError 
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lucasalary-jp-0.1.5 lib/luca_salary/jp-national-tax/income_tax.rb
lucasalary-jp-0.1.4 lib/luca_salary/jp-national-tax/income_tax.rb
lucasalary-jp-0.1.3 lib/luca_salary/jp-national-tax/income_tax.rb
lucasalary-jp-0.1.2 lib/luca_salary/jp-national-tax/income_tax.rb
lucasalary-jp-0.1.1 lib/luca_salary/jp-national-tax/income_tax.rb