module YeshouaCrm::MoneyHelper

Public Instance Methods

all_currencies() click to toggle source
# File lib/yeshoua_crm/money_helper.rb, line 41
def all_currencies
  Currency.table.inject([]) do |array, (id, attributes)|
    array ||= []
    array << ["#{attributes[:name]}" + (attributes[:symbol].blank? ? "" : " (#{attributes[:symbol]})"), attributes[:iso_code]]
    array
  end.sort{|x, y| x[0] <=> y[0]}
end
collection_for_currencies_select(default_currency = 'BRL', major_currencies = %w(BRL USD EUR GBP RUB CHF)) click to toggle source
# File lib/yeshoua_crm/money_helper.rb, line 31
def collection_for_currencies_select(default_currency = 'BRL', major_currencies = %w(BRL USD EUR GBP RUB CHF))
  currencies = []
  currencies << default_currency.to_s unless default_currency.blank?
  currencies |= major_currencies
  currencies.map do |c|
    currency = YeshouaCrm::Currency.find(c)
    ["#{currency.iso_code} (#{currency.symbol})", currency.iso_code] if currency
  end.compact.uniq
end
deal_currency_icon(currency) click to toggle source
# File lib/yeshoua_crm/money_helper.rb, line 18
def deal_currency_icon(currency)
  case currency.to_s.upcase
  when 'EUR'
    "icon-money-euro"
  when 'GBP'
    "icon-money-pound"
  when 'JPY'
    "icon-money-yen"
  else
    "icon-money-dollar"
  end
end
object_price(obj, price_field = :price, options = {}) click to toggle source
# File lib/yeshoua_crm/money_helper.rb, line 6
def object_price(obj, price_field = :price, options = {})
  options.merge!({:symbol => true})
  price_to_currency(obj.try(price_field), obj.currency, options).to_s if obj.respond_to?(:currency)
end
price_to_currency(price, currency="BRL", options={}) click to toggle source
# File lib/yeshoua_crm/money_helper.rb, line 49
def price_to_currency(price, currency="BRL", options={})
  return '' if price.blank?

  currency = "BRL" unless currency.is_a?(String)
  currency = YeshouaCrm::Currency.find(currency)

  return YeshouaCrm::Currency.format(price.to_f, currency, options)# if currency
  price.to_s
end
prices_collection_by_currency(prices_collection, options={}) click to toggle source
# File lib/yeshoua_crm/money_helper.rb, line 11
def prices_collection_by_currency(prices_collection, options={})
  return [] if prices_collection.blank? || prices_collection == 0
  prices = prices_collection
  prices.reject!{|k, v| v.to_i == 0} if options[:hide_zeros]
  prices.collect{|k, v| content_tag(:span, price_to_currency(v, k, :symbol => true), :style => "white-space: nowrap;")}.compact
end