Add filter to account activities #2691

This commit is contained in:
Martin Lensment 2015-07-07 11:22:32 +03:00
parent d6a151b141
commit ca2a2db9ad
4 changed files with 61 additions and 4 deletions

View file

@ -2,9 +2,17 @@ class Registrar::AccountActivitiesController < RegistrarController
load_and_authorize_resource
def index
params[:q] ||= {}
account = current_user.registrar.cash_account
ca_cache = params[:q][:created_at_lteq]
end_time = params[:q][:created_at_lteq].try(:to_date)
params[:q][:created_at_lteq] = end_time.try(:end_of_day)
@q = account.activities.includes(:invoice).search(params[:q])
@q.sorts = 'id desc' if @q.sorts.empty?
@account_activities = @q.result.page(params[:page])
params[:q][:created_at_lteq] = ca_cache
end
end

View file

@ -13,5 +13,11 @@ class AccountActivity < ActiveRecord::Base
account.balance += sum
account.save
end
class << self
def types_for_select
[CREATE, RENEW, ADD_CREDIT].map { |x| [I18n.t(x), x] }
end
end
end

View file

@ -2,16 +2,50 @@
= link_to(t(:back_to_billing), registrar_invoices_path, class: 'btn btn-default')
= render 'shared/title', name: t(:account_activity)
.row
.col-md-12
= search_form_for @q, url: [:registrar, :account_activities], html: { style: 'margin-bottom: 0;' } do |f|
.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-3{style: 'padding-top: 25px;'}
%button.btn.btn-default
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
%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-5'}= t(:description)
%th{class: 'col-xs-3'}= t(:receipt_date)
%th{class: 'col-xs-2'}= t(:invoice)
%th{class: 'col-xs-2'}= t(:sum)
%th{class: 'col-xs-5'}
= sort_link(@q, 'description')
%th{class: 'col-xs-3'}
= sort_link(@q, 'created_at', t(:receipt_date))
%th{class: 'col-xs-2'}
= sort_link(@q, 'invoice_id', t(:invoice))
%th{class: 'col-xs-2'}
= sort_link(@q, 'sum')
%tbody
- @account_activities.each do |x|
%tr
@ -27,3 +61,8 @@
.row
.col-md-12
= paginate @account_activities
:coffee
$(".js-reset-form").on "click", (e) ->
e.preventDefault();
window.location = "#{registrar_account_activities_path}"

View file

@ -856,3 +856,7 @@ en:
blocked_domains: 'Blocked domains'
billing_failure_credit_balance_low: 'Billing failure - credit balance low'
create: 'Create'
activity_type: 'Activity type'
receipt_date_from: 'Receipt date from'
receipt_date_until: 'Receipt date until'
add_credit: 'Add credit'