invoice_printer 1.0.0 → 1.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -83,68 +83,108 @@ module InvoicePrinter
83
83
  :items,
84
84
  :note
85
85
 
86
- def initialize(number: nil,
87
- provider_name: nil,
88
- provider_tax_id: nil,
89
- provider_tax_id2: nil,
90
- provider_street: nil,
91
- provider_street_number: nil,
92
- provider_postcode: nil,
93
- provider_city: nil,
94
- provider_city_part: nil,
95
- provider_extra_address_line: nil,
96
- purchaser_name: nil,
97
- purchaser_tax_id: nil,
98
- purchaser_tax_id2: nil,
99
- purchaser_street: nil,
100
- purchaser_street_number: nil,
101
- purchaser_postcode: nil,
102
- purchaser_city: nil,
103
- purchaser_city_part: nil,
86
+ class << self
87
+ def from_json(json)
88
+ new(
89
+ number: json['number'],
90
+ provider_name: json['provider_name'],
91
+ provider_tax_id: json['provider_tax_id'],
92
+ provider_tax_id2: json['provider_tax_id2'],
93
+ provider_street: json['provider_street'],
94
+ provider_street_number: json['provider_street_number'],
95
+ provider_postcode: json['provider_postcode'],
96
+ provider_city: json['provider_city'],
97
+ provider_city_part: json['provider_city_part'],
98
+ provider_extra_address_line: json['provider_extra_address_line'],
99
+ purchaser_name: json['purchaser_name'],
100
+ purchaser_tax_id: json['purchaser_tax_id'],
101
+ purchaser_tax_id2: json['purchaser_tax_id2'],
102
+ purchaser_street: json['purchaser_street'],
103
+ purchaser_street_number: json['purchaser_street_number'],
104
+ purchaser_postcode: json['purchaser_postcode'],
105
+ purchaser_city: json['purchaser_city'],
106
+ purchaser_city_part: json['purchaser_city_part'],
107
+ purchaser_extra_address_line: json['purchaser_extra_address_line'],
108
+ issue_date: json['issue_date'],
109
+ due_date: json['due_date'],
110
+ subtotal: json['subtotal'],
111
+ tax: json['tax'],
112
+ tax2: json['tax2'],
113
+ tax3: json['tax3'],
114
+ total: json['total'],
115
+ bank_account_number: json['bank_account_number'],
116
+ account_iban: json['account_iban'],
117
+ account_swift: json['account_swift'],
118
+ note: json['note'],
119
+
120
+ items: (json['items'] || []).map { |item_json| Item.from_json(item_json) }
121
+ )
122
+ end
123
+ end
124
+
125
+ def initialize(number: nil,
126
+ provider_name: nil,
127
+ provider_tax_id: nil,
128
+ provider_tax_id2: nil,
129
+ provider_street: nil,
130
+ provider_street_number: nil,
131
+ provider_postcode: nil,
132
+ provider_city: nil,
133
+ provider_city_part: nil,
134
+ provider_extra_address_line: nil,
135
+ purchaser_name: nil,
136
+ purchaser_tax_id: nil,
137
+ purchaser_tax_id2: nil,
138
+ purchaser_street: nil,
139
+ purchaser_street_number: nil,
140
+ purchaser_postcode: nil,
141
+ purchaser_city: nil,
142
+ purchaser_city_part: nil,
104
143
  purchaser_extra_address_line: nil,
105
- issue_date: nil,
106
- due_date: nil,
107
- subtotal: nil,
108
- tax: nil,
109
- tax2: nil,
110
- tax3: nil,
111
- total: nil,
112
- bank_account_number: nil,
113
- account_iban: nil,
114
- account_swift: nil,
115
- items: nil,
116
- note: nil)
117
- @number = String(number)
118
- @provider_name = String(provider_name)
119
- @provider_tax_id = String(provider_tax_id)
120
- @provider_tax_id2 = String(provider_tax_id2)
121
- @provider_street = String(provider_street)
122
- @provider_street_number = String(provider_street_number)
123
- @provider_postcode = String(provider_postcode)
124
- @provider_city = String(provider_city)
125
- @provider_city_part = String(provider_city_part)
126
- @provider_extra_address_line = String(provider_extra_address_line)
127
- @purchaser_name = String(purchaser_name)
128
- @purchaser_tax_id = String(purchaser_tax_id)
129
- @purchaser_tax_id2 = String(purchaser_tax_id2)
130
- @purchaser_street = String(purchaser_street)
131
- @purchaser_street_number = String(purchaser_street_number)
132
- @purchaser_postcode = String(purchaser_postcode)
133
- @purchaser_city = String(purchaser_city)
134
- @purchaser_city_part = String(purchaser_city_part)
144
+ issue_date: nil,
145
+ due_date: nil,
146
+ subtotal: nil,
147
+ tax: nil,
148
+ tax2: nil,
149
+ tax3: nil,
150
+ total: nil,
151
+ bank_account_number: nil,
152
+ account_iban: nil,
153
+ account_swift: nil,
154
+ items: nil,
155
+ note: nil)
156
+
157
+ @number = String(number)
158
+ @provider_name = String(provider_name)
159
+ @provider_tax_id = String(provider_tax_id)
160
+ @provider_tax_id2 = String(provider_tax_id2)
161
+ @provider_street = String(provider_street)
162
+ @provider_street_number = String(provider_street_number)
163
+ @provider_postcode = String(provider_postcode)
164
+ @provider_city = String(provider_city)
165
+ @provider_city_part = String(provider_city_part)
166
+ @provider_extra_address_line = String(provider_extra_address_line)
167
+ @purchaser_name = String(purchaser_name)
168
+ @purchaser_tax_id = String(purchaser_tax_id)
169
+ @purchaser_tax_id2 = String(purchaser_tax_id2)
170
+ @purchaser_street = String(purchaser_street)
171
+ @purchaser_street_number = String(purchaser_street_number)
172
+ @purchaser_postcode = String(purchaser_postcode)
173
+ @purchaser_city = String(purchaser_city)
174
+ @purchaser_city_part = String(purchaser_city_part)
135
175
  @purchaser_extra_address_line = String(purchaser_extra_address_line)
