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 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 add_employee():
    view.clear_console()
    view.print_message("Add new employee:\n")

    new_employee = get_employee_data()

    hr.update(new_employee)

    view.print_message("\nnew employee was added correctly!")
    view.wait_for_reaction()
def get_oldest_and_youngest():
    view.clear_console()
    employees = hr.read()
    employees.sort(key=lambda employee: employee[2])
    oldest_employee = employees[0][1]
    youngest_employee = employees[len(employees) - 1][1]
    oldest_and_youngest = oldest_employee, youngest_employee
    oldest_and_youngest_label = "Oldest and youngest employees is : "
    view.print_general_results(oldest_and_youngest, oldest_and_youngest_label)
    view.wait_for_reaction()

    return oldest_employee, youngest_employee
Ejemplo n.º 5
0
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 next_birthdays():
    view.clear_console()
    employee_list = hr.get_birthday_date_and_name()
    next_birthdays_list = []
    for employee in employee_list:
        days_to_next_birthday = hr.count_time_to_next_birth_day(employee[1])
        if days_to_next_birthday < 14:
            next_birthdays_list.append(employee[0])
            next_birthdays_list.append(str(employee[1].date()))

    next_birthdays_label = "Next birthday has: "
    view.print_general_results(next_birthdays_list, next_birthdays_label)
    view.wait_for_reaction()

    return next_birthdays_list
def count_employees_per_department():
    view.clear_console()
    employees = hr.read()
    sep = " "
    employees.sort(key=lambda emplo: emplo[3])
    dict_of_emplo_in_departament = {}
    for employee in employees:
        name_of_departament = employee[3]
        if name_of_departament not in dict_of_emplo_in_departament:
            dict_of_emplo_in_departament[name_of_departament] = 1
        elif name_of_departament in dict_of_emplo_in_departament:
            dict_of_emplo_in_departament[name_of_departament] += 1
    dict_of_emplo_in_departament_label = "Employee numbers by department"
    view.print_general_results(dict_of_emplo_in_departament,
                               dict_of_emplo_in_departament_label)
    view.wait_for_reaction()
def delete_employee():
    view.clear_console()
    view.print_message("Delete employee: ")

    employees = hr.read()
    view.print_table(employees, hr.HEADERS, title="All Employees")

    delete_label = "Provide employee id to remove: "
    employee_index = view.get_input_number(delete_label,
                                           max_value=len(employees))

    employees.pop(int(employee_index) - 1)

    hr.create(employees)

    view.print_message("Employee was removed correctly.")
    view.wait_for_reaction()
def count_employees_with_clearance():
    view.clear_console()
    employees = hr.read()
    sep = " "
    employees.sort(key=lambda employee: employee[4])
    list_of_employees_with_lowest_clearance = []
    for worker in employees:
        int_worker_clearance = int(worker[4])

        if int_worker_clearance > 0:
            worker_str = sep.join(worker)
            list_of_employees_with_lowest_clearance.append(worker_str)
    list_of_employees_with_lowest_clearance.sort(key=lambda emplo: emplo[4])
    employees_with_lowest_clearance_label = "number of employees with clearances is :"
    view.print_general_results(len(list_of_employees_with_lowest_clearance),
                               employees_with_lowest_clearance_label)
    view.wait_for_reaction()
Ejemplo n.º 10
0
def get_smallest_revenue_product():
    view.clear_console()
    transactions = sales.read()
    revenue = {}
    for transaction in transactions:
        if transaction[2] in revenue.keys():
            revenue[transaction[2]] += float(transaction[3])
        else:
            revenue[transaction[2]] = float(transaction[3])

    the_smallest_transaction = list(revenue.keys())[0]
    for value in revenue:
        if revenue[value] < revenue[the_smallest_transaction]:
            the_smallest_transaction = value

    view.print_message('The smallest revenue transaction is: ' + the_smallest_transaction + ': ' + str(
        revenue[the_smallest_transaction]))
    view.wait_for_reaction()
Ejemplo n.º 11
0
def get_biggest_revenue_product():
    view.clear_console()
    transactions = sales.read()
    revenues = {}
    for transaction in transactions:
        if transaction[2] in revenues.keys():
            revenues[transaction[2]] += float(transaction[3])
        else:
            revenues[transaction[2]] = float(transaction[3])

    the_biggest_product = list(revenues.keys())[0]
    for revenue in revenues:
        if revenues[revenue] > revenues[the_biggest_product]:
            the_biggest_product = revenue

    view.print_message('The biggest revenue product is: ' + the_biggest_product + ': '
                       + str(revenues[the_biggest_product]))
    view.wait_for_reaction()
Ejemplo n.º 12
0
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()
Ejemplo n.º 13
0
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 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 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 menu():
    operation = None
    while operation != '0':
        display_menu()
        try:
            operation = view.get_input(
                view.color_sentence(Fore.GREEN, "\nSelect an operation: "))
            run_operation(int(operation))
            view.wait_for_reaction()
        except KeyError:
            view.print_error_message("There is no such option.")
            view.wait_for_reaction()
        except ValueError:
            view.print_error_message("Please enter a number!")
            view.wait_for_reaction()
Ejemplo n.º 17
0
def list_transactions():
    view.clear_console()
    transactions = sales.read()
    view.print_table(transactions, sales.HEADERS)
    view.wait_for_reaction()
Ejemplo n.º 18
0
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()