add view for all transactions + csv

This commit is contained in:
wvengen 2014-05-06 19:02:01 +02:00
parent b5b4ccd922
commit ef0888f38d
15 changed files with 111 additions and 19 deletions

View File

@ -1,7 +1,7 @@
# encoding: utf-8
class Finance::FinancialTransactionsController < ApplicationController
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
# belongs_to :ordergroup
@ -19,13 +19,23 @@ class Finance::FinancialTransactionsController < ApplicationController
sort = "created_on DESC"
end
@financial_transactions = @ordergroup.financial_transactions.includes(:user).order(sort).
page(params[:page]).per(@per_page)
if params[:query].present?
@financial_transactions = @financial_transactions.where('note LIKE ?', "%#{params[:query]}%")
@q = FinancialTransaction.search(params[:q])
@financial_transactions_all = @q.result(distinct: true).includes(:user).order(sort)
@financial_transactions_all = @financial_transactions_all.where(ordergroup_id: @ordergroup.id) if @ordergroup
@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
def index_collection
index
end
def new
@financial_transaction = @ordergroup.financial_transactions.build
end

View File

@ -40,8 +40,12 @@ module ApplicationHelper
link_to(per_page, params, :remote => true, class: link_class)
end
content_tag :div, class: 'btn-group pull-right' do
if options[:wrap] == false
links.join.html_safe
else
content_tag :div, class: 'btn-group pull-right' do
links.join.html_safe
end
end
end

View File

@ -1,10 +1,18 @@
- if @ordergroup.financial_transactions.count > 20
= items_per_page
- with_ordergroup ||= false
.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
%table.table.table-striped
%thead
%tr
%th= sort_link_helper heading_helper(FinancialTransaction, :created_on), "date"
- if with_ordergroup
%th= heading_helper FinancialTransaction, :ordergroup
%th= heading_helper FinancialTransaction, :user
%th= sort_link_helper heading_helper(FinancialTransaction, :note), "note"
%th= sort_link_helper heading_helper(FinancialTransaction, :amount), "amount"
@ -12,6 +20,8 @@
- @financial_transactions.each do |t|
%tr
%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 t.note
%td.currency{:style => "color:#{t.amount < 0 ? 'red' : 'black'}; width:5em"}= number_to_currency(t.amount)

View File

@ -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')
&nbsp;
= label_tag 'q_created_on_gteq', FinancialTransaction.human_attribute_name(:created_on)
&nbsp;
.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'
&nbsp;
= label_tag 'q_amount_gteq', FinancialTransaction.human_attribute_name(:amount)
&nbsp;
.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'

View File

@ -8,11 +8,7 @@
%strong= t('.balance', balance: number_to_currency(@ordergroup.account_balance))
%br/
%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'

View File

@ -0,0 +1 @@
$('#transactions').html('<%= escape_javascript(render("transactions")) %>');

View File

@ -1 +0,0 @@
$('#transactions').html('#{escape_javascript(render("transactions"))}');

View File

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

View File

@ -0,0 +1 @@
$('#transactions').html('<%= escape_javascript(render("transactions", with_ordergroup: true)) %>');

View File

@ -22,7 +22,7 @@
%h2
= 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
%thead
%tr

View File

@ -1,6 +1,7 @@
- title t('.title')
- 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'
.well.well-small
@ -10,4 +11,4 @@
placeholder: t('.search_placeholder')
#ordergroupsTable
= render :partial => "ordergroups"
= render :partial => "ordergroups"

View File

@ -590,8 +590,10 @@ en:
balance: 'Balance of account: %{balance}'
last_updated_at: (last updated %{when} ago)
new_transaction: Create new transaction
search_placeholder: Search ...
title: Account statement for %{name}
index_collection:
title: Financial transactions
show_groups: Manage accounts
new:
paragraph: Here you can credit and debit money for the order group <b>%{name}</b>.
title: New transaction
@ -603,6 +605,8 @@ en:
ordergroup:
remove: Remove
remove_group: Remove group
transactions_search:
search_placeholder: Search note ...
index:
amount_fc: Amount(FC)
end: End
@ -633,6 +637,7 @@ en:
index:
new_transaction: Add new transactions
search_placeholder: Search ...
show_all: All transactions
title: Manage accounts
ordergroups:
account_statement: Account statement

View File

@ -588,8 +588,10 @@ nl:
balance: 'Tegoed: %{balance}'
last_updated_at: (laatst bijgewerkt %{when} geleden)
new_transaction: Nieuwe transactie toevoegen
search_placeholder: Zoeken ...
title: Rekeningoverzicht voor %{name}
index_collection:
title: Financiële transacties
show_groups: Tegoeden
new:
paragraph: Hier kun je het tegoed van huishouden <b>%{name}</b> ophogen en verlagen.
title: Nieuwe transactie
@ -601,6 +603,8 @@ nl:
ordergroup:
remove: Verwijderen
remove_group: Huishouden verwijderen
transactions_search:
search_placeholder: Zoeken in notitie...
index:
amount_fc: Bedrag(FC)
end: Einde
@ -631,6 +635,7 @@ nl:
index:
new_transaction: Nieuwe transacties toevoegen
search_placeholder: Zoeken ...
show_all: Transactieoverzicht
title: Tegoeden beheren
ordergroups:
account_statement: Rekeningafschrift

View File

@ -159,6 +159,7 @@ Foodsoft::Application.routes.draw do
resources :ordergroups, :only => [:index] do
resources :financial_transactions, :as => :transactions
end
get 'transactions' => 'financial_transactions#index_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'

View 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