app/models/user.rb
# Enrollments report shows all enrollments for the current school year
# :school_year => filter by year
# :fulfilled => true/false to show / not show fulfilled enrollments
Enrollments report shows all enrollments for the current school year
:school_year => filter by year
:fulfilled => true/false to show / not show fulfilled enrollments
Enrollments report shows all enrollments for the current school year : school_year = > filter by year : fulfilled = > true / false to show / not show fulfilled enrollments
def enrollments_report(options = {})
	  q = []
	  params = []
	  q << "SELECT contracts.name AS contract_name, CONCAT(facilitator.last_name, ', ', facilitator.first_name) AS facilitator_name, terms.name AS term_name, terms.school_year AS term_school_year, terms.credit_date AS term_credit_date, contracts.term_id, COALESCE(GROUP_CONCAT(CONCAT(credits.course_name,' / ',credit_assignments.credit_hours) ORDER BY credits.course_name SEPARATOR '; '),'None assigned') AS credit_string, contracts.timeslots, enrollments.*, assignments.assignments_count FROM enrollments"
    q << "INNER JOIN contracts ON enrollments.contract_id = contracts.id"
    q << "INNER JOIN categories ON contracts.category_id = categories.id"
    q << "INNER JOIN terms ON contracts.term_id = terms.id"
    if options[:school_year]
      q << "AND terms.school_year = ?"
      params << options[:school_year]
    end
    q << "INNER JOIN users AS facilitator ON contracts.facilitator_id = facilitator.id"
    q << "LEFT JOIN (SELECT COUNT(id) AS assignments_count, contract_id FROM assignments WHERE active = true GROUP BY contract_id) AS assignments ON assignments.contract_id = contracts.id"
    q << "LEFT JOIN credit_assignments ON credit_assignments.enrollment_id = enrollments.id"
    q << "LEFT JOIN credits ON credit_assignments.credit_id = credits.id"
    q << "WHERE enrollments.participant_id = #{self.id}"
    case options[:fulfilled]
    when true
      q << "AND enrollments.completion_status = #{Enrollment::COMPLETION_FULFILLED}" 
    when false
      q << "AND enrollments.completion_status != #{Enrollment::COMPLETION_FULFILLED}" 
    end
    case options[:canceled]
    when true
      q << "AND enrollments.completion_status = #{Enrollment::COMPLETION_CANCELED}" 
    when false
      q << "AND enrollments.completion_status != #{Enrollment::COMPLETION_CANCELED}" 
    end
    q << "GROUP BY enrollments.id"
    q << "ORDER BY enrollments.completion_status, term_credit_date DESC, term_name, contract_name"
    enrollments = Enrollment.find_by_sql([q.join(' ')]+params)
    enrollments.each do |e|
      e.timeslots = ClassPeriod.timeslot_strings(YAML::load(e[:timeslots]))
    end
    enrollments
	end
def enrollments_report ( options = { } ) q = [ ] params = [ ] q << "SELECT contracts.name AS contract_name, CONCAT(facilitator.last_name, ', ', facilitator.first_name) AS facilitator_name, terms.name AS term_name, terms.school_year AS term_school_year, terms.credit_date AS term_credit_date, contracts.term_id, COALESCE(GROUP_CONCAT(CONCAT(credits.course_name,' / ',credit_assignments.credit_hours) ORDER BY credits.course_name SEPARATOR '; '),'None assigned') AS credit_string, contracts.timeslots, enrollments.*, assignments.assignments_count FROM enrollments" q << "INNER JOIN contracts ON enrollments.contract_id = contracts.id" q << "INNER JOIN categories ON contracts.category_id = categories.id" q << "INNER JOIN terms ON contracts.term_id = terms.id" if options [ :school_year ] q << "AND terms.school_year = ?" params << options [ :school_year ] end q << "INNER JOIN users AS facilitator ON contracts.facilitator_id = facilitator.id" q << "LEFT JOIN (SELECT COUNT(id) AS assignments_count, contract_id FROM assignments WHERE active = true GROUP BY contract_id) AS assignments ON assignments.contract_id = contracts.id" q << "LEFT JOIN credit_assignments ON credit_assignments.enrollment_id = enrollments.id" q << "LEFT JOIN credits ON credit_assignments.credit_id = credits.id" q << "WHERE enrollments.participant_id = #{self.id}" case options [ :fulfilled ] when true q << "AND enrollments.completion_status = #{Enrollment::COMPLETION_FULFILLED}" when false q << "AND enrollments.completion_status != #{Enrollment::COMPLETION_FULFILLED}" end case options [ :canceled ] when true q << "AND enrollments.completion_status = #{Enrollment::COMPLETION_CANCELED}" when false q << "AND enrollments.completion_status != #{Enrollment::COMPLETION_CANCELED}" end q << "GROUP BY enrollments.id" q << "ORDER BY enrollments.completion_status, term_credit_date DESC, term_name, contract_name" enrollments = Enrollment . find_by_sql ( [ q . join ( ' ' ) ] + params ) enrollments . each do | e | e . timeslots = ClassPeriod . timeslot_strings ( YAML :: load ( e [ :timeslots ] ) ) end enrollments end
Enrollments report shows all enrollments for the current school year
:school_year => filter by year
:fulfilled => true/false to show / not show fulfilled enrollments
Enrollments report shows all enrollments for the current school year : school_year = > filter by year : fulfilled = > true / false to show / not show fulfilled enrollments
options
<not_specific>