mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Merge pull request #1554 from internetee/1551-import-bank-statement
Create bank statement export dir if not present
This commit is contained in:
commit
33881951a6
3 changed files with 29 additions and 0 deletions
|
@ -25,10 +25,16 @@ class BankStatement < ApplicationRecord
|
||||||
bank_transactions.build(bt_params)
|
bank_transactions.build(bt_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
prepare_dir
|
||||||
self.import_file_path = "#{ENV['bank_statement_import_dir']}/#{Time.zone.now.to_formatted_s(:number)}.txt"
|
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) }
|
File.open(import_file_path, 'w') { |f| f.write(th6_file.open.read) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prepare_dir
|
||||||
|
dirname = ENV['bank_statement_import_dir']
|
||||||
|
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
||||||
|
end
|
||||||
|
|
||||||
def parse_th6_row(row)
|
def parse_th6_row(row)
|
||||||
return parse_th6_header(row) if row[4, 3].strip == '000'
|
return parse_th6_header(row) if row[4, 3].strip == '000'
|
||||||
return if row[4, 3].strip == '999' # skip footer
|
return if row[4, 3].strip == '999' # skip footer
|
||||||
|
|
7
test/fixtures/files/bank_statement_test.txt
vendored
Normal file
7
test/fixtures/files/bank_statement_test.txt
vendored
Normal file
|
@ -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
|
16
test/system/admin_area/bank_statement_test.rb
Normal file
16
test/system/admin_area/bank_statement_test.rb
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue