# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'EntryWindow/Interfaces/EntryWindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.

import mysql.connector
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QDate
from PyQt5.QtWidgets import QMessageBox

from AddProfileWindow import Ui_AddProfileWindow

# Connect to Database
vhc_db = mysql.connector.connect(
    host="185.201.11.44",
    user="u257284371_ansh",
    password="ansh1Rutu"
)
cursor = vhc_db.cursor()


def get_bank_id_by_name(name):
    cursor.execute("SELECT ID FROM u257284371_vedanya.banks WHERE NAME = '{}';".format(name))
    id = cursor.fetchone()
    return id[0]


def get_state_id_by_name(name):
    cursor.execute("SELECT ID FROM u257284371_vedanya.states WHERE NAME = '{}';".format(name))
    id = cursor.fetchone()
    return id[0]


def get_client_id_by_name(name):
    cursor.execute("SELECT ID FROM u257284371_vedanya.clients WHERE NAME = '{}';".format(name))
    id = cursor.fetchone()
    return id[0]


def get_state_name_by_id(id):
    cursor.execute("SELECT NAME FROM u257284371_vedanya.states WHERE ID = {}".format(id))
    return cursor.fetchall()[0]


def get_sr_name_by_id(id):
    cursor.execute("SELECT NAME FROM u257284371_vedanya.sr WHERE ID = {}".format(id))
    return cursor.fetchall()[0]


def get_sr_id_by_name(name):
    cursor.execute("SELECT ID FROM u257284371_vedanya.sr WHERE NAME = '{}';".format(name))
    id = cursor.fetchone()
    return id[0]


def get_state_abbreviation_by_id(id):
    cursor.execute("SELECT ABBREVIATION FROM u257284371_vedanya.states WHERE ID = {};".format(id))
    return cursor.fetchone()[0]


def perform_query_from_file(file_name):
    path = 'Queries/' + file_name
    with open(path, 'r') as q:
        cursor.execute(q.read(), multi=True)
    return cursor.fetchall()


def add_client(state, sr, name, mobile, city):
    state_id = get_state_id_by_name(state)
    sr_id = get_sr_id_by_name(sr)
    cursor.execute(
        "INSERT INTO u257284371_vedanya.clients (STATE_ID, SR_ID, NAME, MOBILE, CITY) VALUES ({}, {}, '{}', '{}', "
        "'{}'); ".format(state_id, sr_id, name, mobile, city))
    vhc_db.commit()


def add_sr(state, name):
    cursor.execute(
        "INSERT INTO u257284371_vedanya.sr (STATE_ID, NAME) VALUES ({}, '{}');".format(get_state_id_by_name(state),
                                                                                       name))
    vhc_db.commit()


def fetch_clients_list():
    clist = [""]
    cursor.execute("SELECT NAME FROM u257284371_vedanya.clients")
    clients = cursor.fetchall()
    for x in clients:
        for y in x:
            clist.append(str(y))
    return clist


def fetch_sr_list():
    srlist = [""]
    cursor.execute("SELECT NAME FROM u257284371_vedanya.sr")
    sr = cursor.fetchall()
    for x in sr:
        for y in x:
            srlist.append(str(y))
    return srlist


def fetch_bank_list():
    bnlist = [""]
    cursor.execute("SELECT NAME FROM u257284371_vedanya.banks")
    sr = cursor.fetchall()
    for x in sr:
        for y in x:
            bnlist.append(str(y))
    return bnlist


def fetch_client_info(name):
    cursor.execute("SELECT * FROM u257284371_vedanya.clients WHERE NAME = '{}'".format(name))
    return cursor.fetchone()


def make_transaction_entry(bank_id, client_id, state_id, sr_id, amount, type, date):
    cursor.execute("SELECT BALANCE FROM u257284371_vedanya.banks WHERE ID = {}".format(bank_id))
    currentBalance = cursor.fetchone()[0]
    balance = currentBalance + int(amount)
    cursor.execute(
        "INSERT INTO u257284371_vedanya.transactions (BANK_ID, CLIENT_ID, STATE_ID, SR_ID, AMOUNT, BALANCE, TYPE, "
        "DATE) VALUES({}, {}, {}, {}, {}, {}, '{}', '{}')"
        ";".format(bank_id, client_id, state_id, sr_id, amount, balance, type, date))
    cursor.execute("UPDATE u257284371_vedanya.banks SET BALANCE = {} WHERE ID = {};".format(balance, bank_id))
    vhc_db.commit()


