invoice_printer 2.0.0.beta3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
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.
@@ -59,11 +61,14 @@ Options:
59
61
  - `document` - JSON representation of the document
60
62
  - `labels` - JSON for labels
61
63
  - `font` - path to font file or builtin font name
64
+ - `bold_font` - path to bold font file or builtin font name
62
65
  - `stamp` - path to stamp file
63
66
  - `logo` - path to logotype file
64
67
  - `background` - path to background file
65
68
  - `page_size` - letter or A4 page size
66
69
 
70
+ These parameters are the same as for the [command line](./COMMAND_LINE.md).
71
+
67
72
  On success a `200` response is returned:
68
73
 
69
74
  ```json
@@ -99,6 +104,7 @@ Options:
99
104
  - `document` - JSON representation of the document
100
105
  - `labels` - JSON for labels
101
106
  - `font` - path to font file or builtin font name
107
+ - `bold_font` - path to bold font file or builtin font name
102
108
  - `stamp` - path to stamp file
103
109
  - `logo` - path to logotype file
104
110
  - `background` - path to background file
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+ # This is an example of a longer invoice.
3
+
4
+ lib = File.expand_path('../../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'invoice_printer'
7
+
8
+ labels = {
9
+ tax: '10% VAT'
10
+ }
11
+
12
+ item = InvoicePrinter::Document::Item.new(
13
+ name: 'Programming',
14
+ quantity: '10',
15
+ unit: 'h',
16
+ price: '$ 60',
17
+ tax: '$ 60',
18
+ amount: '$ 600'
19
+ )
20
+
21
+ item2 = InvoicePrinter::Document::Item.new(
22
+ name: 'Consulting',
23
+ breakdown: "Excludes 1 hour free consultation",
24
+ quantity: '10',
25
+ unit: 'h',
26
+ price: '$ 30',
27
+ tax: '$ 30',
28
+ amount: '$ 300'
29
+ )
30
+
31
+ breakdown = <<BREAKDOWN
32
+ Issue 404: 15h
33
+ Issue 505: 5h
34
+ BREAKDOWN
35
+
36
+ item3 = InvoicePrinter::Document::Item.new(
37
+ name: 'Support',
38
+ breakdown: breakdown,
39
+ quantity: '20',
40
+ unit: 'h',
41
+ price: '$ 15',
42
+ tax: '$ 30',
43
+ amount: '$ 330'
44
+ )
45
+
46
+ invoice = InvoicePrinter::Document.new(
47
+ number: 'NO. 198900000001',
48
+ provider_name: 'John White',
49
+ provider_lines: "79 Stonybrook St.\nBronx, NY 10457",
50
+ purchaser_name: 'Will Black',
51
+ purchaser_lines: "8648 Acacia Rd.\nBrooklyn, NY 11203",
52
+ issue_date: '05/03/2016',
53
+ due_date: '19/03/2016',
54
+ subtotal: '$ 1,000',
55
+ tax: '$ 100',
56
+ total: '$ 1,100',
57
+ bank_account_number: '156546546465',
58
+ items: [item, item2, item3],
59
+ note: 'This is a note at the end.'
60
+ )
61
+
62
+ InvoicePrinter.print(
63
+ document: invoice,
64
+ labels: labels,
65
+ stamp: File.expand_path('../stamp.png', __FILE__),
66
+ logo: File.expand_path('../prawn.png', __FILE__),
67
+ file_name: 'breakdown.pdf'
68
+ )
69
+
70
+ InvoicePrinter.print(
71
+ document: invoice,
72
+ labels: labels,
73
+ stamp: File.expand_path('../stamp.png', __FILE__),
74
+ logo: File.expand_path('../prawn.png', __FILE__),
75
+ file_name: 'breakdown_a4.pdf',
76
+ page_size: :a4
77
+ )
@@ -80,7 +80,7 @@ InvoicePrinter.print(
80
80
  document: invoice,
81
81
  labels: labels,
82
82
  font: 'overpass',
83
- logo: 'prawn.png',
83
+ logo: File.expand_path('../prawn.png', __FILE__),
84
84
  file_name: 'international_invoice.pdf'
85
85
  )
86
86
 
@@ -88,7 +88,7 @@ InvoicePrinter.print(
88
88
  document: invoice,
89
89
  labels: labels,
90
90
  font: 'overpass',
91
- logo: 'prawn.png',
91
+ logo: File.expand_path('../prawn.png', __FILE__),
92
92
  file_name: 'international_invoice_a4.pdf',
93
93
  page_size: :a4
94
94
  )
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # This is an example of a very simple invoice.
2
+ # This is an example of a longer invoice.
3
3
 
4
4
  lib = File.expand_path('../../lib', __FILE__)
5
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -12,7 +12,7 @@ labels = {
12
12
  item = InvoicePrinter::Document::Item.new(
13
13
  name: 'Programming',
14
14
  quantity: '10',
15
- unit: 'hr',
15
+ unit: 'h',
16
16
  price: '$ 60',
17
17
  tax: '$ 60',
18
18
  amount: '$ 600'
@@ -21,7 +21,7 @@ item = InvoicePrinter::Document::Item.new(
21
21
  item2 = InvoicePrinter::Document::Item.new(
22
22
  name: 'Consulting',
23
23
  quantity: '10',
24
- unit: 'hr',
24
+ unit: 'h',
25
25
  price: '$ 30',
26
26
  tax: '$ 30',
27
27
  amount: '$ 300'
@@ -30,7 +30,7 @@ item2 = InvoicePrinter::Document::Item.new(
30
30
  item3 = InvoicePrinter::Document::Item.new(
31
31
  name: 'Support',
32
32
  quantity: '20',
33
- unit: 'hr',
33
+ unit: 'h',
34
34
  price: '$ 15',
35
35
  tax: '$ 30',
36
36
  amount: '$ 330'
@@ -55,16 +55,16 @@ invoice = InvoicePrinter::Document.new(
55
55
  InvoicePrinter.print(
56
56
  document: invoice,
57
57
  labels: labels,
58
- stamp: 'stamp.png',
59
- logo: 'prawn.png',
58
+ stamp: File.expand_path('../stamp.png', __FILE__),
59
+ logo: File.expand_path('../prawn.png', __FILE__),
60
60
  file_name: 'long_invoice.pdf'
61
61
  )
62
62
 
63
63
  InvoicePrinter.print(
64
64
  document: invoice,
65
65
  labels: labels,
66
- stamp: 'stamp.png',
67
- logo: 'prawn.png',
66
+ stamp: File.expand_path('../stamp.png', __FILE__),
67
+ logo: File.expand_path('../prawn.png', __FILE__),
68
68
  file_name: 'long_invoice_a4.pdf',
69
69
  page_size: :a4
70
70
  )
data/examples/picture.jpg CHANGED
Binary file
data/examples/promo.rb CHANGED
@@ -46,20 +46,24 @@ second_item = InvoicePrinter::Document::Item.new(
46
46
  amount: 'Kč 9.000'
47
47
  )
48
48
 
49
+ provider_address = <<ADDRESS
50
+ Rolnická 1
51
+ 747 05 Opava
52
+ Kateřinky
53
+ ADDRESS
54
+
55
+ purchaser_address = <<ADDRESS
56
+ Ostravská 1
57
+ 747 70 Opava
58
+ ADDRESS
59
+
49
60
  invoice = InvoicePrinter::Document.new(
50
61
  number: 'č. 198900000001',
51
62
  provider_name: 'Petr Nový',
63
+ provider_lines: provider_address,
52
64
  provider_tax_id: '56565656',
53
- provider_street: 'Rolnická',
54
- provider_street_number: '1',
55
- provider_postcode: '747 05',
56
- provider_city: 'Opava',
57
- provider_city_part: 'Kateřinky',
58
65
  purchaser_name: 'Adam Černý',
59
- purchaser_street: 'Ostravská',
60
- purchaser_street_number: '1',
61
- purchaser_postcode: '747 70',
62
- purchaser_city: 'Opava',
66
+ purchaser_lines: purchaser_address,
63
67
  issue_date: '05/03/2016',
64
68
  due_date: '19/03/2016',
65
69
  subtotal: 'Kč 10.000',
@@ -75,16 +79,18 @@ invoice = InvoicePrinter::Document.new(
75
79
  InvoicePrinter.print(
76
80
  document: invoice,
77
81
  labels: labels,
78
- font: File.expand_path('../../../assets/fonts/overpass/Overpass-Regular.ttf', __FILE__),
79
- logo: 'logo.png',
82
+ font: File.expand_path('../../assets/fonts/overpass/Overpass-Regular.ttf', __FILE__),
83
+ bold_font: File.expand_path('../../assets/fonts/overpass/Overpass-Bold.ttf', __FILE__),
84
+ logo: File.expand_path('../logo.png', __FILE__),
80
85
  file_name: 'promo.pdf'
81
86
  )
82
87
 
83
88
  InvoicePrinter.print(
84
89
  document: invoice,
85
90
  labels: labels,
86
- font: File.expand_path('../../../assets/fonts/overpass/Overpass-Regular.ttf', __FILE__),
87
- logo: 'logo.png',
91
+ font: File.expand_path('../../assets/fonts/overpass/Overpass-Regular.ttf', __FILE__),
92
+ bold_font: File.expand_path('../../assets/fonts/overpass/Overpass-Bold.ttf', __FILE__),
93
+ logo: File.expand_path('../logo.png', __FILE__),
88
94
  file_name: 'promo_a4.pdf',
89
95
  page_size: :a4
90
96
  )
@@ -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',
@@ -94,7 +85,7 @@ InvoicePrinter.print(
94
85
  document: invoice,
95
86
  labels: labels,
96
87
  font: 'overpass',
97
- logo: 'prawn.png',
88
+ logo: File.expand_path('../prawn.png', __FILE__),
98
89
  file_name: 'provider_purchaser_lines.pdf'
99
90
  )
100
91
 
@@ -102,7 +93,7 @@ InvoicePrinter.print(
102
93
  document: invoice,
103
94
  labels: labels,
104
95
  font: 'overpass',
105
- logo: 'prawn.png',
96
+ logo: File.expand_path('../prawn.png', __FILE__),
106
97
  file_name: 'provider_purchaser_lines_a4.pdf',
107
98
  page_size: :a4
108
99
  )
@@ -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,36 +26,25 @@ 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(
41
40
  document: invoice,
42
- logo: 'prawn.png',
41
+ logo: File.expand_path('../prawn.png', __FILE__),
43
42
  file_name: 'simple_invoice.pdf'
44
43
  )
45
44
 
46
45
  InvoicePrinter.print(
47
46
  document: invoice,
48
- logo: 'prawn.png',
47
+ logo: File.expand_path('../prawn.png', __FILE__),
49
48
  file_name: 'simple_invoice_a4.pdf',
50
49
  page_size: :a4
51
50
  )
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+ # This is an example of a international invoice with Czech labels and English translation.
3
+
4
+ lib = File.expand_path('../../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'invoice_printer'
7
+
8
+ labels = {
9
+ name: 'Faktura',
10
+ provider: 'Prodejce',
11
+ purchaser: 'Kupující',
12
+ tax_id: 'IČ',
13
+ tax_id2: 'DIČ',
14
+ payment: 'Forma úhrady',
15
+ payment_by_transfer: 'Platba na následující účet:',
16
+ account_number: 'Číslo účtu',
17
+ issue_date: 'Datum vydání',
18
+ due_date: 'Datum splatnosti',
19
+ variable_field: 'Variabilní symbol',
20
+ item: 'Položka',
21
+ quantity: 'Počet',
22
+ unit: 'MJ',
23
+ price_per_item: 'Cena za položku',
24
+ amount: 'Celkem bez daně',
25
+ subtotal: 'Cena bez daně',
26
+ tax: 'DPH 21 %',
27
+ total: 'Celkem'
28
+ }
29
+
30
+ # Default English labels as sublabels
31
+ sublabels = InvoicePrinter::PDFDocument::DEFAULT_LABELS
32
+ labels.merge!({ sublabels: sublabels })
33
+
34
+ first_item = InvoicePrinter::Document::Item.new(
35
+ name: 'Konzultace',
36
+ quantity: '2',
37
+ unit: 'hod',
38
+ price: 'Kč 500',
39
+ amount: 'Kč 1.000'
40
+ )
41
+
42
+ second_item = InvoicePrinter::Document::Item.new(
43
+ name: 'Programování',
44
+ quantity: '10',
45
+ unit: 'hod',
46
+ price: 'Kč 900',
47
+ amount: 'Kč 9.000'
48
+ )
49
+
50
+ provider_address = <<ADDRESS
51
+ Rolnická 1
52
+ 747 05 Opava
53
+ Kateřinky
54
+ ADDRESS
55
+
56
+ purchaser_address = <<ADDRESS
57
+ 8648 Acacia Rd.
58
+ Brooklyn, NY 11203
59
+ ADDRESS
60
+
61
+ invoice = InvoicePrinter::Document.new(
62
+ number: 'č. 198900000001',
63
+ provider_name: 'Petr Nový',
64
+ provider_lines: provider_address,
65
+ provider_tax_id: '56565656',
66
+ purchaser_name: 'Adam Black',
67
+ purchaser_lines: purchaser_address,
68
+ issue_date: '05/03/2016',
69
+ due_date: '19/03/2016',
70
+ variable_symbol: 'VS198900000001',
71
+ subtotal: 'Kč 10.000',
72
+ tax: 'Kč 2.100',
73
+ total: 'Kč 12.100,-',
74
+ bank_account_number: '156546546465',
75
+ account_iban: 'IBAN464545645',
76
+ account_swift: 'SWIFT5456',
77
+ items: [first_item, second_item],
78
+ note: 'Osoba je zapsána v živnostenském rejstříku.'
79
+ )
80
+
81
+ InvoicePrinter.print(
82
+ document: invoice,
83
+ labels: labels,
84
+ font: 'overpass',
85
+ logo: File.expand_path('../prawn.png', __FILE__),
86
+ file_name: 'variable_field_invoice.pdf'
87
+ )
88
+
89
+ InvoicePrinter.print(
90
+ document: invoice,
91
+ labels: labels,
92
+ font: 'overpass',
93
+ logo: File.expand_path('../prawn.png', __FILE__),
94
+ file_name: 'variable_field_invoice_a4.pdf',
95
+ page_size: :a4
96
+ )