facturx 0.1.0 → 0.2.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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -1
  3. data/NOTICE.md +2 -0
  4. data/README.md +27 -1
  5. data/lib/facturx/coerce.rb +74 -0
  6. data/lib/facturx/diagnostic.rb +20 -0
  7. data/lib/facturx/document.rb +45 -0
  8. data/lib/facturx/group.rb +5 -0
  9. data/lib/facturx/model/common.rb +8 -0
  10. data/lib/facturx/model/immutable.rb +75 -0
  11. data/lib/facturx/model/line.rb +14 -0
  12. data/lib/facturx/model/party.rb +10 -0
  13. data/lib/facturx/model/payment.rb +9 -0
  14. data/lib/facturx/model/reference.rb +7 -0
  15. data/lib/facturx/model/trade.rb +9 -0
  16. data/lib/facturx/model.rb +9 -0
  17. data/lib/facturx/pdf/extractor.rb +7 -4
  18. data/lib/facturx/reader/semantic_mapper/delivery_mapping.rb +43 -0
  19. data/lib/facturx/reader/semantic_mapper/document_mapping.rb +109 -0
  20. data/lib/facturx/reader/semantic_mapper/helpers.rb +114 -0
  21. data/lib/facturx/reader/semantic_mapper/line_mapping.rb +120 -0
  22. data/lib/facturx/reader/semantic_mapper/party_mapping.rb +90 -0
  23. data/lib/facturx/reader/semantic_mapper/payment_mapping.rb +71 -0
  24. data/lib/facturx/reader/semantic_mapper/trade_mapping.rb +83 -0
  25. data/lib/facturx/reader/semantic_mapper.rb +67 -0
  26. data/lib/facturx/reader/term_reader/coercion.rb +69 -0
  27. data/lib/facturx/reader/term_reader/unmapped.rb +37 -0
  28. data/lib/facturx/reader/term_reader.rb +124 -0
  29. data/lib/facturx/reader.rb +101 -0
  30. data/lib/facturx/reading.rb +23 -0
  31. data/lib/facturx/source_reader.rb +30 -0
  32. data/lib/facturx/term.rb +5 -0
  33. data/lib/facturx/terms/declaration.rb +20 -0
  34. data/lib/facturx/terms/declarations/adjustments.rb +230 -0
  35. data/lib/facturx/terms/declarations/delivery.rb +83 -0
  36. data/lib/facturx/terms/declarations/document.rb +223 -0
  37. data/lib/facturx/terms/declarations/groups.rb +356 -0
  38. data/lib/facturx/terms/declarations/lines.rb +166 -0
  39. data/lib/facturx/terms/declarations/parties.rb +609 -0
  40. data/lib/facturx/terms/declarations/payment.rb +106 -0
  41. data/lib/facturx/terms/declarations/products.rb +103 -0
  42. data/lib/facturx/terms/declarations/references.rb +72 -0
  43. data/lib/facturx/terms/declarations/taxes.rb +92 -0
  44. data/lib/facturx/terms/declarations/totals.rb +107 -0
  45. data/lib/facturx/terms/reference.rb +21 -0
  46. data/lib/facturx/terms.rb +109 -0
  47. data/lib/facturx/version.rb +1 -1
  48. data/lib/facturx.rb +14 -0
  49. metadata +45 -4
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ Facturx::TermDeclarations::PAYMENT = [
4
+ Facturx::TermDeclarations::Declaration.term(
5
+ 'BT-90', :direct_debit, :creditor_identifier, 'BG-19',
6
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
7
+ '/ram:CreditorReferenceID',
8
+ :string, nil,
9
+ basic_wl: '0..1',
10
+ basic: '0..1',
11
+ en16931: '0..1',
12
+ extended: '0..1'
13
+ ),
14
+ Facturx::TermDeclarations::Declaration.term(
15
+ 'BT-83', :payment_instructions, :remittance_information, 'BG-19',
16
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
17
+ '/ram:PaymentReference',
18
+ :string, nil,
19
+ basic_wl: '0..1',
20
+ basic: '0..1',
21
+ en16931: '0..1',
22
+ extended: '0..1'
23
+ ),
24
+ Facturx::TermDeclarations::Declaration.term(
25
+ 'BT-81', :payment_instructions, :means_code, 'BG-16',
26
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
27
+ '/ram:SpecifiedTradeSettlementPaymentMeans/ram:TypeCode',
28
+ :string, nil,
29
+ basic_wl: '1..1',
30
+ basic: '1..1',
31
+ en16931: '1..1',
32
+ extended: '1..1'
33
+ ),
34
+ Facturx::TermDeclarations::Declaration.term(
35
+ 'BT-82', :payment_instructions, :means_text, 'BG-16',
36
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
37
+ '/ram:SpecifiedTradeSettlementPaymentMeans/ram:Information',
38
+ :string, nil,
39
+ en16931: '0..1',
40
+ extended: '0..1'
41
+ ),
42
+ Facturx::TermDeclarations::Declaration.term(
43
+ 'BT-87', :payment_card, :primary_account_number, 'BG-18',
44
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
45
+ '/ram:SpecifiedTradeSettlementPaymentMeans/ram:ApplicableTradeSettlementFinancialCard/ram:ID',
46
+ :string, nil,
47
+ en16931: '1..1',
48
+ extended: '1..1'
49
+ ),
50
+ Facturx::TermDeclarations::Declaration.term(
51
+ 'BT-88', :payment_card, :holder_name, 'BG-18',
52
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
53
+ '/ram:SpecifiedTradeSettlementPaymentMeans/ram:ApplicableTradeSettlementFinancialCard' \
54
+ '/ram:CardholderName',
55
+ :string, nil,
56
+ en16931: '0..1',
57
+ extended: '0..1'
58
+ ),
59
+ Facturx::TermDeclarations::Declaration.term(
60
+ 'BT-91', :direct_debit, :debtor_account_identifier, 'BG-16',
61
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
62
+ '/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayerPartyDebtorFinancialAccount/ram:IBANID',
63
+ :string, nil,
64
+ basic_wl: '0..1',
65
+ basic: '0..1',
66
+ en16931: '0..1',
67
+ extended: '0..1'
68
+ ),
69
+ Facturx::TermDeclarations::Declaration.term(
70
+ 'BT-84', :credit_transfer, :account_identifier, 'BG-17',
71
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
72
+ '/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayeePartyCreditorFinancialAccount/ram:IBANID',
73
+ :string, nil,
74
+ basic_wl: '1..1',
75
+ basic: '1..1',
76
+ en16931: '1..1',
77
+ extended: '1..1'
78
+ ),
79
+ Facturx::TermDeclarations::Declaration.term(
80
+ 'BT-85', :credit_transfer, :account_name, 'BG-17',
81
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
82
+ '/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayeePartyCreditorFinancialAccount/ram:AccountName',
83
+ :string, nil,
84
+ en16931: '0..1',
85
+ extended: '0..1'
86
+ ),
87
+ Facturx::TermDeclarations::Declaration.term(
88
+ 'BT-86', :credit_transfer, :provider_identifier, 'BG-16',
89
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
90
+ '/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayeeSpecifiedCreditorFinancialInstitution' \
91
+ '/ram:BICID',
92
+ :string, nil,
93
+ en16931: '0..1',
94
+ extended: '0..1'
95
+ ),
96
+ Facturx::TermDeclarations::Declaration.term(
97
+ 'BT-89', :direct_debit, :mandate_identifier, 'BG-19',
98
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
99
+ '/ram:SpecifiedTradePaymentTerms/ram:DirectDebitMandateID',
100
+ :string, nil,
101
+ basic_wl: '0..1',
102
+ basic: '0..1',
103
+ en16931: '0..1',
104
+ extended: '0..1'
105
+ )
106
+ ].freeze
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ Facturx::TermDeclarations::PRODUCTS = [
4
+ Facturx::TermDeclarations::Declaration.term(
5
+ 'BT-157', :product, :global_identifier, 'BG-31',
6
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
7
+ '/ram:SpecifiedTradeProduct/ram:GlobalID',
8
+ :string, nil,
9
+ basic: '0..1',
10
+ en16931: '0..1',
11
+ extended: '0..1'
12
+ ),
13
+ Facturx::TermDeclarations::Declaration.term(
14
+ 'BT-157-1', :product, :global_identifier, 'BG-31',
15
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
16
+ '/ram:SpecifiedTradeProduct/ram:GlobalID/@schemeID',
17
+ :string, nil,
18
+ basic: '1..1',
19
+ en16931: '1..1',
20
+ extended: '1..1'
21
+ ),
22
+ Facturx::TermDeclarations::Declaration.term(
23
+ 'BT-155', :product, :seller_identifier, 'BG-31',
24
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
25
+ '/ram:SpecifiedTradeProduct/ram:SellerAssignedID',
26
+ :string, nil,
27
+ en16931: '0..1',
28
+ extended: '0..1'
29
+ ),
30
+ Facturx::TermDeclarations::Declaration.term(
31
+ 'BT-156', :product, :buyer_identifier, 'BG-31',
32
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
33
+ '/ram:SpecifiedTradeProduct/ram:BuyerAssignedID',
34
+ :string, nil,
35
+ en16931: '0..1',
36
+ extended: '0..1'
37
+ ),
38
+ Facturx::TermDeclarations::Declaration.term(
39
+ 'BT-153', :product, :name, 'BG-31',
40
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
41
+ '/ram:SpecifiedTradeProduct/ram:Name',
42
+ :string, nil,
43
+ basic: '1..1',
44
+ en16931: '1..1',
45
+ extended: '1..1'
46
+ ),
47
+ Facturx::TermDeclarations::Declaration.term(
48
+ 'BT-154', :product, :description, 'BG-31',
49
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
50
+ '/ram:SpecifiedTradeProduct/ram:Description',
51
+ :string, nil,
52
+ en16931: '0..1',
53
+ extended: '0..1'
54
+ ),
55
+ Facturx::TermDeclarations::Declaration.term(
56
+ 'BT-160', :product_attribute, :name, 'BG-32',
57
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
58
+ '/ram:SpecifiedTradeProduct/ram:ApplicableProductCharacteristic/ram:Description',
59
+ :string, nil,
60
+ en16931: '1..1',
61
+ extended: '1..1'
62
+ ),
63
+ Facturx::TermDeclarations::Declaration.term(
64
+ 'BT-161', :product_attribute, :value, 'BG-32',
65
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
66
+ '/ram:SpecifiedTradeProduct/ram:ApplicableProductCharacteristic/ram:Value',
67
+ :string, nil,
68
+ en16931: '1..1',
69
+ extended: '1..1'
70
+ ),
71
+ Facturx::TermDeclarations::Declaration.term(
72
+ 'BT-158', :product_classification, :code, 'BG-31',
73
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
74
+ '/ram:SpecifiedTradeProduct/ram:DesignatedProductClassification/ram:ClassCode',
75
+ :string, nil,
76
+ en16931: '0..n',
77
+ extended: '0..n'
78
+ ),
79
+ Facturx::TermDeclarations::Declaration.term(
80
+ 'BT-158-1', :product_classification, :list_id, 'BG-31',
81
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
82
+ '/ram:SpecifiedTradeProduct/ram:DesignatedProductClassification/ram:ClassCode/@listID',
83
+ :string, nil,
84
+ en16931: '1..1',
85
+ extended: '1..1'
86
+ ),
87
+ Facturx::TermDeclarations::Declaration.term(
88
+ 'BT-158-2', :product_classification, :list_version_id, 'BG-31',
89
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
90
+ '/ram:SpecifiedTradeProduct/ram:DesignatedProductClassification/ram:ClassCode/@listVersionID',
91
+ :string, nil,
92
+ en16931: '0..1',
93
+ extended: '0..1'
94
+ ),
95
+ Facturx::TermDeclarations::Declaration.term(
96
+ 'BT-159', :product, :origin_country_code, 'BG-31',
97
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
98
+ '/ram:SpecifiedTradeProduct/ram:OriginTradeCountry/ram:ID',
99
+ :string, nil,
100
+ en16931: '0..1',
101
+ extended: '0..1'
102
+ )
103
+ ].freeze
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ Facturx::TermDeclarations::REFERENCES = [
4
+ Facturx::TermDeclarations::Declaration.term(
5
+ 'BT-122', :supporting_document, :reference, 'BG-24',
6
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement' \
7
+ '/ram:AdditionalReferencedDocument/ram:IssuerAssignedID',
8
+ :string, nil,
9
+ en16931: '1..1',
10
+ extended: '1..1'
11
+ ),
12
+ Facturx::TermDeclarations::Declaration.term(
13
+ 'BT-124', :supporting_document, :external_location, 'BG-24',
14
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement' \
15
+ '/ram:AdditionalReferencedDocument/ram:URIID',
16
+ :string, nil,
17
+ en16931: '0..1',
18
+ extended: '0..1'
19
+ ),
20
+ Facturx::TermDeclarations::Declaration.term(
21
+ 'BT-123', :supporting_document, :description, 'BG-24',
22
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement' \
23
+ '/ram:AdditionalReferencedDocument/ram:Name',
24
+ :string, nil,
25
+ en16931: '0..1',
26
+ extended: '0..1'
27
+ ),
28
+ Facturx::TermDeclarations::Declaration.term(
29
+ 'BT-125', :supporting_document, :content, 'BG-24',
30
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement' \
31
+ '/ram:AdditionalReferencedDocument/ram:AttachmentBinaryObject',
32
+ :binary, nil,
33
+ en16931: '0..1',
34
+ extended: '0..1'
35
+ ),
36
+ Facturx::TermDeclarations::Declaration.term(
37
+ 'BT-125-1', :supporting_document, :mime_code, 'BG-24',
38
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement' \
39
+ '/ram:AdditionalReferencedDocument/ram:AttachmentBinaryObject/@mimeCode',
40
+ :string, nil,
41
+ en16931: '1..1',
42
+ extended: '1..1'
43
+ ),
44
+ Facturx::TermDeclarations::Declaration.term(
45
+ 'BT-125-2', :supporting_document, :filename, 'BG-24',
46
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement' \
47
+ '/ram:AdditionalReferencedDocument/ram:AttachmentBinaryObject/@filename',
48
+ :string, nil,
49
+ en16931: '1..1',
50
+ extended: '1..1'
51
+ ),
52
+ Facturx::TermDeclarations::Declaration.term(
53
+ 'BT-25', :document_reference, :id, 'BG-3',
54
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
55
+ '/ram:InvoiceReferencedDocument/ram:IssuerAssignedID',
56
+ :string, nil,
57
+ basic_wl: '1..1',
58
+ basic: '1..1',
59
+ en16931: '1..1',
60
+ extended: '1..1'
61
+ ),
62
+ Facturx::TermDeclarations::Declaration.term(
63
+ 'BT-26', :document_reference, :issue_date, 'BG-3',
64
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
65
+ '/ram:InvoiceReferencedDocument/ram:FormattedIssueDateTime/qdt:DateTimeString',
66
+ :date_102, nil,
67
+ basic_wl: '0..1',
68
+ basic: '0..1',
69
+ en16931: '0..1',
70
+ extended: '0..1'
71
+ )
72
+ ].freeze
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ Facturx::TermDeclarations::TAXES = [
4
+ Facturx::TermDeclarations::Declaration.term(
5
+ 'BT-151', :tax_breakdown, :category_code, 'BG-30',
6
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
7
+ '/ram:SpecifiedLineTradeSettlement/ram:ApplicableTradeTax/ram:CategoryCode',
8
+ :string, nil,
9
+ basic: '1..1',
10
+ en16931: '1..1',
11
+ extended: '1..1'
12
+ ),
13
+ Facturx::TermDeclarations::Declaration.term(
14
+ 'BT-152', :tax_breakdown, :rate, 'BG-30',
15
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem' \
16
+ '/ram:SpecifiedLineTradeSettlement/ram:ApplicableTradeTax/ram:RateApplicablePercent',
17
+ :decimal, nil,
18
+ basic: '0..1',
19
+ en16931: '0..1',
20
+ extended: '0..1'
21
+ ),
22
+ Facturx::TermDeclarations::Declaration.term(
23
+ 'BT-117', :tax_breakdown, :tax_amount, 'BG-23',
24
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
25
+ '/ram:ApplicableTradeTax/ram:CalculatedAmount',
26
+ :decimal, 2,
27
+ basic_wl: '1..1',
28
+ basic: '1..1',
29
+ en16931: '1..1',
30
+ extended: '1..1'
31
+ ),
32
+ Facturx::TermDeclarations::Declaration.term(
33
+ 'BT-120', :tax_breakdown, :exemption_reason, 'BG-23',
34
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
35
+ '/ram:ApplicableTradeTax/ram:ExemptionReason',
36
+ :string, nil,
37
+ basic_wl: '0..1',
38
+ basic: '0..1',
39
+ en16931: '0..1',
40
+ extended: '0..1'
41
+ ),
42
+ Facturx::TermDeclarations::Declaration.term(
43
+ 'BT-116', :tax_breakdown, :basis_amount, 'BG-23',
44
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
45
+ '/ram:ApplicableTradeTax/ram:BasisAmount',
46
+ :decimal, 2,
47
+ basic_wl: '1..1',
48
+ basic: '1..1',
49
+ en16931: '1..1',
50
+ extended: '1..1'
51
+ ),
52
+ Facturx::TermDeclarations::Declaration.term(
53
+ 'BT-118', :tax_breakdown, :category_code, 'BG-23',
54
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
55
+ '/ram:ApplicableTradeTax/ram:CategoryCode',
56
+ :string, nil,
57
+ basic_wl: '1..1',
58
+ basic: '1..1',
59
+ en16931: '1..1',
60
+ extended: '1..1'
61
+ ),
62
+ Facturx::TermDeclarations::Declaration.term(
63
+ 'BT-121', :tax_breakdown, :exemption_reason_code, 'BG-23',
64
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
65
+ '/ram:ApplicableTradeTax/ram:ExemptionReasonCode',
66
+ :string, nil,
67
+ basic_wl: '0..1',
68
+ basic: '0..1',
69
+ en16931: '0..1',
70
+ extended: '0..1'
71
+ ),
72
+ Facturx::TermDeclarations::Declaration.term(
73
+ 'BT-8', :tax_breakdown, :due_date_type_code, 'BG-23',
74
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
75
+ '/ram:ApplicableTradeTax/ram:DueDateTypeCode',
76
+ :string, nil,
77
+ basic_wl: '0..1',
78
+ basic: '0..1',
79
+ en16931: '0..1',
80
+ extended: '0..1'
81
+ ),
82
+ Facturx::TermDeclarations::Declaration.term(
83
+ 'BT-119', :tax_breakdown, :rate, 'BG-23',
84
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
85
+ '/ram:ApplicableTradeTax/ram:RateApplicablePercent',
86
+ :decimal, nil,
87
+ basic_wl: '0..1',
88
+ basic: '0..1',
89
+ en16931: '0..1',
90
+ extended: '0..1'
91
+ )
92
+ ].freeze
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ Facturx::TermDeclarations::TOTALS = [
4
+ Facturx::TermDeclarations::Declaration.term(
5
+ 'BT-106', :totals, :line_total, 'BG-22',
6
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
7
+ '/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:LineTotalAmount',
8
+ :decimal, 2,
9
+ basic_wl: '1..1',
10
+ basic: '1..1',
11
+ en16931: '1..1',
12
+ extended: '1..1'
13
+ ),
14
+ Facturx::TermDeclarations::Declaration.term(
15
+ 'BT-108', :totals, :charge_total, 'BG-22',
16
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
17
+ '/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:ChargeTotalAmount',
18
+ :decimal, 2,
19
+ basic_wl: '0..1',
20
+ basic: '0..1',
21
+ en16931: '0..1',
22
+ extended: '0..1'
23
+ ),
24
+ Facturx::TermDeclarations::Declaration.term(
25
+ 'BT-107', :totals, :allowance_total, 'BG-22',
26
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
27
+ '/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:AllowanceTotalAmount',
28
+ :decimal, 2,
29
+ basic_wl: '0..1',
30
+ basic: '0..1',
31
+ en16931: '0..1',
32
+ extended: '0..1'
33
+ ),
34
+ Facturx::TermDeclarations::Declaration.term(
35
+ 'BT-109', :totals, :tax_basis_total, 'BG-22',
36
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
37
+ '/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxBasisTotalAmount',
38
+ :decimal, 2,
39
+ minimum: '1..1',
40
+ basic_wl: '1..1',
41
+ basic: '1..1',
42
+ en16931: '1..1',
43
+ extended: '1..1'
44
+ ),
45
+ Facturx::TermDeclarations::Declaration.term(
46
+ 'BT-110', :totals, :tax_total, 'BG-22',
47
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
48
+ '/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount',
49
+ :decimal, 2,
50
+ minimum: '0..1',
51
+ basic_wl: '0..1',
52
+ basic: '0..1',
53
+ en16931: '0..1',
54
+ extended: '0..1'
55
+ ),
56
+ Facturx::TermDeclarations::Declaration.term(
57
+ 'BT-111', :totals, :tax_total_in_tax_currency, 'BG-22',
58
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
59
+ '/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount',
60
+ :decimal, 2,
61
+ minimum: '0..1',
62
+ basic_wl: '0..1',
63
+ basic: '0..1',
64
+ en16931: '0..1',
65
+ extended: '0..1'
66
+ ),
67
+ Facturx::TermDeclarations::Declaration.term(
68
+ 'BT-114', :totals, :rounding, 'BG-22',
69
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
70
+ '/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:RoundingAmount',
71
+ :decimal, 2,
72
+ en16931: '0..1',
73
+ extended: '0..1'
74
+ ),
75
+ Facturx::TermDeclarations::Declaration.term(
76
+ 'BT-112', :totals, :grand_total, 'BG-22',
77
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
78
+ '/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:GrandTotalAmount',
79
+ :decimal, 2,
80
+ minimum: '1..1',
81
+ basic_wl: '1..1',
82
+ basic: '1..1',
83
+ en16931: '1..1',
84
+ extended: '1..1'
85
+ ),
86
+ Facturx::TermDeclarations::Declaration.term(
87
+ 'BT-113', :totals, :prepaid, 'BG-22',
88
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
89
+ '/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TotalPrepaidAmount',
90
+ :decimal, 2,
91
+ basic_wl: '0..1',
92
+ basic: '0..1',
93
+ en16931: '0..1',
94
+ extended: '0..1'
95
+ ),
96
+ Facturx::TermDeclarations::Declaration.term(
97
+ 'BT-115', :totals, :due_payable, 'BG-22',
98
+ '/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement' \
99
+ '/ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:DuePayableAmount',
100
+ :decimal, 2,
101
+ minimum: '1..1',
102
+ basic_wl: '1..1',
103
+ basic: '1..1',
104
+ en16931: '1..1',
105
+ extended: '1..1'
106
+ )
107
+ ].freeze
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturx
4
+ module Terms
5
+ REFERENCE_VERSION = 'Factur-X 1.09.2 / ZUGFeRD 2.5.2'
6
+ REFERENCE_FILES = {
7
+ minimum: ['Schema/0_Factur-X_1.09.2_MINIMUM/Factur-X_1.09.2_MINIMUM.xlsx',
8
+ '81c979b61ccfe9c4cdee2c8c346d094a41e0fe61656f6285f951f3e8bf94a32e'],
9
+ basic_wl: ['Schema/1_Factur-X_1.09.2_BASICWL/Factur-X_1.09.2_BASICWL.xlsx',
10
+ '21521b45ad32dad015019b3c53eaf751e90d94b6e62853cf22d6b9e2413b9d94'],
11
+ basic: ['Schema/2_Factur-X_1.09.2_BASIC/Factur-X_1.09.2_BASIC.xlsx',
12
+ '662955f7666c58c526b9c1e58730fe2824596381696e0999e184d63662b02a32'],
13
+ en16931: ['Schema/3_Factur-X_1.09.2_EN16931/Factur-X_1.09.2_EN16931.xlsx',
14
+ '306514903279bd1d425fe3280286d1441b811bfc8e031dab671129ff4495d049'],
15
+ extended: ['Schema/4_Factur-X_1.09.2_EXTENDED/Factur-X_1.09.2_EXTENDED.xlsx',
16
+ '80777478de352ab37e536b7e07e67ab5dc196cbbe700fe95326d61118f62cfd4'],
17
+ en16931_appendix: ['Documentation/6_Factur-X_1.09.2_ZUGFeRD_2.5.2_Technical_Appendix_Profile_EN16931.pdf',
18
+ 'b8c5a1a2f857418e3dacc1d3026aaa7b3cac7d385d7cfe1f37856fc994d55e53']
19
+ }.transform_values { |value| value.map(&:freeze).freeze }.freeze
20
+ end
21
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nokogiri'
4
+ require_relative 'term'
5
+ require_relative 'group'
6
+ require_relative 'terms/declaration'
7
+ require_relative 'terms/reference'
8
+ require_relative 'terms/declarations/document'
9
+ require_relative 'terms/declarations/parties'
10
+ require_relative 'terms/declarations/references'
11
+ require_relative 'terms/declarations/delivery'
12
+ require_relative 'terms/declarations/payment'
13
+ require_relative 'terms/declarations/taxes'
14
+ require_relative 'terms/declarations/adjustments'
15
+ require_relative 'terms/declarations/totals'
16
+ require_relative 'terms/declarations/lines'
17
+ require_relative 'terms/declarations/products'
18
+ require_relative 'terms/declarations/groups'
19
+
20
+ module Facturx
21
+ module Terms
22
+ PROFILE_TERM_COUNTS = { minimum: 22, basic_wl: 113, basic: 140, en16931: 184, extended: 184 }.freeze
23
+ TYPES = %i[string decimal date_102 boolean binary].freeze
24
+ SCALES = [nil, 2].freeze
25
+ CARDINALITIES = ['0..1', '1..1', '0..n', '1..n'].freeze
26
+ EMPTY_TERMS = [].freeze
27
+
28
+ ALL = [
29
+ *TermDeclarations::DOCUMENT,
30
+ *TermDeclarations::PARTIES,
31
+ *TermDeclarations::REFERENCES,
32
+ *TermDeclarations::DELIVERY,
33
+ *TermDeclarations::PAYMENT,
34
+ *TermDeclarations::TAXES,
35
+ *TermDeclarations::ADJUSTMENTS,
36
+ *TermDeclarations::TOTALS,
37
+ *TermDeclarations::LINES,
38
+ *TermDeclarations::PRODUCTS
39
+ ].freeze
40
+ GROUPS = TermDeclarations::GROUPS
41
+ BY_ID = ALL.to_h { |term| [term.id, term] }.freeze
42
+ GROUPS_BY_ID = GROUPS.to_h { |group| [group.id, group] }.freeze
43
+ TERMS_BY_PROFILE = PROFILE_TERM_COUNTS.keys.to_h do |profile_id|
44
+ [profile_id, ALL.select { |term| term.cardinalities.key?(profile_id) }.freeze]
45
+ end.freeze
46
+
47
+ module_function
48
+
49
+ def all
50
+ ALL
51
+ end
52
+
53
+ def groups
54
+ GROUPS
55
+ end
56
+
57
+ def fetch(id)
58
+ BY_ID.fetch(id.to_s)
59
+ end
60
+
61
+ def group(id)
62
+ GROUPS_BY_ID.fetch(id.to_s)
63
+ end
64
+
65
+ def for_profile(profile)
66
+ profile_id = profile.respond_to?(:id) ? profile.id : profile.to_sym
67
+ TERMS_BY_PROFILE.fetch(profile_id, EMPTY_TERMS)
68
+ end
69
+
70
+ def validate!
71
+ validate_uniqueness!
72
+ validate_registry_size!
73
+ validate_values!
74
+ validate_profile_counts!
75
+ end
76
+
77
+ def validate_uniqueness!
78
+ raise 'Factur-X term identifiers must be unique' unless BY_ID.size == ALL.size
79
+ raise 'Factur-X group identifiers must be unique' unless GROUPS_BY_ID.size == GROUPS.size
80
+ end
81
+
82
+ def validate_registry_size!
83
+ raise 'Factur-X EN16931 registry must contain 184 terms' unless ALL.size == 184
84
+ raise 'Factur-X EN16931 registry must contain 41 groups' unless GROUPS.size == 41
85
+ end
86
+
87
+ def validate_values!
88
+ raise 'Factur-X term type is unknown' unless ALL.all? { |term| TYPES.include?(term.type) }
89
+ raise 'Factur-X term scale is unknown' unless ALL.all? { |term| SCALES.include?(term.scale) }
90
+ raise 'Factur-X cardinality is unknown' unless cardinalities_valid?
91
+ end
92
+
93
+ def validate_profile_counts!
94
+ PROFILE_TERM_COUNTS.each do |profile_id, count|
95
+ raise "Factur-X #{profile_id} registry must contain #{count} terms" unless for_profile(profile_id).size == count
96
+ end
97
+ end
98
+
99
+ def cardinalities_valid?
100
+ (ALL + GROUPS).all? do |entry|
101
+ entry.cardinalities.values.all? { |cardinality| CARDINALITIES.include?(cardinality) }
102
+ end
103
+ end
104
+ private_class_method :validate_uniqueness!, :validate_registry_size!, :validate_values!, :validate_profile_counts!,
105
+ :cardinalities_valid?
106
+
107
+ validate!
108
+ end
109
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facturx
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/facturx.rb CHANGED
@@ -5,6 +5,13 @@ require 'facturx/error'
5
5
  require 'facturx/embedding'
6
6
  require 'facturx/profile'
7
7
  require 'facturx/profiles'
8
+ require 'facturx/term'
9
+ require 'facturx/group'
10
+ require 'facturx/terms'
11
+ require 'facturx/model'
12
+ require 'facturx/diagnostic'
13
+ require 'facturx/reading'
14
+ require 'facturx/coerce'
8
15
  require 'facturx/xml/verifier'
9
16
  require 'facturx/pdf/document'
10
17
  require 'facturx/pdf/inspector'
@@ -12,10 +19,13 @@ require 'facturx/pdf/extractor'
12
19
  require 'facturx/pdf/verifier'
13
20
  require 'facturx/composers/ghostscript'
14
21
  require 'facturx/attach'
22
+ require 'facturx/reader'
15
23
 
16
24
  module Facturx
17
25
  DEFAULT_ATTACHER = Attach.new
26
+ DEFAULT_READER = Reader.new
18
27
  private_constant :DEFAULT_ATTACHER
28
+ private_constant :DEFAULT_READER
19
29
 
20
30
  class << self
21
31
  def verify_xml(xml:)
@@ -30,5 +40,9 @@ module Facturx
30
40
  def extract_xml(pdf:)
31
41
  Pdf::Extractor.new.call(pdf).xml
32
42
  end
43
+
44
+ def read(source, on_unknown_profile: :fallback)
45
+ DEFAULT_READER.call(source, on_unknown_profile:)
46
+ end
33
47
  end
34
48
  end