factur-x-builder 0.1.0
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 +7 -0
- data/.gitignore +13 -0
- data/.rubocop.yml +29 -0
- data/CHANGELOG.md +25 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +55 -0
- data/LICENSE.txt +21 -0
- data/README.md +169 -0
- data/Rakefile +16 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/factur-x-builder.gemspec +37 -0
- data/lib/factur-x-builder.rb +5 -0
- data/lib/factur_x/address.rb +19 -0
- data/lib/factur_x/allowance_charge.rb +50 -0
- data/lib/factur_x/codes.rb +77 -0
- data/lib/factur_x/contact.rb +18 -0
- data/lib/factur_x/document.rb +400 -0
- data/lib/factur_x/errors.rb +39 -0
- data/lib/factur_x/formatting.rb +84 -0
- data/lib/factur_x/invoice.rb +81 -0
- data/lib/factur_x/line.rb +82 -0
- data/lib/factur_x/note.rb +41 -0
- data/lib/factur_x/party.rb +52 -0
- data/lib/factur_x/payment.rb +46 -0
- data/lib/factur_x/schemas/Factur-X_1.09_EN16931_QualifiedDataType_100.xsd +94 -0
- data/lib/factur_x/schemas/Factur-X_1.09_EN16931_ReusableAggregateBusinessInformationEntity_100.xsd +318 -0
- data/lib/factur_x/schemas/Factur-X_1.09_EN16931_UnqualifiedDataType_100.xsd +84 -0
- data/lib/factur_x/schemas/Factur-X_EN16931.xsd +20 -0
- data/lib/factur_x/tax_breakdown.rb +39 -0
- data/lib/factur_x/totals.rb +35 -0
- data/lib/factur_x/validation/rules.rb +349 -0
- data/lib/factur_x/validation/schema.rb +40 -0
- data/lib/factur_x/version.rb +5 -0
- data/lib/factur_x.rb +49 -0
- metadata +103 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 73b17dce8190b48d61b4b2f1d521396374ef906351888926d986fb45268f0226
|
|
4
|
+
data.tar.gz: a35e0da9ed5066ef58d5ba29adf2168d86de8d16c3ec8bfee0d5503aae282de2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ca76d2866e7950a772f07b2dc4b17ea2390a1ea8f1b450b2daff5d21347662b0f32cc8bb2e33bc020c39e12d9a5a40096e33b1912a56bdd7ebc5d1a9fc50ca28
|
|
7
|
+
data.tar.gz: d5661ef43aad892fd4bb67a56714455c1b959545e13cbf4ecb6d88292e41d5bf8e1087277d0999fe4473b0e941010d60a7f34b6d0215ba5e1cc214c84f90c981
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.7
|
|
3
|
+
NewCops: enable
|
|
4
|
+
Exclude:
|
|
5
|
+
- "local/**/*"
|
|
6
|
+
- "test/schematron/**/*"
|
|
7
|
+
- "lib/factur/x/builder/schemas/**/*"
|
|
8
|
+
|
|
9
|
+
Metrics:
|
|
10
|
+
Enabled: false
|
|
11
|
+
|
|
12
|
+
# Bundler requires the file named after the gem; it has to keep the gem's name.
|
|
13
|
+
Naming/FileName:
|
|
14
|
+
Exclude:
|
|
15
|
+
- "lib/factur-x-builder.rb"
|
|
16
|
+
|
|
17
|
+
Style/Documentation:
|
|
18
|
+
Enabled: false
|
|
19
|
+
|
|
20
|
+
Style/StringLiterals:
|
|
21
|
+
Enabled: true
|
|
22
|
+
EnforcedStyle: double_quotes
|
|
23
|
+
|
|
24
|
+
Style/StringLiteralsInInterpolation:
|
|
25
|
+
Enabled: true
|
|
26
|
+
EnforcedStyle: double_quotes
|
|
27
|
+
|
|
28
|
+
Layout/LineLength:
|
|
29
|
+
Max: 120
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
## [0.1.0] - 2026-08-05
|
|
2
|
+
|
|
3
|
+
- Initial release
|
|
4
|
+
### Added
|
|
5
|
+
|
|
6
|
+
- `FacturX.build` generates an EN 16931 `factur-x.xml` document from invoicing domain objects:
|
|
7
|
+
`FacturX::Invoice`, `Party`, `Address`, `Contact`, `Line`, `TaxBreakdown`, `Totals`,
|
|
8
|
+
`PaymentMeans`, `PaymentTerms`, `AllowanceCharge`, `Note` and `ReferencedInvoice`.
|
|
9
|
+
- The library is required with `require "factur_x"` and lives under the `FacturX` namespace;
|
|
10
|
+
`require "factur-x-builder"` (the gem name, which Bundler requires by default) also works.
|
|
11
|
+
- French identifiers are mapped to their schemes automatically: SIRET to the party `GlobalID`
|
|
12
|
+
(`0009`), SIREN to the legal organization (`0002`), VAT number to the tax registration (`VA`),
|
|
13
|
+
and the electronic routing address (`0225`) derived from the SIRET.
|
|
14
|
+
- `Note.french_legal_mentions` provides the three statements French law requires on a B2B invoice.
|
|
15
|
+
- Business rule validation in Ruby, reported in invoicing terms and carrying the EN 16931 rule
|
|
16
|
+
identifier. Totals supplied by the caller are checked for coherence against the lines and the VAT
|
|
17
|
+
breakdowns (BR-CO-10, BR-CO-13 to BR-CO-17, BR-S-08) rather than recomputed.
|
|
18
|
+
- Two profiles: `:fr_ctc` (default) additionally requires an invoicing mode and the mandatory legal
|
|
19
|
+
statements; `:en16931` applies the European rules only.
|
|
20
|
+
- Structural validation against the vendored official Factur-X 1.0.9 EN 16931 XSD.
|
|
21
|
+
- Conformance test suite running the official EN 16931 and BR-FR-Flux2 schematrons through Saxon,
|
|
22
|
+
asserting that the Ruby rules agree with them. Skips when Saxon is absent.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
|
6
|
+
|
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
|
8
|
+
|
|
9
|
+
## Our Standards
|
|
10
|
+
|
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
|
12
|
+
|
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
|
18
|
+
|
|
19
|
+
Examples of unacceptable behavior include:
|
|
20
|
+
|
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
|
22
|
+
advances of any kind
|
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
24
|
+
* Public or private harassment
|
|
25
|
+
* Publishing others' private information, such as a physical or email
|
|
26
|
+
address, without their explicit permission
|
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
28
|
+
professional setting
|
|
29
|
+
|
|
30
|
+
## Enforcement Responsibilities
|
|
31
|
+
|
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
|
33
|
+
|
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
|
35
|
+
|
|
36
|
+
## Scope
|
|
37
|
+
|
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
|
39
|
+
|
|
40
|
+
## Enforcement
|
|
41
|
+
|
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at jbvilain@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
|
43
|
+
|
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
|
45
|
+
|
|
46
|
+
## Enforcement Guidelines
|
|
47
|
+
|
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
|
49
|
+
|
|
50
|
+
### 1. Correction
|
|
51
|
+
|
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
|
53
|
+
|
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
|
55
|
+
|
|
56
|
+
### 2. Warning
|
|
57
|
+
|
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
|
59
|
+
|
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
|
61
|
+
|
|
62
|
+
### 3. Temporary Ban
|
|
63
|
+
|
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
|
65
|
+
|
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
|
67
|
+
|
|
68
|
+
### 4. Permanent Ban
|
|
69
|
+
|
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
|
71
|
+
|
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
|
73
|
+
|
|
74
|
+
## Attribution
|
|
75
|
+
|
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
78
|
+
|
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
|
80
|
+
|
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
|
82
|
+
|
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
factur-x-builder (0.1.0)
|
|
5
|
+
nokogiri (~> 1.15, < 1.16)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
ast (2.4.3)
|
|
11
|
+
json (2.21.2)
|
|
12
|
+
language_server-protocol (3.17.0.6)
|
|
13
|
+
lint_roller (1.1.0)
|
|
14
|
+
minitest (5.26.1)
|
|
15
|
+
nokogiri (1.15.7-x86_64-darwin)
|
|
16
|
+
racc (~> 1.4)
|
|
17
|
+
parallel (1.28.0)
|
|
18
|
+
parser (3.3.12.0)
|
|
19
|
+
ast (~> 2.4.1)
|
|
20
|
+
racc
|
|
21
|
+
prism (1.9.0)
|
|
22
|
+
racc (1.8.1)
|
|
23
|
+
rainbow (3.1.1)
|
|
24
|
+
rake (13.4.2)
|
|
25
|
+
regexp_parser (2.12.0)
|
|
26
|
+
rubocop (1.89.0)
|
|
27
|
+
json (~> 2.3)
|
|
28
|
+
language_server-protocol (~> 3.17.0.2)
|
|
29
|
+
lint_roller (~> 1.1.0)
|
|
30
|
+
parallel (>= 1.10)
|
|
31
|
+
parser (>= 3.3.0.2)
|
|
32
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
33
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
34
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
35
|
+
ruby-progressbar (~> 1.7)
|
|
36
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
37
|
+
rubocop-ast (1.50.0)
|
|
38
|
+
parser (>= 3.3.7.2)
|
|
39
|
+
prism (~> 1.7)
|
|
40
|
+
ruby-progressbar (1.13.0)
|
|
41
|
+
unicode-display_width (3.2.0)
|
|
42
|
+
unicode-emoji (~> 4.1)
|
|
43
|
+
unicode-emoji (4.2.0)
|
|
44
|
+
|
|
45
|
+
PLATFORMS
|
|
46
|
+
x86_64-darwin-21
|
|
47
|
+
|
|
48
|
+
DEPENDENCIES
|
|
49
|
+
factur-x-builder!
|
|
50
|
+
minitest (~> 5.0)
|
|
51
|
+
rake (~> 13.0)
|
|
52
|
+
rubocop (~> 1.7)
|
|
53
|
+
|
|
54
|
+
BUNDLED WITH
|
|
55
|
+
2.4.5
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jean-Baptiste Vilain
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Factur-X Builder
|
|
2
|
+
|
|
3
|
+
Generates the `factur-x.xml` attachment of a [Factur-X](http://fnfe-mpe.org/factur-x/) invoice in the
|
|
4
|
+
**EN 16931** profile, from objects that speak the language of invoicing rather than the language of
|
|
5
|
+
the CII schema.
|
|
6
|
+
|
|
7
|
+
The gem produces the XML only. Embedding it into a PDF/A-3 is the job of a separate tool
|
|
8
|
+
(`facturx-pdfgen`, Ghostscript, veraPDF…). This split is deliberate: your Rails app builds the
|
|
9
|
+
invoice data, this gem turns it into a compliant XML attachment, and the PDF toolchain stays
|
|
10
|
+
independent.
|
|
11
|
+
|
|
12
|
+
French e-invoicing identifiers are first class — SIRET, SIREN, VAT number and the routing address
|
|
13
|
+
(scheme `0225`) used by the PPF — and the rules that the French reform adds on top of EN 16931 are
|
|
14
|
+
enforced by default.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
gem "factur-x-builder"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Requires Ruby >= 2.7 and Nokogiri ~> 1.15.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
require "factur_x"
|
|
28
|
+
|
|
29
|
+
seller = FacturX::Party.new(
|
|
30
|
+
name: "OFFICE DE TOURISME DES MONTS FICTIFS",
|
|
31
|
+
siret: "39876543800005",
|
|
32
|
+
siren: "398765438",
|
|
33
|
+
vat_number: "FR79398765438",
|
|
34
|
+
contact: FacturX::Contact.new(person_name: "Service comptabilité", email: "compta@example.org"),
|
|
35
|
+
address: FacturX::Address.new(
|
|
36
|
+
line_one: "4 boulevard des Sources",
|
|
37
|
+
postcode: "63240",
|
|
38
|
+
city: "LE MONT-FICTIF",
|
|
39
|
+
country_code: "FR"
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
buyer = FacturX::Party.new(
|
|
44
|
+
name: "SARL COTEAUX ET COMPAGNIE",
|
|
45
|
+
siret: "81234567600009",
|
|
46
|
+
siren: "812345676",
|
|
47
|
+
vat_number: "FR19812345676",
|
|
48
|
+
address: FacturX::Address.new(
|
|
49
|
+
line_one: "123 avenue des Alpages",
|
|
50
|
+
postcode: "74000",
|
|
51
|
+
city: "Annecy",
|
|
52
|
+
country_code: "FR"
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
invoice = FacturX::Invoice.new(
|
|
57
|
+
number: "5-2026-0004",
|
|
58
|
+
issued_on: Date.new(2026, 8, 4),
|
|
59
|
+
business_process: "S1",
|
|
60
|
+
currency: "EUR",
|
|
61
|
+
notes: FacturX::Note.french_legal_mentions,
|
|
62
|
+
seller: seller,
|
|
63
|
+
buyer: buyer,
|
|
64
|
+
delivered_on: Date.new(2026, 8, 4),
|
|
65
|
+
payment_reference: "5-2026-0004",
|
|
66
|
+
payment_means: FacturX::PaymentMeans.new(
|
|
67
|
+
iban: "FR54300020001000012345678",
|
|
68
|
+
account_name: "OFFICE DE TOURISME DES MONTS FICTIFS",
|
|
69
|
+
bic: "AGRIFRPP"
|
|
70
|
+
),
|
|
71
|
+
payment_terms: FacturX::PaymentTerms.new(description: "Paiement à 30 jours",
|
|
72
|
+
due_on: Date.new(2026, 9, 3)),
|
|
73
|
+
lines: [
|
|
74
|
+
FacturX::Line.new(name: "Partenariat 2026", unit_price: 194.00, quantity: 1,
|
|
75
|
+
net_amount: 194.00, vat_rate: 20.0)
|
|
76
|
+
],
|
|
77
|
+
tax_breakdowns: [
|
|
78
|
+
FacturX::TaxBreakdown.new(category: "S", rate: 20.0,
|
|
79
|
+
basis_amount: 194.00, calculated_amount: 38.80)
|
|
80
|
+
],
|
|
81
|
+
totals: FacturX::Totals.new(
|
|
82
|
+
line_total: 194.00,
|
|
83
|
+
tax_basis_total: 194.00,
|
|
84
|
+
tax_total: 38.80,
|
|
85
|
+
grand_total: 232.80,
|
|
86
|
+
due_payable: 232.80
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
File.write("factur-x.xml", FacturX.build(invoice))
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`include FacturX` drops the prefix if you build a lot of invoices in one place —
|
|
94
|
+
`Invoice.new`, `Party.new` — while the entry point stays `FacturX.build`.
|
|
95
|
+
|
|
96
|
+
### Totals are yours, coherence is checked
|
|
97
|
+
|
|
98
|
+
The gem never computes amounts. Your application supplies every total, and the gem verifies they
|
|
99
|
+
hang together before writing anything — a mismatch raises rather than producing a document the
|
|
100
|
+
platform would reject:
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
FacturX.build(invoice)
|
|
104
|
+
# FacturX::ValidationError: invoice is not valid:
|
|
105
|
+
# - total with VAT (BT-112) is 9999.99 but total without VAT plus VAT add up to 232.80 (BR-CO-15)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
To collect every problem instead of raising on the first, use `violations`:
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
FacturX.violations(invoice) # => ["...", "..."]
|
|
112
|
+
FacturX.valid?(invoice) # => false
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Profiles
|
|
116
|
+
|
|
117
|
+
By default the French e-invoicing rules apply on top of EN 16931: an invoicing mode (BT-23) and the
|
|
118
|
+
three mandatory legal statements are required. For an invoice issued outside that regime:
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
FacturX.build(invoice, profile: :en16931)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`FacturX::Note.french_legal_mentions` returns the three statements French law requires (late payment
|
|
125
|
+
penalties, the €40 recovery indemnity, and the absence of an early payment discount). Pass your own
|
|
126
|
+
wording to any of `FacturX::Note.recovery_indemnity`, `FacturX::Note.late_payment_penalties` or
|
|
127
|
+
`FacturX::Note.no_early_payment_discount` to override the default text.
|
|
128
|
+
|
|
129
|
+
### Validation layers
|
|
130
|
+
|
|
131
|
+
| Layer | What it checks | Cost | When |
|
|
132
|
+
|---|---|---|---|
|
|
133
|
+
| `FacturX::Validation::Rules` | EN 16931 + French business rules, in Ruby | sub-millisecond | every `build`, unless `validate: false` |
|
|
134
|
+
| `FacturX::Validation::Schema` | official Factur-X 1.0.9 EN 16931 XSD, via Nokogiri | ~1 ms | every `build`, unless `validate_schema: false` |
|
|
135
|
+
| Schematron | the official rules, via Saxon | ~1.4 s | the test suite only |
|
|
136
|
+
|
|
137
|
+
The Ruby rules exist so your application gets a fast, readable error in the invoicing domain's own
|
|
138
|
+
words. The schematron remains the authority: the test suite runs it against every generated document
|
|
139
|
+
and asserts the Ruby rules agree with it, so the two cannot silently drift apart.
|
|
140
|
+
|
|
141
|
+
## Development
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
bin/setup
|
|
145
|
+
bundle exec rake
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`rake` runs the tests and RuboCop. Conformance tests shell out to Saxon:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
brew install saxon
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Without it, those tests skip rather than fail. The stylesheets live in `test/schematron/` and are
|
|
155
|
+
excluded from the packaged gem.
|
|
156
|
+
|
|
157
|
+
## Scope
|
|
158
|
+
|
|
159
|
+
Supported: invoices and credit notes (`380`, `381`, `389`), multiple VAT rates and categories,
|
|
160
|
+
exemptions with their reason, document level allowances and charges, prepayments, preceding invoice
|
|
161
|
+
references, delivery and billing periods, purchase order / contract / project references, credit
|
|
162
|
+
transfers, direct debits and cards.
|
|
163
|
+
|
|
164
|
+
Not supported: the `extended` and `extended-ctc-fr` profiles (the `EXT-FR-FE-*` fields), UBL syntax,
|
|
165
|
+
Order-X, and embedding the XML into a PDF.
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
Available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rake/testtask"
|
|
5
|
+
|
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
|
7
|
+
t.libs << "test"
|
|
8
|
+
t.libs << "lib"
|
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require "rubocop/rake_task"
|
|
13
|
+
|
|
14
|
+
RuboCop::RakeTask.new
|
|
15
|
+
|
|
16
|
+
task default: %i[test rubocop]
|
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "factur_x"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require "irb"
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/factur_x/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "factur-x-builder"
|
|
7
|
+
spec.version = FacturX::VERSION
|
|
8
|
+
spec.authors = ["Hotentic"]
|
|
9
|
+
spec.email = ["contact@hotentic.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "A simple tool to build a factur-x.xml XML file using required input fields."
|
|
12
|
+
spec.description = "Generates the EN 16931 factur-x.xml attachment of a Factur-X invoice " \
|
|
13
|
+
"from invoicing domain objects, with French e-invoicing identifiers " \
|
|
14
|
+
"(SIRET, SIREN, routing address) supported out of the box."
|
|
15
|
+
spec.homepage = "https://hotentic.com"
|
|
16
|
+
spec.license = "MIT"
|
|
17
|
+
spec.required_ruby_version = ">= 2.7.0"
|
|
18
|
+
|
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/hotentic/factur-x-builder"
|
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/hotentic/factur-x-builder/blob/main/CHANGELOG.md"
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = "exe"
|
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
|
+
spec.require_paths = ["lib"]
|
|
31
|
+
|
|
32
|
+
# 1.15 is the last Nokogiri line supporting Ruby 2.7.
|
|
33
|
+
spec.add_dependency "nokogiri", "~> 1.15", "< 1.16"
|
|
34
|
+
|
|
35
|
+
# For more information and examples about making a new gem, checkout our
|
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
37
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module FacturX
|
|
4
|
+
class Address
|
|
5
|
+
attr_reader :line_one, :line_two, :line_three, :city, :postcode,
|
|
6
|
+
:country_code, :country_subdivision
|
|
7
|
+
|
|
8
|
+
def initialize(country_code:, line_one: nil, line_two: nil, line_three: nil,
|
|
9
|
+
city: nil, postcode: nil, country_subdivision: nil)
|
|
10
|
+
@country_code = country_code
|
|
11
|
+
@line_one = line_one
|
|
12
|
+
@line_two = line_two
|
|
13
|
+
@line_three = line_three
|
|
14
|
+
@city = city
|
|
15
|
+
@postcode = postcode
|
|
16
|
+
@country_subdivision = country_subdivision
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "codes"
|
|
4
|
+
|
|
5
|
+
module FacturX
|
|
6
|
+
# A document level allowance (BG-20) or charge (BG-21).
|
|
7
|
+
class AllowanceCharge
|
|
8
|
+
attr_reader :amount, :basis_amount, :percentage, :reason, :reason_code,
|
|
9
|
+
:vat_category, :vat_rate, :charge
|
|
10
|
+
|
|
11
|
+
def initialize(amount:, charge:, basis_amount: nil, percentage: nil,
|
|
12
|
+
reason: nil, reason_code: nil,
|
|
13
|
+
vat_category: Codes::VatCategory::STANDARD, vat_rate: nil)
|
|
14
|
+
@amount = amount
|
|
15
|
+
@charge = charge
|
|
16
|
+
@basis_amount = basis_amount
|
|
17
|
+
@percentage = percentage
|
|
18
|
+
@reason = reason
|
|
19
|
+
@reason_code = reason_code
|
|
20
|
+
@vat_category = vat_category
|
|
21
|
+
@vat_rate = vat_rate
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.allowance(**attributes)
|
|
25
|
+
new(charge: false, **attributes)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.charge(**attributes)
|
|
29
|
+
new(charge: true, **attributes)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def charge?
|
|
33
|
+
charge
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def amount_decimal
|
|
37
|
+
Formatting.decimal(amount)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class ReferencedInvoice
|
|
42
|
+
attr_reader :number, :issued_on, :type_code
|
|
43
|
+
|
|
44
|
+
def initialize(number:, issued_on: nil, type_code: nil)
|
|
45
|
+
@number = number
|
|
46
|
+
@issued_on = issued_on
|
|
47
|
+
@type_code = type_code
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module FacturX
|
|
4
|
+
module Codes
|
|
5
|
+
EN16931_GUIDELINE = "urn:cen.eu:en16931:2017"
|
|
6
|
+
|
|
7
|
+
COMMERCIAL_INVOICE = "380"
|
|
8
|
+
CREDIT_NOTE = "381"
|
|
9
|
+
SELF_BILLED_INVOICE = "389"
|
|
10
|
+
|
|
11
|
+
DOCUMENT_TYPES = [COMMERCIAL_INVOICE, CREDIT_NOTE, SELF_BILLED_INVOICE].freeze
|
|
12
|
+
|
|
13
|
+
# Invoicing modes accepted by the French e-invoicing reform (BR-FR-08).
|
|
14
|
+
BUSINESS_PROCESSES = %w[B1 S1 M1 B2 S2 M2 S3 B4 S4 M4 S5 S6 B7 S7 B8 S8 M8 B9 S9 M9].freeze
|
|
15
|
+
|
|
16
|
+
VAT_TYPE = "VAT"
|
|
17
|
+
|
|
18
|
+
module VatCategory
|
|
19
|
+
STANDARD = "S"
|
|
20
|
+
ZERO_RATED = "Z"
|
|
21
|
+
EXEMPT = "E"
|
|
22
|
+
REVERSE_CHARGE = "AE"
|
|
23
|
+
INTRA_COMMUNITY = "K"
|
|
24
|
+
EXPORT = "G"
|
|
25
|
+
OUT_OF_SCOPE = "O"
|
|
26
|
+
CANARY_ISLANDS = "L"
|
|
27
|
+
CEUTA_AND_MELILLA = "M"
|
|
28
|
+
|
|
29
|
+
ALL = [STANDARD, ZERO_RATED, EXEMPT, REVERSE_CHARGE, INTRA_COMMUNITY,
|
|
30
|
+
EXPORT, OUT_OF_SCOPE, CANARY_ISLANDS, CEUTA_AND_MELILLA].freeze
|
|
31
|
+
|
|
32
|
+
# BR-E-*, BR-AE-*, BR-K-*, BR-G-*, BR-O-*: these categories are taxed at 0%.
|
|
33
|
+
ZERO_RATE_ONLY = [ZERO_RATED, EXEMPT, REVERSE_CHARGE, INTRA_COMMUNITY,
|
|
34
|
+
EXPORT, OUT_OF_SCOPE].freeze
|
|
35
|
+
|
|
36
|
+
# BR-E-10, BR-AE-10, BR-K-10, BR-G-10: an exemption reason is mandatory.
|
|
37
|
+
REQUIRING_EXEMPTION_REASON = [EXEMPT, REVERSE_CHARGE, INTRA_COMMUNITY, EXPORT].freeze
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
module PaymentMeansType
|
|
41
|
+
CASH = "10"
|
|
42
|
+
CHEQUE = "20"
|
|
43
|
+
CREDIT_TRANSFER = "30"
|
|
44
|
+
BANK_CARD = "48"
|
|
45
|
+
DIRECT_DEBIT = "49"
|
|
46
|
+
SEPA_CREDIT_TRANSFER = "58"
|
|
47
|
+
SEPA_DIRECT_DEBIT = "59"
|
|
48
|
+
NOT_DEFINED = "1"
|
|
49
|
+
|
|
50
|
+
REQUIRING_CREDITOR_ACCOUNT = [CREDIT_TRANSFER, SEPA_CREDIT_TRANSFER].freeze
|
|
51
|
+
REQUIRING_MANDATE = [DIRECT_DEBIT, SEPA_DIRECT_DEBIT].freeze
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
module NoteSubject
|
|
55
|
+
GENERAL = "AAI"
|
|
56
|
+
PAYMENT_TERMS = "PMT"
|
|
57
|
+
PAYMENT_PENALTIES = "PMD"
|
|
58
|
+
DISCOUNT_TERMS = "AAB"
|
|
59
|
+
REGULATORY = "REG"
|
|
60
|
+
INVOICE_TYPE = "ADN"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
module Scheme
|
|
64
|
+
SIRET = "0009"
|
|
65
|
+
SIREN = "0002"
|
|
66
|
+
ROUTING_SIRET = "0225"
|
|
67
|
+
GLN = "0088"
|
|
68
|
+
GTIN = "0160"
|
|
69
|
+
VAT = "VA"
|
|
70
|
+
FISCAL = "FC"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
PIECE_UNIT = "C62"
|
|
74
|
+
|
|
75
|
+
DEFAULT_COUNTRY = "FR"
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module FacturX
|
|
4
|
+
class Contact
|
|
5
|
+
attr_reader :person_name, :department_name, :phone, :email
|
|
6
|
+
|
|
7
|
+
def initialize(person_name: nil, department_name: nil, phone: nil, email: nil)
|
|
8
|
+
@person_name = person_name
|
|
9
|
+
@department_name = department_name
|
|
10
|
+
@phone = phone
|
|
11
|
+
@email = email
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def empty?
|
|
15
|
+
[person_name, department_name, phone, email].all?(&:nil?)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|