"""Invoice totals for a small online shop. Original test fixture by What the tech.

Rules the function must follow:
  * line total = quantity x unit price (prices in cents, integers)
  * volume discount on the SUBTOTAL: 5% from 10 items, 10% from 50 items
    (10 and 50 themselves qualify)
  * sales tax is charged on the subtotal AFTER the discount
  * the result is in cents, rounded half up to a whole cent
"""


def invoice_total(lines, tax_rate):
    """lines: list of (quantity, unit_price_cents); tax_rate: e.g. 0.0825"""
    subtotal = 0
    items = 0
    for quantity, price in lines:
        subtotal += quantity * price
        items += quantity

    discount = 0
    if items > 50:
        discount = 0.10
    elif items > 10:
        discount = 0.05

    taxed = subtotal * (1 + tax_rate)
    total = taxed - subtotal * discount
    return int(total)
