Exemplo n.º 1
0
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 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)
Exemplo n.º 3
0
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!")
Exemplo n.º 4
0
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
Exemplo n.º 5
0
def display_menu():
    options = [
        "Back to main menu", "List customers", "Add new customer",
        "Update customer", "Remove customer", "Subscribed customer emails"
    ]
    view.print_message("")
    view.print_menu("Customer Relationship Management", options)
Exemplo n.º 6
0
def display_menu():
    options = [
        "Exit program", "Customer Relationship Management (CRM)", "Sales",
        "Human Resources"
    ]
    view.print_message("")
    view.print_menu("Main menu", options)
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 add_customer():
    new_customer_input = view.get_inputs([
        "Please provide new user name: ",
        "Please provide new user e-mail address: ",
        "Please provide 1 if subscribed, 0 if not: "
    ])
    crm.adding_new_customer(new_customer_input)
    view.print_message("Successfully added customer!")
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)
Exemplo n.º 10
0
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 add_customer():
    view.clear_console()
    view.print_message("Add customer:\n")

    customer = get_customer_data()
    if customer is None:
        return

    crm.update(customer)
    view.print_message("\nCustomer was added correctly!")
Exemplo n.º 12
0
def add_transaction():
    view.print_message("Enter a new transaction into the database\n ")
    questions = [
        "Please enter customer id: ", "Please enter product name: ",
        "Please enter price value: ",
        "Please enter date of transaction(YYYY-MM-DD): "
    ]
    new_transaction = view.get_inputs(questions)
    sales.insert_data(new_transaction)
    view.print_message("Successfully added transaction!")
Exemplo n.º 13
0
def menu():
    operation = None
    while operation != '0':
        display_menu()
        try:
            view.print_message("")
            operation = view.get_input("Select an operation: ")
            run_operation(int(operation))
        except KeyError as err:
            view.print_error_message(err)
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()
Exemplo n.º 15
0
def add_employee():
    view.print_message("Enter a new employee into the database\n")
    questions = [
        "Enter new employee's name: ",
        "Enter new employee's birth date(YYYY-MM-DD): ",
        "Specify new employee's department: ",
        "Specify new employee's clearance level: "
    ]
    new_employee = view.get_inputs(questions)
    hr.create_new_employee(new_employee)
    view.print_message("Successfully added employee!")
Exemplo n.º 16
0
def menu():
    option = None
    while option != '0':
        display_menu()
        try:
            option = int(view.get_input("Select module"))
            load_module(int(option))
        except KeyError:
            view.print_error_message("There is no such option!")
        except ValueError:
            view.print_error_message("Please enter a number!")
    view.print_message("Good-bye!")
Exemplo n.º 17
0
def display_menu():
    options = ["Back to main menu",
               "List employees",
               "Add new employee",
               "Update employee",
               "Remove employee",
               "Oldest and youngest employees",
               "Employees average age",
               "Employees with birthdays in the next two weeks",
               "Employees with clearance level",
               "Employee numbers by department"]
    view.print_message("")
    view.print_menu("Human resources", options)
Exemplo n.º 18
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()
Exemplo n.º 19
0
def update_customer():
    '''Updates informations of the customer in the dataset.'''
    PREFIX = "Update"
    SUFIX = "(empty -> no change)"

    # prepares labels to ask User about the new customer data
    labels = (f"Enter Customer {HEADERS[HEADER_ID]} to make changes",
              f"{PREFIX} {HEADERS[HEADER_NAME]} {SUFIX}",
              f"{PREFIX} {HEADERS[HEADER_EMAIL]}{SUFIX}",
              f"{PREFIX} {HEADERS[HEADER_SUBSCRIBE]}{SUFIX}")

    data_to_update = view.get_inputs(labels)
    crm.update_item(data_to_update)

    view.print_message(f"Customer '{data_to_update[HEADER_ID]}' updated")
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
def count_transactions_between():
    date_labels = [
        "Please enter date to count from (i.e. YYYY-MM-DD): ",
        "Please enter date to count to (i.e. YYYY-MM-DD): "
    ]
    time_frame = view.get_inputs(date_labels)
    date_from, date_to = time_frame[0], time_frame[1]
    transactions_between = sales.find_transactions_between(date_from, date_to)
    if len(transactions_between) > 1:
        view.print_message(f"\nTransactions between {date_from} to {date_to}")
        view.print_table(sales.HEADERS, transactions_between)
    else:
        view.print_general_results(
            transactions_between,
            f"Transaction between {date_from} to {date_to}")
def delete_customer():
    view.clear_console()
    view.print_message("Delete customer: ")

    customers = crm.read()
    view.print_table(customers, crm.HEADERS, title='All customers:')

    delete_label = view.color_sentence(Fore.GREEN,
                                       "Provide customer id to remove: ")
    customer_index = view.get_input_number(delete_label,
                                           max_value=len(customers))

    customers.pop(int(customer_index) - 1)
    crm.create(customers)

    view.print_message("Customer was removed correctly.")
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 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()
Exemplo n.º 25
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()
Exemplo n.º 26
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()
Exemplo n.º 27
0
def get_biggest_revenue_product():
    transactions = sales.read_data_from_file()
    price_index = sales.HEADERS.index("Price")
    product_index = sales.HEADERS.index("Product")
    products_revenue = {}
    best_seller = 0

    for transaction in transactions:
        if transaction[product_index] not in products_revenue.keys():
            products_revenue[transaction[product_index]] = float(
                transaction[price_index])
        else:
            products_revenue[transaction[product_index]] += float(
                transaction[price_index])
        if best_seller < products_revenue[transaction[product_index]]:
            best_seller = products_revenue[transaction[product_index]]
            product_key = transaction[product_index]
    view.print_message(f"Product with the highest revenue: {product_key}")
def delete_logic(label, folder_name_delete_function, department_data):
    row_to_delete = int(
        view.get_input(
            f"\nEnter a valid row number to delete {label}'s data(e.g. 1): ")
    ) - 1
    if len(department_data) > row_to_delete >= 0:
        delete_confirmation = view.get_input(
            f"\nAre you sure you want to delete this transaction: "
            f"{department_data[row_to_delete]}? (y/n) ").lower()
        if delete_confirmation.startswith("y"):
            folder_name_delete_function(row_to_delete)
            view.print_message(
                f"\nData from row {row_to_delete + 1} has been successfully removed!"
            )
        else:
            view.print_message("\nNo data has been removed.")
    else:
        view.print_error_message(
            f"There isn't such a row ({row_to_delete + 1}) in this table!")
Exemplo n.º 29
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()
Exemplo n.º 30
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()