Moved financial_transaction into the new finance-namespace.

This commit is contained in:
Benjamin Meichsner 2009-01-10 21:28:22 +01:00
parent 1d85b880f2
commit c282cae79c
19 changed files with 167 additions and 153 deletions

View file

@ -0,0 +1,110 @@
class Finance::TransactionsController < ApplicationController
before_filter :authenticate_finance
def index
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
@per_page = params[:per_page].to_i
else
@per_page = 20
end
if params["sort"]
sort = case params["sort"]
when "name" then "name"
when "size" then "actual_size"
when "account_balance" then "account_balance"
when "name_reverse" then "name DESC"
when "size_reverse" then "actual_size DESC"
when "account_balance_reverse" then "account_balance DESC"
end
else
sort = "name"
end
conditions = "name LIKE '%#{params[:query]}%'" unless params[:query].nil?
@total = OrderGroup.count(:conditions => conditions)
@groups = OrderGroup.paginate :conditions => conditions, :page => params[:page], :per_page => @per_page, :order => sort
respond_to do |format|
format.html
format.js do
render :update do |page|
page.replace_html 'table', :partial => "ordergroups"
end
end
end
end
def list
@group = OrderGroup.find(params[:id])
if params['sort']
sort = case params['sort']
when "date" then "created_on"
when "note" then "note"
when "amount" then "amount"
when "date_reverse" then "created_on DESC"
when "note_reverse" then "note DESC"
when "amount_reverse" then "amount DESC"
end
else
sort = "created_on DESC"
end
conditions = ["note LIKE ?", "%#{params[:query]}%"] unless params[:query].nil?
@total = @group.financial_transactions.count(:conditions => conditions)
@financial_transactions = @group.financial_transactions.paginate(:page => params[:page],
:per_page => 10,
:conditions => conditions,
:order => sort)
respond_to do |format|
format.html
format.js do
render :update do |page|
page.replace_html 'table', :partial => "list"
end
end
end
end
def new
@group = OrderGroup.find(params[:id])
@financial_transaction = @group.financial_transactions.build
end
def create
@group = OrderGroup.find(params[:financial_transaction][:order_group_id])
amount = params[:financial_transaction][:amount]
note = params[:financial_transaction][:note]
begin
@group.addFinancialTransaction(amount, note, @current_user)
flash[:notice] = 'Transaktion erfolgreich angelegt.'
redirect_to :action => 'index'
rescue => e
@financial_transaction = FinancialTransaction.new(params[:financial_transaction])
flash.now[:error] = 'Transaktion konnte nicht angelegt werden!' + ' (' + e.message + ')'
render :action => 'new'
end
end
def new_collection
end
def create_collection
note = params[:note]
raise "Note is required!" if note.blank?
params[:financial_transactions].each do |trans|
# ignore empty amount fields ...
unless trans[:amount].blank?
OrderGroup.find(trans[:order_group_id]).addFinancialTransaction trans[:amount], note, @current_user
end
end
flash[:notice] = 'Saved all transactions successfully'
redirect_to :action => 'index'
rescue => error
flash[:error] = "An error occured: " + error.to_s
redirect_to :action => 'new_collection'
end
end

View file

