en16931 0.2.1 → 0.2.3
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/CHANGELOG.md +11 -0
- data/README.md +8 -5
- data/lib/en16931/branding.rb +18 -3
- data/lib/en16931/pdf/renderer.rb +24 -10
- data/lib/en16931/totals.rb +4 -1
- data/lib/en16931/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf89ac5a8a8c19581eafd576c8347a4bfb80a6e10b968a96ad16246de48690d3
|
|
4
|
+
data.tar.gz: aac661f80dfe2dc6a30ca558289811a8f62030a6edbf6ab59e22445b65c8d536
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a65c315c7406a81f6cacb3c1d8ab3fc2088e1b13c07d36492bf8f500c10f9859508fc7ac413f79893080307078a4fb2186fec63e39b1639677f8a1c5d3461206
|
|
7
|
+
data.tar.gz: 90a20ba11843250ca95699b5acd552d19d77407aebb30be0377ad2c5eb0f858850ff7d1e39afa54286331c8366aa15aad97f316b971dcb43f26a0cdc48223215
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.2.3] - 2026-11-13
|
|
4
|
+
|
|
5
|
+
- The accent now colours the rule under the table header and the rule above the amount due, as documented; both were drawn black whatever the accent was.
|
|
6
|
+
- `Branding` takes a `title_font:` for the document title alone (a display face without a bold cut is set as it is, at 20 pt), a `title_color:` apart from the accent, and `letterhead_name: false` to leave the seller's name out of the letterhead when the logo is a wordmark. Glyphs a title font lacks come from DejaVu Sans, like those of a branding font.
|
|
7
|
+
- Negative quantities and amounts in the lines carry the true minus sign (−), like the allowances and the prepaid amount in the totals; they were set with a hyphen.
|
|
8
|
+
|
|
9
|
+
## [0.2.2] - 2026-10-26
|
|
10
|
+
|
|
11
|
+
- A cancellation with negative quantities at 0 % VAT (small business, reverse charge, outside the scope) no longer writes a VAT amount of "-0.00" into the breakdown, which failed BR-CO-14 against the total of "0.00".
|
|
12
|
+
- The reference layout prints negative quantities and amounts with their minus sign; it dropped the sign while grouping the thousands, so a cancellation read like an invoice.
|
|
13
|
+
|
|
3
14
|
## [0.2.1] - 2026-10-22
|
|
4
15
|
|
|
5
16
|
- The buyer's country is named in the invoice language for every ISO country, from the Unicode CLDR (`data/countries.yml`, `rake countries`). Before, only nine countries had a name, in German.
|
data/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
<p align="center"><sub>SPONSORED BY</sub></p>
|
|
4
4
|
<p align="center">
|
|
5
|
-
<a href="https://www.company-mood.com"><
|
|
6
|
-
 
|
|
7
|
-
<a href="https://myron.app"><
|
|
8
|
-
 
|
|
9
|
-
<a href="https://www.affliq.com"><
|
|
5
|
+
<a href="https://www.company-mood.com"><img src=".github/sponsors/companymood.svg" alt="CompanyMood" height="60"></a>
|
|
6
|
+
|
|
7
|
+
<a href="https://myron.app"><img src=".github/sponsors/myron.svg" alt="Myron" height="60"></a>
|
|
8
|
+
|
|
9
|
+
<a href="https://www.affliq.com"><img src=".github/sponsors/affliq.svg" alt="Affliq" height="60"></a>
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
12
|
EN 16931 e-invoices for Ruby, in pure Ruby.
|
|
@@ -85,6 +85,9 @@ branding = EN16931::Branding.new(
|
|
|
85
85
|
logo_height: 40, # points; width follows, capped by logo_max_width (180)
|
|
86
86
|
accent: "FF5A1F", # title and rules
|
|
87
87
|
font: { normal: "Inter-Regular.ttf", bold: "Inter-Bold.ttf" }, # TrueType, embedded; DejaVu Sans otherwise
|
|
88
|
+
title_font: "Gloock-Regular.ttf", # optional: a display face for the title alone, set as it is (no bold)
|
|
89
|
+
title_color: "15161A", # optional: the title's colour; the accent otherwise
|
|
90
|
+
letterhead_name: false, # optional: leave the seller's name out beside a logo that is the name
|
|
88
91
|
intro: "vielen Dank für den Auftrag. Für die vereinbarte Leistung berechne ich wie folgt:",
|
|
89
92
|
closing: "Vielen Dank für die gute Zusammenarbeit.\n\nLena Beispiel",
|
|
90
93
|
giro_code: true # default: EPC QR code for euro invoices with an IBAN and an amount due
|
data/lib/en16931/branding.rb
CHANGED
|
@@ -13,20 +13,35 @@ module EN16931
|
|
|
13
13
|
# @param logo_height [Numeric] the logo's height in points (its width follows, capped at logo_max_width)
|
|
14
14
|
# @param accent [String] six hex digits, used for the title and the rules
|
|
15
15
|
# @param font [String, Hash, nil] a TrueType file, or { normal:, bold: } paths; DejaVu Sans otherwise
|
|
16
|
+
# @param title_font [String, nil] a TrueType file for the document title alone, e.g. a display face that has
|
|
17
|
+
# no bold cut; the title is then set in it as it is, not emboldened. The body keeps `font`.
|
|
18
|
+
# @param title_color [String, nil] six hex digits for the title; the accent otherwise
|
|
19
|
+
# @param letterhead_name [Boolean] print the seller's name in the letterhead; turn it off when the logo is
|
|
20
|
+
# the name (a wordmark). Without a logo the name is always printed.
|
|
16
21
|
# @param intro [String, nil] text above the lines, e.g. a salutation
|
|
17
22
|
# @param closing [String, nil] text below the payment details, e.g. thanks and a signature line
|
|
18
23
|
# @param giro_code [Boolean] print the EPC QR code (GiroCode) next to the bank details when the invoice can carry one
|
|
19
|
-
Branding = Data.define(:logo, :logo_position, :logo_height, :logo_max_width, :accent, :font, :intro, :closing, :giro_code
|
|
24
|
+
Branding = Data.define(:logo, :logo_position, :logo_height, :logo_max_width, :accent, :font, :intro, :closing, :giro_code,
|
|
25
|
+
:title_font, :title_color, :letterhead_name) do
|
|
20
26
|
def initialize(logo: nil, logo_position: :left, logo_height: 40, logo_max_width: 180, accent: "15161A", font: nil,
|
|
21
|
-
intro: nil, closing: nil, giro_code: true)
|
|
27
|
+
intro: nil, closing: nil, giro_code: true, title_font: nil, title_color: nil, letterhead_name: true)
|
|
22
28
|
raise ArgumentError, "logo_position must be :left or :right" unless %i[left right].include?(logo_position)
|
|
23
29
|
raise ArgumentError, "accent must be six hex digits, e.g. \"FF5A1F\"" unless accent.to_s.match?(/\A\h{6}\z/)
|
|
30
|
+
raise ArgumentError, "title_color must be six hex digits, e.g. \"15161A\"" unless title_color.nil? || title_color.to_s.match?(/\A\h{6}\z/)
|
|
31
|
+
raise ArgumentError, "title_font must be the path of a TrueType file" unless title_font.nil? || title_font.is_a?(String)
|
|
24
32
|
|
|
25
33
|
super(logo: Branding.image_bytes(logo), logo_position:, logo_height:, logo_max_width:, accent: accent.to_s.upcase,
|
|
26
|
-
font: Branding.font_files(font), intro:, closing:, giro_code
|
|
34
|
+
font: Branding.font_files(font), intro:, closing:, giro_code:, title_font:,
|
|
35
|
+
title_color: title_color&.to_s&.upcase, letterhead_name: letterhead_name ? true : false)
|
|
27
36
|
logo_info # fail at construction, not at render time
|
|
28
37
|
end
|
|
29
38
|
|
|
39
|
+
# The colour the title is printed in.
|
|
40
|
+
def title_colour = title_color || accent
|
|
41
|
+
|
|
42
|
+
# The seller's name belongs in the letterhead unless a logo stands in for it.
|
|
43
|
+
def letterhead_name? = letterhead_name || logo.nil?
|
|
44
|
+
|
|
30
45
|
# The parsed image: width, height and, for a JPEG, the channel count.
|
|
31
46
|
# CMYK images would need a CMYK output intent, so they are refused.
|
|
32
47
|
def logo_info
|
data/lib/en16931/pdf/renderer.rb
CHANGED
|
@@ -9,6 +9,7 @@ module EN16931
|
|
|
9
9
|
class Renderer
|
|
10
10
|
FONT = "DejaVuSans"
|
|
11
11
|
BRAND_FONT = "Brand"
|
|
12
|
+
TITLE_FONT = "Title"
|
|
12
13
|
# The recipient block starts 45 mm below the page top (DIN 5008 window), unless the letterhead runs deeper.
|
|
13
14
|
ADDRESS_TOP = 45 * 72 / 25.4
|
|
14
15
|
GIRO_CODE_SIZE = 68
|
|
@@ -30,11 +31,10 @@ module EN16931
|
|
|
30
31
|
def document
|
|
31
32
|
@document ||= Prawn::Document.new(page_size: "A4", margin: [56, 50, 56, 50], compress: true, info: {}).tap do |pdf|
|
|
32
33
|
pdf.font_families.update(FONT => { normal: EN16931.font_path("DejaVuSans.ttf"), bold: EN16931.font_path("DejaVuSans-Bold.ttf") })
|
|
33
|
-
if branding.font
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
end
|
|
34
|
+
pdf.font_families.update(BRAND_FONT => branding.font) if branding.font
|
|
35
|
+
pdf.font_families.update(TITLE_FONT => { normal: branding.title_font }) if branding.title_font
|
|
36
|
+
# Glyphs a brand or title font lacks (often € in a subset, or another script) come from DejaVu, never as .notdef.
|
|
37
|
+
pdf.fallback_fonts([FONT]) if branding.font || branding.title_font
|
|
38
38
|
pdf.font(branding.font ? BRAND_FONT : FONT, size: 9.5)
|
|
39
39
|
draw(pdf)
|
|
40
40
|
end
|
|
@@ -66,7 +66,7 @@ module EN16931
|
|
|
66
66
|
pdf.image(StringIO.new(branding.logo), at: [x, top], width: width, height: height)
|
|
67
67
|
name_align = :right if branding.logo_position == :left
|
|
68
68
|
end
|
|
69
|
-
pdf.text invoice.seller.name, size: 14, style: :bold, align: name_align
|
|
69
|
+
pdf.text invoice.seller.name, size: 14, style: :bold, align: name_align if branding.letterhead_name?
|
|
70
70
|
pdf.move_cursor_to [pdf.cursor, top - (size ? size[1] : 0)].min
|
|
71
71
|
pdf.move_down 16
|
|
72
72
|
end
|
|
@@ -90,7 +90,7 @@ module EN16931
|
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
def meta(pdf)
|
|
93
|
-
|
|
93
|
+
title(pdf)
|
|
94
94
|
pdf.move_down 8
|
|
95
95
|
rows = [[t(:number), invoice.number], [t(:date), date(invoice.issue_date)]]
|
|
96
96
|
rows << [t(:due), date(invoice.due_date)] if invoice.due_date
|
|
@@ -108,6 +108,15 @@ module EN16931
|
|
|
108
108
|
pdf.move_down 18
|
|
109
109
|
end
|
|
110
110
|
|
|
111
|
+
# The document title. An own title font is set as it is: a display
|
|
112
|
+
# face rarely has a bold cut, and a faked one is not PDF/A's friend.
|
|
113
|
+
def title(pdf)
|
|
114
|
+
text = Renderer.title(invoice, locale)
|
|
115
|
+
return pdf.text(text, size: 16, style: :bold, color: branding.title_colour) unless branding.title_font
|
|
116
|
+
|
|
117
|
+
pdf.font(TITLE_FONT) { pdf.text text, size: 20, color: branding.title_colour }
|
|
118
|
+
end
|
|
119
|
+
|
|
111
120
|
def intro(pdf)
|
|
112
121
|
return unless branding.intro
|
|
113
122
|
|
|
@@ -128,10 +137,12 @@ module EN16931
|
|
|
128
137
|
[i + 1, [line.description, line.note, line.period && "#{date(line.period.begin)} – #{date(line.period.end)}"].compact.join("\n"),
|
|
129
138
|
"#{number(line.quantity, 0..2)} #{unit(line.unit)}", money(line.unit_price), money(line.net)]
|
|
130
139
|
end
|
|
140
|
+
# Prawn evaluates the block on the table: the renderer's instance variables are out of reach in there.
|
|
141
|
+
accent = @accent
|
|
131
142
|
pdf.table([header] + rows, width: pdf.bounds.width, column_widths: { 0 => 32, 2 => 80, 3 => 80, 4 => 80 },
|
|
132
143
|
cell_style: { borders: [:bottom], border_color: "DDDDDD", padding: [6, 4], size: 9.5 }) do
|
|
133
144
|
row(0).font_style = :bold
|
|
134
|
-
row(0).border_color =
|
|
145
|
+
row(0).border_color = accent
|
|
135
146
|
columns(2..4).align = :right
|
|
136
147
|
column(0).align = :right
|
|
137
148
|
end
|
|
@@ -151,12 +162,13 @@ module EN16931
|
|
|
151
162
|
rows << [t(:gross), money(totals.gross)]
|
|
152
163
|
rows << [t(:prepaid), "−#{money(totals.prepaid)}"] if totals.prepaid.positive?
|
|
153
164
|
rows << [t(:payable), money(totals.payable)]
|
|
165
|
+
accent = @accent
|
|
154
166
|
pdf.indent(pdf.bounds.width - 260) do
|
|
155
167
|
pdf.table(rows, column_widths: [160, 100], cell_style: { borders: [], padding: [3, 4], size: 9.5 }) do
|
|
156
168
|
column(1).align = :right
|
|
157
169
|
row(-1).font_style = :bold
|
|
158
170
|
row(-1).borders = [:top]
|
|
159
|
-
row(-1).border_color =
|
|
171
|
+
row(-1).border_color = accent
|
|
160
172
|
end
|
|
161
173
|
end
|
|
162
174
|
pdf.move_down 14
|
|
@@ -242,14 +254,16 @@ module EN16931
|
|
|
242
254
|
{ "EUR" => "€", "USD" => "$", "GBP" => "£", "CHF" => "CHF" }.fetch(invoice.currency, invoice.currency)
|
|
243
255
|
end
|
|
244
256
|
|
|
257
|
+
# A negative number carries the true minus sign, as the totals write it.
|
|
245
258
|
def number(value, decimals)
|
|
246
259
|
text = format("%.#{decimals.max}f", value)
|
|
260
|
+
sign = text.delete_prefix!("-") ? "−" : ""
|
|
247
261
|
int, frac = text.split(".")
|
|
248
262
|
frac = frac&.sub(/0+\z/, "") if decimals.min < decimals.max
|
|
249
263
|
frac = nil if frac && frac.empty?
|
|
250
264
|
sep = FORMATS.fetch(locale)
|
|
251
265
|
int = int.reverse.scan(/\d{1,3}/).join(sep[0]).reverse
|
|
252
|
-
[int, frac].compact.join(sep[1])
|
|
266
|
+
sign + [int, frac].compact.join(sep[1])
|
|
253
267
|
end
|
|
254
268
|
|
|
255
269
|
def date(d) = d.strftime(FORMATS.fetch(locale)[2])
|
data/lib/en16931/totals.rb
CHANGED
|
@@ -25,13 +25,16 @@ module EN16931
|
|
|
25
25
|
private
|
|
26
26
|
|
|
27
27
|
# One subtotal per distinct tax treatment; amount = taxable × rate, rounded.
|
|
28
|
+
# A negative base at 0 % gives BigDecimal -0, which the XML would print as
|
|
29
|
+
# "-0.00" against a total of "0.00" (BR-CO-14); zero is zero.
|
|
28
30
|
def breakdown(invoice)
|
|
29
31
|
bases = Hash.new(BigDecimal("0"))
|
|
30
32
|
invoice.lines.each { |line| bases[invoice.tax_for(line)] += line.net }
|
|
31
33
|
invoice.allowances.each { |a| bases[a.tax || invoice.tax] -= a.amount }
|
|
32
34
|
invoice.charges.each { |c| bases[c.tax || invoice.tax] += c.amount }
|
|
33
35
|
bases.map do |tax, taxable|
|
|
34
|
-
|
|
36
|
+
amount = (taxable * tax.rate / 100).round(2)
|
|
37
|
+
Subtotal.new(tax: tax, taxable: taxable, amount: amount.zero? ? BigDecimal("0") : amount)
|
|
35
38
|
end
|
|
36
39
|
end
|
|
37
40
|
end
|
data/lib/en16931/version.rb
CHANGED