Class: Taxedo::Receipt
- Inherits:
-
Object
- Object
- Taxedo::Receipt
- Defined in:
- lib/taxedo/receipt.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#equation_type ⇒ Object
Returns the value of attribute equation_type.
Instance Method Summary collapse
- #add_tax(id, rate) ⇒ Object
- #get_source_amount ⇒ Object
-
#initialize(region_id, amount) ⇒ Receipt
constructor
A new instance of Receipt.
- #language ⇒ Object
- #subtotal ⇒ Object
- #t(path) ⇒ Object
- #taxes ⇒ Object
- #to_hash ⇒ Object
- #to_html(options = {}) ⇒ Object
- #to_json ⇒ Object
- #to_text ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(region_id, amount) ⇒ Receipt
Returns a new instance of Receipt.
5 6 7 8 9 10 11 |
# File 'lib/taxedo/receipt.rb', line 5 def initialize(region_id, amount) @region_id = region_id @amount = amount @taxes = [] load_translations end |
Instance Attribute Details
#currency ⇒ Object
Returns the value of attribute currency.
2 3 4 |
# File 'lib/taxedo/receipt.rb', line 2 def currency @currency end |
#equation_type ⇒ Object
Returns the value of attribute equation_type.
3 4 5 |
# File 'lib/taxedo/receipt.rb', line 3 def equation_type @equation_type end |
Instance Method Details
#add_tax(id, rate) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/taxedo/receipt.rb', line 13 def add_tax(id, rate) tax = Taxedo::Tax.new(id) tax.name = tax_name(id) tax.rate = rate tax.source_amount = get_source_amount @taxes << tax end |
#get_source_amount ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/taxedo/receipt.rb', line 22 def get_source_amount if @taxes.empty? or self.equation_type == 'separated' @amount else @taxes.last.subtotal end end |
#language ⇒ Object
30 31 32 |
# File 'lib/taxedo/receipt.rb', line 30 def language defined?(I18n) ? I18n.locale.to_s : 'fr' end |
#subtotal ⇒ Object
34 35 36 |
# File 'lib/taxedo/receipt.rb', line 34 def subtotal @amount end |
#t(path) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/taxedo/receipt.rb', line 38 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 |
#taxes ⇒ Object
49 50 51 |
# File 'lib/taxedo/receipt.rb', line 49 def taxes @taxes end |
#to_hash ⇒ Object
60 61 62 |
# File 'lib/taxedo/receipt.rb', line 60 def to_hash Taxedo::Builder::Hash.new(self).generate end |
#to_html(options = {}) ⇒ Object
64 65 66 67 68 |
# File 'lib/taxedo/receipt.rb', line 64 def to_html(={}) = { columns: 0, custom_content: '', template: :table }.merge() return Taxedo::Builder::Html.new(self).generate([:template], ) end |
#to_json ⇒ Object
70 71 72 |
# File 'lib/taxedo/receipt.rb', line 70 def to_json Taxedo::Builder::Json.new(self).generate end |
#to_text ⇒ Object
74 75 76 |
# File 'lib/taxedo/receipt.rb', line 74 def to_text Taxedo::Builder::Text.new(self).generate end |
#total ⇒ Object
53 54 55 56 57 58 |
# File 'lib/taxedo/receipt.rb', line 53 def total @total = subtotal @taxes.each { |t| @total += t.amount } return @total end |