invoice_printer 2.0.0.beta3 → 2.2.0

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +7 -6
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +29 -16
  5. data/README.md +9 -3
  6. data/assets/fonts/opensans/OpenSans-Bold.ttf +0 -0
  7. data/assets/fonts/overpass/Overpass-Bold.ttf +0 -0
  8. data/assets/fonts/roboto/Roboto-Bold.ttf +0 -0
  9. data/benchmarks/render.yml +19 -13
  10. data/bin/invoice_printer +7 -0
  11. data/docs/COMMAND_LINE.md +122 -0
  12. data/docs/LIBRARY.md +16 -12
  13. data/docs/SERVER.md +8 -2
  14. data/examples/breakdown.rb +77 -0
  15. data/examples/international_invoice.rb +2 -2
  16. data/examples/long_invoice.rb +8 -8
  17. data/examples/picture.jpg +0 -0
  18. data/examples/promo.rb +19 -13
  19. data/examples/provider_purchaser_lines.rb +6 -15
  20. data/examples/simple_invoice.rb +15 -16
  21. data/examples/variable_field_invoice.rb +96 -0
  22. data/invoice_printer.gemspec +3 -2
  23. data/invoice_printer_fonts.gemspec +4 -1
  24. data/lib/invoice_printer.rb +27 -2
  25. data/lib/invoice_printer/document.rb +90 -148
  26. data/lib/invoice_printer/document/item.rb +34 -28
  27. data/lib/invoice_printer/pdf_document.rb +201 -208
  28. data/lib/invoice_printer/version.rb +1 -1
  29. data/test/api_test.rb +2 -2
  30. data/test/background_test.rb +1 -1
  31. data/test/cli_test.rb +1 -1
  32. data/test/dates_box_test.rb +4 -4
  33. data/test/examples_test.rb +2 -0
  34. data/test/inputs_test.rb +4 -4
  35. data/test/invoice_printer_test.rb +2 -2
  36. data/test/items_table_test.rb +2 -2
  37. data/test/labels_test.rb +2 -2
  38. data/test/notes_test.rb +1 -1
  39. data/test/page_numbers_test.rb +4 -4
  40. data/test/payment_box_test.rb +5 -5
  41. data/test/test_ext.rb +2 -1
  42. data/test/test_helper.rb +1 -1
  43. metadata +15 -15
  44. data/assets/logo.png +0 -0
  45. data/examples/background.png +0 -0
  46. data/examples/logo.png +0 -0
  47. data/examples/prawn.png +0 -0
  48. data/examples/stamp.png +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0b5acb10995e69d8aba7d44d9e7d71ce5e9b9104cf5883fec574ada600501b0
4
- data.tar.gz: 3ccaa20f6baeee71cf879cdf74687e6da7ab6441fa5583199fa547d3e5afd34f
3
+ metadata.gz: 33a87300d4ff6a12080b758ea012b7c94a09521575c99579e300844dbfbf0e47
4
+ data.tar.gz: 33446dc1314512a7793ad95b73065dfb59abef1963e5c115fab5263e2dd53ecc
5
5
  SHA512:
6
- metadata.gz: 84cf91f9a5f2445dbe62491e7f51c05e4bfaf3d9c5d58881db035a964c2114a9d02fca485f300b15fc8cb87efea05d2c24d60822c1f9c01145dd1eeba62c22cd
7
- data.tar.gz: aa5566034f52a87d9c7ee432fc485fd233407a82f591ded208a880f0d214aea3c39cc6241add8bfffbcb3abe07311214cb47ff0daec20f1e7ea4ad5a92b131c8
6
+ metadata.gz: ef29b3e26227c6cbeba87fca78154d55a7bb103472f77991fe1a4df24f30a36efa75db3f7f724ddd17a369713870db6d20bd93ea33d0812fb55501bbba9c7ea2
7
+ data.tar.gz: 6c93d97f040190c555dcbdaf742e05d904a00bd458e2f68009dd1191ec3bf190fe92e20033bb19e0ae3337f6e10686361922b05bcfcc6316e86f8bb46b7a0cbf
data/Dockerfile CHANGED
@@ -11,24 +11,25 @@
11
11
  #
12
12
  # $ sudo docker login
13
13
  # $ sudo docker tag printer docker.io/strzibnyj/invoice_printer_server:latest
14
+ # $ sudo docker push strzibnyj/invoice_printer_server:$VERSION
14
15
  # $ sudo docker push strzibnyj/invoice_printer_server:latest
15
- FROM alpine:3.10
16
+ FROM alpine:3.13
16
17
  MAINTAINER Josef Strzibny <strzibny@strzibny.name>
17
18
 
18
19
  ENV GEM_HOME="/usr/local/bundle"
19
20
  ENV PATH $GEM_HOME/bin:$GEM_HOME/gems/bin:$PATH
20
21
 
21
22
  # Update system
22
- RUN apk update && apk upgrade
23
+ RUN apk update && apk upgrade
23
24
 
24
25
  # Install Ruby and build dependencies
25
26
  RUN apk add build-base bash ruby ruby-etc ruby-dev
26
27
 
27
- # Install support for builtin fonts
28
- RUN gem install invoice_printer_fonts --no-document
28
+ # Install builtin fonts
29
+ RUN gem install invoice_printer_fonts --version 2.2.0 --no-document
29
30
 
30
- # Install gem from RubyGems.org
31
- RUN gem install invoice_printer_server --version 2.0.0.beta3 --no-document
31
+ # Install the gem from RubyGems.org
32
+ RUN gem install invoice_printer_server --version 2.2.0 --no-document
32
33
 
33
34
  # Clean APK cache
34
35
  RUN rm -rf /var/cache/apk/*
data/Gemfile CHANGED
@@ -10,7 +10,7 @@ group :test do
10
10
  end
11
11
 
12
12
  group :benchmark do
13
- gem 'benchmark_driver', '0.14.11'
13
+ gem 'benchmark_driver', '0.15.17'
14
14
  # For generating benchmark reports with --output gruff
15
15
  gem 'benchmark_driver-output-gruff'
16
16
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- invoice_printer_server (2.0.0.alpha1)
4
+ invoice_printer (2.2.0)
5
+ json (~> 2.1)
6
+ prawn (~> 2.2)
7
+ prawn-table (~> 0.2.2)
8
+ invoice_printer_server (2.2.0)
9
+ invoice_printer (= 2.2.0)
5
10
  json (~> 2.1)
6
11
  puma (>= 3.9.0)
7
12
  roda (~> 3.5)
@@ -11,41 +16,49 @@ GEM
11
16
  specs:
12
17
  Ascii85 (1.0.3)
13
18
  afm (0.2.2)
14
- benchmark_driver (0.14.11)
19
+ benchmark_driver (0.15.17)
15
20
  benchmark_driver-output-gruff (0.3.1)
16
21
  benchmark_driver (>= 0.12.0)
17
22
  gruff
18
- gruff (0.7.0)
19
- rmagick (~> 2.13, >= 2.13.4)
23
+ gruff (0.11.0)
24
+ histogram
25
+ rmagick
20
26
  hashery (2.1.2)
21
- json (2.2.0)
22
- minitest (5.11.3)
23
- nio4r (2.3.1)
27
+ histogram (0.2.4.1)
28
+ json (2.5.1)
29
+ minitest (5.14.2)
30
+ nio4r (2.5.7)
31
+ pdf-core (0.9.0)
24
32
  pdf-inspector (1.3.0)
25
33
  pdf-reader (>= 1.0, < 3.0.a)
26
- pdf-reader (2.2.0)
34
+ pdf-reader (2.4.1)
27
35
  Ascii85 (~> 1.0.0)
28
36
  afm (~> 0.2.1)
29
37
  hashery (~> 2.0)
30
38
  ruby-rc4
31
39
  ttfunk
32
- puma (4.0.0)
40
+ prawn (2.4.0)
41
+ pdf-core (~> 0.9.0)
42
+ ttfunk (~> 1.7)
43
+ prawn-table (0.2.2)
44
+ prawn (>= 1.3.0, < 3.0.0)
45
+ puma (5.3.2)
33
46
  nio4r (~> 2.0)
34
- rack (2.0.6)
47
+ rack (2.2.3)
35
48
  rack-test (1.1.0)
36
49
  rack (>= 1.0, < 3)
37
- rake (10.5.0)
38
- rmagick (2.16.0)
39
- roda (3.21.0)
50
+ rake (13.0.1)
51
+ rmagick (4.1.2)
52
+ roda (3.45.0)
40
53
  rack
41
54
  ruby-rc4 (0.1.5)
42
- ttfunk (1.4.0)
55
+ ttfunk (1.7.0)
43
56
 
44
57
  PLATFORMS
45
58
  ruby
46
59
 
47
60
  DEPENDENCIES
48
- benchmark_driver (= 0.14.11)
61
+ benchmark_driver (= 0.15.17)
49
62
  benchmark_driver-output-gruff
50
63
  bundler (>= 1.7)
51
64
  invoice_printer_server!
@@ -55,4 +68,4 @@ DEPENDENCIES
55
68
  rake (>= 10.0)
56
69
 
57
70
  BUNDLED WITH
58
- 1.17.2
71
+ 2.1.4
data/README.md CHANGED
@@ -25,10 +25,10 @@ See more usecases in the `examples/` directory.
25
25
  - Purchaser and provider boxes with addresses and identificaton numbers
26
26
  - Payment method box showing banking details including SWIFT and IBAN fields
27
27
  - Issue/due dates box
28
- - Configurable items' table with item description, quantity, unit, price per unit, tax and item's total amount fields
28
+ - Configurable items' table with item description, breakdown, quantity, unit, price per unit, tax and item's total amount fields
29
29
  - Final subtotal/tax/total info box
30
30
  - Page numbers
31
- - Configurable labels & sublabels (optional little labels)
31
+ - Configurable field labels & sublabels (optional little labels)
32
32
  - Configurable font file
33
33
  - Logotype (as image scaled to fit 50px of height)
34
34
  - Background (as image)
@@ -46,6 +46,12 @@ See more usecases in the `examples/` directory.
46
46
  - [Server](./docs/SERVER.md)
47
47
  - [Command line](./docs/COMMAND_LINE.md)
48
48
 
49
+ ## Support
50
+
51
+ I am developing InvoicePrinter as a free and MIT-licensed library for several years now.
52
+
53
+ I would appreciate if you consider [buying my book](https://deploymentfromscratch.com/).
54
+
49
55
  ## Copyright
50
56
 
51
- Copyright 2015-2019 &copy; [Josef Strzibny](http://strzibny.name/). MIT licensed.
57
+ Copyright 2015-2021 &copy; [Josef Strzibny](http://strzibny.name/). MIT licensed.
Binary file
@@ -1,13 +1,25 @@
1
1
  # Run the benchmark with benchmark_driver as:
2
2
  #
3
- # $ benchmark-driver benchmarks/render.yml --output gruff --runner ips -e '/path/to/bin/ruby;/path/to/bin/ruby-2.6.0 --jit'
4
- # $ benchmark-driver benchmarks/render.yml --output compare --runner memory -e '/path/to/bin/ruby;/path/to/bin/ruby-2.6.0 --jit--jit'
5
- loop_count: 10000
3
+ # $ benchmark-driver benchmarks/render.yml --output gruff --runner ips -e '/path/to/bin/ruby;/path/to/bin/ruby-3.0.0 --jit'
4
+ # $ benchmark-driver benchmarks/render.yml --output compare --runner memory -e '/path/to/bin/ruby;/path/to/bin/ruby-3.0.0 --jit'
5
+ # $ benchmark-driver benchmarks/render.yml -e '/home/strzibny/.rubies/ruby-2.7.0/bin/ruby;/home/strzibny/.rubies/ruby-3.0.0/bin/ruby;/home/strzibny/.rubies/ruby-3.0.0/bin/ruby --jit'
6
+ #
7
+ # Note: You need to install invoice_printer as a gem for the require to work.
8
+ loop_count: 3000
6
9
  prelude: |
7
- lib = File.expand_path('../lib', __FILE__)
8
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
9
10
  require 'invoice_printer'
10
11
 
12
+ provider_address = <<ADDRESS
13
+ Rolnicka 1
14
+ 747 05 Opava
15
+ Katerinky
16
+ ADDRESS
17
+
18
+ purchaser_address = <<ADDRESS
19
+ Ostravska 1
20
+ 747 70 Opava
21
+ ADDRESS
22
+
11
23
  item = InvoicePrinter::Document::Item.new(
12
24
  name: 'Programming',
13
25
  quantity: '10',
@@ -19,15 +31,9 @@ prelude: |
19
31
  invoice = InvoicePrinter::Document.new(
20
32
  number: 'NO. 198900000001',
21
33
  provider_name: 'John White',
22
- provider_street: '5th Avenue',
23
- provider_street_number: '1',
24
- provider_postcode: '747 05',
25
- provider_city: 'NYC',
34
+ provider_lines: provider_address,
26
35
  purchaser_name: 'Will Black',
27
- purchaser_street: '7th Avenue',
28
- purchaser_street_number: '1',
29
- purchaser_postcode: '747 70',
30
- purchaser_city: 'NYC',
36
+ purchaser_lines: purchaser_address,
31
37
  issue_date: '05/03/2016',
32
38
  due_date: '19/03/2016',
33
39
  total: '$ 900',
data/bin/invoice_printer CHANGED
@@ -19,6 +19,7 @@ def show_help
19
19
  -d, --document document as JSON
20
20
  -l, --labels labels as JSON
21
21
  --font path to font or builtin font name
22
+ --bold-font path to bold font or builtin font name
22
23
  -s, --stamp path to stamp
23
24
  --logo path to logotype
24
25
  --background path to background image
@@ -47,6 +48,10 @@ parser = OptionParser.new do|opts|
47
48
  options[:font] = path
48
49
  end
49
50
 
51
+ opts.on('--bold-font PATH') do |path|
52
+ options[:bold_font] = path
53
+ end
54
+
50
55
  opts.on('-s', '--stamp PATH') do |path|
51
56
  options[:stamp] = path
52
57
  end
@@ -116,6 +121,7 @@ begin
116
121
  document: document,
117
122
  labels: labels,
118
123
  font: options[:font],
124
+ bold_font: options[:bold_font],
119
125
  stamp: options[:stamp],
120
126
  logo: options[:logo],
121
127
  background: options[:background],
@@ -130,6 +136,7 @@ begin
130
136
  document: document,
131
137
  labels: labels,
132
138
  font: options[:font],
139
+ bold_font: options[:bold_font],
133
140
  stamp: options[:stamp],
134
141
  logo: options[:logo],
135
142
  file_name: options[:filename],
data/docs/COMMAND_LINE.md CHANGED
@@ -13,6 +13,7 @@ Options:
13
13
  -d, --document document as JSON
14
14
  -l, --labels labels as JSON
15
15
  --font path to font or builtin font name
16
+ --bold-font path to bold font or builtin font name
16
17
  -s, --stamp path to stamp
17
18
  --logo path to logotype
18
19
  --background path to background image
@@ -20,6 +21,127 @@ Options:
20
21
  -f, --filename output path
21
22
  -r, --render directly render PDF stream (filename option will be ignored)
22
23
  ```
24
+
25
+ ## Document
26
+
27
+ JSON document with all possible fields filled:
28
+
29
+ ```json
30
+ {
31
+ "number":"c. 198900000001",
32
+ "provider_name":"Petr Novy",
33
+ "provider_tax_id":"56565656",
34
+ "provider_tax_id2":"",
35
+ "provider_lines":"Rolnická 1\n747 05 Opava\nKateřinky",
36
+ "purchaser_name":"Adam Cerny",
37
+ "purchaser_tax_id":"",
38
+ "purchaser_tax_id2":"",
39
+ "purchaser_lines":"Ostravská 1\n747 70 Opava",
40
+ "issue_date":"05/03/2016",
41
+ "due_date":"19/03/2016",
42
+ "variable_symbol":"198900000001",
43
+ "subtotal":"Kc 10.000",
44
+ "tax":"Kc 2.100",
45
+ "tax2":"",
46
+ "tax3":"",
47
+ "variable":"Extra column",
48
+ "total":"Kc 12.100,-",
49
+ "bank_account_number":"156546546465",
50
+ "account_iban":"IBAN464545645",
51
+ "account_swift":"SWIFT5456",
52
+ "items":[
53
+ {
54
+ "name":"Konzultace",
55
+ "variable": "",
56
+ "quantity":"2",
57
+ "unit":"hod",
58
+ "price":"Kc 500",
59
+ "tax":"",
60
+ "tax2":"",
61
+ "tax3":"",
62
+ "amount":"Kc 1.000"
63
+ },
64
+ {
65
+ "name":"Programovani",
66
+ "variable": "",
67
+ "quantity":"10",
68
+ "unit":"hod",
69
+ "price":"Kc 900",
70
+ "tax":"",
71
+ "tax2":"",
72
+ "tax3":"",
73
+ "amount":"Kc 9.000"
74
+ }
75
+ ],
76
+ "note":"Osoba je zapsána v zivnostenském rejstríku."
77
+ }
78
+ ```
79
+
80
+ **Note**: `provider_lines` and `purchaser_lines` are 4 lines of data separated by new line character`\n`. Other lines are being stripped.
81
+
82
+ **Note**: There is `variable` field that can be used for any
83
+ extra column.
84
+
85
+ ## Field labels
86
+
87
+ All labels:
88
+
89
+ ```json
90
+ {
91
+ "name":"Invoice",
92
+ "provider":"Provider",
93
+ "purchaser":"Purchaser",
94
+ "tax_id":"Identification number",
95
+ "tax_id2":"Identification number",
96
+ "payment":"Payment",
97
+ "payment_by_transfer":"Payment by bank transfer on the account below:",
98
+ "payment_in_cash":"Payment in cash",
99
+ "account_number":"Account NO",
100
+ "swift":"SWIFT",
101
+ "iban":"IBAN",
102
+ "issue_date":"Issue date",
103
+ "due_date": "Due date",
104
+ "variable_symbol": "Variable symbol",
105
+ "item":"Item",
106
+ "variable":"",
107
+ "quantity":"Quantity",
108
+ "unit": "Unit",
109
+ "price_per_item":"Price per item",
110
+ "amount":"Amount",
111
+ "tax":"Tax",
112
+ "tax2":"Tax 2",
113
+ "tax3":"Tax 3",
114
+ "subtotal":"Subtotal",
115
+ "total":"Total",
116
+ "sublabels":{
117
+ "name":"Faktura",
118
+ "provider":"Prodejce",
119
+ "purchaser":"Kupující",
120
+ "tax_id":"IČ",
121
+ "tax_id2":"DIČ",
122
+ "payment":"Forma úhrady",
123
+ "payment_by_transfer":"Platba na následující účet:",
124
+ "account_number":"Číslo účtu",
125
+ "issue_date":"Datum vydání",
126
+ "due_date":"Datum splatnosti",
127
+ "item":"Položka",
128
+ "variable:":"",
129
+ "quantity":"Počet",
130
+ "unit":"MJ",
131
+ "price_per_item":"Cena za položku",
132
+ "amount":"Celkem bez daně",
133
+ "subtota":"Cena bez daně",
134
+ "tax":"DPH 21 %",
135
+ "total":"Celkem"
136
+ }
137
+ }
138
+ ```
139
+ **Note**: Notice the `sublabels` which you might not want to necessary include.
140
+
141
+ ## Built-in fonts
142
+
143
+ Supported builtin fonts are: `overpass`, `opensans`, and `roboto`. They ship with bold versions.
144
+
23
145
  ## Examples
24
146
 
25
147
  ```
data/docs/LIBRARY.md CHANGED
@@ -31,6 +31,7 @@ Here is an full example for creating the document object:
31
31
  ```ruby
32
32
  item = InvoicePrinter::Document::Item.new(
33
33
  name: 'Web consultation',
34
+ breakdown: 'Excludes 1h free consultation',
34
35
  quantity: nil,
35
36
  unit: 'hours',
36
37
  price: '$ 25',
@@ -72,13 +73,11 @@ invoice = InvoicePrinter::Document.new(
72
73
  **Note**: `provider_lines` and `purchaser_lines` are 4 lines of data separated by new line character`\n`. Other lines are being stripped.
73
74
 
74
75
  **Note**: There is `variable` field that can be used for any
75
- extra column. `tax2` and `tax3` for more complex taxes are
76
- available as well.
76
+ extra column.
77
77
 
78
78
  ### Ruby on Rails
79
79
 
80
- If you want to use InvoicePrinter for printing PDF documents directly from Rails
81
- actions, you can:
80
+ If you want to use InvoicePrinter for printing PDF documents directly from Rails actions, you can:
82
81
 
83
82
  ```ruby
84
83
  # GET /invoices/1
@@ -109,11 +108,8 @@ InvoicePrinter.print(
109
108
  document: document,
110
109
  ...
111
110
  )
112
-
113
111
  ```
114
112
 
115
-
116
-
117
113
  ## Customization
118
114
 
119
115
  ### Page size
@@ -153,8 +149,7 @@ InvoicePrinter.print(
153
149
  )
154
150
  ```
155
151
 
156
- Here is the full list of labels to configure. You can paste and edit this block
157
- to `initializers/invoice_printer.rb` if you are using Rails.
152
+ Here is the full list of labels to configure. You can paste and edit this block to `initializers/invoice_printer.rb` if you are using Rails.
158
153
 
159
154
  ```ruby
160
155
  InvoicePrinter.labels = {
@@ -171,6 +166,7 @@ InvoicePrinter.labels = {
171
166
  iban: 'IBAN',
172
167
  issue_date: 'Issue date',
173
168
  due_date: 'Due date',
169
+ variable_symbol: 'Variable symbol',
174
170
  item: 'Item',
175
171
  variable: '',
176
172
  quantity: 'Quantity',
@@ -204,6 +200,7 @@ sublabels = {
204
200
  account_number: 'Číslo účtu',
205
201
  issue_date: 'Datum vydání',
206
202
  due_date: 'Datum splatnosti',
203
+ variable_symbol: 'Variabilní symbol',
207
204
  item: 'Položka',
208
205
  variable: '',
209
206
  quantity: 'Počet',
@@ -226,16 +223,23 @@ Now the document will have little sublabels next to the original labels in Czech
226
223
 
227
224
  To support specific characters you might need to specify a TTF font to be used:
228
225
 
229
- ``` ruby
226
+ ```ruby
230
227
  InvoicePrinter.print(
231
228
  ...
232
229
  font: File.expand_path('../Overpass-Regular.ttf', __FILE__)
233
230
  )
234
231
  ```
235
232
 
236
- If you don't have a font around, you can install `invoice_printer_fonts` gem and specify the supported font name instead.
233
+ If you don't have a font around, you can install `invoice_printer_fonts` gem and specify the supported font name instead:
234
+
235
+ ```ruby
236
+ InvoicePrinter.print(
237
+ document: invoice,
238
+ font: "roboto"
239
+ )
240
+ ```
237
241
 
238
- Supported builtin fonts are: `overpass`, `opensans`, and `ruboto`. Note that searching the path takes preference.
242
+ Supported builtin fonts are: `overpass`, `opensans`, and `roboto`. Note that searching the path takes preference.
239
243
 
240
244
  ### Background
241
245