Class: Einvoicing::LineItem
- Inherits:
-
Data
- Object
- Data
- Einvoicing::LineItem
- Defined in:
- lib/einvoicing/line_item.rb
Overview
A single line on an invoice.
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#exemption_reason ⇒ Object
readonly
Returns the value of attribute exemption_reason.
-
#exemption_reason_code ⇒ Object
readonly
Returns the value of attribute exemption_reason_code.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
-
#unit_price ⇒ Object
readonly
Returns the value of attribute unit_price.
-
#vat_rate ⇒ Object
readonly
Returns the value of attribute vat_rate.
Instance Method Summary collapse
-
#gross_amount ⇒ Object
Gross line total (including VAT).
-
#initialize(description:, quantity:, unit_price:, vat_rate: 0.20, unit: "C62", category: nil, exemption_reason: nil, exemption_reason_code: nil) ⇒ LineItem
constructor
A new instance of LineItem.
-
#net_amount ⇒ Object
Net line total (excluding VAT).
-
#tax_category_code ⇒ Object
CII/UBL tax category code — delegates to shared Tax logic.
-
#vat_amount ⇒ Object
VAT amount for this line.
- #vat_rate_percent ⇒ Object
Constructor Details
#initialize(description:, quantity:, unit_price:, vat_rate: 0.20, unit: "C62", category: nil, exemption_reason: nil, exemption_reason_code: nil) ⇒ LineItem
Returns a new instance of LineItem.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/einvoicing/line_item.rb', line 23 def initialize(description:, quantity:, unit_price:, vat_rate: 0.20, unit: "C62", category: nil, exemption_reason: nil, exemption_reason_code: nil) super( description: description, quantity: BigDecimal(quantity.to_s), unit_price: BigDecimal(unit_price.to_s), vat_rate: vat_rate, unit: unit, category: category, exemption_reason: exemption_reason, exemption_reason_code: exemption_reason_code ) end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category
16 17 18 |
# File 'lib/einvoicing/line_item.rb', line 16 def category @category end |
#description ⇒ Object (readonly)
Returns the value of attribute description
16 17 18 |
# File 'lib/einvoicing/line_item.rb', line 16 def description @description end |
#exemption_reason ⇒ Object (readonly)
Returns the value of attribute exemption_reason
16 17 18 |
# File 'lib/einvoicing/line_item.rb', line 16 def exemption_reason @exemption_reason end |
#exemption_reason_code ⇒ Object (readonly)
Returns the value of attribute exemption_reason_code
16 17 18 |
# File 'lib/einvoicing/line_item.rb', line 16 def exemption_reason_code @exemption_reason_code end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity
16 17 18 |
# File 'lib/einvoicing/line_item.rb', line 16 def quantity @quantity end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit
16 17 18 |
# File 'lib/einvoicing/line_item.rb', line 16 def unit @unit end |
#unit_price ⇒ Object (readonly)
Returns the value of attribute unit_price
16 17 18 |
# File 'lib/einvoicing/line_item.rb', line 16 def unit_price @unit_price end |
#vat_rate ⇒ Object (readonly)
Returns the value of attribute vat_rate
16 17 18 |
# File 'lib/einvoicing/line_item.rb', line 16 def vat_rate @vat_rate end |
Instance Method Details
#gross_amount ⇒ Object
Gross line total (including VAT).
48 49 50 |
# File 'lib/einvoicing/line_item.rb', line 48 def gross_amount (net_amount + vat_amount).round(2, :half_up) end |
#net_amount ⇒ Object
Net line total (excluding VAT).
38 39 40 |
# File 'lib/einvoicing/line_item.rb', line 38 def net_amount (quantity * unit_price).round(2, :half_up) end |
#tax_category_code ⇒ Object
CII/UBL tax category code — delegates to shared Tax logic.
57 58 59 |
# File 'lib/einvoicing/line_item.rb', line 57 def tax_category_code Tax.category_code_for(rate: vat_rate, category: category) end |
#vat_amount ⇒ Object
VAT amount for this line. Exempt / reverse-charge categories bill 0 %.
43 44 45 |
# File 'lib/einvoicing/line_item.rb', line 43 def vat_amount (net_amount * Tax.effective_rate(rate: vat_rate, category: category)).round(2, :half_up) end |
#vat_rate_percent ⇒ Object
52 53 54 |
# File 'lib/einvoicing/line_item.rb', line 52 def vat_rate_percent (Tax.effective_rate(rate: vat_rate, category: category) * 100).round(2) end |