def start_module():
    """
    Starts this module and displays its menu.
    User can access default special features from here.
    User can go back to main menu from here.

    Returns:
        None
    """

    title = "\nAccounting manager"
    exit_statement = "Back to main menu"
    options = [
        "Show table", "Add item", "Remove item", "Update table",
        "Which year has the highest profit?",
        "What is the average (per item) profit in a given year?"
    ]

    module = os.path.dirname(__file__)
    data_file = "items.csv"
    data_file_path = os.path.join(module, data_file)
    table = data_manager.get_table_from_file(data_file_path)

    while True:
        ui.print_menu(title, options, exit_statement)
        choice = ui.get_inputs(["Choose your module: "], "")
        choice = choice[0]

        if choice == "1":
            show_table(table)
        elif choice == "2":
            add(table)
        elif choice == "3":
            show_table(table)
            id_input = common.check_id(table)

            remove(table, id_input)

        elif choice == "4":
            show_table(table)
            id_input = common.check_id(table)
            update(table, id_input)

        elif choice == "5":
            max_year = which_year_max(table)
            ui.print_result(max_year, 'Year with highest profit')

        elif choice == "6":
            run_avg_amount(table)

        elif choice == "0":
            break
        else:
            ui.print_error_message("Wrong input")
        ui.clear_terminal()
Esempio n. 2
0
def create_position(table, fields):
    '''
    Users can create new positions. A position has an ID, description, number of seats and a “Company ID”.
    Position IDs are unique amongst other positions.
    Descriptions cannot be empty.
    The number of seats must be greater than 0.
    Company ID must exist.
    '''
    new_position = ui.user_inputs(fields)
    new_id = common.create_id(table)

    company_table = data_manager.read_data('company.csv')
    company_id = 2
    check_company = common.check_id(new_position[company_id], company_table, 0)
    seats_id = 1
    try:
        check_seats = int(new_position[seats_id]) > 0
    except:
        check_seats = False

    if check_company and check_seats:
        new_position.insert(0, new_id)
        table.append(new_position)
        return table
    else:
        return []
Esempio n. 3
0
def update_company(table, fields):
    '''
    Users can update the details of existing companies by first entering their ID and then the information (name) to be updated.
    IDs cannot be updated.
    Company names can be updated, but they should stay unique.
    '''

    company_id = ui.user_inputs(['ID'])

    line = None
    for i in range(len(table)):
        if table[i][0] == company_id:
            line = i

    if line != None:
        new_company = ui.user_inputs(fields)
        company_name = 0
        company_name_in_company = 1
        check_company = common.check_id(new_company[company_name], table,
                                        company_name_in_company)
        if not check_company:
            new_company.insert(0, company_id)
            table.pop(line)
            table.insert(line, new_company)
        else:
            return []
    else:
        return []

    return table
Esempio n. 4
0
def update(positions):
    position = common.check_id(positions)
    if position:
        inputs = ui.get_inputs(["Description: "])
        position.description = inputs[0]
    else:
        ui.print_notification("No position found with that ID!")
Esempio n. 5
0
def update(students):
    student = common.check_id(students)
    if student:
        inputs = ui.get_inputs(["Name: ", "Age: "])
        (student.name, student.age) = (inputs[0], inputs[1])
    else:
        ui.print_notification("No student found with that ID!")
Esempio n. 6
0
def read(companies):
    company = common.check_id(companies)
    if company:
        positions = position.get_positions(company)

        ui.print_company(company, positions)
    else:
        ui.print_notification("No company found with that ID!")
Esempio n. 7
0
def read(positions):
    position = common.check_id(positions)
    if position:
        apps = application.get_applications_by_position_id(position.ID)
        students = student.get_students_from_applications(apps)

        ui.print_position(position, students)
    else:
        ui.print_notification("No position found with that ID!")
Esempio n. 8
0
def delete(students, id_=0):
    student = common.check_id(students)
    if student:
        if not application.get_applications_by_student_id(student.ID):
            students.remove(student)
            ui.print_notification(student.name + " deleted.")
        else:
            ui.print_notification("This student has applications!")
    else:
        ui.print_notification("No student found with that ID!")
Esempio n. 9
0
def delete(companies):
    company = common.check_id(companies)
    if company:
        if not position.get_positions(company):
            companies.remove(company)
            ui.print_notification("Company " + company.name + " deleted.")
        else:
            ui.print_notification("This company has positions!")
    else:
        ui.print_notification("No company found with that ID!")
Esempio n. 10
0
def update(companies):
    company = common.check_id(companies)
    if company:
        inputs = ui.get_inputs(["Name: "])
        if common.check_company_name(companies, inputs[0]):
            company.name = inputs[0]
        else:
            ui.print_notification("Cannot change company name to " + inputs[0] + " because it already exists!")
    else:
        ui.print_notification("No company found with that ID!")
