Class: Facturae::Line

Inherits:
Object
  • Object
show all
Includes:
Validatable
Defined in:
lib/facturae/models/line.rb

Overview

Represents a line in an invoice.

Constant Summary collapse

UNIT_DEFAULT =

Default unit of measure code (units)

"01"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

#errors, #valid?

Constructor Details

#initialize(item_description:, quantity:, unit_price_without_tax:, total_cost:, **options) ⇒ Line

Returns a new instance of Line.



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/facturae/models/line.rb', line 30

def initialize(item_description:, quantity:, unit_price_without_tax:, total_cost:, **options)
  @item_description = item_description
  @quantity = quantity
  @unit_price_without_tax = unit_price_without_tax
  @total_cost = total_cost
  @article_code = options.fetch(:article_code, nil)
  @unit_of_measure = options.fetch(:unit_of_measure, UNIT_DEFAULT)
  @taxes_output = options.fetch(:taxes_output, [])
  @discounts_and_rebates = []
  @charges = []
  @gross_amount = quantity * unit_price_without_tax
end

Instance Attribute Details

#article_codeString

The article code.

Returns:

  • (String)

    the current value of article_code



13
14
15
# File 'lib/facturae/models/line.rb', line 13

def article_code
  @article_code
end

#chargesArray

The charges.

Returns:

  • (Array)

    the current value of charges



13
14
15
# File 'lib/facturae/models/line.rb', line 13

def charges
  @charges
end

#discounts_and_rebatesArray

The discounts and rebates.

Returns:

  • (Array)

    the current value of discounts_and_rebates



13
14
15
# File 'lib/facturae/models/line.rb', line 13

def discounts_and_rebates
  @discounts_and_rebates
end

#gross_amountFloat

The gross amount.

Returns:

  • (Float)

    the current value of gross_amount



13
14
15
# File 'lib/facturae/models/line.rb', line 13

def gross_amount
  @gross_amount
end

#item_descriptionString

The item description.

Returns:

  • (String)

    the current value of item_description



13
14
15
# File 'lib/facturae/models/line.rb', line 13

def item_description
  @item_description
end

#quantityFloat

The quantity.

Returns:

  • (Float)

    the current value of quantity



13
14
15
# File 'lib/facturae/models/line.rb', line 13

def quantity
  @quantity
end

#taxes_outputObject

Returns the value of attribute taxes_output.



19
20
21
# File 'lib/facturae/models/line.rb', line 19

def taxes_output
  @taxes_output
end

#total_costFloat

The total cost.

Returns:

  • (Float)

    the current value of total_cost



13
14
15
# File 'lib/facturae/models/line.rb', line 13

def total_cost
  @total_cost
end

#unit_of_measureObject

Returns the value of attribute unit_of_measure.



19
20
21
# File 'lib/facturae/models/line.rb', line 19

def unit_of_measure
  @unit_of_measure
end

#unit_price_without_taxFloat

The unit price without tax.

Returns:

  • (Float)

    the current value of unit_price_without_tax



13
14
15
# File 'lib/facturae/models/line.rb', line 13

def unit_price_without_tax
  @unit_price_without_tax
end

Instance Method Details

#add_charge(reason, amount) ⇒ Object



47
48
49
# File 'lib/facturae/models/line.rb', line 47

def add_charge(reason, amount)
  @charges << { reason: reason, amount: amount }
end

#add_discount(reason, amount) ⇒ Object



43
44
45
# File 'lib/facturae/models/line.rb', line 43

def add_discount(reason, amount)
  @discounts_and_rebates << { reason: reason, amount: amount }
end