def update_one_employee_salary(id, working_hour, wage, office, frame, window_s): try: f = open( "C:/Users/G40/Desktop/Human Resource/Database/Salary{}.pickle". format(office), "rb") # Read file p_list = pickle.load(f) f.close() except: p_list = [] f = open("C:/Users/G40/Desktop/Human Resource/Database/Employee{}.pickle". format(office), "rb") # Read file e_list = pickle.load(f) f.close() if not any(employee.id == id.get() for employee in e_list): messagebox.showerror("", "ID Not Found !", parent=window_s) else: for i in range(len(p_list)): if p_list[i - 1].id == id.get(): p_list.pop(i - 1) for i in range(len(e_list)): if e_list[i].id == id.get(): name = e_list[i].name id2 = id.get() try: if float(working_hour.get()) > 200.0: messagebox.showwarning("", "Work Hour : No more than 200h", parent=window_s) # Show error dialog else: working_hour2 = float(working_hour.get()) # String to float try: if float(wage.get()) > 9999.0: messagebox.showwarning( "", "Wage : No more than 9999$ !", parent=window_s) # Show error dialog else: wage2 = float(wage.get()) # String to float total = wage2 * working_hour2 total = math.floor(total) p_list.append( Salary(id2, name, office, working_hour2, wage2, total)) p_list = sorted( p_list, key=lambda x: x.id) # Sort list base on ID f = open( "C:/Users/G40/Desktop/Human Resource/Database/Salary{}.pickle" .format(office), "wb") pickle.dump(p_list, f) # Dump p_list to new file f.close() show_all_employee_salary(office, frame, window_s) # Show p_list except: messagebox.showwarning( "", "Wage : Number only ! ", parent=window_s) # Show error dialog except: messagebox.showwarning("", "Work Hour : Number only !", parent=window_s) # Show error dialog
def update_one_staff_salary(id, working_hour, wage, frame, window_m): # Update salary of one Staff in s_list try: f = open( "C:\\Users\\FLOS IGNIS\\OneDrive\\Máy tính\\Human Resource\\Database\\Staff Salary.pickle", "rb") # Read database file m_list = pickle.load(f) f.close() except: m_list = [] f = open( "C:\\Users\\FLOS IGNIS\\OneDrive\\Máy tính\\Human Resource\\Database\\Staff_s.pickle", "rb") # Read database file s_list = pickle.load(f) f.close() if not any(staff.id == id.get() for staff in s_list): messagebox.showerror("", "ID Not Found !", parent=window_m) # Error dialog else: for i in range(len(m_list)): # If ID is found in m_list if m_list[i - 1].id == id.get(): m_list.pop(i - 1) # Delete Salary info of that ID for i in range(len(s_list)): if s_list[i].id == id.get(): name = s_list[i].name office = s_list[i].office id2 = id.get() try: if float(working_hour.get()) > 200.0: messagebox.showwarning( "", "Work Hour : No more than 200h") # Error dialog else: working_hour2 = float(working_hour.get()) # String to float try: if float(wage.get()) > 9999.0: messagebox.showwarning( "", "Wage : No more than 9999$ !") # Error dialog else: wage2 = float(wage.get()) # String to float total = wage2 * working_hour2 total = math.floor(total) m_list.append( Salary(id2, name, office, working_hour2, wage2, total)) # Add new salary info for that ID m_list = sorted(m_list, key=lambda x: x.id) f = open( "C:\\Users\\FLOS IGNIS\\OneDrive\\Máy tính\\Human Resource\\Database\\Staff Salary.pickle", "wb") pickle.dump(m_list, f) # Dump m_list to new file f.close() show_all_staff_salary(frame, window_m) # Show m_list except: messagebox.showwarning("", "Wage : Number only ! ", parent=window_m) # Error dialog except: messagebox.showwarning("", "Work Hour : Number only !", parent=window_m) # Error dialog
def salary(e_list, office): # # Create a new list of salary base on e_list # Payment list (Employee salary) as p_list # # return p_list show_Employee(e_list) print() print("Choose employee 'ID' from the list to update salary ") print() p_list = [] for i in range(len(e_list)): # ID --------------------------------------------------------------- id = input("Employee ID : ") while True: id = prevent_Duplicate(id, p_list) if not any(employee.id == id for employee in e_list): id = input("\tNo ID found. Try again : ") else: break for j in range(len(e_list)): if e_list[j].id == id: name = e_list[j].name # Working hours ----------------------------------------------------- working_hour = input("\tWorking Hours (total hour/month) : ") while True: try: if float(working_hour) < 201.0: working_hour = float(working_hour) break else: working_hour = input("Try again (smaller than 201h) : ") except: working_hour = input("Number only (smaller than 201h) : ") # wage -------------------------------------------------------------- wage = input("\tWage/Hour (smaller than 9999$) : ") while True: try: if float(wage) < 9999.0: wage = float(wage) break else: wage = input("Try again (smaller than 9999$) : ") except: wage = input("Number only (smaller than 9999$) : ") total = wage * working_hour total = math.floor(total) p_list.append(Salary(id, name, office, working_hour, wage, total)) print() p_list = sorted(p_list, key=lambda x: x.id) return p_list
def add_Staff_Salary(s_list, m_list): # # Add new staff salary info # return m_list print() show_Staff_Salary(m_list) id = input("Staff ID : ") while True: id = prevent_Duplicate(id, m_list) if not any(staff.id == id for staff in s_list): id = input("\tNo ID found. Try again : ") else: break for j in range(len(s_list)): if s_list[j].id == id: name = s_list[j].name working_hour = input("\tWorking Hours (total hour/month) : ") while True: try: if float(working_hour) < 201.0: working_hour = float(working_hour) break else: working_hour = input("Try again (smaller than 201h) : ") except: working_hour = input("Number only (smaller than 201h) : ") wage = input("\tWage/Hour (smaller than 9999$) : ") while True: try: if float(wage) < 9999.0: wage = float(wage) break else: wage = input("Try again (smaller than 9999$) : ") except: wage = input("Number only (smaller than 9999$) : ") total = wage * working_hour total = math.floor(total) office = id[0] m_list.append(Salary(id, name, office, working_hour, wage, total)) print() m_list = sorted(m_list, key=lambda x: x.id) return m_list
def add_Salary(e_list, p_list, office): # # Add new salary info of the office # return p_list print() show_Salary(p_list) # ID ---------------------------------------------------------------- id = input("Employee ID : ") while True: id = prevent_Duplicate(id, p_list) if not any(employee.id == id for employee in e_list): id = input("\tNo ID found. Try again : ") else: break for j in range(len(e_list)): if e_list[j].id == id: name = e_list[j].name # Working hours ------------------------------------------------------- working_hour = input("\tWorking Hours (total hour/month) : ") while True: try: if float(working_hour) < 201.0: working_hour = float(working_hour) break else: working_hour = input("Try again (smaller than 201h) : ") except: working_hour = input("Number only (smaller than 201h) : ") # wage ---------------------------------------------------------------- wage = input("\tWage/Hour (smaller than 9999$) : ") while True: try: if float(wage) < 9999.0: wage = float(wage) break else: wage = input("Try again (smaller than 9999$) : ") except: wage = input("Number only (smaller than 9999$) : ") total = wage * working_hour total = math.floor(total) p_list.append(Salary(id, name, office, working_hour, wage, total)) print() p_list = sorted(p_list, key=lambda x: x.id) return p_list
def update_all_staff_salary( working_hour, wage, frame, window_m): # Update all staff salary for staff in s_list f = open( "C:\\Users\\FLOS IGNIS\\OneDrive\\Máy tính\\Human Resource\\Database\\Staff_s.pickle", "rb") # Read Staff_s.pickle s_list = pickle.load(f) f.close() m_list = [] try: if float(working_hour.get()) > 200.0: messagebox.showwarning("", "Work Hour : No more than 200h", parent=window_m) # Error dialog else: working_hour2 = float(working_hour.get()) # Turn string to float try: if float(wage.get()) > 9999.0: messagebox.showwarning("", "Wage : No more than 9999$ !", parent=window_m) # Error dialog else: for i in range(len(s_list)): wage2 = float(wage.get()) # Turn string to float total = wage2 * working_hour2 total = math.floor(total) id = s_list[i].id name = s_list[i].name office = id[0] # office = first letter of ID m_list.append( Salary(id, name, office, working_hour2, wage2, total)) m_list = sorted( m_list, key=lambda x: x.id) # Sort m_list base on ID f = open( "C:\\Users\\FLOS IGNIS\\OneDrive\\Máy tính\\Human Resource\\Database\\Staff Salary.pickle", "wb") pickle.dump(m_list, f) # Create new file, dump m_list to the file f.close() show_all_staff_salary(frame, window_m) # Show m_list except: messagebox.showwarning("", "Wage : Number only ! ", parent=window_m) # Error dialog except: messagebox.showwarning("", "Work Hour : Number only !", parent=window_m) # Error dialog
def update_all_employee_salary(working_hour, wage, office, frame, window_s): f = open( "C:\\Users\\FLOS IGNIS\\OneDrive\\Máy tính\\Human Resource\\Database\\Employee{}.pickle" .format(office), "rb") # Read file e_list = pickle.load(f) f.close() p_list = [] try: if float(working_hour.get()) > 200.0: messagebox.showwarning("", "Work Hour : No more than 200h", parent=window_s) # Show error dialog else: working_hour2 = float(working_hour.get()) # String to float try: if float(wage.get()) > 9999.0: messagebox.showwarning( "", "Wage : No more than 9999$ !", parent=window_s) # Show error dialog else: for i in range(len(e_list)): wage2 = float(wage.get()) # String to float total = wage2 * working_hour2 total = math.floor(total) id = e_list[i].id name = e_list[i].name office = id[0] p_list.append( Salary(id, name, office, working_hour2, wage2, total)) p_list = sorted(p_list, key=lambda x: x.id) # Sort list base on ID f = open( "C:\\Users\\FLOS IGNIS\\OneDrive\\Máy tính\\Human Resource\\Database\\Salary{}.pickle" .format(office), "wb") pickle.dump(p_list, f) # Dump p_list to new file f.close() show_all_employee_salary(office, frame, window_s) # Show p_list except: messagebox.showwarning("", "Wage : Number only !", parent=window_s) # Show error dialog except: messagebox.showwarning("", "Work Hour : Number only !", parent=window_s) # Show error dialog
def staff_Salary(s_list): # # Create a new list of salary base on s_list # Money list (Staff salary) as m_list # # return m_list show_Staff(s_list) print() print("Choose Staff 'ID' from the list to update salary ") print() m_list = [] for i in range(len(s_list)): # Input Staff id # if id is not match # input id # else # break id = input("Staff ID : ") while True: id = prevent_Duplicate(id, m_list) if not any(staff.id == id for staff in s_list): id = input("\tNo ID found. Try again : ") else: break for j in range(len(s_list)): if s_list[j].id == id: name = s_list[j].name # # input working_hour of Staff # while # if working_hour < 201.0 # return working_hour # else # retry =input(working_hour) working_hour = input("\tWorking Hours (total hour/month) : ") while True: try: if float(working_hour) < 201.0: working_hour = float(working_hour) break else: working_hour = input("Try again (smaller than 201h) : ") except: working_hour = input("Number only (smaller than 201h) : ") # # input wage of staff per hour # while # if wage < 9999.0 # return wage # else # retry = input(wage) wage = input("\tWage/Hour (smaller than 9999$) : ") while True: try: if float(wage) < 9999.0: wage = float(wage) break else: wage = input("Try again (smaller than 9999$) : ") except: wage = input("Number only (smaller than 9999$) : ") # Total salary = woring_hour * wage total = wage * working_hour total = math.floor(total) office = id[0] m_list.append(Salary(id, name, office, working_hour, wage, total)) print() m_list = sorted(m_list, key=lambda x: x.id) return m_list