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

# Form implementation generated from reading ui file 'ReportWindow/Interfaces/ReportWindow.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.
from os.path import expanduser

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

from Generator import generateReport

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


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_sr_from_state_id(id):
    cursor.execute("SELECT NAME FROM u257284371_vedanya.sr WHERE STATE_ID = {};".format(id))
    return cursor.fetchall()


def fetch_available_states():
    slist = ['']
    cursor.execute("SELECT NAME FROM u257284371_vedanya.states")
    states = cursor.fetchall()
    for x in states:
        for y in x:
            slist.append(str(y))
    return slist


class Ui_ReportsWindow(object):
    def setupUi(self, ReportsWindow):
        ReportsWindow.setObjectName("ReportsWindow")
        ReportsWindow.resize(844, 720)
        font = QtGui.QFont()
        font.setFamily("Yu Gothic Light")
        ReportsWindow.setFont(font)
        ReportsWindow.setStyleSheet("#ReportsWindow{\n"
                                    "background-color: white\n"
                                    "}\n"
                                    "\n"
                                    "#sr_llist_area{\n"
                                    "background-color: white\n"
                                    "}")
        self.centralwidget = QtWidgets.QWidget(ReportsWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setGeometry(QtCore.QRect(3, 10, 1161, 81))
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.static_2 = QtWidgets.QLabel(self.frame)
        self.static_2.setGeometry(QtCore.QRect(10, 3, 75, 75))
        self.static_2.setStyleSheet("border-style: solid;\n"
                                    "border-radius:500px;\n"
                                    "max-width:75px;\n"
                                    "max-height:75px;\n"
                                    "min-width:75px;\n"
                                    "min-height:75px;")
        self.static_2.setText("")
        self.static_2.setPixmap(QtGui.QPixmap("assets/report.png"))
        self.static_2.setScaledContents(True)
        self.static_2.setObjectName("static_2")
        self.label = QtWidgets.QLabel(self.frame)
        self.label.setGeometry(QtCore.QRect(100, -1, 431, 75))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(51)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.static_seperator = QtWidgets.QFrame(self.frame)
        self.static_seperator.setGeometry(QtCore.QRect(93, 0, 1, 80))
        self.static_seperator.setStyleSheet("#static_seperator{\n"
                                            "background-color: rgb(125, 125, 125);\n"
                                            "}")
        self.static_seperator.setFrameShape(QtWidgets.QFrame.VLine)
        self.static_seperator.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.static_seperator.setObjectName("static_seperator")
        self.saveReport = QtWidgets.QPushButton(self.centralwidget)
        self.saveReport.setGeometry(QtCore.QRect(720, 610, 100, 100))
        self.saveReport.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.saveReport.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.saveReport.setText("")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("assets/save.png"),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.saveReport.setIcon(icon)
        self.saveReport.setIconSize(QtCore.QSize(100, 100))
        self.saveReport.setObjectName("saveReport")
        self.toDatePickFrame = QtWidgets.QFrame(self.centralwidget)
        self.toDatePickFrame.setEnabled(True)
        self.toDatePickFrame.setGeometry(QtCore.QRect(440, 366, 381, 231))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.toDatePickFrame.setFont(font)
        self.toDatePickFrame.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.toDatePickFrame.setAutoFillBackground(True)
        self.toDatePickFrame.setStyleSheet("#calendarFrame{\n"
                                           "background-color:rgb(230,230,230);\n"
                                           "border-raduis: 50px;\n"
                                           "}")
        self.toDatePickFrame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.toDatePickFrame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.toDatePickFrame.setObjectName("toDatePickFrame")
        self.toDateCalendar = QtWidgets.QCalendarWidget(self.toDatePickFrame)
        self.toDateCalendar.setGeometry(QtCore.QRect(10, 10, 361, 183))
        self.toDateCalendar.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.toDateCalendar.setStyleSheet("class MyDateEdit : QDateEdit\n"
                                          "{\n"
                                          "  Q_OBJECT\n"
                                          "\n"
                                          "protected:\n"
                                          "  void mouseEvent(QEvent *event) {\n"
                                          "    this.calendarWidget().show();\n"
                                          "  }\n"
                                          "};")
        self.toDateCalendar.setNavigationBarVisible(True)
        self.toDateCalendar.setDateEditEnabled(True)
        self.toDateCalendar.setObjectName("toDateCalendar")
        self.toDateCalendarConfirmBtn = QtWidgets.QPushButton(self.toDatePickFrame)
        self.toDateCalendarConfirmBtn.setGeometry(QtCore.QRect(290, 200, 85, 26))
        self.toDateCalendarConfirmBtn.setAutoFillBackground(False)
        self.toDateCalendarConfirmBtn.setStyleSheet("#confirm_calendar_selection_btn{\n"
                                                    "background-color: white;\n"
                                                    "}")
        self.toDateCalendarConfirmBtn.setAutoDefault(False)
        self.toDateCalendarConfirmBtn.setDefault(False)
        self.toDateCalendarConfirmBtn.setFlat(False)
        self.toDateCalendarConfirmBtn.setObjectName("toDateCalendarConfirmBtn")
        self.fromDatePickFrame = QtWidgets.QFrame(self.centralwidget)
        self.fromDatePickFrame.setEnabled(True)
        self.fromDatePickFrame.setGeometry(QtCore.QRect(20, 366, 381, 231))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.fromDatePickFrame.setFont(font)
        self.fromDatePickFrame.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.fromDatePickFrame.setAutoFillBackground(True)
        self.fromDatePickFrame.setStyleSheet("#calendarFrame{\n"
                                             "background-color:rgb(230,230,230);\n"
                                             "border-raduis: 50px;\n"
                                             "}")
        self.fromDatePickFrame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.fromDatePickFrame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.fromDatePickFrame.setObjectName("fromDatePickFrame")
        self.fromDateCalendar = QtWidgets.QCalendarWidget(self.fromDatePickFrame)
        self.fromDateCalendar.setGeometry(QtCore.QRect(10, 10, 361, 183))
        self.fromDateCalendar.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.fromDateCalendar.setStyleSheet("class MyDateEdit : QDateEdit\n"
                                            "{\n"
                                            "  Q_OBJECT\n"
                                            "\n"
                                            "protected:\n"
                                            "  void mouseEvent(QEvent *event) {\n"
                                            "    this.calendarWidget().show();\n"
                                            "  }\n"
                                            "};")
        self.fromDateCalendar.setNavigationBarVisible(True)
        self.fromDateCalendar.setDateEditEnabled(True)
        self.fromDateCalendar.setObjectName("fromDateCalendar")
        self.fromDateCalendarConfirmBtn = QtWidgets.QPushButton(self.fromDatePickFrame)
        self.fromDateCalendarConfirmBtn.setGeometry(QtCore.QRect(290, 200, 85, 26))
        self.fromDateCalendarConfirmBtn.setAutoFillBackground(False)
        self.fromDateCalendarConfirmBtn.setStyleSheet("#confirm_calendar_selection_btn{\n"
                                                      "background-color: white;\n"
                                                      "}")
        self.fromDateCalendarConfirmBtn.setAutoDefault(False)
        self.fromDateCalendarConfirmBtn.setDefault(False)
        self.fromDateCalendarConfirmBtn.setFlat(False)
        self.fromDateCalendarConfirmBtn.setObjectName("fromDateCalendarConfirmBtn")
        self.static_6 = QtWidgets.QLabel(self.centralwidget)
        self.static_6.setGeometry(QtCore.QRect(30, 336, 61, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(13)
        self.static_6.setFont(font)
        self.static_6.setObjectName("static_6")
        self.fromDateEdit = QtWidgets.QDateEdit(self.centralwidget)
        self.fromDateEdit.setGeometry(QtCore.QRect(100, 340, 110, 21))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.fromDateEdit.setFont(font)
        self.fromDateEdit.setObjectName("fromDateEdit")
        self.static_5 = QtWidgets.QLabel(self.centralwidget)
        self.static_5.setGeometry(QtCore.QRect(440, 336, 61, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(13)
        self.static_5.setFont(font)
        self.static_5.setObjectName("static_5")
        self.toDateEdit = QtWidgets.QDateEdit(self.centralwidget)
        self.toDateEdit.setGeometry(QtCore.QRect(510, 340, 110, 22))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.toDateEdit.setFont(font)
        self.toDateEdit.setObjectName("toDateEdit")
        self.generationOptionBox = QtWidgets.QGroupBox(self.centralwidget)
        self.generationOptionBox.setGeometry(QtCore.QRect(490, 610, 211, 100))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI")
        self.generationOptionBox.setFont(font)
        self.generationOptionBox.setObjectName("generationOptionBox")
        self.BothRadioButton = QtWidgets.QRadioButton(self.generationOptionBox)
        self.BothRadioButton.setGeometry(QtCore.QRect(10, 60, 111, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.BothRadioButton.setFont(font)
        self.BothRadioButton.setObjectName("BothRadioButton")
        self.PDFRadioButton = QtWidgets.QRadioButton(self.generationOptionBox)
        self.PDFRadioButton.setGeometry(QtCore.QRect(10, 20, 90, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.PDFRadioButton.setFont(font)
        self.PDFRadioButton.setObjectName("PDFRadioButton")
        self.ExcelRadioBotton = QtWidgets.QRadioButton(self.generationOptionBox)
        self.ExcelRadioBotton.setGeometry(QtCore.QRect(10, 40, 90, 30))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(10)
        self.ExcelRadioBotton.setFont(font)
        self.ExcelRadioBotton.setObjectName("ExcelRadioBotton")
        self.sr_frame = QtWidgets.QFrame(self.centralwidget)
        self.sr_frame.setGeometry(QtCore.QRect(440, 140, 380, 180))
        font = QtGui.QFont()
        font.setBold(False)
        font.setWeight(50)
        self.sr_frame.setFont(font)
        self.sr_frame.setStyleSheet("background-color: white;\n"
                                    "")
        self.sr_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.sr_frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.sr_frame.setObjectName("sr_frame")
        self.sr_llist_area = QtWidgets.QScrollArea(self.sr_frame)
        self.sr_llist_area.setGeometry(QtCore.QRect(10, 6, 360, 170))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.MinimumExpanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.sr_llist_area.sizePolicy().hasHeightForWidth())
        self.sr_llist_area.setSizePolicy(sizePolicy)
        self.sr_llist_area.setAutoFillBackground(True)
        self.sr_llist_area.setStyleSheet("    \n"
                                         "    QScrollArea {\n"
                                         "        background:white;\n"
                                         "        border: 6px black;\n"
                                         "        background-color: white;\n"
                                         "    }\n"
                                         "\n"
                                         "    QScrollBar {\n"
                                         "        background:white;\n"
                                         "        background: white;\n"
                                         "        border-radius: 5px;\n"
                                         "    }\n"
                                         "\n"
                                         "    QScrollBar:vertical {\n"
                                         "        background:white;\n"
                                         "        width: 13px;\n"
                                         "    }\n"
                                         "\n"
                                         "    QScrollBar::handle:vertical {\n"
                                         "        width: 25px;\n"
                                         "        min-height: 10px;\n"
                                         "    }\n"
                                         "\n"
                                         "    QScrollBar::add-line {\n"
                                         "        border: none;\n"
                                         "        background: none;\n"
                                         "    }\n"
                                         "\n"
                                         "    QScrollBar::sub-line {\n"
                                         "        border: none;\n"
                                         "        background: none;\n"
                                         "    }\n"
                                         "\n"
                                         "\n"
                                         "    QScrollBar::handle {\n"
                                         "        background: rgb(58,168, 138);\n"
                                         "        border-radius: 6px;\n"
                                         "    }\n"
                                         "\n"
                                         "\n"
                                         "\n"
                                         "/* QScrollBar:vertical\n"
                                         " {\n"
                                         "     background-color: rgb(229, 229, 229);\n"
                                         "     width: 15px;\n"
                                         "     margin: 15px 3px 15px 3px;\n"
                                         "     border: 5px white;\n"
                                         "     border-radius: 4px;\n"
                                         " }\n"
                                         "\n"
                                         " QScrollBar::handle:vertical\n"
                                         " {\n"
                                         "     background-color: rgb(58, 168, 138); \n"
                                         "     min-height: 5px;\n"
                                         "     border-radius: 4px;\n"
                                         " }\n"
                                         "\n"
                                         " QScrollBar::sub-line:vertical\n"
                                         " {\n"
                                         "     margin: 3px 0px 3px 0px;\n"
                                         "     border-image: url(:/qss_icons/rc/up_arrow_disabled.png);\n"
                                         "     height: 10px;\n"
                                         "     width: 10px;\n"
                                         "     subcontrol-position: top;\n"
                                         "     subcontrol-origin: margin;\n"
                                         " }\n"
                                         "\n"
                                         " QScrollBar::add-line:vertical\n"
                                         " {\n"
                                         "     margin: 3px 0px 3px 0px;\n"
                                         "     border-image: url(:/qss_icons/rc/down_arrow_disabled.png);\n"
                                         "     height: 10px;\n"
                                         "     width: 10px;\n"
                                         "     subcontrol-position: bottom;\n"
                                         "     subcontrol-origin: margin;\n"
                                         " }\n"
                                         "\n"
                                         " QScrollBar::sub-line:vertical:hover,QScrollBar::sub-line:vertical:on\n"
                                         " {\n"
                                         "\n"
                                         "     border-image: url(:/qss_icons/rc/up_arrow.png);\n"
                                         "     height: 10px;\n"
                                         "     width: 10px;\n"
                                         "     subcontrol-position: top;\n"
                                         "     subcontrol-origin: margin;\n"
                                         " }\n"
                                         "\n"
                                         "\n"
                                         " QScrollBar::add-line:vertical:hover, QScrollBar::add-line:vertical:on\n"
                                         " {\n"
                                         "     border-image: url(:/qss_icons/rc/down_arrow.png);\n"
                                         "     height: 10px;\n"
                                         "     width: 10px;\n"
                                         "     subcontrol-position: bottom;\n"
                                         "     subcontrol-origin: margin;\n"
                                         " }\n"
                                         "\n"
                                         " QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical\n"
                                         " {\n"
                                         "     background: none;\n"
                                         " }\n"
                                         "\n"
                                         "\n"
                                         " QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical\n"
                                         " {\n"
                                         "     background: none;\n"
                                         " }\n"
                                         "\n"
                                         "\n"
                                         "QScrollBar{\n"
                                         "background-color: transparent;\n"
                                         "}")
        self.sr_llist_area.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.sr_llist_area.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.sr_llist_area.setLineWidth(8)
        self.sr_llist_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.sr_llist_area.setWidgetResizable(True)
        self.sr_llist_area.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
        self.sr_llist_area.setObjectName("sr_llist_area")
        self.scrollAreaWidgetContents = QtWidgets.QWidget()
        self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 341, 170))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.scrollAreaWidgetContents.setFont(font)
        self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
        self.vboxlayout = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents)
        self.vboxlayout.setObjectName("vboxlayout")
        self.sr_llist_area.setWidget(self.scrollAreaWidgetContents)
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setGeometry(QtCore.QRect(440, 314, 380, 16))
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.line_2 = QtWidgets.QFrame(self.centralwidget)
        self.line_2.setGeometry(QtCore.QRect(440, 133, 380, 16))
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.line_3 = QtWidgets.QFrame(self.centralwidget)
        self.line_3.setGeometry(QtCore.QRect(440, 140, 3, 180))
        self.line_3.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_3.setObjectName("line_3")
        self.line_4 = QtWidgets.QFrame(self.centralwidget)
        self.line_4.setGeometry(QtCore.QRect(820, 140, 3, 180))
        self.line_4.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_4.setObjectName("line_4")
        self.line_5 = QtWidgets.QFrame(self.centralwidget)
        self.line_5.setGeometry(QtCore.QRect(380, 150, 3, 170))
        self.line_5.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_5.setObjectName("line_5")
        self.line_6 = QtWidgets.QFrame(self.centralwidget)
        self.line_6.setGeometry(QtCore.QRect(20, 143, 361, 16))
        self.line_6.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_6.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_6.setObjectName("line_6")
        self.line_7 = QtWidgets.QFrame(self.centralwidget)
        self.line_7.setGeometry(QtCore.QRect(20, 314, 361, 16))
        self.line_7.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_7.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_7.setObjectName("line_7")
        self.line_8 = QtWidgets.QFrame(self.centralwidget)
        self.line_8.setGeometry(QtCore.QRect(20, 150, 3, 170))
        self.line_8.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_8.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_8.setObjectName("line_8")
        self.state_frame = QtWidgets.QFrame(self.centralwidget)
        self.state_frame.setGeometry(QtCore.QRect(21, 151, 359, 170))
        font = QtGui.QFont()
        font.setBold(False)
        font.setWeight(50)
        self.state_frame.setFont(font)
        self.state_frame.setStyleSheet("background-color: white;\n"
                                       "")
        self.state_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.state_frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.state_frame.setObjectName("state_frame")
        self.state_list_area = QtWidgets.QScrollArea(self.state_frame)
        self.state_list_area.setGeometry(QtCore.QRect(10, 4, 341, 161))
        self.state_list_area.setAutoFillBackground(True)
        self.state_list_area.setStyleSheet("    \n"
                                           "    QScrollArea {\n"
                                           "        background:white;\n"
                                           "        border: 6px black;\n"
                                           "        background-color: white;\n"
                                           "    }\n"
                                           "\n"
                                           "    QScrollBar {\n"
                                           "        background:white;\n"
                                           "        background: white;\n"
                                           "        border-radius: 5px;\n"
                                           "    }\n"
                                           "\n"
                                           "    QScrollBar:vertical {\n"
                                           "        background:white;\n"
                                           "        width: 13px;\n"
                                           "    }\n"
                                           "\n"
                                           "    QScrollBar::handle:vertical {\n"
                                           "        width: 25px;\n"
                                           "        min-height: 10px;\n"
                                           "    }\n"
                                           "\n"
                                           "    QScrollBar::add-line {\n"
                                           "        border: none;\n"
                                           "        background: none;\n"
                                           "    }\n"
                                           "\n"
                                           "    QScrollBar::sub-line {\n"
                                           "        border: none;\n"
                                           "        background: none;\n"
                                           "    }\n"
                                           "\n"
                                           "\n"
                                           "    QScrollBar::handle {\n"
                                           "        background: rgb(58,168, 138);\n"
                                           "        border-radius: 6px;\n"
                                           "    }\n"
                                           "\n"
                                           "\n"
                                           "\n"
                                           "/* QScrollBar:vertical\n"
                                           " {\n"
                                           "     background-color: rgb(229, 229, 229);\n"
                                           "     width: 15px;\n"
                                           "     margin: 15px 3px 15px 3px;\n"
                                           "     border: 5px white;\n"
                                           "     border-radius: 4px;\n"
                                           " }\n"
                                           "\n"
                                           " QScrollBar::handle:vertical\n"
                                           " {\n"
                                           "     background-color: rgb(58, 168, 138); \n"
                                           "     min-height: 5px;\n"
                                           "     border-radius: 4px;\n"
                                           " }\n"
                                           "\n"
                                           " QScrollBar::sub-line:vertical\n"
                                           " {\n"
                                           "     margin: 3px 0px 3px 0px;\n"
                                           "     border-image: url(:/qss_icons/rc/up_arrow_disabled.png);\n"
                                           "     height: 10px;\n"
                                           "     width: 10px;\n"
                                           "     subcontrol-position: top;\n"
                                           "     subcontrol-origin: margin;\n"
                                           " }\n"
                                           "\n"
                                           " QScrollBar::add-line:vertical\n"
                                           " {\n"
                                           "     margin: 3px 0px 3px 0px;\n"
                                           "     border-image: url(:/qss_icons/rc/down_arrow_disabled.png);\n"
                                           "     height: 10px;\n"
                                           "     width: 10px;\n"
                                           "     subcontrol-position: bottom;\n"
                                           "     subcontrol-origin: margin;\n"
                                           " }\n"
                                           "\n"
                                           " QScrollBar::sub-line:vertical:hover,QScrollBar::sub-line:vertical:on\n"
                                           " {\n"
                                           "\n"
                                           "     border-image: url(:/qss_icons/rc/up_arrow.png);\n"
                                           "     height: 10px;\n"
                                           "     width: 10px;\n"
                                           "     subcontrol-position: top;\n"
                                           "     subcontrol-origin: margin;\n"
                                           " }\n"
                                           "\n"
                                           "\n"
                                           " QScrollBar::add-line:vertical:hover, QScrollBar::add-line:vertical:on\n"
                                           " {\n"
                                           "     border-image: url(:/qss_icons/rc/down_arrow.png);\n"
                                           "     height: 10px;\n"
                                           "     width: 10px;\n"
                                           "     subcontrol-position: bottom;\n"
                                           "     subcontrol-origin: margin;\n"
                                           " }\n"
                                           "\n"
                                           " QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical\n"
                                           " {\n"
                                           "     background: none;\n"
                                           " }\n"
                                           "\n"
                                           "\n"
                                           " QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical\n"
                                           " {\n"
                                           "     background: none;\n"
                                           " }\n"
                                           "\n"
                                           "\n"
                                           "QScrollBar{\n"
                                           "background-color: transparent;\n"
                                           "}")
        self.state_list_area.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.state_list_area.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.state_list_area.setLineWidth(8)
        self.state_list_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.state_list_area.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        self.state_list_area.setWidgetResizable(True)
        self.state_list_area.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
        self.state_list_area.setObjectName("state_list_area")
        self.scrollAreaWidgetContents_2 = QtWidgets.QWidget()
        self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, 0, 322, 161))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.scrollAreaWidgetContents_2.setFont(font)
        self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
        self._2 = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents_2)
        self._2.setObjectName("_2")
        font = QtGui.QFont()
        font.setPointSize(11)
        self.state_list_area.setWidget(self.scrollAreaWidgetContents_2)
        self.static_7 = QtWidgets.QLabel(self.centralwidget)
        self.static_7.setGeometry(QtCore.QRect(20, 94, 141, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(13)
        self.static_7.setFont(font)
        self.static_7.setObjectName("static_7")
        self.static_8 = QtWidgets.QLabel(self.centralwidget)
        self.static_8.setGeometry(QtCore.QRect(440, 94, 141, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI Light")
        font.setPointSize(13)
        self.static_8.setFont(font)
        self.static_8.setObjectName("static_8")
        self.stateSelectionBox = QtWidgets.QComboBox(self.centralwidget)
        self.stateSelectionBox.setGeometry(QtCore.QRect(20, 120, 361, 26))
        self.stateSelectionBox.setObjectName("stateSelectionBox")
        self.frame.raise_()
        self.saveReport.raise_()
        self.static_6.raise_()
        self.fromDateEdit.raise_()
        self.static_5.raise_()
        self.toDateEdit.raise_()
        self.generationOptionBox.raise_()
        self.fromDatePickFrame.raise_()
        self.toDatePickFrame.raise_()
        self.sr_frame.raise_()
        self.line.raise_()
        self.line_2.raise_()
        self.line_3.raise_()
        self.line_4.raise_()
        self.line_5.raise_()
        self.line_6.raise_()
        self.line_7.raise_()
        self.line_8.raise_()
        self.state_frame.raise_()
        self.static_7.raise_()
        self.static_8.raise_()
        self.stateSelectionBox.raise_()
        ReportsWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(ReportsWindow)
        QtCore.QMetaObject.connectSlotsByName(ReportsWindow)
        # Custom Code Below

        self.current_states_by_sr = {}
        self.checkedStates = []
        self.checked_sr = []
        self.addedStates = []
        self.sr_llist_area.setWidget(self.scrollAreaWidgetContents)
        self.toDate = ''
        self.fromDate = ''

        # fill states
        self.stateSelectionBox.addItems(fetch_available_states())
        self.stateSelectionBox.currentTextChanged.connect(lambda: self.addState(self.stateSelectionBox.currentText()))
        self.saveReport.clicked.connect(self.onReportSave)
        self.fromDateEdit.setReadOnly(True)
        self.toDateEdit.setReadOnly(True)
        self.fromDateCalendarConfirmBtn.setHidden(True)
        self.toDateCalendarConfirmBtn.setHidden(True)
        self.toDateCalendar.setMaximumDate(QDate.currentDate())
        self.fromDateCalendar.setMaximumDate(QDate.currentDate())
        self.fromDateCalendar.selectionChanged.connect(self.fromDateConfirm)
        self.toDateCalendar.selectionChanged.connect(self.toDateConfirm)

    def retranslateUi(self, ReportsWindow):
        _translate = QtCore.QCoreApplication.translate
        ReportsWindow.setWindowTitle(_translate("ReportsWindow", "MainWindow"))
        self.label.setText(_translate("ReportsWindow", "REPORTS"))
        self.toDateCalendarConfirmBtn.setText(_translate("ReportsWindow", "OK"))
        self.fromDateCalendarConfirmBtn.setText(_translate("ReportsWindow", "OK"))
        self.static_6.setText(_translate("ReportsWindow", "FROM:"))
        self.static_5.setText(_translate("ReportsWindow", "TO:"))
        self.generationOptionBox.setTitle(_translate("ReportsWindow", "GENERATION OPTIONS:"))
        self.BothRadioButton.setText(_translate("ReportsWindow", "PDF + EXCEL"))
        self.PDFRadioButton.setText(_translate("ReportsWindow", "PDF"))
        self.ExcelRadioBotton.setText(_translate("ReportsWindow", "EXCEL"))
        self.static_7.setText(_translate("ReportsWindow", "SELECT STATES:"))
        self.static_8.setText(_translate("ReportsWindow", "SELECT SR(S):"))

    def raise_error(self):
        assert False

    def fromDateConfirm(self):
        self.fromDateEdit.setDate(self.fromDateCalendar.selectedDate())
        self.fromDate = self.fromDateEdit.date().toPyDate()

    def toDateConfirm(self):
        self.toDateEdit.setDate(self.toDateCalendar.selectedDate())
        self.toDate = self.toDateEdit.date().toPyDate()

    def onReportSave(self):
        reportRawData = {}
        for package in self.current_states_by_sr.values():
            sr_s = []
            if package[1] is not None:
                for sr_cb in package[1][1]:
                    if sr_cb.isChecked() and sr_cb.isEnabled:
                        sr_s.append(sr_cb.text())
            if package[0].isChecked() and package[0].isEnabled():
                reportRawData[package[0].text()] = sr_s
        print(reportRawData)
        self.save(reportRawData)

    def save(self, reportRawData):
        home = expanduser("~\\Documents\\")
        filename = QFileDialog.getSaveFileName(directory=home, filter='EXCEL Files (*.xlsx)')
        print(filename[0])
        if filename[0]:
            print('😁')
            print(filename[0])
            path = filename[0]
            result = generateReport(self.fromDate, self.toDate, reportRawData, path)
            print(path)
            print(reportRawData)
            if result == 1:
                msgBox = QMessageBox()
                msgBox.setStyleSheet("QMessageBox{min-width: 700px;}")
                msgBox.setIcon(QMessageBox.Warning)
                msgBox.setText('FILE IS BEING USED BY ANOTHER PROGRAM')
                msgBox.setInformativeText('PLEASE TRY TO SAVE WITH ANOTHER NAME')
                msgBox.show()
                msgBox.exec_()
            if result != 0:
                self.save(reportRawData)

    def addState(self, state):
        if state not in self.current_states_by_sr.keys() or state not in self.checkedStates and state not in self.addedStates:
            self.current_states_by_sr[state] = self.makeDictObject(state)
            self._2.addWidget(self.current_states_by_sr[state][0])
            self.current_states_by_sr[state][0].clicked.connect(
                lambda: self.stateUnchecked(self.current_states_by_sr[state][0])
            )
            if state not in self.addedStates:
                self.addedStates.append(state)
            if state not in self.checkedStates and self.current_states_by_sr[state][1] is not None:
                self.checkedStates.append(state)
            if self.current_states_by_sr[state][1] is not None:
                self.vboxlayout.addWidget(self.current_states_by_sr[state][1][0])
                for srBx in self.current_states_by_sr[state][1][1]:
                    self.vboxlayout.addWidget(srBx)
                    srBx.clicked.connect(lambda: self.onSRBoxChanged(state))
                    if srBx.text() not in self.checked_sr:
                        self.checked_sr.append(srBx.text())
            if self.current_states_by_sr[state][1] is None:
                self.current_states_by_sr[state][0].setChecked(False)
                self.current_states_by_sr[state][0].setText('{} (No SR)'.format(state))
                self.current_states_by_sr[state][0].setEnabled(False)
            self.refreshScrollStyles()

    def onSRBoxChanged(self, state):
        pass

    def stateUnchecked(self, stBx):
        if not stBx.isChecked():
            state = stBx.text()
            self.checkedStates.remove(state)
            self.current_states_by_sr[state][1][0].setHidden(True)
            for sr_cbs in self.current_states_by_sr[state][1][1]:
                sr_cbs.setChecked(False)
                sr_cbs.setHidden(True)
        if stBx.isChecked():
            state = stBx.text()
            self.checkedStates.append(state)
            self.current_states_by_sr[state][1][0].setHidden(False)
            for sr_cbs in self.current_states_by_sr[state][1][1]:
                sr_cbs.setHidden(False)
                sr_cbs.setChecked(True)

    def makeDictObject(self, state):
        st_cbo = self.createStateCheckBoxObject(state)
        SRPkg = self.generateStateBySRPackage(state)
        if not SRPkg is None:
            st_lbl = SRPkg[0]
            sr_cbs = SRPkg[1]
            return [st_cbo, [st_lbl, sr_cbs]]
        else:
            return [st_cbo, None]

    def createStateCheckBoxObject(self, state_name):
        _translate = QtCore.QCoreApplication.translate
        newStateObject = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setFamily('Yu Gothic UI Light')
        newStateObject.setFont(font)
        newStateObject.setObjectName(state_name)
        newStateObject.setText(state_name)
        newStateObject.setFixedHeight(16)
        newStateObject.setChecked(True)
        return newStateObject

    def generateStateBySRPackage(self, state):
        assigned_sr = get_sr_from_state_id(get_state_id_by_name(state))
        if not assigned_sr:
            return None
        stateLabel = QtWidgets.QLabel(self.scrollAreaWidgetContents)
        stateLabel.setMaximumSize(QtCore.QSize(16777215, 25))
        font = QtGui.QFont()
        font.setFamily("Yu Gothic UI")
        font.setPointSize(9)
        stateLabel.setFont(font)
        stateLabel.setObjectName(state)
        stateLabel.setText(state)

        srs = []
        for sr in assigned_sr:
            sr_name = str(sr[0])
            newSRObject = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
            font = QtGui.QFont()
            font.setPointSize(10)
            font.setFamily('Yu Gothic UI Light')
            newSRObject.setFont(font)
            newSRObject.setObjectName(sr_name)
            newSRObject.setText(sr_name)
            newSRObject.setFixedHeight(16)
            newSRObject.setChecked(True)
            newSRObject.clicked.connect(lambda: self.onSRBoxChanged(sr_name))
            srs.append(newSRObject)

        return [stateLabel, srs]

    def refreshScrollStyles(self):
        self.state_list_area.setStyleSheet("    \n"
                                           "    QScrollArea {\n"
                                           "        background:white;\n"
                                           "        border: 6px black;\n"
                                           "        background-color: white;\n"
                                           "    }\n"
                                           "\n"
                                           "    QScrollBar {\n"
                                           "        background:white;\n"
                                           "        background: white;\n"
                                           "        border-radius: 5px;\n"
                                           "    }\n"
                                           "\n"
                                           "    QScrollBar:vertical {\n"
                                           "        background:white;\n"
                                           "        width: 13px;\n"
                                           "    }\n"
                                           "\n"
                                           "    QScrollBar::handle:vertical {\n"
                                           "        width: 25px;\n"
                                           "        min-height: 10px;\n"
                                           "    }\n"
                                           "\n"
                                           "    QScrollBar::add-line {\n"
                                           "        border: none;\n"
                                           "        background: none;\n"
                                           "    }\n"
                                           "\n"
                                           "    QScrollBar::sub-line {\n"
                                           "        border: none;\n"
                                           "        background: none;\n"
                                           "    }\n"
                                           "\n"
                                           "\n"
                                           "    QScrollBar::handle {\n"
                                           "        background: rgb(58,168, 138);\n"
                                           "        border-radius: 6px;\n"
                                           "    }\n"
                                           "\n"
                                           "\n"
                                           "\n"
                                           "/* QScrollBar:vertical\n"
                                           " {\n"
                                           "     background-color: rgb(229, 229, 229);\n"
                                           "     width: 15px;\n"
                                           "     margin: 15px 3px 15px 3px;\n"
                                           "     border: 5px white;\n"
                                           "     border-radius: 4px;\n"
                                           " }\n"
                                           "\n"
                                           " QScrollBar::handle:vertical\n"
                                           " {\n"
                                           "     background-color: rgb(58, 168, 138); \n"
                                           "     min-height: 5px;\n"
                                           "     border-radius: 4px;\n"
                                           " }\n"
                                           "\n"
                                           " QScrollBar::sub-line:vertical\n"
                                           " {\n"
                                           "     margin: 3px 0px 3px 0px;\n"
                                           "     border-image: url(:/qss_icons/rc/up_arrow_disabled.png);\n"
                                           "     height: 10px;\n"
                                           "     width: 10px;\n"
                                           "     subcontrol-position: top;\n"
                                           "     subcontrol-origin: margin;\n"
                                           " }\n"
                                           "\n"
                                           " QScrollBar::add-line:vertical\n"
                                           " {\n"
                                           "     margin: 3px 0px 3px 0px;\n"
                                           "     border-image: url(:/qss_icons/rc/down_arrow_disabled.png);\n"
                                           "     height: 10px;\n"
                                           "     width: 10px;\n"
                                           "     subcontrol-position: bottom;\n"
                                           "     subcontrol-origin: margin;\n"
                                           " }\n"
                                           "\n"
                                           " QScrollBar::sub-line:vertical:hover,QScrollBar::sub-line:vertical:on\n"
                                           " {\n"
                                           "\n"
                                           "     border-image: url(:/qss_icons/rc/up_arrow.png);\n"
                                           "     height: 10px;\n"
                                           "     width: 10px;\n"
                                           "     subcontrol-position: top;\n"
                                           "     subcontrol-origin: margin;\n"
                                           " }\n"
                                           "\n"
                                           "\n"
                                           " QScrollBar::add-line:vertical:hover, QScrollBar::add-line:vertical:on\n"
                                           " {\n"
                                           "     border-image: url(:/qss_icons/rc/down_arrow.png);\n"
                                           "     height: 10px;\n"
                                           "     width: 10px;\n"
                                           "     subcontrol-position: bottom;\n"
                                           "     subcontrol-origin: margin;\n"
                                           " }\n"
                                           "\n"
                                           " QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical\n"
                                           " {\n"
                                           "     background: none;\n"
                                           " }\n"
                                           "\n"
                                           "\n"
                                           " QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical\n"
                                           " {\n"
                                           "     background: none;\n"
                                           " }\n"
                                           "\n"
                                           "\n"
                                           "QScrollBar{\n"
                                           "background-color: transparent;\n"
                                           "}")
        self.sr_llist_area.setStyleSheet("    \n"
                                         "    QScrollArea {\n"
                                         "        background:white;\n"
                                         "        border: 6px black;\n"
                                         "        background-color: white;\n"
                                         "    }\n"
                                         "\n"
                                         "    QScrollBar {\n"
                                         "        background:white;\n"
                                         "        background: white;\n"
                                         "        border-radius: 5px;\n"
                                         "    }\n"
                                         "\n"
                                         "    QScrollBar:vertical {\n"
                                         "        background:white;\n"
                                         "        width: 13px;\n"
                                         "    }\n"
                                         "\n"
                                         "    QScrollBar::handle:vertical {\n"
                                         "        width: 25px;\n"
                                         "        min-height: 10px;\n"
                                         "    }\n"
                                         "\n"
                                         "    QScrollBar::add-line {\n"
                                         "        border: none;\n"
                                         "        background: none;\n"
                                         "    }\n"
                                         "\n"
                                         "    QScrollBar::sub-line {\n"
                                         "        border: none;\n"
                                         "        background: none;\n"
                                         "    }\n"
                                         "\n"
                                         "\n"
                                         "    QScrollBar::handle {\n"
                                         "        background: rgb(58,168, 138);\n"
                                         "        border-radius: 6px;\n"
                                         "    }\n"
                                         "\n"
                                         "\n"
                                         "\n"
                                         "/* QScrollBar:vertical\n"
                                         " {\n"
                                         "     background-color: rgb(229, 229, 229);\n"
                                         "     width: 15px;\n"
                                         "     margin: 15px 3px 15px 3px;\n"
                                         "     border: 5px white;\n"
                                         "     border-radius: 4px;\n"
                                         " }\n"
                                         "\n"
                                         " QScrollBar::handle:vertical\n"
                                         " {\n"
                                         "     background-color: rgb(58, 168, 138); \n"
                                         "     min-height: 5px;\n"
                                         "     border-radius: 4px;\n"
                                         " }\n"
                                         "\n"
                                         " QScrollBar::sub-line:vertical\n"
                                         " {\n"
                                         "     margin: 3px 0px 3px 0px;\n"
                                         "     border-image: url(:/qss_icons/rc/up_arrow_disabled.png);\n"
                                         "     height: 10px;\n"
                                         "     width: 10px;\n"
                                         "     subcontrol-position: top;\n"
                                         "     subcontrol-origin: margin;\n"
                                         " }\n"
                                         "\n"
                                         " QScrollBar::add-line:vertical\n"
                                         " {\n"
                                         "     margin: 3px 0px 3px 0px;\n"
                                         "     border-image: url(:/qss_icons/rc/down_arrow_disabled.png);\n"
                                         "     height: 10px;\n"
                                         "     width: 10px;\n"
                                         "     subcontrol-position: bottom;\n"
                                         "     subcontrol-origin: margin;\n"
                                         " }\n"
                                         "\n"
                                         " QScrollBar::sub-line:vertical:hover,QScrollBar::sub-line:vertical:on\n"
                                         " {\n"
                                         "\n"
                                         "     border-image: url(:/qss_icons/rc/up_arrow.png);\n"
                                         "     height: 10px;\n"
                                         "     width: 10px;\n"
                                         "     subcontrol-position: top;\n"
                                         "     subcontrol-origin: margin;\n"
                                         " }\n"
                                         "\n"
                                         "\n"
                                         " QScrollBar::add-line:vertical:hover, QScrollBar::add-line:vertical:on\n"
                                         " {\n"
                                         "     border-image: url(:/qss_icons/rc/down_arrow.png);\n"
                                         "     height: 10px;\n"
                                         "     width: 10px;\n"
                                         "     subcontrol-position: bottom;\n"
                                         "     subcontrol-origin: margin;\n"
                                         " }\n"
                                         "\n"
                                         " QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical\n"
                                         " {\n"
                                         "     background: none;\n"
                                         " }\n"
                                         "\n"
                                         "\n"
                                         " QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical\n"
                                         " {\n"
                                         "     background: none;\n"
                                         " }\n"
                                         "\n"
                                         "\n"
                                         "QScrollBar{\n"
                                         "background-color: transparent;\n"
                                         "}")


if __name__ == "__main__":
    import sys, traceback


    def excepthook(exc_type, exc_value, exc_tb):
        tb = "".join(traceback.format_exception(exc_type, exc_value, exc_tb))
        print("error catched!:")
        print("error message:\n", tb)
        QtWidgets.QApplication.quit()
        # or QtWidgets.QApplication.exit(0)


    sys.excepthook = excepthook
    app = QtWidgets.QApplication(sys.argv)
    ReportsWindow = QtWidgets.QMainWindow()
    ui = Ui_ReportsWindow()
    ui.setupUi(ReportsWindow)
    ReportsWindow.show()
    sys.exit(app.exec_())
