1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00

migrate export reservations to axlsx

This commit is contained in:
Sylvain 2016-07-12 13:00:56 +02:00
parent d72e39f716
commit 85912603a2
5 changed files with 37 additions and 29 deletions

View File

@ -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

View File

@ -1,24 +0,0 @@
<table border="1">
<tr>
<th><%=t('export_reservations.customer_id')%></th>
<th><%=t('export_reservations.customer')%></th>
<th><%=t('export_reservations.email')%></th>
<th><%=t('export_reservations.reservation_date')%></th>
<th><%=t('export_reservations.reservation_type')%></th>
<th><%=t('export_reservations.reservation_object')%></th>
<th><%=t('export_reservations.slots_number_hours_tickets')%></th>
</tr>
<% @datas.each do |d| %>
<tr>
<td><%= d.user.id %></td>
<td><%= d.user.profile.full_name %></td>
<td><%= d.user.email %></td>
<td><%= d.created_at %></td>
<td><%= d.reservable_type %></td>
<td><%= d.reservable.name if !d.reservable.nil? %></td>
<td><%= d.slots.count %></td>
<td><%= (d.stp_invoice_id.nil?)? t('export_reservations.local_payment') : t('export_reservations.online_payment') %></td>
</tr>
<% end %>
</table>

View File

@ -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

View File

@ -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"

View File

@ -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"