diff --git a/app/models/bank_statement.rb b/app/models/bank_statement.rb index 942ae3907..e1d582f90 100644 --- a/app/models/bank_statement.rb +++ b/app/models/bank_statement.rb @@ -25,10 +25,16 @@ class BankStatement < ApplicationRecord bank_transactions.build(bt_params) end + prepare_dir self.import_file_path = "#{ENV['bank_statement_import_dir']}/#{Time.zone.now.to_formatted_s(:number)}.txt" File.open(import_file_path, 'w') { |f| f.write(th6_file.open.read) } end + def prepare_dir + dirname = ENV['bank_statement_import_dir'] + FileUtils.mkdir_p(dirname) unless File.directory?(dirname) + end + def parse_th6_row(row) return parse_th6_header(row) if row[4, 3].strip == '000' return if row[4, 3].strip == '999' # skip footer diff --git a/test/fixtures/files/bank_statement_test.txt b/test/fixtures/files/bank_statement_test.txt new file mode 100644 index 000000000..d3f561a7d --- /dev/null +++ b/test/fixtures/files/bank_statement_test.txt @@ -0,0 +1,7 @@ +VV 000689NL85RABO74981124931508051533 +VV 220150805 M NL85RABO7498112493EUR Algsaldo C 26397 +VV 12015080520890321MK NL85RABO7498112493EUR401NL93ABNA8027105943 Registrar Second Prepayment Invoice no.3131071 C 72055 +VV 12015080520890321MK NL85RABO7498112493EUR401NL93ABNA8027105943 eedirect Prepayment Invoice no. 13 C 480 +VV 12015080521042372MK NL85RABO7498112493EUR767EE021222121767323770 Line Suva 8 Arve nr 2015-01 D 55000 +VV 320150805 M NL85RABO7498112493EUR Lõppsaldo C 5417 +VV 999 176980 diff --git a/test/system/admin_area/bank_statement_test.rb b/test/system/admin_area/bank_statement_test.rb new file mode 100644 index 000000000..c95035a8d --- /dev/null +++ b/test/system/admin_area/bank_statement_test.rb @@ -0,0 +1,16 @@ +require 'application_system_test_case' + +class BankStatementTest < ApplicationSystemTestCase + setup do + sign_in users(:admin) + travel_to Time.zone.parse('2010-07-05 00:30:00') + end + + def test_import_statement + assert_difference 'BankStatement.count', 1 do + visit import_admin_bank_statements_path + attach_file 'Th6 file', Rails.root.join('test', 'fixtures', 'files', 'bank_statement_test.txt').to_s + click_link_or_button 'Save' + end + end +end