def resetCalendar(self): format_normal = QtGui.QTextCharFormat() format_normal.setBackground(QtCore.Qt.white) AllUsersIDs = searchAllUsersID(self.connection) IDCurrentPeriod = getIDCurrentPeriod(self.connection) # reseteo dias de empleados for idemployee in AllUsersIDs: Days = searchDaysAcceptedByID(idemployee[0], self.connection, IDCurrentPeriod) for iday in Days: if iday[1] != None: currDay = iday[0] maxDay = iday[1] while currDay <= maxDay: day = QtCore.QDate(currDay.year, currDay.month, currDay.day) self.ui.employeecalendarWidget.setDateTextFormat( day, format_normal) currDay += datetime.timedelta(1) else: day = QtCore.QDate(iday[0].year, iday[0].month, iday[0].day) self.ui.employeecalendarWidget.setDateTextFormat( day, format_normal) # reseteo feriados Feriados = getFeriados(self.connection, IDCurrentPeriod) for iFeriados in Feriados: self.ui.employeecalendarWidget.setDateTextFormat( iFeriados[0], format_normal) return
def addEmployeesToCB(self): AllUsersIDs = searchAllUsersID(self.connection) for UserID in AllUsersIDs: Nombre = searchNameForUserByID(self.connection, UserID[0]) self.ui.employee_comboBox.addItem(Nombre[0][0] + ' ' + Nombre[0][1]) return
def addPeriod(self): year, end_date, ok = DateDialog.getDateTime() if ok: msg = '¿Desea crear el periodo ' + str(year) + '?' Rta = showMessage( msg, 4, QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) if Rta == QtWidgets.QMessageBox.Yes: Res = addPeriod(self.connection, year, end_date) if Res == 0: # para cada usuario, insertar sus dias para el respectivo periodo IDs = searchAllUsersID(self.connection) IDPeriod = getIDPeriodByYear(self.connection, year) for ID in IDs: Res = addDaysOnPeriod(self.connection, ID[0], IDPeriod) if Res != 0: showMessage( 'Error insertando los días del periódo. Contacte con el administrador inmediatamente.' ) return QtWidgets.QMessageBox.information(self, 'Exito', 'Operación realizada') self.showPeriods() elif Res == 23505: showMessage('El periodo ya existe') else: showMessage('El periodo no pudo ser creado') return
def fillComboBox(self): self.ui.employee_comboBox.clear() AllUsersIDs = searchAllUsersID(self.connection) for UserID in AllUsersIDs: Nombre = searchNameForUserByID(self.connection, UserID[0]) self.ui.employee_comboBox.addItem(Nombre[0][0] + ' ' + Nombre[0][1]) return
def giveDays(self): senderButton = self.sender().objectName() dialog = QtWidgets.QDialog() dialog.setFixedSize(362, 280) admDialog = Ui_AdmDaysDialog() admDialog.setupUi(dialog) AllUsersIDs = searchAllUsersID(self.connection) for UserID in AllUsersIDs: Nombre = searchNameForUserByID(self.connection, UserID[0]) admDialog.employee_comboBox.addItem(Nombre[0][0] + ' ' + Nombre[0][1]) result = dialog.exec_() if result: dias = admDialog.days_doubleSpinBox.value() if (dias % .5 != 0): showMessage('El número ingresado no es válido') return empleado = admDialog.employee_comboBox.currentText() txt = 'agregar ' if senderButton == 'giveDays_pushButton' else 'descontar ' msg = '¿Desea ' + str(txt) + str( dias) + ' días al empleado ' + str(empleado) + '?' Rta = showMessage( msg, 4, QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) if Rta == QtWidgets.QMessageBox.Yes: empleado = empleado.split(' ') ID_Usuario = getUserID(self.connection, empleado[0], empleado[1]) IDCurrentPeriod = getIDCurrentPeriod(self.connection) DiasOriginal = searchDaysByUserID(self.connection, ID_Usuario, IDCurrentPeriod) DiasTotal = DiasOriginal + dias if senderButton == 'giveDays_pushButton' else DiasOriginal - dias ID_Usuario = getUserID(self.connection, empleado[0], empleado[1]) Result = AddDaysToUser(self.connection, DiasTotal, ID_Usuario, IDCurrentPeriod) if Result == 0: QtWidgets.QMessageBox.information(self, 'Exito', 'Operación realizada') # IDCurrentPeriod=getIDCurrentPeriod(self.connection) Razon = str(admDialog.razon_plainTextEdit.toPlainText() ) if admDialog.razon_plainTextEdit.toPlainText( ) != '' else '-' AltaBaja = 1 if senderButton == 'giveDays_pushButton' else 0 IDUsuario = getUserID(self.connection, empleado[0], empleado[1]) AddNotification(self.connection, Razon, str(dias), AltaBaja, IDUsuario, IDCurrentPeriod, self.currentUserID) self.showEmployeeStatus() else: showMessage('No se pudo realizar la operación solicitada') return
def colourRequestedDays(self): format_reqday_one = QtGui.QTextCharFormat() format_reqday_one.setBackground(YELLOW) format_reqday_two = QtGui.QTextCharFormat() format_reqday_two.setBackground(GREEN) AllUsersIDs = searchAllUsersID(self.connection) IDCurrentPeriod = getIDCurrentPeriod(self.connection) daysEmployeeDict = [ ] #Lista que me indica todos los dias que fueron pedidos self.daysForEmployee.clear( ) #Diccionario con key=dia_mediodia y value una lista con los id de los empleados for idemployee in AllUsersIDs: Days = searchDaysAcceptedByID(idemployee[0], self.connection, IDCurrentPeriod) for iday in Days: if iday[1] != None: currDay = iday[0] maxDay = iday[1] while currDay <= maxDay: day = QtCore.QDate(currDay.year, currDay.month, currDay.day) color = format_reqday_one if day not in daysEmployeeDict else format_reqday_two self.ui.employeecalendarWidget.setDateTextFormat( day, color) daysEmployeeDict.append(day) key = day.toString() + '_' + str( iday[2]) if iday[2] != None else day.toString() if key in self.daysForEmployee: self.daysForEmployee[key].append(idemployee[0]) else: self.daysForEmployee[key] = [idemployee[0]] currDay += datetime.timedelta(1) else: day = QtCore.QDate(iday[0].year, iday[0].month, iday[0].day) color = format_reqday_one if day not in daysEmployeeDict else format_reqday_two self.ui.employeecalendarWidget.setDateTextFormat( day, color) daysEmployeeDict.append(day) key = day.toString() + '_' + str( iday[2]) if iday[2] != None else day.toString() if key in self.daysForEmployee: self.daysForEmployee[key].append(idemployee[0]) else: self.daysForEmployee[key] = [idemployee[0]] return
def showEmployeeStatus(self): self.ui.employeeStatustableWidget.clearContents() self.ui.employeeStatustableWidget.setRowCount(0) IDCurrentPeriod = getIDCurrentPeriod(self.connection) AllUsersIDs = searchAllUsersID(self.connection) Feriados = getFeriados(self.connection, IDCurrentPeriod) for UserID in AllUsersIDs: Dias = searchDaysForUserByID(self.connection, UserID[0], IDCurrentPeriod) Nombre = searchNameForUserByID(self.connection, UserID[0]) currentRow = self.ui.employeeStatustableWidget.rowCount() self.ui.employeeStatustableWidget.setRowCount(currentRow + 1) it0 = QtWidgets.QTableWidgetItem( str(Nombre[0][0] + ' ' + Nombre[0][1])) it0.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) self.ui.employeeStatustableWidget.setItem(currentRow, 0, it0) DaysTotal = Dias[0][0] it1 = QtWidgets.QTableWidgetItem(str(DaysTotal)) it1.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) self.ui.employeeStatustableWidget.setItem(currentRow, 1, it1) Absences = searchforAbsenceOrLicenseByUserID( self.connection, UserID[0], IDCurrentPeriod, True) DaysAbsences = calculateDays(Absences, Feriados) it2 = QtWidgets.QTableWidgetItem(str(DaysAbsences)) it2.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) self.ui.employeeStatustableWidget.setItem(currentRow, 2, it2) Licenses = searchforAbsenceOrLicenseByUserID( self.connection, UserID[0], IDCurrentPeriod, False) DaysLicenses = calculateDays(Licenses, Feriados) it3 = QtWidgets.QTableWidgetItem(str(DaysLicenses)) it3.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) self.ui.employeeStatustableWidget.setItem(currentRow, 3, it3) RestOfDays = DaysTotal - DaysAbsences - DaysLicenses it4 = QtWidgets.QTableWidgetItem(str(RestOfDays)) it4.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) self.ui.employeeStatustableWidget.setItem(currentRow, 4, it4) color = GREEN if RestOfDays == 0 else YELLOW if RestOfDays > 0 else RED it0.setBackground(color) return