From 8ffb852b4d647561614ed42dde7351c1b62b5d4e Mon Sep 17 00:00:00 2001 From: Godwin Date: Tue, 9 Aug 2016 22:03:11 -0700 Subject: [PATCH] Added data to excel sheet --- app/controllers/conferences_controller.rb | 76 +++++++++++++++++++---- app/views/conferences/stats.xlsx.haml | 9 +-- config/locales/en.yml | 10 ++- 3 files changed, 79 insertions(+), 16 deletions(-) diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index e118b94..274a2fe 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -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 diff --git a/app/views/conferences/stats.xlsx.haml b/app/views/conferences/stats.xlsx.haml index a92ca09..50faf10 100644 --- a/app/views/conferences/stats.xlsx.haml +++ b/app/views/conferences/stats.xlsx.haml @@ -8,13 +8,14 @@ - @excel_data[:data].each do |row| %tr - @excel_data[:columns].each do |column| - %td{class: (@excel_data[:column_types].present? && @excel_data[:column_types][column].present?) ? @excel_data[:column_types][column].to_s : nil} - - if row[column].present? - =_!row[column] + %td{class: (@excel_data[:column_types].present? && @excel_data[:column_types][column].present?) ? @excel_data[:column_types][column] : nil}=(row[column].present? ? (_!row[column]) : '') - format_xls 'table' do - workbook use_autowidth: true - format bg_color: '333333' - format 'td', font_name: 'Calibri', bg_color: 'ffffff', fg_color: '333333' - format 'th', font_name: 'Calibri', b: true, bg_color: '333333', fg_color: 'ffffff' - - format 'td.date', num_fmt: 22, font_name: 'Courier New', sz: 10 + - format 'td.date', num_fmt: 22, font_name: 'Courier New', sz: 10, bg_color: 'ffffff', fg_color: '333333' + - format 'td.date.day', num_fmt: 14, font_name: 'Courier New', sz: 10, bg_color: 'ffffff', fg_color: '333333' + - format 'td.money', num_fmt: 2, font_name: 'Courier New', sz: 10, bg_color: 'ffffff', fg_color: '333333' + - format 'td.bold', font_name: 'Calibri', bg_color: 'ffffff', fg_color: '333333', b: true diff --git a/config/locales/en.yml b/config/locales/en.yml index aee50ad..8e75660 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1061,6 +1061,11 @@ en: Total_Donations: Total Donations Total_Registrations: Total Registrations Date: Registration Date + registration_status: + unregistered: Unregistered + preregistered: Preregistered + registered: Registered + companion: Companion about_bikebike: paragraphs: bicycle_project_paragraph: 'From collectives that use the bicycle as an excuse to change society, economy and the environment. Non-profit groups that have a community bike shops, cooperatives and other projects that promote the use of the bicycle and that come together to turn their communities into a place where riding is easier, more inclusive, safer and more fun. The list below uses the criteria found in the old Bicycle Organization Organization Project for what constitutes a community bike shop. The bike project need not meet all these criteria. Rather, it is a general list of qualities which are common among many bicycle projects.' @@ -1207,7 +1212,10 @@ en: subregion: State / Province country: Country postal_code: Postal Code - status: Status + status: Status, + bike: Bike + food: Food + housing: Housing actions: generic: login: Sign In