def get_average_age(): view.clear_console() current_year = int(datetime.now().year) all_together = 0 number_of_employee = 0 employees = hr.read() for employee in employees: date_list = employee[2].split("-") year = int(date_list[0]) all_together += year number_of_employee += 1 average = current_year - all_together // number_of_employee average_label = "the average age of the employees is" view.print_general_results(average, average_label) view.wait_for_reaction() return average
def sum_transactions_between(): view.clear_console() transactions = sales.read() min_data = view.get_input("Provide start transaction data (e.g. 2020-10-31): ") max_data = view.get_input("Provide end transaction data (e.g. 2020-10-31): ") min_data = min_data.split("-") max_data = max_data.split("-") min_data = datetime.date(int(min_data[0]), int(min_data[1]), int(min_data[2])) max_data = datetime.date(int(max_data[0]), int(max_data[1]), int(max_data[2])) sum_transaction = 0 for transaction in transactions: current_transaction_data = transaction[4] current_transaction_data = current_transaction_data.split("-") current_transaction_data = datetime.date(int(current_transaction_data[0]), int(current_transaction_data[1]), int(current_transaction_data[2])) if current_transaction_data <= max_data and current_transaction_data >= min_data: sum_transaction += float(transaction[3]) view.print_message("Sum equals: " + str(sum_transaction)) view.wait_for_reaction()
def count_transactions_between(): view.clear_console() transactions = sales.read() start_date = view.get_input("Provide start transaction date (e.g. 2018-02-03): ") end_date = view.get_input("Provide end transaction date (e.g. 2020-11-04): ") start_date = start_date.split("-") end_date = end_date.split("-") start_date = datetime.date(int(start_date[0]), int(start_date[1]), int(start_date[2])) end_date = datetime.date(int(end_date[0]), int(end_date[1]), int(end_date[2])) counter = 0 for index in range(len(transactions)): tran_date = transactions[index][4] tran_date = tran_date.split("-") tran_date = datetime.date(int(tran_date[0]), int(tran_date[1]), int(tran_date[2])) if tran_date <= end_date and tran_date >= start_date: counter += 1 view.print_message('Count transactions between equals: ' + str(counter)) view.wait_for_reaction()
def update_employee(): view.clear_console() view.print_message("update employee:\n") employees = hr.read() view.print_table(employees, hr.HEADERS, title="All Employees") update_label = "Provide employees id to update: " employee_index = view.get_input_number(update_label, max_value=len(employees)) - 1 employee_to_update = employees.pop(int(employee_index)) updated_employee = get_updated_employee_data(employee_to_update, hr.HEADERS) employees.insert(int(employee_index), updated_employee) hr.create(employees) view.print_message("Customer was updated correctly.") view.wait_for_reaction()
def update_customer(): view.clear_console() view.print_message("Update customer: ") customers = crm.read() view.print_table(customers, crm.HEADERS, title='All customers:') update_label = view.color_sentence(Fore.GREEN, "Provide customer id to update: ") customer_index = view.get_input_number(update_label, max_value=len(customers)) - 1 customer_to_update = customers.pop(int(customer_index)) updated_customer = get_updated_customer_data(customer_to_update, crm.HEADERS) customers.insert(int(customer_index), updated_customer) crm.create(customers) view.print_message("Customer was updated correctly.")
def list_transactions(): view.clear_console() transactions = sales.read() view.print_table(transactions, sales.HEADERS) view.wait_for_reaction()
def add_transaction(): view.clear_console() inputs = view.get_inputs(['Give Customer: ', 'Give Product: ', 'Give Price: ']) inputs.append(str(datetime.date.today())) sales.update(inputs) view.wait_for_reaction()