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_pension_grade(date, prefecture, pension_grade) ⇒ Object
- .find_by_date_and_prefecture_and_salary(date, prefecture, salary) ⇒ Object
- .find_health_insurance_by_date_and_prefecture_and_salary(date, prefecture, salary) ⇒ Object
- .find_max_pension_grade_by_date(date) ⇒ Object
- .find_welfare_pension_by_date_and_salary(date, salary) ⇒ 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
Constructor Details
#initialize(row) ⇒ SocialInsurance
Returns a new instance of SocialInsurance.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tax_jp/social_insurance.rb', line 22 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)
等級
16 17 18 |
# File 'lib/tax_jp/social_insurance.rb', line 16 def grade @grade end |
#health_insurance ⇒ Object (readonly)
健康保険
18 19 20 |
# File 'lib/tax_jp/social_insurance.rb', line 18 def health_insurance @health_insurance end |
#welfare_pension ⇒ Object (readonly)
厚生年金
20 21 22 |
# File 'lib/tax_jp/social_insurance.rb', line 20 def welfare_pension @welfare_pension end |
Class Method Details
.find_all_by_date_and_prefecture(date, prefecture) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/tax_jp/social_insurance.rb', line 65 def self.find_all_by_date_and_prefecture(date, prefecture) date = TaxJp::Utils.convert_to_date(date) prefecture_code = convert_to_prefecture_code(prefecture) TaxJp::Utils.with_database(DB_PATH) do |db| sql, params = base_query(date, prefecture_code) sql << 'where g.valid_from <= ? and g.valid_until >= ? ' params += [date, date] ret = [] db.execute(sql, params) do |row| ret << TaxJp::SocialInsurance.new(row) end ret end end |
.find_by_date_and_prefecture_and_pension_grade(date, prefecture, pension_grade) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/tax_jp/social_insurance.rb', line 105 def self.find_by_date_and_prefecture_and_pension_grade(date, prefecture, pension_grade) date = TaxJp::Utils.convert_to_date(date) prefecture_code = convert_to_prefecture_code(prefecture) TaxJp::Utils.with_database(DB_PATH) do |db| sql, params = base_query(date, prefecture_code) sql << 'where g.valid_from <= ? and g.valid_until >= ? and g.pension_grade = ? ' params += [date, date, pension_grade] ret = nil db.execute(sql, params) do |row| ret = TaxJp::SocialInsurance.new(row) end ret end end |
.find_by_date_and_prefecture_and_salary(date, prefecture, salary) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/tax_jp/social_insurance.rb', line 83 def self.find_by_date_and_prefecture_and_salary(date, prefecture, salary) date = TaxJp::Utils.convert_to_date(date) prefecture_code = convert_to_prefecture_code(prefecture) salary = salary.to_i TaxJp::Utils.with_database(DB_PATH) do |db| sql, params = base_query(date, prefecture_code) sql << 'where g.valid_from <= ? and g.valid_until >= ? and g.salary_from <= ? and g.salary_to > ? ' params += [date, date, salary, salary] row = db.execute(sql, params).first ret = TaxJp::SocialInsurance.new(row) if ret.welfare_pension.grade.pension_grade == TaxJp::INTEGER_MAX ret.welfare_pension.grade = find_max_pension_grade_by_date(date) end ret end end |
.find_health_insurance_by_date_and_prefecture_and_salary(date, prefecture, salary) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/tax_jp/social_insurance.rb', line 123 def self.find_health_insurance_by_date_and_prefecture_and_salary(date, prefecture, salary) date = TaxJp::Utils.convert_to_date(date) prefecture_code = convert_to_prefecture_code(prefecture) TaxJp::Utils.with_database(DB_PATH) do |db| sql = 'select * from health_insurances ' sql << 'where valid_from <= ? and valid_until >= ? and (prefecture_code = ? or prefecture_code is null) ' params = [date, date, prefecture_code] ret = nil db.execute(sql, params) do |row| ret = TaxJp::SocialInsurances::HealthInsurance.new(row) ret.salary = salary end ret end end |
.find_max_pension_grade_by_date(date) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/tax_jp/social_insurance.rb', line 141 def self.find_max_pension_grade_by_date(date) date = TaxJp::Utils.convert_to_date(date) TaxJp::Utils.with_database(DB_PATH, results_as_hash: true) do |db| sql = 'select * from grades ' sql << 'where valid_from <= ? and valid_until >= ? and pension_grade = ( ' sql << ' select max(pension_grade) from grades ' sql << ' where valid_from <= ? and valid_until >= ? and pension_grade < ? ' sql << ') ' params = [date, date, date, date, TaxJp::INTEGER_MAX] row = db.execute(sql, params).first.with_indifferent_access TaxJp::SocialInsurances::Grade.new(row) end end |
.find_welfare_pension_by_date_and_salary(date, salary) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/tax_jp/social_insurance.rb', line 157 def self.find_welfare_pension_by_date_and_salary(date, salary) date = TaxJp::Utils.convert_to_date(date) TaxJp::Utils.with_database(DB_PATH) do |db| sql = 'select * from welfare_pensions ' sql << 'where valid_from <= ? and valid_until >= ? ' params = [date, date] ret = nil db.execute(sql, params) do |row| ret = TaxJp::SocialInsurances::WelfarePension.new(row) ret.salary = salary end ret end end |
Instance Method Details
#valid_from ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tax_jp/social_insurance.rb', line 43 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
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tax_jp/social_insurance.rb', line 54 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 |