@ -315,42 +315,98 @@ class ConferencesController < ApplicationController
end
end
end
end
when :stats
when :stats
@registrations = ConferenceRegistration . where ( :conference_id = > @this_conference . id )
if request . format . xlsx?
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 "
logger . info " Generating stats.xls "
@excel_data = {
@excel_data = {
columns : [ :name , :email , :city , :date , :languages ] ,
columns : [
column_types : { date : :date } ,
: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 : {
keys : {
name : 'forms.labels.generic.name' ,
name : 'forms.labels.generic.name' ,
email : 'forms.labels.generic.email' ,
email : 'forms.labels.generic.email' ,
status : 'forms.labels.generic.registration_status' ,
city : 'forms.labels.generic.location' ,
city : 'forms.labels.generic.location' ,
date : 'articles.conference_registration.terms.Date' ,
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 |
@registrations . each do | r |
user = r . user_id ? User . where ( id : r . user_id ) . first : nil
user = r . user_id ? User . where ( id : r . user_id ) . first : nil
if user . present?
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 ] << {
@excel_data [ :data ] << {
name : user . firstname || '' ,
name : user . firstname || '' ,
email : user . email || '' ,
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 " ) : '' ,
date : r . created_at ? r . created_at . strftime ( " %F %T " ) : '' ,
city : r . city || '' ,
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
end
end
return respond_to do | format |
return respond_to do | format |
# format.html
format . xlsx { render xlsx : :stats , filename : " stats- #{ DateTime . now . strftime ( '%Y-%m-%d' ) } " }
format . xlsx { render xlsx : :stats , filename : " stats- #{ DateTime . now . strftime ( '%Y-%m-%d' ) } " }
end
end
else
else
@registrations = ConferenceRegistration . where ( :conference_id = > @this_conference . id )
@registration_count = @registrations . size
@registration_count = @registrations . size
@completed_registrations = 0
@completed_registrations = 0
@bikes = 0 #@registrations.count { |r| r.bike == 'yes' }
@bikes = 0
@donation_count = 0
@donation_count = 0
@donations = 0
@donations = 0
@food = { meat : 0 , vegan : 0 , vegetarian : 0 , all : 0 }
@food = { meat : 0 , vegan : 0 , vegetarian : 0 , all : 0 }
@ -360,10 +416,8 @@ class ConferencesController < ApplicationController
@bikes += 1 if r . bike == 'yes'
@bikes += 1 if r . bike == 'yes'
#if r.food.present?
@food [ r . food . to_sym ] += 1
@food [ r . food . to_sym ] += 1
@food [ :all ] += 1
@food [ :all ] += 1
#end
if r . registration_fees_paid . present? && r . registration_fees_paid > 0
if r . registration_fees_paid . present? && r . registration_fees_paid > 0
@donation_count += 1
@donation_count += 1