Sha256: 1eda5b6236f4c998e30fdc8832fb9f6ea1dd74a138ef44bdb4e54f0de294f26c

Contents?: true

Size: 1.09 KB

Versions: 33

Compression:

Stored size: 1.09 KB

Contents

module Bankserv

  class Statement < ActiveRecord::Base
    
    has_many :transactions, :foreign_key => 'bankserv_statement_id'
  
    def self.store(string)
      options = Absa::Esd::Transmission::Document.hash_from_s(string)
      
      raise "Expected a document set" unless options[:type] == "document"
    
      client_code = options[:data][0][:data][0][:data][:client_code]
    
      statement = new
      statement.client_code = client_code
      statement.data = options
      statement.save!
      statement
    end
  
    def process!
      raise "Document already processed" if processed?
    
      recon_account_detail_records.each do |record|
        Bankserv::Transaction.create! data: record[:data], client_code: client_code, bankserv_statement_id: id
      end
    
      self.processed = true
      self.save
    end
  
    def recon_transmission_data
      data[:data][0][:data]
    end
  
    def recon_account_data
      recon_transmission_data[1][:data]
    end
  
    def recon_account_detail_records
      recon_account_data.select{|item| item[:type] == 'detail'}
    end
  
  end
  
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
bankserv-0.4.6 lib/bankserv/transmission/statement.rb
bankserv-0.4.5 lib/bankserv/transmission/statement.rb
bankserv-0.4.4 lib/bankserv/transmission/statement.rb
bankserv-0.4.3 lib/bankserv/transmission/statement.rb
bankserv-0.4.2 lib/bankserv/transmission/statement.rb
bankserv-0.4.1 lib/bankserv/transmission/statement.rb
bankserv-0.4.0 lib/bankserv/transmission/statement.rb
bankserv-0.3.9 lib/bankserv/transmission/statement.rb
bankserv-0.3.8 lib/bankserv/transmission/statement.rb
bankserv-0.3.7 lib/bankserv/transmission/statement.rb
bankserv-0.3.6 lib/bankserv/transmission/statement.rb
bankserv-0.3.5 lib/bankserv/transmission/statement.rb
bankserv-0.3.4 lib/bankserv/transmission/statement.rb
bankserv-0.3.3 lib/bankserv/transmission/statement.rb
bankserv-0.3.2 lib/bankserv/transmission/statement.rb
bankserv-0.3.1 lib/bankserv/transmission/statement.rb
bankserv-0.3.0 lib/bankserv/transmission/statement.rb
bankserv-0.2.9 lib/bankserv/transmission/statement.rb
bankserv-0.2.8 lib/bankserv/transmission/statement.rb
bankserv-0.2.7 lib/bankserv/transmission/statement.rb