示例#1
0
def get_unassigned_orders():
    clear()
    print(fmt_string('Viewing: UNASSIGNED ORDERS', fg='Cyan'))
    data = DbController.instance().call_proc('get_unassigned_orders')
    if len(data) > 0:
        dicts_to_table(data)
        input(fmt_string('Press ENTER To Continue', fg='Green'))
示例#2
0
def get_free_couriers():
    clear()
    print(fmt_string('Viewing: FREE COURIERS', fg='Cyan'))
    data = DbController.instance().call_proc('get_unassigned_couriers')
    if len(data) > 0:
        dicts_to_table(data)
    input(fmt_string('Press ENTER To Continue', fg='Green'))
示例#3
0
def show_update_status_menu() -> None:
    data = get_order_data()
    current_ids = [order['id'] for order in data]

    is_looping = True
    while is_looping:
        clear()
        dicts_to_table(data)

        index = get_validated_input('Please Select An Id To Update: ',
                                    int,
                                    fg='Blue',
                                    cancel_on='0',
                                    is_present=current_ids)
        if not index:
            is_looping = False
            continue

        status_list = DbController.instance().get_all_rows(
            'status', 'id, code')
        current_row = DbController.instance().get_rows_where(
            'orders', '*', 'id', index)[0]

        clear()
        dicts_to_table(data)
        print(fmt_string(f'\nUpdating Order {index}...', fg='Cyan'))
        dicts_to_table(status_list)

        status_index = get_validated_input(f'Please Select A New Status: ',
                                           int,
                                           fg='Blue',
                                           min_length=0,
                                           max_value=len(status_list),
                                           min_value=1,
                                           cancel_on='0')
        if not status_index:
            continue

        current_row['status'] = status_index
        DbController.instance().update('orders', index, current_row)
        data = get_order_data()

        clear()
        dicts_to_table(data)

        if input(
                fmt_string(
                    'Status SuccessFully Updated. Would You Like To Update Another?[y/n]\n',
                    fg='Green')) == 'n':
            is_looping = False
            continue
示例#4
0
def show_delete_order_menu() -> None:
    data = get_order_data()

    current_ids = [item['id'] for item in data]

    is_looping = True
    while is_looping:
        clear()
        dicts_to_table(data)

        id = get_validated_input('Please Enter An ID To Delete: ',
                                 int,
                                 fg='Blue',
                                 min_length=1,
                                 is_present=current_ids,
                                 cancel_on='0')

        if not id:
            return

        DbController.instance().delete('orders', id)

        data = get_order_data()

        clear()
        dicts_to_table(data)

        if input(
                fmt_string(
                    'Item SuccessFully Updated. Would You Like To Update Another?[y/n]\n',
                    fg='Green')) == 'n':
            is_looping = False
示例#5
0
def show_delete_item_menu(get_key: str) -> None:
    data = get_cats(DbController.instance().get_all_rows(get_key, '*'),
                    action='delete')

    current_ids = [item['id'] for item in data]

    is_looping = True
    while is_looping:
        clear()
        dicts_to_table(data)
        item_id = get_validated_input(f'Please Enter An ID To Delete: ',
                                      int,
                                      fg='Blue',
                                      min_length=1,
                                      is_present=current_ids,
                                      cancel_on='0')
        if not item_id:
            return

        DbController.instance().delete(get_key, item_id)

        clear()
        data = get_cats(DbController.instance().get_all_rows(get_key, '*'),
                        action='delete')
        dicts_to_table(data)

        if input(
                fmt_string(
                    'Item SuccessFully Added. Would You Like To Add Another?[y/n]\n',
                    fg='Green')) == 'n':
            is_looping = False
示例#6
0
    def test_behaviour(self):
        #Given
        fg = 'White'
        bg = 'Red'
        msg = 'Test'
        expected = '\u001b[37;1m\u001b[41;1mTest\u001b[0m'

        #When
        actual = fmt_string(msg, fg, bg)

        #Then
        self.assertEqual(expected, actual)
示例#7
0
def search_table(table: str):
    clear()
    term = get_validated_input('Please Enter A Search Term: ', fg='Blue')

    if table == 'orders':
        data = DbController.instance().search_joined_table(
            table='orders o',
            term=term,
            fields=[
                'o.id', 'o.name', 'o.address', 'o.area', 'o.phone',
                'courier.name AS Courier', 's.code AS status'
            ],
            targets=['couriers courier', 'status s'],
            conditions=['courier.id = o.courier', 's.id = o.status'])
    else:
        data = get_cats(DbController.instance().search_table(table, term),
                        action='join')

    if len(data) > 0:
        dicts_to_table(data)
    else:
        print(fmt_string('No Results Found', fg='White', bg='Red'))
    input(fmt_string('Press Enter To Continue', fg='Green'))
示例#8
0
def show_add_order_menu() -> None:
    display_data = get_order_data()

    schema = {k.lower(): type(v) for (k, v) in display_data[0].items()}
    validation = {'all': {'min_length': 1, 'cancel_on': '0', 'fg': 'Blue'}}

    is_looping = True
    while is_looping:
        clear()
        dicts_to_table(display_data)

        new_dict = dict_builder(schema, ['id', 'courier', 'status'],
                                validation)
        if not new_dict:
            return

        clear()
        dicts_to_table(display_data)
        print(fmt_string('\nOrder Complete!', fg='Green'))

        dicts_to_table([new_dict], headers=list(display_data[0].keys())[1:-2])

        if input(fmt_string('Does This Look Correct?[y/n]\n',
                            fg='Green')).lower() == 'n':
            continue

        DbController.instance().insert('orders', new_dict)

        clear()
        display_data = get_order_data()
        dicts_to_table(display_data)

        if input(
                fmt_string(
                    'Item SuccessFully Added. Would You Like To Add Another?[y/n]\n',
                    fg='Green')) == 'n':
            is_looping = False
示例#9
0
def view_procs():
    clear()
    views = DbController.instance().get_available_procs()
    list_to_table(views, 'Views', enumerate=True)
    action = get_validated_input('Select A Item To Preview: ',
                                 int,
                                 fg='Green',
                                 min_value=1,
                                 max_value=len(views),
                                 cancel_on='0')

    if not action:
        return

    dicts_to_table(DbController.instance().call_proc(views[action - 1].replace(
        ' ', '_')))

    input(fmt_string('Press Enter To Continue', fg='Green'))
示例#10
0
def show_menu(menu_name: str) -> None:
    # Set the global menu_state to the selected menu to allow us to backtrack when returning
    global menu_state
    menu_state = menu_name
    clear()
    print(fmt_string('Hi and Welcome to the F&B Ordering System.\n',
                     fg='Blue'))
    log('debug', f'Menu {menu_name} loaded')
    # Get the menu structure from the menus object, using it's items value to print to the screen
    menu = menus[menu_name]
    #print_table(menu['title'], menu['items'])
    list_to_table(menu['items'], menu['title'])

    if (menu_option :=
            validated_input('\nPlease Select An Option.\n',
                            int,
                            fg='Green',
                            min_value=0,
                            max_value=len(menu['handlers']) - 1))[0] == 0:
        input(menu_option[1])
        return
示例#11
0
def show_add_item_menu(get_key: str) -> None:
    data = get_cats(DbController.instance().get_all_rows(get_key, '*'),
                    action='delete')

    current_names = [item['name'] for item in data]

    schema = {k.lower(): type(v) for (k, v) in data[0].items()}
    validation = {
        'all': {
            'min_length': 1,
            'cancel_on': '0',
            'fg': 'Blue'
        },
        'name': {
            'unique': current_names
        }
    }

    is_looping = True
    while is_looping:
        clear()
        dicts_to_table(data)

        new_dict = dict_builder(schema, ['id', 'basket'],
                                validation=validation)
        if not new_dict:
            return

        DbController.instance().insert(get_key, new_dict)

        clear()
        data = get_cats(DbController.instance().get_all_rows(get_key, '*'),
                        action='delete')
        dicts_to_table(data)

        if input(
                fmt_string(
                    'Item SuccessFully Added. Would You Like To Add Another?[y/n]\n',
                    fg='Green')) == 'n':
            is_looping = False
示例#12
0
def show_update_item_menu(get_key: str) -> None:
    data = get_cats(DbController.instance().get_all_rows(get_key, '*'),
                    action='delete')

    current_ids = [item['id'] for item in data]

    schema = {k.lower(): type(v) for (k, v) in data[0].items()}
    validation = {'all': {'min_length': 1, 'cancel_on': '0', 'fg': 'Blue'}}

    is_looping = True
    while is_looping:
        clear()
        dicts_to_table(data)

        id = get_validated_input('Please Enter An ID To Edit: ',
                                 int,
                                 fg='Blue',
                                 min_length=1,
                                 is_present=current_ids,
                                 cancel_on='0')
        if not id:
            return

        new_dict = dict_builder(schema, ['id', 'items'], validation=validation)
        if not new_dict:
            return

        DbController.instance().update(get_key, id, new_dict)
        clear()
        data = get_cats(DbController.instance().get_all_rows(get_key, '*'),
                        action='delete')
        dicts_to_table(data)

        if input(
                fmt_string(
                    'Item SuccessFully Added. Would You Like To Add Another?[y/n]\n',
                    fg='Green')) == 'n':
            is_looping = False
示例#13
0
def show_order_detail_menu(order) -> None:
    # Use the data recived in view_order to print -> use the `status` tables style value to colour by status
    for k, v in order.items():
        if k == 'status':
            col = DbController.instance().get_rows_where(
                'status', '*', 'code', v)[0]['style']
            print(fmt_string(f'{str(k).title()}: ', fg='Blue'),
                  fmt_string(f'{str(v).title()}\n', fg=col))
        else:
            print(fmt_string(f'{str(k).title()}: ', fg='Blue'),
                  f'{str(v).title()}\n')

    # Get the orders current basket from the `basket` table and add a total price per item on
    items = DbController.instance().get_joins_where(
        fields=[
            'b.quantity AS "#x"', 'p.name',
            'b.quantity * p.price AS "Sub Total"'
        ],
        source='orders o',
        targets=['basket b', 'products p'],
        conditions=[f'b.order_id = {order["id"]}', 'b.item = p.id'],
        where=f'o.id = {order["id"]}',
        type='INNER')

    sub = 0
    for item in items:
        sub += item['Sub Total']

    if len(items) > 0:
        items.append({'#x': '', 'name': '', 'Sub Total': '----------'})
        items.append({'#x': '', 'name': '', 'Sub Total': sub})
        dicts_to_table(items)
    else:
        print(fmt_string('Order: ', fg='Blue'),
              fmt_string('Basket Is Empty', fg='Red'))

    input(fmt_string('\nPress ENTER To Continue', fg='Green'))
示例#14
0
def get_order_totals():
    data = DbController.instance().call_proc('get_order_totals')
    clear()
    print(fmt_string('Viewing: TOTALS BY ORDER', fg='Cyan'))
    dicts_to_table(data)
    input(fmt_string('Press ENTER To Continue', fg='Green'))
示例#15
0
def update_catagory_mapping():
    is_in_cat = True
    while is_in_cat:
        cats = DbController.instance().get_all_rows('catagories', '*')
        cat_ids = [item['id'] for item in cats]
        clear()
        dicts_to_table(cats)

        selected_catagory = get_validated_input(
            'Please Select A Catagory To Update: ',
            int,
            fg='Blue',
            is_present=cat_ids,
            cancel_on='0')

        if not selected_catagory:
            is_in_cat = False
            continue

        is_editing = True
        while is_editing:
            data = DbController.instance().get_rows_where(
                'products', 'name, id', 'catagory', selected_catagory)
            product_ids = [
                item['id'] for item in DbController.instance().get_all_rows(
                    'products', 'id')
            ]
            list_names = ['*' + item['name'] for item in data]
            list_ids = [item['id'] for item in data]

            clear()
            list_to_table(list_names, "Current Menu", max_length=3)

            dicts_to_table(get_cats(DbController.instance().get_all_rows(
                'products', '*')),
                           paginate=True,
                           page_length=10,
                           on_clear=lambda: list_to_table(
                               list_names, "Current Menu", max_length=3))

            selected_item = get_validated_input(
                'Please Select An Item To Add: ',
                int,
                fg='Blue',
                is_present=product_ids,
                cancel_on='0',
                cancel_text='GO BACK')

            if not selected_item:
                is_editing = False
                continue

            if selected_catagory == 9 and selected_item in list_ids:
                input(
                    fmt_string(
                        'That Item Is Already In This Menu, But You Can Not Remove From The Default Menu',
                        fg='White',
                        bg='Red'))
                continue

            elif selected_item in list_ids:
                if input(
                        fmt_string(
                            'That Item Is Already In This Menu. Would You Like To Remove It [y/n]? \n',
                            fg='White',
                            bg='Red')) == 'y':
                    DbController.instance().update('products', selected_item,
                                                   {'catagory': 9})

            else:
                DbController.instance().update('products', selected_item,
                                               {'catagory': selected_catagory})
示例#16
0
def select_order_items(order_id) -> None:
    current_basket = list(DbController.instance().get_joins_where(
        source='basket b',
        fields=['p.id', 'p.name', 'b.quantity'],
        targets=['products p'],
        conditions=['b.item = p.id'],
        where=f'b.order_id = {order_id}'))

    current_rows = DbController.instance().get_rows_where(
        'basket', '*', 'order_id', order_id)
    current_ids = [item['item'] for item in current_rows]

    catagories = DbController.instance().get_all_rows('catagories', '*')
    catagory_ids = [cat['id'] for cat in catagories]

    to_update = []
    to_insert = []
    to_delete = []

    is_in_cat = True
    while is_in_cat:
        clear()
        if len(current_basket) > 0:
            dicts_to_table(current_basket)
        print(fmt_string(f'Updating Basket For Order {order_id}...',
                         fg='Cyan'))
        dicts_to_table(catagories)

        catagory = get_validated_input('Please Select A Catagory: ',
                                       int,
                                       fg='Blue',
                                       is_present=catagory_ids,
                                       cancel_on='0',
                                       cancel_text='SKIP')

        if not catagory:
            is_in_cat = False
            continue

        is_in_product = True
        while (is_in_product):
            clear()

            # Reconcile duplicate records -> only affects locally
            if len(current_basket) > 0:
                for i in range(len(current_basket) - 1):
                    for j in range(i + 1, len(current_basket)):
                        if current_basket[i]['id'] == current_basket[j]['id']:
                            current_basket[i]['quantity'] += current_basket[j][
                                'quantity']
                            del current_basket[j]

                    if current_basket[i]['quantity'] <= 0:
                        del current_basket[i]

                dicts_to_table(current_basket)

            products = DbController.instance().get_rows_where(
                'products', 'id, name', 'catagory', catagory)
            product_ids = [item['id'] for item in products]

            print(
                fmt_string(f'Updating Basket For Order {order_id}...',
                           fg='Cyan'))
            dicts_to_table(products)

            product = get_validated_input('Please Select An Item: ',
                                          int,
                                          fg='Blue',
                                          is_present=product_ids,
                                          cancel_on='0',
                                          cancel_text='GO BACK')

            if not product:
                is_in_product = False
                continue

            quantity = get_validated_input('Please Enter A Quantity: ',
                                           int,
                                           fg='Blue',
                                           cancel_on='0',
                                           cancel_text='GO BACK')

            if product in current_ids:
                for item in current_rows:
                    if item['item'] == product:
                        if item['quantity'] + quantity <= 0:
                            to_delete.append(item)
                            current_rows.remove(item)

                            for row in current_basket:
                                print(row['id'], product)
                                if row['id'] == product:
                                    current_basket.remove(row)

                        else:
                            item['quantity'] += quantity
                            to_update.append(item)

                            for row in current_basket:
                                if row['id'] == product:
                                    row['quantity'] += quantity

            else:
                to_insert.append({
                    'order_id': order_id,
                    'item': product,
                    'quantity': quantity
                })
                for row in products:
                    if row['id'] == product:
                        current_basket.append({
                            'id': product,
                            'name': row['name'],
                            'quantity': quantity
                        })

            # reconcile updates to additions -> would affect table
            for i in range(len(to_insert) - 1):
                for j in range(i + 1, len(to_insert)):
                    if to_insert[i]['item'] == to_insert[j]['item']:
                        to_insert[i]['quantity'] += to_insert[j]['quantity']
                        del to_insert[j]

                if to_insert[i]['quantity'] <= 0:
                    del to_insert[i]

    for record in to_update:
        DbController.instance().update_where('basket', ['order_id', 'item'],
                                             [order_id, record['item']],
                                             record)

    for record in to_delete:
        DbController.instance().delete_where('basket', ['order_id', 'item'],
                                             [order_id, record['item']])

    for record in to_insert:
        DbController.instance().insert('basket', record)
