invoice_printer 2.1.0 → 2.2.0.alpha1
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 +4 -4
- data/docs/COMMAND_LINE.md +2 -0
- data/docs/LIBRARY.md +2 -0
- data/examples/variable_field_invoice.rb +96 -0
- data/lib/invoice_printer.rb +1 -0
- data/lib/invoice_printer/document.rb +6 -0
- data/lib/invoice_printer/pdf_document.rb +77 -85
- data/lib/invoice_printer/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73bc8cc15f44b26e3208614d83ee31dbb385b804e7a248723b07d6c9b60e7238
|
4
|
+
data.tar.gz: 5d2ab37a9051dba8ddd0018a4d7bc3d2f6a14949f131679f77ac7a0cd9069981
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fb1d1f236410e510f79c30b9c817d63285ae9dd49a579ec4930e6596f1ab3c06d8d480c7e4c3f11f14873c14aa9d6b62bbd6e91687cafc052e6387244a791f3
|
7
|
+
data.tar.gz: 2819f38b58b55ec97517c5521cee21a70ab33ad64303d6c71f92ae41186f5c7136f66a88ef8aad9eaea0144c632cc96d71244cff04264a642f8f0cd13437b52a
|
data/docs/COMMAND_LINE.md
CHANGED
@@ -38,6 +38,7 @@ JSON document with all possible fields filled:
|
|
38
38
|
"purchaser_lines":"Ostravská 1\n747 70 Opava",
|
39
39
|
"issue_date":"05/03/2016",
|
40
40
|
"due_date":"19/03/2016",
|
41
|
+
"variable_symbol":"198900000001",
|
41
42
|
"subtotal":"Kc 10.000",
|
42
43
|
"tax":"Kc 2.100",
|
43
44
|
"tax2":"",
|
@@ -99,6 +100,7 @@ All labels:
|
|
99
100
|
"iban":"IBAN",
|
100
101
|
"issue_date":"Issue date",
|
101
102
|
"due_date": "Due date",
|
103
|
+
"variable_symbol": "Variable symbol",
|
102
104
|
"item":"Item",
|
103
105
|
"variable":"",
|
104
106
|
"quantity":"Quantity",
|
data/docs/LIBRARY.md
CHANGED
@@ -165,6 +165,7 @@ InvoicePrinter.labels = {
|
|
165
165
|
iban: 'IBAN',
|
166
166
|
issue_date: 'Issue date',
|
167
167
|
due_date: 'Due date',
|
168
|
+
variable_symbol: 'Variable symbol',
|
168
169
|
item: 'Item',
|
169
170
|
variable: '',
|
170
171
|
quantity: 'Quantity',
|
@@ -198,6 +199,7 @@ sublabels = {
|
|
198
199
|
account_number: 'Číslo účtu',
|
199
200
|
issue_date: 'Datum vydání',
|
200
201
|
due_date: 'Datum splatnosti',
|
202
|
+
variable_symbol: 'Variabilní symbol',
|
201
203
|
item: 'Položka',
|
202
204
|
variable: '',
|
203
205
|
quantity: 'Počet',
|
@@ -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
|
+
)
|
data/lib/invoice_printer.rb
CHANGED
@@ -15,6 +15,7 @@ module InvoicePrinter
|
|
15
15
|
# purchaser_lines: "Ostravska 2\n747 05 Opava",
|
16
16
|
# issue_date: '19/03/3939',
|
17
17
|
# due_date: '19/03/3939',
|
18
|
+
# variable_symbol: '198900000001',
|
18
19
|
# subtotal: '$ 150',
|
19
20
|
# tax: '$ 50',
|
20
21
|
# total: '$ 200',
|
@@ -46,6 +47,7 @@ module InvoicePrinter
|
|
46
47
|
:purchaser_lines,
|
47
48
|
:issue_date,
|
48
49
|
:due_date,
|
50
|
+
:variable_symbol,
|
49
51
|
# Account details
|
50
52
|
:subtotal,
|
51
53
|
:tax,
|
@@ -73,6 +75,7 @@ module InvoicePrinter
|
|
73
75
|
purchaser_lines: json['purchaser_lines'],
|
74
76
|
issue_date: json['issue_date'],
|
75
77
|
due_date: json['due_date'],
|
78
|
+
variable_symbol: json['variable_symbol'],
|
76
79
|
subtotal: json['subtotal'],
|
77
80
|
tax: json['tax'],
|
78
81
|
tax2: json['tax2'],
|
@@ -99,6 +102,7 @@ module InvoicePrinter
|
|
99
102
|
purchaser_lines: nil,
|
100
103
|
issue_date: nil,
|
101
104
|
due_date: nil,
|
105
|
+
variable_symbol: nil,
|
102
106
|
subtotal: nil,
|
103
107
|
tax: nil,
|
104
108
|
tax2: nil,
|
@@ -121,6 +125,7 @@ module InvoicePrinter
|
|
121
125
|
@purchaser_lines = String(purchaser_lines)
|
122
126
|
@issue_date = String(issue_date)
|
123
127
|
@due_date = String(due_date)
|
128
|
+
@variable_symbol = String(variable_symbol)
|
124
129
|
@subtotal = String(subtotal)
|
125
130
|
@tax = String(tax)
|
126
131
|
@tax2 = String(tax2)
|
@@ -149,6 +154,7 @@ module InvoicePrinter
|
|
149
154
|
'purchaser_lines': @purchaser_lines,
|
150
155
|
'issue_date': @issue_date,
|
151
156
|
'due_date': @due_date,
|
157
|
+
'variable_symbol': @variable_symbol,
|
152
158
|
'subtotal': @subtotal,
|
153
159
|
'tax': @tax,
|
154
160
|
'tax2': @tax2,
|
@@ -36,6 +36,7 @@ module InvoicePrinter
|
|
36
36
|
iban: 'IBAN',
|
37
37
|
issue_date: 'Issue date',
|
38
38
|
due_date: 'Due date',
|
39
|
+
variable_symbol: 'Variable symbol',
|
39
40
|
item: 'Item',
|
40
41
|
variable: '',
|
41
42
|
quantity: 'Quantity',
|
@@ -252,41 +253,6 @@ module InvoicePrinter
|
|
252
253
|
width: x(240)
|
253
254
|
)
|
254
255
|
end
|
255
|
-
else
|
256
|
-
@pdf.text_box(
|
257
|
-
"#{@document.provider_street} #{@document.provider_street_number}",
|
258
|
-
size: 10,
|
259
|
-
at: [10, y(620) - @push_down],
|
260
|
-
width: x(240)
|
261
|
-
)
|
262
|
-
@pdf.text_box(
|
263
|
-
@document.provider_postcode,
|
264
|
-
size: 10,
|
265
|
-
at: [10, y(605) - @push_down],
|
266
|
-
width: x(240)
|
267
|
-
)
|
268
|
-
@pdf.text_box(
|
269
|
-
@document.provider_city,
|
270
|
-
size: 10,
|
271
|
-
at: [60, y(605) - @push_down],
|
272
|
-
width: x(240)
|
273
|
-
)
|
274
|
-
unless @document.provider_city_part.empty?
|
275
|
-
@pdf.text_box(
|
276
|
-
@document.provider_city_part,
|
277
|
-
size: 10,
|
278
|
-
at: [60, y(590) - @push_down],
|
279
|
-
width: x(240)
|
280
|
-
)
|
281
|
-
end
|
282
|
-
unless @document.provider_extra_address_line.empty?
|
283
|
-
@pdf.text_box(
|
284
|
-
@document.provider_extra_address_line,
|
285
|
-
size: 10,
|
286
|
-
at: [10, y(575) - @push_down],
|
287
|
-
width: x(240)
|
288
|
-
)
|
289
|
-
end
|
290
256
|
end
|
291
257
|
unless @document.provider_tax_id.empty?
|
292
258
|
@pdf.text_box(
|
@@ -357,41 +323,6 @@ module InvoicePrinter
|
|
357
323
|
width: x(240)
|
358
324
|
)
|
359
325
|
end
|
360
|
-
else
|
361
|
-
@pdf.text_box(
|
362
|
-
"#{@document.purchaser_street} #{@document.purchaser_street_number}",
|
363
|
-
size: 10,
|
364
|
-
at: [x(284), y(620) - @push_down],
|
365
|
-
width: x(240)
|
366
|
-
)
|
367
|
-
@pdf.text_box(
|
368
|
-
@document.purchaser_postcode,
|
369
|
-
size: 10,
|
370
|
-
at: [x(284), y(605) - @push_down],
|
371
|
-
width: x(240)
|
372
|
-
)
|
373
|
-
@pdf.text_box(
|
374
|
-
@document.purchaser_city,
|
375
|
-
size: 10,
|
376
|
-
at: [x(334), y(605) - @push_down],
|
377
|
-
width: x(240)
|
378
|
-
)
|
379
|
-
unless @document.purchaser_city_part.empty?
|
380
|
-
@pdf.text_box(
|
381
|
-
@document.purchaser_city_part,
|
382
|
-
size: 10,
|
383
|
-
at: [x(334), y(590) - @push_down],
|
384
|
-
width: x(240)
|
385
|
-
)
|
386
|
-
end
|
387
|
-
unless @document.purchaser_extra_address_line.empty?
|
388
|
-
@pdf.text_box(
|
389
|
-
@document.purchaser_extra_address_line,
|
390
|
-
size: 10,
|
391
|
-
at: [x(284), y(575) - @push_down],
|
392
|
-
width: x(240)
|
393
|
-
)
|
394
|
-
end
|
395
326
|
end
|
396
327
|
unless @document.purchaser_tax_id.empty?
|
397
328
|
@pdf.text_box(
|
@@ -440,6 +371,10 @@ module InvoicePrinter
|
|
440
371
|
end
|
441
372
|
@payment_box_height = min_height
|
442
373
|
|
374
|
+
if big_info_box?
|
375
|
+
@payment_box_height = 110
|
376
|
+
end
|
377
|
+
|
443
378
|
if @document.bank_account_number.empty?
|
444
379
|
@pdf.text_box(
|
445
380
|
@labels[:payment],
|
@@ -551,6 +486,7 @@ module InvoicePrinter
|
|
551
486
|
@payment_box_height += 30
|
552
487
|
@push_items_table += 18
|
553
488
|
end
|
489
|
+
|
554
490
|
if min_height > @payment_box_height
|
555
491
|
@payment_box_height = min_height
|
556
492
|
@push_items_table += 25
|
@@ -571,6 +507,8 @@ module InvoicePrinter
|
|
571
507
|
# | Issue date sublabel |
|
572
508
|
# | Due date: 03/03/2016|
|
573
509
|
# | Due date sublabel |
|
510
|
+
# | Variable symbol: VS12345678|
|
511
|
+
# | Variable symbol sublabel |
|
574
512
|
# --------------------------------
|
575
513
|
#
|
576
514
|
def build_info_box
|
@@ -590,17 +528,17 @@ module InvoicePrinter
|
|
590
528
|
width: x(146),
|
591
529
|
align: :right
|
592
530
|
)
|
593
|
-
end
|
594
531
|
|
595
|
-
|
596
|
-
|
532
|
+
if used? @labels[:sublabels][:issue_date]
|
533
|
+
position = issue_date_present ? 483 : 498
|
597
534
|
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
535
|
+
@pdf.text_box(
|
536
|
+
@labels[:sublabels][:issue_date],
|
537
|
+
size: 10,
|
538
|
+
at: [x(284), y(position) - @push_down],
|
539
|
+
width: x(240)
|
540
|
+
)
|
541
|
+
end
|
604
542
|
end
|
605
543
|
|
606
544
|
due_date_present = !@document.due_date.empty?
|
@@ -622,29 +560,83 @@ module InvoicePrinter
|
|
622
560
|
width: x(146),
|
623
561
|
align: :right
|
624
562
|
)
|
563
|
+
|
564
|
+
if used? @labels[:sublabels][:due_date]
|
565
|
+
position = issue_date_present ? 463 : 478
|
566
|
+
position -= 10 if used? @labels[:sublabels][:issue_date]
|
567
|
+
|
568
|
+
@pdf.text_box(
|
569
|
+
@labels[:sublabels][:due_date],
|
570
|
+
size: 10,
|
571
|
+
at: [x(284), y(position) - @push_down],
|
572
|
+
width: x(240)
|
573
|
+
)
|
574
|
+
end
|
625
575
|
end
|
626
576
|
|
627
|
-
|
628
|
-
|
577
|
+
variable_symbol_present = !@document.variable_symbol.empty?
|
578
|
+
|
579
|
+
if variable_symbol_present
|
580
|
+
position = (issue_date_present || due_date_present) ? 483 : 498
|
581
|
+
position = issue_date_present && due_date_present ? 458 : 463
|
629
582
|
position -= 10 if used? @labels[:sublabels][:issue_date]
|
583
|
+
position -= 10 if used? @labels[:sublabels][:due_date]
|
630
584
|
|
631
585
|
@pdf.text_box(
|
632
|
-
@labels[:
|
633
|
-
size:
|
586
|
+
@labels[:variable_symbol],
|
587
|
+
size: 11,
|
634
588
|
at: [x(284), y(position) - @push_down],
|
635
589
|
width: x(240)
|
636
590
|
)
|
591
|
+
@pdf.text_box(
|
592
|
+
@document.variable_symbol,
|
593
|
+
size: 13,
|
594
|
+
at: [x(384), y(position) - @push_down],
|
595
|
+
width: x(146),
|
596
|
+
align: :right
|
597
|
+
)
|
598
|
+
|
599
|
+
if used? @labels[:sublabels][:variable_symbol]
|
600
|
+
position = issue_date_present ? 443 : 458
|
601
|
+
position -= 10 if used? @labels[:sublabels][:issue_date]
|
602
|
+
position -= 10 if used? @labels[:sublabels][:due_date]
|
603
|
+
|
604
|
+
@pdf.text_box(
|
605
|
+
@labels[:sublabels][:variable_symbol],
|
606
|
+
size: 10,
|
607
|
+
at: [x(284), y(position) - @push_down],
|
608
|
+
width: x(240)
|
609
|
+
)
|
610
|
+
end
|
637
611
|
end
|
638
612
|
|
639
|
-
if issue_date_present || due_date_present
|
613
|
+
if issue_date_present || due_date_present || variable_symbol_present
|
614
|
+
big_box = (issue_date_present && due_date_present && variable_symbol_present && info_box_sublabels_used?)
|
640
615
|
height = (issue_date_present && due_date_present) ? 75 : 60
|
616
|
+
height = big_box ? 110 : height
|
641
617
|
height = @payment_box_height if @payment_box_height > height
|
642
618
|
|
643
619
|
@pdf.stroke_rounded_rectangle([x(274), y(508) - @push_down], x(266), height, 6)
|
644
|
-
@push_items_table +=
|
620
|
+
@push_items_table += 23 if @push_items_table <= 18
|
621
|
+
@push_items_table += 24 if big_box
|
622
|
+
|
623
|
+
#@push_items_table += 30
|
645
624
|
end
|
646
625
|
end
|
647
626
|
|
627
|
+
def big_info_box?
|
628
|
+
!@document.issue_date.empty? &&
|
629
|
+
!@document.due_date.empty? &&
|
630
|
+
!@document.variable_symbol.empty? &&
|
631
|
+
info_box_sublabels_used?
|
632
|
+
end
|
633
|
+
|
634
|
+
def info_box_sublabels_used?
|
635
|
+
used?(@labels[:sublabels][:issue_date]) ||
|
636
|
+
used?(@labels[:sublabels][:due_date]) ||
|
637
|
+
used?(@labels[:sublabels][:variable_symbol])
|
638
|
+
end
|
639
|
+
|
648
640
|
# Build the following table for document items:
|
649
641
|
#
|
650
642
|
# =================================================================
|
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.
|
4
|
+
version: 2.2.0.alpha1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josef Strzibny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- examples/promo.rb
|
112
112
|
- examples/provider_purchaser_lines.rb
|
113
113
|
- examples/simple_invoice.rb
|
114
|
+
- examples/variable_field_invoice.rb
|
114
115
|
- invoice_printer.gemspec
|
115
116
|
- invoice_printer_fonts.gemspec
|
116
117
|
- invoice_printer_server.gemspec
|
@@ -148,11 +149,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
149
|
version: '2.4'
|
149
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
151
|
requirements:
|
151
|
-
- - "
|
152
|
+
- - ">"
|
152
153
|
- !ruby/object:Gem::Version
|
153
|
-
version:
|
154
|
+
version: 1.3.1
|
154
155
|
requirements: []
|
155
|
-
rubygems_version: 3.2.
|
156
|
+
rubygems_version: 3.2.0.rc.1
|
156
157
|
signing_key:
|
157
158
|
specification_version: 4
|
158
159
|
summary: Super simple PDF invoicing in pure Ruby
|