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 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
Beispiel #3
0
 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
Beispiel #4
0
 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()
Beispiel #5
0
    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)
Beispiel #6
0
class FbUpload:
    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_api(self ,cfg):
        graph = facebook.GraphAPI(cfg['access_token'])
        resp = graph.get_object('me/accounts')
        page_access_token = None
        for page in resp['data']:
            if page['id'] == cfg['page_id']:
                page_access_token = page['access_token']
        graph = facebook.GraphAPI(page_access_token)
        return graph
Beispiel #7
0
    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
Beispiel #8
0
 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
Beispiel #9
0
    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
Beispiel #10
0
    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)
Beispiel #11
0
    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
Beispiel #12
0
class ProfileWindow(QtGui.QMainWindow, EmployeeView.Ui_EmployeeView):
    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)
        # # # SALARY # # #

    # # # PROFILE # # #
    def fetch_employee(self):
        employee = self.db.fetch_profile()
        for i in employee:
            if i['id'] == self.user_id:
                return i

    def fetch_profile(self):
        employee_profile = self.db.fetch_profile_ext()
        for i in employee_profile:
            if i['user'] == self.user_id:
                return i

    def fetch_config(self):
        employee_config = self.db.fetch_profile_config()
        for i in employee_config:
            if i['user'] == self.user_id:
                return i

    def setUp_profile(self):
        emp = self.fetch_employee()
        userx = self.db.get_user_info(emp['user'])
        profile = self.fetch_profile()
        config = self.fetch_config()

        label_color = "<font color='#0f7a62'>%s</font>"
        lbl_text_green = "<font color='green'>%s</font>"
        lbl_text_warning = "<font color='orangered'>%s</font>"
        lbl_text_red = "<font color='red'>%s</font>"
        # font_style = "QLabel {font: Arial}"

        # Profile Information
        if emp['is_active'] is False:
            status = 'Inactive'
            self.lbl_status.setText(self.lbl_status.text() +
                                    lbl_text_red % status)
        else:
            status = 'Active'
            self.lbl_status.setText(self.lbl_status.text() +
                                    lbl_text_green % status)

        # self.lbl_status.setStyleSheet(font_style)

        self.lbl_username.setText(self.lbl_username.text() +
                                  label_color % userx[0])

        self.lbl_name_2.setText(self.lbl_name_2.text() + \
                                lbl_text_green % '%s, %s %s'.capitalize() %
                                (emp['last_name'], emp['first_name'], emp['middle_name']))

        self.name_full = '%s, %s %s'.capitalize() % (
            emp['last_name'], emp['first_name'], emp['middle_name'])

        self.lbl_id.setText(self.lbl_id.text() + \
                            lbl_text_green % sp.convert_id(emp['id'], emp['start_date'][:4]))

        birthday = parse(profile['birthday']).astimezone(time_zone)
        birthday = birthday.strftime("%b %d, %Y")

        self.lbl_bday.setText(self.lbl_bday.text() + label_color % birthday)

        self.lbl_gender.setText(self.lbl_gender.text() +
                                label_color % profile['gender'].capitalize())

        self.lbl_address.setText(self.lbl_address.text() + \
                                 label_color % "<font size=2>%s</font>" % profile['address'].capitalize())

        self.lbl_gmail.setText(self.lbl_gmail.text() + label_color %
                               "<font size=2>%s</font>" % userx[1])

        self.lbl_contact.setText(self.lbl_contact.text() +
                                 label_color % profile['contact_number'])
        # self.lbl_contact.setStyleSheet(font_style)

        self.lbl_height.setText(self.lbl_height.text() +
                                label_color % str(profile['height']))

        age = int(datetime.now().strftime('%Y')) - int(profile['birthday'][:4])
        self.lbl_age.setText(self.lbl_age.text() + label_color % str(age))

        date_joined = parse(emp['start_date']).astimezone(time_zone)
        date_joined = date_joined.strftime("%b %d, %Y")

        self.lbl_start_date.setText(self.lbl_start_date.text() +
                                    label_color % date_joined)

        self.lbl_presence_count.setText(self.lbl_presence_count.text() + \
                                        lbl_text_green % str(profile['presences_count']))

        abstext_color = lbl_text_green
        if profile['absences_count'] > 0:
            abstext_color = lbl_text_warning

        elif profile['absences_count'] > 10:
            abstext_color = lbl_text_red

        self.lbl_absence_count.setText(self.lbl_absence_count.text() + \
                                       abstext_color % str(profile['absences_count']))

        # Job Information
        self.lbl_position.setText(self.lbl_position.text() +
                                  label_color % emp['position'].capitalize())
        self.position = emp['position']

        self.lbl_rate.setText(self.lbl_rate.text() + label_color %
                              "PHP %s/hour" % str(config['rate_per_hour']))

        self.lbl_dayoff.setText(self.lbl_dayoff.text() +
                                label_color % config['non_working_days'])

        self.lbl_sss.setText(self.lbl_sss.text() +
                             label_color % config['sss_number'])

        self.lbl_philhealth.setText(self.lbl_philhealth.text() +
                                    label_color % config['philhealth_number'])

        self.lbl_pagibig.setText(self.lbl_pagibig.text() +
                                 label_color % config['pagibig_number'])

        self.lbl_tin.setText(self.lbl_tin.text() +
                             label_color % config['tin_number'])

        self.lbl_profile_photo.setPixmap(
            QtGui.QPixmap(_fromUtf8("profilepics/%s.png" % str(userx[2]))))
        self.lbl_profile_photo.setScaledContents(True)
        self.lbl_profile_photo.setObjectName(_fromUtf8("lbl_profile_photo"))

        # populate update text boxes
        self.fname_txt.setText(emp['first_name'].capitalize())
        self.mname_txt.setText(emp['middle_name'].capitalize())
        self.lname_txt.setText(emp['last_name'].capitalize())
        self.contact_txt.setText(profile['contact_number'])
        self.address_txt.setText(profile['address'].capitalize())
        bday = profile['birthday'].split('-')
        self.birthday_txt.setDate(
            QtCore.QDate(int(bday[0]), int(bday[1]), int(bday[2])))

        self.male_radio.setChecked(True)
        if profile['gender'] != 'male':
            self.female_radio.setChecked(True)
        self.height_txt.setText(str(profile['height']))

        self.active_radio.setChecked(True)
        if emp['is_active'] is False:
            self.inactive_radio.setChecked(True)

        if 'monday' in config['non_working_days']:
            self.checkBox_mon.setChecked(True)
        if 'tuesday' in config['non_working_days']:
            self.checkBox_tue.setChecked(True)
        if 'wednesday' in config['non_working_days']:
            self.checkBox_wed.setChecked(True)
        if 'thursday' in config['non_working_days']:
            self.checkBox_thu.setChecked(True)
        if 'friday' in config['non_working_days']:
            self.checkBox_fri.setChecked(True)
        if 'saturday' in config['non_working_days']:
            self.checkBox_sat.setChecked(True)

        position_lists = ['instructor', 'administrator']
        for i in position_lists:
            self.position_combo.addItem(i)
        if emp['is_admin']:
            self.position_combo.setCurrentIndex(1)

        global_conf = self.db.get_config()[0]

        rates_list = [
            global_conf['level_1_rate'], global_conf['level_2_rate'],
            global_conf['level_3_rate']
        ]
        for i in range(3):
            self.rate_combo.addItem('PHP ' + str(rates_list[i]))
            if config['rate_per_hour'] == rates_list[i]:
                self.rate_combo.setCurrentIndex(i)

        self.sss_txt.setText(config['sss_number'])
        self.philhealth_txt.setText(config['philhealth_number'])
        self.pagibig_txt.setText(config['pagibig_number'])
        self.tin_txt.setText(config['tin_number'])

        regex_letter = QtCore.QRegExp("([a-zA-Z]+[ ])+")
        validator_letter = QtGui.QRegExpValidator(regex_letter)

        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)

        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.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)

    def show_attendance_view(self):
        all_logs = self.db.fetch_attendance_logs()
        user_log = []
        for i in all_logs:
            if i['user'] == self.user_id:
                user_log.append(i)
        attendancewindow = AttendanceWindow(user_log, self)
        attendancewindow.show()

    def show_salary_view(self):
        salarywindow = SalaryWindow(self.user_id, self)
        salarywindow.show()

    # # # PROFILE # # #

    # # # SALARY # # #
    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 populate_report(self, log_id, period):
        salary_log = self.fetch_salary_logs()
        report = []
        for i in salary_log:
            if i['id'] == log_id:
                report.append(i)
                break
        selected_log = report[0]

        # labels
        label_color = "<font color='#0f7a62'>%s</font>"
        lbl_text_green = "<font color='green'>%s</font>"
        lbl_text_warning = "<font color='orangered'>%s</font>"

        self.netpay_frame.setVisible(False)
        self.lbl_total_time.setText('Total Time: ')
        self.lbl_total_ot.setText('Total Over Time: ')
        self.lbl_days_present.setText('No. of Days Present: ')
        self.lbl_days_absent.setText('No. of Days Absent: ')
        self.lbl_sss_2.setText('SSS Contirbution: PHP ')
        self.lbl_philhealth_2.setText('PHILHEALTH Contribution: PHP ')
        self.lbl_pagibig_2.setText('PAG-IBIG contribution: PHP ')
        self.lbl_tax.setText('Tax: PHP ')
        self.lbl_total_deductions.setText('Total: PHP ')
        self.lbl_special_pay.setText('Special Pay: PHP ')
        self.lbl_gross_pay.setText('Gross Pay: PHP ')
        self.lbl_period.setText('Period: ')
        self.lbl_status_2.setText('Status: ')
        self.lbl_net_pay.setText('Net Pay: PHP ')

        self.lbl_total_time.setText(self.lbl_total_time.text() + \
                                    label_color % str(selected_log['total_time']))

        self.lbl_total_ot.setText(self.lbl_total_ot.text() + \
                                    label_color % str(selected_log['total_over_time']))

        self.lbl_days_present.setText(self.lbl_days_present.text() + \
                                      label_color % str(selected_log['days_present']))

        self.lbl_days_absent.setText(self.lbl_days_absent.text() + \
                                     label_color % str(selected_log['days_absent']))

        self.lbl_sss_2.setText(self.lbl_sss_2.text() + \
                             label_color % str("{:.2f}".format(selected_log['sss_contrib'])))

        self.lbl_philhealth_2.setText(self.lbl_philhealth_2.text() + \
                                    label_color % str("{:.2f}".format(selected_log['sss_contrib'])))

        self.lbl_pagibig_2.setText(self.lbl_pagibig_2.text() + \
                                 label_color % str("{:.2f}".format(selected_log['pagibig_contrib'])))

        self.lbl_tax.setText(self.lbl_tax.text() + \
                             label_color % str("{:.2f}".format(selected_log['tax'])))

        total_deds = str("{:.2f}".format(
            sum([
                selected_log['sss_contrib'], selected_log['sss_contrib'],
                selected_log['sss_contrib'], selected_log['tax']
            ])))

        self.lbl_total_deductions.setText(self.lbl_total_deductions.text() +
                                          label_color % total_deds)

        self.lbl_special_pay.setText(self.lbl_special_pay.text() + \
                                     label_color % str("{:.2f}".format(selected_log['special_pay'])))

        self.lbl_gross_pay.setText(self.lbl_gross_pay.text() + \
                                   label_color % str("{:.2f}".format(selected_log['gross_pay'])))

        self.lbl_period.setText(self.lbl_period.text() + label_color % period)

        status_text = self.lbl_status_2.text() + lbl_text_warning % 'Current'
        stat = 'Current'
        if selected_log['is_released']:
            status_text = self.lbl_status_2.text(
            ) + lbl_text_green % 'Released'
            stat = 'Released'
        self.lbl_status_2.setText(status_text)

        if selected_log['net_pay'] > 0:
            self.netpay_frame.setVisible(True)

        self.lbl_net_pay.setText(self.lbl_net_pay.text() +\
                                 lbl_text_green % str("{:.2f}".format(selected_log['net_pay'])))
        self.print_btn.setVisible(True)

        self.data_to_print = {
            'title':
            self.name_full.replace(' ', '') + '-' +
            datetime.now().strftime("%B %d, %Y %I:%M:%S %p") + '-' + period,
            'current_date':
            datetime.now().strftime("%B %d, %Y %I:%M:%S %p"),
            'total_time':
            str(selected_log['total_time']),
            'total_overtime':
            str(selected_log['total_over_time']),
            'days_present':
            str(selected_log['days_present']),
            'days_absent':
            str(selected_log['days_absent']),
            'sss':
            str("{:.2f}".format(selected_log['sss_contrib'])),
            'philhealth':
            str("{:.2f}".format(selected_log['philhealth_contrib'])),
            'pagibig':
            str("{:.2f}".format(selected_log['pagibig_contrib'])),
            'tax':
            str("{:.2f}".format(selected_log['tax'])),
            'total_ded':
            total_deds,
            'special_pay':
            str("{:.2f}".format(selected_log['special_pay'])),
            'gross_pay':
            str("{:.2f}".format(selected_log['gross_pay'])),
            'period':
            period,
            'status':
            stat,
            'net_pay':
            str("{:.2f}".format(selected_log['net_pay'])),
            'name':
            self.name_full,
            'position':
            self.position
        }

        # # # SALARY # # #

    # # # Generate and Print PDF # # #
    def gen_pdf(self):
        create_pdf(self.data_to_print)
        return QtGui.QMessageBox.warning(
            self, 'Note', 'PDF file was generated.'
            ' Silent print job was sent on process', None)

    # # # Generate and Print PDF # # #

    # # # Update User Info and Config # # #
    def update_employee(self):
        emp = self.fetch_employee()
        profile = self.fetch_profile()
        config = self.fetch_config()

        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'

        status_value = True
        if self.inactive_radio.isChecked():
            status_value = False

        birthday = datetime.strptime(self.birthday_txt.text(),
                                     "%Y-%m-%d").date()

        if self.fname_txt.text().lower() == emp['first_name'].lower() \
                and self.mname_txt.text().lower() == emp['middle_name'].lower() \
                and self.lname_txt.text().lower() == emp['last_name'].lower() \
                and self.contact_txt.text() == profile['contact_number'] \
                and self.address_txt.text().lower() == profile['address'].lower() \
                and str(birthday) == str(profile['birthday']) \
                and self.height_txt.text() == str(profile['height']) \
                and gender == profile['gender'] \
                and status_value == emp['is_active'] \
                and position == emp['position'] \
                and rate == config['rate_per_hour'] \
                and dayoff == config['non_working_days'] \
                and self.sss_txt.text() == config['sss_number'] \
                and self.philhealth_txt.text() == config['philhealth_number'] \
                and self.pagibig_txt.text() == config['pagibig_number'] \
                and self.tin_txt.text() == config['tin_number']:
            QtGui.QMessageBox.information(self, 'Note',
                                          'you did not made any changes', None)
            return 0

        input_fields = [
            self.fname_txt.text(),
            self.mname_txt.text(),
            self.lname_txt.text(),
            self.contact_txt.text(),
            self.height_txt.text(),
            self.sss_txt.text(),
            self.philhealth_txt.text(),
            self.pagibig_txt.text(),
            self.tin_txt.text(),
            self.address_txt.text()
        ]

        if any(i == '' or i == None for i in input_fields):
            QtGui.QMessageBox.information(self, 'Note', 'complete the fields',
                                          None)
            return 0

        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)

        content = {
            'id': self.user_id,
            'first_name': self.fname_txt.text(),
            'middle_name': self.mname_txt.text(),
            'last_name': self.lname_txt.text(),
            'position': position,
            'is_admin': is_admin,
            'is_active': status_value,
            "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_per_hour': rate,
            'non_working_days': dayoff,
            'birthday': birthday,
            'address': self.address_txt.text(),
            'gender': gender,
            'height': self.height_txt.text(),
            'contact_number': self.contact_txt.text(),
        }

        title_failed = 'Failed'

        if len(self.height_txt.text()) != 3:
            title = 'Failed'
            msg = 'Incorrect height value'
            return QtGui.QMessageBox.information(self, title, msg, None)

        if len(self.sss_txt.text()) != 14:
            msg = 'Incorrect SSS number'
            QtGui.QMessageBox.information(self, title_failed, msg, None)
            return 0
        elif len(self.philhealth_txt.text()) != 14:
            msg = 'Incorrect PHILHEALTH number'
            QtGui.QMessageBox.information(self, title_failed, msg, None)
            return 0
        elif len(self.pagibig_txt.text()) != 14:
            msg = 'Incorrect PAGIBIG number'
            QtGui.QMessageBox.information(self, title_failed, msg, None)
            return 0
        elif len(self.tin_txt.text()) < 16:
            msg = 'Incorrect TIN number'
            QtGui.QMessageBox.information(self, title_failed, msg, None)
            return 0
        else:
            update = self.db.update_employee(content)

            if update == 'nice mother f****r':
                title_success = 'Success'
                msg = 'employee\'s information and configurations are updated'
                QtGui.QMessageBox.information(self, title_success, msg, None)
                self.hide()
                return 0
            else:
                msg = 'something went wrong, please check internet connection'
                QtGui.QMessageBox.information(self, title_failed, msg, None)
                return 0

    # # # Update User Info and Config # # #

    # # # Update Face Data Set # # #
    def capture_dataset(self):

        emp = self.fetch_employee()
        userx = self.db.get_user_info(emp['user'])
        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 False or int(id) == int(userx[2]):

                self.setEnabled(False)
                dataSetCreator.DataSetCreator(config.CAMERA_INDEX,
                                              int(userx[2]), 1,
                                              'dataSetsample')
                check_if_ok = CaptureCheckWindow(int(userx[2]),
                                                 for_update=True,
                                                 parent=self)
                if not check_if_ok.exec_():
                    check_if_ok.hide()
                else:
                    pass
                cv2.destroyAllWindows()
                self.setEnabled(True)
                msg = 'Face data sets are updated'
                QtGui.QMessageBox.information(self, 'Note', msg, None)
                return 0
            else:
                return QtGui.QMessageBox.warning(
                    self, 'Note',
                    'That face was already in use by other users', None)
Beispiel #13
0
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",
Beispiel #14
0
 def forgot_pass(self):
     db = EMS_db_model()
     forgot_pass_link = db.get_forgot_pass_link()
     webbrowser.open(forgot_pass_link)
Beispiel #15
0
    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)
    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)
    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)
Beispiel #18
0
import os
import subprocess
import shlex
from datetime import datetime, timedelta
import time
from models import EMS_db_model
db = EMS_db_model()


def clock_in():
    print(db.record_attendance(2, 'clock-in', 'longview048'))
    print(db.record_attendance(3, 'clock-in', 'what the f**k'))


def clock_out():
    print(db.record_attendance(2, 'clock-out', 'longview048'))
    print(db.record_attendance(3, 'clock-out', 'what the f**k'))


for i in range(246):
    if i == 0:
        now = datetime.now() + timedelta(days=1)

        date_str = now.strftime("%d %b %Y %H:%M:%S")

        subprocess.call(shlex.split("sudo date -s '%s'" % date_str))
        subprocess.call(shlex.split("sudo hwclock -w"))
        clock_in()
        print('first')
    else:
        if i % 2 == 0: