mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-03-21 12:29:03 +01:00
migrate export subscriptions to axlsx
This commit is contained in:
parent
85912603a2
commit
827b3334e1
@ -91,11 +91,9 @@ class API::MembersController < API::ApiController
|
||||
# export subscriptions
|
||||
def export_subscriptions
|
||||
authorize :export
|
||||
@datas = Subscription.includes(:plan, :user).all
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xls
|
||||
end
|
||||
@subscriptions = Subscription.includes(:plan, :user).all
|
||||
|
||||
render xlsx: 'export_subscriptions.xlsx', filename: "export_subscriptions.xlsx"
|
||||
end
|
||||
|
||||
# export reservations
|
||||
|
@ -1,26 +0,0 @@
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th><%=t('export_subscriptions.id')%></th>
|
||||
<th><%=t('export_subscriptions.customer')%></th>
|
||||
<th><%=t('export_subscriptions.email')%></th>
|
||||
<th><%=t('export_subscriptions.subscription')%></th>
|
||||
<th><%=t('export_subscriptions.period')%></th>
|
||||
<th><%=t('export_subscriptions.start_date')%></th>
|
||||
<th><%=t('export_subscriptions.expiration_date')%></th>
|
||||
<th><%=t('export_subscriptions.amount')%></th>
|
||||
<th><%=t('export_subscriptions.payment_method')%></th>
|
||||
</tr>
|
||||
<% @datas.each do |data| %>
|
||||
<tr>
|
||||
<td><%= data.user.id %></td>
|
||||
<td><%= data.user.profile.full_name %></td>
|
||||
<td><%= data.user.email %></td>
|
||||
<td><%= data.plan.human_readable_name(group: true) %></td>
|
||||
<td><%= t("duration.#{data.plan.interval}", count: data.plan.interval_count) %></td>
|
||||
<td><%= data.created_at %></td>
|
||||
<td><%= data.expired_at %></td>
|
||||
<td><%= number_to_currency(data.plan.amount / 100) %></td>
|
||||
<td><%= (data.stp_subscription_id.nil?)? t('export_subscriptions.local_payment') : t('export_subscriptions.online_payment') %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
33
app/views/api/members/export_subscriptions.xlsx.axlsx
Normal file
33
app/views/api/members/export_subscriptions.xlsx.axlsx
Normal file
@ -0,0 +1,33 @@
|
||||
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_subscriptions.subscriptions')) do |sheet|
|
||||
|
||||
## data table
|
||||
# heading labels
|
||||
columns = [t('export_subscriptions.id'), t('export_subscriptions.customer'), t('export_subscriptions.email'),
|
||||
t('export_subscriptions.subscription'), t('export_subscriptions.period'), t('export_subscriptions.start_date'),
|
||||
t('export_subscriptions.expiration_date'), t('export_subscriptions.amount'), t('export_subscriptions.payment_method')]
|
||||
sheet.add_row columns, :style => header
|
||||
|
||||
# data rows
|
||||
@subscriptions.each do |sub|
|
||||
data = [
|
||||
sub.user.id,
|
||||
sub.user.profile.full_name,
|
||||
sub.user.email,
|
||||
sub.plan.human_readable_name(group: true),
|
||||
t("duration.#{sub.plan.interval}", count: sub.plan.interval_count),
|
||||
sub.created_at.to_date,
|
||||
sub.expired_at.to_date,
|
||||
number_to_currency(sub.plan.amount / 100),
|
||||
(sub.stp_subscription_id.nil?)? t('export_subscriptions.local_payment') : t('export_subscriptions.online_payment')
|
||||
]
|
||||
styles = [nil, nil, nil, nil, nil, date, date, nil, nil]
|
||||
types = [:integer, :string, :string, :string, :string, :date, :date, :string, :string]
|
||||
|
||||
sheet.add_row data, :style => styles, :types => types
|
||||
end
|
||||
end
|
@ -145,6 +145,7 @@ en:
|
||||
|
||||
export_subscriptions:
|
||||
# subscriptions list export to EXCEL format
|
||||
subscriptions: "Subscriptions"
|
||||
id: "ID"
|
||||
customer: "Customer"
|
||||
email: "E-mail"
|
||||
|
@ -145,6 +145,7 @@ fr:
|
||||
|
||||
export_subscriptions:
|
||||
# export de la liste des abonnements au format EXCEL
|
||||
subscriptions: "Abonnements"
|
||||
id: "ID"
|
||||
customer: "Client"
|
||||
email: "Courriel"
|
||||
|
Loading…
x
Reference in New Issue
Block a user