secretariat 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6d3c5177f9a94e1341b1b533cfe34b91f9babe7eafa5d483cbf4b5f489509c0
4
- data.tar.gz: d51e684d34ac4fc61007cd6243c26cc8cfd31df95799b39079841d6e23b352f8
3
+ metadata.gz: 78a5b530fb987800431c180f91436cd9d538ed364f478aa17ddee805e85fc2f3
4
+ data.tar.gz: c4d569c8923b971e91eb5d1862f1e8484ddaf402cb62b6e405c4bee24ba2518f
5
5
  SHA512:
6
- metadata.gz: a1c7ea742126169c1b97b0ce347d8d7f6830f5eabb5542b814ae9313c9a0c4d904076124fccd18a182e217ce1a4e87008bc6e5350f7f53b562fee8795855486e
7
- data.tar.gz: f228bac7b78241d5437b61fb1d9505c0ebb2ed2608f7489cf5145da34a662b5efd50a87090cf3b9ca27af9e2af6708865e3cf7039e0c466fc48711f3347017cb
6
+ metadata.gz: 7dbdd370a0790c03b4f2fdbbefa16c3653e5554236e97b25eb7ff778ec1253a57e1323166ada9e8010fd5b47266ceee0bfc5e3c4e0f4d31a98f8ffd2d417f5d1
7
+ data.tar.gz: 61c934e0e8994226b61ad2780695c610d86000265cb0e95478d994f3740143f5849c3662be0fe2e8754cc5ef02aff1176f2e7753a5036437cb087a39d833fb56
@@ -15,5 +15,12 @@ module Secretariat
15
15
  xml.text(format(amount, round: 4, digits: digits))
16
16
  end
17
17
  end
18
+
19
+ def self.date_element(xml, date)
20
+ date = date.strftime("%Y%m%d") if date.respond_to?(:strftime)
21
+ xml['udt'].DateTimeString(format: '102') do
22
+ xml.text(date)
23
+ end
24
+ end
18
25
  end
19
26
  end
@@ -20,12 +20,18 @@ module Secretariat
20
20
  Invoice = Struct.new("Invoice",
21
21
  :id,
22
22
  :issue_date,
23
+ :service_period_start,
24
+ :service_period_end,
23
25
  :seller,
24
26
  :buyer,
27
+ :buyer_reference,
25
28
  :line_items,
26
29
  :currency_code,
27
30
  :payment_type,
28
31
  :payment_text,
32
+ :payment_terms_text,
33
+ :payment_due_date,
34
+ :payment_iban,
29
35
  :tax_category,
30
36
  :tax_percent,
31
37
  :tax_amount,
@@ -104,12 +110,12 @@ module Secretariat
104
110
  )
105
111
  end
106
112
 
107
- def to_xml(version: 1)
113
+ def to_xml(version: 1, validate: true)
108
114
  if version < 1 || version > 2
109
115
  raise 'Unsupported Document Version'
110
116
  end
111
117
 
112
- unless valid?
118
+ if validate && !valid?
113
119
  raise ValidationError.new("Invoice is invalid", errors)
114
120
  end
115
121
 
@@ -141,19 +147,23 @@ module Secretariat
141
147
  xml.text(issue_date.strftime("%Y%m%d"))
142
148
  end
143
149
  end
150
+
144
151
  end
145
152
  transaction = by_version(version, 'SpecifiedSupplyChainTradeTransaction', 'SupplyChainTradeTransaction')
146
153
  xml['rsm'].send(transaction) do
147
154
 
148
155
  if version == 2
149
156
  line_items.each_with_index do |item, i|
150
- item.to_xml(xml, i + 1, version: version) # one indexed
157
+ item.to_xml(xml, i + 1, version: version, validate: validate) # one indexed
151
158
  end
152
159
  end
153
160
 
154
161
  trade_agreement = by_version(version, 'ApplicableSupplyChainTradeAgreement', 'ApplicableHeaderTradeAgreement')
155
162
 
156
163
  xml['ram'].send(trade_agreement) do
164
+ if buyer_reference
165
+ xml['ram'].BuyerReference buyer_reference
166
+ end
157
167
  xml['ram'].SellerTradeParty do
158
168
  seller.to_xml(xml, version: version)
159
169
  end
@@ -184,6 +194,11 @@ module Secretariat
184
194
  xml['ram'].SpecifiedTradeSettlementPaymentMeans do
185
195
  xml['ram'].TypeCode payment_code
186
196
  xml['ram'].Information payment_text
197
+ if payment_iban
198
+ xml['ram'].PayeePartyCreditorFinancialAccount do
199
+ xml['ram'].IBANID payment_iban
200
+ end
201
+ end
187
202
  end
188
203
  xml['ram'].ApplicableTradeTax do
189
204
 
@@ -198,8 +213,23 @@ module Secretariat
198
213
  percent = by_version(version, 'ApplicablePercent', 'RateApplicablePercent')
199
214
  xml['ram'].send(percent, Helpers.format(tax_percent))
200
215
  end
216
+ if version == 2 && service_period_start && service_period_end
217
+ xml['ram'].BillingSpecifiedPeriod do
218
+ xml['ram'].StartDateTime do
219
+ Helpers.date_element(xml, service_period_start)
220
+ end
221
+ xml['ram'].EndDateTime do
222
+ Helpers.date_element(xml, service_period_end)
223
+ end
224
+ end
225
+ end
201
226
  xml['ram'].SpecifiedTradePaymentTerms do
202
- xml['ram'].Description "Paid"
227
+ xml['ram'].Description payment_terms_text || "Paid"
228
+ if payment_due_date
229
+ xml['ram'].DueDateDateTime do
230
+ Helpers.date_element(xml, payment_due_date)
231
+ end
232
+ end
203
233
  end
204
234
 
205
235
  monetary_summation = by_version(version, 'SpecifiedTradeSettlementMonetarySummation', 'SpecifiedTradeSettlementHeaderMonetarySummation')
@@ -84,8 +84,8 @@ module Secretariat
84
84
  TAX_CATEGORY_CODES[tax_category] || 'S'
85
85
  end
86
86
 
87
- def to_xml(xml, line_item_index, version: 2)
88
- if !valid?
87
+ def to_xml(xml, line_item_index, version: 2, validate: true)
88
+ if validate && !valid?
89
89
  pp errors
90
90
  raise ValidationError.new("LineItem #{line_item_index} is invalid", errors)
91
91
  end
@@ -15,8 +15,13 @@ limitations under the License.
15
15
  =end
16
16
 
17
17
  require 'nokogiri'
18
+ require 'tmpdir'
18
19
 
19
20
  module Secretariat
21
+
22
+ class ValidatorError < StandardError; end
23
+
24
+
20
25
  class Validator
21
26
  SCHEMATRON = [
22
27
  '../../schemas/zugferd_1/ZUGFeRD1p0.sch',
@@ -55,10 +60,27 @@ module Secretariat
55
60
  Dir.mktmpdir do |dir|
56
61
  docpath = File.join(dir, 'doc.xml')
57
62
  File.write(docpath, doc, mode: 'wb')
58
- out = `java -jar bin/schxslt-cli.jar -v -d #{docpath} -s #{schematron_path}`
59
- return [] if out.match("[valid]")
60
- out.lines
63
+ jarpath = File.join(__dir__, '../..', 'bin', 'schxslt-cli.jar')
64
+ out = `java -jar #{jarpath} -v -d #{docpath} -s #{schematron_path}`
65
+ return [] if out.start_with?("[valid]")
66
+ return process_schematron_errors(out)
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def process_schematron_errors(output)
73
+ errors = []
74
+ error_lines = output.lines.clone
75
+ error_lines.shift # get rid of file notice
76
+
77
+ while(error_lines.length > 0) do
78
+ assert_error = error_lines.shift
79
+ _, ref = assert_error.split(" failed-assert ").map(&:strip)
80
+ error_description = error_lines.shift.strip
81
+ errors << ValidatorError.new("#{error_description} - Reference: #{ref}")
61
82
  end
83
+ errors
62
84
  end
63
85
  end
64
86
  end
@@ -15,5 +15,5 @@ limitations under the License.
15
15
  =end
16
16
 
17
17
  module Secretariat
18
- VERSION = '3.0.0'
18
+ VERSION = '3.1.0'
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secretariat
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Krutisch