invoice_printer 2.0.0 → 2.1.0.rc1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97ea4a809c4a18acd04d91edcef4d1950468c230a417e7df3908ecc03eb53766
4
- data.tar.gz: ffc3a08b88914e8761fa925b6a3b6ff11e47b2e49e9c2542d566f358c378adbb
3
+ metadata.gz: 926ffa0b9c6ce419a715122202dbc5e5b6489323c0daafe1da259cb86efb0acc
4
+ data.tar.gz: d0a6882d42b488d4df932f8b5981a188beb515af31ec3a0d5eb49a6b64a28882
5
5
  SHA512:
6
- metadata.gz: 45b38f99524e0a0b6b44028ec55e4cdce79fcdfcf8c9cf6a40b8cc4878a26da59cb55cf90038bbb56142cd210873f9e534cc8e5156b5a426a19d0305bf404239
7
- data.tar.gz: d5369bc2301aaa7ae07d7196a2ccc3363fb8827776c155bf668747775699e3c6f7691a5a090f3ce2fdda325891a2e39ccb7a5c9fbf07c0619ccb13820eb8aeae
6
+ metadata.gz: 383e3dc9b714a1faf3a585ed9313db8d0e77031d4556643894395757de723a787b216f5af2eba8ea7aa5c183c0d5ea55bc69534bf9bc40def043767f10c9aeb3
7
+ data.tar.gz: b53666c983492ffc59668c305b4b1e1e914f78488a44ec8c048c83de847a4a3559a0092534795d985a61c0192698ab99a2f0b3ecdf8d74a91dde1ff3a7f524af
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- invoice_printer (2.0.0.beta3)
4
+ invoice_printer (2.0.0)
5
5
  json (~> 2.1)
6
6
  prawn (~> 2.2)
7
7
  prawn-table (~> 0.2.2)
8
- invoice_printer_server (2.0.0.beta3)
9
- invoice_printer (= 2.0.0.beta3)
8
+ invoice_printer_server (2.0.0)
9
+ invoice_printer (= 2.0.0)
10
10
  json (~> 2.1)
11
11
  puma (>= 3.9.0)
12
12
  roda (~> 3.5)
@@ -20,37 +20,39 @@ GEM
20
20
  benchmark_driver-output-gruff (0.3.1)
21
21
  benchmark_driver (>= 0.12.0)
22
22
  gruff
23
- gruff (0.7.0)
24
- rmagick (~> 2.13, >= 2.13.4)
23
+ gruff (0.11.0)
24
+ histogram
25
+ rmagick
25
26
  hashery (2.1.2)
26
- json (2.2.0)
27
- minitest (5.11.3)
28
- nio4r (2.5.1)
29
- pdf-core (0.7.0)
27
+ histogram (0.2.4.1)
28
+ json (2.3.1)
29
+ minitest (5.14.2)
30
+ nio4r (2.5.4)
31
+ pdf-core (0.9.0)
30
32
  pdf-inspector (1.3.0)
31
33
  pdf-reader (>= 1.0, < 3.0.a)
32
- pdf-reader (2.2.1)
34
+ pdf-reader (2.4.1)
33
35
  Ascii85 (~> 1.0.0)
34
36
  afm (~> 0.2.1)
35
37
  hashery (~> 2.0)
36
38
  ruby-rc4
37
39
  ttfunk
38
- prawn (2.2.2)
39
- pdf-core (~> 0.7.0)
40
- ttfunk (~> 1.5)
40
+ prawn (2.4.0)
41
+ pdf-core (~> 0.9.0)
42
+ ttfunk (~> 1.7)
41
43
  prawn-table (0.2.2)
42
44
  prawn (>= 1.3.0, < 3.0.0)
43
- puma (4.1.0)
45
+ puma (5.0.2)
44
46
  nio4r (~> 2.0)
45
- rack (2.0.7)
47
+ rack (2.2.3)
46
48
  rack-test (1.1.0)
47
49
  rack (>= 1.0, < 3)
48
- rake (12.3.3)
49
- rmagick (2.16.0)
50
- roda (3.23.0)
50
+ rake (13.0.1)
51
+ rmagick (4.1.2)
52
+ roda (3.36.0)
51
53
  rack
52
54
  ruby-rc4 (0.1.5)
53
- ttfunk (1.5.1)
55
+ ttfunk (1.7.0)
54
56
 
55
57
  PLATFORMS
56
58
  ruby
@@ -66,4 +68,4 @@ DEPENDENCIES
66
68
  rake (>= 10.0)
67
69
 
68
70
  BUNDLED WITH
69
- 1.17.2
71
+ 2.1.4
data/README.md CHANGED
@@ -28,7 +28,7 @@ See more usecases in the `examples/` directory.
28
28
  - Configurable items' table with item description, 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)
@@ -48,4 +48,4 @@ See more usecases in the `examples/` directory.
48
48
 
49
49
  ## Copyright
50
50
 
