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.
-
#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) ⇒ 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) ⇒ LineItem
Returns a new instance of LineItem.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/einvoicing/line_item.rb', line 17 def initialize(description:, quantity:, unit_price:, vat_rate: 0.20, unit: "C62", category: nil) super( description: description, quantity: BigDecimal(quantity.to_s), unit_price: BigDecimal(unit_price.to_s), vat_rate: vat_rate, unit: unit, category: category ) 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 |
#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).
39 40 41 |
# File 'lib/einvoicing/line_item.rb', line 39 def gross_amount (net_amount + vat_amount).round(2, :half_up) end |
#net_amount ⇒ Object
Net line total (excluding VAT).
29 30 31 |
# File 'lib/einvoicing/line_item.rb', line 29 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.
50 51 52 |
# File 'lib/einvoicing/line_item.rb', line 50 def tax_category_code Tax.category_code_for(rate: vat_rate, category: category) end |
#vat_amount ⇒ Object
VAT amount for this line.
34 35 36 |
# File 'lib/einvoicing/line_item.rb', line 34 def vat_amount (net_amount * BigDecimal(vat_rate.to_s)).round(2, :half_up) end |
#vat_rate_percent ⇒ Object
43 44 45 46 47 |
# File 'lib/einvoicing/line_item.rb', line 43 def vat_rate_percent return BigDecimal("0") if category == :reverse_charge (BigDecimal(vat_rate.to_s) * 100).round(2) end |