parent
3baea9331e
commit
df96574a98
@ -0,0 +1,87 @@ |
||||
import os |
||||
import pandas as pd |
||||
from datetime import datetime as dt, timedelta |
||||
import sys, getopt |
||||
import re |
||||
from pathlib import Path |
||||
import time |
||||
from pprint import pprint as prt |
||||
|
||||
contract_number_regex = "\d{3}-\d{7}-\d{3}" |
||||
|
||||
def create_line_divider(breakage_list: list): |
||||
""" |
||||
This allows for the creation of a custom data extractor |
||||
Breakage list defines the split points that will be used for the line |
||||
Example |
||||
Given breakage_list [10, 20, 30] |
||||
using slot_num 0 in the resulting extract_line_slot will yield |
||||
characters 0 - 10 from the string. |
||||
Slot 1 would give characters 10 - 20 |
||||
""" |
||||
def extract_line_slot(slot_num : int, line_string: str, debug : bool = False): |
||||
""" |
||||
Pulls data from a line/string using break points defined by the |
||||
parent function. |
||||
ONLY USE THIS FUNCTION THROUGH CREATION USING 'create_line_extractor' |
||||
Will automatically convert numbers to floats |
||||
""" |
||||
assert(slot_num < len(breakage_list)+1) |
||||
low_range = 0 if slot_num == 0 else breakage_list[slot_num-1] |
||||
high_range = len(line_string) if slot_num == len(breakage_list) else breakage_list[slot_num] |
||||
data = line_string[low_range:high_range].strip().replace(",", "") |
||||
try: data = float(data) |
||||
except: pass |
||||
if debug: |
||||
print(f"Slot num: {slot_num} | Low: {low_range} | High: {high_range} | Data: {data}") |
||||
return data |
||||
return extract_line_slot |
||||
|
||||
|
||||
def ach(report: str, save_name: str): |
||||
|
||||
lines = report.splitlines() |
||||
extracted_data_dict = { |
||||
"ContractNumber" : [], |
||||
"CustomerName" : [], |
||||
"BankCode" : [], |
||||
"BankNumber": [], |
||||
"AccountNumber" : [], |
||||
"Payment" : [], |
||||
"Batch": [], |
||||
"Lessor": [], |
||||
"PaymentDate": [], |
||||
} |
||||
columns = list(extracted_data_dict.keys()) |
||||
batches = { |
||||
"batch_num": [], |
||||
"payment_date": [], |
||||
"lessor": [], |
||||
"count": [], |
||||
"total": [] |
||||
} |
||||
|
||||
data_extractor = create_line_divider([19,57,67,82,104]) |
||||
bank_number_regex = "\d{9}" |
||||
batch_num_regex = "BATCH \d{4} TOTAL" |
||||
for line in enumerate(lines): |
||||
if (re.search(contract_number_regex, line[1]) != None) & (re.search(bank_number_regex, line[1]) != None): |
||||
[extracted_data_dict[columns[c]].append(data_extractor(c, line[1])) for c in range(0, len(columns)-3)] |
||||
if re.search(batch_num_regex, line[1]) != None: |
||||
batches["batch_num"].append(line[1][96:101]) |
||||
batches["payment_date"].append(lines[line[0]+2][114:125]) |
||||
batches["lessor"].append(extracted_data_dict["ContractNumber"][-1][0:3]) |
||||
batches["total"].append(float(line[1][107:125].strip().replace(",", ""))) |
||||
batches["count"].append(float(lines[line[0]+6][107:125].strip().replace(",", ""))) |
||||
[extracted_data_dict["Batch"].append(batches["batch_num"][-1]) for _ in range(0, (len(extracted_data_dict["BankCode"]) - len(extracted_data_dict["Batch"])))] |
||||
[extracted_data_dict["Lessor"].append(batches["lessor"][-1]) for _ in range(0, (len(extracted_data_dict["BankCode"]) - len(extracted_data_dict["Lessor"])))] |
||||
[extracted_data_dict["PaymentDate"].append(batches["payment_date"][-1]) for _ in range(0, (len(extracted_data_dict["BankCode"]) - len(extracted_data_dict["PaymentDate"])))] |
||||
|
||||
dataframe = pd.DataFrame(extracted_data_dict) |
||||
|
||||
return dataframe |
||||
|
||||
with open("/config/workspace/LEAF/IL Extract SRC/2022.05.04_ACH_C") as rep_file: |
||||
report = rep_file.read() |
||||
|
||||
prt(ach(report, "ACH_TESTING.xlsx")) |
||||
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 512 B |
@ -0,0 +1,268 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>MainWindow</class> |
||||
<widget class="QMainWindow" name="MainWindow"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>1001</width> |
||||
<height>664</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>MainWindow</string> |
||||
</property> |
||||
<widget class="QWidget" name="centralwidget"> |
||||
<widget class="QTextBrowser" name="inputFilePreview"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>20</x> |
||||
<y>220</y> |
||||
<width>951</width> |
||||
<height>391</height> |
||||
</rect> |
||||
</property> |
||||
</widget> |
||||
<widget class="QPushButton" name="processReportButton"> |
||||
<property name="enabled"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>20</x> |
||||
<y>180</y> |
||||
<width>250</width> |
||||
<height>36</height> |
||||
</rect> |
||||
</property> |
||||
<property name="text"> |
||||
<string>&Process Report</string> |
||||
</property> |
||||
</widget> |
||||
<widget class="QPushButton" name="openReportButton"> |
||||
<property name="enabled"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>280</x> |
||||
<y>180</y> |
||||
<width>241</width> |
||||
<height>36</height> |
||||
</rect> |
||||
</property> |
||||
<property name="text"> |
||||
<string>&Copy to Clipboard</string> |
||||
</property> |
||||
</widget> |
||||
<widget class="QWidget" name="layoutWidget"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>21</x> |
||||
<y>90</y> |
||||
<width>951</width> |
||||
<height>84</height> |
||||
</rect> |
||||
</property> |
||||
<layout class="QVBoxLayout" name="fileSettingsBox"> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="inputFileBox"> |
||||
<item> |
||||
<widget class="QPushButton" name="inputFileButton"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>250</width> |
||||
<height>0</height> |
||||
</size> |
||||
</property> |
||||
<property name="maximumSize"> |
||||
<size> |
||||
<width>250</width> |
||||
<height>36</height> |
||||
</size> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Select &InfoLease Report</string> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset> |
||||
<normaloff>../../.designer/backup/Pictures/svgs/folder.svg</normaloff>../../.designer/backup/Pictures/svgs/folder.svg</iconset> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLineEdit" name="inputFileLE"> |
||||
<property name="readOnly"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="placeholderText"> |
||||
<string>No file selected</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="outFileLocation"> |
||||
<item> |
||||
<widget class="QPushButton" name="outputFileButton"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>250</width> |
||||
<height>0</height> |
||||
</size> |
||||
</property> |
||||
<property name="maximumSize"> |
||||
<size> |
||||
<width>250</width> |
||||
<height>36</height> |
||||
</size> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Select &Report Output Location</string> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset> |
||||
<normaloff>../../.designer/backup/Pictures/svgs/folder.svg</normaloff>../../.designer/backup/Pictures/svgs/folder.svg</iconset> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLineEdit" name="outputFileLE"> |
||||
<property name="readOnly"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="placeholderText"> |
||||
<string>No location selected</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<widget class="QComboBox" name="reportTypeCB"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>21</x> |
||||
<y>51</y> |
||||
<width>250</width> |
||||
<height>37</height> |
||||
</rect> |
||||
</property> |
||||
<item> |
||||
<property name="text"> |
||||
<string>ACH</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Disposition</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Gain Loss</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Lock Box</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Minv_C</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Net Inv. Loans</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>NI Renewal</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>NIV After</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>PBP / Epay</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Returned Check</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Unapplied</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>VMCC</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Wires</string> |
||||
</property> |
||||
</item> |
||||
</widget> |
||||
<widget class="QLabel" name="reportTypeL"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>21</x> |
||||
<y>21</y> |
||||
<width>144</width> |
||||
<height>24</height> |
||||
</rect> |
||||
</property> |
||||
<property name="font"> |
||||
<font> |
||||
<pointsize>14</pointsize> |
||||
<weight>75</weight> |
||||
<bold>true</bold> |
||||
</font> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Infolease Report</string> |
||||
</property> |
||||
<property name="buddy"> |
||||
<cstring>reportTypeCB</cstring> |
||||
</property> |
||||
</widget> |
||||
</widget> |
||||
<widget class="QMenuBar" name="menubar"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>1001</width> |
||||
<height>29</height> |
||||
</rect> |
||||
</property> |
||||
</widget> |
||||
<widget class="QStatusBar" name="statusbar"/> |
||||
</widget> |
||||
<tabstops> |
||||
<tabstop>reportTypeCB</tabstop> |
||||
<tabstop>inputFileButton</tabstop> |
||||
<tabstop>outputFileButton</tabstop> |
||||
<tabstop>processReportButton</tabstop> |
||||
<tabstop>openReportButton</tabstop> |
||||
<tabstop>inputFileLE</tabstop> |
||||
<tabstop>outputFileLE</tabstop> |
||||
<tabstop>inputFilePreview</tabstop> |
||||
</tabstops> |
||||
<resources/> |
||||
<connections/> |
||||
</ui> |
||||
|
After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in new issue