示例#1
0
def sum_transactions_between():
    temp_list = data_manager.read_table_from_file(sales.DATAFILE)
    start_date = view.get_input('Enter start date YYYY-MM-DD and press enter ')
    while not CRUD.validate(start_date):
        start_date = view.get_input('Enter start date YYYY-MM-DD and press enter ')
        CRUD.validate(start_date)
    end_date = view.get_input('Enter end date YYYY-MM-DD and press enter ')
    while not CRUD.validate(end_date):
        end_date = view.get_input('Enter end date YYYY-MM-DD and press enter ')
        CRUD.validate(end_date)
    sum = 0
    for item in temp_list:
        if start_date <= item[4] <= end_date:
            sum += float(item[3])
    view.print_message(f'The sum of transactions between {start_date} and {end_date} is {sum}')
示例#2
0
def count_transactions_between():
    temp_list = data_manager.read_table_from_file(sales.DATAFILE)
    start_date = view.get_input('Enter start date YYYY-MM-DD and press enter ')
    while not CRUD.validate(start_date):
        start_date = view.get_input('Enter start date YYYY-MM-DD and press enter ')
        CRUD.validate(start_date)
    end_date = view.get_input('Enter end date YYYY-MM-DD and press enter ')
    while not CRUD.validate(end_date):
        end_date = view.get_input('Enter end date YYYY-MM-DD and press enter ')
        CRUD.validate(end_date)
    counter = 0
    for item in temp_list:
        if start_date <= item[4] <= end_date:
            counter += 1
    view.print_message(f'The number of transactions between {start_date} and {end_date} is {counter}')
示例#3
0
def menu():
    operation = None
    while operation != '0':
        display_menu()
        try:
            operation = view.get_input("Select an operation ")
            run_operation(int(operation))
        except KeyError as err:
            view.print_error_message(err)
示例#4
0
def menu():
    option = None
    while option != '0':
        display_menu()
        try:
            option = 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!")
示例#5
0
def delete(datafile, headers):
    temp_list = data_manager.read_table_from_file(datafile)
    item_to_delete = view.get_input("Please enter an id to delete ")
    marker = 0
    for item in temp_list:
        if item_to_delete == item[0]:
            temp_list.remove(item)
            data_manager.write_table_to_file(datafile, temp_list)
            view.print_message('Delete successful')
            marker += 1
            break
    if marker == 0:
        view.print_error_message('Delete failed')