mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
migrate export members to axlsx
This commit is contained in:
parent
d84238b331
commit
d72e39f716
@ -110,11 +110,9 @@ class API::MembersController < API::ApiController
|
||||
|
||||
def export_members
|
||||
authorize :export
|
||||
@datas = User.with_role(:member).includes(:group, :subscriptions, :profile)
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xls
|
||||
end
|
||||
@members = User.with_role(:member).includes(:group, :subscriptions, :profile)
|
||||
|
||||
render xlsx: 'export_members.xlsx', filename: "export_members.xlsx"
|
||||
end
|
||||
|
||||
def merge
|
||||
|
@ -1,30 +0,0 @@
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th><%=t('export_members.id')%></th>
|
||||
<th><%=t('export_members.surname')%></th>
|
||||
<th><%=t('export_members.first_name')%></th>
|
||||
<th><%=t('export_members.email')%></th>
|
||||
<th><%=t('export_members.gender')%></th>
|
||||
<th><%=t('export_members.age')%></th>
|
||||
<th><%=t('export_members.phone')%></th>
|
||||
<th><%=t('export_members.group')%></th>
|
||||
<th><%=t('export_members.subscription')%></th>
|
||||
<th><%=t('export_members.subscription_end_date')%></th>
|
||||
<th><%=t('export_members.validated_trainings')%></th>
|
||||
</tr>
|
||||
<% @datas.each do |data| %>
|
||||
<tr>
|
||||
<td><%= data.id %></td>
|
||||
<td><%= data.profile.last_name %></td>
|
||||
<td><%= data.profile.first_name %></td>
|
||||
<td><%= data.email %></td>
|
||||
<td><%= data.profile.gender ? t('export_members.man') : t('export_members.woman') %></td>
|
||||
<td><%= data.profile.age %></td>
|
||||
<td><%= data.profile.phone %></td>
|
||||
<td><%= data.group.name %></td>
|
||||
<td><%= (data.subscription and data.subscription.expired_at > Time.now) ? data.subscription.plan.name : t('export_members.without_subscriptions') %></td>
|
||||
<td><%= (data.subscription and data.subscription.expired_at > Time.now) ? data.subscription.expired_at : '' %></td>
|
||||
<td><%= raw data.trainings.map(&:name).join(' ') %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
35
app/views/api/members/export_members.xlsx.axlsx
Normal file
35
app/views/api/members/export_members.xlsx.axlsx
Normal file
@ -0,0 +1,35 @@
|
||||
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_members.members')) do |sheet|
|
||||
|
||||
## data table
|
||||
# heading labels
|
||||
columns = [t('export_members.id'), t('export_members.surname'), t('export_members.first_name'), t('export_members.email'),
|
||||
t('export_members.gender'), t('export_members.age'), t('export_members.phone'), t('export_members.group'),
|
||||
t('export_members.subscription'), t('export_members.subscription_end_date'), t('export_members.validated_trainings')]
|
||||
sheet.add_row columns, :style => header
|
||||
|
||||
# data rows
|
||||
@members.each do |member|
|
||||
data = [
|
||||
member.id,
|
||||
member.profile.last_name,
|
||||
member.profile.first_name,
|
||||
member.email,
|
||||
member.profile.gender ? t('export_members.man') : t('export_members.woman'),
|
||||
member.profile.age,
|
||||
member.profile.phone,
|
||||
member.group.name,
|
||||
(member.subscription and member.subscription.expired_at > Time.now) ? member.subscription.plan.name : t('export_members.without_subscriptions'),
|
||||
(member.subscription and member.subscription.expired_at > Time.now) ? member.subscription.expired_at.to_date : nil,
|
||||
member.trainings.map(&:name).join("\n")
|
||||
]
|
||||
styles = [nil, nil, nil, nil, nil, nil, nil, nil, nil, date, nil]
|
||||
types = [:integer, :string, :string, :string, :string, :integer, :string, :string, :string, :date, :string]
|
||||
|
||||
sheet.add_row data, :style => styles, :types => types
|
||||
end
|
||||
end
|
@ -113,6 +113,7 @@ en:
|
||||
|
||||
export_members:
|
||||
# members list export to EXCEL format
|
||||
members: "Members"
|
||||
id: "ID"
|
||||
surname: "Surname"
|
||||
first_name: "First name"
|
||||
|
@ -113,6 +113,7 @@ fr:
|
||||
|
||||
export_members:
|
||||
# export de la liste des members au format EXCEL
|
||||
members: "Membres"
|
||||
id: "ID"
|
||||
surname: "Nom"
|
||||
first_name: "Prénom"
|
||||
|
Loading…
x
Reference in New Issue
Block a user