Esempio n. 11
0
def delete(positions, id_=0):
    position = common.check_id(positions)
    if position:
        if not application.get_applications_by_position_id(position.ID):
            positions.remove(position)
            ui.print_notification("Position " + position.description +
                                  " deleted.")
        else:
            ui.print_notification("This position has applications!")
    else:
        ui.print_notification("No position found with that ID!")
Esempio n. 12
0
def update(table, id_):
    """Updates specified record in the table. Ask users for new data.
    Args:
        table: list in which record should be updated
        id_ (str): id of a record to update
    Returns:
        table with updated record """

    title = 'Update'
    list_labels = ['Name', 'Email', 'Subscribed']
    common.check_id(table)
    for data in range(len(table)):
        if table[data][0] == id_:
            inputs = ui.get_inputs(list_labels, title)
            table[data][1] = inputs[0]
            table[data][2] = inputs[1]
            check(inputs, table, data)
            data_manager.write_table_to_file("crm/customers.csv", table)
            break
    return table
Esempio n. 13
0
def change_status(students):
    student = common.check_id(students)
    if student:
        if student.status == "1":
            student.status = "0"
            ui.print_notification("Status changed to: 0 (deactivated)")
        else:
            student.status = "1"
            ui.print_notification("Status changed to: 1 (activated)")
    else:
        ui.print_notification("No student found with that ID!")
Esempio n. 14
0
def read(students):
    student = common.check_id(students)
    if student:
        apps = application.get_applications_by_student_id(student.ID)
        position_descs = position.get_positions_description(apps)

        company_ids = position.get_positions_id_by_applications(apps)
        company_names = company.get_company_names(company_ids)

        ui.print_student(student, position_descs, company_names)
    else:
        ui.print_notification("No student found with that ID!")
Esempio n. 15
0
def start_module():
    """
    Starts this module and displays its menu.
    User can access default special features from here.
    User can go back to main menu from here.
    Returns:
        None
    """

    title = "\nCustomer Relationship Management (CRM)"
    exit_statement = "Back to main menu"
    options = [
        "Show table", "Add item", "Remove item", "Update table",
        "What is the id of the customer with the longest name?",
        "Which customers has subscribed to the newsletter?"
    ]

    module = os.path.dirname(__file__)
    data_file = "customers.csv"
    data_file_path = os.path.join(module, data_file)
    table = data_manager.get_table_from_file(data_file_path)

    while True:
        ui.print_menu(title, options, exit_statement)
        choice = ui.get_inputs(["Choose your module: "], "")
        choice = choice[0]

        if choice == "1":
            show_table(table)
        elif choice == "2":
            add(table)
        elif choice == "3":
            show_table(table)
            choose_id = ui.get_inputs(["ID: "], '0 to exit')
            remove(table, choose_id)
            show_table(table)
        elif choice == "4":
            show_table(table)
            id_ = common.check_id(table)
            update(table, id_)
            show_table(table)
        elif choice == "5":
            longest_id = get_longest_name_id(table)
            ui.print_result(longest_id, 'longest name ID')
        elif choice == "6":
            nice_list = get_subscribed_emails(table)
            show_nicelist(nice_list)
        elif choice == "0":
            break
        else:
            ui.print_error_message("Wrong input")
        ui.clear_terminal()
Esempio n. 16
0
def create_company(table, fields):
    '''
    Users can create new companies. Companies have an ID, name.
    IDs and names of companies are unique amongst other companies.
    '''
    new_company = ui.user_inputs(fields)
    new_id = common.create_id(table)
    company_name = 0
    company_name_in_company = 1
    check_company = common.check_id(new_company[company_name], table,
                                    company_name_in_company)
    if check_company:
        return []
    else:
        new_company.insert(0, new_id)
        table.append(new_company)
    return table
Esempio n. 17
0
def update(applications):
    application = common.check_id(applications)
    if application:
        inputs = ui.get_inputs(["Status"])

        taken_seats = position.get_taken_seats()[0]
        max_seats = position.get_taken_seats()[1]

        for i in range(len(max_seats)):
            if max_seats[i].ID == application.position_id:
                if inputs[0] == "1":
                    if taken_seats[i] >= int(max_seats[i].seats):
                        ui.print_notification("Status can't be changed! Seats are already full!")
                else:
                    application.status = inputs[0]
                    ui.print_notification("Status successfully changed.")
    else:
        ui.print_notification("No application found with that ID!")
Esempio n. 18
0
import sys
import config
import datetime
import threading
import time
import signal
import ssh_connection

if __name__ == '__main__':
    if not common.check_argv(sys.argv):
        common.print_error('no enough arguments')
        common.print_info('%s id params')
        exit(2)

    robot_id = sys.argv[1]
    if not common.check_id(robot_id):
        common.print_error('please check the robot id')
        exit(3)
    j = 2
    for i in range(2, len(sys.argv)):
        if '-j' in sys.argv[i]:
            j = int(sys.argv[i][2:])
            break

    if not common.build_project(True, j):
        common.print_error('build error, please check code')
        exit(4)

    args = common.parse_argv(sys.argv)
    ip_address = common.get_ip(robot_id)