# -*- encoding : utf-8 -*-
class SheetYear < ActiveRecord::Base
  belongs_to :sheet
  
  validates_presence_of :year
  
  JOIN_TYPE = {1 => "Individuel", 2 => "Familial", 3 =>"Association"}
  PAYMENT_TYPE = {1 => "Chèque", 2 => "Liquide"}
  
  
	def after_save
		sy = self.sheet.sheet_years.find(:first, :order => "year DESC")
		if sy
			self.sheet.last_year = sy.year
			self.sheet.first_year = self.sheet.sheet_years.find(:first, :order => "year ASC").year
			self.sheet.save


  
		end



	end


	def after_destroy
		sy = self.sheet.sheet_years.find(:first, :order => "year DESC")
	    if sy
			self.sheet.last_year = sy.year
			self.sheet.first_year = self.sheet.sheet_years.find(:first, :order => "year ASC").year
			self.sheet.save



	    end
		
	end


end
