def list_employees(): result = [] result.append(hr.HEADERS) with open(hr.DATAFILE) as f: for line in f: result.append(line.strip().split(';')) view.print_table(result)
def list_transactions(): result = [] result.append(sales.HEADERS) with open(sales.DATAFILE) as f: for line in f: result.append(line.strip().split(';')) view.print_table(result)
def update_employee(): HEADERS = ["Id", "Name", "Date of birth", "Department", "Clearance"] labels = view.get_inputs(HEADERS) table = hr.update_data(labels[0], labels[1], labels[2], labels[3], labels[4]) table.insert(0, hr.HEADERS) view.print_table(table)
def get_biggest_revenue_product(): biggest_revenue_product = sales.get_biggest_revenue_product() if not biggest_revenue_product == False: view.print_table(biggest_revenue_product) else: view.print_error_message( 'Error while getting transactions number between dates')
def list_employees(): view.clear_console() employee = hr.read() view.print_table(employee, hr.HEADERS, title="All employees") view.wait_for_reaction() view.clear_console() display_menu()
def update_transaction(): HEADERS = ["record_id", "Customer", "Product", "Price", "Date"] labels = view.get_inputs(HEADERS) table = sales.modify_item(labels[0], labels[1], labels[2], labels[3], labels[4]) table.insert(0, sales.HEADERS) view.print_table(table)
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 update_customer(): customer_table = crm.data_manager.read_table_from_file(crm.DATAFILE) view.print_table(customer_table) selected_customer = input("choose a customer by ID: ") for line in customer_table: if selected_customer in line[0]: selected_line = line selected_data = input("choose data what would like to modify (id/name/email/subscribed): ") if selected_data == "id": replaced_id = input("please enter a new id: ") selected_line[0] = replaced_id elif selected_data == "name": replaced_name = input("please enter a new name: ") selected_line[1] = replaced_name elif selected_data == "email": replaced_email = input("please enter a new email: ") selected_line[2] = replaced_email elif selected_data == "subscribed": replaced_sub = input("please enter a new subscribed: ") selected_line[3] = replaced_sub else: print("invalid input!") crm.data_manager.write_table_to_file(crm.DATAFILE, customer_table, separator=';')
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_oldest_and_youngest(): data_headers = list(hr.data_read()) data = data_headers[0] headers = data_headers[1] print(len(data)) j = 0 birthdays = [] for i in data: elements = data[0 + j] dates = elements[2] date = dates.split("-") birthdays.append(date) j += 1 a = 0 years = [] for day in birthdays: elem = birthdays[0 + a] year = elem[0] years.append(int(year)) a += 1 oldest = min(years) youngest = max(years) index = years.index(oldest) index_young = years.index(youngest) print("The oldest employee is:") view.print_table([data[index]], headers) print("") print("The youngest employee is:") view.print_table([data[index_young]], headers)
def update_customer(): customer_id_asked = input( crm.labels["customer_id"]) #wywalić do terminala view customer_index = get_customer_from_id(customers, customer_id_asked) if customer_index is not None: customer_new_name = str(input( crm.labels["ask_name"])) #wywalić do terminala view customer_new_email = str(input( crm.labels["ask_email"])) #wywalić do terminala view customer_new_sub_input = input( crm.labels["subscribed"]).upper() #wywalić do terminala view if customer_new_sub_input == "Y": #wywalić do terminala view customer_new_subscribed = 1 #wywalić do terminala view else: customer_new_subscribed = 0 #wywalić do terminala view customer_updated = [ customer_id_asked, customer_new_name, customer_new_email, str(customer_new_subscribed) ] customers[customer_index[0]] = customer_updated #list_customers_updated = data_manager.write_table_to_file(crm.DATAFILE,customers) view.print_table(customers) else: add_customer()
def count_transactions_between(): transactions_between, start_date, end_date = get_transactions_between() view.print_message( f"Number of transactions found between {start_date} and {end_date}: {len(transactions_between)}" ) view.print_table([sales.HEADERS, *transactions_between ]) if len(transactions_between) > 0 else None
def list_customers(): view.clear_console() customers = crm.read() view.print_table(customers, crm.HEADERS, title='All customers:') view.wait_for_reaction() view.clear_console() display_menu()
def update_employee(): hr_table = hr.data_manager.read_table_from_file(hr.DATAFILE) view.print_table(hr_table) selected_customer = input("Choose a customer by ID") for line in hr_table: if selected_customer in line[0]: selected_line = line selected_data = input( "choose data what would like to modify (id/name/birthday/department/clearance): " ) if selected_data == "id": replaced_id = input("please enter a new id: ") selected_line[0] = replaced_id elif selected_data == "name": replaced_name = input("please enter a new name: ") selected_line[1] = replaced_name elif selected_data == "birthday": replaced_birthday = input("please enter a new birthday: ") selected_line[2] = replaced_birthday elif selected_data == "department": replaced_department = input("please enter a new clearance level: ") selected_line[3] = replaced_department elif selected_data == "clearance": replaced_clearance = input("please enter a new clearance level: ") selected_line[4] = replaced_clearance else: print("invalid input!") hr.data_manager.write_table_to_file(hr.DATAFILE, hr_table, separator=';')
def add_transaction(): HEADERS = ["Customer", "Product", "Price", "Date"] id_number = util.generate_id() labels = view.get_inputs(HEADERS) table = sales.create_item(id_number, labels[0], labels[1], labels[2], labels[3]) table.insert(0, sales.HEADERS) view.print_table(table)
def add_employee(): HEADERS = ["Name", "Date of birth", "Department", "Clearance"] id_number = util.generate_id() labels = view.get_inputs(HEADERS) table = hr.create_data(id_number, labels[0], labels[1], labels[2], labels[3]) table.insert(0, hr.HEADERS) view.print_table(table)
def get_biggest_revenue_transaction(): lines = file_handling.read_table_from_file(sales.DATAFILE, separator=';') biggest_revenue_transaction_list = [] line_of_biggest_revenue_transaction = biggest_revenue_product_and_transaction( ) biggest_revenue_transaction_list.append( lines[line_of_biggest_revenue_transaction]) view.print_table(biggest_revenue_transaction_list, sales.HEADERS)
def get_subscribed_emails(): view.clear_console() view.print_message("Subscribed emails: ") customers = crm.read() subscribers = list(filter(lambda x: x[-1] == '1', customers)) view.print_table(subscribers, crm.HEADERS)
def list_customers(): result = [] result.append(crm.HEADERS) with open(crm.DATAFILE, 'r') as f: for line in f: result.append(line.strip().split(';')) # return result view.print_table(result)
def next_birthdays(): customer_table = hr.data_manager.read_table_from_file(hr.DATAFILE) view.print_table(customer_table) today = datetime.date.today() print(today) for item in customer_table: if item[2].strip()[-5:-1] == today[-5:-1]: print(item[0].strip() + " " + item[1].strip())
def sum_transactions_between(): transactions_between, start_date, end_date = get_transactions_between() sum_of_transactions = sum( [float(price[price_index]) for price in transactions_between]) view.print_message( f"Sum of transactions found between {start_date} and {end_date}: {sum_of_transactions}$" ) view.print_table([sales.HEADERS, *transactions_between ]) if len(transactions_between) > 0 else None
def count_employees_with_clearance(): customer_table = hr.data_manager.read_table_from_file(hr.DATAFILE) view.print_table(customer_table) which_clearance = input("Enter the user's clearance level:") count = 0 for item in customer_table: if item[4] >= which_clearance: count += 1 print(count)
def get_subscribed_emails(): index_email = 2 email_list = [] index_name = 1 table = crm.get_table() for c, emails in enumerate(table): if '@' in emails[index_email]: email_list.append([c, emails[index_email], emails[index_name]] ) view.print_table(email_list) return email_list
def count_employees_per_department(): customer_table = hr.data_manager.read_table_from_file(hr.DATAFILE) view.print_table(customer_table) departments = dict() for item in customer_table: if item[3].strip() in departments: departments[item[3].strip()] += 1 else: departments[item[3].strip()] = 1 print(departments)
def delete_customer(): customer_table = crm.data_manager.read_table_from_file(crm.DATAFILE) view.print_table(customer_table) which_id_input = view.get_input('Enter the user`s ID that you wish to delete: ') count = 0 for item in customer_table: if which_id_input in item[0]: del customer_table[count] count += 1 crm.data_manager.write_table_to_file(crm.DATAFILE,customer_table) view.print_table(customer_table)
def delete_customer(): customer_id_asked = input( crm.labels["customer_id"]) #wywalić do terminala view customer_index = get_customer_from_id(customers, customer_id_asked) if customer_index is not None: customer_to_remove = customers[customer_index[0]] customers.remove(customer_to_remove) #ustomers_after_remove = data_manager.write_table_to_file(crm.DATAFILE,customers) view.print_table(customers) else: print("no such id")
def add_employee(): hr_table = hr.data_manager.read_table_from_file(hr.DATAFILE) add_input_labels = hr.HEADERS view.print_table(hr_table) all_inputs = view.get_inputs(add_input_labels) for item in all_inputs: if item == "PLACEHOLDER": item = hr.util.generate_id() all_inputs[0] = hr.util.generate_id() hr_table.append(all_inputs) hr.data_manager.write_table_to_file(hr.DATAFILE, hr_table) return add_input_labels
def delete_employee(): hr_table = hr.data_manager.read_table_from_file(hr.DATAFILE) view.print_table(hr_table) which_id_input = view.get_input( 'Enter the user`s ID that you wish to delete: ') count = 0 for item in hr_table: if which_id_input in item[0]: del hr_table[count] count += 1 hr.data_manager.write_table_to_file(hr.DATAFILE, hr_table) view.print_table(hr_table)
def add_customer(): customer_table = crm.data_manager.read_table_from_file(crm.DATAFILE) add_input_labels = crm.HEADERS view.print_table(customer_table) all_inputs = view.get_inputs(add_input_labels) for item in all_inputs: if item == "PLACEHOLDER": item = crm.util.generate_id() all_inputs[0] = crm.util.generate_id() customer_table.append(all_inputs) crm.data_manager.write_table_to_file(crm.DATAFILE,customer_table) return add_input_labels
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