mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Add csv export to activities #2691
This commit is contained in:
parent
af40038160
commit
f7556f48c8
4 changed files with 25 additions and 4 deletions
|
@ -6,12 +6,18 @@ class Registrar::AccountActivitiesController < RegistrarController
|
||||||
account = current_user.registrar.cash_account
|
account = current_user.registrar.cash_account
|
||||||
|
|
||||||
ca_cache = params[:q][:created_at_lteq]
|
ca_cache = params[:q][:created_at_lteq]
|
||||||
end_time = params[:q][:created_at_lteq].try(:to_date)
|
begin
|
||||||
params[:q][:created_at_lteq] = end_time.try(:end_of_day)
|
end_time = params[:q][:created_at_lteq].try(:to_date)
|
||||||
|
params[:q][:created_at_lteq] = end_time.try(:end_of_day)
|
||||||
|
rescue; end
|
||||||
|
|
||||||
@q = account.activities.includes(:invoice).search(params[:q])
|
@q = account.activities.includes(:invoice).search(params[:q])
|
||||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||||
@account_activities = @q.result.page(params[:page])
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { @account_activities = @q.result.page(params[:page]) }
|
||||||
|
format.csv { send_data @q.result.to_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" }
|
||||||
|
end
|
||||||
|
|
||||||
params[:q][:created_at_lteq] = ca_cache
|
params[:q][:created_at_lteq] = ca_cache
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,18 @@ class AccountActivity < ActiveRecord::Base
|
||||||
def types_for_select
|
def types_for_select
|
||||||
[CREATE, RENEW, ADD_CREDIT].map { |x| [I18n.t(x), x] }
|
[CREATE, RENEW, ADD_CREDIT].map { |x| [I18n.t(x), x] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_csv
|
||||||
|
attributes = %w(description activity_type created_at sum)
|
||||||
|
|
||||||
|
CSV.generate(headers: true) do |csv|
|
||||||
|
csv << %w(description activity_type receipt_date sum)
|
||||||
|
|
||||||
|
all.each do |x|
|
||||||
|
csv << attributes.map{ |attr| x.send(attr) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
- content_for :actions do
|
- content_for :actions do
|
||||||
= link_to(t(:back_to_billing), registrar_invoices_path, class: 'btn btn-default')
|
= link_to(t(:back_to_billing), registrar_invoices_path, class: 'btn btn-default')
|
||||||
|
= link_to(t(:export_csv), url_for(params.merge(format: 'csv')), class: 'btn btn-default')
|
||||||
|
|
||||||
= render 'shared/title', name: t(:account_activity)
|
= render 'shared/title', name: t(:account_activity)
|
||||||
|
|
||||||
.row
|
.row
|
||||||
|
@ -23,7 +25,7 @@
|
||||||
.form-group
|
.form-group
|
||||||
= f.label t(:receipt_date_until)
|
= f.label t(:receipt_date_until)
|
||||||
= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control datepicker', placeholder: t(:receipt_date_until), autocomplete: 'off'
|
= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control datepicker', placeholder: t(:receipt_date_until), autocomplete: 'off'
|
||||||
.col-md-3{style: 'padding-top: 25px;'}
|
.col-md-6{style: 'padding-top: 25px;'}
|
||||||
%button.btn.btn-default
|
%button.btn.btn-default
|
||||||
|
|
||||||
%span.glyphicon.glyphicon-search
|
%span.glyphicon.glyphicon-search
|
||||||
|
|
|
@ -860,3 +860,4 @@ en:
|
||||||
receipt_date_from: 'Receipt date from'
|
receipt_date_from: 'Receipt date from'
|
||||||
receipt_date_until: 'Receipt date until'
|
receipt_date_until: 'Receipt date until'
|
||||||
add_credit: 'Add credit'
|
add_credit: 'Add credit'
|
||||||
|
export_csv: 'Export CSV'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue