Class: TaxJp::WithheldTax

Inherits:
Object
  • Object
show all
Defined in:
lib/tax_jp/withheld_tax.rb

Constant Summary collapse

DB_PATH =
File.join(TaxJp::Utils.data_dir, '源泉徴収税.db')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ WithheldTax

Returns a new instance of WithheldTax.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tax_jp/withheld_tax.rb', line 15

def initialize(row)
  @valid_from = row[0]
  @valid_until = row[1]
  @salary_range_from = row[2]
  @salary_range_to = row[3]
  @dependent_0 = row[4]
  @dependent_1 = row[5]
  @dependent_2 = row[6]
  @dependent_3 = row[7]
  @dependent_4 = row[8]
  @dependent_5 = row[9]
  @dependent_6 = row[10]
  @dependent_7 = row[11]
  @sub_salary = row[12]
end

Instance Attribute Details

#dependent_0Object (readonly)

Returns the value of attribute dependent_0.



12
13
14
# File 'lib/tax_jp/withheld_tax.rb', line 12

def dependent_0
  @dependent_0
end

#dependent_1Object (readonly)

Returns the value of attribute dependent_1.



12
13
14
# File 'lib/tax_jp/withheld_tax.rb', line 12

def dependent_1
  @dependent_1
end

#dependent_2Object (readonly)

Returns the value of attribute dependent_2.



12
13
14
# File 'lib/tax_jp/withheld_tax.rb', line 12

def dependent_2
  @dependent_2
end

#dependent_3Object (readonly)

Returns the value of attribute dependent_3.



12
13
14
# File 'lib/tax_jp/withheld_tax.rb', line 12

def dependent_3
  @dependent_3
end

#dependent_4Object (readonly)

Returns the value of attribute dependent_4.



12
13
14
# File 'lib/tax_jp/withheld_tax.rb', line 12

def dependent_4
  @dependent_4
end

#dependent_5Object (readonly)

Returns the value of attribute dependent_5.



12
13
14
# File 'lib/tax_jp/withheld_tax.rb', line 12

def dependent_5
  @dependent_5
end

#dependent_6Object (readonly)

Returns the value of attribute dependent_6.



12
13
14
# File 'lib/tax_jp/withheld_tax.rb', line 12

def dependent_6
  @dependent_6
end

#dependent_7Object (readonly)

Returns the value of attribute dependent_7.



12
13
14
# File 'lib/tax_jp/withheld_tax.rb', line 12

def dependent_7
  @dependent_7
end

#salary_range_fromObject (readonly)

Returns the value of attribute salary_range_from.



11
12
13
# File 'lib/tax_jp/withheld_tax.rb', line 11

def salary_range_from
  @salary_range_from
end

#salary_range_toObject (readonly)

Returns the value of attribute salary_range_to.



11
12
13
# File 'lib/tax_jp/withheld_tax.rb', line 11

def salary_range_to
  @salary_range_to
end

#sub_salaryObject (readonly)

Returns the value of attribute sub_salary.



13
14
15
# File 'lib/tax_jp/withheld_tax.rb', line 13

def sub_salary
  @sub_salary
end

#valid_fromObject (readonly)

Returns the value of attribute valid_from.



10
11
12
# File 'lib/tax_jp/withheld_tax.rb', line 10

def valid_from
  @valid_from
end

#valid_untilObject (readonly)

Returns the value of attribute valid_until.



10
11
12
# File 'lib/tax_jp/withheld_tax.rb', line 10

def valid_until
  @valid_until
end

Class Method Details

.find_by_date(date) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/tax_jp/withheld_tax.rb', line 48

def self.find_by_date(date)
  date = date.strftime('%Y-%m-%d') if date.is_a?(Date)
  with_database do |db|
    sql = 'select * from withheld_taxes where valid_from <= ? and valid_until >= ?'
    
    ret = []
    db.execute(sql, [date, date]) do |row|
      ret << TaxJp::WithheldTax.new(row)
    end
    
    ret.sort{|a, b| a.salary_range_from <=> b.salary_range_from }
  end
end

.find_by_date_and_salary(date, salary) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tax_jp/withheld_tax.rb', line 31

def self.find_by_date_and_salary(date, salary)
  date = date.strftime('%Y-%m-%d') if date.is_a?(Date)
  with_database do |db|
    sql = 'select * from withheld_taxes where valid_from <= ? and valid_until >= ? and salary_range_from <= ? and salary_range_to > ?'

    ret = nil
    db.execute(sql, [date, date, salary, salary]) do |row|
      if ret
        raise "源泉徴収税が重複して登録されています。date=#{date}, salary=#{salary}"
      else
        ret = TaxJp::WithheldTax.new(row)
      end
    end
    ret
  end
end