Class: Croatia::Invoice
- Inherits:
-
Object
- Object
- Croatia::Invoice
- Includes:
- Enum, EInvoicable, Fiscalizable, Payable
- Defined in:
- lib/croatia/invoice.rb
Defined Under Namespace
Modules: EInvoicable, Fiscalizable, Payable Classes: LineItem, Party, Tax
Instance Attribute Summary collapse
-
#business_location_identifier ⇒ Object
Returns the value of attribute business_location_identifier.
- #buyer(&block) ⇒ Object
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#due_date ⇒ Object
Returns the value of attribute due_date.
-
#issue_date ⇒ Object
Returns the value of attribute issue_date.
- #issuer(&block) ⇒ Object
-
#line_items ⇒ Object
Returns the value of attribute line_items.
-
#register_identifier ⇒ Object
Returns the value of attribute register_identifier.
- #seller(&block) ⇒ Object
-
#sequential_number ⇒ Object
Returns the value of attribute sequential_number.
-
#unique_invoice_identifier ⇒ Object
Returns the value of attribute unique_invoice_identifier.
Instance Method Summary collapse
- #add_line_item(line_item = nil, &block) ⇒ Object
-
#initialize(**options) ⇒ Invoice
constructor
A new instance of Invoice.
- #number ⇒ Object
- #subtotal ⇒ Object
- #tax ⇒ Object
- #total ⇒ Object
- #total_cents ⇒ Object
Methods included from Payable
Methods included from Fiscalizable
Methods included from Enum
Constructor Details
#initialize(**options) ⇒ Invoice
Returns a new instance of Invoice.
32 33 34 35 36 37 38 39 40 |
# File 'lib/croatia/invoice.rb', line 32 def initialize(**) self.line_items = .delete(:line_items) { [] } self.payment_method = :card self.sequential_by = :register .each do |key, value| public_send("#{key}=", value) end end |
Instance Attribute Details
#business_location_identifier ⇒ Object
Returns the value of attribute business_location_identifier.
21 22 23 |
# File 'lib/croatia/invoice.rb', line 21 def business_location_identifier @business_location_identifier end |
#buyer(&block) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/croatia/invoice.rb', line 83 def buyer(&block) if block_given? self.buyer = Party.new.tap(&block) else @buyer end end |
#currency ⇒ Object
Returns the value of attribute currency.
21 22 23 |
# File 'lib/croatia/invoice.rb', line 21 def currency @currency end |
#due_date ⇒ Object
Returns the value of attribute due_date.
19 20 21 |
# File 'lib/croatia/invoice.rb', line 19 def due_date @due_date end |
#issue_date ⇒ Object
Returns the value of attribute issue_date.
19 20 21 |
# File 'lib/croatia/invoice.rb', line 19 def issue_date @issue_date end |
#issuer(&block) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/croatia/invoice.rb', line 75 def issuer(&block) if block_given? self.issuer = Party.new.tap(&block) else @issuer end end |
#line_items ⇒ Object
Returns the value of attribute line_items.
21 22 23 |
# File 'lib/croatia/invoice.rb', line 21 def line_items @line_items end |
#register_identifier ⇒ Object
Returns the value of attribute register_identifier.
21 22 23 |
# File 'lib/croatia/invoice.rb', line 21 def register_identifier @register_identifier end |
#seller(&block) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/croatia/invoice.rb', line 91 def seller(&block) if block_given? self.seller = Party.new.tap(&block) else @seller end end |
#sequential_number ⇒ Object
Returns the value of attribute sequential_number.
21 22 23 |
# File 'lib/croatia/invoice.rb', line 21 def sequential_number @sequential_number end |
#unique_invoice_identifier ⇒ Object
Returns the value of attribute unique_invoice_identifier.
21 22 23 |
# File 'lib/croatia/invoice.rb', line 21 def unique_invoice_identifier @unique_invoice_identifier end |
Instance Method Details
#add_line_item(line_item = nil, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/croatia/invoice.rb', line 62 def add_line_item(line_item = nil, &block) if line_item.nil? && block.nil? raise ArgumentError, "You must provide a line item or a block" end line_item ||= LineItem.new.tap(&block) self.line_items ||= [] line_items << line_item line_item end |
#number ⇒ Object
42 43 44 |
# File 'lib/croatia/invoice.rb', line 42 def number [ sequential_number, business_location_identifier, register_identifier ].join("/") end |
#subtotal ⇒ Object
46 47 48 |
# File 'lib/croatia/invoice.rb', line 46 def subtotal line_items.sum(&:subtotal).to_d end |
#tax ⇒ Object
50 51 52 |
# File 'lib/croatia/invoice.rb', line 50 def tax line_items.sum(&:tax).to_d end |
#total ⇒ Object
54 55 56 |
# File 'lib/croatia/invoice.rb', line 54 def total line_items.sum(&:total).to_d end |
#total_cents ⇒ Object
58 59 60 |
# File 'lib/croatia/invoice.rb', line 58 def total_cents (total * 100).to_i end |