Class: TaxJp::SocialInsurance
- Inherits:
-
Object
- Object
- TaxJp::SocialInsurance
- Extended by:
- TaxJp::SocialInsurances::Utils
- Defined in:
- lib/tax_jp/social_insurance.rb
Overview
社会保険
Constant Summary collapse
Instance Attribute Summary collapse
-
#grade ⇒ Object
readonly
等級.
-
#health_insurance ⇒ Object
readonly
健康保険.
-
#welfare_pension ⇒ Object
readonly
厚生年金.
Class Method Summary collapse
- .find_all_by_date_and_prefecture(date, prefecture) ⇒ Object
- .find_by_date_and_prefecture_and_salary(date, prefecture, salary) ⇒ Object
- .with_database ⇒ Object
Instance Method Summary collapse
-
#initialize(row) ⇒ SocialInsurance
constructor
A new instance of SocialInsurance.
- #valid_from ⇒ Object
- #valid_until ⇒ Object
Methods included from TaxJp::SocialInsurances::Utils
convert_to_date, convert_to_prefecture_code
Constructor Details
#initialize(row) ⇒ SocialInsurance
Returns a new instance of SocialInsurance.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tax_jp/social_insurance.rb', line 24 def initialize(row) @grade = TaxJp::SocialInsurances::Grade.new( :valid_from => row[0], :valid_until => row[1], :grade => row[2], :pension_grade => row[3], :monthly_standard => row[4], :daily_standard => row[5], :salary_from => row[6], :salary_to => row[7]) @health_insurance = TaxJp::SocialInsurances::HealthInsurance.new( :grade => @grade, :valid_from => row[8], :valid_until => row[9], :prefecture => Prefecture.find_by_code(row[10]), :general => row[11], :care => row[12], :particular => row[13], :basic => row[14]) @welfare_pension = TaxJp::SocialInsurances::WelfarePension.new( :grade => @grade, :valid_from => row[15], :valid_until => row[16], :general => row[17], :particular => row[18], :child_support => row[19]) end |
Instance Attribute Details
#grade ⇒ Object (readonly)
等級
18 19 20 |
# File 'lib/tax_jp/social_insurance.rb', line 18 def grade @grade end |
#health_insurance ⇒ Object (readonly)
健康保険
20 21 22 |
# File 'lib/tax_jp/social_insurance.rb', line 20 def health_insurance @health_insurance end |
#welfare_pension ⇒ Object (readonly)
厚生年金
22 23 24 |
# File 'lib/tax_jp/social_insurance.rb', line 22 def welfare_pension @welfare_pension end |
Class Method Details
.find_all_by_date_and_prefecture(date, prefecture) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/tax_jp/social_insurance.rb', line 67 def self.find_all_by_date_and_prefecture(date, prefecture) date = convert_to_date(date) prefecture_code = convert_to_prefecture_code(prefecture) with_database do |db| sql = 'select g.*, hi.*, wp.* from grades g ' sql << 'inner join health_insurances hi on (hi.valid_from <= ? and hi.valid_until >= ? and (hi.prefecture_code = ? or hi.prefecture_code is null)) ' sql << 'inner join welfare_pensions wp on (wp.valid_from <= ? and wp.valid_until >= ?) ' sql << 'where g.valid_from <= ? and g.valid_until >= ? ' ret = [] db.execute(sql, [date, date, prefecture_code, date, date, date, date]) do |row| ret << TaxJp::SocialInsurance.new(row) end ret end end |
.find_by_date_and_prefecture_and_salary(date, prefecture, salary) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/tax_jp/social_insurance.rb', line 85 def self.find_by_date_and_prefecture_and_salary(date, prefecture, salary) date = convert_to_date(date) prefecture_code = convert_to_prefecture_code(prefecture) salary = salary.to_i with_database do |db| sql = 'select g.*, hi.*, wp.* from grades g ' sql << 'inner join health_insurances hi on (hi.valid_from <= ? and hi.valid_until >= ? and (hi.prefecture_code = ? or hi.prefecture_code is null)) ' sql << 'inner join welfare_pensions wp on (wp.valid_from <= ? and wp.valid_until >= ?) ' sql << 'where g.valid_from <= ? and g.valid_until >= ? and g.salary_from <= ? and g.salary_to > ? ' ret = nil db.execute(sql, [date, date, prefecture_code, date, date, date, date, salary, salary]) do |row| ret = TaxJp::SocialInsurance.new(row) end ret end end |
.with_database ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/tax_jp/social_insurance.rb', line 104 def self.with_database db = SQLite3::Database.new(DB_PATH) begin yield db ensure db.close end end |
Instance Method Details
#valid_from ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/tax_jp/social_insurance.rb', line 45 def valid_from ret = grade.valid_from if health_insurance and health_insurance.valid_from > ret ret = health_insurance.valid_from end if welfare_pension and welfare_pension.valid_from > ret ret = welfare_pension.valid_from end ret end |
#valid_until ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tax_jp/social_insurance.rb', line 56 def valid_until ret = grade.valid_until if health_insurance and health_insurance.valid_until < ret ret = health_insurance.valid_until end if welfare_pension and welfare_pension.valid_until < ret ret = welfare_pension.valid_until end ret end |