SHARE
TWEET

Untitled

a guest Oct 14th, 2019 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def calculation(client)
  2.   loan_amount = client.goods_cost - client.downpayment
  3.  
  4.   insurance_amount = 0
  5.   client.insurance.sort.each do |item|
  6.     insurance_amount =
  7.     case item
  8.     when :life
  9.       if client.age < 30
  10.         loan_amount * (1.1 / 100.0) * client.term
  11.        elsif client.age < 60
  12.         loan_amount * (1.4 / 100.0) * client.term
  13.       else
  14.         loan_amount * (1.8 / 100.0) * client.term
  15.       end
  16.     when :job
  17.       case client.employment
  18.       when :own_business
  19.         loan_amount / (1 - client.term / 100.0 ) - loan_amount
  20.       when :clerk
  21.         loan_amount * 0.014
  22.       else
  23.         0.00
  24.       end
  25.     else
  26.       0.0
  27.     end
  28.  
  29.     loan_amount += insurance_amount
  30.   end
  31.  
  32.   rate = 15 / 1200.0
  33.   monthly_payment = rate * (rate + 1)**client.term / ((rate + 1)**client.term - 1) * loan_amount
  34.  
  35.   puts "Сумма займа: #{loan_amount.round(2)}"
  36.   puts "Первоначальный взнос #{client.downpayment}"
  37.   puts "Ежемесячный платеж: #{monthly_payment.round(2)}"
  38.   puts "Срок кредита: #{client.term} месяцев"
  39.   puts "Сумма выплат: #{(monthly_payment * client.term).round(2) }"
  40.   puts "Страхование: #{client.insurance}, #{insurance_amount.round(2)}"
  41. end
  42.  
  43.  
  44. require 'ostruct'
  45. person = OpenStruct.new(goods_cost: 30_000, downpayment: 3000, term: 12, age: 44, employment: :own_business,  insurance: [:life, :job])
  46. calculation(person)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top