Question

I'm doing reccuring deposit calculations, When open reccuring deposit account on that time itself i have set opening date as today's date using before_save. I dono how to calculate account maturity date. Because, in my reccuring deposit i have many fields in my dropdown like 6months, 1year, 2years ... upto 5 years. According to that openedon date i have to close that account or renew it on that maturity date itself.

i have use the below code for openedon date

  before_save :set_openedon   

  def set_openedon
    self.openedon = Date.today
  end  

for example:

  1. for first rd account openedon date is 13/05/2013 and maturity date must be 13/05/2014 for one year.

  2. for second rd account openedon date is 15/09/2012 and maturity date must be 15/09/2014 for two years.

like that i have to calculate maturity date for all the accounts. But i dono how to do. Kindly help me.

-Thanks in advance.

Was it helpful?

Solution 2

Something alike:

def calculate_dates
    self.openedon = Date.today
    case self.noy
    when '1'
      self.md = self.openedon+1.year
    when '2'
      self.md = self.openedon+2.years
    when '3'
      self.md = self.openedon+3.years
    when '4'
      self.md = self.openedon+4.years
    when '5'
      self.md = self.openedon+5.years
    else
      self.md = self.openedon+6.months
    end
end

OTHER TIPS

Rails has quite easy-to-use date operators:

Date.parse('13/05/2013') + 1.year
# => Tue, 13 May 2014
Date.parse('15/09/2012') + 2.years
# => Mon, 15 Sep 2014 

Same for 6.months, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top