Add format helper for currency

This commit is contained in:
Patrick Gansterer 2018-09-16 12:05:39 +02:00
parent 5408c08b58
commit 6cc02cb563
7 changed files with 21 additions and 9 deletions

View File

@ -521,3 +521,11 @@ i.package.icon-only {
padding: 15px; padding: 15px;
padding-bottom: 0px; padding-bottom: 0px;
} }
span.positive_amount {
color: black;
}
span.negative_amout {
color: red;
}

View File

@ -19,6 +19,11 @@ module ApplicationHelper
I18n.l(time, :format => format) unless (time.nil? || format.nil?) I18n.l(time, :format => format) unless (time.nil? || format.nil?)
end end
def format_currency(amount)
class_name = amount < 0 ? 'negative_amout' : 'positive_amount'
content_tag :span, number_to_currency(amount), class: class_name
end
# Creates ajax-controlled-links for pagination # Creates ajax-controlled-links for pagination
def pagination_links_remote(collection, options = {}) def pagination_links_remote(collection, options = {})
per_page = options[:per_page] || @per_page per_page = options[:per_page] || @per_page

View File

@ -17,7 +17,7 @@
= format_date item[:date] = format_date item[:date]
%td= item[:type] %td= item[:type]
%td= item[:description] %td= item[:description]
%td.currency{:style => "color:#{item[:amount] < 0 ? 'red' : 'black'}; width:5em"}= number_to_currency(item[:amount]) %td.numeric{style: 'width:5em'}= format_currency item[:amount]
%p %p
= @financial_link.note = @financial_link.note

View File

@ -37,6 +37,6 @@
%td= h t.financial_transaction_type.name %td= h t.financial_transaction_type.name
%td= h t.note %td= h t.note
- FinancialTransactionClass.sorted.each do |c| - FinancialTransactionClass.sorted.each do |c|
%td.currency{:style => "color:#{t.amount < 0 ? 'red' : 'black'}; width:5em"} %td.numeric{style: 'width:5em'}
- if t.financial_transaction_type.financial_transaction_class == c - if t.financial_transaction_type.financial_transaction_class == c
= number_to_currency(t.amount) = format_currency t.amount

View File

@ -36,7 +36,7 @@
%td= format_date(ft.created_on) %td= format_date(ft.created_on)
%td= ft.ordergroup.name %td= ft.ordergroup.name
%td= ft.note %td= ft.note
%td.numeric{:style => "color:#{ft.amount < 0 ? 'red' : 'black'}"}= number_to_currency(ft.amount) %td.numeric= format_currency ft.amount
.span6 .span6
%h2 %h2
= t('.open_transactions') = t('.open_transactions')

View File

@ -17,8 +17,8 @@
%td= ordergroup.contact %td= ordergroup.contact
- FinancialTransactionClass.sorted.each do |c| - FinancialTransactionClass.sorted.each do |c|
- amount = ordergroup["sum_of_class_#{c.id}"] - amount = ordergroup["sum_of_class_#{c.id}"]
%td.numeric{:style => "color:#{amount < 0 ? 'red' : 'black'}"} %td.numeric
= number_to_currency amount = format_currency amount
%td %td
= link_to t('.new_transaction'), new_finance_ordergroup_transaction_path(ordergroup), class: 'btn btn-mini' = link_to t('.new_transaction'), new_finance_ordergroup_transaction_path(ordergroup), class: 'btn btn-mini'
= link_to t('.account_statement'), finance_ordergroup_transactions_path(ordergroup), class: 'btn btn-mini' = link_to t('.account_statement'), finance_ordergroup_transactions_path(ordergroup), class: 'btn btn-mini'

View File

@ -80,11 +80,10 @@
- if FinancialTransactionType.has_multiple_types - if FinancialTransactionType.has_multiple_types
%td= h(ft.financial_transaction_type.name) %td= h(ft.financial_transaction_type.name)
%td= h(ft.note) %td= h(ft.note)
- color = ft.amount < 0 ? 'red' : 'black'
- FinancialTransactionClass.sorted.each do |fc| - FinancialTransactionClass.sorted.each do |fc|
%td{:style => "color:#{color}; width:5em", :class => "currency"} %td.numeric{style: 'width:5em'}
- if ft.financial_transaction_type.financial_transaction_class == fc - if ft.financial_transaction_type.financial_transaction_class == fc
= number_to_currency(ft.amount) = format_currency ft.amount
-# placeholder deface to add content using erb[silent]:contains() -# placeholder deface to add content using erb[silent]:contains()
- '<dashboard_bottom_mark>' - '<dashboard_bottom_mark>'