Add account activity to registrar

This commit is contained in:
Martin Lensment 2015-04-16 13:21:43 +03:00
parent f2f2e42608
commit 32073ca862
15 changed files with 117 additions and 32 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,4 +1,10 @@
class Account < ActiveRecord::Base
belongs_to :registrar
has_many :account_activities
CASH = 'cash'
def activities
account_activities
end
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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')

View file

@ -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

View file

@ -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')

View file

@ -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'