def get_attendance_stat(self): db = EMS_db_model() logs = db.get_salary_log() if len(logs) == 0: QtGui.QMessageBox.information( self, 'Note', 'There are no attendance logs to plot', None) return None period = [] attendances = [] absences = [] for k, v in groupby(logs, key=lambda x: x['period']): if k is None: continue vlistA = [] vlistB = [] splitter = k.split('/') whole_n_part = int(splitter[2].split(' ')[2]) decimal_part = float(splitter[3] + splitter[4]) * 0.01 / 12 k = float(whole_n_part + decimal_part) k = round(k, 2) for i in list(v): vlistA.append(i['days_present']) vlistB.append(i['days_absent']) vlistA = sum(vlistA) / len(vlistA) vlistB = sum(vlistB) / len(vlistB) period.append(k) attendances.append(vlistA) absences.append(vlistB) logs_dict = { 'key': period, 'attendance_ave': attendances, 'absence_ave': absences } return logs_dict
def get_salary_stat(self): db = EMS_db_model() logs = db.get_salary_log()[::-1] if len(logs) == 0: QtGui.QMessageBox.information(self, 'Note', 'There are no salary logs to plot', None) return None period = [] salary = [] for k, v in groupby(logs, key=lambda x: x['period']): if k is None: continue vlistA = [] splitter = k.split('/') whole_n_part = int(splitter[2].split(' ')[2][2:]) decimal_part = float(splitter[3] + splitter[4]) * 0.01 / 12 k = float(whole_n_part + decimal_part) k = round(k, 2) for i in list(v): vlistA.append(i['net_pay']) vlistA = sum(vlistA) / len(vlistA) period.append(k) salary.append(vlistA) logs_dict = { 'key': period, 'salary_ave': salary, } return logs_dict
def fetch_salary_logs(self): db = EMS_db_model() all_logs = db.get_salary_log() emp_log = [] for i in all_logs: if i['user'] == self.user_id: emp_log.append(i) return emp_log
def clocked_employee_show(self): db = self.connection() if db is False: return 0 db = EMS_db_model() emp_list = db.fetch_profile() clocked_employee_window = ClockedEmployeeWindow(emp_list, self) clocked_employee_window.show()
def connection(self): try: return EMS_db_model() except: QtGui.QMessageBox.warning( self, 'Connection Failed', 'Cannot connect to the server,\nCheck your internet connection.', None) return False
def __init__(self, user_id, parent=None): super(ProfileWindow, self).__init__(parent) self.setupUi(self) fg = self.frameGeometry() cp = QtGui.QDesktopWidget().availableGeometry().center() fg.moveCenter(cp) self.move(fg.topLeft()) self.setFixedSize(self.size()) self.statusBar().setVisible(False) self.setWindowModality(QtCore.Qt.ApplicationModal) self.birthday_txt.setCalendarPopup(True) self.print_btn.setVisible(False) self.data_to_print = None self.user_id = user_id self.db = EMS_db_model() self.setUp_profile() self.attendancelog_btn.clicked.connect(self.show_attendance_view) self.update_btn.clicked.connect(self.update_employee) self.train_btn.clicked.connect(self.capture_dataset) self.print_btn.clicked.connect(self.gen_pdf) # # # SALARY # # # self.netpay_frame.setVisible(False) self.scrollArea.setWidgetResizable(True) self.scrollContent = QtGui.QWidget(self.scrollArea) self.scrollLayout = QtGui.QVBoxLayout(self.scrollContent) self.scrollLayout.setAlignment(QtCore.Qt.AlignTop) self.scrollContent.setLayout(self.scrollLayout) self.user_id = user_id self.emp_logs = self.fetch_salary_logs() for i in self.emp_logs: btn_text = ' Current' if i['is_released']: start_date = i['period'].split(' - ')[0] start_date = parse(start_date) start_date = start_date.strftime("%b %d, %Y") end_date = i['period'].split(' - ')[1] end_date = parse(end_date) end_date = end_date.strftime("%b %d, %Y") btn_text = " %s - %s" % (start_date, end_date) btn_link = QtGui.QPushButton(btn_text, self.scrollArea) btn_link.setStyleSheet("text-align: left;\n color: #fff;\n" "background-color: rgb(5, 101, 255);") btn_link.clicked.connect( partial(self.populate_report, i['id'], btn_text)) self.scrollLayout.addWidget(btn_link) self.scrollArea.setWidget(self.scrollContent)
def show_all_attendance_logs(self): self.search_lineEdit_2.setVisible(False) self.search_lineEdit.setVisible(True) self.label_search.setVisible(True) self.btn_close.setVisible(True) db = EMS_db_model() all_logs = db.fetch_attendance_logs() self.attendance_view.setColumnCount(4) self.attendance_table_headers.append('Employee Name') self.attendance_table_headers.append('ID') self.attendance_view.setHorizontalHeaderLabels( self.attendance_table_headers) self.header.setResizeMode(2, QtGui.QHeaderView.Stretch) self.attendance_view.setRowCount(len(all_logs)) row = 0 for_filtering = [] all_profile = db.fetch_profile() for i in all_logs: emp_name = '' gcc_id = '' for ii in all_profile: if ii['id'] == i['user']: gcc_id = sp.convert_id(ii['id'], ii['start_date'][:4]) emp_name = '%s, %s %s' % ( ii['last_name'], ii['first_name'], ii['middle_name']) time_in = parse(i['time_in']).astimezone(time_zone) time_in = time_in.strftime("%B %d, %Y %I:%M:%S %p") time_out = ' ' if i['time_out'] is not None: time_out = parse(i['time_out']).astimezone(time_zone) time_out = time_out.strftime("%B %d, %Y %I:%M:%S %p") self.attendance_view.setItem(row, 0, QtGui.QTableWidgetItem(str(time_in))) self.attendance_view.setItem(row, 1, QtGui.QTableWidgetItem(str(time_out))) self.attendance_view.setItem(row, 2, QtGui.QTableWidgetItem(emp_name)) self.attendance_view.setItem(row, 3, QtGui.QTableWidgetItem(gcc_id)) row += 1 for_filtering.append([time_in, time_out, emp_name, gcc_id]) self.attendance_view.scrollToBottom() self.name_label.setText('') self.filtering_list = for_filtering
def __init__(self, memo, imagex=None): self.memo = memo self.img = imagex self.db = EMS_db_model() self.config = self.db.get_config()[0] self.fb_id = self.config['fb_page_id'] self.user_token = self.config['fb_user_token'] cfg = { "page_id": self.fb_id, "access_token": self.user_token, } api = self.get_api(cfg) if self.img is None: api.put_object('me', 'feed', message=self.memo) else: api.put_photo(image=open(self.img, 'rb'), message=self.memo)
def get_current_config(self): db = EMS_db_model() current = db.get_config()[0] content = { 'pstart': current['first_cutoff'], 'pend': current['second_cutoff'], 'lvl_1_rate': current['level_1_rate'], 'lvl_2_rate': current['level_2_rate'], 'lvl_3_rate': current['level_3_rate'], 'ot_rate': current['overtime_rate'], 'sss_pay_day' : current['sss_pay_day'], 'philhealth_pay_day': current['philhealth_pay_day'], 'pagibig_pay_day': current['pagibig_pay_day'], 'tax_pay_day': current['tax_pay_day'], 'is_operating': current['is_operating'], } self.current_config = content
def show_attendance_logs(self, user_id): self.search_lineEdit.setVisible(False) self.search_lineEdit_2.setVisible(True) self.label_search.setVisible(True) self.btn_close.setVisible(True) self.attendance_table_headers = ['Time-In', 'Time-Out'] self.attendance_view.setColumnCount(2) self.header.setResizeMode(0, QtGui.QHeaderView.Stretch) self.header.setResizeMode(1, QtGui.QHeaderView.Stretch) db = EMS_db_model() all_profile = db.fetch_profile() for i in all_profile: if i['id'] == user_id: self.name_label.setText( '%s, %s %s %s' % (i['last_name'], i['first_name'], i['middle_name'], 'ID:' + sp.convert_id(user_id, i['start_date'][:4]))) all_logs = db.fetch_attendance_logs() user_log = [] for i in all_logs: if i['user'] == user_id: user_log.append(i) self.attendance_view.setRowCount(len(user_log)) row = 0 for_filtering = [] for i in user_log: time_in = parse(i['time_in']).astimezone(time_zone) time_in = time_in.strftime("%B %d, %Y %I:%M:%S %p") time_out = ' ' if i['time_out'] is not None: time_out = parse(i['time_out']).astimezone(time_zone) time_out = time_out.strftime("%B %d, %Y %I:%M:%S %p") self.attendance_view.setItem(row, 0, QtGui.QTableWidgetItem(str(time_in))) self.attendance_view.setItem(row, 1, QtGui.QTableWidgetItem(str(time_out))) row += 1 for_filtering.append([time_in, time_out]) self.attendance_view.scrollToBottom() self.filtering_list = for_filtering
def register_user(self): db = EMS_db_model() position = str(self.position_combo.currentText()) rate = float(self.rate_combo.currentText().split(' ')[1]) dayoff = 'sunday' if self.checkBox_mon.isChecked(): dayoff += ', monday' if self.checkBox_tue.isChecked(): dayoff += ', tuesday' if self.checkBox_wed.isChecked(): dayoff += ', wednesday' if self.checkBox_thu.isChecked(): dayoff += ', thursday' if self.checkBox_fri.isChecked(): dayoff += ', friday' if self.checkBox_sat.isChecked(): dayoff += ', saturday' is_admin = False if position == 'administrator': is_admin = True gender = 'male' if self.female_radio.isChecked(): gender = 'female' content = { 'username': self.username_txt.text(), 'password': self.password_txt.text(), 'confirm': self.confirm_txt.text(), 'email': self.gmail_txt.text(), 'fname': self.fname_txt.text(), 'mname': self.mname_txt.text(), 'lname': self.lname_txt.text(), 'position': position, 'is_admin': is_admin, "sss_number": self.sss_txt.text(), "pagibig_number": self.pagibig_txt.text(), "philhealth_number": self.philhealth_txt.text(), "tin_number": self.tin_txt.text(), 'rate': rate, 'day_off': dayoff, 'birthday': self.birthday_txt.text(), 'address': self.address_txt.text(), 'gender': gender, 'height': self.height_txt.text(), 'contact_number': self.contact_txt.text(), } title = 'Success' msg = 'Employee has been registered' dataCheck = [content['username'], content['password'], content['confirm'], content['email'], content['height'], content['fname'], content['mname'], content['lname'], content['sss_number'], content['contact_number'], content['philhealth_number'], content['pagibig_number'], content['tin_number'], content['address']] for i in dataCheck: if len(str(i)) == 0 or i == None: title = 'Failed' msg = 'Complete the Fields' return QtGui.QMessageBox.information(self, title, msg, None) if len(self.contact_txt.text()) != 10: title = 'Failed' msg = 'Please enter a correct contact number. eg. 9xxxxxxxxx' return QtGui.QMessageBox.information(self, title, msg, None) if len(self.height_txt.text()) != 3: title = 'Failed' msg = 'Incorrect height value' return QtGui.QMessageBox.information(self, title, msg, None) if len(dayoff.split(',')) > 4: title = 'Failed' msg = 'Maximum of 3 day-offs are allowed' return QtGui.QMessageBox.information(self, title, msg, None) if len(self.sss_txt.text()) != 14: title = 'Failed' msg = 'Incorrect SSS number' elif len(self.philhealth_txt.text()) != 14: title = 'Failed' msg = 'Incorrect PHILHEALTH number' elif len(self.pagibig_txt.text()) != 14: title = 'Failed' msg = 'Incorrect PAGIBIG number' elif len(self.tin_txt.text()) < 16: title = 'Failed' msg = 'Incorrect TIN number' else: authCD = AuthCDWindow(self) if not authCD.exec_(): authCD.hide() else: self.setEnabled(False) cap = Identifier.Detect(config.CAMERA_INDEX) id = cap.identify() cv2.destroyAllWindows() self.setEnabled(True) if id is not False: return QtGui.QMessageBox.warning(self, 'Note', 'That face was already in use.', None) register = db.register_user(content) if register == 'complete the fields': title = 'Failed' msg = register elif register == 'you are not yet at the proper age of working': title = 'Failed' msg = register elif register == 'passwords didn\'t match': title = 'Failed' msg = register self.password_txt.clear() self.confirm_txt.clear() #successful registration here elif register[0] is True: self.capture_dataset(register[1]) check_if_ok = CaptureCheckWindow(register[1], self) if not check_if_ok.exec_(): check_if_ok.hide() self.close_window() else: self.close_window() else: title = 'Failed' msg = '' for i in register: msg += i + '\n' QtGui.QMessageBox.information(self, title, msg, None)
def __init__(self, parent=None): super(RegisterWindow, self).__init__(parent) self.setupUi(self) fg = self.frameGeometry() cp = QtGui.QDesktopWidget().availableGeometry().center() fg.moveCenter(cp) self.move(fg.topLeft()) self.setFixedSize(self.size()) self.parent = parent self.cancel_btn.clicked.connect(self.close_window) self.male_radio.setChecked(True) self.birthday_txt.setCalendarPopup(True) # regex regex_letter = QtCore.QRegExp("([a-zA-Z]+[ ])+") validator_letter = QtGui.QRegExpValidator(regex_letter) regex_nospace = QtCore.QRegExp("[a-zA-Z0-9_.-]+") validator_nospace = QtGui.QRegExpValidator(regex_nospace) regex_contact = QtCore.QRegExp("^9(?!(000000000))\d{9}$") validator_contact = QtGui.QRegExpValidator(regex_contact) regex_sss = QtCore.QRegExp("^(?!(00))\d{2}-(?!(000000000))\d{9}-(?!(0))\d{1}$") validator_sss = QtGui.QRegExpValidator(regex_sss) regex_philhealth = QtCore.QRegExp("^(?!(00))\d{2}-(?!(000000000))\d{9}-(?!(0))\d{1}$") validator_philhealth = QtGui.QRegExpValidator(regex_philhealth) regex_pagibig = QtCore.QRegExp("^(?!(0000))\d{4}-(?!(0000))\d{4}-(?!(0000))\d{4}$") validator_pagibig = QtGui.QRegExpValidator(regex_pagibig) regex_tin = QtCore.QRegExp("^(?!(000))\d{3}-(?!(000))\d{3}-(?!(000))\d{3}-(?!(00000))\d{5}$") validator_tin = QtGui.QRegExpValidator(regex_tin) regex_height = QtCore.QRegExp("^1(?!([1, 2, 9, 0]))\d{1}(?!(0))\d{1}$") validator_height = QtGui.QRegExpValidator(regex_height) passEcho = QtGui.QLineEdit.Password self.username_txt.setValidator(validator_nospace) self.username_txt.setMaxLength(20) self.password_txt.setEchoMode(passEcho) self.password_txt.setMaxLength(25) self.confirm_txt.setEchoMode(passEcho) self.confirm_txt.setMaxLength(25) self.fname_txt.setValidator(validator_letter) self.fname_txt.setMaxLength(35) self.mname_txt.setValidator(validator_letter) self.mname_txt.setMaxLength(35) self.lname_txt.setValidator(validator_letter) self.lname_txt.setMaxLength(35) self.gmail_txt.setValidator(validator_nospace) self.gmail_txt.setMaxLength(30) self.height_txt.setValidator(validator_height) self.contact_txt.setValidator(validator_contact) self.sss_txt.setValidator(validator_sss) self.philhealth_txt.setValidator(validator_philhealth) self.pagibig_txt.setValidator(validator_pagibig) self.tin_txt.setValidator(validator_tin) # get config db = EMS_db_model() config = db.get_config()[0] # get rates rates_list = [config['level_1_rate'], config['level_2_rate'], config['level_3_rate']] for i in rates_list: self.rate_combo.addItem('PHP ' + str(i)) position_lists = ['instructor', 'administrator'] for i in position_lists: self.position_combo.addItem(i) self.train_btn.clicked.connect(self.register_user) self.setWindowModality(QtCore.Qt.ApplicationModal)
from models import EMS_db_model import json from datetime import date, datetime import calendar from face import Identifier, dataSetCreator db = EMS_db_model() import requests from threading import Timer import time import signal import schedule import time from datetime import timedelta from pytz import timezone from itertools import groupby # test cases def register(): content = { 'username': '******', 'password': '******', 'confirm': 'longview048', 'email': 'cedrick044', 'fname': 'jolo', 'mname': 'cuizon', 'lname': 'domingo', 'position': 'instructor', 'is_admin': False, "sss_number": "3242-2342342-4234", "pagibig_number": "3242-4234-2342",
def forgot_pass(self): db = EMS_db_model() forgot_pass_link = db.get_forgot_pass_link() webbrowser.open(forgot_pass_link)
def save_changes(self): lvl1_rate = float(self.lvl_1_rate_edit.text()[4:]) lvl2_rate = float(self.lvl_2_rate_edit.text()[4:]) lvl3_rate = float(self.lvl_3_rate_edit.text()[4:]) ot_rate = float(self.ot_rate_edit.text()) is_operating = False if self.enable_radio.isChecked(): is_operating = True if lvl1_rate >= lvl2_rate or lvl1_rate >= lvl3_rate\ or lvl2_rate >= lvl3_rate: note = 'rates should vary. level 1 rate should have the lowest value.\n' \ ' level 2 rate should be greater than level 1 and level 3 should\n' \ ' be greater than level 2' QtGui.QMessageBox.information(self, 'Note', note, None) return 0 first_cut_off = int(self.start_combo.currentText().replace("th day of month", '')) second_cut_off = int(self.end_combo.currentText().replace("th day of month", '')) sss_pday_new = second_cut_off if self.sss_pday.currentIndex() == 1: sss_pday_new = first_cut_off philhealth_pday_new = second_cut_off if self.philhealth_pday.currentIndex() == 1: philhealth_pday_new = first_cut_off pagibig_pday_new = second_cut_off if self.pagibig_pday.currentIndex() == 1: pagibig_pday_new = first_cut_off tax_pday_new = second_cut_off if self.tax_pday.currentIndex() == 1: tax_pday_new = first_cut_off if any(i < 50 for i in [lvl1_rate, lvl2_rate, lvl3_rate]): note = 'any of rates should not be less than PHP 50' QtGui.QMessageBox.information(self, 'Note', note, None) return 0 if ot_rate < 1: note = 'overtime rate should not be less than 1' QtGui.QMessageBox.information(self, 'Note', note, None) return 0 content = { "first_cutoff": first_cut_off, "second_cutoff": second_cut_off, "level_1_rate": lvl1_rate, "level_2_rate": lvl2_rate, "level_3_rate": lvl3_rate, "overtime_rate": ot_rate, "pagibig_pay_day": pagibig_pday_new, "philhealth_pay_day": philhealth_pday_new, "sss_pay_day": sss_pday_new, "tax_pay_day": tax_pday_new, "is_operating": is_operating } db = EMS_db_model() save = db.update_global_conf(content) if save == 'configurations are updated': QtGui.QMessageBox.information(self, 'Note', save, None) self.hide() self.update_btn.setDisabled(True)