Sha256: 1e4ecf923590def55d1fd6e445e21589eb1c2e323d39393d0f88e6bb2c8f519b
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
class Taxedo::Receipt attr_accessor :currency def initialize(region_id, amount) @region_id = region_id @amount = amount @taxes = [] load_translations end def add_tax(id, rate) tax = Taxedo::Tax.new(id) tax.name = tax_name(id) tax.rate = rate tax.source_amount = (@taxes.empty? ? @amount : @taxes.last.subtotal) @taxes << tax end def language defined?(I18n) ? I18n.locale.to_s : 'fr' end def subtotal @amount end def t(path) text = @translations path.split('.').each do |p| raise "TAXEDO: No #{language} translation for #{path}." if not text text = text[p] end return text.to_s end def taxes @taxes end def total @total = subtotal @taxes.each { |t| @total += t.amount } return @total end def to_hash Taxedo::Builder::Hash.new(self).generate end def to_html(options={}) options = { columns: 0, custom_content: '', template: :table }.merge(options) return Taxedo::Builder::Html.new(self).generate(options[:template], options) end def to_json Taxedo::Builder::Json.new(self).generate end def to_text Taxedo::Builder::Text.new(self).generate end private def load_translations @translations = YAML.load_file(Taxedo.base_languages_path + "#{language}.yml")['taxedo'][language] end def tax_name(tax_id) t("regions.#{@region_id}.taxes.#{tax_id}.short") end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
taxedo-0.0.4 | lib/taxedo/receipt.rb |