@ -315,42 +315,98 @@ class ConferencesController < ApplicationController
end
end
when :stats
@registrations = ConferenceRegistration . where ( :conference_id = > @this_conference . id )
if request . format . xlsx?
@registrations = ConferenceRegistration . where ( :conference_id = > @this_conference . id ) . sort { | a , b | ( a . user . present? ? ( a . user . firstname || '' ) : '' ) . downcase < = > ( b . user . present? ? ( b . user . firstname || '' ) : '' ) . downcase }
logger . info " Generating stats.xls "
@excel_data = {
columns : [ :name , :email , :city , :date , :languages ] ,
column_types : { date : :date } ,
columns : [
:name ,
:email ,
:status ,
:registration_fees_paid ,
:date ,
:city ,
:preferred_language ,
:languages ,
:arrival ,
:departure ,
:housing ,
:bike ,
:food ,
:companion ,
:allergies
] ,
column_types : {
name : :bold ,
date : :date ,
arrival : [ :date , :day ] ,
departure : [ :date , :day ] ,
registration_fees_paid : :money
} ,
keys : {
name : 'forms.labels.generic.name' ,
email : 'forms.labels.generic.email' ,
status : 'forms.labels.generic.registration_status' ,
city : 'forms.labels.generic.location' ,
date : 'articles.conference_registration.terms.Date' ,
languages : 'articles.conference_registration.terms.Languages'
languages : 'articles.conference_registration.terms.Languages' ,
preferred_language : 'articles.conference_registration.terms.Preferred_Languages' ,
arrival : 'forms.labels.generic.arrival' ,
departure : 'forms.labels.generic.departure' ,
housing : 'forms.labels.generic.housing' ,
bike : 'forms.labels.generic.bike' ,
food : 'forms.labels.generic.food' ,
companion : 'articles.conference_registration.terms.companion' ,
allergies : 'forms.labels.generic.allergies' ,
registration_fees_paid : 'articles.conference_registration.headings.fees_paid'
} ,
data : [ ] ,
data : [ ]
}
#@registrations.sort_by! { |a, b| a.title.downcase <=> b.title.downcase }
@registrations . each do | r |
user = r . user_id ? User . where ( id : r . user_id ) . first : nil
if user . present?
companion = ''
if r . housing_data . present? && r . housing_data [ 'companions' ] . present?
companion_user = User . find_by_email ( r . housing_data [ 'companions' ] . first )
companion = view_context . _ 'articles.conference_registration.terms.registration_status.unregistered'
if companion_user . present?
cr = ConferenceRegistration . where ( user_id : companion_user . id ) . order ( created_at : :desc ) . limit ( 1 ) . first
if cr . present? && ( ( cr . steps_completed || [ ] ) . include? 'questions' )
companion = companion_user . named_email
end
end
end
steps = r . steps_completed || [ ]
@excel_data [ :data ] << {
name : user . firstname || '' ,
email : user . email || '' ,
status : ( view_context . _ " articles.conference_registration.terms.registration_status. #{ ( steps . include? 'questions' ) ? 'registered' : ( ( steps . include? 'contact_info' ) ? 'preregistered' : 'unregistered' ) } " ) ,
date : r . created_at ? r . created_at . strftime ( " %F %T " ) : '' ,
city : r . city || '' ,
languages : ( ( r . languages || [ ] ) . map { | x | view_context . language x } ) . join ( ', ' ) . to_s
preferred_language : user . locale . present? ? ( view_context . language user . locale ) : '' ,
languages : ( ( r . languages || [ ] ) . map { | x | view_context . language x } ) . join ( ', ' ) . to_s ,
arrival : r . arrival ? r . arrival . strftime ( " %F %T " ) : '' ,
departure : r . departure ? r . departure . strftime ( " %F %T " ) : '' ,
housing : r . housing || '' ,
bike : r . bike . present? ? ( view_context . _ " articles.conference_registration.questions.bike. #{ r . bike } " ) : '' ,
food : r . food . present? ? ( view_context . _ " articles.conference_registration.questions.food. #{ r . food } " ) : '' ,
companion : companion ,
allergies : r . allergies ,
registration_fees_paid : r . registration_fees_paid
}
end
end
return respond_to do | format |
# format.html
format . xlsx { render xlsx : :stats , filename : " stats- #{ DateTime . now . strftime ( '%Y-%m-%d' ) } " }
end
else
@registrations = ConferenceRegistration . where ( :conference_id = > @this_conference . id )
@registration_count = @registrations . size
@completed_registrations = 0
@bikes = 0 #@registrations.count { |r| r.bike == 'yes' }
@bikes = 0
@donation_count = 0
@donations = 0
@food = { meat : 0 , vegan : 0 , vegetarian : 0 , all : 0 }
@ -360,10 +416,8 @@ class ConferencesController < ApplicationController
@bikes += 1 if r . bike == 'yes'
#if r.food.present?
@food [ r . food . to_sym ] += 1
@food [ :all ] += 1
#end
if r . registration_fees_paid . present? && r . registration_fees_paid > 0
@donation_count += 1