From 85912603a2fa66919bb82d56545e0b04c71a9e7e Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 12 Jul 2016 13:00:56 +0200 Subject: [PATCH] migrate export reservations to axlsx --- app/controllers/api/members_controller.rb | 8 ++--- .../api/members/export_reservations.xls.erb | 24 -------------- .../members/export_reservations.xlsx.axlsx | 32 +++++++++++++++++++ config/locales/en.yml | 1 + config/locales/fr.yml | 1 + 5 files changed, 37 insertions(+), 29 deletions(-) delete mode 100644 app/views/api/members/export_reservations.xls.erb create mode 100644 app/views/api/members/export_reservations.xlsx.axlsx diff --git a/app/controllers/api/members_controller.rb b/app/controllers/api/members_controller.rb index d0c41acf5..bfa8b6613 100644 --- a/app/controllers/api/members_controller.rb +++ b/app/controllers/api/members_controller.rb @@ -101,11 +101,9 @@ class API::MembersController < API::ApiController # export reservations def export_reservations authorize :export - @datas = Reservation.includes(:user, :slots).all - respond_to do |format| - format.html - format.xls - end + @reservations = Reservation.includes(:user, :slots).all + + render xlsx: 'export_reservations.xlsx', filename: "export_reservations.xlsx" end def export_members diff --git a/app/views/api/members/export_reservations.xls.erb b/app/views/api/members/export_reservations.xls.erb deleted file mode 100644 index 7b117c592..000000000 --- a/app/views/api/members/export_reservations.xls.erb +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - <% @datas.each do |d| %> - - - - - - - - - - - <% end %> -
<%=t('export_reservations.customer_id')%><%=t('export_reservations.customer')%><%=t('export_reservations.email')%><%=t('export_reservations.reservation_date')%><%=t('export_reservations.reservation_type')%><%=t('export_reservations.reservation_object')%><%=t('export_reservations.slots_number_hours_tickets')%>
<%= d.user.id %><%= d.user.profile.full_name %><%= d.user.email %><%= d.created_at %><%= d.reservable_type %><%= d.reservable.name if !d.reservable.nil? %><%= d.slots.count %><%= (d.stp_invoice_id.nil?)? t('export_reservations.local_payment') : t('export_reservations.online_payment') %>
\ No newline at end of file diff --git a/app/views/api/members/export_reservations.xlsx.axlsx b/app/views/api/members/export_reservations.xlsx.axlsx new file mode 100644 index 000000000..54bbb0e90 --- /dev/null +++ b/app/views/api/members/export_reservations.xlsx.axlsx @@ -0,0 +1,32 @@ +wb = xlsx_package.workbook + +header = wb.styles.add_style :b => true, :bg_color => Stylesheet.primary.upcase.gsub('#', 'FF'), :fg_color => 'FFFFFFFF' +date = wb.styles.add_style :format_code => Rails.application.secrets.excel_date_format + +wb.add_worksheet(name: t('export_reservations.reservations')) do |sheet| + + ## data table + # heading labels + columns = [t('export_reservations.customer_id'), t('export_reservations.customer'), t('export_reservations.email'), + t('export_reservations.reservation_date'), t('export_reservations.reservation_type'), t('export_reservations.reservation_object'), + t('export_reservations.slots_number_hours_tickets'), t('export_reservations.payment_method')] + sheet.add_row columns, :style => header + + # data rows + @reservations.each do |resrv| + data = [ + resrv.user.id, + resrv.user.profile.full_name, + resrv.user.email, + resrv.created_at.to_date, + resrv.reservable_type, + (resrv.reservable.nil? ? '' : resrv.reservable.name), + resrv.slots.count, + (resrv.stp_invoice_id.nil?)? t('export_reservations.local_payment') : t('export_reservations.online_payment') + ] + styles = [nil, nil, nil, date, nil, nil, nil, nil] + types = [:integer, :string, :string, :date, :string, :string, :integer, :string] + + sheet.add_row data, :style => styles, :types => types + end +end \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 3f7fba470..f44221f4e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -131,6 +131,7 @@ en: export_reservations: # machines/trainings/events reservations list to EXCEL format + reservations: "Reservations" customer_id: "Customer ID" customer: "Customer" email: "E-mail" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 2e31325c2..c4b6d3f18 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -131,6 +131,7 @@ fr: export_reservations: # export de la liste des réservations machines/formations/évènements au format EXCEL + reservations: "Réservations" customer_id: "ID client" customer: "Client" email: "Courriel"