Class: Einvoicing::Tax
- Inherits:
-
Data
- Object
- Data
- Einvoicing::Tax
- Defined in:
- lib/einvoicing/tax.rb
Overview
VAT breakdown entry for a single tax rate.
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#rate ⇒ Object
readonly
Returns the value of attribute rate.
-
#tax_amount ⇒ Object
readonly
Returns the value of attribute tax_amount.
-
#taxable_amount ⇒ Object
readonly
Returns the value of attribute taxable_amount.
Class Method Summary collapse
-
.category_code_for(rate:, category: nil) ⇒ Object
Shared lookup used by both Tax and LineItem.
Instance Method Summary collapse
- #category_code ⇒ Object
-
#initialize(rate:, taxable_amount:, tax_amount:, category: nil) ⇒ Tax
constructor
A new instance of Tax.
- #rate_percent ⇒ Object
Constructor Details
#initialize(rate:, taxable_amount:, tax_amount:, category: nil) ⇒ Tax
Returns a new instance of Tax.
13 14 15 16 17 |
# File 'lib/einvoicing/tax.rb', line 13 def initialize(rate:, taxable_amount:, tax_amount:, category: nil) raise ArgumentError, Einvoicing::I18n.t("tax.invalid_rate", rate: rate) if rate.to_f.negative? super end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category
8 9 10 |
# File 'lib/einvoicing/tax.rb', line 8 def category @category end |
#rate ⇒ Object (readonly)
Returns the value of attribute rate
8 9 10 |
# File 'lib/einvoicing/tax.rb', line 8 def rate @rate end |
#tax_amount ⇒ Object (readonly)
Returns the value of attribute tax_amount
8 9 10 |
# File 'lib/einvoicing/tax.rb', line 8 def tax_amount @tax_amount end |
#taxable_amount ⇒ Object (readonly)
Returns the value of attribute taxable_amount
8 9 10 |
# File 'lib/einvoicing/tax.rb', line 8 def taxable_amount @taxable_amount end |
Class Method Details
.category_code_for(rate:, category: nil) ⇒ Object
Shared lookup used by both Tax and LineItem.
20 21 22 23 24 25 26 |
# File 'lib/einvoicing/tax.rb', line 20 def self.category_code_for(rate:, category: nil) if rate.to_f == 0.0 category == :reverse_charge ? "AE" : "Z" else "S" end end |
Instance Method Details
#category_code ⇒ Object
28 29 30 |
# File 'lib/einvoicing/tax.rb', line 28 def category_code Tax.category_code_for(rate: rate, category: category) end |
#rate_percent ⇒ Object
32 33 34 35 36 |
# File 'lib/einvoicing/tax.rb', line 32 def rate_percent return BigDecimal("0") if category == :reverse_charge (BigDecimal(rate.to_s) * 100).round(2) end |