51
- Copyright 2015-2019 &copy; [Josef Strzibny](http://strzibny.name/). MIT licensed.
51
+ Copyright 2015-2021 &copy; [Josef Strzibny](http://strzibny.name/). MIT licensed.
@@ -8,6 +8,17 @@ prelude: |
8
8
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
9
9
  require 'invoice_printer'
10
10
 
11
+ provider_address = <<ADDRESS
12
+ Rolnická 1
13
+ 747 05 Opava
14
+ Kateřinky
15
+ ADDRESS
16
+
17
+ purchaser_address = <<ADDRESS
18
+ Ostravská 1
19
+ 747 70 Opava
20
+ ADDRESS
21
+
11
22
  item = InvoicePrinter::Document::Item.new(
12
23
  name: 'Programming',
13
24
  quantity: '10',
@@ -19,15 +30,9 @@ prelude: |
19
30
  invoice = InvoicePrinter::Document.new(
20
31
  number: 'NO. 198900000001',
21
32
  provider_name: 'John White',
22
- provider_street: '5th Avenue',
23
- provider_street_number: '1',
24
- provider_postcode: '747 05',
25
- provider_city: 'NYC',
33
+ provider_lines: provider_address,
26
34
  purchaser_name: 'Will Black',
27
- purchaser_street: '7th Avenue',
28
- purchaser_street_number: '1',
29
- purchaser_postcode: '747 70',
30
- purchaser_city: 'NYC',
35
+ purchaser_lines: purchaser_address,
31
36
  issue_date: '05/03/2016',
32
37
  due_date: '19/03/2016',
33
38
  total: '$ 900',
data/docs/COMMAND_LINE.md CHANGED
@@ -20,6 +20,125 @@ Options:
20
20
  -f, --filename output path
21
21
  -r, --render directly render PDF stream (filename option will be ignored)
22
22
  ```
23
+
24
+ ## Document
25
+
26
+ JSON document with all possible fields filled:
27
+
28
+ ```json
29
+ {
30
+ "number":"c. 198900000001",
31
+ "provider_name":"Petr Novy",
32
+ "provider_tax_id":"56565656",
33
+ "provider_tax_id2":"",
34
+ "provider_lines":"Rolnická 1\n747 05 Opava\nKateřinky",
35
+ "purchaser_name":"Adam Cerny",
36
+ "purchaser_tax_id":"",
37
+ "purchaser_tax_id2":"",
38
+ "purchaser_lines":"Ostravská 1\n747 70 Opava",
39
+ "issue_date":"05/03/2016",
40
+ "due_date":"19/03/2016",
41
+ "subtotal":"Kc 10.000",
42
+ "tax":"Kc 2.100",
43
+ "tax2":"",
44
+ "tax3":"",
45
+ "variable":"Extra column",
46
+ "total":"Kc 12.100,-",
47
+ "bank_account_number":"156546546465",
48
+ "account_iban":"IBAN464545645",
49
+ "account_swift":"SWIFT5456",
50
+ "items":[
51
+ {
52
+ "name":"Konzultace",
53
+ "variable": "",
54
+ "quantity":"2",
55
+ "unit":"hod",
56
+ "price":"Kc 500",
57
+ "tax":"",
58
+ "tax2":"",
59
+ "tax3":"",
60
+ "amount":"Kc 1.000"
61
+ },
62
+ {
63
+ "name":"Programovani",
64
+ "variable": "",
65
+ "quantity":"10",
66
+ "unit":"hod",
67
+ "price":"Kc 900",
68
+ "tax":"",
69
+ "tax2":"",
70
+ "tax3":"",
71
+ "amount":"Kc 9.000"
72
+ }
73
+ ],
74
+ "note":"Osoba je zapsána v zivnostenském rejstríku."
75
+ }
76
+ ```
77
+
78
+ **Note**: `provider_lines` and `purchaser_lines` are 4 lines of data separated by new line character`\n`. Other lines are being stripped.
79
+
80
+ **Note**: There is `variable` field that can be used for any
81
+ extra column.
82
+
83
+ ## Field labels
84
+
85
+ All labels:
86
+
87
+ ```json
88
+ {
89
+ "name":"Invoice",
90
+ "provider":"Provider",
91
+ "purchaser":"Purchaser",
92
+ "tax_id":"Identification number",
93
+ "tax_id2":"Identification number",
94
+ "payment":"Payment",
95
+ "payment_by_transfer":"Payment by bank transfer on the account below:",
96
+ "payment_in_cash":"Payment in cash",
97
+ "account_number":"Account NO",
98
+ "swift":"SWIFT",
99
+ "iban":"IBAN",
100
+ "issue_date":"Issue date",
101
+ "due_date": "Due date",
102
+ "item":"Item",
103
+ "variable":"",
104
+ "quantity":"Quantity",
105
+ "unit": "Unit",
106
+ "price_per_item":"Price per item",
107
+ "amount":"Amount",
108
+ "tax":"Tax",
109
+ "tax2":"Tax 2",
110
+ "tax3":"Tax 3",
111
+ "subtotal":"Subtotal",
112
+ "total":"Total",
113
+ "sublabels":{
114
+ "name":"Faktura",
115
+ "provider":"Prodejce",
116
+ "purchaser":"Kupující",
117
+ "tax_id":"IČ",
118
+ "tax_id2":"DIČ",
119
+ "payment":"Forma úhrady",
120
+ "payment_by_transfer":"Platba na následující účet:",
121
+ "account_number":"Číslo účtu",
122
+ "issue_date":"Datum vydání",
123
+ "due_date":"Datum splatnosti",
124
+ "item":"Položka",
125
+ "variable:":"",
126
+ "quantity":"Počet",
127
+ "unit":"MJ",
128
+ "price_per_item":"Cena za položku",
129
+ "amount":"Celkem bez daně",
130
+ "subtota":"Cena bez daně",
131
+ "tax":"DPH 21 %",
132
+ "total":"Celkem"
133
+ }
134
+ }
135
+ ```
136
+ **Note**: Notice the `sublabels` which you might not want to necessary include.
137
+
138
+ ## Built-in fonts
139
+
140
+ Supported builtin fonts are: `overpass`, `opensans`, and `roboto`.
141
+
23
142
  ## Examples
24
143
 
25
144
  ```
data/docs/LIBRARY.md CHANGED
@@ -72,13 +72,11 @@ invoice = InvoicePrinter::Document.new(
72
72
  **Note**: `provider_lines` and `purchaser_lines` are 4 lines of data separated by new line character`\n`. Other lines are being stripped.
73
73
 
74
74
  **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.
75
+ extra column.
77
76
 
78
77
  ### Ruby on Rails
79
78
 
80
- If you want to use InvoicePrinter for printing PDF documents directly from Rails
81
- actions, you can:
79
+ If you want to use InvoicePrinter for printing PDF documents directly from Rails actions, you can:
82
80
 
83
81
  ```ruby
84
82
  # GET /invoices/1
@@ -109,11 +107,8 @@ InvoicePrinter.print(
109
107
  document: document,
110
108
  ...
111
109
  )
112
-
113
110
  ```
114
111
 
115
-
116
-
117
112
  ## Customization
118
113
 
119
114
  ### Page size
@@ -153,8 +148,7 @@ InvoicePrinter.print(
153
148
  )
154
149
  ```
155
150
 
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.
151
+ 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
152
 
159
153
  ```ruby
160
154
  InvoicePrinter.labels = {
@@ -226,16 +220,23 @@ Now the document will have little sublabels next to the original labels in Czech
226
220
 
227
221
  To support specific characters you might need to specify a TTF font to be used:
228
222
 
229
- ``` ruby
223
+ ```ruby
230
224
  InvoicePrinter.print(
231
225
  ...
232
226
  font: File.expand_path('../Overpass-Regular.ttf', __FILE__)
233
227
  )
234
228
  ```
235
229
 
236
- If you don't have a font around, you can install `invoice_printer_fonts` gem and specify the supported font name instead.
230
+ If you don't have a font around, you can install `invoice_printer_fonts` gem and specify the supported font name instead:
231
+
232
+ ```ruby
233
+ InvoicePrinter.print(
234
+ document: invoice,
235
+ font: "roboto"
236
+ )
237
+ ```
237
238
 
238
- Supported builtin fonts are: `overpass`, `opensans`, and `ruboto`. Note that searching the path takes preference.
239
+ Supported builtin fonts are: `overpass`, `opensans`, and `roboto`. Note that searching the path takes preference.
239
240
 
240
241
  ### Background
241
242
 
data/docs/SERVER.md CHANGED
@@ -23,9 +23,11 @@ By default server binds to `0.0.0.0:9393`.
23
23
  Get the public image and run it:
24
24
 
25
25
  ```bash
26
- $ sudo docker pull strzibnyj/invoice_printer_server:latest
27
- $ sudo docker run -d -p 9393:9393 -t docker.io/strzibnyj/invoice_printer_server
26
+ $ sudo docker pull strzibnyj/invoice_printer_server:$VERSION
27
+ $ sudo docker run -d -p 9393:9393 -v ~/path/to/invocies:/data:Z -t docker.io/strzibnyj/invoice_printer_server
28
28
  ```
29
+ You can use `latest` as a `$VERSION`. Specifying the `-v` option is only required when using the `/print` action to create the documents at certain path. It will allow you to provide the desired filename as "/data/invoice-name.pdf".
30
+
29
31
  The server will then be available on `0.0.0.0:9393`.
30
32
 
31
33
  Docker image already contains the optional `invoice_printer_fonts` gem.
@@ -64,6 +66,8 @@ Options:
64
66
  - `background` - path to background file
65
67
  - `page_size` - letter or A4 page size
66
68
 
69
+ These parameters are the same as for the [command line](./COMMAND_LINE.md).
70
+
67
71
  On success a `200` response is returned:
68
72
 
69
73
  ```json
@@ -47,7 +47,8 @@ Rolnická 1
47
47
  747 05 Opava
48
48
  Kateřinky
49
49
 
50
- fith line wont show
50
+
51
+ 6th line wont show
51
52
  ADDRESS
52
53
 
53
54
  purchaser_address = <<ADDRESS
@@ -55,8 +56,7 @@ Ostravská 1
55
56
  747 70 Opava
56
57
 
57
58
 
58
-
59
- fith line wont show
59
+ 6th line wont show
60
60
  ADDRESS
61
61
 
62
62
  invoice = InvoicePrinter::Document.new(
@@ -64,20 +64,11 @@ invoice = InvoicePrinter::Document.new(
64
64
  provider_name: 'Petr Nový',
65
65
  provider_tax_id: '56565656',
66
66
  provider_tax_id2: 'CZ56565656',
67
- provider_street: 'Rolnická',
68
- provider_street_number: '1',
69
- provider_postcode: '747 05',
70
- provider_city: 'Opava',
71
- provider_city_part: 'Kateřinky',
72
67
  provider_lines: provider_address,
73
68
  purchaser_name: 'Adam Černý',
74
- purchaser_street: 'Ostravská',
75
- purchaser_street_number: '1',
76
- purchaser_postcode: '747 70',
77
- purchaser_city: 'Opava',
78
- purchaser_lines: purchaser_address,
79
69
  purchaser_tax_id: '56565656',
80
70
  purchaser_tax_id2: 'CZ56565656',
71
+ purchaser_lines: purchaser_address,
81
72
  issue_date: '05/03/2016',
82
73
  due_date: '19/03/2016',
83
74
  subtotal: 'Kč 10.000',
@@ -5,6 +5,16 @@ lib = File.expand_path('../../lib', __FILE__)
5
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
  require 'invoice_printer'
7
7
 
8
+ provider_address = <<ADDRESS
9
+ 5th Avenue
10
+ 747 05 NYC
11
+ ADDRESS
12
+
13
+ purchaser_address = <<ADDRESS
14
+ 7th Avenue
15
+ 747 70 NYC
16
+ ADDRESS
17
+
8
18
  item = InvoicePrinter::Document::Item.new(
9
19
  name: 'Programming',
10
20
  quantity: '10',
@@ -16,25 +26,14 @@ item = InvoicePrinter::Document::Item.new(
16
26
  invoice = InvoicePrinter::Document.new(
17
27
  number: 'NO. 198900000001',
18
28
  provider_name: 'John White',
19
- # Deprecated 1.3 API, use provider_lines
20
- # Here for compatibility test
21
- provider_street: '5th Avenue',
22
- provider_street_number: '1',
23
- provider_postcode: '747 05',
24
- provider_city: 'NYC',
25
- purchaser_name: 'Will Black',
26
- # Deprecated 1.3 API, use purchaser_lines
27
- # Here for compatibility test
28
- purchaser_street: '7th Avenue',
29
- purchaser_street_number: '1',
30
- purchaser_postcode: '747 70',
31
- purchaser_city: 'NYC',
29
+ provider_lines: provider_address,
30
+ purchaser_lines: purchaser_address,
32
31
  issue_date: '05/03/2016',
33
32
  due_date: '19/03/2016',
34
33
  total: '$ 900',
35
34
  bank_account_number: '156546546465',
36
35
  items: [item],
37
- note: 'This is a note at the end.'
36
+ note: "This is a note at the end.\nA note with two lines."
38
37
  )
39
38
 
40
39
  InvoicePrinter.print(
@@ -39,25 +39,11 @@ module InvoicePrinter
39
39
  :provider_tax_id,
40
40
  :provider_tax_id2,
41
41
  :provider_lines,
42
- # Provider address fields
43
- :provider_street,
44
- :provider_street_number,
45
- :provider_postcode,
46
- :provider_city,
47
- :provider_city_part,
48
- :provider_extra_address_line,
49
42
  # Purchaser fields
50
43
  :purchaser_name,
51
44
  :purchaser_tax_id,
52
45
  :purchaser_tax_id2,
53
46
  :purchaser_lines,
54
- # Purchaser address fields
55
- :purchaser_street,
56
- :purchaser_street_number,
57
- :purchaser_postcode,
58
- :purchaser_city,
59
- :purchaser_city_part,
60
- :purchaser_extra_address_line,
61
47
  :issue_date,
62
48
  :due_date,
63
49
  # Account details
@@ -76,113 +62,75 @@ module InvoicePrinter
76
62
  class << self
77
63
  def from_json(json)
78
64
  new(
79
- number: json['number'],
80
- provider_name: json['provider_name'],
81
- provider_tax_id: json['provider_tax_id'],
82
- provider_tax_id2: json['provider_tax_id2'],
83
- provider_street: json['provider_street'],
84
- provider_street_number: json['provider_street_number'],
85
- provider_postcode: json['provider_postcode'],
86
- provider_city: json['provider_city'],
87
- provider_city_part: json['provider_city_part'],
88
- provider_extra_address_line: json['provider_extra_address_line'],
89
- provider_lines: json['provider_lines'],
90
- purchaser_name: json['purchaser_name'],
91
- purchaser_tax_id: json['purchaser_tax_id'],
92
- purchaser_tax_id2: json['purchaser_tax_id2'],
93
- purchaser_street: json['purchaser_street'],
94
- purchaser_street_number: json['purchaser_street_number'],
95
- purchaser_postcode: json['purchaser_postcode'],
96
- purchaser_city: json['purchaser_city'],
97
- purchaser_city_part: json['purchaser_city_part'],
98
- purchaser_extra_address_line: json['purchaser_extra_address_line'],
99
- purchaser_lines: json['purchaser_lines'],
100
- issue_date: json['issue_date'],
101
- due_date: json['due_date'],
102
- subtotal: json['subtotal'],
103
- tax: json['tax'],
104
- tax2: json['tax2'],
105
- tax3: json['tax3'],
106
- total: json['total'],
107
- bank_account_number: json['bank_account_number'],
108
- account_iban: json['account_iban'],
109
- account_swift: json['account_swift'],
110
- note: json['note'],
65
+ number: json['number'],
66
+ provider_name: json['provider_name'],
67
+ provider_tax_id: json['provider_tax_id'],
68
+ provider_tax_id2: json['provider_tax_id2'],
69
+ provider_lines: json['provider_lines'],
70
+ purchaser_name: json['purchaser_name'],
71
+ purchaser_tax_id: json['purchaser_tax_id'],
72
+ purchaser_tax_id2: json['purchaser_tax_id2'],
73
+ purchaser_lines: json['purchaser_lines'],
74
+ issue_date: json['issue_date'],
75
+ due_date: json['due_date'],
76
+ subtotal: json['subtotal'],
77
+ tax: json['tax'],
78
+ tax2: json['tax2'],
79
+ tax3: json['tax3'],
80
+ total: json['total'],
81
+ bank_account_number: json['bank_account_number'],
82
+ account_iban: json['account_iban'],
83
+ account_swift: json['account_swift'],
84
+ note: json['note'],
111
85
 
112
- items: (json['items'] || []).map { |item_json| Item.from_json(item_json) }
86
+ items: (json['items'] || []).map { |item_json| Item.from_json(item_json) }
113
87
  )
114
88
  end
115
89
  end
116
90
 
117
- def initialize(number: nil,
118
- provider_name: nil,
119
- provider_tax_id: nil,
120
- provider_tax_id2: nil,
121
- provider_street: nil,
122
- provider_street_number: nil,
123
- provider_postcode: nil,
124
- provider_city: nil,
125
- provider_city_part: nil,
126
- provider_extra_address_line: nil,
127
- provider_lines: nil,
128
- purchaser_name: nil,
129
- purchaser_tax_id: nil,
130
- purchaser_tax_id2: nil,
131
- purchaser_street: nil,
132
- purchaser_street_number: nil,
133
- purchaser_postcode: nil,
134
- purchaser_city: nil,
135
- purchaser_city_part: nil,
136
- purchaser_extra_address_line: nil,
137
- purchaser_lines: nil,
138
- issue_date: nil,
139
- due_date: nil,
140
- subtotal: nil,
141
- tax: nil,
142
- tax2: nil,
143
- tax3: nil,
144
- total: nil,
145
- bank_account_number: nil,
146
- account_iban: nil,
147
- account_swift: nil,
148
- items: nil,
149
- note: nil)
150
-
151
- @number = String(number)
152
- @provider_name = String(provider_name)
153
- @provider_tax_id = String(provider_tax_id)
154
- @provider_tax_id2 = String(provider_tax_id2)
155
- @provider_street = String(provider_street)
156
- @provider_street_number = String(provider_street_number)
157
- @provider_postcode = String(provider_postcode)
158
- @provider_city = String(provider_city)
159
- @provider_city_part = String(provider_city_part)
160
- @provider_extra_address_line = String(provider_extra_address_line)
161
- @provider_lines = String(provider_lines)
162
- @purchaser_name = String(purchaser_name)
163
- @purchaser_tax_id = String(purchaser_tax_id)
164
- @purchaser_tax_id2 = String(purchaser_tax_id2)
165
- @purchaser_street = String(purchaser_street)
166
- @purchaser_street_number = String(purchaser_street_number)
167
- @purchaser_postcode = String(purchaser_postcode)
168
- @purchaser_city = String(purchaser_city)
169
- @purchaser_city_part = String(purchaser_city_part)
170
- @purchaser_extra_address_line = String(purchaser_extra_address_line)
171
- @purchaser_lines = String(purchaser_lines)
172
- @issue_date = String(issue_date)
173
- @due_date = String(due_date)
174
- @subtotal = String(subtotal)
175
- @tax = String(tax)
176
- @tax2 = String(tax2)
177
- @tax3 = String(tax3)
178
- @total = String(total)
179
- @bank_account_number = String(bank_account_number)
180
- @account_iban = String(account_iban)
181
- @account_swift = String(account_swift)
182
- @items = items
183
- @note = String(note)
184
-
91
+ def initialize(number: nil,
92
+ provider_name: nil,
93
+ provider_tax_id: nil,
94
+ provider_tax_id2: nil,
95
+ provider_lines: nil,
96
+ purchaser_name: nil,
97
+ purchaser_tax_id: nil,
98
+ purchaser_tax_id2: nil,
99
+ purchaser_lines: nil,
100
+ issue_date: nil,
101
+ due_date: nil,
102
+ subtotal: nil,
103
+ tax: nil,
104
+ tax2: nil,
105
+ tax3: nil,
106
+ total: nil,
107
+ bank_account_number: nil,
108
+ account_iban: nil,
109
+ account_swift: nil,
110
+ items: nil,
111
+ note: nil)
185
112
 
113
+ @number = String(number)
114
+ @provider_name = String(provider_name)
115
+ @provider_tax_id = String(provider_tax_id)
116
+ @provider_tax_id2 = String(provider_tax_id2)
117
+ @provider_lines = String(provider_lines)
118
+ @purchaser_name = String(purchaser_name)
119
+ @purchaser_tax_id = String(purchaser_tax_id)
120
+ @purchaser_tax_id2 = String(purchaser_tax_id2)
121
+ @purchaser_lines = String(purchaser_lines)
122
+ @issue_date = String(issue_date)
123
+ @due_date = String(due_date)
124
+ @subtotal = String(subtotal)
125
+ @tax = String(tax)
126
+ @tax2 = String(tax2)
127
+ @tax3 = String(tax3)
128
+ @total = String(total)
129
+ @bank_account_number = String(bank_account_number)
130
+ @account_iban = String(account_iban)
131
+ @account_swift = String(account_swift)
132
+ @items = items
133
+ @note = String(note)
186
134
 
187
135
  raise InvalidInput, 'items are not only a type of InvoicePrinter::Document::Item' \
188
136
  unless @items.select{ |i| !i.is_a?(InvoicePrinter::Document::Item) }.empty?
@@ -190,39 +138,27 @@ module InvoicePrinter
190
138
 
191
139
  def to_h
192
140
  {
193
- 'number': @number,
194
- 'provider_name': @provider_name,
195
- 'provider_tax_id': @provider_tax_id,
196
- 'provider_tax_id2': @provider_tax_id2,
197
- 'provider_street': @provider_street,
198
- 'provider_street_number': @provider_street_number,
199
- 'provider_postcode': @provider_postcode,
200
- 'provider_city': @provider_city,
201
- 'provider_city_part': @provider_city_part,
202
- 'provider_extra_address_line': @provider_extra_address_line,
203
- 'provider_lines': @provider_lines,
204
- 'purchaser_name': @purchaser_name,
205
- 'purchaser_tax_id': @purchaser_tax_id,
206
- 'purchaser_tax_id2': @purchaser_tax_id2,
207
- 'purchaser_street': @purchaser_street,
208
- 'purchaser_street_number': @purchaser_street_number,
209
- 'purchaser_postcode': @purchaser_postcode,
210
- 'purchaser_city': @purchaser_city,
211
- 'purchaser_city_part': @purchaser_city_part,
212
- 'purchaser_extra_address_line': @purchaser_extra_address_line,
213
- 'purchaser_lines': @purchaser_lines,
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
141
+ 'number': @number,
142
+ 'provider_name': @provider_name,
143
+ 'provider_tax_id': @provider_tax_id,
144
+ 'provider_tax_id2': @provider_tax_id2,
145
+ 'provider_lines': @provider_lines,
146
+ 'purchaser_name': @purchaser_name,
147
+ 'purchaser_tax_id': @purchaser_tax_id,
148
+ 'purchaser_tax_id2': @purchaser_tax_id2,
149
+ 'purchaser_lines': @purchaser_lines,
150
+ 'issue_date': @issue_date,
151
+ 'due_date': @due_date,
152
+ 'subtotal': @subtotal,
153
+ 'tax': @tax,
154
+ 'tax2': @tax2,
155
+ 'tax3': @tax3,
156
+ 'total': @total,
157
+ 'bank_account_number': @bank_account_number,
158
+ 'account_iban': @account_iban,
159
+ 'account_swift': @account_swift,
160
+ 'items': @items.map(&:to_h),
161
+ 'note': @note
226
162
  }
227
163
  end
228
164
 
@@ -97,36 +97,6 @@ module InvoicePrinter
97
97
  use_font(@font)
98
98
  end
99
99
 
100
- # Version 2.1 deprecation warnings
101
- warnings = [
102
- @document.provider_street,
103
- @document.provider_street_number,
104
- @document.provider_postcode,
105
- @document.provider_city,
106
- @document.provider_city_part,
107
- @document.provider_extra_address_line,
108
- @document.purchaser_street,
109
- @document.purchaser_street_number,
110
- @document.purchaser_postcode,
111
- @document.purchaser_city,
112
- @document.purchaser_city_part,
113
- @document.purchaser_extra_address_line
114
- ].delete_if(&:empty?)
115
-
116
- unless warnings.empty?
117
- warning = <<~WARN
118
- WARNING: Following values are used in deprecated fields and
119
- won't be rendered in future versions of InvoicePrinter:
120
-
121
- #{warnings.join(", ")}
122
-
123
- Use new provider_lines and purchaser_lines fields instead of
124
- the old address fields.
125
- WARN
126
-
127
- $stderr.puts warning
128
- end
129
-
130
100
  build_pdf
131
101
  end
132
102
 
@@ -859,7 +829,7 @@ module InvoicePrinter
859
829
  # If a note is present, position it on top of it.
860
830
  def build_logo
861
831
  if @logo && !@logo.empty?
862
- bottom = @document.note.empty? ? 75 : 85
832
+ bottom = @document.note.empty? ? 75 : (75 + note_height)
863
833
  @pdf.image(@logo, at: [0, bottom], fit: [200, 50])
864
834
  end
865
835
  end
@@ -877,12 +847,19 @@ module InvoicePrinter
877
847
  @pdf.text_box(
878
848
  "#{@document.note}",
879
849
  size: 10,
880
- at: [0, 10],
850
+ at: [0, note_height],
881
851
  width: x(450),
882
852
  align: :left
883
853
  )
884
854
  end
885
855
 
856
+ def note_height
857
+ @note_height ||= begin
858
+ num_of_lines = @document.note.lines.count
859
+ (num_of_lines * 11)
860
+ end
861
+ end
862
+
886
863
  # Include page numbers if we got more than one page
887
864
  def build_footer
888
865
  @pdf.number_pages(
@@ -1,3 +1,3 @@
1
1
  module InvoicePrinter
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0.rc1'
3
3
  end
data/test/api_test.rb CHANGED
@@ -31,7 +31,7 @@ class ApiTest < Minitest::Test
31
31
  end
32
32
 
33
33
  def test_print_with_valid_document
34
- invoice = InvoicePrinter::Document.new(default_document_params)
34
+ invoice = InvoicePrinter::Document.new(**default_document_params)
35
35
 
36
36
  json = {
37
37
  'document' => invoice.to_h,
@@ -60,7 +60,7 @@ class ApiTest < Minitest::Test
60
60
  end
61
61
 
62
62
  def test_render_with_valid_document
63
- invoice = InvoicePrinter::Document.new(default_document_params)
63
+ invoice = InvoicePrinter::Document.new(**default_document_params)
64
64
  output = InvoicePrinter.render(document: invoice)
65
65
 
66
66
  json = {
@@ -4,7 +4,7 @@ class BackgroundTest < Minitest::Test
4
4
  include InvoicePrinterHelpers
5
5
 
6
6
  def setup
7
- @invoice = InvoicePrinter::Document.new(default_document_params)
7
+ @invoice = InvoicePrinter::Document.new(**default_document_params)
8
8
  end
9
9
 
10
10
  def test_background_render
data/test/cli_test.rb CHANGED
@@ -8,7 +8,7 @@ class CLITest < Minitest::Test
8
8
  t = Time.now.strftime("%Y%m%d")
9
9
  tmpname = "/tmp/invoice-#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-fd"
10
10
 
11
- @invoice = InvoicePrinter::Document.new(default_document_params)
11
+ @invoice = InvoicePrinter::Document.new(**default_document_params)
12
12
  @invoice_as_json = @invoice.to_json
13
13
  @output_path = tmpname
14
14
  end
@@ -8,7 +8,7 @@ class DatesBoxTest < Minitest::Test
8
8
  issue_date: '05/03/2016',
9
9
  due_date: '14/03/2016'
10
10
  )
11
- invoice = InvoicePrinter::Document.new(params)
11
+ invoice = InvoicePrinter::Document.new(**params)
12
12
  rendered_pdf = InvoicePrinter.render(document: invoice)
13
13
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
14
14
 
@@ -21,7 +21,7 @@ class DatesBoxTest < Minitest::Test
21
21
  issue_date: '05/03/2016',
22
22
  due_date: ''
23
23
  )
24
- invoice = InvoicePrinter::Document.new(params)
24
+ invoice = InvoicePrinter::Document.new(**params)
25
25
  rendered_pdf = InvoicePrinter.render(document: invoice)
26
26
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
27
27
 
@@ -34,7 +34,7 @@ class DatesBoxTest < Minitest::Test
34
34
  issue_date: nil,
35
35
  due_date: '05/03/2016'
36
36
  )
37
- invoice = InvoicePrinter::Document.new(params)
37
+ invoice = InvoicePrinter::Document.new(**params)
38
38
  rendered_pdf = InvoicePrinter.render(document: invoice)
39
39
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
40
40
 
@@ -47,7 +47,7 @@ class DatesBoxTest < Minitest::Test
47
47
  issue_date: '',
48
48
  due_date: nil
49
49
  )
50
- invoice = InvoicePrinter::Document.new(params)
50
+ invoice = InvoicePrinter::Document.new(**params)
51
51
  rendered_pdf = InvoicePrinter.render(document: invoice)
52
52
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
53
53
 
data/test/inputs_test.rb CHANGED
@@ -28,12 +28,12 @@ class InputsTest < Minitest::Test
28
28
  )
29
29
 
30
30
  # No exceptions should be raised
31
- invoice = InvoicePrinter::Document.new(params)
31
+ invoice = InvoicePrinter::Document.new(**params)
32
32
  InvoicePrinter.render(document: invoice)
33
33
  end
34
34
 
35
35
  def test_missing_font_raises_an_exception
36
- invoice = InvoicePrinter::Document.new(default_document_params)
36
+ invoice = InvoicePrinter::Document.new(**default_document_params)
37
37
 
38
38
  assert_raises(InvoicePrinter::PDFDocument::FontFileNotFound) do
39
39
  InvoicePrinter.render(document: invoice, font: 'missing.font')
@@ -41,7 +41,7 @@ class InputsTest < Minitest::Test
41
41
  end
42
42
 
43
43
  def test_missing_logo_raises_an_exception
44
- invoice = InvoicePrinter::Document.new(default_document_params)
44
+ invoice = InvoicePrinter::Document.new(**default_document_params)
45
45
 
46
46
  assert_raises(InvoicePrinter::PDFDocument::LogoFileNotFound) do
47
47
  InvoicePrinter.render(document: invoice, logo: 'missing.png')
@@ -49,7 +49,7 @@ class InputsTest < Minitest::Test
49
49
  end
50
50
 
51
51
  def test_missing_stamp_raises_an_exception
52
- invoice = InvoicePrinter::Document.new(default_document_params)
52
+ invoice = InvoicePrinter::Document.new(**default_document_params)
53
53
 
54
54
  assert_raises(InvoicePrinter::PDFDocument::StampFileNotFound) do
55
55
  InvoicePrinter.render(document: invoice, stamp: 'missing.png')
@@ -4,7 +4,7 @@ class InvoicePrinterTest < Minitest::Test
4
4
  include InvoicePrinterHelpers
5
5
 
6
6
  def test_render_document
7
- invoice = InvoicePrinter::Document.new(default_document_params)
7
+ invoice = InvoicePrinter::Document.new(**default_document_params)
8
8
  rendered_pdf = InvoicePrinter.render(document: invoice)
9
9
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
10
10
  strings = InvoicePrinter::PDFDocument.new(document: invoice).to_a
@@ -13,7 +13,7 @@ class InvoicePrinterTest < Minitest::Test
13
13
  end
14
14
 
15
15
  def test_render_document_from_json
16
- invoice = InvoicePrinter::Document.new(default_document_params)
16
+ invoice = InvoicePrinter::Document.new(**default_document_params)
17
17
  invoice_json = JSON.parse(invoice.to_json)
18
18
  invoice_from_json = InvoicePrinter::Document.from_json(invoice_json)
19
19
  rendered_pdf = InvoicePrinter.render(document: invoice_from_json)
@@ -41,10 +41,10 @@ class ItemsTableTest < Minitest::Test
41
41
 
42
42
  def invoice_without_item_column(column)
43
43
  InvoicePrinter::Document.new(
44
- default_document_params.merge(
44
+ **default_document_params.merge(
45
45
  items: [
46
46
  InvoicePrinter::Document::Item.new(
47
- default_document_item_params.merge("#{column}": nil)
47
+ **default_document_item_params.merge("#{column}": nil)
48
48
  )
49
49
  ]
50
50
  )
data/test/labels_test.rb CHANGED
@@ -6,7 +6,7 @@ class LabelsTest < Minitest::Test
6
6
  def test_setting_global_labels
7
7
  labels = { provider: 'Default Provider', purchaser: 'Default Purchaser' }
8
8
  InvoicePrinter.labels = labels
9
- invoice = InvoicePrinter::Document.new(default_document_params)
9
+ invoice = InvoicePrinter::Document.new(**default_document_params)
10
10
  rendered_pdf = InvoicePrinter.render(document: invoice)
11
11
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
12
12
 
@@ -16,7 +16,7 @@ class LabelsTest < Minitest::Test
16
16
 
17
17
  def test_setting_instant_labels
18
18
  labels = { provider: 'Current Provider', purchaser: 'Current Purchaser' }
19
- invoice = InvoicePrinter::Document.new(default_document_params)
19
+ invoice = InvoicePrinter::Document.new(**default_document_params)
20
20
  rendered_pdf = InvoicePrinter.render(document: invoice, labels: labels)
21
21
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
22
22
 
data/test/notes_test.rb CHANGED
@@ -7,7 +7,7 @@ class NotesTest < Minitest::Test
7
7
  params = default_document_params.merge(
8
8
  note: 'ABC is a registered trademark.'
9
9
  )
10
- invoice = InvoicePrinter::Document.new(params)
10
+ invoice = InvoicePrinter::Document.new(**params)
11
11
  rendered_pdf = InvoicePrinter.render(document: invoice)
12
12
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
13
13
 
@@ -5,11 +5,11 @@ class PageNumbersTest < Minitest::Test
5
5
 
6
6
  # If there is only one page, we skip numbering
7
7
  def test_do_not_number_1_page
8
- item = InvoicePrinter::Document::Item.new(default_document_item_params)
8
+ item = InvoicePrinter::Document::Item.new(**default_document_item_params)
9
9
  params = default_document_params.merge(
10
10
  items: [item]
11
11
  )
12
- invoice = InvoicePrinter::Document.new(params)
12
+ invoice = InvoicePrinter::Document.new(**params)
13
13
  rendered_pdf = InvoicePrinter.render(document: invoice)
14
14
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
15
15
 
@@ -17,12 +17,12 @@ class PageNumbersTest < Minitest::Test
17
17
  end
18
18
 
19
19
  def test_number_2_and_more_pages
20
- item = InvoicePrinter::Document::Item.new(default_document_item_params)
20
+ item = InvoicePrinter::Document::Item.new(**default_document_item_params)
21
21
  items = [item] * 50
22
22
  params = default_document_params.merge(
23
23
  items: items
24
24
  )
25
- invoice = InvoicePrinter::Document.new(params)
25
+ invoice = InvoicePrinter::Document.new(**params)
26
26
  rendered_pdf = InvoicePrinter.render(document: invoice)
27
27
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
28
28
 
@@ -8,7 +8,7 @@ class PaymentBoxTest < Minitest::Test
8
8
  bank_account_number: nil,
9
9
  account_iban: 'IBAN'
10
10
  )
11
- invoice = InvoicePrinter::Document.new(params)
11
+ invoice = InvoicePrinter::Document.new(**params)
12
12
  rendered_pdf = InvoicePrinter.render(document: invoice)
13
13
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
14
14
 
@@ -24,7 +24,7 @@ class PaymentBoxTest < Minitest::Test
24
24
  account_iban: nil,
25
25
  account_swift: nil
26
26
  )
27
- invoice = InvoicePrinter::Document.new(params)
27
+ invoice = InvoicePrinter::Document.new(**params)
28
28
  rendered_pdf = InvoicePrinter.render(document: invoice)
29
29
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
30
30
 
@@ -41,7 +41,7 @@ class PaymentBoxTest < Minitest::Test
41
41
  account_iban: 'SAMPLE_IBAN',
42
42
  account_swift: nil
43
43
  )
44
- invoice = InvoicePrinter::Document.new(params)
44
+ invoice = InvoicePrinter::Document.new(**params)
45
45
  rendered_pdf = InvoicePrinter.render(document: invoice)
46
46
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
47
47
 
@@ -59,7 +59,7 @@ class PaymentBoxTest < Minitest::Test
59
59
  account_iban: nil,
60
60
  account_swift: 'SAMPLE_SWIFT'
61
61
  )
62
- invoice = InvoicePrinter::Document.new(params)
62
+ invoice = InvoicePrinter::Document.new(**params)
63
63
  rendered_pdf = InvoicePrinter.render(document: invoice)
64
64
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
65
65
 
@@ -77,7 +77,7 @@ class PaymentBoxTest < Minitest::Test
77
77
  account_iban: 'SAMPLE_IBAN',
78
78
  account_swift: 'SAMPLE_SWIFT'
79
79
  )
80
- invoice = InvoicePrinter::Document.new(params)
80
+ invoice = InvoicePrinter::Document.new(**params)
81
81
  rendered_pdf = InvoicePrinter.render(document: invoice)
82
82
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
83
83
 
data/test/test_helper.rb CHANGED
@@ -33,7 +33,7 @@ module InvoicePrinterHelpers
33
33
  account_swift: 'SWIFT5456',
34
34
  items: [
35
35
  InvoicePrinter::Document::Item.new(
36
- default_document_item_params
36
+ **default_document_item_params
37
37
  )
38
38
  ]
39
39
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoice_printer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josef Strzibny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-02 00:00:00.000000000 Z
11
+ date: 2021-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -153,11 +153,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
153
  version: '2.4'
154
154
  required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  requirements:
156
- - - ">="
156
+ - - ">"
157
157
  - !ruby/object:Gem::Version
158
- version: '0'
158
+ version: 1.3.1
159
159
  requirements: []
160
- rubygems_version: 3.0.3
160
+ rubygems_version: 3.2.0.rc.1
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: Super simple PDF invoicing in pure Ruby