Class: InvoicePrinter::Document
- Inherits:
-
Object
- Object
- InvoicePrinter::Document
- Defined in:
- lib/invoice_printer/document.rb,
lib/invoice_printer/document/item.rb
Overview
Invoice and receipt representation
Example:
invoice = InvoicePrinter::Document.new(
number: '198900000001',
provider_name: 'Business s.r.o.',
provider_tax_id: '56565656',
provider_tax_id2: '465454',
provider_lines: "Rolnicka 1\n747 05 Opava",
purchaser_name: 'Adam',
purchaser_tax_id: '',
purchaser_tax_id2: '',
purchaser_lines: "Ostravska 2\n747 05 Opava",
issue_date: '19/03/3939',
due_date: '19/03/3939',
variable_symbol: '198900000001',
subtotal: '$ 150',
tax: '$ 50',
total: '$ 200',
bank_account_number: '156546546465',
account_iban: 'IBAN464545645',
account_swift: 'SWIFT5456',
items: [
InvoicePrinter::Document::Item.new,
InvoicePrinter::Document::Item.new
],
note: 'A note at the end.'
)
+amount should equal the sum of all item’s amount
, but this is not enforced.
Defined Under Namespace
Classes: InvalidInput, Item
Instance Attribute Summary collapse
-
#account_iban ⇒ Object
readonly
Returns the value of attribute account_iban.
-
#account_swift ⇒ Object
readonly
Returns the value of attribute account_swift.
-
#bank_account_number ⇒ Object
readonly
Returns the value of attribute bank_account_number.
-
#due_date ⇒ Object
readonly
Returns the value of attribute due_date.
-
#issue_date ⇒ Object
readonly
Returns the value of attribute issue_date.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#provider_lines ⇒ Object
readonly
Returns the value of attribute provider_lines.
-
#provider_name ⇒ Object
readonly
Returns the value of attribute provider_name.
-
#provider_tax_id ⇒ Object
readonly
Returns the value of attribute provider_tax_id.
-
#provider_tax_id2 ⇒ Object
readonly
Returns the value of attribute provider_tax_id2.
-
#purchaser_lines ⇒ Object
readonly
Returns the value of attribute purchaser_lines.
-
#purchaser_name ⇒ Object
readonly
Returns the value of attribute purchaser_name.
-
#purchaser_tax_id ⇒ Object
readonly
Returns the value of attribute purchaser_tax_id.
-
#purchaser_tax_id2 ⇒ Object
readonly
Returns the value of attribute purchaser_tax_id2.
-
#subtotal ⇒ Object
readonly
Returns the value of attribute subtotal.
-
#tax ⇒ Object
readonly
Returns the value of attribute tax.
-
#tax2 ⇒ Object
readonly
Returns the value of attribute tax2.
-
#tax3 ⇒ Object
readonly
Returns the value of attribute tax3.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#variable_symbol ⇒ Object
readonly
Returns the value of attribute variable_symbol.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(number: nil, provider_name: nil, provider_tax_id: nil, provider_tax_id2: nil, provider_lines: nil, purchaser_name: nil, purchaser_tax_id: nil, purchaser_tax_id2: nil, purchaser_lines: nil, issue_date: nil, due_date: nil, variable_symbol: nil, subtotal: nil, tax: nil, tax2: nil, tax3: nil, total: nil, bank_account_number: nil, account_iban: nil, account_swift: nil, items: nil, note: nil) ⇒ Document
constructor
A new instance of Document.
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(number: nil, provider_name: nil, provider_tax_id: nil, provider_tax_id2: nil, provider_lines: nil, purchaser_name: nil, purchaser_tax_id: nil, purchaser_tax_id2: nil, purchaser_lines: nil, issue_date: nil, due_date: nil, variable_symbol: nil, subtotal: nil, tax: nil, tax2: nil, tax3: nil, total: nil, bank_account_number: nil, account_iban: nil, account_swift: nil, items: nil, note: nil) ⇒ Document
Returns a new instance of Document.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/invoice_printer/document.rb', line 94 def initialize(number: nil, provider_name: nil, provider_tax_id: nil, provider_tax_id2: nil, provider_lines: nil, purchaser_name: nil, purchaser_tax_id: nil, purchaser_tax_id2: nil, purchaser_lines: nil, issue_date: nil, due_date: nil, variable_symbol: nil, subtotal: nil, tax: nil, tax2: nil, tax3: nil, total: nil, bank_account_number: nil, account_iban: nil, account_swift: nil, items: nil, note: nil) @number = String(number) @provider_name = String(provider_name) @provider_tax_id = String(provider_tax_id) @provider_tax_id2 = String(provider_tax_id2) @provider_lines = String(provider_lines) @purchaser_name = String(purchaser_name) @purchaser_tax_id = String(purchaser_tax_id) @purchaser_tax_id2 = String(purchaser_tax_id2) @purchaser_lines = String(purchaser_lines) @issue_date = String(issue_date) @due_date = String(due_date) @variable_symbol = String(variable_symbol) @subtotal = String(subtotal) @tax = String(tax) @tax2 = String(tax2) @tax3 = String(tax3) @total = String(total) @bank_account_number = String(bank_account_number) @account_iban = String(account_iban) @account_swift = String(account_swift) @items = items @note = String(note) raise InvalidInput, 'items are not only a type of InvoicePrinter::Document::Item' \ unless @items.select{ |i| !i.is_a?(InvoicePrinter::Document::Item) }.empty? end |
Instance Attribute Details
#account_iban ⇒ Object (readonly)
Returns the value of attribute account_iban.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def account_iban @account_iban end |
#account_swift ⇒ Object (readonly)
Returns the value of attribute account_swift.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def account_swift @account_swift end |
#bank_account_number ⇒ Object (readonly)
Returns the value of attribute bank_account_number.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def bank_account_number @bank_account_number end |
#due_date ⇒ Object (readonly)
Returns the value of attribute due_date.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def due_date @due_date end |
#issue_date ⇒ Object (readonly)
Returns the value of attribute issue_date.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def issue_date @issue_date end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def items @items end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def note @note end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def number @number end |
#provider_lines ⇒ Object (readonly)
Returns the value of attribute provider_lines.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def provider_lines @provider_lines end |
#provider_name ⇒ Object (readonly)
Returns the value of attribute provider_name.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def provider_name @provider_name end |
#provider_tax_id ⇒ Object (readonly)
Returns the value of attribute provider_tax_id.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def provider_tax_id @provider_tax_id end |
#provider_tax_id2 ⇒ Object (readonly)
Returns the value of attribute provider_tax_id2.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def provider_tax_id2 @provider_tax_id2 end |
#purchaser_lines ⇒ Object (readonly)
Returns the value of attribute purchaser_lines.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def purchaser_lines @purchaser_lines end |
#purchaser_name ⇒ Object (readonly)
Returns the value of attribute purchaser_name.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def purchaser_name @purchaser_name end |
#purchaser_tax_id ⇒ Object (readonly)
Returns the value of attribute purchaser_tax_id.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def purchaser_tax_id @purchaser_tax_id end |
#purchaser_tax_id2 ⇒ Object (readonly)
Returns the value of attribute purchaser_tax_id2.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def purchaser_tax_id2 @purchaser_tax_id2 end |
#subtotal ⇒ Object (readonly)
Returns the value of attribute subtotal.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def subtotal @subtotal end |
#tax ⇒ Object (readonly)
Returns the value of attribute tax.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def tax @tax end |
#tax2 ⇒ Object (readonly)
Returns the value of attribute tax2.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def tax2 @tax2 end |
#tax3 ⇒ Object (readonly)
Returns the value of attribute tax3.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def tax3 @tax3 end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def total @total end |
#variable_symbol ⇒ Object (readonly)
Returns the value of attribute variable_symbol.
37 38 39 |
# File 'lib/invoice_printer/document.rb', line 37 def variable_symbol @variable_symbol end |
Class Method Details
.from_json(json) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/invoice_printer/document.rb', line 65 def from_json(json) new( number: json['number'], provider_name: json['provider_name'], provider_tax_id: json['provider_tax_id'], provider_tax_id2: json['provider_tax_id2'], provider_lines: json['provider_lines'], purchaser_name: json['purchaser_name'], purchaser_tax_id: json['purchaser_tax_id'], purchaser_tax_id2: json['purchaser_tax_id2'], purchaser_lines: json['purchaser_lines'], issue_date: json['issue_date'], due_date: json['due_date'], variable_symbol: json['variable_symbol'], subtotal: json['subtotal'], tax: json['tax'], tax2: json['tax2'], tax3: json['tax3'], total: json['total'], bank_account_number: json['bank_account_number'], account_iban: json['account_iban'], account_swift: json['account_swift'], note: json['note'], items: (json['items'] || []).map { |item_json| Item.from_json(item_json) } ) end |
Instance Method Details
#to_h ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/invoice_printer/document.rb', line 144 def to_h { 'number': @number, 'provider_name': @provider_name, 'provider_tax_id': @provider_tax_id, 'provider_tax_id2': @provider_tax_id2, 'provider_lines': @provider_lines, 'purchaser_name': @purchaser_name, 'purchaser_tax_id': @purchaser_tax_id, 'purchaser_tax_id2': @purchaser_tax_id2, 'purchaser_lines': @purchaser_lines, 'issue_date': @issue_date, 'due_date': @due_date, 'variable_symbol': @variable_symbol, 'subtotal': @subtotal, 'tax': @tax, 'tax2': @tax2, 'tax3': @tax3, 'total': @total, 'bank_account_number': @bank_account_number, 'account_iban': @account_iban, 'account_swift': @account_swift, 'items': @items.map(&:to_h), 'note': @note } end |
#to_json ⇒ Object
171 172 173 |
# File 'lib/invoice_printer/document.rb', line 171 def to_json to_h.to_json end |