示例#17
0
def show_update_order_menu() -> None:
    data = get_order_data()
    current_ids = [item['id'] for item in data]
    status_list = DbController.instance().get_all_rows('status', '*')
    status_ids = [status['id'] for status in status_list]
    courier_list = DbController.instance().get_all_rows('couriers', '*')
    courier_ids = [courier['id'] for courier in courier_list]

    is_looping = True
    while is_looping:
        clear()
        dicts_to_table(data)
        id = get_validated_input('Please Enter An ID To Edit: ',
                                 int,
                                 fg='Blue',
                                 min_length=1,
                                 is_present=current_ids,
                                 cancel_on='0')
        if not id:
            return

        order = DbController.instance().get_joins_where(
            fields=[
                'o.id', 'o.name', 'o.address', 'o.area', 'o.phone',
                'courier.name AS courier', 's.code AS status'
            ],
            source='orders o',
            targets=['couriers courier', 'status s'],
            conditions=['courier.id = o.courier', 's.id = o.status'],
            where=f'o.id = {id}',
            order='ORDER BY o.status')

        clear()
        dicts_to_table(order)

        schema = {k.lower(): type(v) for (k, v) in data[0].items()}
        schema['courier'] = int
        schema['status'] = int
        validation = {
            'all': {
                'min_length': 0,
                'cancel_on': '',
                'cancel_text': 'SKIP',
                'fg': 'Blue'
            },
            'status': {
                'is_present': status_ids,
                'cancel_on': '0'
            },
            'courier': {
                'is_present': courier_ids,
                'cancel_on': '0'
            }
        }
        on_key = {
            'status': [
                clear, lambda: dicts_to_table(order),
                lambda: dicts_to_table(status_list)
            ],
            'courier': [
                clear, lambda: dicts_to_table(order),
                lambda: dicts_to_table(courier_list)
            ]
        }

        new_dict = dict_builder(schema, ['id'],
                                validation,
                                on_key=on_key,
                                on_cancel='skip')

        if new_dict:
            DbController.instance().update('orders', id, new_dict)

        select_order_items(id)

        clear()
        data = get_order_data()
        dicts_to_table(data)

        if input(
                fmt_string(
                    'Item SuccessFully Updated. Would You Like To Update Another?[y/n]\n',
                    fg='Green')) == 'n':
            is_looping = False