def project_completion(self): """ this method is used to complete project of current gpm. """ try: print("choose project") project_list = self.get_project_list() menu = Menu() project_names = [x for x in project_list.keys()] project_names.extend([str(BackButton.EXIT.name), str(BackButton.BACK.name)]) project_name = menu.draw_menu(project_names) input() if str(BackButton.BACK.name) == project_name: return project_id = project_list[project_name] self.project_id = project_id member_ids = self.conn.get_project_members(self.project_id) if len(member_ids) == 0: print(Color.F_Red+"Can't send project completion request to BDO \n because " "no member assigned to this project \n"+Base.END) else: for member_id in member_ids: self.member_id = member_id[0] self.delete_project_request() self.conn.commit_data() print(Color.F_Green + "Wage Request sent to BDO for all the assigned members \n "+ Base.END) except sqlite3.Error as e: print(e) self.conn.rollback_data()
def file_complain(self): """ this method is used to file complain. """ accident_types = self.conn.get_accident_types() accident_types_list = [x[1] for x in accident_types] menu = Menu() print("\n Choose accident type: \n") accident_types_list.extend([str(BackButton.BACK.name), str(BackButton.EXIT.name)]) accident_type = menu.draw_menu(accident_types_list) input() os.system('clear') if accident_type == str(BackButton.BACK.name): return accident_id = [x[0] for x in accident_types if x[1] == accident_type] location = input('enter accident location: ') complain_dict = dict() complain_dict['type'] = accident_id[0] complain_dict['timestamp'] = d.datetime.now() complain_dict['created_by'] = self.employee_id complain_dict['location'] = location complain_dict['status'] = AccidentStatus.NEW.name try: self.conn.report_new_accident(complain_dict) self.conn.commit_data() print("\n" + Color.F_Green + "record inserted" + Base.END) except Exception as e: print("\n" + Color.F_Red + "some exception occurred" + Base.END) print("reason:", e)
def employee_features(self): """ this method is used to print all employee features on console. """ try: while True: supervisor_role = self.conn.get_user_role(self.employee_id, Role.SUPERVISOR.value) if supervisor_role is not None: print(Color.F_Red, '\nYou are supervisor also.', Base.END) print(Color.F_Red, 'for more info contact admin.', Base.END) print("choose feature :\n") menu = Menu() features = [x.name for x in MemberFeatures] features.extend([str(BackButton.EXIT.name)]) feature = menu.draw_menu(features) input() required_feature = getattr(self, feature.lower()) required_feature() # again calling employee menu input() os.system('clear') self.employee_features() except Exception as e: print(e) sys.exit()
def main(): """ this method is used to call main menu for login """ conn = ConnectDb() try: os.system('clear') # select role for login print("login as:\n") menu = Menu() roles = [x.name for x in Role] roles.extend([str(BackButton.EXIT.name)]) role = menu.draw_menu(roles) role_id = Role[role].value input() # get user name and password for login user_name = input("enter user name: ") password = getpass() # check user authentication result = conn.get_user_with_role(user_name, role_id) flag = True if result is not None: os.system('clear') actual_pass = decrypt_pass(result[1]) if str(actual_pass.decode("utf-8")) == password: flag = False if role_id == int(Role.BDO.value): bdo = BDO() bdo.bdo_id = result[0] bdo.bdo_features() elif role_id == int(Role.GPM.value): gpm = GPM() gpm.gpm_id = result[0] gpm.gpm_features() elif role_id == int(Role.Member.value): member = Member() member.member_id = result[0] member.member_features() if result is None or flag: print(Color.F_Red + 'wrong credentials' + Base.END) input() main() except Exception as e: print(e) sys.exit() finally: conn.close_conn()
def show_requests(self): """ this method is used show request and resolve request of current gpm. """ try: projects = self.conn.get_requests(self.gpm_id) result = projects.fetchall() counter = 0 # getting columns for showing requests and adding index column at first in list projects_fields = (('index'),) + projects.description # request is empty then returning early with a message if len(result) == 0: print(Color.F_Red + "there is no pending request" + Base.END) return temp = result # converting list of tuples into list of list temp = [list(elem) for elem in temp] print("write index of request to manage:\n") for request in temp: request.insert(0, counter) counter += 1 table = PrettyTable() table.field_names = [column[0] for column in projects_fields[:-1]] for row in temp: table.add_row(row[:-1]) print(table) row_number = input("enter index number: ") if not Validation.is_int(row_number): print("row number is not valid") input() return menu = Menu() result_names = [x.name for x in RequestResult] result_names.extend([str(BackButton.EXIT.name)]) result_name = menu.draw_menu(result_names) input() status = "NULL" if str(result_name) == str(RequestResult.APPROVED.name): status = "'True'" elif str(result_name) == str(RequestResult.REJECTED.name): status = "'False'" self.conn.resolve_request(status, result[int(row_number)][4]) self.conn.commit_data() print(Color.F_Green + "Request completed successfully" + Base.END) except Exception as e: print(e) self.conn.rollback_data()
def delete_project(self): """ this method is used to delete project for current bdo. """ print("choose project") project_list = self.get_project_list() menu = Menu() project_names = [x for x in project_list.keys()] project_names.extend( [str(BackButton.EXIT.name), str(BackButton.BACK.name)]) project_name = menu.draw_menu(project_names) input() if project_name == str(BackButton.BACK.name): return project_id = project_list[project_name] self.project_id = project_id self.project_deletion() print(Color.F_Green + "project deleted successfully " + Base.END)
def gpm_features(self): """ this method is used to print all gpm features on console. """ try: print("choose feature :\n") menu = Menu() features = [x.name for x in GpmFeatures] features.extend([str(BackButton.EXIT.name)]) feature = menu.draw_menu(features) input() required_feature = getattr(self, feature.lower()) required_feature() # again calling gpm menu input() os.system('clear') self.gpm_features() except Exception as e: print(e) sys.exit()
def complete_member_project(self): """ this method is used to complete project of current gpm. """ try: print("choose project") project_list = self.get_project_list() menu = Menu() project_names = [x for x in project_list.keys()] project_names.extend([str(BackButton.EXIT.name), str(BackButton.BACK.name)]) project_name = menu.draw_menu(project_names) input() if str(BackButton.BACK.name) == project_name: return project_id = project_list[project_name] self.project_id = project_id member_ids = self.conn.get_project_member_name(self.project_id) member_dict = {} for data in member_ids: member_dict[data[1]] = data[0] menu = Menu() member_names = [x for x in member_dict.keys()] member_names.extend([str(BackButton.EXIT.name)]) member_name = menu.draw_menu(member_names) input() member_id = member_dict[member_name] self.member_id = member_id self.delete_project_request() self.conn.commit_data() print(Color.F_Green + "member removal request sent to BDO" + Base.END) except sqlite3.Error as e: print(e) self.conn.rollback_data()
def update_gpm(self): """ this method is used to update gpm for current bdo. """ try: gpm_list = self.get_gpm_list() menu = Menu() gpm_names = [x for x in gpm_list.keys()] gpm_names.extend( [str(BackButton.EXIT.name), str(BackButton.BACK.name)]) gpm_name = menu.draw_menu(gpm_names) input() if str(BackButton.BACK.name) == gpm_name: return gpm_id = gpm_list[gpm_name] print("select the field to update: \n") menu = Menu() details = [x.name for x in GpmUpdateFields] details.extend([str(BackButton.EXIT.name)]) field = menu.draw_menu(details) input() user_input = input("enter new value for " + str(field) + " ") user_table_fields = [1, 2, 3] # validating field if field == str(GpmUpdateFields.PASSWORD.name): if not Validation.password(user_input): print("password is weak") input() return user_input = encrypt_pass(user_input) if field == str(GpmUpdateFields.AGE.name): if not Validation.age(user_input): print("age is not valid") input() return if field == str(GpmUpdateFields.PINCODE.name): if not Validation.pincode(user_input): print("pincode is not valid") input() return if field == str(GpmUpdateFields.GENDER.name): if not Validation.gender(user_input): print("gender is not valid") input() return query = "" # if field belong to user table if user_table_fields.count(GpmUpdateFields[field].value) == 1: self.conn.update_user(str(field), gpm_id, user_input) else: self.conn.update_personal_details(str(field), gpm_id, user_input) self.conn.commit_data() print("\n" + Color.F_Green + "record updated" + Base.END) except Exception as e: print(e) self.conn.rollback_data()
def create_project(self): """ this method is used to create project for current bdo. """ try: print("choose gpm for project\n") gpm_list = self.get_gpm_list() menu = Menu() gpm_names = [x for x in gpm_list.keys()] gpm_names.extend([str(BackButton.EXIT.name)]) gpm_name = menu.draw_menu(gpm_names) input() gpm_id = gpm_list[gpm_name] print("choose project type:\n") menu2 = Menu() project_types = [x.name for x in ProjectType] project_types.extend([str(BackButton.EXIT.name)]) project_type = menu2.draw_menu(project_types) input() project_id = str(uuid.uuid4()) project_name = input("enter project name: ") labours = input("enter expected labours: ") if not Validation.is_int(labours): print("labours count is not valid") input() sys.exit() cost = input("enter estimated project cost: ") if not Validation.is_int(cost): print("cost is not valid") input() sys.exit() area = input("enter estimated project area: ") if not Validation.is_int(area): print("area is not valid") input() sys.exit() start_date = input("enter estimated start date: ") if not Validation.is_date(start_date): print("start date is not valid") input() sys.exit() end_date = input("enter estimated end date: ") if not Validation.is_date(end_date): print("end date is not valid") input() sys.exit() is_deleted = 'False' created_by = self.bdo_id self.conn.create_project(project_id, project_name, labours, cost, area, start_date, end_date, gpm_id, created_by, project_type, is_deleted) self.conn.commit_data() print("\n" + Color.F_Green + "project created" + Base.END) except Exception as e: print(e) self.conn.rollback_data()
def file_complain(self): """ this method is used to file complain for current member to bdo/gpm. """ try: print("Choose a complain recipient:\n") menu = Menu() recipients = [x.name for x in ComplainRecipients] recipients.extend( [str(BackButton.EXIT.name), str(BackButton.BACK.name)]) recipient = menu.draw_menu(recipients) input() if str(BackButton.BACK.name) == recipient: return member_details = self.conn.get_bdo_gpm_for_member(self.member_id) if member_details is None: print("you don't have any manager to file complain") return recipient_id = "" if recipient == str(ComplainRecipients.BDO.name): recipient_id = member_details[2] elif recipient == str(ComplainRecipients.GPM.name): recipient_id = member_details[1] else: print(Color.F_Red + "Invalid option" + Base.END) return request_msg = input("enter your request: ") self.conn.register_complain(str(RequestType.ISSUES.name), self.member_id, request_msg, recipient_id) self.conn.commit_data() print(Color.F_Green + "Request sent to " + recipient + Base.END) except sqlite3.Error as e: print(e) self.conn.rollback_data()
def delete_gpm(self): """ this method is used to delete gpm for current bdo. """ try: print("choose gmp to delete:\n") gpm_list = self.get_gpm_list() menu = Menu() gpm_names = [x for x in gpm_list.keys()] gpm_names.extend( [str(BackButton.EXIT.name), str(BackButton.BACK.name)]) gpm_name = menu.draw_menu(gpm_names) input() if gpm_name == str(BackButton.BACK.name): return self.gpm_id = gpm_list.pop(gpm_name) os.system('clear') print('choose another gpm to assign current gpm members:\n') menu2 = Menu() if len(gpm_list.keys()) == 0: print( Color.F_Red + "Can't delete GPM because you don't have any alternative GPM " + Base.END) return alternative_gpm_names = [x for x in gpm_list.keys()] alternative_gpm_names.extend( [str(BackButton.EXIT.name), str(BackButton.BACK.name)]) alternative_gpm_name = menu2.draw_menu(alternative_gpm_names) input() if alternative_gpm_name == str(BackButton.BACK.name): return # assigning new gpm to members self.conn.update_member_gpm(gpm_list[alternative_gpm_name], self.gpm_id) # completing all gpm projects project_ids = self.conn.get_gpm_projects(self.gpm_id) for project_id in project_ids: self.project_id = project_id member_ids = self.conn.get_project_members(self.project_id) for member_id in member_ids: self.member_id = member_id[0] self.delete_project_members() self.conn.update_user('is_deleted', self.gpm_id, 'True') self.conn.commit_data() except Exception as e: print(e) self.conn.rollback_data()
def update_members(self): """ this method is used to update member details of current gpm. """ members_list = self.get_members_list() menu = Menu() members_names = [x for x in members_list.keys()] members_names.extend( [str(BackButton.EXIT.name), str(BackButton.BACK.name)]) members_name = menu.draw_menu(members_names) input() if str(BackButton.BACK.name) == members_name: return members_id = members_list[members_name] print("select the field to update: \n") menu = Menu() details = [x.name for x in GpmUpdateFields] details.extend([str(BackButton.EXIT.name)]) field = menu.draw_menu(details) input() user_input = input("enter new value for " + str(field) + " ") user_table_fields = [1, 2, 3] # validations if field == str(GpmUpdateFields.GENDER.name): if not Validation.gender(user_input): print("gender is not valid") input() sys.exit() if field == str(GpmUpdateFields.PINCODE.name): if not Validation.pincode(user_input): print("pincode is not valid") input() sys.exit() if field == str(GpmUpdateFields.AGE.name): if not Validation.is_int(user_input): print("age is not valid") input() sys.exit() # if field belong to user table if user_table_fields.count(GpmUpdateFields[field].value) == 1: self.conn.update_user(str(field), members_id, user_input) else: self.conn.update_personal_details(str(field), members_id, user_input) self.conn.commit_data() print("\n" + Color.F_Green + "record updated" + Base.END)
def assign_members_to_projects(self): """ this method is used to assign member to project of current gpm. """ print("choose project") project_list = self.get_project_list() menu = Menu() project_names = [x for x in project_list.keys()] project_names.extend( [str(BackButton.EXIT.name), str(BackButton.BACK.name)]) project_name = menu.draw_menu(project_names) input() if str(BackButton.BACK.name) == project_name: return project_id = project_list[project_name] print("choose member for project") members_list = self.get_members_list() self.project_id = project_id project_members_id = self.conn.get_project_members(self.project_id) # removing already assigned members from the list for id in project_members_id: temp = None for key, value in members_list.items(): if id[0] == value: temp = key break members_list.pop(temp, None) members_required = self.conn.get_project_members_required( self.project_id) # checking if total number of members in given project are less then actual project requirement if members_required[0] <= len(project_members_id): print(Color.F_Red + "members limit exceeded" + Base.END) return # removing members who are already in some projects members_list = { key: value for key, value in members_list.items() if project_members_id.count(value) == 0 } menu = Menu() member_names = [x for x in members_list.keys()] member_names.extend([str(BackButton.EXIT.name)]) member_name = menu.draw_menu(member_names) input() member_id = members_list[member_name] self.member_id = member_id self.assign_project_members_request()
def main(): """ this method is used to call main menu for login """ conn = ConnectDb() try: os.system('clear') # select role for login print("login as:\n") menu = Menu() roles = [x.name for x in Role] roles.extend([str(BackButton.EXIT.name)]) role = menu.draw_menu(roles) role_id = Role[role].value input() # get user name and password for login user_name = input("enter user name: ") password = getpass() # check user authentication result = conn.get_user_info(user_name) flag = True auth_flag = True if result is not None: os.system('clear') actual_pass = decrypt_pass(result[1].encode()) if actual_pass == password: flag = False if role_id == int(Role.EMPLOYEE.value): auth_flag = False emp = Employee() emp.employee_id = result[0] emp.employee_features() else: user_role = conn.get_user_role(result[0], role_id) if user_role is not None: auth_flag = False if role_id == int(Role.SUPERVISOR.value): pass supervisor = Supervisor() supervisor.supervisor_id = result[0] supervisor.supervisor_features() elif role_id == int(Role.ADMIN.value): pass member = Admin() member.admin_id = result[0] member.admin_features() if flag: print(Color.F_Red + 'wrong credentials' + Base.END) input() main() if auth_flag: print(Color.F_Red + 'you are not authorized' + Base.END) input() main() except Exception as e: print(e) sys.exit() finally: conn.close_conn()
def show_requests(self): """ this method is used to show and resolve all requests for current bdo. """ try: projects = self.conn.get_requests(self.bdo_id) # adding index column to given result projects_fields = (('index'), ) + projects.description result = projects.fetchall() counter = 0 # request is empty then returning early with a message if len(result) == 0: print(Color.F_Red + "there is no pending request" + Base.END) return print("write index of request to manage:\n") temp = result # converting list of tuples into list of list temp = [list(elem) for elem in temp] for request in temp: if str(RequestType.APPROVAL.name) == str(request[0]): temp2 = str(request[2]).split('|') request[2] = temp2[0] + " request for " + temp2[ 4] + " project for " + temp2[1] + " member" # inserting data for index column request.insert(0, counter) counter += 1 table = PrettyTable() # assigning field names to pretty table object and removing request id column table.field_names = [column[0] for column in projects_fields[:-1]] for row in temp: # removing request id from temp list and adding to table row table.add_row(row[:-1]) print(table) row_number = input("enter index number: ") if not Validation.is_int(row_number): print("index number is not valid") input() sys.exit() menu = Menu() result_names = [x.name for x in RequestResult] result_names.extend([str(BackButton.EXIT.name)]) result_name = menu.draw_menu(result_names) input() status = "NULL" if str(RequestType.APPROVAL.name) == str( result[int(row_number)][0]): temp = str(result[int(row_number)][2]).split('|') req_type = str(temp[0]) self.project_id = str(temp[3]) self.member_id = str(temp[2]) if req_type == str( ApprovalType.WAGE.name) and str(result_name) == str( RequestResult.APPROVED.name): self.delete_project_members() status = "'True'" elif req_type == str( ApprovalType.MEMBER.name) and str(result_name) == str( RequestResult.APPROVED.name): project_members_id = self.conn.get_project_members( self.project_id) members_required = self.conn.get_project_members_required( self.project_id) # checking if total number of members in given project are less then actual project requirement if members_required[0] <= len(project_members_id): print( Color.F_Red + "project members limit exceeded can't accept request" + Base.END) return self.conn.assign_project_members(self.project_id, self.member_id) status = "'True'" elif str(result_name) == str(RequestResult.REJECTED.name): status = "'False'" else: if str(result_name) == str(RequestResult.APPROVED.name): status = "'True'" elif str(result_name) == str(RequestResult.REJECTED.name): status = "'False'" self.conn.resolve_request(status, result[int(row_number)][4]) self.conn.commit_data() print(Color.F_Green + "Request completed successfully" + Base.END) except Exception as e: print(e) self.conn.rollback_data()
def update_project(self): """ this method is used to update project for current bdo. """ print("choose project") project_list = self.get_project_list() menu = Menu() project_names = [x for x in project_list.keys()] project_names.extend( [str(BackButton.EXIT.name), str(BackButton.BACK.name)]) project_name = menu.draw_menu(project_names) input() if str(BackButton.BACK.name) == project_name: return project_id = project_list[project_name] print("select the field to update: \n") menu2 = Menu() details = [x.name for x in ProjectsUpdateFields] details.extend([str(BackButton.EXIT.name)]) field = menu2.draw_menu(details) input() user_input = "" if ProjectsUpdateFields[ field].value == ProjectsUpdateFields.PROJECT_TYPE.value: print("choose project type: \n") menu3 = Menu() project_types = [x.name for x in ProjectType] project_types.extend([str(BackButton.EXIT.name)]) user_input = menu3.draw_menu(project_types) input() else: user_input = input("enter new value for " + str(field) + " ") # validations if field == str(ProjectsUpdateFields.AREA_OF_PROJECT.name): if not Validation.is_int(user_input): print("area is not valid") input() sys.exit() if field == str(ProjectsUpdateFields.TOTAL_LABOUR_REQUIRED.name): if not Validation.is_int(user_input): print("labour required is not valid") input() sys.exit() if field == str(ProjectsUpdateFields.ESTIMATED_START_DATE.name): if not Validation.is_date(user_input): print("start date is not valid") input() sys.exit() if field == str(ProjectsUpdateFields.ESTIMATED_END_DATE.name): if not Validation.is_date(user_input): print("end date is not valid") input() sys.exit() if field == str(ProjectsUpdateFields.ESTIMATED_COST.name): if not Validation.is_int(user_input): print("cost is not valid") input() sys.exit() self.conn.update_project(field, user_input, project_id) self.conn.commit_data() print("\n" + Color.F_Green + "record updated" + Base.END)