lib/aba/batch.rb in aba-0.5.0 vs lib/aba/batch.rb in aba-1.0.0
- old
+ new
@@ -163,18 +163,19 @@
# Char position: 81-120
output += " " * 40
end
def batch_control_record
- net_total_amount = 0
credit_total_amount = 0
debit_total_amount = 0
- entries.each do |t|
- net_total_amount += t.amount.to_i
- credit_total_amount += t.amount.to_i if t.amount.to_i > 0
- debit_total_amount += t.amount.to_i if t.amount.to_i < 0
+ entries.each do |entry|
+ if entry.debit?
+ debit_total_amount += Integer(entry.amount).abs
+ else
+ credit_total_amount += Integer(entry.amount).abs
+ end
end
# Record type
# Max: 1
# Char position: 1
@@ -191,20 +192,20 @@
output += " " * 12
# Net total
# Max: 10
# Char position: 21-30
- output += net_total_amount.abs.to_s.rjust(10, "0")
+ output += (credit_total_amount - debit_total_amount).abs.to_s.rjust(10, "0")
# Credit Total Amount
# Max: 10
# Char position: 31-40
- output += credit_total_amount.abs.to_s.rjust(10, "0")
+ output += credit_total_amount.to_s.rjust(10, "0")
# Debit Total Amount
# Max: 10
# Char position: 41-50
- output += debit_total_amount.abs.to_s.rjust(10, "0")
+ output += debit_total_amount.to_s.rjust(10, "0")
# Reserved
# Max: 24
# Char position: 51-74
output += " " * 24