Module: Bankserv::Eft
Instance Attribute Summary collapse
-
#request_id ⇒ Object
This module is tightly coupled to the Debit and Credit class.
Class Method Summary collapse
Instance Method Summary collapse
- #build!(options) ⇒ Object
- #build_batch!(options) ⇒ Object
- #build_contra!(batch_id, options) ⇒ Object
- #build_standard!(batch_id, options) ⇒ Object
- #create_standard!(batch_id, options) ⇒ Object
- #has_test_work? ⇒ Boolean
- #has_work? ⇒ Boolean
- #next_batch_id ⇒ Object
- #partial_class_name ⇒ Object
Instance Attribute Details
#request_id ⇒ Object
This module is tightly coupled to the Debit and Credit class. Any change here will ripple down…
5 6 7 |
# File 'lib/bankserv/eft.rb', line 5 def request_id @request_id end |
Class Method Details
.for_reference(reference) ⇒ Object
84 85 86 |
# File 'lib/bankserv/eft.rb', line 84 def self.for_reference(reference) Debit.for_reference(reference) + Credit.for_reference(reference) end |
Instance Method Details
#build!(options) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/bankserv/eft.rb', line 7 def build!() @request_id = [:bankserv_request_id] [:batches].each do |batch| build_batch! batch end end |
#build_batch!(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bankserv/eft.rb', line 15 def build_batch!() batch_id = next_batch_id if self.partial_class_name == "Debit" build_standard!(batch_id, [:debit]) build_contra!(batch_id, [:credit]) else build_standard!(batch_id, [:credit]) build_contra!(batch_id, [:debit]) end end |
#build_contra!(batch_id, options) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bankserv/eft.rb', line 30 def build_contra!(batch_id, ) account_name = .delete(:account_name) account_type = .delete(:account_type) account_number = .delete(:account_number) branch_code = .delete(:branch_code) initials = .delete(:initials) id_number = .delete(:id_number) bank_account = BankAccount.create!(account_name: account_name, account_type: account_type, account_number: account_number, branch_code: branch_code, initials: initials) = .merge(record_type: "contra", batch_id: batch_id, bankserv_request_id: @request_id, bankserv_bank_account_id: bank_account.id) contra = new() contra.save! end |
#build_standard!(batch_id, options) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/bankserv/eft.rb', line 46 def build_standard!(batch_id, ) if .is_a? Array .each do |debit| create_standard!(batch_id, debit) end else create_standard!(batch_id, ) end end |
#create_standard!(batch_id, options) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bankserv/eft.rb', line 56 def create_standard!(batch_id, ) account_name = .delete(:account_name) account_type = .delete(:account_type) account_number = .delete(:account_number) branch_code = .delete(:branch_code) initials = .delete(:initials) id_number = .delete(:id_number) bank_account = BankAccount.create!(account_name: account_name, account_type: account_type, account_number: account_number, branch_code: branch_code, initials: initials) = .merge(record_type: "standard", batch_id: batch_id, bankserv_request_id: @request_id, bankserv_bank_account_id: bank_account.id) standard = new() standard.save! end |
#has_test_work? ⇒ Boolean
80 81 82 |
# File 'lib/bankserv/eft.rb', line 80 def has_test_work? unprocessed.select{|item| item.request.test?}.any? end |
#has_work? ⇒ Boolean
76 77 78 |
# File 'lib/bankserv/eft.rb', line 76 def has_work? unprocessed.select{|item| not item.request.test?}.any? end |
#next_batch_id ⇒ Object
72 73 74 |
# File 'lib/bankserv/eft.rb', line 72 def next_batch_id maximum('batch_id').nil? ? 1 : maximum('batch_id') + 1 end |
#partial_class_name ⇒ Object
26 27 28 |
# File 'lib/bankserv/eft.rb', line 26 def partial_class_name self.name.split("::")[-1] end |