136
- @issue_date = String(issue_date)
137
- @due_date = String(due_date)
138
- @subtotal = String(subtotal)
139
- @tax = String(tax)
140
- @tax2 = String(tax2)
141
- @tax3 = String(tax3)
142
- @total = String(total)
143
- @bank_account_number = String(bank_account_number)
144
- @account_iban = String(account_iban)
145
- @account_swift = String(account_swift)
146
- @items = items
147
- @note = String(note)
176
+ @issue_date = String(issue_date)
177
+ @due_date = String(due_date)
178
+ @subtotal = String(subtotal)
179
+ @tax = String(tax)
180
+ @tax2 = String(tax2)
181
+ @tax3 = String(tax3)
182
+ @total = String(total)
183
+ @bank_account_number = String(bank_account_number)
184
+ @account_iban = String(account_iban)
185
+ @account_swift = String(account_swift)
186
+ @items = items
187
+ @note = String(note)
148
188
 
149
189
  raise InvalidInput, 'items are not only a type of InvoicePrinter::Document::Item' \
150
190
  unless @items.select{ |i| !i.is_a?(InvoicePrinter::Document::Item) }.empty?
@@ -152,37 +192,37 @@ module InvoicePrinter
152
192
 
153
193
  def to_h
154
194
  {
155
- 'number': @number,
156
- 'provider_name': @provider_name,
157
- 'provider_tax_id': @provider_tax_id,
158
- 'provider_tax_id2': @provider_tax_id2,
159
- 'provider_street': @provider_street,
160
- 'provider_street_number': @provider_street_number,
161
- 'provider_postcode': @provider_postcode,
162
- 'provider_city': @provider_city,
163
- 'provider_city_part': @provider_city_part,
164
- 'provider_extra_address_line': @provider_extra_address_line,
165
- 'purchaser_name': @purchaser_name,
166
- 'purchaser_tax_id': @purchaser_tax_id,
167
- 'purchaser_tax_id2': @purchaser_tax_id2,
168
- 'purchaser_street': @purchaser_street,
169
- 'purchaser_street_number': @purchaser_street_number,
170
- 'purchaser_postcode': @purchaser_postcode,
171
- 'purchaser_city': @purchaser_city,
172
- 'purchaser_city_part': @purchaser_city_part,
195
+ 'number': @number,
196
+ 'provider_name': @provider_name,
197
+ 'provider_tax_id': @provider_tax_id,
198
+ 'provider_tax_id2': @provider_tax_id2,
199
+ 'provider_street': @provider_street,
200
+ 'provider_street_number': @provider_street_number,
201
+ 'provider_postcode': @provider_postcode,
202
+ 'provider_city': @provider_city,
203
+ 'provider_city_part': @provider_city_part,
204
+ 'provider_extra_address_line': @provider_extra_address_line,
205
+ 'purchaser_name': @purchaser_name,
206
+ 'purchaser_tax_id': @purchaser_tax_id,
207
+ 'purchaser_tax_id2': @purchaser_tax_id2,
208
+ 'purchaser_street': @purchaser_street,
209
+ 'purchaser_street_number': @purchaser_street_number,
210
+ 'purchaser_postcode': @purchaser_postcode,
211
+ 'purchaser_city': @purchaser_city,
212
+ 'purchaser_city_part': @purchaser_city_part,
173
213
  'purchaser_extra_address_line': @purchaser_extra_address_line,
174
- 'issue_date': @issue_date,
175
- 'due_date': @due_date,
176
- 'subtotal': @subtotal,
177
- 'tax': @tax,
178
- 'tax2': @tax2,
179
- 'tax3': @tax3,
180
- 'total': @total,
181
- 'bank_account_number': @bank_account_number,
182
- 'account_iban': @account_iban,
183
- 'account_swift': @account_swift,
184
- 'items': @items.map(&:to_h),
185
- 'note': @note
214
+ 'issue_date': @issue_date,
215
+ 'due_date': @due_date,
216
+ 'subtotal': @subtotal,
217
+ 'tax': @tax,
218
+ 'tax2': @tax2,
219
+ 'tax3': @tax3,
220
+ 'total': @total,
221
+ 'bank_account_number': @bank_account_number,
222
+ 'account_iban': @account_iban,
223
+ 'account_swift': @account_swift,
224
+ 'items': @items.map(&:to_h),
225
+ 'note': @note
186
226
  }
187
227
  end
188
228