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:
parent
d72e39f716
commit
85912603a2
@ -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
|
||||
|
@ -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>
|
32
app/views/api/members/export_reservations.xlsx.axlsx
Normal file
32
app/views/api/members/export_reservations.xlsx.axlsx
Normal 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
|
@ -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"
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user