invoice_printer 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -6
- data/examples/czech_invoice.rb +3 -3
- data/examples/simple_invoice.pdf +0 -0
- data/examples/simple_invoice.rb +1 -0
- data/lib/invoice_printer.rb +19 -3
- data/lib/invoice_printer/document.rb +22 -20
- data/lib/invoice_printer/document/item.rb +17 -0
- data/lib/invoice_printer/pdf_document.rb +23 -12
- data/lib/invoice_printer/version.rb +1 -1
- data/test/inputs_test.rb +4 -4
- data/test/test_ext.rb +8 -8
- data/test/test_helper.rb +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63f93d4c152d2abbbae2b1b8ceb8eb5dfd8be827
|
4
|
+
data.tar.gz: a1c352ad082498294f84bd041768e7a7c3f47e63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2fbdf0d91fcd1fbd6b478b4e6a9325697a02d355d3e7b03c3e4d5f1c0f6be60b62f8e66f410bbe9d64e219b052d72786f2fb60de83dbc2b08fcf8af21916013
|
7
|
+
data.tar.gz: 828eff18046495b5bf2e4481715524c8742444af0722b11e74fe0158b8f792c63183588313e8159e0a99c9ed2a1850f1af05e90930c126d87f5fe7d6b52910b0
|
data/README.md
CHANGED
@@ -23,6 +23,7 @@ See more usecases in the `examples/` directory.
|
|
23
23
|
- Configurable labels
|
24
24
|
- Configurable font file
|
25
25
|
- Logotype
|
26
|
+
- Stamp & signature (as image)
|
26
27
|
- Note
|
27
28
|
- Well tested
|
28
29
|
|
@@ -78,8 +79,8 @@ item = InvoicePrinter::Document::Item.new(
|
|
78
79
|
invoice = InvoicePrinter::Document.new(
|
79
80
|
number: '201604030001',
|
80
81
|
provider_name: 'Business s.r.o.',
|
81
|
-
|
82
|
-
|
82
|
+
provider_tax_id: '56565656',
|
83
|
+
provider_tax_id2: '465454',
|
83
84
|
provider_street: 'Rolnicka',
|
84
85
|
provider_street_number: '1',
|
85
86
|
provider_postcode: '747 05',
|
@@ -87,8 +88,8 @@ invoice = InvoicePrinter::Document.new(
|
|
87
88
|
provider_city_part: 'Katerinky',
|
88
89
|
provider_extra_address_line: 'Czech Republic',
|
89
90
|
purchaser_name: 'Adam',
|
90
|
-
|
91
|
-
|
91
|
+
purchaser_tax_id: '',
|
92
|
+
purchaser_tax_id2: '',
|
92
93
|
purchaser_street: 'Ostravska',
|
93
94
|
purchaser_street_number: '1',
|
94
95
|
purchaser_postcode: '747 70',
|
@@ -139,8 +140,8 @@ InvoicePrinter.labels = {
|
|
139
140
|
name: 'Invoice'
|
140
141
|
provider: 'Provider',
|
141
142
|
purchaser: 'Purchaser',
|
142
|
-
|
143
|
-
|
143
|
+
tax_id: 'Identification number',
|
144
|
+
tax_id2: 'Identification number',
|
144
145
|
payment: 'Payment',
|
145
146
|
payment_by_transfer: 'Payment by bank transfer on the account below:',
|
146
147
|
payment_in_cash: 'Payment in cash',
|
data/examples/czech_invoice.rb
CHANGED
@@ -12,8 +12,8 @@ labels = {
|
|
12
12
|
name: 'Faktura',
|
13
13
|
provider: 'Prodejce',
|
14
14
|
purchaser: 'Kupující',
|
15
|
-
|
16
|
-
|
15
|
+
tax_id: 'IČ',
|
16
|
+
tax_id2: 'DIČ',
|
17
17
|
payment: 'Forma úhrady',
|
18
18
|
payment_by_transfer: 'Platba na následující účet:',
|
19
19
|
account_number: 'Číslo účtu',
|
@@ -48,7 +48,7 @@ second_item = InvoicePrinter::Document::Item.new(
|
|
48
48
|
invoice = InvoicePrinter::Document.new(
|
49
49
|
number: 'č. 198900000001',
|
50
50
|
provider_name: 'Petr Nový',
|
51
|
-
|
51
|
+
provider_tax_id: '56565656',
|
52
52
|
provider_street: 'Rolnická',
|
53
53
|
provider_street_number: '1',
|
54
54
|
provider_postcode: '747 05',
|
data/examples/simple_invoice.pdf
CHANGED
Binary file
|
data/examples/simple_invoice.rb
CHANGED
data/lib/invoice_printer.rb
CHANGED
@@ -10,7 +10,8 @@ require 'invoice_printer/pdf_document'
|
|
10
10
|
# InvoicePrinter.print(
|
11
11
|
# document: invoice,
|
12
12
|
# font: 'path-to-font-file.ttf',
|
13
|
-
#
|
13
|
+
# stamp: 'stamp.jpg',
|
14
|
+
# logo: 'logo.jpg',
|
14
15
|
# file_name: 'invoice.pdf'
|
15
16
|
# )
|
16
17
|
module InvoicePrinter
|
@@ -46,21 +47,36 @@ module InvoicePrinter
|
|
46
47
|
end
|
47
48
|
|
48
49
|
# Print the given InvoicePrinter::Document to PDF file named +file_name+
|
49
|
-
|
50
|
+
#
|
51
|
+
# document - InvoicePrinter::Document object
|
52
|
+
# file_name - output file
|
53
|
+
# labels - labels to override
|
54
|
+
# font - font file to use
|
55
|
+
# stamp - stamp & signature (image)
|
56
|
+
# logo - logotype (image)
|
57
|
+
def self.print(document:, file_name:, labels: {}, font: nil, stamp: nil, logo: nil)
|
50
58
|
PDFDocument.new(
|
51
59
|
document: document,
|
52
60
|
labels: labels,
|
53
61
|
font: font,
|
62
|
+
stamp: stamp,
|
54
63
|
logo: logo,
|
55
64
|
).print(file_name)
|
56
65
|
end
|
57
66
|
|
58
67
|
# Render the PDF document InvoicePrinter::Document to PDF directly
|
59
|
-
|
68
|
+
#
|
69
|
+
# document - InvoicePrinter::Document object
|
70
|
+
# labels - labels to override
|
71
|
+
# font - font file to use
|
72
|
+
# stamp - stamp & signature (image)
|
73
|
+
# logo - logotype (image)
|
74
|
+
def self.render(document:, labels: {}, font: nil, stamp: nil, logo: nil)
|
60
75
|
PDFDocument.new(
|
61
76
|
document: document,
|
62
77
|
labels: labels,
|
63
78
|
font: font,
|
79
|
+
stamp: stamp,
|
64
80
|
logo: logo
|
65
81
|
).render
|
66
82
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module InvoicePrinter
|
2
4
|
# Invoice and receipt representation
|
3
5
|
#
|
@@ -6,8 +8,8 @@ module InvoicePrinter
|
|
6
8
|
# invoice = InvoicePrinter::Document.new(
|
7
9
|
# number: '198900000001',
|
8
10
|
# provider_name: 'Business s.r.o.',
|
9
|
-
#
|
10
|
-
#
|
11
|
+
# provider_tax_id: '56565656',
|
12
|
+
# provider_tax_id2: '465454',
|
11
13
|
# provider_street: 'Rolnicka',
|
12
14
|
# provider_street_number: '1',
|
13
15
|
# provider_postcode: '747 05',
|
@@ -15,8 +17,8 @@ module InvoicePrinter
|
|
15
17
|
# provider_city_part: 'Katerinky',
|
16
18
|
# provider_extra_address_line: 'Czech Republic',
|
17
19
|
# purchaser_name: 'Adam',
|
18
|
-
#
|
19
|
-
#
|
20
|
+
# purchaser_tax_id: '',
|
21
|
+
# purchaser_tax_id2: '',
|
20
22
|
# purchaser_street: 'Ostravska',
|
21
23
|
# purchaser_street_number: '1',
|
22
24
|
# purchaser_postcode: '747 70',
|
@@ -46,8 +48,8 @@ module InvoicePrinter
|
|
46
48
|
attr_reader :number,
|
47
49
|
# Provider fields
|
48
50
|
:provider_name,
|
49
|
-
:
|
50
|
-
:
|
51
|
+
:provider_tax_id,
|
52
|
+
:provider_tax_id2,
|
51
53
|
# Provider address fields
|
52
54
|
:provider_street,
|
53
55
|
:provider_street_number,
|
@@ -57,8 +59,8 @@ module InvoicePrinter
|
|
57
59
|
:provider_extra_address_line,
|
58
60
|
# Purchaser fields
|
59
61
|
:purchaser_name,
|
60
|
-
:
|
61
|
-
:
|
62
|
+
:purchaser_tax_id,
|
63
|
+
:purchaser_tax_id2,
|
62
64
|
# Purchaser address fields
|
63
65
|
:purchaser_street,
|
64
66
|
:purchaser_street_number,
|
@@ -83,8 +85,8 @@ module InvoicePrinter
|
|
83
85
|
|
84
86
|
def initialize(number: nil,
|
85
87
|
provider_name: nil,
|
86
|
-
|
87
|
-
|
88
|
+
provider_tax_id: nil,
|
89
|
+
provider_tax_id2: nil,
|
88
90
|
provider_street: nil,
|
89
91
|
provider_street_number: nil,
|
90
92
|
provider_postcode: nil,
|
@@ -92,8 +94,8 @@ module InvoicePrinter
|
|
92
94
|
provider_city_part: nil,
|
93
95
|
provider_extra_address_line: nil,
|
94
96
|
purchaser_name: nil,
|
95
|
-
|
96
|
-
|
97
|
+
purchaser_tax_id: nil,
|
98
|
+
purchaser_tax_id2: nil,
|
97
99
|
purchaser_street: nil,
|
98
100
|
purchaser_street_number: nil,
|
99
101
|
purchaser_postcode: nil,
|
@@ -114,8 +116,8 @@ module InvoicePrinter
|
|
114
116
|
note: nil)
|
115
117
|
@number = String(number)
|
116
118
|
@provider_name = String(provider_name)
|
117
|
-
@
|
118
|
-
@
|
119
|
+
@provider_tax_id = String(provider_tax_id)
|
120
|
+
@provider_tax_id2 = String(provider_tax_id2)
|
119
121
|
@provider_street = String(provider_street)
|
120
122
|
@provider_street_number = String(provider_street_number)
|
121
123
|
@provider_postcode = String(provider_postcode)
|
@@ -123,8 +125,8 @@ module InvoicePrinter
|
|
123
125
|
@provider_city_part = String(provider_city_part)
|
124
126
|
@provider_extra_address_line = String(provider_extra_address_line)
|
125
127
|
@purchaser_name = String(purchaser_name)
|
126
|
-
@
|
127
|
-
@
|
128
|
+
@purchaser_tax_id = String(purchaser_tax_id)
|
129
|
+
@purchaser_tax_id2 = String(purchaser_tax_id2)
|
128
130
|
@purchaser_street = String(purchaser_street)
|
129
131
|
@purchaser_street_number = String(purchaser_street_number)
|
130
132
|
@purchaser_postcode = String(purchaser_postcode)
|
@@ -152,8 +154,8 @@ module InvoicePrinter
|
|
152
154
|
{
|
153
155
|
'number': @number,
|
154
156
|
'provider_name': @provider_name,
|
155
|
-
'
|
156
|
-
'
|
157
|
+
'provider_tax_id': @provider_tax_id,
|
158
|
+
'provider_tax_id2': @provider_tax_id2,
|
157
159
|
'provider_street': @provider_street,
|
158
160
|
'provider_street_number': @provider_street_number,
|
159
161
|
'provider_postcode': @provider_postcode,
|
@@ -161,8 +163,8 @@ module InvoicePrinter
|
|
161
163
|
'provider_city_part': @provider_city_part,
|
162
164
|
'provider_extra_address_line': @provider_extra_address_line,
|
163
165
|
'purchaser_name': @purchaser_name,
|
164
|
-
'
|
165
|
-
'
|
166
|
+
'purchaser_tax_id': @purchaser_tax_id,
|
167
|
+
'purchaser_tax_id2': @purchaser_tax_id2,
|
166
168
|
'purchaser_street': @purchaser_street,
|
167
169
|
'purchaser_street_number': @purchaser_street_number,
|
168
170
|
'purchaser_postcode': @purchaser_postcode,
|
@@ -44,6 +44,23 @@ module InvoicePrinter
|
|
44
44
|
@tax3 = String(tax3)
|
45
45
|
@amount = String(amount)
|
46
46
|
end
|
47
|
+
|
48
|
+
def to_h
|
49
|
+
{
|
50
|
+
'name': @name,
|
51
|
+
'quantity': @quantity,
|
52
|
+
'unit': @unit,
|
53
|
+
'price': @price,
|
54
|
+
'tax': @tax,
|
55
|
+
'tax2': @tax2,
|
56
|
+
'tax3': @tax3,
|
57
|
+
'amount': @amount,
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_json
|
62
|
+
to_h.to_json
|
63
|
+
end
|
47
64
|
end
|
48
65
|
end
|
49
66
|
end
|
@@ -11,6 +11,7 @@ module InvoicePrinter
|
|
11
11
|
# document: invoice,
|
12
12
|
# labels: {},
|
13
13
|
# font: 'font.ttf',
|
14
|
+
# stamp: 'stamp.jpg',
|
14
15
|
# logo: 'example.jpg'
|
15
16
|
# )
|
16
17
|
class PDFDocument
|
@@ -18,14 +19,14 @@ module InvoicePrinter
|
|
18
19
|
class LogoFileNotFound < StandardError; end
|
19
20
|
class InvalidInput < StandardError; end
|
20
21
|
|
21
|
-
attr_reader :invoice, :labels, :file_name, :font, :logo
|
22
|
+
attr_reader :invoice, :labels, :file_name, :font, :stamp, :logo
|
22
23
|
|
23
24
|
DEFAULT_LABELS = {
|
24
25
|
name: 'Invoice',
|
25
26
|
provider: 'Provider',
|
26
27
|
purchaser: 'Purchaser',
|
27
|
-
|
28
|
-
|
28
|
+
tax_id: 'Identification number',
|
29
|
+
tax_id2: 'Identification number',
|
29
30
|
payment: 'Payment',
|
30
31
|
payment_by_transfer: 'Payment by bank transfer on the account below:',
|
31
32
|
payment_in_cash: 'Payment in cash',
|
@@ -54,11 +55,12 @@ module InvoicePrinter
|
|
54
55
|
@@labels = DEFAULT_LABELS.merge(labels)
|
55
56
|
end
|
56
57
|
|
57
|
-
def initialize(document: Document.new, labels: {}, font: nil, logo: nil)
|
58
|
+
def initialize(document: Document.new, labels: {}, font: nil, stamp: nil, logo: nil)
|
58
59
|
@document = document
|
59
60
|
@labels = PDFDocument.labels.merge(labels)
|
60
61
|
@pdf = Prawn::Document.new
|
61
62
|
@font = font
|
63
|
+
@stamp = stamp
|
62
64
|
@logo = logo
|
63
65
|
|
64
66
|
raise InvalidInput, 'document is not a type of InvoicePrinter::Document' \
|
@@ -121,6 +123,7 @@ module InvoicePrinter
|
|
121
123
|
build_info_box
|
122
124
|
build_items
|
123
125
|
build_total
|
126
|
+
build_stamp
|
124
127
|
build_logo
|
125
128
|
build_note
|
126
129
|
build_footer
|
@@ -205,17 +208,17 @@ module InvoicePrinter
|
|
205
208
|
width: 240
|
206
209
|
)
|
207
210
|
end
|
208
|
-
unless @document.
|
211
|
+
unless @document.provider_tax_id.empty?
|
209
212
|
@pdf.text_box(
|
210
|
-
"#{@labels[:
|
213
|
+
"#{@labels[:tax_id]}: #{@document.provider_tax_id}",
|
211
214
|
size: 10,
|
212
215
|
at: [10, 550 - @push_down],
|
213
216
|
width: 240
|
214
217
|
)
|
215
218
|
end
|
216
|
-
unless @document.
|
219
|
+
unless @document.provider_tax_id2.empty?
|
217
220
|
@pdf.text_box(
|
218
|
-
"#{@labels[:
|
221
|
+
"#{@labels[:tax_id2]}: #{@document.provider_tax_id2}",
|
219
222
|
size: 10,
|
220
223
|
at: [10, 535 - @push_down],
|
221
224
|
width: 240
|
@@ -284,17 +287,17 @@ module InvoicePrinter
|
|
284
287
|
width: 240
|
285
288
|
)
|
286
289
|
end
|
287
|
-
unless @document.
|
290
|
+
unless @document.purchaser_tax_id2.empty?
|
288
291
|
@pdf.text_box(
|
289
|
-
"#{@labels[:
|
292
|
+
"#{@labels[:tax_id2]}: #{@document.purchaser_tax_id2}",
|
290
293
|
size: 10,
|
291
294
|
at: [290, 550 - @push_down],
|
292
295
|
width: 240
|
293
296
|
)
|
294
297
|
end
|
295
|
-
unless @document.
|
298
|
+
unless @document.purchaser_tax_id.empty?
|
296
299
|
@pdf.text_box(
|
297
|
-
"#{@labels[:
|
300
|
+
"#{@labels[:tax_id]}: #{@document.purchaser_tax_id}",
|
298
301
|
size: 10,
|
299
302
|
at: [290, 535 - @push_down],
|
300
303
|
width: 240
|
@@ -570,6 +573,14 @@ module InvoicePrinter
|
|
570
573
|
@pdf.image(@logo, at: [0, bottom]) if @logo && !@logo.empty?
|
571
574
|
end
|
572
575
|
|
576
|
+
# Insert a stamp (with signature) after the total table
|
577
|
+
def build_stamp
|
578
|
+
if @stamp && !@stamp.empty?
|
579
|
+
@pdf.move_down(15)
|
580
|
+
@pdf.image(@stamp, position: :right)
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
573
584
|
# Note at the end
|
574
585
|
def build_note
|
575
586
|
@pdf.text_box(
|
data/test/inputs_test.rb
CHANGED
@@ -21,10 +21,10 @@ class InputsTest < Minitest::Test
|
|
21
21
|
|
22
22
|
def test_non_string_inputs_are_converted_to_strings
|
23
23
|
params = default_document_params.merge(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
provider_tax_id: 12345678910,
|
25
|
+
provider_tax_id2: 12345678910,
|
26
|
+
purchaser_tax_id: 12345678910,
|
27
|
+
purchaser_tax_id2: 12345678910
|
28
28
|
)
|
29
29
|
|
30
30
|
# No exceptions should be raised
|
data/test/test_ext.rb
CHANGED
@@ -30,10 +30,10 @@ module InvoicePrinter
|
|
30
30
|
strings << @document.provider_city
|
31
31
|
strings << @document.provider_city_part
|
32
32
|
strings << @document.provider_extra_address_line
|
33
|
-
strings << "#{@labels[:
|
34
|
-
unless @document.
|
35
|
-
strings << "#{@labels[:
|
36
|
-
unless @document.
|
33
|
+
strings << "#{@labels[:tax_id]}: #{@document.provider_tax_id}" \
|
34
|
+
unless @document.provider_tax_id.empty?
|
35
|
+
strings << "#{@labels[:tax_id2]}: #{@document.provider_tax_id2}" \
|
36
|
+
unless @document.provider_tax_id2.empty?
|
37
37
|
strings
|
38
38
|
end
|
39
39
|
|
@@ -47,10 +47,10 @@ module InvoicePrinter
|
|
47
47
|
strings << @document.purchaser_city
|
48
48
|
strings << @document.purchaser_city_part
|
49
49
|
strings << @document.purchaser_extra_address_line
|
50
|
-
strings << "#{@labels[:
|
51
|
-
unless @document.
|
52
|
-
strings << "#{@labels[:
|
53
|
-
unless @document.
|
50
|
+
strings << "#{@labels[:tax_id]}: #{@document.purchaser_tax_id}" \
|
51
|
+
unless @document.purchaser_tax_id.empty?
|
52
|
+
strings << "#{@labels[:tax_id2]}: #{@document.purchaser_tax_id2}" \
|
53
|
+
unless @document.purchaser_tax_id2.empty?
|
54
54
|
strings
|
55
55
|
end
|
56
56
|
|
data/test/test_helper.rb
CHANGED
@@ -9,8 +9,8 @@ module InvoicePrinterHelpers
|
|
9
9
|
{
|
10
10
|
number: '198900000001',
|
11
11
|
provider_name: 'Business s.r.o.',
|
12
|
-
|
13
|
-
|
12
|
+
provider_tax_id: '56565656',
|
13
|
+
provider_tax_id2: '465454',
|
14
14
|
provider_street: 'Rolnicka',
|
15
15
|
provider_street_number: '1',
|
16
16
|
provider_postcode: '747 05',
|
@@ -18,8 +18,8 @@ module InvoicePrinterHelpers
|
|
18
18
|
provider_city_part: 'Katerinky',
|
19
19
|
provider_extra_address_line: 'Czech Republic',
|
20
20
|
purchaser_name: 'Adam',
|
21
|
-
|
22
|
-
|
21
|
+
purchaser_tax_id: nil,
|
22
|
+
purchaser_tax_id2: nil,
|
23
23
|
purchaser_street: 'Ostravska',
|
24
24
|
purchaser_street_number: '1',
|
25
25
|
purchaser_postcode: '747 70',
|
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: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josef Strzibny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
version: '0'
|
134
134
|
requirements: []
|
135
135
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.5.1
|
137
137
|
signing_key:
|
138
138
|
specification_version: 4
|
139
139
|
summary: Super simple PDF invoicing in pure Ruby
|