...
 
Commits (3)
......@@ -26,8 +26,9 @@ end
post '/process' do
filename = params[:file][:filename]
file = params[:file][:tempfile]
iban = params[:iban]
content = file.read
attachment filename + '.v11'
CamtToV11.convert(content)
CamtToV11.convert(content, iban: iban)
end
#!/usr/bin/env ruby
require 'active_support/core_ext/hash/conversions'
#require 'pp'
require 'pp'
# Referenznummer (kann mehrfach auftauchen)
# BkToCstmrDbtCdtNtfctn.Ntfctn.Ntry.NtryDtls
......@@ -12,7 +12,7 @@ module CamtToV11
extend self
def convert(data)
def convert(data, opts)
doc = Hash.from_xml(data)
entries = doc['Document']['BkToCstmrDbtCdtNtfctn']['Ntfctn']['Ntry']
result = []
......@@ -32,6 +32,13 @@ module CamtToV11
#puts edetail
tp = detail['Refs']['Prtry']['Tp']
ref = detail['RmtInf']['Strd']['CdtrRefInf']['Ref']
puts '-'*80
pp detail
if opts[:iban]
related_parties = detail['RltdPties']
debitor_account = related_parties && related_parties['DbtrAcct']
iban = debitor_account && debitor_account['Id']['IBAN']
end
amount = (detail['Amt'].to_f * 100).to_i
tmp = detail['Refs']['Prtry']['Ref']
dat1 = tmp.slice(2,6)
......@@ -49,7 +56,7 @@ module CamtToV11
cost = (charges['TtlChrgsAndTaxAmt'].to_f * 100).to_i
end
result << "%1s%2s%9s%27s%010d%10s%6s%6s%6s%9s%1s%9s%04d" %
rline = "%1s%2s%9s%27s%010d%10s%6s%6s%6s%9s%1s%9s%04d" %
[0,
tp,
entry_ref,
......@@ -63,6 +70,9 @@ module CamtToV11
reject_code,
'0' * 9,
cost]
rline += " #{iban}" if opts[:iban]
result << rline
end
end
......@@ -86,5 +96,5 @@ end
if $0 == __FILE__
file = ARGV.first
xml = open(file).read
puts CamtToV11.convert(xml)
puts CamtToV11.convert(xml, iban: true)
end
......@@ -22,6 +22,7 @@
<h2>upload camt, download v11</h2>
<form action="/process" method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<label><input type="checkbox" name="iban">+iban</label>
<br/>
<br/>
<input type="submit" value="Uffeladde">
......