invoice_printer 1.3.0 → 2.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 327ecc31f48a1b7a25b413c9423c47ce335c1a1b
4
- data.tar.gz: bb454cbed1da8260b3f73c8f6ede4db3328326e5
2
+ SHA256:
3
+ metadata.gz: cdf5ab1be5ba608592e459feb3295450b61fb43d063adf9e250281bad74fa87e
4
+ data.tar.gz: ffbe76f56621e22d5e0020ba0a285305b4ce018f5923d7240e543140fb8b9acd
5
5
  SHA512:
6
- metadata.gz: 1aa09af511628b9dba7d3d5aa3497c33f5927c0d96b55964b5cf0a9b24219582dde29e3a8d8855fc8806ab99c77b4e69f4f34ad0cda1e52a520d8a3a5f362c95
7
- data.tar.gz: 8de19983830a6263597e6799fd6c7738c81b5ee1b73dff6e44a504ef5b80c093da19eb7cbf25f73161987a9388314972df12f9e80e43f6f69be4a81aeecadbaa
6
+ metadata.gz: 9d5f1023dd14f26e190b579edf7a4def0f86530574d64024a4ebd49d82735efcd4294a0913e09c95a38ed44e8a12fe46ac56326e8e1d8db565d3a9df242a9441
7
+ data.tar.gz: f768d976020dc7397241344cecf5daa164e24e51f71815105cf37d781b8d9e278a6f98af3445cbb97deb8df3d46dbc082be5999e666016735ff411ae975d1059
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in invoice_printer.gemspec
4
- gemspec
3
+ # Specify server's gemspec since it will have all dependencies
4
+ gemspec name: 'invoice_printer_server'
5
5
 
6
6
  group :test do
7
7
  gem 'pdf-inspector'
@@ -1,12 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- invoice_printer (1.2.0)
4
+ invoice_printer_server (2.0.0.alpha1)
5
5
  json (~> 2.1)
6
- prawn (= 2.1.0)
7
- prawn-layout (= 0.8.4)
8
- puma (~> 3.9)
9
- roda (= 3.5.0)
6
+ puma (>= 3.9.0)
7
+ roda (~> 3.5)
10
8
 
11
9
  GEM
12
10
  remote: https://rubygems.org/
@@ -20,9 +18,9 @@ GEM
20
18
  gruff (0.7.0)
21
19
  rmagick (~> 2.13, >= 2.13.4)
22
20
  hashery (2.1.2)
23
- json (2.1.0)
21
+ json (2.2.0)
24
22
  minitest (5.11.3)
25
- pdf-core (0.6.1)
23
+ nio4r (2.3.1)
26
24
  pdf-inspector (1.3.0)
27
25
  pdf-reader (>= 1.0, < 3.0.a)
28
26
  pdf-reader (2.2.0)
@@ -31,17 +29,14 @@ GEM
31
29
  hashery (~> 2.0)
32
30
  ruby-rc4
33
31
  ttfunk
34
- prawn (2.1.0)
35
- pdf-core (~> 0.6.1)
36
- ttfunk (~> 1.4.0)
37
- prawn-layout (0.8.4)
38
- puma (3.12.0)
32
+ puma (4.0.0)
33
+ nio4r (~> 2.0)
39
34
  rack (2.0.6)
40
35
  rack-test (1.1.0)
41
36
  rack (>= 1.0, < 3)
42
37
  rake (10.5.0)
43
38
  rmagick (2.16.0)
44
- roda (3.5.0)
39
+ roda (3.21.0)
45
40
  rack
46
41
  ruby-rc4 (0.1.5)
47
42
  ttfunk (1.4.0)
@@ -52,12 +47,12 @@ PLATFORMS
52
47
  DEPENDENCIES
53
48
  benchmark_driver (= 0.14.11)
54
49
  benchmark_driver-output-gruff
55
- bundler (~> 1.7)
56
- invoice_printer!
50
+ bundler (>= 1.7)
51
+ invoice_printer_server!
57
52
  minitest
58
53
  pdf-inspector
59
54
  rack-test
60
- rake (~> 10.0)
55
+ rake (>= 10.0)
61
56
 
62
57
  BUNDLED WITH
63
- 1.16.1
58
+ 1.17.2
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015-2016 Josef Strzibny
1
+ Copyright (c) 2015-2019 Josef Strzibny
2
2
 
3
3
  MIT License
4
4
 
data/Rakefile CHANGED
@@ -1,9 +1,10 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks(name: 'invoice_printer_server')
3
3
 
4
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
5
5
  require 'invoice_printer'
6
6
 
7
+ require 'rake/testtask'
7
8
  Rake::TestTask.new('test') do |t|
8
9
  t.libs << 'test'
9
10
  t.pattern = 'test/**/*test.rb'
@@ -5,7 +5,7 @@ require 'optparse'
5
5
  require 'invoice_printer'
6
6
 
7
7
  def show_version
8
- puts "InvoicePrinter v#{InvoicePrinter::VERSION}"
8
+ puts "InvoicePrinter Server v#{InvoicePrinter::VERSION}"
9
9
 
10
10
  exit 0
11
11
  end
@@ -25,6 +25,7 @@ def show_help
25
25
  --page-size letter or a4 (letter is the default)
26
26
  -f, --filename output path
27
27
  -r, --render directly render PDF stream (filename option will be ignored)
28
+ -v, --version show version
28
29
 
29
30
  HELP
30
31
 
@@ -19,5 +19,9 @@ Options:
19
19
  --page-size letter or a4 (letter is the default)
20
20
  -f, --filename output path
21
21
  -r, --render directly render PDF stream (filename option will be ignored)
22
+ ```
23
+ ## Examples
22
24
 
23
25
  ```
26
+ $ invoice_printer --document '{"number":"c. 198900000001","provider_name":"Petr Novy","provider_tax_id":"56565656","provider_tax_id2":"","provider_lines":"Rolnická 1\n747 05 Opava\nKateřinky","purchaser_name":"Adam Cerny","purchaser_tax_id":"","purchaser_tax_id2":"","purchaser_lines":"Ostravská 1\n747 70 Opava","issue_date":"05/03/2016","due_date":"19/03/2016","subtotal":"Kc 10.000","tax":"Kc 2.100","tax2":"","tax3":"","total":"Kc 12.100,-","bank_account_number":"156546546465","account_iban":"IBAN464545645","account_swift":"SWIFT5456","items":[{"name":"Konzultace","quantity":"2","unit":"hod","price":"Kc 500","tax":"","tax2":"","tax3":"","amount":"Kc 1.000"},{"name":"Programovani","quantity":"10","unit":"hod","price":"Kc 900","tax":"","tax2":"","tax3":"","amount":"Kc 9.000"}],"note":"Osoba je zapsána v zivnostenském rejstríku."}' --font Overpass-Regular.ttf --filename out.pdf
27
+ ```
@@ -38,26 +38,22 @@ item = InvoicePrinter::Document::Item.new(
38
38
  amount: '$ 100'
39
39
  )
40
40
 
41
+ provider_address = <<~ADDRESS
42
+ Rolnická 1
43
+ 747 05 Opava
44
+ Kateřinky
45
+ ADDRESS
46
+
41
47
  invoice = InvoicePrinter::Document.new(
42
48
  number: '201604030001',
43
49
  provider_name: 'Business s.r.o.',
44
50
  provider_tax_id: '56565656',
45
51
  provider_tax_id2: '465454',
46
- provider_street: 'Rolnicka',
47
- provider_street_number: '1',
48
- provider_postcode: '747 05',
49
- provider_city: 'Opava',
50
- provider_city_part: 'Katerinky',
51
- provider_extra_address_line: 'Czech Republic',
52
+ provider_lines: provider_address,
52
53
  purchaser_name: 'Adam',
53
54
  purchaser_tax_id: '',
54
55
  purchaser_tax_id2: '',
55
- purchaser_street: 'Ostravska',
56
- purchaser_street_number: '1',
57
- purchaser_postcode: '747 70',
58
- purchaser_city: 'Opava',
59
- purchaser_city_part: '',
60
- purchaser_extra_address_line: '',
56
+ purchaser_lines: "Ostravská 1\n747 70 Opava",
61
57
  issue_date: '19/03/3939',
62
58
  due_date: '19/03/3939',
63
59
  subtotal: '175',
@@ -73,6 +69,8 @@ invoice = InvoicePrinter::Document.new(
73
69
  )
74
70
  ```
75
71
 
72
+ **Note**: `provider_lines` and `purchaser_lines` are 4 lines of data separated by new line character`\n`. Other lines are being stripped.
73
+
76
74
  **Note**: There is `variable` field that can be used for any
77
75
  extra column. `tax2` and `tax3` for more complex taxes are
78
76
  available as well.
@@ -71,7 +71,7 @@ On error a `400` response is returned:
71
71
  Example of calling the API to render a document using `curl`:
72
72
 
73
73
  ```
74
- $ curl -X POST http://0.0.0.0:9393/render -H "Content-Type: application/json" --data '{"document":{"number":"c. 198900000001","provider_name":"Petr Novy","provider_tax_id":"56565656","provider_tax_id2":"","provider_street":"Rolnicka","provider_street_number":"1","provider_postcode":"747 05","provider_city":"Opava","provider_city_part":"Katerinky","provider_extra_address_line":"","purchaser_name":"Adam Cerny","purchaser_tax_id":"","purchaser_tax_id2":"","purchaser_street":"Ostravska","purchaser_street_number":"1","purchaser_postcode":"747 70","purchaser_city":"Opava","purchaser_city_part":"","purchaser_extra_address_line":"","issue_date":"05/03/2016","due_date":"19/03/2016","subtotal":"Kc 10.000","tax":"Kc 2.100","tax2":"","tax3":"","total":"Kc 12.100,-","bank_account_number":"156546546465","account_iban":"IBAN464545645","account_swift":"SWIFT5456","items":[{"name":"Konzultace","quantity":"2","unit":"hod","price":"Kc 500","tax":"","tax2":"","tax3":"","amount":"Kc 1.000"},{"name":"Programovani","quantity":"10","unit":"hod","price":"Kc 900","tax":"","tax2":"","tax3":"","amount":"Kc 9.000"}],"note":"Osoba je zapsána v zivnostenském rejstríku."}}'
74
+ $ curl -X POST http://0.0.0.0:9393/render -H "Content-Type: application/json" --data '{"document":{"number":"c. 198900000001","provider_name":"Petr Novy","provider_tax_id":"56565656","provider_tax_id2":"","provider_lines":"Rolnická 1\n747 05 Opava\nKateřinky","purchaser_name":"Adam Cerny","purchaser_tax_id":"","purchaser_tax_id2":"","purchaser_lines":"Ostravská 1\n747 70 Opava","issue_date":"05/03/2016","due_date":"19/03/2016","subtotal":"Kc 10.000","tax":"Kc 2.100","tax2":"","tax3":"","total":"Kc 12.100,-","bank_account_number":"156546546465","account_iban":"IBAN464545645","account_swift":"SWIFT5456","items":[{"name":"Konzultace","quantity":"2","unit":"hod","price":"Kc 500","tax":"","tax2":"","tax3":"","amount":"Kc 1.000"},{"name":"Programovani","quantity":"10","unit":"hod","price":"Kc 900","tax":"","tax2":"","tax3":"","amount":"Kc 9.000"}],"note":"Osoba je zapsána v zivnostenském rejstríku."}}'
75
75
  ```
76
76
 
77
77
  ##### Node.js
@@ -13,21 +13,11 @@ const invoice = {
13
13
  "provider_name": "John White",
14
14
  "provider_tax_id": "",
15
15
  "provider_tax_id2": "",
16
- "provider_street": "5th Avenue",
17
- "provider_street_number": "1",
18
- "provider_postcode": "747 05",
19
- "provider_city": "NYC",
20
- "provider_city_part": "",
21
- "provider_extra_address_line": "",
16
+ "provider_lines": "79 Stonybrook St.\nBronx, NY 10457",
22
17
  "purchaser_name": "Will Black",
23
18
  "purchaser_tax_id": "",
24
19
  "purchaser_tax_id2": "",
25
- "purchaser_street": "7th Avenue",
26
- "purchaser_street_number": "1",
27
- "purchaser_postcode": "747 70",
28
- "purchaser_city": "NYC",
29
- "purchaser_city_part": "",
30
- "purchaser_extra_address_line": "",
20
+ "purchaser_lines": "8648 Acacia Rd.\nBrooklyn, NY 11203",
31
21
  "issue_date": "05/03/2016",
32
22
  "due_date": "19/03/2016",
33
23
  "subtotal": "$ 1,000",
@@ -46,15 +46,9 @@ item3 = InvoicePrinter::Document::Item.new(
46
46
  invoice = InvoicePrinter::Document.new(
47
47
  number: 'NO. 198900000001',
48
48
  provider_name: 'John White',
49
- provider_street: '5th Avenue',
50
- provider_street_number: '1',
51
- provider_postcode: '747 05',
52
- provider_city: 'NYC',
49
+ provider_lines: "79 Stonybrook St.\nBronx, NY 10457",
53
50
  purchaser_name: 'Will Black',
54
- purchaser_street: '7th Avenue',
55
- purchaser_street_number: '1',
56
- purchaser_postcode: '747 70',
57
- purchaser_city: 'NYC',
51
+ purchaser_lines: "8648 Acacia Rd.\nBrooklyn, NY 11203",
58
52
  issue_date: '05/03/2016',
59
53
  due_date: '19/03/2016',
60
54
  subtotal: '$ 1,000',
@@ -45,21 +45,25 @@ second_item = InvoicePrinter::Document::Item.new(
45
45
  amount: 'Kč 9.000'
46
46
  )
47
47
 
48
+ provider_address = <<ADDRESS
49
+ Rolnická 1
50
+ 747 05 Opava
51
+ Kateřinky
52
+ ADDRESS
53
+
54
+ purchaser_address = <<ADDRESS
55
+ Ostravská 1
56
+ 747 70 Opava
57
+ ADDRESS
58
+
48
59
  invoice = InvoicePrinter::Document.new(
49
60
  number: 'č. 198900000001',
50
61
  provider_name: 'Petr Nový',
62
+ provider_lines: provider_address,
51
63
  provider_tax_id: '56565656',
52
64
  provider_tax_id2: 'CZ56565656',
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
  purchaser_tax_id: '56565656',
64
68
  purchaser_tax_id2: 'CZ56565656',
65
69
  issue_date: '05/03/2016',
@@ -45,21 +45,25 @@ second_item = InvoicePrinter::Document::Item.new(
45
45
  amount: 'Kč 9.000'
46
46
  )
47
47
 
48
+ provider_address = <<ADDRESS
49
+ Rolnická 1
50
+ 747 05 Opava
51
+ Kateřinky
52
+ ADDRESS
53
+
54
+ purchaser_address = <<ADDRESS
55
+ Ostravská 1
56
+ 747 70 Opava
57
+ ADDRESS
58
+
48
59
  invoice = InvoicePrinter::Document.new(
49
60
  number: 'č. 198900000001',
50
61
  provider_name: 'Petr Nový',
62
+ provider_lines: provider_address,
51
63
  provider_tax_id: '56565656',
52
64
  provider_tax_id2: 'CZ56565656',
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
  purchaser_tax_id: '56565656',
64
68
  purchaser_tax_id2: 'CZ56565656',
65
69
  issue_date: '05/03/2016',
@@ -49,20 +49,24 @@ second_item = InvoicePrinter::Document::Item.new(
49
49
  amount: 'Kč 9.000'
50
50
  )
51
51
 
52
+ provider_address = <<ADDRESS
53
+ Rolnická 1
54
+ 747 05 Opava
55
+ Kateřinky
56
+ ADDRESS
57
+
58
+ purchaser_address = <<ADDRESS
59
+ 8648 Acacia Rd.
60
+ Brooklyn, NY 11203
61
+ ADDRESS
62
+
52
63
  invoice = InvoicePrinter::Document.new(
53
64
  number: 'č. 198900000001',
54
65
  provider_name: 'Petr Nový',
66
+ provider_lines: provider_address,
55
67
  provider_tax_id: '56565656',
56
- provider_street: 'Rolnická',
57
- provider_street_number: '1',
58
- provider_postcode: '747 05',
59
- provider_city: 'Opava',
60
- provider_city_part: 'Kateřinky',
61
- purchaser_name: 'Adam Černý',
62
- purchaser_street: 'Ostravská',
63
- purchaser_street_number: '1',
64
- purchaser_postcode: '747 70',
65
- purchaser_city: 'Opava',
68
+ purchaser_name: 'Adam Black',
69
+ purchaser_lines: purchaser_address,
66
70
  issue_date: '05/03/2016',
67
71
  due_date: '19/03/2016',
68
72
  subtotal: 'Kč 10.000',
@@ -39,15 +39,9 @@ item3 = InvoicePrinter::Document::Item.new(
39
39
  invoice = InvoicePrinter::Document.new(
40
40
  number: 'NO. 198900000001',
41
41
  provider_name: 'John White',
42
- provider_street: '5th Avenue',
43
- provider_street_number: '1',
44
- provider_postcode: '747 05',
45
- provider_city: 'NYC',
42
+ provider_lines: "79 Stonybrook St.\nBronx, NY 10457",
46
43
  purchaser_name: 'Will Black',
47
- purchaser_street: '7th Avenue',
48
- purchaser_street_number: '1',
49
- purchaser_postcode: '747 70',
50
- purchaser_city: 'NYC',
44
+ purchaser_lines: "8648 Acacia Rd.\nBrooklyn, NY 11203",
51
45
  issue_date: '05/03/2016',
52
46
  due_date: '19/03/2016',
53
47
  subtotal: '$ 1,000',
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+ # This is an example of a Czech invoice.
3
+ #
4
+ # Due to the special characters it requires Overpass-Regular.ttf font to be
5
+ # present in this directory.
6
+
7
+ lib = File.expand_path('../../lib', __FILE__)
8
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
9
+ require 'invoice_printer'
10
+
11
+ labels = {
12
+ name: 'Faktura',
13
+ provider: 'Prodejce',
14
+ purchaser: 'Kupující',
15
+ tax_id: 'IČ',
16
+ tax_id2: 'DIČ',
17
+ payment: 'Forma úhrady',
18
+ payment_by_transfer: 'Platba na následující účet:',
19
+ account_number: 'Číslo účtu',
20
+ issue_date: 'Datum vydání',
21
+ due_date: 'Datum splatnosti',
22
+ item: 'Položka',
23
+ quantity: 'Počet',
24
+ unit: 'MJ',
25
+ price_per_item: 'Cena za položku',
26
+ amount: 'Celkem bez daně',
27
+ subtotal: 'Cena bez daně',
28
+ tax: 'DPH 21 %',
29
+ total: 'Celkem'
30
+ }
31
+
32
+ first_item = InvoicePrinter::Document::Item.new(
33
+ name: 'Konzultace',
34
+ quantity: '2',
35
+ unit: 'hod',
36
+ price: 'Kč 500',
37
+ amount: 'Kč 1.000'
38
+ )
39
+
40
+ second_item = InvoicePrinter::Document::Item.new(
41
+ name: 'Programování',
42
+ quantity: '10',
43
+ unit: 'hod',
44
+ price: 'Kč 900',
45
+ amount: 'Kč 9.000'
46
+ )
47
+
48
+ provider_address = <<ADDRESS
49
+ Rolnická 1
50
+ 747 05 Opava
51
+ Kateřinky
52
+
53
+ fith line wont show
54
+ ADDRESS
55
+
56
+ purchaser_address = <<ADDRESS
57
+ Ostravská 1
58
+ 747 70 Opava
59
+
60
+
61
+
62
+ fith line wont show
63
+ ADDRESS
64
+
65
+ invoice = InvoicePrinter::Document.new(
66
+ number: 'č. 198900000001',
67
+ provider_name: 'Petr Nový',
68
+ provider_tax_id: '56565656',
69
+ provider_tax_id2: 'CZ56565656',
70
+ provider_street: 'Rolnická',
71
+ provider_street_number: '1',
72
+ provider_postcode: '747 05',
73
+ provider_city: 'Opava',
74
+ provider_city_part: 'Kateřinky',
75
+ provider_lines: provider_address,
76
+ purchaser_name: 'Adam Černý',
77
+ purchaser_street: 'Ostravská',
78
+ purchaser_street_number: '1',
79
+ purchaser_postcode: '747 70',
80
+ purchaser_city: 'Opava',
81
+ purchaser_lines: purchaser_address,
82
+ purchaser_tax_id: '56565656',
83
+ purchaser_tax_id2: 'CZ56565656',
84
+ issue_date: '05/03/2016',
85
+ due_date: '19/03/2016',
86
+ subtotal: 'Kč 10.000',
87
+ tax: 'Kč 2.100',
88
+ total: 'Kč 12.100,-',
89
+ bank_account_number: '156546546465',
90
+ account_iban: 'IBAN464545645',
91
+ account_swift: 'SWIFT5456',
92
+ items: [first_item, second_item],
93
+ note: 'Osoba je zapsána v živnostenském rejstříku.'
94
+ )
95
+
96
+ InvoicePrinter.print(
97
+ document: invoice,
98
+ labels: labels,
99
+ font: File.expand_path('../Overpass-Regular.ttf', __FILE__),
100
+ logo: 'prawn.png',
101
+ file_name: 'provider_purchaser_lines.pdf'
102
+ )
103
+
104
+ InvoicePrinter.print(
105
+ document: invoice,
106
+ labels: labels,
107
+ font: File.expand_path('../Overpass-Regular.ttf', __FILE__),
108
+ logo: 'prawn.png',
109
+ file_name: 'provider_purchaser_lines_a4.pdf',
110
+ page_size: :a4
111
+ )