@ -15,123 +15,6 @@ class FinanceController < ApplicationController
@unpaid_invoices = Invoice.unpaid
end
#list all ordergroups
def listOrdergroups
@user = @current_user
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
@per_page = params[:per_page].to_i
else
@per_page = 20
end
if params["sort"]
sort = case params["sort"]
when "name" then "name"
when "size" then "actual_size"
when "account_balance" then "account_balance"
when "name_reverse" then "name DESC"
when "size_reverse" then "actual_size DESC"
when "account_balance_reverse" then "account_balance DESC"
end
else
sort = "name"
end
conditions = "name LIKE '%#{params[:query]}%'" unless params[:query].nil?
@total = OrderGroup.count(:conditions => conditions)
@groups = OrderGroup.paginate :conditions => conditions, :page => params[:page], :per_page => @per_page, :order => sort
respond_to do |format|
format.html # listOrdergroups.haml
format.js do
render :update do |page|
page.replace_html 'table', :partial => "listOrdergroups" # _listOrdergroups.haml
end
end
end
end
#new financial transactions (ordergroups)
def newTransaction
@group = OrderGroup.find(params[:id])
@financial_transaction = FinancialTransaction.new(:order_group => @group)
render :template => 'financial_transactions/new'
end
#save the new financial transaction and update the account_balance of the ordergroup
def createTransaction
@group = OrderGroup.find(params[:id])
amount = params[:financial_transaction][:amount]
note = params[:financial_transaction][:note]
begin
@group.addFinancialTransaction(amount, note, @current_user)
flash[:notice] = MSG_TRANSACTION_SUCCESS
redirect_to :action => 'listTransactions', :id => @group
rescue => e
@financial_transaction = FinancialTransaction.new(params[:financial_transaction])
flash.now[:error] = ERROR_TRANSACTION_FAILED + ' (' + e.message + ')'
render :template => 'financial_transactions/new'
end
end
# list transactions of a specific ordergroup
def listTransactions
@group = Group.find(params[:id])
if params['sort']
sort = case params['sort']
when "date" then "created_on"
when "note" then "note"
when "amount" then "amount"
when "date_reverse" then "created_on DESC"
when "note_reverse" then "note DESC"
when "amount_reverse" then "amount DESC"
end
else
sort = "created_on DESC"
end
conditions = ["note LIKE ?", "%#{params[:query]}%"] unless params[:query].nil?
@total = @group.financial_transactions.count(:conditions => conditions)
@financial_transactions = @group.financial_transactions.paginate(:page => params[:page],
:per_page => 10,
:conditions => conditions,
:order => sort)
respond_to do |format|
format.html {render :template => 'financial_transactions/list'}
format.js do
render :update do |page|
page.replace_html 'table', :partial => "financial_transactions/list"
end
end
end
end
# gives a view to add multiple transactions to different groups
# e.g. this is helpful when updating multiple accounts in case of a new statement
def new_transactions
end
# creates multiple transactions at once
def create_transactions
begin
note = params[:note]
raise _("Note is required!") if note.blank?
params[:financial_transactions].each do |trans|
# ignore empty amount fields ...
unless trans[:amount].blank?
OrderGroup.find(trans[:order_group_id]).addFinancialTransaction trans[:amount], note, @current_user
end
end
flash[:notice] = _('Saved all transactions successfully')
redirect_to :action => 'index'
rescue => error
flash[:error] = _("An error occured: ") + error.to_s
redirect_to :action => 'new_transactions'
end
end
# list finished orders for the order-clearing
def listOrders
@orders = Order.paginate_all_by_finished true, :page => params[:page], :per_page => 10, :order => 'ends DESC'

View file

@ -0,0 +1,2 @@
module Finance::TransactionsHelper
end

View file

@ -19,7 +19,7 @@ class FinancialTransaction < ActiveRecord::Base
validates_presence_of :note, :user_id, :order_group_id
validates_numericality_of :amount
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
def amount=(amount)
self[:amount] = String.delocalized_decimal(amount)

View file

@ -19,10 +19,10 @@
%tbody
- for group in @groups
%tr{:class => cycle('even','odd', :name => 'groups')}
%td= @current_user.role_admin? ? link_to(group.name, {:controller => 'admin', :action => 'showGroup', :id => group}, {:title => _("Show ordergroup")}) : group.name
%td= group.name
%td= group.actual_size
%td{:class => "currency", :style => "width:5em"}= number_to_currency(group.account_balance)
%td{:class => "actions"}
= link_to image_tag("euro_new.png", :size => "16x16", :alt => _("New transaction"), :border => "0"), {:action => 'newTransaction', :id => group}, {:title => _("New transaction")}
= link_to image_tag("b_browse.png", :size => "16x16", :border => "0", :alt => 'Kontoauszug'), {:action => 'listTransactions', :id => group}, {:title => _("List transactions")}
= link_to image_tag("euro_new.png", :size => "16x16", :alt => _("New transaction"), :border => "0"), {:action => 'new', :id => group}, {:title => _("New transaction")}
= link_to image_tag("b_browse.png", :size => "16x16", :border => "0", :alt => 'Kontoauszug'), {:action => 'list', :id => group}, {:title => _("List transactions")}

View file

@ -0,0 +1,2 @@
<h1>Finance::Transactions#create</h1>
<p>Find me in app/views/finance/transactions/create.html.erb</p>

View file

@ -0,0 +1,2 @@
<h1>Finance::Transactions#create_collection</h1>
<p>Find me in app/views/finance/transactions/create_collection.html.erb</p>

View file

@ -1,8 +1,9 @@
- title _("Manage accounts")
%h1 Manage accounts
%p
%i
=_ "To create multiple transactions at once please follow this "
= link_to _("link"), :action => 'new_transactions'
= link_to _("link"), :action => 'new_collection'
.left_column{:style=>"width:50em"}
.box_title
%h2=_ "Ordergroups"
@ -15,10 +16,10 @@
= observe_field 'query', :frequency => 2, |
:before => "Element.show('loader')", |
:success => "Element.hide('loader')", |
:url => {:action => 'listOrdergroups'}, |
:url => {:action => 'index'}, |
:with => 'query' |
#table
= render :partial => "listOrdergroups"
= render :partial => "ordergroups"
%br/
- if @current_user.role_admin?
= link_to _("New ordergroup"), :controller => 'admin', :action => 'newOrderGroup'

