Created
December 2, 2015 11:17
-
-
Save anonymous/a255f0aa405ede6c1282 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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