From 0fd682c6b94f4269939784ecad5281fc8ad1b0cc Mon Sep 17 00:00:00 2001 From: Stas Date: Wed, 9 Dec 2015 14:00:31 +0200 Subject: [PATCH 1/5] 107279984-credit_balance_views --- app/controllers/admin/registrars_controller.rb | 2 +- app/views/admin/account_activities/index.haml | 9 +++++++++ app/views/admin/registrars/index.haml | 7 +++++-- app/views/admin/registrars/show.haml | 3 +++ config/locales/en.yml | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index c0d28908f..cf8c89505 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -6,7 +6,7 @@ class Admin::RegistrarsController < AdminController end def index - @q = Registrar.ordered.search(params[:q]) + @q = Registrar.joins(:accounts).ordered.search(params[:q]) @registrars = @q.result.page(params[:page]) end diff --git a/app/views/admin/account_activities/index.haml b/app/views/admin/account_activities/index.haml index 35e270dce..521ebf84c 100644 --- a/app/views/admin/account_activities/index.haml +++ b/app/views/admin/account_activities/index.haml @@ -55,6 +55,7 @@ %th{class: 'col-xs-2'} = sort_link(@q, 'sum') %tbody + -total = 0 - @account_activities.each do |x| %tr %td= link_to(x.account.registrar.try(:code), admin_registrar_path(x.account.registrar)) @@ -63,7 +64,15 @@ %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}" + -total += x.sum %td{class: c}= s + - if @account_activities.count > 0 + %tr + %td + %td + %td + %td{class: 'text-right'}= t(:total) + %td{class: 'text-success'}= total > 0 ? "+#{total} EUR" : "#{total} EUR" .row .col-md-12 = paginate @account_activities diff --git a/app/views/admin/registrars/index.haml b/app/views/admin/registrars/index.haml index a2604dbec..8ba45d205 100644 --- a/app/views/admin/registrars/index.haml +++ b/app/views/admin/registrars/index.haml @@ -8,15 +8,18 @@ %table.table.table-hover.table-bordered.table-condensed %thead %tr - %th{class: 'col-xs-6'} + %th{class: 'col-xs-4'} = sort_link(@q, 'name') - %th{class: 'col-xs-6'} + %th{class: 'col-xs-4'} = sort_link(@q, 'reg_no', t(:reg_no)) + %th{class: 'col-xs-4'} + = t(:credit_balance) %tbody - @registrars.each do |x| %tr %td= link_to(x, [:admin, x]) %td= x.reg_no + %td= "#{x.balance}" .row .col-md-12 = paginate @registrars diff --git a/app/views/admin/registrars/show.haml b/app/views/admin/registrars/show.haml index e3966583f..35938c0c6 100644 --- a/app/views/admin/registrars/show.haml +++ b/app/views/admin/registrars/show.haml @@ -32,6 +32,9 @@ %dt= t(:id) %dd= @registrar.code + %dt= t(:credit_balance) + %dd= @registrar.balance + .col-md-6 .panel.panel-default .panel-heading diff --git a/config/locales/en.yml b/config/locales/en.yml index 07f4ebc0a..07b8cde24 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -351,6 +351,7 @@ en: status: 'Status' eedirekt: 'EEDirekt' contact: 'Contact' + credit_balance: 'Credit balance' domain_transfer_requested: 'Domain transfer requested!' domain_transfer_approved: 'Domain transfer approved!' From 6909f3d0ef19be4a05cbd26476a4b0d838536404 Mon Sep 17 00:00:00 2001 From: Stas Date: Fri, 18 Dec 2015 13:30:51 +0200 Subject: [PATCH 2/5] 10729984-starting_balance --- app/controllers/admin/account_activities_controller.rb | 1 + app/views/admin/account_activities/index.haml | 7 +++++++ config/locales/en.yml | 1 + 3 files changed, 9 insertions(+) diff --git a/app/controllers/admin/account_activities_controller.rb b/app/controllers/admin/account_activities_controller.rb index 1c447d8a6..640acf2e7 100644 --- a/app/controllers/admin/account_activities_controller.rb +++ b/app/controllers/admin/account_activities_controller.rb @@ -14,6 +14,7 @@ class Admin::AccountActivitiesController < AdminController @q = AccountActivity.includes(:invoice, account: :registrar).search(params[:q]) @q.sorts = 'id desc' if @q.sorts.empty? + @b = AccountActivity.where.not(id: @q.result.map(&:id)) respond_to do |format| format.html { @account_activities = @q.result.page(params[:page]) } diff --git a/app/views/admin/account_activities/index.haml b/app/views/admin/account_activities/index.haml index 521ebf84c..6efefb814 100644 --- a/app/views/admin/account_activities/index.haml +++ b/app/views/admin/account_activities/index.haml @@ -36,6 +36,13 @@   %button.btn.btn-default.js-reset-form = t(:clear_fields) +.row + .col-md-3 + .col-md-3 + .col-md-2 + .col-md-4{class: 'text-right'} + = t(:starting_balance) + " #{@b.sum('sum').to_f} EUR" + %hr .row diff --git a/config/locales/en.yml b/config/locales/en.yml index 07b8cde24..fbfc09780 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -352,6 +352,7 @@ en: eedirekt: 'EEDirekt' contact: 'Contact' credit_balance: 'Credit balance' + starting_balance: 'Starting balance' domain_transfer_requested: 'Domain transfer requested!' domain_transfer_approved: 'Domain transfer approved!' From cbe0193cbfb1dbdba5085d8041ac906993be6315 Mon Sep 17 00:00:00 2001 From: Stas Date: Tue, 5 Jan 2016 17:57:56 +0200 Subject: [PATCH 3/5] 107279984-balance_fix --- app/controllers/admin/account_activities_controller.rb | 8 +++++++- app/views/admin/account_activities/index.haml | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/account_activities_controller.rb b/app/controllers/admin/account_activities_controller.rb index 640acf2e7..bb5b72df8 100644 --- a/app/controllers/admin/account_activities_controller.rb +++ b/app/controllers/admin/account_activities_controller.rb @@ -12,9 +12,15 @@ class Admin::AccountActivitiesController < AdminController logger.warn('Invalid date') end + balance_params = params[:q].deep_dup + + if balance_params[:created_at_gteq] + balance_params.delete('created_at_gteq') + end + @q = AccountActivity.includes(:invoice, account: :registrar).search(params[:q]) @q.sorts = 'id desc' if @q.sorts.empty? - @b = AccountActivity.where.not(id: @q.result.map(&:id)) + @b = AccountActivity.search(balance_params).result.where.not(id: @q.result.map(&:id)) respond_to do |format| format.html { @account_activities = @q.result.page(params[:page]) } diff --git a/app/views/admin/account_activities/index.haml b/app/views/admin/account_activities/index.haml index 6efefb814..4999fd558 100644 --- a/app/views/admin/account_activities/index.haml +++ b/app/views/admin/account_activities/index.haml @@ -62,7 +62,7 @@ %th{class: 'col-xs-2'} = sort_link(@q, 'sum') %tbody - -total = 0 + -total = @b.sum('sum').to_f - @account_activities.each do |x| %tr %td= link_to(x.account.registrar.try(:code), admin_registrar_path(x.account.registrar)) @@ -79,7 +79,7 @@ %td %td %td{class: 'text-right'}= t(:total) - %td{class: 'text-success'}= total > 0 ? "+#{total} EUR" : "#{total} EUR" + %td{class: total > 0 ? 'text-success' : 'text-danger'}= total > 0 ? "+#{total} EUR" : "#{total} EUR" .row .col-md-12 = paginate @account_activities From 96552a03440cd080eb4a570007a55d57a954505b Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 11 Jan 2016 15:44:26 +0200 Subject: [PATCH 4/5] 107279984-filter_changes --- .../admin/account_activities_controller.rb | 44 ++++++++++++++++++- app/views/admin/account_activities/index.haml | 10 +++-- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/account_activities_controller.rb b/app/controllers/admin/account_activities_controller.rb index bb5b72df8..1419dbea9 100644 --- a/app/controllers/admin/account_activities_controller.rb +++ b/app/controllers/admin/account_activities_controller.rb @@ -19,11 +19,51 @@ class Admin::AccountActivitiesController < AdminController end @q = AccountActivity.includes(:invoice, account: :registrar).search(params[:q]) + @b = AccountActivity.search(balance_params) @q.sorts = 'id desc' if @q.sorts.empty? - @b = AccountActivity.search(balance_params).result.where.not(id: @q.result.map(&:id)) + + + + @account_activities = @q.result.page(params[:page]).per(params[:results_per_page]) + sort = @account_activities.orders.map(&:to_sql).join(",") + + + if params[:page] && params[:page].to_i > 1 + + + @sum = @q.result.reorder(sort).limit(@account_activities.offset_value) + @b.result.where.not(id: @q.result.map(&:id)) + + else + + @sum = @b.result.where.not(id: @q.result.map(&:id)) + + + end + + + + + + + # throw "cdsfs" + + # if params[:page] && params[:page].to_i > 1 + # + # @b = @q.result.page(params[:page].to_i - 1) + # + # @b = @b.per(params[:results_per_page]) + # + # + # else + # + # @b = AccountActivity.search(balance_params) + # + # @b = @b.result.where.not(id: @q.result.map(&:id)) + # + # end respond_to do |format| - format.html { @account_activities = @q.result.page(params[:page]) } + format.html format.csv do send_data @q.result.to_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv" end diff --git a/app/views/admin/account_activities/index.haml b/app/views/admin/account_activities/index.haml index 4999fd558..80ebba2f6 100644 --- a/app/views/admin/account_activities/index.haml +++ b/app/views/admin/account_activities/index.haml @@ -29,7 +29,11 @@ .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;'} + .col-md-3 + .form-group + = label_tag t(:results_per_page) + = text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) + .col-md-3{style: 'padding-top: 25px;'} %button.btn.btn-default.search   %span.glyphicon.glyphicon-search @@ -41,7 +45,7 @@ .col-md-3 .col-md-2 .col-md-4{class: 'text-right'} - = t(:starting_balance) + " #{@b.sum('sum').to_f} EUR" + = t(:starting_balance) + " #{@sum.to_a.map(&:sum).sum.to_f} EUR" %hr @@ -62,7 +66,7 @@ %th{class: 'col-xs-2'} = sort_link(@q, 'sum') %tbody - -total = @b.sum('sum').to_f + -total = @sum.to_a.map(&:sum).sum.to_f - @account_activities.each do |x| %tr %td= link_to(x.account.registrar.try(:code), admin_registrar_path(x.account.registrar)) From c4ead607da38e05f7c17a7bf420fff65fc0b38cd Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 11 Jan 2016 17:02:35 +0200 Subject: [PATCH 5/5] 107279984-refactor --- .../admin/account_activities_controller.rb | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/app/controllers/admin/account_activities_controller.rb b/app/controllers/admin/account_activities_controller.rb index 1419dbea9..0f095734f 100644 --- a/app/controllers/admin/account_activities_controller.rb +++ b/app/controllers/admin/account_activities_controller.rb @@ -22,46 +22,15 @@ class Admin::AccountActivitiesController < AdminController @b = AccountActivity.search(balance_params) @q.sorts = 'id desc' if @q.sorts.empty? - - @account_activities = @q.result.page(params[:page]).per(params[:results_per_page]) sort = @account_activities.orders.map(&:to_sql).join(",") - if params[:page] && params[:page].to_i > 1 - - @sum = @q.result.reorder(sort).limit(@account_activities.offset_value) + @b.result.where.not(id: @q.result.map(&:id)) - else - @sum = @b.result.where.not(id: @q.result.map(&:id)) - - end - - - - - - # throw "cdsfs" - - # if params[:page] && params[:page].to_i > 1 - # - # @b = @q.result.page(params[:page].to_i - 1) - # - # @b = @b.per(params[:results_per_page]) - # - # - # else - # - # @b = AccountActivity.search(balance_params) - # - # @b = @b.result.where.not(id: @q.result.map(&:id)) - # - # end - respond_to do |format| format.html format.csv do