invoice_printer 1.3.0 → 2.0.0.alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Gemfile +2 -2
- data/Gemfile.lock +12 -17
- data/LICENSE.txt +1 -1
- data/Rakefile +3 -2
- data/bin/invoice_printer +2 -1
- data/docs/COMMAND_LINE.md +4 -0
- data/docs/LIBRARY.md +10 -12
- data/docs/SERVER.md +1 -1
- data/examples/clients/node.js +2 -12
- data/examples/complex_invoice.rb +2 -8
- data/examples/czech_invoice.rb +13 -9
- data/examples/czech_invoice_long.rb +13 -9
- data/examples/international_invoice.rb +14 -10
- data/examples/long_invoice.rb +2 -8
- data/examples/provider_purchaser_lines.rb +111 -0
- data/examples/simple_invoice.rb +4 -0
- data/invoice_printer.gemspec +11 -6
- data/invoice_printer_server.gemspec +35 -0
- data/lib/invoice_printer/document.rb +14 -12
- data/lib/invoice_printer/pdf_document.rb +113 -51
- data/lib/invoice_printer/version.rb +1 -1
- data/test/cli_test.rb +4 -1
- data/test/test_ext.rb +6 -10
- data/test/test_helper.rb +18 -12
- metadata +15 -45
- data/bin/invoice_printer_server +0 -69
- data/lib/invoice_printer/server.rb +0 -90
data/examples/simple_invoice.rb
CHANGED
@@ -16,11 +16,15 @@ item = InvoicePrinter::Document::Item.new(
|
|
16
16
|
invoice = InvoicePrinter::Document.new(
|
17
17
|
number: 'NO. 198900000001',
|
18
18
|
provider_name: 'John White',
|
19
|
+
# Deprecated 1.3 API, use provider_lines
|
20
|
+
# Here for compatibility test
|
19
21
|
provider_street: '5th Avenue',
|
20
22
|
provider_street_number: '1',
|
21
23
|
provider_postcode: '747 05',
|
22
24
|
provider_city: 'NYC',
|
23
25
|
purchaser_name: 'Will Black',
|
26
|
+
# Deprecated 1.3 API, use purchaser_lines
|
27
|
+
# Here for compatibility test
|
24
28
|
purchaser_street: '7th Avenue',
|
25
29
|
purchaser_street_number: '1',
|
26
30
|
purchaser_postcode: '747 70',
|
data/invoice_printer.gemspec
CHANGED
@@ -2,6 +2,11 @@ lib = File.expand_path('../lib', __FILE__)
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require 'invoice_printer/version'
|
4
4
|
|
5
|
+
SERVER_FILES = [
|
6
|
+
'bin/invoice_printer_server',
|
7
|
+
'lib/invoice_printer/server.rb'
|
8
|
+
]
|
9
|
+
|
5
10
|
Gem::Specification.new do |spec|
|
6
11
|
spec.name = 'invoice_printer'
|
7
12
|
spec.version = InvoicePrinter::VERSION
|
@@ -12,8 +17,10 @@ Gem::Specification.new do |spec|
|
|
12
17
|
spec.homepage = 'https://github.com/strzibny/invoice_printer'
|
13
18
|
spec.license = 'MIT'
|
14
19
|
|
20
|
+
# Remove server files
|
15
21
|
# Remove .pdf files as they take a lot of space
|
16
22
|
package_files = `git ls-files -z`.split("\x0")
|
23
|
+
.reject{ |file| SERVER_FILES.include?(file) }
|
17
24
|
.reject{ |file| file.match /.*\.pdf/ }
|
18
25
|
|
19
26
|
spec.files = package_files
|
@@ -23,11 +30,9 @@ Gem::Specification.new do |spec|
|
|
23
30
|
spec.bindir = 'bin'
|
24
31
|
|
25
32
|
spec.add_dependency 'json', '~> 2.1'
|
26
|
-
spec.add_dependency '
|
27
|
-
spec.add_dependency '
|
28
|
-
spec.add_dependency 'prawn', '2.1.0'
|
29
|
-
spec.add_dependency 'prawn-layout', '0.8.4'
|
33
|
+
spec.add_dependency 'prawn', '~> 2.1.0'
|
34
|
+
spec.add_dependency 'prawn-layout', '~> 0.8.4'
|
30
35
|
|
31
|
-
spec.add_development_dependency 'bundler', '
|
32
|
-
spec.add_development_dependency 'rake', '
|
36
|
+
spec.add_development_dependency 'bundler', '>= 1.7'
|
37
|
+
spec.add_development_dependency 'rake', '>= 10.0'
|
33
38
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'invoice_printer/version'
|
4
|
+
|
5
|
+
SERVER_FILES = [
|
6
|
+
'bin/invoice_printer_server',
|
7
|
+
'lib/invoice_printer/server.rb',
|
8
|
+
'lib/invoice_printer/version.rb'
|
9
|
+
]
|
10
|
+
|
11
|
+
Gem::Specification.new do |spec|
|
12
|
+
spec.name = 'invoice_printer_server'
|
13
|
+
spec.version = InvoicePrinter::VERSION
|
14
|
+
spec.authors = ['Josef Strzibny']
|
15
|
+
spec.email = ['strzibny@strzibny.name']
|
16
|
+
spec.summary = 'Super simple PDF invoicing in pure Ruby'
|
17
|
+
spec.description = 'Super simple and fast PDF invoicing in pure Ruby (based on Prawn library).'
|
18
|
+
spec.homepage = 'https://github.com/strzibny/invoice_printer'
|
19
|
+
spec.license = 'MIT'
|
20
|
+
|
21
|
+
# Include only server files
|
22
|
+
spec.files = SERVER_FILES
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
spec.bindir = 'bin'
|
27
|
+
|
28
|
+
spec.add_dependency 'invoice_printer', InvoicePrinter::VERSION
|
29
|
+
spec.add_dependency 'json', '~> 2.1'
|
30
|
+
spec.add_dependency 'roda', '~> 3.5'
|
31
|
+
spec.add_dependency 'puma', '>= 3.9.0'
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '>= 1.7'
|
34
|
+
spec.add_development_dependency 'rake', '>= 10.0'
|
35
|
+
end
|
@@ -8,21 +8,11 @@ module InvoicePrinter
|
|
8
8
|
# provider_name: 'Business s.r.o.',
|
9
9
|
# provider_tax_id: '56565656',
|
10
10
|
# provider_tax_id2: '465454',
|
11
|
-
#
|
12
|
-
# provider_street_number: '1',
|
13
|
-
# provider_postcode: '747 05',
|
14
|
-
# provider_city: 'Opava',
|
15
|
-
# provider_city_part: 'Katerinky',
|
16
|
-
# provider_extra_address_line: 'Czech Republic',
|
11
|
+
# provider_lines: "Rolnicka 1\n747 05 Opava",
|
17
12
|
# purchaser_name: 'Adam',
|
18
13
|
# purchaser_tax_id: '',
|
19
14
|
# purchaser_tax_id2: '',
|
20
|
-
#
|
21
|
-
# purchaser_street_number: '1',
|
22
|
-
# purchaser_postcode: '747 70',
|
23
|
-
# purchaser_city: 'Opava',
|
24
|
-
# purchaser_city_part: '',
|
25
|
-
# purchaser_extra_address_line: '',
|
15
|
+
# purchaser_lines: "Ostravska 2\n747 05 Opava",
|
26
16
|
# issue_date: '19/03/3939',
|
27
17
|
# due_date: '19/03/3939',
|
28
18
|
# subtotal: '$ 150',
|
@@ -48,6 +38,7 @@ module InvoicePrinter
|
|
48
38
|
:provider_name,
|
49
39
|
:provider_tax_id,
|
50
40
|
:provider_tax_id2,
|
41
|
+
:provider_lines,
|
51
42
|
# Provider address fields
|
52
43
|
:provider_street,
|
53
44
|
:provider_street_number,
|
@@ -59,6 +50,7 @@ module InvoicePrinter
|
|
59
50
|
:purchaser_name,
|
60
51
|
:purchaser_tax_id,
|
61
52
|
:purchaser_tax_id2,
|
53
|
+
:purchaser_lines,
|
62
54
|
# Purchaser address fields
|
63
55
|
:purchaser_street,
|
64
56
|
:purchaser_street_number,
|
@@ -94,6 +86,7 @@ module InvoicePrinter
|
|
94
86
|
provider_city: json['provider_city'],
|
95
87
|
provider_city_part: json['provider_city_part'],
|
96
88
|
provider_extra_address_line: json['provider_extra_address_line'],
|
89
|
+
provider_lines: json['provider_lines'],
|
97
90
|
purchaser_name: json['purchaser_name'],
|
98
91
|
purchaser_tax_id: json['purchaser_tax_id'],
|
99
92
|
purchaser_tax_id2: json['purchaser_tax_id2'],
|
@@ -103,6 +96,7 @@ module InvoicePrinter
|
|
103
96
|
purchaser_city: json['purchaser_city'],
|
104
97
|
purchaser_city_part: json['purchaser_city_part'],
|
105
98
|
purchaser_extra_address_line: json['purchaser_extra_address_line'],
|
99
|
+
purchaser_lines: json['purchaser_lines'],
|
106
100
|
issue_date: json['issue_date'],
|
107
101
|
due_date: json['due_date'],
|
108
102
|
subtotal: json['subtotal'],
|
@@ -130,6 +124,7 @@ module InvoicePrinter
|
|
130
124
|
provider_city: nil,
|
131
125
|
provider_city_part: nil,
|
132
126
|
provider_extra_address_line: nil,
|
127
|
+
provider_lines: nil,
|
133
128
|
purchaser_name: nil,
|
134
129
|
purchaser_tax_id: nil,
|
135
130
|
purchaser_tax_id2: nil,
|
@@ -139,6 +134,7 @@ module InvoicePrinter
|
|
139
134
|
purchaser_city: nil,
|
140
135
|
purchaser_city_part: nil,
|
141
136
|
purchaser_extra_address_line: nil,
|
137
|
+
purchaser_lines: nil,
|
142
138
|
issue_date: nil,
|
143
139
|
due_date: nil,
|
144
140
|
subtotal: nil,
|
@@ -162,6 +158,7 @@ module InvoicePrinter
|
|
162
158
|
@provider_city = String(provider_city)
|
163
159
|
@provider_city_part = String(provider_city_part)
|
164
160
|
@provider_extra_address_line = String(provider_extra_address_line)
|
161
|
+
@provider_lines = String(provider_lines)
|
165
162
|
@purchaser_name = String(purchaser_name)
|
166
163
|
@purchaser_tax_id = String(purchaser_tax_id)
|
167
164
|
@purchaser_tax_id2 = String(purchaser_tax_id2)
|
@@ -171,6 +168,7 @@ module InvoicePrinter
|
|
171
168
|
@purchaser_city = String(purchaser_city)
|
172
169
|
@purchaser_city_part = String(purchaser_city_part)
|
173
170
|
@purchaser_extra_address_line = String(purchaser_extra_address_line)
|
171
|
+
@purchaser_lines = String(purchaser_lines)
|
174
172
|
@issue_date = String(issue_date)
|
175
173
|
@due_date = String(due_date)
|
176
174
|
@subtotal = String(subtotal)
|
@@ -184,6 +182,8 @@ module InvoicePrinter
|
|
184
182
|
@items = items
|
185
183
|
@note = String(note)
|
186
184
|
|
185
|
+
|
186
|
+
|
187
187
|
raise InvalidInput, 'items are not only a type of InvoicePrinter::Document::Item' \
|
188
188
|
unless @items.select{ |i| !i.is_a?(InvoicePrinter::Document::Item) }.empty?
|
189
189
|
end
|
@@ -200,6 +200,7 @@ module InvoicePrinter
|
|
200
200
|
'provider_city': @provider_city,
|
201
201
|
'provider_city_part': @provider_city_part,
|
202
202
|
'provider_extra_address_line': @provider_extra_address_line,
|
203
|
+
'provider_lines': @provider_lines,
|
203
204
|
'purchaser_name': @purchaser_name,
|
204
205
|
'purchaser_tax_id': @purchaser_tax_id,
|
205
206
|
'purchaser_tax_id2': @purchaser_tax_id2,
|
@@ -209,6 +210,7 @@ module InvoicePrinter
|
|
209
210
|
'purchaser_city': @purchaser_city,
|
210
211
|
'purchaser_city_part': @purchaser_city_part,
|
211
212
|
'purchaser_extra_address_line': @purchaser_extra_address_line,
|
213
|
+
'purchaser_lines': @purchaser_lines,
|
212
214
|
'issue_date': @issue_date,
|
213
215
|
'due_date': @due_date,
|
214
216
|
'subtotal': @subtotal,
|
@@ -101,6 +101,36 @@ module InvoicePrinter
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
+
# Version 2.1 deprecation warnings
|
105
|
+
warnings = [
|
106
|
+
@document.provider_street,
|
107
|
+
@document.provider_street_number,
|
108
|
+
@document.provider_postcode,
|
109
|
+
@document.provider_city,
|
110
|
+
@document.provider_city_part,
|
111
|
+
@document.provider_extra_address_line,
|
112
|
+
@document.purchaser_street,
|
113
|
+
@document.purchaser_street_number,
|
114
|
+
@document.purchaser_postcode,
|
115
|
+
@document.purchaser_city,
|
116
|
+
@document.purchaser_city_part,
|
117
|
+
@document.purchaser_extra_address_line
|
118
|
+
].delete_if(&:empty?)
|
119
|
+
|
120
|
+
unless warnings.empty?
|
121
|
+
warning = <<~WARN
|
122
|
+
WARNING: Following values are used in deprecated fields and
|
123
|
+
won't be rendered in future versions of InvoicePrinter:
|
124
|
+
|
125
|
+
#{warnings.join(", ")}
|
126
|
+
|
127
|
+
Use new provider_lines and purchaser_lines fields instead of
|
128
|
+
the old address fields.
|
129
|
+
WARN
|
130
|
+
|
131
|
+
$stderr.puts warning
|
132
|
+
end
|
133
|
+
|
104
134
|
build_pdf
|
105
135
|
end
|
106
136
|
|
@@ -189,7 +219,7 @@ module InvoicePrinter
|
|
189
219
|
# Build the following provider box:
|
190
220
|
#
|
191
221
|
# ------------------------------------------
|
192
|
-
# | Provider
|
222
|
+
# | Provider Optional provider sublabel|
|
193
223
|
# | PROVIDER co. |
|
194
224
|
# | 5th Street |
|
195
225
|
# | 747 27 City |
|
@@ -221,39 +251,55 @@ module InvoicePrinter
|
|
221
251
|
align: :right
|
222
252
|
)
|
223
253
|
end
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
at: [60, y(605) - @push_down],
|
240
|
-
width: x(240)
|
241
|
-
)
|
242
|
-
unless @document.provider_city_part.empty?
|
254
|
+
# Render provider_lines if present
|
255
|
+
if !@document.provider_lines.empty?
|
256
|
+
lines = @document.provider_lines.split("\n")
|
257
|
+
line_y = 618
|
258
|
+
lines.each_with_index do |line, index|
|
259
|
+
next if index > 3
|
260
|
+
|
261
|
+
@pdf.text_box(
|
262
|
+
"#{line}",
|
263
|
+
size: 10,
|
264
|
+
at: [10, y(line_y - index*15) - @push_down],
|
265
|
+
width: x(240)
|
266
|
+
)
|
267
|
+
end
|
268
|
+
else
|
243
269
|
@pdf.text_box(
|
244
|
-
@document.
|
270
|
+
"#{@document.provider_street} #{@document.provider_street_number}",
|
245
271
|
size: 10,
|
246
|
-
at: [
|
272
|
+
at: [10, y(620) - @push_down],
|
247
273
|
width: x(240)
|
248
274
|
)
|
249
|
-
end
|
250
|
-
unless @document.provider_extra_address_line.empty?
|
251
275
|
@pdf.text_box(
|
252
|
-
@document.
|
276
|
+
@document.provider_postcode,
|
253
277
|
size: 10,
|
254
|
-
at: [10, y(
|
278
|
+
at: [10, y(605) - @push_down],
|
255
279
|
width: x(240)
|
256
280
|
)
|
281
|
+
@pdf.text_box(
|
282
|
+
@document.provider_city,
|
283
|
+
size: 10,
|
284
|
+
at: [60, y(605) - @push_down],
|
285
|
+
width: x(240)
|
286
|
+
)
|
287
|
+
unless @document.provider_city_part.empty?
|
288
|
+
@pdf.text_box(
|
289
|
+
@document.provider_city_part,
|
290
|
+
size: 10,
|
291
|
+
at: [60, y(590) - @push_down],
|
292
|
+
width: x(240)
|
293
|
+
)
|
294
|
+
end
|
295
|
+
unless @document.provider_extra_address_line.empty?
|
296
|
+
@pdf.text_box(
|
297
|
+
@document.provider_extra_address_line,
|
298
|
+
size: 10,
|
299
|
+
at: [10, y(575) - @push_down],
|
300
|
+
width: x(240)
|
301
|
+
)
|
302
|
+
end
|
257
303
|
end
|
258
304
|
unless @document.provider_tax_id.empty?
|
259
305
|
@pdf.text_box(
|
@@ -310,39 +356,55 @@ module InvoicePrinter
|
|
310
356
|
align: :right
|
311
357
|
)
|
312
358
|
end
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
at: [x(334), y(605) - @push_down],
|
329
|
-
width: x(240)
|
330
|
-
)
|
331
|
-
unless @document.purchaser_city_part.empty?
|
359
|
+
# Render purchaser_lines if present
|
360
|
+
if !@document.purchaser_lines.empty?
|
361
|
+
lines = @document.purchaser_lines.split("\n")
|
362
|
+
line_y = 618
|
363
|
+
lines.each_with_index do |line, index|
|
364
|
+
next if index > 3
|
365
|
+
|
366
|
+
@pdf.text_box(
|
367
|
+
"#{line}",
|
368
|
+
size: 10,
|
369
|
+
at: [x(284), y(line_y - index*15) - @push_down],
|
370
|
+
width: x(240)
|
371
|
+
)
|
372
|
+
end
|
373
|
+
else
|
332
374
|
@pdf.text_box(
|
333
|
-
@document.
|
375
|
+
"#{@document.purchaser_street} #{@document.purchaser_street_number}",
|
334
376
|
size: 10,
|
335
|
-
at: [x(
|
377
|
+
at: [x(284), y(620) - @push_down],
|
336
378
|
width: x(240)
|
337
379
|
)
|
338
|
-
end
|
339
|
-
unless @document.purchaser_extra_address_line.empty?
|
340
380
|
@pdf.text_box(
|
341
|
-
@document.
|
381
|
+
@document.purchaser_postcode,
|
342
382
|
size: 10,
|
343
|
-
at: [x(284), y(
|
383
|
+
at: [x(284), y(605) - @push_down],
|
344
384
|
width: x(240)
|
345
385
|
)
|
386
|
+
@pdf.text_box(
|
387
|
+
@document.purchaser_city,
|
388
|
+
size: 10,
|
389
|
+
at: [x(334), y(605) - @push_down],
|
390
|
+
width: x(240)
|
391
|
+
)
|
392
|
+
unless @document.purchaser_city_part.empty?
|
393
|
+
@pdf.text_box(
|
394
|
+
@document.purchaser_city_part,
|
395
|
+
size: 10,
|
396
|
+
at: [x(334), y(590) - @push_down],
|
397
|
+
width: x(240)
|
398
|
+
)
|
399
|
+
end
|
400
|
+
unless @document.purchaser_extra_address_line.empty?
|
401
|
+
@pdf.text_box(
|
402
|
+
@document.purchaser_extra_address_line,
|
403
|
+
size: 10,
|
404
|
+
at: [x(284), y(575) - @push_down],
|
405
|
+
width: x(240)
|
406
|
+
)
|
407
|
+
end
|
346
408
|
end
|
347
409
|
unless @document.purchaser_tax_id.empty?
|
348
410
|
@pdf.text_box(
|
data/test/cli_test.rb
CHANGED
@@ -5,9 +5,12 @@ class CLITest < Minitest::Test
|
|
5
5
|
include InvoicePrinterHelpers
|
6
6
|
|
7
7
|
def setup
|
8
|
+
t = Time.now.strftime("%Y%m%d")
|
9
|
+
tmpname = "/tmp/invoice-#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-fd"
|
10
|
+
|
8
11
|
@invoice = InvoicePrinter::Document.new(default_document_params)
|
9
12
|
@invoice_as_json = @invoice.to_json
|
10
|
-
@output_path =
|
13
|
+
@output_path = tmpname
|
11
14
|
end
|
12
15
|
|
13
16
|
def teardown
|
data/test/test_ext.rb
CHANGED
@@ -25,11 +25,9 @@ module InvoicePrinter
|
|
25
25
|
strings = []
|
26
26
|
strings << @document.provider_name
|
27
27
|
strings << @labels[:provider]
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
strings << @document.provider_city_part
|
32
|
-
strings << @document.provider_extra_address_line
|
28
|
+
@document.provider_lines.split("\n").each do |line|
|
29
|
+
strings << line
|
30
|
+
end
|
33
31
|
strings << "#{@labels[:tax_id]}: #{@document.provider_tax_id}" \
|
34
32
|
unless @document.provider_tax_id.empty?
|
35
33
|
strings << "#{@labels[:tax_id2]}: #{@document.provider_tax_id2}" \
|
@@ -42,11 +40,9 @@ module InvoicePrinter
|
|
42
40
|
strings = []
|
43
41
|
strings << @document.purchaser_name
|
44
42
|
strings << @labels[:purchaser]
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
strings << @document.purchaser_city_part
|
49
|
-
strings << @document.purchaser_extra_address_line
|
43
|
+
@document.purchaser_lines.split("\n").each do |line|
|
44
|
+
strings << line
|
45
|
+
end
|
50
46
|
strings << "#{@labels[:tax_id]}: #{@document.purchaser_tax_id}" \
|
51
47
|
unless @document.purchaser_tax_id.empty?
|
52
48
|
strings << "#{@labels[:tax_id2]}: #{@document.purchaser_tax_id2}" \
|