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.
123 lines
5.3 KiB
123 lines
5.3 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 ''
|
|
print(f"Input File: {inFile}")
|
|
with open(inFile[0], errors="replace") as inF:
|
|
txt = inF.read()
|
|
print(txt)
|
|
self.inputFilePreview.setText(txt)
|
|
self.inputFile = inFile[0]
|
|
inFileEnd = inFile[0].split('/')[-1]
|
|
outputRoot = self.inputFile.removesuffix(inFileEnd)
|
|
self.outputFile = f"{outputRoot}{self.reportTypeCB.currentText()}_{dt.now().strftime('%Y%m%d_%H%M')}.xlsx"
|
|
self.outputFileLE.setText(self.outputFile)
|
|
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()
|
|
self.check_ready_to_process()
|
|
|
|
def setOutput(self):
|
|
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):
|
|
self.rtp = True if ((self.inputFile != "") & (self.outputFile != "")) else False
|
|
if self.rtp :
|
|
self.processReportButton.setEnabled(True)
|
|
|
|
def process_selection(self):
|
|
with open(self.inputFile, errors="replace") as inF:
|
|
reportString = inF.read()
|
|
try:
|
|
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() == "Returns":
|
|
extract_function = ilx.payment_transactions
|
|
|
|
dataframe = ilx.ILReport(
|
|
location= self.inputFile,
|
|
extraction_function=extract_function,
|
|
output_location=self.outputFile,
|
|
).process()
|
|
dataframe.to_excel(self.outputFile, index=False, engine="xlsxwriter")
|
|
smallDF = dataframe.iloc[0:500,:]
|
|
self.inputFilePreview.setText(smallDF.to_html(index=False))
|
|
self.openReportButton.setEnabled(True)
|
|
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() |