achtools

Adding initial version of ACH Effective Date Totals script.
draft default tip
2018-06-04, John Bailey
74c3553591cf
Adding initial version of ACH Effective Date Totals script.
"""ach-eff-tot.py - Produce a report detailing ACH totals by effective date."""
import sys
def read_ach_file(filename):
"""Reads the ACH file specified by filename."""
achfile = open(filename, 'r')
lines = achfile.readlines()
achfile.close()
return lines
def start():
"""Performs actual processing."""
lines = read_ach_file(sys.argv[1])
linecount = len(lines)
i = 0
totalcr = {}
totaldr = {}
while i < linecount:
if (lines[i])[0] == '5': # batch header record
bcr = 0
bdr = 0
j = i + 1
# batch effective date - reformat into MM/DD/YY format
bdt = '{}/{}/{}'.format((lines[i])[71:73], (lines[i])[73:75],
(lines[i])[69:71])
odt = (lines[i])[69:75]
while j < linecount:
if (lines[j])[0] == '8': # batch control record
bdr = float((lines[j])[20:32]) / 100 # batch total debits
bcr = float((lines[j])[32:44]) / 100 # batch total credits
i = j # outer loop will go to next batch
break # end this loop
j = j + 1
if bdt in totalcr:
totalcr[bdt] = totalcr[bdt] + bcr
else:
totalcr[bdt] = bcr
if bdt in totaldr:
totaldr[bdt] = totaldr[bdt] + bdr
else:
totaldr[bdt] = bdr
i = i + 1
print("Filename:\t{}\n-------------------------------\n".format(sys.argv[1]))
print ("Total Debits by Effective Date:")
for key in totaldr:
print("{}\t{:.2f}".format(key, totaldr[key]))
print("-------------------------------")
print ("Total Credits by Effective Date:")
for key in totalcr:
print("{}\t{:.2f}".format(key, totalcr[key]))
print("\n")
start()