Skip to content

Instantly share code, notes, and snippets.

Created December 2, 2015 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a255f0aa405ede6c1282 to your computer and use it in GitHub Desktop.
Save anonymous/a255f0aa405ede6c1282 to your computer and use it in GitHub Desktop.
class RTMYearPlan < VeplasRTM
self.table_name = "mm_year_plan_months"
self.primary_key = "mm_year_plan_month_id"
alias_attribute :month_nr, :mm_year_plan_month_index_id
belongs_to :year, :class_name => "RTMYearName", :foreign_key => "mm_year_plan_id"
belongs_to :month, :class_name => "RTMMonthName", :foreign_key => "mm_year_plan_month_index_id"
has_many :product_plans, :class_name => "RTMProductPlan", :foreign_key => "mm_year_plan_month_id"
class << self
def find_by_year_and_month(year, month) # find_by_year_and_month("2015", 3)
if found_year = RTMYearName.find_by( year: 2015 )
#~ find_by mm_year_plan_id: found_year.id, month_nr: month.to_i
print found_year.id
end
end
def calculate_for year="2015", month=1
if plan = find_by_year_and_month(year, month)
plan.product_plans.sum(:sell_price_value)
end
end
def calculate_year year="2015"
calculations = {}
(0..11).each do |month_nr|
month_name = Util.abbr_months[month_nr]
calculations[ month_name ] = calculate_for(year, month_nr + 1)
end
calculations
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment