A PyQT GUI application for converting InfoLease report outputs into Excel files. Handles parsing and summarizing. Learns where files are meant to be store and compiles monthly and yearly summaries.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
InfoLeaseExtract/main.py

133 lines
6.2 KiB

from mainWindow_new import Ui_MainWindow
import sys
import os
import pandas as pd
from PyQt5 import QtWidgets
from datetime import datetime as dt
import ILExtract as ilx
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, *args, obj=None, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setupUi(self)
self.inputFile = ""
self.outputFile = ""
self.rtp = False # Ready to Process
self.ofa = False # Output file ready
# Actions
self.inputFileButton.clicked.connect(self.getfile)
self.outputFileButton.clicked.connect(self.setOutput)
self.processReportButton.clicked.connect(self.process_selection)
self.openReportButton.clicked.connect(self.to_clipboard)
def getfile(self):
inFile = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file')
self.inputFileLE.setText(inFile[0])
if inFile[0] == '' : return ''
# Replacing errors fixes some UTF-8 character issues
with open(inFile[0], errors="replace") as inF:
txt = inF.read()
self.inputFilePreview.setText(txt)
self.inputFile = inFile[0]
# This gets the actual file name
inFileEnd = inFile[0].split('/')[-1]
# Takes just the root of the input file
outputRoot = self.inputFile.removesuffix(inFileEnd)
# Automatically sets output to be in the same file as input, with a naming scheme
# The report type selected in the combo box will dictate the naming
self.outputFile = f"{outputRoot}{self.reportTypeCB.currentText()}_{dt.now().strftime('%Y%m%d_%H%M')}.xlsx"
self.outputFileLE.setText(self.outputFile)
# Check to make sure the user has selected the correct report type
if self.reportTypeCB.currentText().split(" ")[-1].lower() not in self.inputFile.lower():
print("Possibly wrong file type")
warning = QtWidgets.QMessageBox()
warning.setWindowTitle("Warning: File Type Mis-Match")
warning.setText(f"Selected report type is {self.reportTypeCB.currentText()} but input file did not contain '{self.reportTypeCB.currentText().split(' ')[-1].lower()}'!\n\
Make sure you select the correct report type before processing!")
s = warning.exec()
# Enables the process button
self.check_ready_to_process()
def setOutput(self):
# This allows the user to change the automatic naming and location
outFile = QtWidgets.QFileDialog.getSaveFileName(self, "Output file name")
if outFile[0] == '': return ''
self.outputFileLE.setText(f"{outFile[0]}__{dt.now().strftime('%Y%m%d_%H_%M')}.xlsx")
print(f"Output: {outFile}")
self.outputFile = f"{outFile[0]}__{dt.now().strftime('%Y%m%d_%H_%M')}.xlsx"
self.check_ready_to_process()
def check_ready_to_process(self):
# Makes sure there is an input and output selected before allowing processing
self.rtp = True if ((self.inputFile != "") & (self.outputFile != "")) else False
if self.rtp :
self.processReportButton.setEnabled(True)
def process_selection(self):
self.inputFilePreview.setText("Processing file...")
# If only this was python 3.10 and we could use switch statments
# but this should get the job done
try:
# Here we set the extraction function that will be used on the report
if self.reportTypeCB.currentText() == "ACH":
extract_function = ilx.ach
elif self.reportTypeCB.currentText() == "Disposition":
extract_function = ilx.disposition
elif self.reportTypeCB.currentText() == "Gain Loss":
extract_function = ilx.gainloss
elif self.reportTypeCB.currentText() == "Lock Box":
extract_function = ilx.lockbox
elif self.reportTypeCB.currentText() == "Minv_C":
extract_function = ilx.minv
elif self.reportTypeCB.currentText() == "Net Inv. Loans":
extract_function = ilx.net_invest_trial_balance
elif self.reportTypeCB.currentText() == "NI Renewal":
extract_function = ilx.renewal_net_invest_trial_balance
elif self.reportTypeCB.currentText() == "NIV After":
extract_function = ilx.net_invest_trial_balance
elif self.reportTypeCB.currentText() == "PBP Epay":
extract_function = ilx.payment_transactions
elif self.reportTypeCB.currentText() == "Unapplied":
extract_function = ilx.unapplied
elif self.reportTypeCB.currentText() == "VMCC":
extract_function = ilx.payment_transactions
elif self.reportTypeCB.currentText() == "Wires":
extract_function = ilx.payment_transactions
elif self.reportTypeCB.currentText() == "Returned Check":
extract_function = ilx.payment_transactions
# This is where the actual processing happens
# We create an ILReport object and pass in the nessecary information
dataframe = ilx.ILReport(
location= self.inputFile,
extraction_function=extract_function,
output_location=self.outputFile,
).process()
# The text preview box can have trouble loading the larger dataframes so
# they are trimmed to 500 so that the users can see if anything got messed up
smallDF = dataframe.iloc[0:500,:]
self.inputFilePreview.setText(smallDF.to_html(index=False))
except:
error = QtWidgets.QMessageBox()
error.setWindowTitle('Error Processing File!')
error.setText(f"Unable to process {self.inputFile}!\nPlease check input file!")
def preview_report(self):
df = pd.read_excel(self.outputFile)
self.inputFilePreview.setText(df.to_html())
def to_clipboard(self):
df = pd.read_excel(self.outputFile)
df.to_clipboard(excel=True)
app = QtWidgets.QApplication(sys.argv)
app.setStyle("Fusion")
window = MainWindow()
window.setWindowTitle("IL Extract")
window.show()
app.exec()