View file

@ -1,4 +1,5 @@
<h1>Kontoauszug für <%= @group.name %></h1>
<% title "Kontoauszug für #{@group.name}" %>
<p>
<b>Kontostand: <%= number_to_currency(@group.account_balance) -%></b>
<span style="color:grey">(zuletzt aktualisiert vor <%= distance_of_time_in_words(Time.now, @group.account_updated) -%>)</span>
@ -13,12 +14,12 @@
<%= observe_field 'query', :frequency => 2,
:before => "Element.show('loader')",
:success => "Element.hide('loader')",
:url => {:action => 'listTransactions'},
:url => {:action => 'list'},
:with => 'query' %>
<div id="table">
<%= render :partial => "/financial_transactions/list" %>
<%= render :partial => "list" %>
</div>
<p><%= link_to 'Neue Transaktion', :action => 'newTransaction', :id => @group %></p>
<p><%= link_to 'Neue Transaktion', :action => 'new', :id => @group %></p>
</div>
<%= link_to 'Gruppenübersicht', :action => 'index' %>
</div>
<%= link_to 'Bestellgruppen', :controller => 'finance', :action => "listOrdergroups" %>

View file

@ -0,0 +1,21 @@
%h1 New transaction
.edit_form{ :style => "width:30em" }
- form_for(@financial_transaction, :url => { :action => 'create' }) do |f|
= f.error_messages
= f.hidden_field :order_group_id
%p
Group:
%b=h @group.name
%p
= f.label :amount
%br/
= f.text_field :amount, :size => 10
%p
= f.label :note
%br/
= f.text_area :note, :cols => 40, :rows => 5
%p
= submit_tag "Save"
= link_to "Back", :controller => 'transactions'

View file

@ -0,0 +1,2 @@
<h1>Finance::Transactions#new_collection</h1>
<p>Find me in app/views/finance/transactions/new_collection.html.erb</p>

View file

@ -1,6 +1,6 @@
- title _("Update multiple accounts")
- form_tag :action => "create_transactions" do
- form_tag :action => "create_collection" do
%p
%b= _("Note") + ":"
= text_field_tag "note"
@ -17,4 +17,4 @@
%p
= submit_tag _("Save")
|
= link_to _("Cancel"), :action => 'listOrdergroups'
= link_to _("Cancel"), :controller => 'finance/transactions'

View file

@ -1,10 +0,0 @@
<%= error_messages_for 'financial_transaction' %>
<div class="edit_form" style="width:30em">
<p><b><%=h @group.name %></b>
<p><label for="financial_transaction_amount">Betrag</label>
<%= text_field 'financial_transaction', 'amount', :size => '10' %> Euro</p>
<p><label for="financial_transaction_note">Note</label><br/>
<%= text_area 'financial_transaction', 'note', :cols => "40", :rows => "5" %></p>
</div>

View file

@ -1,9 +0,0 @@
<h1>Neue Transaktion</h1>
<% form_tag(:action => 'createTransaction', :id => @group) do -%>
<%= render :partial => 'financial_transactions/form' %>
<%= submit_tag 'Speichern' %>
<%= hidden_field 'financial_transaction', 'order_group_id' %>
<% end -%>
<br />
<%= link_to 'Zurück', :controller => 'finance' %>

View file

@ -26,10 +26,10 @@
{ :name => "Suppliers", :url => suppliers_path, :access? => (u.role_suppliers?) }
]
},
{ :name => "Finance", :url => "/finance", :active => ["finance", "invoices"],
{ :name => "Finance", :url => "/finance", :active => ["finance", "invoices", "transactions"],
:access? => (u.role_finance?),
:subnav => [
{ :name => "Ordergroups", :url => "/finance/listOrdergroups" },
{ :name => "Manage accounts", :url => "/finance/transactions" },
{ :name => "Balance orders", :url => "/finance/listOrders" },
{ :name => "Invoices", :url => finance_invoices_path }
]

View file

@ -2,6 +2,7 @@ ActionController::Routing::Routes.draw do |map|
map.namespace :finance do |finance|
finance.resources :invoices
finance.connect 'transactions/:action/:id', :controller => 'transactions'
end
#map.resources :invoices

View file

@ -0,0 +1,8 @@
require 'test_helper'
class Finance::TransactionsControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end