From 32073ca862072e84d8d8f30210a81e16c8fdd055 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Thu, 16 Apr 2015 13:21:43 +0300 Subject: [PATCH] Add account activity to registrar --- .../account_activities_controller.rb | 21 ++++++++++ .../registrar/invoices_controller.rb | 5 ++- app/models/ability.rb | 1 + app/models/account.rb | 6 +++ app/models/bank_transaction.rb | 3 +- app/models/invoice.rb | 5 +-- .../registrar/account_activities/index.haml | 34 +++++++++++++++ app/views/registrar/deposits/new.haml | 11 +++-- app/views/registrar/invoices/index.haml | 42 +++++++++++-------- .../registrar/invoices/partials/_details.haml | 6 +-- app/views/registrar/invoices/show.haml | 2 +- config/locales/en.yml | 4 +- config/routes.rb | 1 + ...026_add_description_to_account_activity.rb | 5 +++ db/schema.rb | 3 +- 15 files changed, 117 insertions(+), 32 deletions(-) create mode 100644 app/controllers/registrar/account_activities_controller.rb create mode 100644 app/views/registrar/account_activities/index.haml create mode 100644 db/migrate/20150416092026_add_description_to_account_activity.rb diff --git a/app/controllers/registrar/account_activities_controller.rb b/app/controllers/registrar/account_activities_controller.rb new file mode 100644 index 000000000..72d370a73 --- /dev/null +++ b/app/controllers/registrar/account_activities_controller.rb @@ -0,0 +1,21 @@ +class Registrar::AccountActivitiesController < RegistrarController + load_and_authorize_resource + + # before_action :set_invoice, only: [:show] + + def index + account = current_user.registrar.cash_account + @q = account.activities.search(params[:q]) + @q.sorts = 'id desc' if @q.sorts.empty? + @account_activities = @q.result.page(params[:page]) + end + + def show + end + + private + + def set_invoice + @invoice = Invoice.find(params[:id]) + end +end diff --git a/app/controllers/registrar/invoices_controller.rb b/app/controllers/registrar/invoices_controller.rb index 086175982..fd9ad77da 100644 --- a/app/controllers/registrar/invoices_controller.rb +++ b/app/controllers/registrar/invoices_controller.rb @@ -4,7 +4,10 @@ class Registrar::InvoicesController < RegistrarController before_action :set_invoice, only: [:show] def index - @invoices = current_user.registrar.invoices.includes(:invoice_items).order(id: :desc) + invoices = current_user.registrar.invoices.includes(:invoice_items, :account_activity) + @q = invoices.search(params[:q]) + @q.sorts = 'id desc' if @q.sorts.empty? + @invoices = @q.result.page(params[:page]) end def show diff --git a/app/models/ability.rb b/app/models/ability.rb index c53bd48d4..b4d62e083 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -47,6 +47,7 @@ class Ability def registrar can :manage, Invoice + can :read, AccountActivity can :view, :registrar_dashboard can :delete, :registrar_poll can :manage, :registrar_xml_console diff --git a/app/models/account.rb b/app/models/account.rb index e1db234ba..092945d89 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,4 +1,10 @@ class Account < ActiveRecord::Base belongs_to :registrar + has_many :account_activities + CASH = 'cash' + + def activities + account_activities + end end diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 765df6b8b..c4f1b97ec 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -37,7 +37,8 @@ class BankTransaction < ActiveRecord::Base account: registrar.cash_account, invoice: invoice, sum: sum, - currency: currency + currency: currency, + description: description ) end # rubocop: enable Metrics/PerceivedComplexity diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 01ccd2a3d..fd381a5c7 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -13,9 +13,8 @@ class Invoice < ActiveRecord::Base account_activity.present? end - def paid_at - # TODO: Cache this? - account_activity.try(:bank_transaction).try(:paid_at) + def receipt_date + account_activity.try(:created_at) end def to_s diff --git a/app/views/registrar/account_activities/index.haml b/app/views/registrar/account_activities/index.haml new file mode 100644 index 000000000..6b646dc0e --- /dev/null +++ b/app/views/registrar/account_activities/index.haml @@ -0,0 +1,34 @@ +.row + .col-sm-6 + %h1.text-center-xs + = t('account_activity') + .col-sm-6 + %h1.text-right.text-center-xs + = link_to(t('back_to_billing'), registrar_invoices_path, class: 'btn btn-default') + +%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') + %tbody + - @account_activities.each do |x| + %tr + %td= x.description.present? ? x.description : '-' + %td= l(x.created_at) + - if x.invoice + %td= link_to(x.invoice, [:registrar, x.invoice]) + - else + %td \- + - 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 diff --git a/app/views/registrar/deposits/new.haml b/app/views/registrar/deposits/new.haml index d2af9f3c9..9023f18cd 100644 --- a/app/views/registrar/deposits/new.haml +++ b/app/views/registrar/deposits/new.haml @@ -1,4 +1,11 @@ -%h1= t(:add_deposit) +.row + .col-sm-6 + %h1.text-center-xs + = t(:add_deposit) + .col-sm-6 + %h1.text-right.text-center-xs + = link_to(t('back_to_billing'), registrar_invoices_path, class: 'btn btn-default') + %hr = form_for([:registrar, @deposit], method: :post) do |f| .row @@ -18,5 +25,3 @@ .row .col-md-12.text-right = button_tag(t(:add), class: 'btn btn-primary') - - diff --git a/app/views/registrar/invoices/index.haml b/app/views/registrar/invoices/index.haml index ee1a6459b..2db9556b1 100644 --- a/app/views/registrar/invoices/index.haml +++ b/app/views/registrar/invoices/index.haml @@ -4,6 +4,7 @@ = t('your_account') .col-sm-6 %h1.text-right.text-center-xs + = link_to(t('account_activity'), registrar_account_activities_path, class: 'btn btn-default') = link_to(t('add_deposit'), new_registrar_deposit_path, class: 'btn btn-default') %hr @@ -11,21 +12,26 @@ %h1= t('invoices') %hr -.table-responsive - %table.table.table-hover.table-condensed - %thead - %tr - %th{class: 'col-xs-3'}= t('invoice') - %th{class: 'col-xs-3'}= t('paid_at') - %th{class: 'col-xs-3'}= t('due_date') - %th{class: 'col-xs-3'}= t('total') - %tbody - - @invoices.each do |x| - %tr - %td= link_to(t('invoice_no', no: x.id), [:registrar, x]) - - if x.paid_at - %td= l(x.paid_at) - - else - %td{class: 'text-danger'}= t('unpaid') - %td= l(x.due_date) - %td= x.sum +.row + .col-md-12 + .table-responsive + %table.table.table-hover.table-condensed + %thead + %tr + %th{class: 'col-xs-3'}= t('invoice') + %th{class: 'col-xs-3'}= t('receipt_date') + %th{class: 'col-xs-3'}= t('due_date') + %th{class: 'col-xs-3'}= t('total') + %tbody + - @invoices.each do |x| + %tr + %td= link_to(t('invoice_no', no: x.id), [:registrar, x]) + - if x.receipt_date + %td= l(x.receipt_date) + - else + %td{class: 'text-danger'}= t('unpaid') + %td= l(x.due_date) + %td= x.sum +.row + .col-md-12 + = paginate @invoices diff --git a/app/views/registrar/invoices/partials/_details.haml b/app/views/registrar/invoices/partials/_details.haml index 95f1e5f31..bbe51c9c9 100644 --- a/app/views/registrar/invoices/partials/_details.haml +++ b/app/views/registrar/invoices/partials/_details.haml @@ -7,9 +7,9 @@ %dt= t('due_date') %dd= l(@invoice.due_date) - %dt= t('paid_at') - - if @invoice.paid_at - %dd= l(@invoice.paid_at) + %dt= t('receipt_date') + - if @invoice.binded? + %dd= l(@invoice.receipt_date) - else %dd{class: 'text-danger'}= t('unpaid') diff --git a/app/views/registrar/invoices/show.haml b/app/views/registrar/invoices/show.haml index bebe999f1..b0c50a7c0 100644 --- a/app/views/registrar/invoices/show.haml +++ b/app/views/registrar/invoices/show.haml @@ -4,7 +4,7 @@ = t('invoice_no', no: @invoice.id) .col-sm-6 %h1.text-right.text-center-xs - = link_to(t('back_to_billing'), registrar_invoices_path, class: 'btn btn-default') + = link_to(t('back'), :back, class: 'btn btn-default') %hr .row .col-md-6= render 'registrar/invoices/partials/details' diff --git a/config/locales/en.yml b/config/locales/en.yml index 46fb51be0..44fa9943e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -652,7 +652,7 @@ en: prepayment: 'Prepayment' vat: 'VAT (%{vat_prc}%)' unpaid: 'Unpaid' - your_current_account_balance_is: 'Your current account balance is %{balance} %{currency]' + your_current_account_balance_is: 'Your current account balance is %{balance} %{currency}' billing: 'Billing' your_account: 'Your account' pay_by_bank_link: 'Pay by bank link' @@ -711,3 +711,5 @@ en: domain_tech_contact_help: The domain name server 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' + receipt_date: 'Receipt date' diff --git a/config/routes.rb b/config/routes.rb index 882ee2be5..abbd041fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,6 +22,7 @@ Rails.application.routes.draw do resources :invoices resources :deposits + resources :account_activities devise_scope :user do get 'login' => 'sessions#login' diff --git a/db/migrate/20150416092026_add_description_to_account_activity.rb b/db/migrate/20150416092026_add_description_to_account_activity.rb new file mode 100644 index 000000000..127272b0d --- /dev/null +++ b/db/migrate/20150416092026_add_description_to_account_activity.rb @@ -0,0 +1,5 @@ +class AddDescriptionToAccountActivity < ActiveRecord::Migration + def change + add_column :account_activities, :description, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 5b91817ed..a1c41cbdf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150416080828) do +ActiveRecord::Schema.define(version: 20150416092026) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -24,6 +24,7 @@ ActiveRecord::Schema.define(version: 20150416080828) do t.integer "bank_transaction_id" t.datetime "created_at" t.datetime "updated_at" + t.string "description" end create_table "accounts", force: :cascade do |t|