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_ic: '56565656',
provider_dic: '465454',
provider_street: 'Rolnicka',
provider_street_number: '1',
provider_postcode: '747 05',
provider_city: 'Opava',
provider_city_part: 'Katerinky',
provider_extra_address_line: 'Czech Republic',
purchaser_name: 'Adam',
purchaser_ic: '',
purchaser_dic: '',
purchaser_street: 'Ostravska',
purchaser_street_number: '1',
purchaser_postcode: '747 70',
purchaser_city: 'Opava',
purchaser_city_part: '',
purchaser_extra_address_line: '',
issue_date: '19/03/3939',
due_date: '19/03/3939',
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_city ⇒ Object
readonly
Returns the value of attribute provider_city.
-
#provider_city_part ⇒ Object
readonly
Returns the value of attribute provider_city_part.
-
#provider_dic ⇒ Object
readonly
Returns the value of attribute provider_dic.
-
#provider_extra_address_line ⇒ Object
readonly
Returns the value of attribute provider_extra_address_line.
-
#provider_ic ⇒ Object
readonly
Returns the value of attribute provider_ic.
-
#provider_name ⇒ Object
readonly
Returns the value of attribute provider_name.
-
#provider_postcode ⇒ Object
readonly
Returns the value of attribute provider_postcode.
-
#provider_street ⇒ Object
readonly
Returns the value of attribute provider_street.
-
#provider_street_number ⇒ Object
readonly
Returns the value of attribute provider_street_number.
-
#purchaser_city ⇒ Object
readonly
Returns the value of attribute purchaser_city.
-
#purchaser_city_part ⇒ Object
readonly
Returns the value of attribute purchaser_city_part.
-
#purchaser_dic ⇒ Object
readonly
Returns the value of attribute purchaser_dic.
-
#purchaser_extra_address_line ⇒ Object
readonly
Returns the value of attribute purchaser_extra_address_line.
-
#purchaser_ic ⇒ Object
readonly
Returns the value of attribute purchaser_ic.
-
#purchaser_name ⇒ Object
readonly
Returns the value of attribute purchaser_name.
-
#purchaser_postcode ⇒ Object
readonly
Returns the value of attribute purchaser_postcode.
-
#purchaser_street ⇒ Object
readonly
Returns the value of attribute purchaser_street.
-
#purchaser_street_number ⇒ Object
readonly
Returns the value of attribute purchaser_street_number.
-
#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.
Instance Method Summary collapse
-
#initialize(number: nil, provider_name: nil, provider_ic: nil, provider_dic: nil, provider_street: nil, provider_street_number: nil, provider_postcode: nil, provider_city: nil, provider_city_part: nil, provider_extra_address_line: nil, purchaser_name: nil, purchaser_ic: nil, purchaser_dic: nil, purchaser_street: nil, purchaser_street_number: nil, purchaser_postcode: nil, purchaser_city: nil, purchaser_city_part: nil, purchaser_extra_address_line: nil, issue_date: nil, due_date: 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_ic: nil, provider_dic: nil, provider_street: nil, provider_street_number: nil, provider_postcode: nil, provider_city: nil, provider_city_part: nil, provider_extra_address_line: nil, purchaser_name: nil, purchaser_ic: nil, purchaser_dic: nil, purchaser_street: nil, purchaser_street_number: nil, purchaser_postcode: nil, purchaser_city: nil, purchaser_city_part: nil, purchaser_extra_address_line: nil, issue_date: nil, due_date: 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.
84 85 86 87 88 89 90 91 92 93 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 143 144 145 146 147 148 149 |
# File 'lib/invoice_printer/document.rb', line 84 def initialize(number: nil, provider_name: nil, provider_ic: nil, provider_dic: nil, provider_street: nil, provider_street_number: nil, provider_postcode: nil, provider_city: nil, provider_city_part: nil, provider_extra_address_line: nil, purchaser_name: nil, purchaser_ic: nil, purchaser_dic: nil, purchaser_street: nil, purchaser_street_number: nil, purchaser_postcode: nil, purchaser_city: nil, purchaser_city_part: nil, purchaser_extra_address_line: nil, issue_date: nil, due_date: 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_ic = String(provider_ic) @provider_dic = String(provider_dic) @provider_street = String(provider_street) @provider_street_number = String(provider_street_number) @provider_postcode = String(provider_postcode) @provider_city = String(provider_city) @provider_city_part = String(provider_city_part) @provider_extra_address_line = String(provider_extra_address_line) @purchaser_name = String(purchaser_name) @purchaser_ic = String(purchaser_ic) @purchaser_dic = String(purchaser_dic) @purchaser_street = String(purchaser_street) @purchaser_street_number = String(purchaser_street_number) @purchaser_postcode = String(purchaser_postcode) @purchaser_city = String(purchaser_city) @purchaser_city_part = String(purchaser_city_part) @purchaser_extra_address_line = String(purchaser_extra_address_line) @issue_date = String(issue_date) @due_date = String(due_date) @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.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def account_iban @account_iban end |
#account_swift ⇒ Object (readonly)
Returns the value of attribute account_swift.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def account_swift @account_swift end |
#bank_account_number ⇒ Object (readonly)
Returns the value of attribute bank_account_number.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def bank_account_number @bank_account_number end |
#due_date ⇒ Object (readonly)
Returns the value of attribute due_date.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def due_date @due_date end |
#issue_date ⇒ Object (readonly)
Returns the value of attribute issue_date.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def issue_date @issue_date end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def items @items end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def note @note end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def number @number end |
#provider_city ⇒ Object (readonly)
Returns the value of attribute provider_city.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def provider_city @provider_city end |
#provider_city_part ⇒ Object (readonly)
Returns the value of attribute provider_city_part.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def provider_city_part @provider_city_part end |
#provider_dic ⇒ Object (readonly)
Returns the value of attribute provider_dic.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def provider_dic @provider_dic end |
#provider_extra_address_line ⇒ Object (readonly)
Returns the value of attribute provider_extra_address_line.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def provider_extra_address_line @provider_extra_address_line end |
#provider_ic ⇒ Object (readonly)
Returns the value of attribute provider_ic.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def provider_ic @provider_ic end |
#provider_name ⇒ Object (readonly)
Returns the value of attribute provider_name.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def provider_name @provider_name end |
#provider_postcode ⇒ Object (readonly)
Returns the value of attribute provider_postcode.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def provider_postcode @provider_postcode end |
#provider_street ⇒ Object (readonly)
Returns the value of attribute provider_street.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def provider_street @provider_street end |
#provider_street_number ⇒ Object (readonly)
Returns the value of attribute provider_street_number.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def provider_street_number @provider_street_number end |
#purchaser_city ⇒ Object (readonly)
Returns the value of attribute purchaser_city.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def purchaser_city @purchaser_city end |
#purchaser_city_part ⇒ Object (readonly)
Returns the value of attribute purchaser_city_part.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def purchaser_city_part @purchaser_city_part end |
#purchaser_dic ⇒ Object (readonly)
Returns the value of attribute purchaser_dic.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def purchaser_dic @purchaser_dic end |
#purchaser_extra_address_line ⇒ Object (readonly)
Returns the value of attribute purchaser_extra_address_line.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def purchaser_extra_address_line @purchaser_extra_address_line end |
#purchaser_ic ⇒ Object (readonly)
Returns the value of attribute purchaser_ic.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def purchaser_ic @purchaser_ic end |
#purchaser_name ⇒ Object (readonly)
Returns the value of attribute purchaser_name.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def purchaser_name @purchaser_name end |
#purchaser_postcode ⇒ Object (readonly)
Returns the value of attribute purchaser_postcode.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def purchaser_postcode @purchaser_postcode end |
#purchaser_street ⇒ Object (readonly)
Returns the value of attribute purchaser_street.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def purchaser_street @purchaser_street end |
#purchaser_street_number ⇒ Object (readonly)
Returns the value of attribute purchaser_street_number.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def purchaser_street_number @purchaser_street_number end |
#subtotal ⇒ Object (readonly)
Returns the value of attribute subtotal.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def subtotal @subtotal end |
#tax ⇒ Object (readonly)
Returns the value of attribute tax.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def tax @tax end |
#tax2 ⇒ Object (readonly)
Returns the value of attribute tax2.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def tax2 @tax2 end |
#tax3 ⇒ Object (readonly)
Returns the value of attribute tax3.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def tax3 @tax3 end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
46 47 48 |
# File 'lib/invoice_printer/document.rb', line 46 def total @total end |
Instance Method Details
#to_h ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/invoice_printer/document.rb', line 151 def to_h { 'number': @number, 'provider_name': @provider_name, 'provider_ic': @provider_ic, 'provider_dic': @provider_dic, 'provider_street': @provider_street, 'provider_street_number': @provider_street_number, 'provider_postcode': @provider_postcode, 'provider_city': @provider_city, 'provider_city_part': @provider_city_part, 'provider_extra_address_line': @provider_extra_address_line, 'purchaser_name': @purchaser_name, 'purchaser_ic': @purchaser_ic, 'purchaser_dic': @purchaser_dic, 'purchaser_street': @purchaser_street, 'purchaser_street_number': @purchaser_street_number, 'purchaser_postcode': @purchaser_postcode, 'purchaser_city': @purchaser_city, 'purchaser_city_part': @purchaser_city_part, 'purchaser_extra_address_line': @purchaser_extra_address_line, 'issue_date': @issue_date, 'due_date': @due_date, '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
187 188 189 |
# File 'lib/invoice_printer/document.rb', line 187 def to_json to_h.to_json end |