Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calculation(client)
- loan_amount = client.goods_cost - client.downpayment
- insurance_amount = 0
- client.insurance.sort.each do |item|
- insurance_amount =
- case item
- when :life
- if client.age < 30
- loan_amount * (1.1 / 100.0) * client.term
- elsif client.age < 60
- loan_amount * (1.4 / 100.0) * client.term
- else
- loan_amount * (1.8 / 100.0) * client.term
- end
- when :job
- case client.employment
- when :own_business
- loan_amount / (1 - client.term / 100.0 ) - loan_amount
- when :clerk
- loan_amount * 0.014
- else
- 0.00
- end
- else
- 0.0
- end
- loan_amount += insurance_amount
- end
- rate = 15 / 1200.0
- monthly_payment = rate * (rate + 1)**client.term / ((rate + 1)**client.term - 1) * loan_amount
- puts "Сумма займа: #{loan_amount.round(2)}"
- puts "Первоначальный взнос #{client.downpayment}"
- puts "Ежемесячный платеж: #{monthly_payment.round(2)}"
- puts "Срок кредита: #{client.term} месяцев"
- puts "Сумма выплат: #{(monthly_payment * client.term).round(2) }"
- puts "Страхование: #{client.insurance}, #{insurance_amount.round(2)}"
- end
- require 'ostruct'
- person = OpenStruct.new(goods_cost: 30_000, downpayment: 3000, term: 12, age: 44, employment: :own_business, insurance: [:life, :job])
- calculation(person)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement