zipdatev 0.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93a524d3a6c114e4ba449add730c39e4db83007ff043ef1b0e734786b4f56c1f
4
- data.tar.gz: be5eb61e54fb13aca8fc308286c6ca02b5302f1663217b5470770e4e7fe786be
3
+ metadata.gz: d6ce4539843ac8f2840887a89f59845cd0be78851e3716319542599dd49277ba
4
+ data.tar.gz: 4585e899c3328ce71283cc56f617b1bb5e5bb60d95dab358a5e730f52a263810
5
5
  SHA512:
6
- metadata.gz: 3637481aa9773fcdc5458ecbdced141d9fa817fc6098df825b6e395fcee5fa0f92ce33ab18d6bef5d8d499f037a19f691f5f4873b44bee233c4280393c6c973b
7
- data.tar.gz: 87d7e721150ac9771e7ec9bc20d1c7a2569a2c9736cd30ff9b8b071e269571b30f8c8dda538436155b06f54d0eb1889523fb09ed8adbd85d06cadb8fa806148e
6
+ metadata.gz: bc7772d543e0fab287ec9123946a95f0785512320f5d90916d7d1e64419f4b4547633e68e02c755fe8fefee22eb7c99e6603bf0ef1d5513552dc184b043738c0
7
+ data.tar.gz: 37f4b06a40a5ba78d4a14d6f0dd5a1d2dbdd506db055fa3cbcc9fb92b51747d565caa216bb557eb84f30e56225d680cdfcea36ccacbee631a237a298f808eb97
@@ -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}
@@ -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
@@ -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
- xml.document do
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
 
@@ -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
@@ -62,7 +62,7 @@ module ZipDatev
62
62
 
63
63
  record.errors.add(
64
64
  :base,
65
- "All line items must have the same date, found: #{dates.map(&:to_s).join(", ")}"
65
+ "All line items must have the same date, found: #{dates.join(", ")}"
66
66
  )
67
67
  end
68
68
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZipDatev
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipdatev
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dexter Team