Class: FacturX::Line
- Inherits:
-
Object
- Object
- FacturX::Line
- Defined in:
- lib/factur_x/line.rb
Instance Attribute Summary collapse
-
#accounting_reference ⇒ Object
readonly
Returns the value of attribute accounting_reference.
-
#buyer_item_id ⇒ Object
readonly
Returns the value of attribute buyer_item_id.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#global_id ⇒ Object
readonly
Returns the value of attribute global_id.
-
#global_id_scheme ⇒ Object
readonly
Returns the value of attribute global_id_scheme.
-
#gross_unit_price ⇒ Object
readonly
Returns the value of attribute gross_unit_price.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#net_amount ⇒ Object
readonly
Returns the value of attribute net_amount.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#order_line_id ⇒ Object
readonly
Returns the value of attribute order_line_id.
-
#origin_country ⇒ Object
readonly
Returns the value of attribute origin_country.
-
#period_end ⇒ Object
readonly
Returns the value of attribute period_end.
-
#period_start ⇒ Object
readonly
Returns the value of attribute period_start.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
-
#seller_item_id ⇒ Object
readonly
Returns the value of attribute seller_item_id.
-
#unit_code ⇒ Object
readonly
Returns the value of attribute unit_code.
-
#unit_discount ⇒ Object
readonly
Returns the value of attribute unit_discount.
-
#unit_price ⇒ Object
readonly
Returns the value of attribute unit_price.
-
#vat_amount ⇒ Object
readonly
Returns the value of attribute vat_amount.
-
#vat_category ⇒ Object
readonly
Returns the value of attribute vat_category.
-
#vat_rate ⇒ Object
readonly
Returns the value of attribute vat_rate.
Instance Method Summary collapse
- #gross_price? ⇒ Boolean
-
#initialize(name:, unit_price:, quantity:, net_amount:, number: nil, description: nil, seller_item_id: nil, buyer_item_id: nil, global_id: nil, global_id_scheme: nil, gross_unit_price: nil, unit_discount: nil, unit_code: Codes::PIECE_UNIT, vat_category: Codes::VatCategory::STANDARD, vat_rate: nil, vat_amount: nil, note: nil, origin_country: nil, period_start: nil, period_end: nil, order_line_id: nil, accounting_reference: nil) ⇒ Line
constructor
A new instance of Line.
- #net_amount_decimal ⇒ Object
-
#tax_key ⇒ Object
Groups lines into VAT breakdowns: BR-S-08 and friends require one breakdown per (category, rate) pair.
- #to_h ⇒ Object
- #vat_rate_decimal ⇒ Object
- #with_number(value) ⇒ Object
Constructor Details
#initialize(name:, unit_price:, quantity:, net_amount:, number: nil, description: nil, seller_item_id: nil, buyer_item_id: nil, global_id: nil, global_id_scheme: nil, gross_unit_price: nil, unit_discount: nil, unit_code: Codes::PIECE_UNIT, vat_category: Codes::VatCategory::STANDARD, vat_rate: nil, vat_amount: nil, note: nil, origin_country: nil, period_start: nil, period_end: nil, order_line_id: nil, accounting_reference: nil) ⇒ Line
Returns a new instance of Line.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/factur_x/line.rb', line 14 def initialize(name:, unit_price:, quantity:, net_amount:, number: nil, description: nil, seller_item_id: nil, buyer_item_id: nil, global_id: nil, global_id_scheme: nil, gross_unit_price: nil, unit_discount: nil, unit_code: Codes::PIECE_UNIT, vat_category: Codes::VatCategory::STANDARD, vat_rate: nil, vat_amount: nil, note: nil, origin_country: nil, period_start: nil, period_end: nil, order_line_id: nil, accounting_reference: nil) @number = number @name = name @description = description @seller_item_id = seller_item_id @buyer_item_id = buyer_item_id @global_id = global_id @global_id_scheme = global_id_scheme @unit_price = unit_price @gross_unit_price = gross_unit_price @unit_discount = unit_discount @quantity = quantity @unit_code = unit_code @vat_category = vat_category @vat_rate = vat_rate @vat_amount = vat_amount @net_amount = net_amount @note = note @origin_country = origin_country @period_start = period_start @period_end = period_end @order_line_id = order_line_id @accounting_reference = accounting_reference end |
Instance Attribute Details
#accounting_reference ⇒ Object (readonly)
Returns the value of attribute accounting_reference.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def accounting_reference @accounting_reference end |
#buyer_item_id ⇒ Object (readonly)
Returns the value of attribute buyer_item_id.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def buyer_item_id @buyer_item_id end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def description @description end |
#global_id ⇒ Object (readonly)
Returns the value of attribute global_id.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def global_id @global_id end |
#global_id_scheme ⇒ Object (readonly)
Returns the value of attribute global_id_scheme.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def global_id_scheme @global_id_scheme end |
#gross_unit_price ⇒ Object (readonly)
Returns the value of attribute gross_unit_price.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def gross_unit_price @gross_unit_price end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def name @name end |
#net_amount ⇒ Object (readonly)
Returns the value of attribute net_amount.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def net_amount @net_amount end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def note @note end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def number @number end |
#order_line_id ⇒ Object (readonly)
Returns the value of attribute order_line_id.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def order_line_id @order_line_id end |
#origin_country ⇒ Object (readonly)
Returns the value of attribute origin_country.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def origin_country @origin_country end |
#period_end ⇒ Object (readonly)
Returns the value of attribute period_end.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def period_end @period_end end |
#period_start ⇒ Object (readonly)
Returns the value of attribute period_start.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def period_start @period_start end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def quantity @quantity end |
#seller_item_id ⇒ Object (readonly)
Returns the value of attribute seller_item_id.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def seller_item_id @seller_item_id end |
#unit_code ⇒ Object (readonly)
Returns the value of attribute unit_code.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def unit_code @unit_code end |
#unit_discount ⇒ Object (readonly)
Returns the value of attribute unit_discount.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def unit_discount @unit_discount end |
#unit_price ⇒ Object (readonly)
Returns the value of attribute unit_price.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def unit_price @unit_price end |
#vat_amount ⇒ Object (readonly)
Returns the value of attribute vat_amount.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def vat_amount @vat_amount end |
#vat_category ⇒ Object (readonly)
Returns the value of attribute vat_category.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def vat_category @vat_category end |
#vat_rate ⇒ Object (readonly)
Returns the value of attribute vat_rate.
8 9 10 |
# File 'lib/factur_x/line.rb', line 8 def vat_rate @vat_rate end |
Instance Method Details
#gross_price? ⇒ Boolean
59 60 61 |
# File 'lib/factur_x/line.rb', line 59 def gross_price? !gross_unit_price.nil? end |
#net_amount_decimal ⇒ Object
45 46 47 |
# File 'lib/factur_x/line.rb', line 45 def net_amount_decimal Formatting.decimal(net_amount) end |
#tax_key ⇒ Object
Groups lines into VAT breakdowns: BR-S-08 and friends require one breakdown per (category, rate) pair.
55 56 57 |
# File 'lib/factur_x/line.rb', line 55 def tax_key [vat_category, vat_rate_decimal] end |
#to_h ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/factur_x/line.rb', line 69 def to_h { number: number, name: name, description: description, seller_item_id: seller_item_id, buyer_item_id: buyer_item_id, global_id: global_id, global_id_scheme: global_id_scheme, unit_price: unit_price, gross_unit_price: gross_unit_price, unit_discount: unit_discount, quantity: quantity, unit_code: unit_code, vat_category: vat_category, vat_rate: vat_rate, vat_amount: vat_amount, net_amount: net_amount, note: note, origin_country: origin_country, period_start: period_start, period_end: period_end, order_line_id: order_line_id, accounting_reference: accounting_reference } end |
#vat_rate_decimal ⇒ Object
49 50 51 |
# File 'lib/factur_x/line.rb', line 49 def vat_rate_decimal Formatting.decimal(vat_rate || 0) end |
#with_number(value) ⇒ Object
63 64 65 66 67 |
# File 'lib/factur_x/line.rb', line 63 def with_number(value) return self if number self.class.new(**to_h, number: value) end |