def add(self):
        """This method is automatically called on clicking 'Add Designation' button

        This first checks if all inputs are valid. If any of the inputs are invalid, error message
        is shown for the first invalid input, else a new Designation object is created from available info.
        This Employee object is then passed to addEmployee() function of DatabaseManager which adds
        a new designation record in the database.
        """
        valid = True

        for i in range(len(self.inputs)):
            if not self.inputs[i].isValid():
                QMessageBox(QMessageBox.Information,
                            "Error",
                            self.inputs[i].getErrorMessage(),
                            parent=self).exec_()
                valid = False
                break
        if valid:
            desg = Designation(self.designation.text(), self.da.text(),
                               self.hra.text(), self.ta.text(), self.it.text(),
                               self.pt.text())
            try:
                Database.getdb().addDesignation(desg)
                QMessageBox(QMessageBox.NoIcon,
                            "Success",
                            "Designation added successfully",
                            parent=self).exec_()
                self.goBack()

            except mysql.connector.Error as e:
                ShowMysqlError(e, self)
    def removeEmployee(self):
        """Automatically called on clicking 'Remove Employee' button"""

        if str(self.id.currentText()) == "":
            msg = QtGui.QMessageBox(QtGui.QMessageBox.Information, "Error!!!", "First enter all the information", parent=self)
            msg.exec_()
        else:
            choice = QtGui.QMessageBox.question(self, 'Remove Confirmation!!!',
                                                "Are you sure you want to delete this employee?\nName: " + str(
                                                    self.name.text()) + "\nID: " +
                                                    self.id.currentText() + "\nDesignation: " + str(
                                                    self.designation.text()),
                                                QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
            if choice == QtGui.QMessageBox.Yes:
                try:
                    Database.getdb().delEmployee(self.id.currentText())
                    msg = QtGui.QMessageBox(QtGui.QMessageBox.NoIcon, "Success", "Deleted Successfully", parent=self)
                    msg.exec_()
                    # reload name list
                    self.name.clear()
                    nameList = Database.getdb().getEmployeeNameList()
                    self.name.addItems(nameList)
                    self.name.setCurrentIndex(-1)

                except Exception as e:
                    raise e
Esempio n. 3
0
    def save(self):
        valid = True
        if len(self.id.currentText()) == 0:
            QMessageBox(QMessageBox.Information,
                        "Error",
                        "Please select name and ID!",
                        parent=self).exec_()
            valid = False
        else:
            for i in range(len(self.inputs)):
                if not self.inputs[i].isValid():
                    valid = False
                    QtGui.QMessageBox(QtGui.QMessageBox.Information,
                                      "Error",
                                      self.inputs[i].getErrorMessage(),
                                      parent=self).exec_()
                    break

        if valid:
            emp = Employee(self.id.currentText(), self.nameEdit.text(),
                           self.designation.currentText(),
                           self.originalPay.text(),
                           self.originalPayGrade.text(), self.DOJ.getDate(),
                           self.pan.text())
            try:
                Database.getdb().editEmployee(emp)
            except mysql.connector.Error as e:
                ShowMysqlError(e, self)
                return

            QMessageBox(QMessageBox.NoIcon,
                        "Success",
                        "Employee edited successfully",
                        parent=self).exec_()
Esempio n. 4
0
 def changeDetails(self):
     origDesig = self.chooseDesignation.currentText()
     valid = True
     if len(origDesig) == 0:
         QtGui.QMessageBox(QtGui.QMessageBox.Information,
                           "Error",
                           "Please select a Designation to edit!",
                           parent=self).exec_()
         valid = False
     else:
         for i in range(len(self.inputs)):
             if not self.inputs[i].isValid():
                 QtGui.QMessageBox(QtGui.QMessageBox.Information,
                                   "Error",
                                   self.inputs[i].getErrorMessage(),
                                   parent=self).exec_()
                 valid = False
                 break
     if valid:
         desig = Designation(self.designation.text(), self.da.text(),
                             self.hra.text(), self.ta.text(),
                             self.it.text(), self.pt.text())
         try:
             Database.getdb().editDesignationInfo(desig, origDesig)
             self.loadDesignations()
             self.clearInfo()
         except mysql.connector.Error as e:
             ShowMysqlError(e, self)
             return
         QtGui.QMessageBox(QtGui.QMessageBox.NoIcon,
                           "Success",
                           "Designation edited successfully",
                           parent=self).exec_()
Esempio n. 5
0
    def add(self):
        """This method is automatically called on clicking 'Add Employee' button

        This first checks if all inputs are valid. If any of the inputs are invalid, error message
        is shown for the first invalid input, else a new Employee object is created from available info.
        This Employee object is then passed to addEmployee() function of DatabaseManager which adds
        a new employee record in the database.
        """

        valid = True
        for i in range(len(self.inputs)):
            if not self.inputs[i].isValid():
                valid = False
                QtGui.QMessageBox(QtGui.QMessageBox.Information, "Error", self.inputs[i].getErrorMessage(),
                                        parent=self).exec_()
                break

        if valid:
            emp = Employee(self.id.text(),
                           self.name.text(),
                           self.designation.currentText(),
                           self.originalPay.text(),
                           self.gradePay.text(),
                           self.DOJ.getDate(),
                           self.pan.text())
            try:
                Database.getdb().addEmployee(emp)
                QtGui.QMessageBox(QtGui.QMessageBox.NoIcon, "Success", "Employee added successfully",
                                  parent=self).exec_()
                self.goBack()
            except mysql.connector.Error as e:
                ShowMysqlError(e, self)
                return
Esempio n. 6
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.__parent = parent
        self.title = "Add Employee"

        self.id = ValidatingLineEdit("ID", "[a-zA-Z0-9-_]+", self)
        self.name = ValidatingLineEdit("Name", "[a-zA-Z\s]+", self)
        self.designation = QtGui.QComboBox(self)
        self.designation.addItems(Database.getdb().getDesignations())
        self.originalPay = ValidatingLineEdit("Original Pay", QtGui.QDoubleValidator(), self)
        self.gradePay = ValidatingLineEdit("Grade Pay", QtGui.QDoubleValidator(), self)
        self.DOJ = DatePicker(self)
        self.pan = ValidatingLineEdit("PAN", "[A-Z]{5}\d{4}[A-Z]", self)
        self.pan.textEdited.connect(lambda s: self.pan.setText(str(s).upper()))

        # inputs whos validity needs to checked are put in a list
        # so that we can loop through them to check validity
        self.inputs = [self.id, self.name, self.originalPay, self.gradePay, self.pan]

        self.bttnAddEmployee = QtGui.QPushButton("Add Employee")
        self.bttnCancel = QtGui.QPushButton("Cancel")
        self.bttnAddEmployee.setObjectName("OkButton")
        self.bttnCancel.setObjectName("CancelButton")
        self.bttnCancel.clicked.connect(self.goBack)
        self.bttnAddEmployee.clicked.connect(self.add)

        self.setupUI()
    def __init__(self, parent=None):
        super(DelEmployeeWidget, self).__init__(parent)
        self.__parent = parent
        self.title = "Delete Employee"
        self.idList = []

        nameList = Database.getdb().getEmployeeNameList()
        self.name = SearchBox(self, nameList)
        self.name.setPlaceholderText("Enter Name")

        self.name.returnPressed.connect(self.setIdList)

        self.id = QtGui.QComboBox()
        self.id.currentIndexChanged.connect(lambda: self.updateInformation(self.id.currentText()))

        self.designation = QtGui.QLineEdit()
        self.designation.setReadOnly(True)
        self.joinDate = QtGui.QLineEdit()
        self.joinDate.setReadOnly(True)
        self.panNo = QtGui.QLineEdit()
        self.panNo.setReadOnly(True)

        self.remove = QtGui.QPushButton("Remove Employee")
        self.remove.clicked.connect(self.removeEmployee)
        self.remove.setObjectName("CancelButton")

        self.back = QtGui.QPushButton("Back")
        self.back.clicked.connect(self.goBack)
        self.back.setObjectName("OkButton")

        self.setupUI()
Esempio n. 8
0
 def loadInfo(self, designation):
     if designation != "":
         self.designation.setText(designation)
         desig = Database.getdb().getDesignationInfo(designation)
         self.da.setText(str(desig.da))
         self.hra.setText(str(desig.hra))
         self.ta.setText(str(desig.ta))
         self.it.setText(str(desig.it))
         self.pt.setText(str(desig.pt))
Esempio n. 9
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.__parent = parent
        self.title = "Edit Employee"

        # ------elements for selecting employee-----------
        self.nameSearch = SearchBox(self)
        self.nameSearch.setPlaceholderText("Enter Name")

        self.nameList = []
        self.nameList = Database.getdb().getEmployeeNameList()
        self.nameSearch.setList(self.nameList)
        self.nameSearch.setCurrentIndex(-1)

        self.id = QComboBox()
        self.id.currentIndexChanged.connect(
            lambda: self.loadInfo(self.id.currentText()))
        self.nameSearch.returnPressed.connect(self.setIDList)

        # ------elements for ediiting employee-----------
        self.nameEdit = ValidatingLineEdit("Name", "[a-zA-Z\s]+", self)
        self.designation = QComboBox(self)
        self.originalPay = ValidatingLineEdit("Original Pay",
                                              QDoubleValidator(), self)
        self.originalPayGrade = ValidatingLineEdit("Original Pay Grade",
                                                   QDoubleValidator(), self)
        self.DOJ = DatePicker(self)
        self.pan = ValidatingLineEdit("PAN", "[A-Z]{5}\d{4}[A-Z]", self)
        self.inputs = [
            self.nameEdit, self.originalPay, self.originalPayGrade, self.pan
        ]

        self.bttnSave = QPushButton("Save Changes")
        self.bttnCancel = QPushButton("Back")
        self.bttnSave.setObjectName("OkButton")
        self.bttnCancel.setObjectName("CancelButton")
        self.bttnCancel.clicked.connect(self.goBack)
        self.bttnSave.clicked.connect(self.save)

        self.designation.addItems(Database.getdb().getDesignations())
        self.nameSearch.editTextChanged.connect(self.clearInfo)
        self.clearInfo()

        self.setupUI()
    def setIdList(self, name):
        """Loads IDs of all employees with given name into the ID dropdown box

        This function is automatically called after selecting a name from the GUI

        Args:
            name (str): Name of employee
        """
        self.id.clear()
        self.id.addItems(Database.getdb().getIdListForName(name))
Esempio n. 11
0
 def printSlip(self):
     try:
         Database.getdb().saveSalary(self.salary)
         printPaySlip(*self.salary.result())
     except mysql.connector.Error as e:
         if e.errno == errorcode.ER_DUP_ENTRY:
             choice = QtGui.QMessageBox.question(
                 self, 'Replace?',
                 "Salary calculation of " + self.salary.id + " for " +
                 self.salary.month + ", " + str(self.salary.year) +
                 " already exists! Do you want to replace it?",
                 QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
             if choice == QtGui.QMessageBox.Yes:
                 try:
                     Database.getdb().replaceSalary(self.salary)
                     printPaySlip(*self.salary.result())
                 except mysql.connector.Error as e:
                     ShowMysqlError(e)
         else:
             ShowMysqlError(e)
Esempio n. 12
0
 def doLogin(self):
     try:
         # if DatabaseManager.db.checkLogin(self.username.text(), self.password.text()):
         if Database.getdb().checkLogin(self.username.text(),
                                        self.password.text()):
             if self._parent is not None:
                 self._parent.gotoPage("Home")
         else:
             QtGui.QMessageBox.warning(self, 'Error',
                                       'Bad user or password')
     except mysql.connector.Error as e:
         ShowMysqlError(e, self)
Esempio n. 13
0
    def loadInfo(self, id):
        print "id =", id, "...", len(id)
        if id != '':
            emp = Database.getdb().getEmployeeInfo(id)
            self.nameEdit.setText(emp.name)
            self.designation.setCurrentIndex(
                self.designation.findText(emp.designation))
            self.originalPay.setText(str(emp.originalPay))
            self.originalPayGrade.setText(str(emp.originalPayGrade))
            self.DOJ.setDate(emp.getQDate())
            self.pan.setText(emp.pan)

            self.setInputReadOnly(False)
    def updateInformation(self, id):
        """Loads info for given ID in the GUI boxes. This automatically called on selecting an ID from GUI

        Args:
            id (str): ID of employee who's info needs to be loaded
        """

        emp = Database.getdb().getEmployeeInfo(id)
        if emp is None:
            self.clearInfo()
        else:
            self.designation.setText(emp.designation)
            self.joinDate.setText(emp.getStrDate())
            self.panNo.setText(emp.pan)
Esempio n. 15
0
    def loadInfo(self, id):
        """Loads info for given ID in the GUI boxes. This automatically called on selecting an ID from GUI

        Args:
            id (str): ID of employee who's info needs to be loaded
        """
        print "id =", id, "...", len(id)
        if id != '':
            self.__emp = Database.getdb().getEmployeeInfo(id)
            self.designation.setText(self.__emp.designation)
            self.originalPay.setText(str(self.__emp.originalPay))
            self.originalPayGrade.setText(str(self.__emp.originalPayGrade))
            self.DOJ.setText(self.__emp.getStrDate())
            self.pan.setText(self.__emp.pan)

            self.__desig = Database.getdb().getDesignationInfo(
                self.__emp.designation)

            self.da_percent.setText(str(self.__desig.da))
            self.hra_percent.setText(str(self.__desig.hra))
            self.ta_percent.setText(str(self.__desig.ta))
            self.it_percent.setText(str(self.__desig.it))
            self.pt_percent.setText(str(self.__desig.pt))
Esempio n. 16
0
    def removeDesignation(self):
        origDesig = self.chooseDesignation.currentText()
        if len(origDesig) == 0:
            QtGui.QMessageBox(QtGui.QMessageBox.Information, "Error", "Please select a Designation to edit!", parent=self).exec_()

        elif Database.getdb().employeeWithDesigExists(origDesig):
            QtGui.QMessageBox(QtGui.QMessageBox.Information, "Error", "Unable to delete! Employees with this designation exist!",
                              parent=self).exec_()
        else:
            choice = QtGui.QMessageBox.question(self, 'Confirmation',
                                                "Are you sure you want to delete this designation?",
                                                QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
            if choice == QtGui.QMessageBox.Yes:
                try:
                    Database.getdb().delDesignation(origDesig)
                    msg = QtGui.QMessageBox(QtGui.QMessageBox.NoIcon, "Success", "Deleted Successfully", parent=self)
                    msg.exec_()
                    # reload name list
                    self.chooseDesignation.clear()
                    self.loadDesignations()
                    self.clearInfo()

                except Exception as e:
                    raise e
    def loadTable(self):
        """Loads all the info in the QTableWidget"""

        info = Database.getdb().getAllEmployeeInfo()
        self.table.setRowCount(len(info))
        self.table.setColumnCount(len(info[0]))

        for i in range(len(info)):
            for j in range(len(info[0])):
                self.table.setItem(i, j, QtGui.QTableWidgetItem(str(info[i][j])))

        self.table.setHorizontalHeaderLabels(
            ["ID", "Name", "Designation", "Original Pay", "Original Pay Grade", "DOJ", "PAN"])
        self.table.resizeColumnsToContents()
        self.table.setSortingEnabled(True)
        self.table.sortByColumn(0, Qt.AscendingOrder)
    def loadTable(self):
        """Loads all the info in the QTableWidget"""

        info = Database.getdb().getAllDesignationInfo()
        self.table.setRowCount(len(info))
        self.table.setColumnCount(len(info[0]))

        for i in range(len(info)):
            for j in range(len(info[0])):
                self.table.setItem(i, j,
                                   QtGui.QTableWidgetItem(str(info[i][j])))

        self.table.setHorizontalHeaderLabels(
            ["Designation", "DA", "HRA", "TA", "IT", "PT"])
        self.table.resizeColumnsToContents()
        self.table.setSortingEnabled(True)
        self.table.sortByColumn(0, Qt.AscendingOrder)
Esempio n. 19
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.__parent = parent
        self.title = "Calculate Salary"

        self.__desig = None
        self.__emp = None

        t = datetime.now()
        self.month = QComboBox()
        self.month.addItems([
            "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY",
            "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"
        ])
        self.month.setCurrentIndex(t.month - 1)
        self.year = QSpinBox()
        self.year.setRange(1900, 3000)
        self.year.setValue(t.year)

        self.name = SearchBox(self)
        self.name.setPlaceholderText("Enter Name")

        self.nameList = []
        self.nameList = Database.getdb().getEmployeeNameList()
        self.name.setList(self.nameList)

        self.id = QComboBox()

        self.designation = QLineEdit()
        self.designation.setReadOnly(True)
        self.originalPay = QLineEdit()
        self.originalPay.setReadOnly(True)
        self.originalPayGrade = QLineEdit()
        self.originalPayGrade.setReadOnly(True)
        self.DOJ = QLineEdit()
        self.DOJ.setReadOnly(True)
        self.pan = QLineEdit()
        self.pan.setReadOnly(True)

        self.presentPay = QLineEdit()
        self.presentPay.setReadOnly(True)
        self.da_percent = ValueBox()
        self.hra_percent = ValueBox()
        self.ta_percent = ValueBox()
        self.it_percent = ValueBox()
        self.pt_percent = ValueBox()

        self.name.editTextChanged.connect(self.clearInfo)

        self.bttnCalculate = QPushButton("Calculate")
        self.bttnCalculate.clicked.connect(self.calculate)
        self.bttnCancel = QPushButton("Back")
        self.bttnCancel.clicked.connect(self.goBack)
        self.bttnCalculate.setObjectName("OkButton")
        self.bttnCancel.setObjectName("CancelButton")

        self.name.returnPressed.connect(self.setIDList)
        self.id.currentIndexChanged.connect(
            lambda: self.loadInfo(self.id.currentText()))

        self.setupUI()
Esempio n. 20
0
 def setIDList(self, name):
     self.id.clear()
     self.id.addItems(Database.getdb().getIdListForName(name))
Esempio n. 21
0
 def loadDesignations(self):
     self.chooseDesignation.clear()
     self.desigList = Database.getdb().getDesignations()
     self.chooseDesignation.addItems(self.desigList)
     self.chooseDesignation.setCurrentIndex(-1)