def update_transaction(): view.clear_console() transactions = sales.read() view.print_table(transactions, sales.HEADERS, "Transactions: ") is_correct_value = False while not is_correct_value: transaction_id = view.get_input('Provide a valid transactions id to update profile: ') try: transaction_id = int(transaction_id) if transaction_id > 0 and transaction_id <= len(transactions): is_correct_value = True transaction_id = int(transaction_id) - 1 else: view.print_error_message("Incorrect value. Try again.") except: view.print_error_message("Incorrect value. Try again.") transaction_to_change = transactions.pop(transaction_id) want_change_next_value = True while want_change_next_value: index = view.get_input( 'Specify which value you are attempting to change \n1 for Customer id, 2 for Product, 3 for Price, 4 for Date: ') choices = ['1', '2', '3', '4'] while index not in choices: view.print_error_message("Incorrect value. Try again!") index = view.get_input( 'Specify which value you are attempting to change \n1 for Customer id, 2 for Product, 3 for Price, 4 for Date: ') transaction_to_change[int(index)] = view.get_input("Provide new value: ") want_change_next_value = view.get_yes_or_no("Would you like to change another value? ") transactions.append(transaction_to_change) sales.create(transactions)
def add_customer(): view.print_message("") questions = [ "Please enter the name for the new customer:", "Please enter the email address for the new customer:", "Please enter \"yes\" or \"no\" if the new customer is subscribed to our news letter:" ] answers = [] for item in questions: if item != questions[-1]: user_input = view.get_input(item) answers.append(user_input) view.print_message("") else: counter = 0 while counter < 1: user_input = view.get_input(item) if user_input == "yes": answers.append("1") counter = counter + 1 elif user_input == "no": answers.append("0") counter = counter + 1 else: view.print_message("Invalid input") continue crm.create_new_customer(answers[0], answers[1], answers[2]) view.print_message("") view.print_message( "New customer added, please list customers to see the update.") view.print_message("")
def add_transaction(): # view.print_error_message("Not implemented yet.") '''cześć potrzebna gdy już bedzie działał crm''' matching_customers_names_list = [] while matching_customers_names_list == []: partial_customer_name = view.get_input("Enter name or part of customer's name") matching_customers_names_list = get_matching_names(partial_customer_name) if matching_customers_names_list == None: return insert_exit_option(matching_customers_names_list) view.print_menu("Matching customers names", matching_customers_names_list) customer_number = int(view.get_input("Choose the customer to add transaction on it")) if customer_number == 0: return customer_name = matching_customers_names_list[customer_number] # # funkcja która dostaje nazwę klienta i zwraca jego id customer_id = crm.find_customer_id(customer_name) new_transaction_data = view.get_inputs(sales.HEADERS[sales.PRODUCT_INDEX:]) new_transaction_data.insert(0,customer_id) new_transaction = sales.create_new_transaction(new_transaction_data) # print(new_transaction) view.print_message("New transaction has been added") view.print_table([new_transaction],sales.HEADERS)
def get_employee_data(): data_label = hr.HEADERS # id_label = f"Please provide {data_label[0]} of new employee: " # id = view.get_input(id_label) # id = accept_data(id, id_label) # unikalny id name_label = f"Please provide {data_label[1]} of new employee: " name = view.get_input(name_label) name = accept_data(name, name_label) date_of_birth_label = f"Please provide {data_label[2]} of new employee i n format yyyy-mm-dd: " date_of_birth = view.get_input(date_of_birth_label) date_of_birth = accept_data(date_of_birth, date_of_birth_label) department_label = f"Please provide {data_label[3]} of new employee: " department = view.get_input(department_label) department = accept_data(department, department_label) clearance_label = f"Please provide {data_label[4]} of new employee: " clearance = view.get_input(clearance_label) clearance = accept_data(clearance, clearance_label) return [name, date_of_birth, department, clearance]
def update_customer(): NAME = 1 EMAIL = 2 SUBSCRIBED = 3 data = crm.get_CRM_info() HEADERS = ["NAME", "EMAIL", "SUBSCRIBED"] counter = 0 counter_1 = 0 id_list = [] for item in data: id_list.append(item[0]) while counter < 1: view.print_message("") cust_id = view.get_input( "Please enter the id of the client for which you want to perform updates:" ) view.print_message("") if cust_id in id_list: view.print_message( "Your input is valid, please see below the details:") view.print_message("") counter = counter + 1 else: view.print_message("Invalid ID") for inner_list in data: if cust_id in inner_list: view.print_message("ID : " + inner_list[0]) view.print_message("NAME : " + inner_list[1]) view.print_message("EMAIL : " + inner_list[2]) view.print_message("SUBSCRIBED : " + inner_list[3]) while counter_1 < 1: view.print_message("") user_input = view.get_input( "Please enter the value that you want to modify \"name\", \"email\" or \"subscribed\":" ) view.print_message("") if user_input.upper() in HEADERS: view.print_message(f"{user_input.upper()} selected") counter_1 = counter_1 + 1 else: view.print_message("Invalid input") view.print_message("") user_modify = view.get_input( f"Please enter the new value for {user_input.upper()}:") view.print_message("") for inner_list1 in data: if cust_id in inner_list1: if user_input.upper() == "NAME": inner_list1[NAME] = user_modify elif user_input.upper() == "EMAIL": inner_list1[EMAIL] = user_modify elif user_input.upper() == "SUBSCRIBED": inner_list1[SUBSCRIBED] = user_modify view.print_message( "Update performed, please list customers to see the update.") crm.update_customer_info(data)
def delete_transaction(): view.print_message("Delete transaction.") transaction_id = view.get_input("Provide transaction ID") if view.get_input("Type 'yes' to confirm deletion").lower() == 'yes': view.print_message(f"Transaction {transaction_id} succesfully deleted.") if sales.remove_transaction(transaction_id) \ else view.print_error_message(f"Transaction of ID {transaction_id} does not exist.") else: view.print_message("Delete cancelled")
def update_employee(): EMPLOYEE = 1 BIRTHDATE = 2 DEPARTMENT = 3 CLEARANCE = 4 data = hr.list_employees1() HEADERS = ["EMPLOYEE", "BIRTHDATE", "DEPARTMENT", "CLEARANCE"] counter = 0 counter_1 = 0 id_list = [] for item in data: id_list.append(item[0]) while counter < 1: view.print_message("") cust_id = view.get_input("Please enter the id of the employee you want to update info: ") view.print_message("") if cust_id in id_list: view.print_message("Your input is valid, please see below the details:") view.print_message("") counter += 1 else: view.print_message("Invalid ID") for inner_list in data: if cust_id in inner_list: view.print_message("ID :" + inner_list[0]) view.print_message("EMPLOYEE: "+ inner_list[1]) view.print_message("BIRTHDATE : "+ inner_list[2]) view.print_message("DEPARTMENT : "+ inner_list[3]) view.print_message("CLEARANCE : "+ inner_list[4]) while counter_1 < 1: view.print_message("") user_input = view.get_input("Please enter the value that you want to modify \'employee\', \'birthdate\', \'department\', \'clearance\': ") view.print_message("") if user_input.upper() in HEADERS: view.print_message(f"{user_input.upper()} selected") counter_1 += 1 else: view.print_message("Invalid input") view.print_message("") user_modify = view.get_input(f"Please enter the new value for {user_input.upper()}: ") view.print_message('') for inner_list in data: if cust_id in inner_list: if user_input.upper() == "EMPLOYEE": inner_list[EMPLOYEE] = user_modify elif user_input.upper() == "BIRTHDATE": inner_list[BIRTHDATE] = user_modify elif user_input.upper() == "DEPARTMENT": inner_list[DEPARTMENT] = user_modify elif user_input.upper() == "CLEARANCE": inner_list[CLEARANCE] = user_modify view.print_message("Update performed, please list employees to see the update.") hr.update_employee1(data)
def add_customer(): index_customer_name = 1 index_Id = 0 table = crm.get_table() Id = list(crm.get_Id()) name = view.get_input("Customer name: ") email = view.get_input("Customer email:") subscribtion = view.get_input("Is subscribed to the newsletter? 1: yes, 0: no:") table.insert(0, Id) view.print_table(table) data_manager.write_table_to_file("model/crm/crm.csv", table, separator= ';') return table
def count_and_sum_transactions(): lines = file_handling.read_table_from_file(sales.DATAFILE, separator=';') user_input_start_date = view.get_input(sales.HEADERS[DATE_INDEX]) user_input_end_date = view.get_input(sales.HEADERS[DATE_INDEX]) user_range_date_list = [user_input_start_date, user_input_end_date] counter = 0 sum_of_transactions = 0 for line in range(len(lines)): transaction_date = lines[line][DATE_INDEX] month_of_user_input_start_date = months.get( user_range_date_list[0][5:7]) month_of_user_input_end_date = months.get(user_range_date_list[1][5:7]) month_of_transaction = months.get(transaction_date[5:7]) day_of_user_input_start_date = days.get(user_range_date_list[0][8:10]) day_of_user_input_end_date = days.get(user_range_date_list[1][8:10]) day_of_transaction = days.get(transaction_date[8:10]) if transaction_date[0:4] > user_range_date_list[0][ 0:4] and transaction_date[0:4] < user_range_date_list[1][0:4]: counter += 1 sum_of_transactions = float(sum_of_transactions) + float( lines[line][PRICE_INDEX]) elif transaction_date[0:4] == user_range_date_list[0][ 0:4] or transaction_date[0:4] == user_range_date_list[1][0:4]: if transaction_date[0:4] == user_range_date_list[0][0:4]: if month_of_transaction >= month_of_user_input_start_date: if month_of_transaction > month_of_user_input_start_date: counter += 1 sum_of_transactions = float( sum_of_transactions) + float( lines[line][PRICE_INDEX]) else: if day_of_transaction >= day_of_user_input_start_date: counter += 1 sum_of_transactions = float( sum_of_transactions) + float( lines[line][PRICE_INDEX]) elif transaction_date[0:4] == user_range_date_list[1][0:4]: if month_of_transaction <= month_of_user_input_end_date: if month_of_transaction < month_of_user_input_end_date: counter += 1 sum_of_transactions = float( sum_of_transactions) + float( lines[line][PRICE_INDEX]) else: if day_of_transaction <= day_of_user_input_end_date: counter += 1 sum_of_transactions = float( sum_of_transactions) + float( lines[line][PRICE_INDEX]) return counter, sum_of_transactions
def update_transaction(): user_input = view.get_input("Transaction ID / or 'quit'") user_wants_to_quit = False while not __is_transaction_to_update_valid( user_input) and not user_wants_to_quit: view.print_error_message( "Error: Invalid input for Transaction to update") user_input = view.get_input("Transaction ID / or 'quit'") if user_input == 'quit': user_wants_to_quit = True transaction_id_to_update = user_input new_transaction = [] new_transaction.append(transaction_id_to_update) new_transaction.append(view.get_input("Customer")) new_transaction.append(view.get_input("Product")) user_input = view.get_input("Price") while not __is_transaction_price_valid(user_input): view.print_error_message("Error: Invalid input for Price") user_input = view.get_input("Price") new_transaction.append(user_input) user_input = view.get_input("Date i.e. 1989-03-21") while not __is_transaction_date_format_valid(user_input): view.print_error_message("Error: Invalid input for Date") user_input = view.get_input("Date i.e. 1989-03-21") new_transaction.append(user_input) if sales.update_transaction(new_transaction): view.print_message("Transaction updated") else: view.print_error_message("Error while updating transaction!")
def update_list(): user_input_id = view.get_input("Please enter a " + "'" + HEADERS[ID_INDEX] + "'" + " of transaction: ") counter = 0 for transaction in range(len(TRANSACTIONS)): if user_input_id == TRANSACTIONS[transaction][ID_INDEX]: for i in range(len(HEADERS) - 1): user_input_update = view.get_input(HEADERS[i + 1]) TRANSACTIONS[transaction][i + 1] = user_input_update counter += 1 else: counter = 0 return TRANSACTIONS, counter
def delete_transaction(): view.clear_console() transactions = sales.read() view.print_table(transactions, sales.HEADERS) index = view.get_input('Provide a valid transactions id to delete profile: ') choices = range(len(transactions)) choices = map(lambda x: str(x + 1), choices) while index not in choices: view.print_error_message("Incorrect value. Try again!") index = view.get_input('Provide a valid transactions id to update profile: ') transactions.pop(int(index) - 1) sales.create(transactions) view.print_message(view.color_sentence(Fore.GREEN, "Transaction was deleted.")) view.wait_for_reaction()
def update_transaction(): # view.print_error_message("Not implemented yet.") transaction_id = view.get_input(f"Specify the transaction {sales.HEADERS[sales.ID_TRANSACTION_INDEX]}") # view.print_message("Specify what do you want to change.") headers_menu = sales.HEADERS.copy()[sales.ID_CUSTOMER_INDEX:] insert_exit_option(headers_menu) view.print_menu("Possible positions to update", headers_menu) index = view.get_input("Specify which position would you like to update") index_in_headers_menu = int(index) if index_in_headers_menu == 0: return new_value = view.get_input("Enter new value") updated_transaction = sales.update_transaction(transaction_id,index_in_headers_menu,new_value) view.print_message("The updated transaction: ") view.print_table(updated_transaction,sales.HEADERS)
def delete_transaction(): try: transaction_number = view.get_input("transaction number") if transaction_index_valid(transaction_number): sales.remove_transaction(transaction_number) except IndexError: view.print_error_message("Index not found")
def update_employee(): list_employees() view.print_message("Update employee.") updated_employee_id = view.get_input("Provide employee ID: ") updated_employee_data = view.get_inputs([hr.HEADERS[hr.NAME_INDEX], hr.HEADERS[hr.DATE_OF_BIRTH_INDEX], hr.HEADERS[hr.DEPARTMENT_INDEX], hr.HEADERS[hr.CLEARANCE_INDEX]]) hr.update_employee(updated_employee_id, updated_employee_data) view.print_message("Employee updated!")
def delete_employee(): try: number = view.get_input("number of employee") if check_employee_index_valid(number): hr.delete_nested_list_and_write_content(number) except IndexError: view.print_error_message("Index not found")
def next_birthdays(): answers = [] months_list = ["01","02","03","04","05","06",'07','08','09',"10","11","12"] days_list = ["01","02","03","04","05","06",'07','08','09',"10","11","12","13", "14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"] birth_date_complete = 0 while birth_date_complete < 1: user_input = view.get_input("Please enter the starting date (yyyy-mm-dd): ") try: year, month, day = user_input.split("-") if int(year) not in range(1950,2021): view.print_message("Invalid year!") continue elif month not in months_list: view.print_message("Invalid month!") continue elif day not in days_list: view.print_message("Invalid day!") continue else: view.print_message("") if hr.next_birthdays1(user_input) == False: view.print_message("There are no birthdays in the selected period.") else: view.print_message("") view.print_message(f"The following employees have birthdays in the next 2 weeks {hr.next_birthdays1(user_input)}.") birth_date_complete = birth_date_complete + 1 except ValueError: view.print_message("Invalid input")
def menu(): option = None while option != '0': display_menu() option = view.get_input("Select module") load_module(int(option)) view.print_message("Good-bye!")
def run_operation(option): if option == '1': os.system('clear') list_employees() elif option == '2': os.system('clear') add_employee() elif option == '3': os.system('clear') update_employee() elif option == '4': os.system('clear') delete_employee() elif option == '5': os.system('clear') get_oldest_and_youngest() elif option == '6': os.system('clear') get_average_age() elif option == '7': os.system('clear') next_birthdays(view.get_input('Type starting date (yyyy-mm-dd): ')) elif option == '8': os.system('clear') count_employees_with_clearance() elif option == '9': os.system('clear') count_employees_per_department() elif option == '0': return 0 else: raise KeyError("There is no such option.")
def delete_transaction(): user_input = view.get_input("Transaction ID / or 'quit'") user_wants_to_quit = False while not __is_transaction_to_delete_valid( user_input) and not user_wants_to_quit: view.print_error_message( "Error: Invalid input for Transaction to update") user_input = view.get_input("Transaction ID / or 'quit'") if user_input == 'quit': user_wants_to_quit = True transaction_id_to_delete = user_input if sales.delete_transaction(transaction_id_to_delete): view.print_message("Transaction deleted") else: view.print_error_message("Error while deleting transaction!")
def add_transaction(): view.print_message("New transaction: ") customer_id = view.get_input(f"{sales.HEADERS[customer_index]}") if not any(customer_id in customers[id_index] for customers in crm.CUSTOMERS): answer = view.get_input( "Given customer does not exist. Type 'Y' to create").upper() if answer == "Y": view.print_message("Add customer") new_customer = crm_controller.add_customer() customer_id = new_customer[id_index] view.print_message( f"New customer generated with random id of {customer_id}") values = view.get_inputs(sales.HEADERS[product_index:]) sales.add_transaction([customer_id, *values]) view.print_message("Transaction added!")
def delete_transaction(): delete_id = view.get_input( "Please choose a transaction ID you want to delete") try: index, product_list = sales.look_for_product_list(delete_id) print(*product_list) check_answer = view.get_input( "Are you sure you want delete this transaction?") if check_answer == "yes": sales.delete_transaction(index) else: delete_transaction() except: view.print_error_message("Invalid ID") delete_transaction()
def add_new_transaction(): transaction_list = [] for i in range(len(HEADERS)): user_input = view.get_input("Please enter a " + "'" + HEADERS[i] + "'" + " of transaction: ") transaction_list.append(user_input) TRANSACTIONS.append(transaction_list) return TRANSACTIONS
def menu(): operation = None while operation != '0': display_menu() try: operation = view.get_input("Select an operation") run_operation(int(operation)) except KeyError as err: view.print_error_message(err)
def update_customer(): search_id = view.get_input('Id') if crm.if_customer_exists(search_id): print("Give the new data.") new_data = view.get_inputs(['Name', 'Email', 'Subscribed']) crm.update_customer(new_data) else: view.print_error_message("Id does not exist. \n")
def update_employee(): transaction_id = view.get_input( "Please choose a employee ID you want to update") try: index, product_list = hr.show_employee(transaction_id) print(*product_list) change_info = view.get_input( "Please choose what you want to change in the information").lower( ) if change_info in UPDATE_OPTIONS: new_info = view.get_input("Enter new information") hr.update_element(index, UPDATE_OPTIONS[change_info], new_info) except: view.print_error_message("Invalid ID") update_employee()
def delete_employee(): delete_id = view.get_input( "Please choose a transaction ID you want to delete") try: index, product_list = hr.show_employee(delete_id) print(*product_list) check_answer = view.get_input( "Are you sure you want delete this transaction?").lower() if check_answer == "yes": hr.delete_employee(index) else: view.print_menu() except: view.print_error_message("Invalid ID") view.print_menu()
def update_transaction(): transaction_id = view.get_input( "Please choose a transaction ID you want to update") try: index, product_list = sales.look_for_product_list(transaction_id) print(*product_list) change_info = view.get_input( "Please choose what you want to change in the information").lower( ) if change_info in UPDATE_OPTIONS: new_info = view.get_input("Enter new information") sales.update_transaction(index, UPDATE_OPTIONS[change_info], new_info) except: view.print_error_message("Invalid ID") update_transaction()
def update_employee(): employee_id = view.get_input("Please input user ID") table = ["","Please provide name","Please provide date of birth like YYYY-MM-DD","Please input your department","Please input Clearance status"] if hr.is_id_in_base(employee_id): [table[NAME_INDEX], table[DATE_OF_BIRTH], table[DEPARTMENT], table[CLEARANCE_LEVEL]] = view.get_inputs( [table[NAME_INDEX], table[DATE_OF_BIRTH], table[DEPARTMENT], table[CLEARANCE_LEVEL]]) hr.update_employee(employee_id, table) else: view.print_error_message("There is no such id in the base.")
def count_employees_with_clearance(): list_of_employes = hr.get_employee() employes_with_clearance = 0 number = int(view.get_input("Please write a clearence level: ")) for i in range(len(list_of_employes)): if int(list_of_employes[i][hr.CLEARANCE_INDEX]) <= number: employes_with_clearance += 1 view.print_general_results( employes_with_clearance, "Number of employeees with required clearance level")