mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Add account activities view to admin #2893
This commit is contained in:
parent
ce3397dbfb
commit
34e4342219
7 changed files with 151 additions and 0 deletions
28
app/controllers/admin/account_activities_controller.rb
Normal file
28
app/controllers/admin/account_activities_controller.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
class Admin::AccountActivitiesController < AdminController
|
||||
load_and_authorize_resource
|
||||
|
||||
def index # rubocop: disable Metrics/AbcSize
|
||||
params[:q] ||= {}
|
||||
# account = current_user.registrar.cash_account
|
||||
|
||||
ca_cache = params[:q][:created_at_lteq]
|
||||
begin
|
||||
end_time = params[:q][:created_at_lteq].try(:to_date)
|
||||
params[:q][:created_at_lteq] = end_time.try(:end_of_day)
|
||||
rescue
|
||||
logger.warn('Invalid date')
|
||||
end
|
||||
|
||||
@q = AccountActivity.includes(:invoice, account: :registrar).search(params[:q])
|
||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||
|
||||
respond_to do |format|
|
||||
format.html { @account_activities = @q.result.page(params[:page]) }
|
||||
format.csv do
|
||||
send_data @q.result.to_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv"
|
||||
end
|
||||
end
|
||||
|
||||
params[:q][:created_at_lteq] = ca_cache
|
||||
end
|
||||
end
|
|
@ -99,6 +99,7 @@ class Ability
|
|||
can :manage, MailTemplate
|
||||
can :manage, Invoice
|
||||
can :manage, WhiteIp
|
||||
can :manage, AccountActivity
|
||||
can :read, ApiLog::EppLog
|
||||
can :read, ApiLog::ReppLog
|
||||
can :update, :pending
|
||||
|
|
74
app/views/admin/account_activities/index.haml
Normal file
74
app/views/admin/account_activities/index.haml
Normal file
|
@ -0,0 +1,74 @@
|
|||
- content_for :actions do
|
||||
= link_to(t(:export_csv), url_for(params.merge(format: 'csv')), class: 'btn btn-default')
|
||||
|
||||
= render 'shared/title', name: t(:account_activities)
|
||||
|
||||
.row
|
||||
.col-md-12
|
||||
= search_form_for @q, url: [:admin, :account_activities], html: { style: 'margin-bottom: 0;' } do |f|
|
||||
.row
|
||||
.col-md-12
|
||||
.form-group
|
||||
= f.label t(:registrar)
|
||||
= f.select :account_registrar_id_in, Registrar.all.map { |x| [x, x.id] }, {}, class: 'form-control js-combobox', placeholder: t(:choose), multiple: true
|
||||
.row
|
||||
.col-md-6
|
||||
.form-group
|
||||
= f.label t(:activity_type)
|
||||
= f.select :activity_type_in, AccountActivity.types_for_select, {}, class: 'form-control js-combobox', placeholder: t(:choose), multiple: true
|
||||
.col-md-6
|
||||
.form-group
|
||||
= f.label t(:description)
|
||||
= f.search_field :description_cont, class: 'form-control', placeholder: t(:description), autocomplete: 'off'
|
||||
.row
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:receipt_date_from)
|
||||
= f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control datepicker', placeholder: t(:receipt_date_from), autocomplete: 'off'
|
||||
.col-md-3
|
||||
.form-group
|
||||
= 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'
|
||||
.col-md-6{style: 'padding-top: 25px;'}
|
||||
%button.btn.btn-default.search
|
||||
|
||||
%span.glyphicon.glyphicon-search
|
||||
|
||||
%button.btn.btn-default.js-reset-form
|
||||
= t(:clear_fields)
|
||||
%hr
|
||||
|
||||
.row
|
||||
.col-md-12
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'registrar')
|
||||
%th{class: 'col-xs-3'}
|
||||
= sort_link(@q, 'description')
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'activity_type')
|
||||
%th{class: 'col-xs-3'}
|
||||
= sort_link(@q, 'created_at', t(:receipt_date))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'sum')
|
||||
%tbody
|
||||
- @account_activities.each do |x|
|
||||
%tr
|
||||
%td= link_to(x.account.registrar.try(:code), admin_registrar_path(x.account.registrar))
|
||||
%td= x.description.present? ? x.description : '-'
|
||||
%td= x.activity_type ? t(x.activity_type) : ''
|
||||
%td= l(x.created_at)
|
||||
- c = x.sum > 0.0 ? 'text-success' : 'text-danger'
|
||||
- s = x.sum > 0.0 ? "+#{x.sum} #{x.currency}" : "#{x.sum} #{x.currency}"
|
||||
%td{class: c}= s
|
||||
.row
|
||||
.col-md-12
|
||||
= paginate @account_activities
|
||||
|
||||
:coffee
|
||||
$(".js-reset-form").on "click", (e) ->
|
||||
e.preventDefault();
|
||||
window.location = "#{admin_account_activities_path}"
|
|
@ -55,6 +55,7 @@
|
|||
%li= link_to t(:pricelists), admin_pricelists_path
|
||||
%li= link_to t(:bank_statements), admin_bank_statements_path
|
||||
%li= link_to t(:invoices), admin_invoices_path
|
||||
%li= link_to t(:account_activities), admin_account_activities_path
|
||||
%li.divider
|
||||
%li.dropdown-header= t(:system)
|
||||
%li= link_to t(:settings), admin_settings_path
|
||||
|
|
|
@ -730,6 +730,7 @@ en:
|
|||
<b>The domain name server</b>
|
||||
is a computer that saves and forwards via a general-access data communications network such data that is connected with the domain name and corresponding IP addresses. Your IT helpdesk or Internet service provider will have the necessary information about the domain name servers.
|
||||
account_activity: 'Account activity'
|
||||
account_activities: 'Account activities'
|
||||
receipt_date: 'Receipt date'
|
||||
manual_binding: 'Manual binding'
|
||||
transaction_is_already_binded: 'Transaction is already binded'
|
||||
|
|
|
@ -161,6 +161,7 @@ Rails.application.routes.draw do
|
|||
resources :keyrelays
|
||||
resources :pricelists
|
||||
resources :mail_templates
|
||||
resources :account_activities
|
||||
|
||||
resources :bank_statements do
|
||||
resources :bank_transactions
|
||||
|
|
45
spec/features/admin/account_activity_spec.rb
Normal file
45
spec/features/admin/account_activity_spec.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require 'rails_helper'
|
||||
|
||||
feature 'Account activity', type: :feature do
|
||||
before :all do
|
||||
@user = Fabricate(:admin_user)
|
||||
r = Fabricate(:registrar)
|
||||
Fabricate.times(5, :account_activity, account: r.cash_account)
|
||||
Fabricate(:account_activity, account: r.cash_account, description: 'acc activity test', sum: -12)
|
||||
end
|
||||
|
||||
context 'as unknown user' do
|
||||
it 'should redirect to sign in page' do
|
||||
visit '/admin/account_activities'
|
||||
current_path.should == '/admin/login'
|
||||
page.should have_text('You need to sign in or sign up')
|
||||
end
|
||||
end
|
||||
|
||||
context 'as signed in user' do
|
||||
before do
|
||||
sign_in @user
|
||||
end
|
||||
|
||||
it 'should navigate to account activities page' do
|
||||
visit admin_account_activities_path
|
||||
page.should have_text('+110.0 EUR', count: 5)
|
||||
page.should have_text('-12.0 EUR')
|
||||
end
|
||||
|
||||
it 'should search activities by description' do
|
||||
visit admin_account_activities_path
|
||||
fill_in 'Description', with: 'test'
|
||||
find('.btn.btn-default.search').click
|
||||
page.should have_text('-12.0 EUR')
|
||||
page.should_not have_text('+110.0 EUR')
|
||||
end
|
||||
|
||||
it 'should download csv' do
|
||||
visit admin_account_activities_path
|
||||
click_link 'Export CSV'
|
||||
response_headers['Content-Type'].should == 'text/csv'
|
||||
response_headers['Content-Disposition'].should match(/attachment; filename="account_activities_\d+\.csv"/)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue