add view for all transactions + csv
This commit is contained in:
parent
b5b4ccd922
commit
ef0888f38d
15 changed files with 111 additions and 19 deletions
|
@ -1,7 +1,7 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
class Finance::FinancialTransactionsController < ApplicationController
|
class Finance::FinancialTransactionsController < ApplicationController
|
||||||
before_filter :authenticate_finance
|
before_filter :authenticate_finance
|
||||||
before_filter :find_ordergroup, :except => [:new_collection, :create_collection]
|
before_filter :find_ordergroup, :except => [:new_collection, :create_collection, :index_collection]
|
||||||
inherit_resources
|
inherit_resources
|
||||||
# belongs_to :ordergroup
|
# belongs_to :ordergroup
|
||||||
|
|
||||||
|
@ -19,13 +19,23 @@ class Finance::FinancialTransactionsController < ApplicationController
|
||||||
sort = "created_on DESC"
|
sort = "created_on DESC"
|
||||||
end
|
end
|
||||||
|
|
||||||
@financial_transactions = @ordergroup.financial_transactions.includes(:user).order(sort).
|
@q = FinancialTransaction.search(params[:q])
|
||||||
page(params[:page]).per(@per_page)
|
@financial_transactions_all = @q.result(distinct: true).includes(:user).order(sort)
|
||||||
if params[:query].present?
|
@financial_transactions_all = @financial_transactions_all.where(ordergroup_id: @ordergroup.id) if @ordergroup
|
||||||
@financial_transactions = @financial_transactions.where('note LIKE ?', "%#{params[:query]}%")
|
@financial_transactions = @financial_transactions_all.page(params[:page]).per(@per_page)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.js; format.html { render }
|
||||||
|
format.csv do
|
||||||
|
send_data FinancialTransactionsCsv.new(@financial_transactions_all).to_csv, filename: 'transactions.csv', type: 'text/csv'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def index_collection
|
||||||
|
index
|
||||||
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@financial_transaction = @ordergroup.financial_transactions.build
|
@financial_transaction = @ordergroup.financial_transactions.build
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,8 +40,12 @@ module ApplicationHelper
|
||||||
link_to(per_page, params, :remote => true, class: link_class)
|
link_to(per_page, params, :remote => true, class: link_class)
|
||||||
end
|
end
|
||||||
|
|
||||||
content_tag :div, class: 'btn-group pull-right' do
|
if options[:wrap] == false
|
||||||
links.join.html_safe
|
links.join.html_safe
|
||||||
|
else
|
||||||
|
content_tag :div, class: 'btn-group pull-right' do
|
||||||
|
links.join.html_safe
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
- if @ordergroup.financial_transactions.count > 20
|
- with_ordergroup ||= false
|
||||||
= items_per_page
|
.pull-right
|
||||||
|
.btn-group
|
||||||
|
= link_to url_for(q: params[:q], format: :csv), class: 'btn' do
|
||||||
|
= glyph :download
|
||||||
|
CSV
|
||||||
|
- if @financial_transactions.total_pages > 1
|
||||||
|
.btn-group= items_per_page wrap: false
|
||||||
= pagination_links_remote @financial_transactions
|
= pagination_links_remote @financial_transactions
|
||||||
%table.table.table-striped
|
%table.table.table-striped
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
%th= sort_link_helper heading_helper(FinancialTransaction, :created_on), "date"
|
%th= sort_link_helper heading_helper(FinancialTransaction, :created_on), "date"
|
||||||
|
- if with_ordergroup
|
||||||
|
%th= heading_helper FinancialTransaction, :ordergroup
|
||||||
%th= heading_helper FinancialTransaction, :user
|
%th= heading_helper FinancialTransaction, :user
|
||||||
%th= sort_link_helper heading_helper(FinancialTransaction, :note), "note"
|
%th= sort_link_helper heading_helper(FinancialTransaction, :note), "note"
|
||||||
%th= sort_link_helper heading_helper(FinancialTransaction, :amount), "amount"
|
%th= sort_link_helper heading_helper(FinancialTransaction, :amount), "amount"
|
||||||
|
@ -12,6 +20,8 @@
|
||||||
- @financial_transactions.each do |t|
|
- @financial_transactions.each do |t|
|
||||||
%tr
|
%tr
|
||||||
%td= format_time(t.created_on)
|
%td= format_time(t.created_on)
|
||||||
|
- if with_ordergroup
|
||||||
|
%td= h link_to t.ordergroup.name, finance_ordergroup_transactions_path(t.ordergroup)
|
||||||
%td= h show_user(t.user)
|
%td= h show_user(t.user)
|
||||||
%td= h t.note
|
%td= h t.note
|
||||||
%td.currency{:style => "color:#{t.amount < 0 ? 'red' : 'black'}; width:5em"}= number_to_currency(t.amount)
|
%td.currency{:style => "color:#{t.amount < 0 ? 'red' : 'black'}; width:5em"}= number_to_currency(t.amount)
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
.well.well-small
|
||||||
|
= search_form_for @q, url: url,
|
||||||
|
html: {data: {'submit-onchange' => true}, method: :get, remote: true, class: 'form-search'} do |f|
|
||||||
|
= f.text_field :note_cont, class: 'search-query', placeholder: t('.search_placeholder')
|
||||||
|
|
||||||
|
|
||||||
|
= label_tag 'q_created_on_gteq', FinancialTransaction.human_attribute_name(:created_on)
|
||||||
|
|
||||||
|
.input-append.input-prepend
|
||||||
|
= f.text_field :created_on_gteq, class: 'input-small datepicker'
|
||||||
|
%span.add-on -
|
||||||
|
= f.text_field :created_on_lteq, class: 'input-small search-query datepicker'
|
||||||
|
|
||||||
|
|
||||||
|
= label_tag 'q_amount_gteq', FinancialTransaction.human_attribute_name(:amount)
|
||||||
|
|
||||||
|
.input-append.input-prepend
|
||||||
|
%span.add-on= t 'number.currency.format.unit'
|
||||||
|
= f.text_field :amount_gteq, class: 'input-mini'
|
||||||
|
%span.add-on -
|
||||||
|
= f.text_field :amount_lteq, class: 'input-mini search-query'
|
||||||
|
|
|
@ -8,11 +8,7 @@
|
||||||
%strong= t('.balance', balance: number_to_currency(@ordergroup.account_balance))
|
%strong= t('.balance', balance: number_to_currency(@ordergroup.account_balance))
|
||||||
%br/
|
%br/
|
||||||
%small= t('.last_updated_at', when: distance_of_time_in_words(Time.now, @ordergroup.account_updated))
|
%small= t('.last_updated_at', when: distance_of_time_in_words(Time.now, @ordergroup.account_updated))
|
||||||
.well.well-small
|
|
||||||
= form_tag finance_ordergroup_transactions_path(@ordergroup), :method => :get, :remote => true,
|
|
||||||
'data-submit-onchange' => true, class: 'form-search' do
|
|
||||||
= text_field_tag :query, params[:query], class: 'input-medium search-query',
|
|
||||||
placeholder: t('.search_placeholder')
|
|
||||||
|
|
||||||
|
= render 'transactions_search', url: finance_ordergroup_transactions_path(@ordergroup)
|
||||||
|
|
||||||
#transactions= render 'transactions'
|
#transactions= render 'transactions'
|
1
app/views/finance/financial_transactions/index.js.erb
Normal file
1
app/views/finance/financial_transactions/index.js.erb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
$('#transactions').html('<%= escape_javascript(render("transactions")) %>');
|
|
@ -1 +0,0 @@
|
||||||
$('#transactions').html('#{escape_javascript(render("transactions"))}');
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
- title t('.title')
|
||||||
|
|
||||||
|
- content_for :actionbar do
|
||||||
|
= link_to t('.show_groups'), finance_ordergroups_path, class: 'btn'
|
||||||
|
|
||||||
|
= render 'transactions_search', url: finance_transactions_path
|
||||||
|
|
||||||
|
#transactions= render 'transactions', with_ordergroup: true
|
|
@ -0,0 +1 @@
|
||||||
|
$('#transactions').html('<%= escape_javascript(render("transactions", with_ordergroup: true)) %>');
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
%h2
|
%h2
|
||||||
= t('.last_transactions')
|
= t('.last_transactions')
|
||||||
%small= link_to(t('.show_all'), finance_ordergroups_path)
|
%small= link_to(t('.show_all'), finance_transactions_path)
|
||||||
%table.table.table-striped
|
%table.table.table-striped
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
- title t('.title')
|
- title t('.title')
|
||||||
|
|
||||||
- content_for :actionbar do
|
- content_for :actionbar do
|
||||||
|
= link_to t('.show_all'), finance_transactions_path, class: 'btn'
|
||||||
= link_to t('.new_transaction'), finance_new_transaction_collection_path, class: 'btn btn-primary'
|
= link_to t('.new_transaction'), finance_new_transaction_collection_path, class: 'btn btn-primary'
|
||||||
|
|
||||||
.well.well-small
|
.well.well-small
|
||||||
|
|
|
@ -590,8 +590,10 @@ en:
|
||||||
balance: 'Balance of account: %{balance}'
|
balance: 'Balance of account: %{balance}'
|
||||||
last_updated_at: (last updated %{when} ago)
|
last_updated_at: (last updated %{when} ago)
|
||||||
new_transaction: Create new transaction
|
new_transaction: Create new transaction
|
||||||
search_placeholder: Search ...
|
|
||||||
title: Account statement for %{name}
|
title: Account statement for %{name}
|
||||||
|
index_collection:
|
||||||
|
title: Financial transactions
|
||||||
|
show_groups: Manage accounts
|
||||||
new:
|
new:
|
||||||
paragraph: Here you can credit and debit money for the order group <b>%{name}</b>.
|
paragraph: Here you can credit and debit money for the order group <b>%{name}</b>.
|
||||||
title: New transaction
|
title: New transaction
|
||||||
|
@ -603,6 +605,8 @@ en:
|
||||||
ordergroup:
|
ordergroup:
|
||||||
remove: Remove
|
remove: Remove
|
||||||
remove_group: Remove group
|
remove_group: Remove group
|
||||||
|
transactions_search:
|
||||||
|
search_placeholder: Search note ...
|
||||||
index:
|
index:
|
||||||
amount_fc: Amount(FC)
|
amount_fc: Amount(FC)
|
||||||
end: End
|
end: End
|
||||||
|
@ -633,6 +637,7 @@ en:
|
||||||
index:
|
index:
|
||||||
new_transaction: Add new transactions
|
new_transaction: Add new transactions
|
||||||
search_placeholder: Search ...
|
search_placeholder: Search ...
|
||||||
|
show_all: All transactions
|
||||||
title: Manage accounts
|
title: Manage accounts
|
||||||
ordergroups:
|
ordergroups:
|
||||||
account_statement: Account statement
|
account_statement: Account statement
|
||||||
|
|
|
@ -588,8 +588,10 @@ nl:
|
||||||
balance: 'Tegoed: %{balance}'
|
balance: 'Tegoed: %{balance}'
|
||||||
last_updated_at: (laatst bijgewerkt %{when} geleden)
|
last_updated_at: (laatst bijgewerkt %{when} geleden)
|
||||||
new_transaction: Nieuwe transactie toevoegen
|
new_transaction: Nieuwe transactie toevoegen
|
||||||
search_placeholder: Zoeken ...
|
|
||||||
title: Rekeningoverzicht voor %{name}
|
title: Rekeningoverzicht voor %{name}
|
||||||
|
index_collection:
|
||||||
|
title: Financiële transacties
|
||||||
|
show_groups: Tegoeden
|
||||||
new:
|
new:
|
||||||
paragraph: Hier kun je het tegoed van huishouden <b>%{name}</b> ophogen en verlagen.
|
paragraph: Hier kun je het tegoed van huishouden <b>%{name}</b> ophogen en verlagen.
|
||||||
title: Nieuwe transactie
|
title: Nieuwe transactie
|
||||||
|
@ -601,6 +603,8 @@ nl:
|
||||||
ordergroup:
|
ordergroup:
|
||||||
remove: Verwijderen
|
remove: Verwijderen
|
||||||
remove_group: Huishouden verwijderen
|
remove_group: Huishouden verwijderen
|
||||||
|
transactions_search:
|
||||||
|
search_placeholder: Zoeken in notitie...
|
||||||
index:
|
index:
|
||||||
amount_fc: Bedrag(FC)
|
amount_fc: Bedrag(FC)
|
||||||
end: Einde
|
end: Einde
|
||||||
|
@ -631,6 +635,7 @@ nl:
|
||||||
index:
|
index:
|
||||||
new_transaction: Nieuwe transacties toevoegen
|
new_transaction: Nieuwe transacties toevoegen
|
||||||
search_placeholder: Zoeken ...
|
search_placeholder: Zoeken ...
|
||||||
|
show_all: Transactieoverzicht
|
||||||
title: Tegoeden beheren
|
title: Tegoeden beheren
|
||||||
ordergroups:
|
ordergroups:
|
||||||
account_statement: Rekeningafschrift
|
account_statement: Rekeningafschrift
|
||||||
|
|
|
@ -159,6 +159,7 @@ Foodsoft::Application.routes.draw do
|
||||||
resources :ordergroups, :only => [:index] do
|
resources :ordergroups, :only => [:index] do
|
||||||
resources :financial_transactions, :as => :transactions
|
resources :financial_transactions, :as => :transactions
|
||||||
end
|
end
|
||||||
|
get 'transactions' => 'financial_transactions#index_collection'
|
||||||
|
|
||||||
get 'transactions/new_collection' => 'financial_transactions#new_collection', :as => 'new_transaction_collection'
|
get 'transactions/new_collection' => 'financial_transactions#new_collection', :as => 'new_transaction_collection'
|
||||||
post 'transactions/create_collection' => 'financial_transactions#create_collection', :as => 'create_transaction_collection'
|
post 'transactions/create_collection' => 'financial_transactions#create_collection', :as => 'create_transaction_collection'
|
||||||
|
|
29
lib/financial_transactions_csv.rb
Normal file
29
lib/financial_transactions_csv.rb
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
require 'csv'
|
||||||
|
|
||||||
|
class FinancialTransactionsCsv < RenderCSV
|
||||||
|
include ApplicationHelper
|
||||||
|
|
||||||
|
def header
|
||||||
|
[
|
||||||
|
FinancialTransaction.human_attribute_name(:created_on),
|
||||||
|
FinancialTransaction.human_attribute_name(:ordergroup),
|
||||||
|
FinancialTransaction.human_attribute_name(:ordergroup),
|
||||||
|
FinancialTransaction.human_attribute_name(:user),
|
||||||
|
FinancialTransaction.human_attribute_name(:note),
|
||||||
|
FinancialTransaction.human_attribute_name(:amount)
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
def data
|
||||||
|
@object.includes(:user, :ordergroup).each do |t|
|
||||||
|
yield [
|
||||||
|
t.created_on,
|
||||||
|
t.ordergroup_id,
|
||||||
|
t.ordergroup.name,
|
||||||
|
show_user(t.user),
|
||||||
|
t.note,
|
||||||
|
number_to_currency(t.amount)
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue