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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6529faa82615534d3264b96cd81e8402fb46543f
4
- data.tar.gz: 39685b41d40e812c7b83d95994e1dfad9dafe5ed
3
+ metadata.gz: 63f93d4c152d2abbbae2b1b8ceb8eb5dfd8be827
4
+ data.tar.gz: a1c352ad082498294f84bd041768e7a7c3f47e63
5
5
  SHA512:
6
- metadata.gz: 6b180c62070d36ab9d1ad80db58e583bfd43068daf8b1dfbb4acd7129b50d84e50d47f5ecf2ca7cb9e5d689f1ce84f4f21174ce1b9baaa60db8d6b37018ab375
7
- data.tar.gz: 988a1f21746a489cf0f350208e2b985e1a72995667f6f31c5a9fdab51370cce7919022126ef3f8696af04e0e92d5f260fea8a49419e1ee23bba117c3e4a29916
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
- provider_ic: '56565656',
82
- provider_dic: '465454',
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
- purchaser_ic: '',
91
- purchaser_dic: '',
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
- ic: 'Identification number',
143
- dic: 'Identification number',
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',
@@ -12,8 +12,8 @@ labels = {
12
12
  name: 'Faktura',
13
13
  provider: 'Prodejce',
14
14
  purchaser: 'Kupující',
15
- ic: 'IČ',
16
- dic: 'DIČ',
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
- provider_ic: '56565656',
51
+ provider_tax_id: '56565656',
52
52
  provider_street: 'Rolnická',
53
53
  provider_street_number: '1',
54
54
  provider_postcode: '747 05',
Binary file
@@ -35,5 +35,6 @@ invoice = InvoicePrinter::Document.new(
35
35
 
36
36
  InvoicePrinter.print(
37
37
  document: invoice,
38
+ logo: 'example.jpg',
38
39
  file_name: 'simple_invoice.pdf'
39
40
  )
@@ -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
- # logo: 'logo.jpg'
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
- def self.print(document:, file_name:, labels: {}, font: nil, logo: nil)
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
- def self.render(document:, labels: {}, font: nil, logo: nil)
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
- # provider_ic: '56565656',
10
- # provider_dic: '465454',
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
- # purchaser_ic: '',
19
- # purchaser_dic: '',
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
- :provider_ic,
50
- :provider_dic,
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
- :purchaser_ic,
61
- :purchaser_dic,
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
- provider_ic: nil,
87
- provider_dic: nil,
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
- purchaser_ic: nil,
96
- purchaser_dic: nil,
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
- @provider_ic = String(provider_ic)
118
- @provider_dic = String(provider_dic)
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
- @purchaser_ic = String(purchaser_ic)
127
- @purchaser_dic = String(purchaser_dic)
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
- 'provider_ic': @provider_ic,
156
- 'provider_dic': @provider_dic,
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
- 'purchaser_ic': @purchaser_ic,
165
- 'purchaser_dic': @purchaser_dic,
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
- ic: 'Identification number',
28
- dic: 'Identification number',
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.provider_ic.empty?
211
+ unless @document.provider_tax_id.empty?
209
212
  @pdf.text_box(
210
- "#{@labels[:ic]}: #{@document.provider_ic}",
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.provider_dic.empty?
219
+ unless @document.provider_tax_id2.empty?
217
220
  @pdf.text_box(
218
- "#{@labels[:dic]}: #{@document.provider_dic}",
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.purchaser_ic.empty?
290
+ unless @document.purchaser_tax_id2.empty?
288
291
  @pdf.text_box(
289
- "#{@labels[:ic]}: #{@document.purchaser_ic}",
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.purchaser_dic.empty?
298
+ unless @document.purchaser_tax_id.empty?
296
299
  @pdf.text_box(
297
- "#{@labels[:dic]}: #{@document.purchaser_dic}",
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(
@@ -1,3 +1,3 @@
1
1
  module InvoicePrinter
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
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
- provider_ic: 12345678910,
25
- provider_dic: 12345678910,
26
- purchaser_ic: 12345678910,
27
- purchaser_dic: 12345678910
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[:ic]}: #{@document.provider_ic}" \
34
- unless @document.provider_ic.empty?
35
- strings << "#{@labels[:dic]}: #{@document.provider_dic}" \
36
- unless @document.provider_dic.empty?
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[:ic]}: #{@document.purchaser_ic}" \
51
- unless @document.purchaser_ic.empty?
52
- strings << "#{@labels[:dic]}: #{@document.purchaser_dic}" \
53
- unless @document.purchaser_dic.empty?
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
- provider_ic: '56565656',
13
- provider_dic: '465454',
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
- purchaser_ic: nil,
22
- purchaser_dic: nil,
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.5
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-08-06 00:00:00.000000000 Z
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.4.8
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