class Ui_EntryWindow(object):

    def setupUi(self, EntryWindow):
        EntryWindow.setObjectName("EntryWindow")
        EntryWindow.resize(1110, 710)
        EntryWindow.setMinimumSize(QtCore.QSize(1110, 710))
        EntryWindow.setMaximumSize(QtCore.QSize(1200, 710))
        EntryWindow.setStyleSheet("#EntryWindow{background-color: rgb(225, 255, 245);}")
        self.centralwidget = QtWidgets.QWidget(EntryWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.clientInformationBox = QtWidgets.QGroupBox(self.centralwidget)
        self.clientInformationBox.setEnabled(True)
        self.clientInformationBox.setGeometry(QtCore.QRect(10, 420, 1091, 261))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.clientInformationBox.setFont(font)
        self.clientInformationBox.setStyleSheet("#clientInformationBox{\n"
                                                "background-color: white;\n"
                                                "border-radius: 20px;\n"
                                                "}")
        self.clientInformationBox.setAlignment(QtCore.Qt.AlignCenter)
        self.clientInformationBox.setObjectName("clientInformationBox")
        self.info_sr_id = QtWidgets.QLabel(self.clientInformationBox)
        self.info_sr_id.setGeometry(QtCore.QRect(30, 130, 90, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.info_sr_id.setFont(font)
        self.info_sr_id.setObjectName("info_sr_id")
        self.info_client_state_code = QtWidgets.QLabel(self.clientInformationBox)
        self.info_client_state_code.setGeometry(QtCore.QRect(30, 190, 90, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.info_client_state_code.setFont(font)
        self.info_client_state_code.setObjectName("info_client_state_code")
        self.info_client_id = QtWidgets.QLabel(self.clientInformationBox)
        self.info_client_id.setGeometry(QtCore.QRect(30, 70, 90, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.info_client_id.setFont(font)
        self.info_client_id.setObjectName("info_client_id")
        self.info_client_name = QtWidgets.QLabel(self.clientInformationBox)
        self.info_client_name.setGeometry(QtCore.QRect(30, 40, 101, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.info_client_name.setFont(font)
        self.info_client_name.setObjectName("info_client_name")
        self.info_client_city = QtWidgets.QLabel(self.clientInformationBox)
        self.info_client_city.setGeometry(QtCore.QRect(30, 220, 90, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.info_client_city.setFont(font)
        self.info_client_city.setObjectName("info_client_city")
        self.info_client_state = QtWidgets.QLabel(self.clientInformationBox)
        self.info_client_state.setGeometry(QtCore.QRect(30, 160, 90, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.info_client_state.setFont(font)
        self.info_client_state.setObjectName("info_client_state")
        self.info_sr_name = QtWidgets.QLabel(self.clientInformationBox)
        self.info_sr_name.setGeometry(QtCore.QRect(30, 100, 90, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.info_sr_name.setFont(font)
        self.info_sr_name.setObjectName("info_sr_name")
        self.line_2 = QtWidgets.QFrame(self.clientInformationBox)
        self.line_2.setGeometry(QtCore.QRect(360, 14, 421, 20))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(6)
        font.setBold(False)
        font.setWeight(50)
        self.line_2.setFont(font)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setObjectName("line_2")
        self.info_client_name_value = QtWidgets.QTextEdit(self.clientInformationBox)
        self.info_client_name_value.setGeometry(QtCore.QRect(230, 40, 531, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI")
        font.setPointSize(10)
        font.setBold(False)
        font.setWeight(50)
        self.info_client_name_value.setFont(font)
        self.info_client_name_value.setStyleSheet("QTextEdit {\n"
                                                  "    border:0;\n"
                                                  "}")
        self.info_client_name_value.setReadOnly(True)
        self.info_client_name_value.setObjectName("info_client_name_value")
        self.info_sr_id_value = QtWidgets.QTextEdit(self.clientInformationBox)
        self.info_sr_id_value.setGeometry(QtCore.QRect(230, 130, 531, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI")
        font.setPointSize(10)
        font.setBold(False)
        font.setWeight(50)
        self.info_sr_id_value.setFont(font)
        self.info_sr_id_value.setStyleSheet("QTextEdit {\n"
                                            "    border:0;\n"
                                            "}")
        self.info_sr_id_value.setReadOnly(True)
        self.info_sr_id_value.setObjectName("info_sr_id_value")
        self.info_client_state_name_value = QtWidgets.QTextEdit(self.clientInformationBox)
        self.info_client_state_name_value.setGeometry(QtCore.QRect(230, 160, 531, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI")
        font.setPointSize(10)
        font.setBold(False)
        font.setWeight(50)
        self.info_client_state_name_value.setFont(font)
        self.info_client_state_name_value.setStyleSheet("QTextEdit {\n"
                                                        "    border:0;\n"
                                                        "}")
        self.info_client_state_name_value.setReadOnly(True)
        self.info_client_state_name_value.setObjectName("info_client_state_name_value")
        self.info_client_state_code_value = QtWidgets.QTextEdit(self.clientInformationBox)
        self.info_client_state_code_value.setGeometry(QtCore.QRect(230, 190, 531, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI")
        font.setPointSize(10)
        font.setBold(False)
        font.setWeight(50)
        self.info_client_state_code_value.setFont(font)
        self.info_client_state_code_value.setStyleSheet("QTextEdit {\n"
                                                        "    border:0;\n"
                                                        "}")
        self.info_client_state_code_value.setReadOnly(True)
        self.info_client_state_code_value.setObjectName("info_client_state_code_value")
        self.info_sr_name_value = QtWidgets.QTextEdit(self.clientInformationBox)
        self.info_sr_name_value.setGeometry(QtCore.QRect(230, 100, 531, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI")
        font.setPointSize(10)
        font.setBold(False)
        font.setWeight(50)
        self.info_sr_name_value.setFont(font)
        self.info_sr_name_value.setStyleSheet("QTextEdit {\n"
                                              "    border:0;\n"
                                              "}")
        self.info_sr_name_value.setReadOnly(True)
        self.info_sr_name_value.setObjectName("info_sr_name_value")
        self.info_client_id_value = QtWidgets.QTextEdit(self.clientInformationBox)
        self.info_client_id_value.setGeometry(QtCore.QRect(230, 70, 531, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI")
        font.setPointSize(10)
        font.setBold(False)
        font.setWeight(50)
        self.info_client_id_value.setFont(font)
        self.info_client_id_value.setStyleSheet("QTextEdit {\n"
                                                "    border:0;\n"
                                                "}")
        self.info_client_id_value.setReadOnly(True)
        self.info_client_id_value.setObjectName("info_client_id_value")
        self.info_client_city_value = QtWidgets.QTextEdit(self.clientInformationBox)
        self.info_client_city_value.setGeometry(QtCore.QRect(230, 220, 531, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI")
        font.setPointSize(10)
        font.setBold(False)
        font.setWeight(50)
        self.info_client_city_value.setFont(font)
        self.info_client_city_value.setStyleSheet("QTextEdit {\n"
                                                  "    border:0;\n"
                                                  "}")
        self.info_client_city_value.setReadOnly(True)
        self.info_client_city_value.setObjectName("info_client_city_value")
        self.EntryBox = QtWidgets.QGroupBox(self.centralwidget)
        self.EntryBox.setGeometry(QtCore.QRect(10, 10, 1091, 401))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.EntryBox.setFont(font)
        self.EntryBox.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.EntryBox.setStyleSheet("#EntryBox {\n"
                                    "background-color: white;\n"
                                    "border-radius: 20px;\n"
                                    "}")
        self.EntryBox.setAlignment(QtCore.Qt.AlignCenter)
        self.EntryBox.setObjectName("EntryBox")
        self.label = QtWidgets.QLabel(self.EntryBox)
        self.label.setGeometry(QtCore.QRect(30, 60, 191, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.client_selection = QtWidgets.QComboBox(self.EntryBox)
        self.client_selection.setGeometry(QtCore.QRect(230, 61, 251, 23))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.client_selection.setFont(font)
        self.client_selection.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.client_selection.setObjectName("client_selection")
        self.submitEntryButton = QtWidgets.QPushButton(self.EntryBox)
        self.submitEntryButton.setGeometry(QtCore.QRect(945, 320, 70, 70))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.submitEntryButton.setFont(font)
        self.submitEntryButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.submitEntryButton.setStyleSheet("border-style: solid;\n"
                                             "border-radius:500px;\n"
                                             "max-width:70px;\n"
                                             "max-height:70px;\n"
                                             "min-width:70px;\n"
                                             "min-height:70px;")
        self.submitEntryButton.setText("")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("assets/submit.png"), QtGui.QIcon.Normal,
                       QtGui.QIcon.Off)
        self.submitEntryButton.setIcon(icon)
        self.submitEntryButton.setIconSize(QtCore.QSize(70, 70))
        self.submitEntryButton.setObjectName("submitEntryButton")
        self.label_2 = QtWidgets.QLabel(self.EntryBox)
        self.label_2.setGeometry(QtCore.QRect(30, 88, 191, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.bank_selection = QtWidgets.QComboBox(self.EntryBox)
        self.bank_selection.setGeometry(QtCore.QRect(230, 91, 251, 23))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.bank_selection.setFont(font)
        self.bank_selection.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.bank_selection.setObjectName("bank_selection")
        self.line_3 = QtWidgets.QFrame(self.EntryBox)
        self.line_3.setGeometry(QtCore.QRect(360, 14, 421, 20))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(6)
        font.setBold(False)
        font.setWeight(50)
        self.line_3.setFont(font)
        self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_3.setObjectName("line_3")
        self.label_3 = QtWidgets.QLabel(self.EntryBox)
        self.label_3.setGeometry(QtCore.QRect(30, 170, 191, 16))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")
        self.currentDateEdit = QtWidgets.QDateEdit(self.EntryBox)
        self.currentDateEdit.setGeometry(QtCore.QRect(230, 210, 161, 22))
        self.currentDateEdit.setReadOnly(True)
        self.currentDateEdit.setObjectName("currentDateEdit")
        self.add_profile_btn = QtWidgets.QPushButton(self.EntryBox)
        self.add_profile_btn.setGeometry(QtCore.QRect(934, 61, 100, 100))
        self.add_profile_btn.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.add_profile_btn.setStyleSheet("border-style: solid;\n"
                                           "/*border-radius:500px;*/\n"
                                           "max-width:100px;\n"
                                           "max-height:100px;\n"
                                           "min-width:100px;\n"
                                           "min-height:100px;")
        self.add_profile_btn.setText("")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("assets/add_profile.png"), QtGui.QIcon.Normal,
                        QtGui.QIcon.Off)
        self.add_profile_btn.setIcon(icon1)
        self.add_profile_btn.setIconSize(QtCore.QSize(100, 100))
        self.add_profile_btn.setObjectName("add_profile_btn")
        self.add_profile_label = QtWidgets.QLabel(self.EntryBox)
        self.add_profile_label.setGeometry(QtCore.QRect(930, 161, 100, 20))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(9)
        self.add_profile_label.setFont(font)
        self.add_profile_label.setAlignment(QtCore.Qt.AlignCenter)
        self.add_profile_label.setObjectName("add_profile_label")
        self.label_5 = QtWidgets.QLabel(self.EntryBox)
        self.label_5.setGeometry(QtCore.QRect(510, 161, 41, 31))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI")
        font.setPointSize(13)
        font.setBold(True)
        font.setWeight(75)
        self.label_5.setFont(font)
        self.label_5.setObjectName("label_5")
        self.current_date_radio_btn = QtWidgets.QRadioButton(self.EntryBox)
        self.current_date_radio_btn.setGeometry(QtCore.QRect(230, 170, 121, 18))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.current_date_radio_btn.setFont(font)
        self.current_date_radio_btn.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.current_date_radio_btn.setObjectName("current_date_radio_btn")
        self.manual_date_radio_btn = QtWidgets.QRadioButton(self.EntryBox)
        self.manual_date_radio_btn.setGeometry(QtCore.QRect(610, 170, 121, 18))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.manual_date_radio_btn.setFont(font)
        self.manual_date_radio_btn.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.manual_date_radio_btn.setObjectName("manual_date_radio_btn")
        self.manuaDateEdit = QtWidgets.QDateEdit(self.EntryBox)
        self.manuaDateEdit.setGeometry(QtCore.QRect(610, 210, 161, 22))
        self.manuaDateEdit.setReadOnly(True)
        self.manuaDateEdit.setObjectName("manuaDateEdit")
        self.label_12 = QtWidgets.QLabel(self.EntryBox)
        self.label_12.setGeometry(QtCore.QRect(30, 116, 191, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.label_12.setFont(font)
        self.label_12.setObjectName("label_12")
        self.plainTextEdit = QtWidgets.QPlainTextEdit(self.EntryBox)
        self.plainTextEdit.setGeometry(QtCore.QRect(230, 120, 251, 25))
        self.plainTextEdit.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.IBeamCursor))
        self.plainTextEdit.setObjectName("plainTextEdit")
        self.current_date_info_frame = QtWidgets.QFrame(self.EntryBox)
        self.current_date_info_frame.setGeometry(QtCore.QRect(230, 251, 261, 101))
        self.current_date_info_frame.setAutoFillBackground(False)
        self.current_date_info_frame.setStyleSheet("#current_date_info_frame{\n"
                                                   "background-color: rgb(255, 255, 176);\n"
                                                   "}")
        self.current_date_info_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.current_date_info_frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.current_date_info_frame.setObjectName("current_date_info_frame")
        self.warning1_2 = QtWidgets.QLabel(self.current_date_info_frame)
        self.warning1_2.setGeometry(QtCore.QRect(18, 38, 241, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.warning1_2.setFont(font)
        self.warning1_2.setObjectName("warning1_2")
        self.warning1_3 = QtWidgets.QLabel(self.current_date_info_frame)
        self.warning1_3.setGeometry(QtCore.QRect(18, 58, 241, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.warning1_3.setFont(font)
        self.warning1_3.setObjectName("warning1_3")
        self.warning1_1 = QtWidgets.QLabel(self.current_date_info_frame)
        self.warning1_1.setGeometry(QtCore.QRect(18, 10, 191, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.warning1_1.setFont(font)
        self.warning1_1.setObjectName("warning1_1")
        self.manual_date_info_frame = QtWidgets.QFrame(self.EntryBox)
        self.manual_date_info_frame.setGeometry(QtCore.QRect(610, 250, 261, 101))
        self.manual_date_info_frame.setAutoFillBackground(False)
        self.manual_date_info_frame.setStyleSheet("#manual_date_info_frame{\n"
                                                  "background-color: rgb(255, 255, 176);\n"
                                                  "}")
        self.manual_date_info_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.manual_date_info_frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.manual_date_info_frame.setObjectName("manual_date_info_frame")
        self.warning2_2 = QtWidgets.QLabel(self.manual_date_info_frame)
        self.warning2_2.setGeometry(QtCore.QRect(18, 38, 241, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.warning2_2.setFont(font)
        self.warning2_2.setObjectName("warning2_2")
        self.warning2_3 = QtWidgets.QLabel(self.manual_date_info_frame)
        self.warning2_3.setGeometry(QtCore.QRect(18, 58, 241, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.warning2_3.setFont(font)
        self.warning2_3.setObjectName("warning2_3")
        self.warning2_1 = QtWidgets.QLabel(self.manual_date_info_frame)
        self.warning2_1.setGeometry(QtCore.QRect(18, 10, 191, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.warning2_1.setFont(font)
        self.warning2_1.setObjectName("warning2_1")
        self.calendarPopUpButton = QtWidgets.QPushButton(self.EntryBox)
        self.calendarPopUpButton.setGeometry(QtCore.QRect(780, 208, 25, 25))
        self.calendarPopUpButton.setStyleSheet("#calendarPopUpButton{\n"
                                               "background-color: white\n"
                                               "}")
        self.calendarPopUpButton.setText("")
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap("assets/calendar.png"), QtGui.QIcon.Normal,
                        QtGui.QIcon.Off)
        self.calendarPopUpButton.setIcon(icon2)
        self.calendarPopUpButton.setIconSize(QtCore.QSize(30, 30))
        self.calendarPopUpButton.setFlat(True)
        self.calendarPopUpButton.setObjectName("calendarPopUpButton")
        self.manual_date_info_frame.raise_()
        self.label.raise_()
        self.client_selection.raise_()
        self.submitEntryButton.raise_()
        self.label_2.raise_()
        self.bank_selection.raise_()
        self.line_3.raise_()
        self.label_3.raise_()
        self.currentDateEdit.raise_()
        self.add_profile_btn.raise_()
        self.add_profile_label.raise_()
        self.label_5.raise_()
        self.current_date_radio_btn.raise_()
        self.manual_date_radio_btn.raise_()
        self.manuaDateEdit.raise_()
        self.label_12.raise_()
        self.plainTextEdit.raise_()
        self.current_date_info_frame.raise_()
        self.calendarPopUpButton.raise_()
        self.calendarFrame = QtWidgets.QFrame(self.centralwidget)
        self.calendarFrame.setEnabled(True)
        self.calendarFrame.setGeometry(QtCore.QRect(620, 260, 381, 231))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.calendarFrame.setFont(font)
        self.calendarFrame.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.calendarFrame.setStyleSheet("#calendarFrame{\n"
                                         "background-color:rgb(230,230,230);\n"
                                         "border-raduis: 50px;\n"
                                         "}")
        self.calendarFrame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.calendarFrame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.calendarFrame.setObjectName("calendarFrame")
        self.calendarWidget = QtWidgets.QCalendarWidget(self.calendarFrame)
        self.calendarWidget.setGeometry(QtCore.QRect(10, 10, 361, 183))
        self.calendarWidget.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.calendarWidget.setStyleSheet("class MyDateEdit : QDateEdit\n"
                                          "{\n"
                                          "  Q_OBJECT\n"
                                          "\n"
                                          "protected:\n"
                                          "  void mouseEvent(QEvent *event) {\n"
                                          "    this.calendarWidget().show();\n"
                                          "  }\n"
                                          "};")
        self.calendarWidget.setNavigationBarVisible(True)
        self.calendarWidget.setDateEditEnabled(True)
        self.calendarWidget.setObjectName("calendarWidget")
        self.confirm_calendar_selection_btn = QtWidgets.QPushButton(self.calendarFrame)
        self.confirm_calendar_selection_btn.setGeometry(QtCore.QRect(290, 200, 85, 26))
        self.confirm_calendar_selection_btn.setAutoFillBackground(False)
        self.confirm_calendar_selection_btn.setStyleSheet("#confirm_calendar_selection_btn{\n"
                                                          "background-color: white;\n"
                                                          "}")
        self.confirm_calendar_selection_btn.setAutoDefault(False)
        self.confirm_calendar_selection_btn.setDefault(False)
        self.confirm_calendar_selection_btn.setFlat(False)
        self.confirm_calendar_selection_btn.setObjectName("confirm_calendar_selection_btn")
        self.confirm_calendar_selection_btn.raise_()
        self.calendarWidget.raise_()
        EntryWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(EntryWindow)
        self.statusbar.setObjectName("statusbar")
        EntryWindow.setStatusBar(self.statusbar)

        self.retranslateUi(EntryWindow)
        QtCore.QMetaObject.connectSlotsByName(EntryWindow)

        # Custom Code Below:
        self.isValidBankSelected = False
        self.entryErrors = []
        # fill clients list
        self.client_selection.addItems(fetch_clients_list())
        self.bank_selection.addItems(fetch_bank_list())
        # self.bank_selection.addItems(fetch_bank_list())

        self.manuaDateEdit.setMaximumDate(QDate.currentDate())
        # hide calendar
        self.calendarWidget.setHidden(True)
        self.confirm_calendar_selection_btn.setHidden(True)
        self.calendarFrame.setVisible(False)

        # initial disable manual date selection
        self.manuaDateEdit.setEnabled(False)
        self.manual_date_info_frame.setEnabled(False)
        self.current_date_radio_btn.setChecked(True)

        # set current date
        self.currentDateEdit.setDate(QDate.currentDate())
        self.finalisedDate = ""
        self.isValidCientSelected = False
        # toggle manual date selection
        self.manual_date_radio_btn.toggled.connect(self.onManualDateRB)
        self.current_date_radio_btn.toggled.connect(self.onCurrentDateRB)

        self.confirm_calendar_selection_btn.clicked.connect(self.onCalendarDateConfirm)
        self.calendarPopUpButton.clicked.connect(lambda: self.showCalendarPopUp(True))
        self.submitEntryButton.clicked.connect(self.onSubmit)
        self.bank_selection.currentTextChanged.connect(self.setBankSelection)
        self.add_profile_btn.clicked.connect(self.onAddProfile)
        self.plainTextEdit.textChanged.connect(self.updateClientList)
        self.client_selection.currentTextChanged.connect(self.updateClientInfo)

        self.addProfileWindow = QtWidgets.QMainWindow()
        self.addProfileWindowUi = Ui_AddProfileWindow()
        self.addProfileWindowUi.setupUi(self.addProfileWindow)

    def retranslateUi(self, EntryWindow):
        _translate = QtCore.QCoreApplication.translate
        EntryWindow.setWindowTitle(_translate("EntryWindow", "MainWindow"))
        self.clientInformationBox.setTitle(_translate("EntryWindow", "CLIENT INFORMATION"))
        self.info_sr_id.setText(_translate("EntryWindow", "SR ID:"))
        self.info_client_state_code.setText(_translate("EntryWindow", "STATE CODE:"))
        self.info_client_id.setText(_translate("EntryWindow", "CLIENT ID:"))
        self.info_client_name.setText(_translate("EntryWindow", "CLIENT NAME:"))
        self.info_client_city.setText(_translate("EntryWindow", "CITY:"))
        self.info_client_state.setText(_translate("EntryWindow", "STATE:"))
        self.info_sr_name.setText(_translate("EntryWindow", "SR NAME:"))
        self.EntryBox.setTitle(_translate("EntryWindow", "SEARCH AREA"))
        self.label.setText(_translate("EntryWindow", "EXISTING CLIENT NAME:"))
        self.label_2.setText(_translate("EntryWindow", "BANK NAME:"))
        self.label_3.setText(_translate("EntryWindow", "DATE:"))
        self.add_profile_label.setText(_translate("EntryWindow", "ADD PROFILE"))
        self.label_5.setText(_translate("EntryWindow", "OR"))
        self.current_date_radio_btn.setText(_translate("EntryWindow", "CURRENT DATE"))
        self.manual_date_radio_btn.setText(_translate("EntryWindow", "MANUAL DATE"))
        self.label_12.setText(_translate("EntryWindow", "AMOUNT:"))
        self.confirm_calendar_selection_btn.setText(_translate("EntryWindow", "OK"))
        self.warning1_2.setText(_translate("EntryWindow", "THIS WILL AUTOMATICALLY SELECT"))
        self.warning1_3.setText(_translate("EntryWindow", "THE CURRENT DATE."))
        self.warning1_1.setText(_translate("EntryWindow", "WARNING:"))
        self.warning2_2.setText(_translate("EntryWindow", "THIS WILL LET YOU SELECT"))
        self.warning2_3.setText(_translate("EntryWindow", "THE DATE MANUALLY"))
        self.warning2_1.setText(_translate("EntryWindow", "WARNING:"))

    def updateClientList(self):
        if self.client_selection.currentText() == '' and len(self.plainTextEdit.toPlainText()) == 1:
            vhc_db.commit()
            self.client_selection.clear()
            self.client_selection.addItems(fetch_clients_list())
            print('client updated')

    def setBankSelection(self):
        if not self.bank_selection.currentText() == '':
            self.isValidBankSelected = True
        else:
            self.isValidCientSelected = False

    def onManualDateRB(self):
        self.showCalendarPopUp(True)
        self.currentDateEdit.setEnabled(False)
        self.current_date_info_frame.setEnabled(False)
        self.manuaDateEdit.setEnabled(True)
        self.manual_date_info_frame.setEnabled(True)

    def onCurrentDateRB(self):
        self.showCalendarPopUp(False)
        self.manuaDateEdit.setEnabled(False)
        self.manual_date_info_frame.setEnabled(False)
        self.currentDateEdit.setEnabled(True)
        self.current_date_info_frame.setEnabled(True)

    def onCalendarDateConfirm(self):
        self.manuaDateEdit.setDate(self.calendarWidget.selectedDate())
        self.calendarWidget.setHidden(True)
        self.confirm_calendar_selection_btn.setHidden(True)
        self.calendarFrame.setVisible(False)

    def showCalendarPopUp(self, value):
        if not value:
            self.calendarWidget.setHidden(True)
            self.confirm_calendar_selection_btn.setHidden(True)
            self.calendarFrame.setVisible(False)
        if value:
            self.calendarWidget.setHidden(False)
            self.confirm_calendar_selection_btn.setHidden(False)
            self.calendarFrame.setVisible(True)

    def updateClientInfo(self):

        if self.client_selection.currentText() == "":
            self.info_client_id_value.setText("")
            self.info_sr_name_value.setText("")
            self.info_client_state_code_value.setText("")
            self.info_sr_id_value.setText("")
            self.info_client_name_value.setText("")
            self.info_client_city_value.setText("")
            self.info_client_state_name_value.setText("")
            self.isValidCientSelected = False
        else:
            selected_client = self.client_selection.currentText()
            info = fetch_client_info(selected_client)
            state = get_state_name_by_id(info[1])
            print(info[1])
            sr = get_sr_name_by_id(info[2])
            st_code = get_state_abbreviation_by_id(info[1])
            self.info_client_id_value.setText(str(info[0]))
            self.info_sr_name_value.setText(str(sr[0]))
            self.info_client_state_code_value.setText(str(st_code))
            self.info_sr_id_value.setText(str(info[2]))
            self.info_client_name_value.setText(str(info[3]))
            self.info_client_city_value.setText(str(info[5]))
            self.info_client_state_name_value.setText(str(state[0]))
            print(selected_client)
            self.isValidCientSelected = True

    def onSubmit(self):
        dateCheck = False
        clientCheck = False
        bankCheck = False
        amountCheck = False
        if self.current_date_radio_btn.isChecked():
            self.finalisedDate = str(self.currentDateEdit.date().toPyDate())
            dateCheck = True
        if self.manual_date_radio_btn.isChecked():
            self.finalisedDate = str(self.manuaDateEdit.date().toPyDate())
            dateCheck = True
        if not self.bank_selection.currentData() == "":
            bankCheck = True
        if not self.client_selection.currentData() == "":
            clientCheck = True
        if not self.plainTextEdit.toPlainText() == '':
            if self.plainTextEdit.toPlainText().isnumeric():
                amountCheck = True
                amount = int(self.plainTextEdit.toPlainText())
            else:
                print("invalid amount")
        else:
            print("invalid amount")
        if dateCheck and clientCheck and bankCheck and amountCheck and self.isValidCientSelected and self.isValidBankSelected:
            if self.showEntryConfirmation(self.bank_selection.currentText(), self.client_selection.currentText(),
                                          self.plainTextEdit.toPlainText()) == 1024:
                make_transaction_entry(
                    int(get_bank_id_by_name(str(self.bank_selection.currentText()))),
                    int(get_client_id_by_name(str(self.client_selection.currentText()))),
                    int(get_state_id_by_name(str(self.info_client_state_name_value.toPlainText()))),
                    int(str(self.info_sr_id_value.toPlainText())),
                    int(str(self.plainTextEdit.toPlainText())),
                    'CREDIT',
                    str(self.finalisedDate),
                )
                self.showSuccessMessage()
        else:
            self.entryErrors.clear()
            if not dateCheck:
                self.entryErrors.append('Date is not valid!')
            if not self.isValidCientSelected:
                self.entryErrors.append('No valid client selected!')
            if not self.isValidBankSelected:
                self.entryErrors.append('No valid bank is selected!')
            if not amountCheck:
                self.entryErrors.append('Amount entered is not valid!')
            self.generateErrorEntryMessageBox(self.entryErrors)

    def generateErrorEntryMessageBox(self, errors):
        msg = ''
        for x in errors:
            msg = msg + '-  ' + x + '\n'
        msgBox = QMessageBox()
        msgBox.setStyleSheet("QMessageBox{min-width: 700px;}")
        msgBox.setIcon(QMessageBox.Critical)
        msgBox.setText('WARNING')
        msgBox.setInformativeText('ENTRY IS NOT VALID. CHECK THE DETAILS FOR CAUSES OF THIS ERROR')
        msgBox.setDetailedText(msg)
        msgBox.show()
        msgBox.exec_()

    def showEntryConfirmation(self, bank, client, amount):
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Information)
        msg.setText("PLEASE CONFIRM THE ENTRY DETAILS:")
        msg.setInformativeText("Client Name : {} \nBank: {}\nAmount: {}".format(client, bank, amount))
        msg.setWindowTitle("Confirm Entry")
        msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
        msg.setDefaultButton(QMessageBox.Ok)
        retval = msg.exec_()
        return retval

    def showSuccessMessage(self):
        msgBox = QMessageBox()
        msgBox.setStyleSheet("QMessageBox{min-width: 700px;}")
        msgBox.setIcon(QMessageBox.Information)
        msgBox.setText('SUCCESS! ')
        msgBox.setInformativeText('ENTRY SUCCESSFULLY MADE. YOU MAY CLOSE THE DIALOGBOX')
        msgBox.show()
        msgBox.exec_()

    def onAddProfile(self):
        self.profileWindow = None
        self.profileWindow = QtWidgets.QMainWindow()
        self.profileWindowUi = Ui_AddProfileWindow()
        self.profileWindowUi.setupUi(self.addProfileWindow)
        self.addProfileWindow.show()


if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)
    EntryWindow = QtWidgets.QMainWindow()
    ui = Ui_EntryWindow()
    ui.setupUi(EntryWindow)
    EntryWindow.show()
    sys.exit(app.exec_())
