zipdatev 0.1.0 → 0.1.2
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/lib/zipdatev/constants.rb +4 -0
- data/lib/zipdatev/document.rb +12 -2
- data/lib/zipdatev/generators/base.rb +8 -1
- data/lib/zipdatev/generators/document_xml.rb +4 -1
- data/lib/zipdatev/package.rb +4 -2
- data/lib/zipdatev/validators/consolidation_validator.rb +1 -1
- data/lib/zipdatev/validators/decimal_precision_validator.rb +3 -3
- data/lib/zipdatev/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: d6ce4539843ac8f2840887a89f59845cd0be78851e3716319542599dd49277ba
|
|
4
|
+
data.tar.gz: 4585e899c3328ce71283cc56f617b1bb5e5bb60d95dab358a5e730f52a263810
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc7772d543e0fab287ec9123946a95f0785512320f5d90916d7d1e64419f4b4547633e68e02c755fe8fefee22eb7c99e6603bf0ef1d5513552dc184b043738c0
|
|
7
|
+
data.tar.gz: 37f4b06a40a5ba78d4a14d6f0dd5a1d2dbdd506db055fa3cbcc9fb92b51747d565caa216bb557eb84f30e56225d680cdfcea36ccacbee631a237a298f808eb97
|
data/lib/zipdatev/constants.rb
CHANGED
|
@@ -71,6 +71,10 @@ module ZipDatev
|
|
|
71
71
|
ZA ZM ZW
|
|
72
72
|
].freeze
|
|
73
73
|
|
|
74
|
+
# Pattern for GUID/UUID: 8-4-4-4-12 hex digits (RFC 4122)
|
|
75
|
+
# From XSD p10037: [0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}
|
|
76
|
+
GUID_PATTERN = /\A[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\z/
|
|
77
|
+
|
|
74
78
|
# Pattern for invoice ID: alphanumeric + $%&*+-/
|
|
75
79
|
# From XSD p10040: [a-zA-Z0-9$%&*+-/]{0,36}
|
|
76
80
|
INVOICE_ID_PATTERN = %r{\A[a-zA-Z0-9$%&*+\-/]{0,36}\z}
|
data/lib/zipdatev/document.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "active_model"
|
|
4
|
+
require_relative "constants"
|
|
4
5
|
|
|
5
6
|
module ZipDatev
|
|
6
7
|
# Represents a document entry in the DATEV package.
|
|
@@ -20,19 +21,21 @@ module ZipDatev
|
|
|
20
21
|
include ActiveModel::Model
|
|
21
22
|
include ActiveModel::Validations
|
|
22
23
|
|
|
23
|
-
attr_accessor :invoice, :attachments, :invoice_month, :folder_name, :repository
|
|
24
|
+
attr_accessor :invoice, :attachments, :invoice_month, :folder_name, :repository, :guid
|
|
24
25
|
|
|
25
26
|
# Validations
|
|
26
27
|
validates :invoice, presence: true
|
|
27
28
|
validate :invoice_must_be_valid
|
|
28
29
|
validate :attachments_must_exist
|
|
30
|
+
validate :guid_must_be_valid_format
|
|
29
31
|
|
|
30
|
-
def initialize(invoice: nil, attachments: [], invoice_month: nil, folder_name: nil, repository: nil)
|
|
32
|
+
def initialize(invoice: nil, attachments: [], invoice_month: nil, folder_name: nil, repository: nil, guid: nil)
|
|
31
33
|
@invoice = invoice
|
|
32
34
|
@attachments = attachments || []
|
|
33
35
|
@invoice_month = invoice_month
|
|
34
36
|
@folder_name = folder_name
|
|
35
37
|
@repository = repository
|
|
38
|
+
@guid = guid
|
|
36
39
|
end
|
|
37
40
|
|
|
38
41
|
private
|
|
@@ -56,5 +59,12 @@ module ZipDatev
|
|
|
56
59
|
errors.add(:attachments, "file not found: #{path}")
|
|
57
60
|
end
|
|
58
61
|
end
|
|
62
|
+
|
|
63
|
+
def guid_must_be_valid_format
|
|
64
|
+
return if guid.blank?
|
|
65
|
+
return if guid.match?(Constants::GUID_PATTERN)
|
|
66
|
+
|
|
67
|
+
errors.add(:guid, "must be a valid GUID (RFC 4122 format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)")
|
|
68
|
+
end
|
|
59
69
|
end
|
|
60
70
|
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "bigdecimal"
|
|
3
4
|
require "nokogiri"
|
|
4
5
|
require "active_support/core_ext/string/inflections"
|
|
5
6
|
|
|
@@ -82,13 +83,19 @@ module ZipDatev
|
|
|
82
83
|
|
|
83
84
|
# Format a decimal value for XML output with specified precision
|
|
84
85
|
#
|
|
86
|
+
# Uses BigDecimal's string representation to avoid floating point artifacts
|
|
87
|
+
# from format()/sprintf(), which implicitly convert BigDecimal to Float.
|
|
88
|
+
#
|
|
85
89
|
# @param value [BigDecimal, Numeric, nil] The value to format
|
|
86
90
|
# @param precision [Integer] Number of decimal places (default: 2)
|
|
87
91
|
# @return [String, nil] Formatted decimal string or nil if value is nil
|
|
88
92
|
def format_decimal(value, precision: 2)
|
|
89
93
|
return nil if value.nil?
|
|
90
94
|
|
|
91
|
-
|
|
95
|
+
decimal = value.is_a?(BigDecimal) ? value : BigDecimal(value.to_s)
|
|
96
|
+
str = decimal.round(precision).to_s("F")
|
|
97
|
+
integer_part, fractional_part = str.split(".")
|
|
98
|
+
"#{integer_part}.#{(fractional_part || "").ljust(precision, "0")}"
|
|
92
99
|
end
|
|
93
100
|
|
|
94
101
|
# Convert a Ruby snake_case symbol to XML camelCase element name
|
|
@@ -79,7 +79,10 @@ module ZipDatev
|
|
|
79
79
|
|
|
80
80
|
# Generate a document element for a single document
|
|
81
81
|
def generate_document(xml, document)
|
|
82
|
-
|
|
82
|
+
attrs = {}
|
|
83
|
+
attrs["guid"] = document.guid if document.guid.present?
|
|
84
|
+
|
|
85
|
+
xml.document(attrs) do
|
|
83
86
|
# Generate ledger extension (accountsPayableLedger)
|
|
84
87
|
generate_ledger_extension(xml, document)
|
|
85
88
|
|
data/lib/zipdatev/package.rb
CHANGED
|
@@ -47,14 +47,16 @@ module ZipDatev
|
|
|
47
47
|
# @param invoice_month [String] Invoice month in "YYYY-MM" format
|
|
48
48
|
# @param folder_name [String] Folder name for filing
|
|
49
49
|
# @param repository [Repository, nil] Optional repository structure
|
|
50
|
+
# @param guid [String, nil] Optional GUID (RFC 4122) for the document element
|
|
50
51
|
# @return [Document] The created document
|
|
51
|
-
def add_document(invoice:, attachments: [], invoice_month: nil, folder_name: nil, repository: nil)
|
|
52
|
+
def add_document(invoice:, attachments: [], invoice_month: nil, folder_name: nil, repository: nil, guid: nil)
|
|
52
53
|
document = Document.new(
|
|
53
54
|
invoice: invoice,
|
|
54
55
|
attachments: attachments,
|
|
55
56
|
invoice_month: invoice_month,
|
|
56
57
|
folder_name: folder_name,
|
|
57
|
-
repository: repository
|
|
58
|
+
repository: repository,
|
|
59
|
+
guid: guid
|
|
58
60
|
)
|
|
59
61
|
@documents << document
|
|
60
62
|
document
|
|
@@ -36,9 +36,9 @@ class DecimalPrecisionValidator < ActiveModel::EachValidator
|
|
|
36
36
|
# Convert to BigDecimal for consistent handling
|
|
37
37
|
decimal = value.is_a?(BigDecimal) ? value : BigDecimal(value.to_s)
|
|
38
38
|
|
|
39
|
-
# Use string representation to
|
|
40
|
-
#
|
|
41
|
-
str =
|
|
39
|
+
# Use BigDecimal's string representation to avoid floating point artifacts
|
|
40
|
+
# BigDecimal#to_s("F") returns a fixed-point string like "12691.72"
|
|
41
|
+
str = decimal.to_s("F")
|
|
42
42
|
parts = str.split(".")
|
|
43
43
|
|
|
44
44
|
return places.zero? if parts.length == 1
|
data/lib/zipdatev/version.rb
CHANGED