예제 #1
0
def get_ticket_type_lists(tickets):
    tickets = sorted(tickets, key=lambda k: k['type'])

    # initialize values for the first type
    current_type = tickets[0]['type']
    old_type = tickets[0]['type']

    current_tickets = []  # current list being created
    all_tickets = []  # final 2D array of tickets by types

    for t in tickets:
        current_type = t['type']

        if current_type != old_type:
            current_tickets[0]['checkout_price'] = format_price(
                current_tickets[0]['num_price'] * len(current_tickets))
            all_tickets.append(list(current_tickets))
            current_tickets.clear()

        t['seat'] = format_seat(t['seat'])
        current_tickets.append(dict(t))
        old_type = t['type']

    current_tickets[0]['checkout_price'] = format_price(
        current_tickets[0]['num_price'] * len(current_tickets))
    all_tickets.append(list(current_tickets))
    return all_tickets
예제 #2
0
def create_booking_objects():
    order_id = 0
    total = session['total']
    card_id = request.form['card_id']
    showtime_id = session['showtime']
    movie_id = get_movie_by_showtime(showtime_id).get_id()
    customer_id = get_current_customer().get_id()
    order_date = datetime.now()

    promo_id = None
    if session.get('promo'):
        promo_id = session['promo']['id']

    booking = Booking()
    booking.create(order_id=order_id,
                   total_price=total,
                   credit_card_id=card_id,
                   promo_id=promo_id,
                   movie_id=movie_id,
                   customer_id=customer_id,
                   showtime_id=showtime_id,
                   order_date=order_date)

    unique_id = booking.get_id()
    order = generate_order_id(unique_id, showtime_id, movie_id)
    booking.set_order_id(order)
    booking.save()

    associate_tickets(booking.get_id())
    send_confirmation_email(order, format_price(total))
    return booking.get_id()
예제 #3
0
def refund_booking(bid):
    # clean up
    # delete all tickets, reset showtime incrementer
    booking = Booking()
    if not booking.fetch(bid):
        return redirect(url_for('IndexController.index'))
    total = booking.get_total_price()

    movie = Movie()
    movie.fetch(booking.get_movie_id())
    movie_title = movie.get_title()

    tickets = booking.get_tickets()
    ticket_count = len(tickets)

    # delete individual ticket objects
    ticket_obj = Ticket()
    for ticket in tickets:
        ticket_obj.delete(ticket['ticket_id'])

    # delete the actual booking object
    showtime = booking.get_showtime_id()
    booking.delete(bid)

    # reset showtime seats
    showtime_obj = Showtime()
    showtime_obj.fetch(showtime)
    showtime_obj.increment_available_seats(ticket_count)
    time = showtime_obj.get_time().strftime('%I:%M %p  :  %B %d, %Y')
    showtime_obj.save()

    # send an email!
    customer = create_user('customer')
    customer.fetch(g.user['username'])
    customer.send_refund_email(movie_title, time, format_price(total))
예제 #4
0
def calculate_fees_and_total(subtotal):
    price = Price()
    tax_price = price.get_tax_price() * subtotal
    online_fee = price.get_online_fee()
    total = subtotal + tax_price + online_fee

    fees = [
        {'name': 'Taxes', 'amount': format_price(tax_price)},
        {'name': 'Online Booking', 'amount': format_price(online_fee)}
    ]

    if session.get('promo'):
        promo_amt = session['promo']['percent'] * subtotal
        promo_fee = {'name': 'Promo: {}'.format(session['promo']['name']),
                     'amount': "-" + format_price(promo_amt)}
        fees.append(promo_fee)
        total = total - promo_amt

    return fees, total
예제 #5
0
def payment_confirmation(bid):

    confirm = False
    if bid[-1] == 'c':
        bid = bid[0:-1]
        confirm = True

    fees = []

    booking = Booking()
    if not booking.fetch(bid):
        return redirect(url_for('IndexController.index'))

    movie = Movie()
    movie = movie.obj_as_dict(booking.get_movie_id())
    showtime = Showtime()
    showtime.fetch(booking.get_showtime_id())
    showroom = Showroom()
    showroom.fetch(showtime.get_showroom_id())

    tkts = booking.get_tickets()
    tickets = []
    for t in tkts:
        t = dict(t)
        t['seat_number'] = format_seat(t['seat_number'])
        tickets.append(t)

    booking = dict(booking.obj_as_dict(bid))
    booking['order_date'] = create_datetime_from_sql(booking['order_date'])
    booking['total_price'] = format_price(booking['total_price'])
    return render_template('confirmation.html',
                           tickets=tickets,
                           fees=fees,
                           movie=movie,
                           showtime=showtime.get_time(),
                           booking=booking,
                           confirm=confirm,
                           showroom=showroom.get_showroom_name())
예제 #6
0
def process_bookings(bookings):
    refund_info = {}
    refunds = []

    for booking in bookings:
        refund_info['order_no'] = booking['order_id']
        refund_info['total'] = format_price(booking['total_price'])
        refund_info['bid'] = booking['booking_id']

        # get tickets
        booking_obj = Booking()
        booking_obj.fetch(booking['booking_id'])
        tickets = booking_obj.get_tickets()
        refund_info['tickets'] = process_tickets(tickets)

        movie = Movie()
        movie.fetch(booking['movie_id'])
        refund_info['movie_title'] = movie.get_title()

        showtime = Showtime()
        print(showtime.fetch(booking['showtime_id']))
        print(booking['showtime_id'])
        refund_info['date'] = showtime.get_time()
        print(showtime.get_time())

        now = datetime.datetime.now()
        hour = datetime.timedelta(hours=1)
        if now + hour > showtime.get_time():
            refund_info['is_refundable'] = False
        else:
            refund_info['is_refundable'] = True

        refunds.append(dict(refund_info))

    # sort here
    refunds = sorted(refunds, key=lambda k: k['date'], reverse=True)
    return refunds
예제 #7
0
def checkout():

    if (not session.get('showtime') or
        not session.get('tickets') or
            not g.user.get('username')):
        return redirect(url_for('IndexController.index'))

    if request.method == 'POST':
        delete_id = request.form.get('delete_ticket')

        if request.form.get('coupon'):
            promo = Promo()
            session['promo'], error = apply_promo(promo)
            if error is not None:
                flash(error)
        elif delete_id:
            if not delete_ticket(delete_id):
                return redirect(url_for('BookingController.cancel_booking'))
        elif request.form.get('add_payment'):
            session['checkout'] = True
            return redirect(url_for('AccountController.make_payment'))
        elif request.form.get('checkout'):
            if request.form.get('card_id'):
                bid = create_booking_objects()
                clear_booking_info()
                return redirect(
                    url_for('BookingController.payment_confirmation', bid=bid))
            else:
                flash("Please choose a payment card to proceed with checkout")
        elif request.form.get('cancel'):
            clear_booking_info()
            return redirect(url_for('IndexController.index'))

    customer = create_user('customer')
    customer.fetch(g.user['username'])
    cards = customer.get_all_cards()

    showtime = Showtime()
    showtime.fetch(session['showtime'])

    movie = Movie()
    movie.fetch(showtime.get_movie_id())

    tickets, subtotal = clean_tickets(session['tickets'])

    # Returns a 2D array of tickets
    # each list is a different type
    all_tickets = get_ticket_type_lists(tickets)

    fees, total = calculate_fees_and_total(subtotal)
    session['total'] = total

    total = format_price(total)
    subtotal = format_price(subtotal)

    return render_template('checkout.html',
                           showtime=showtime.get_time(),
                           movie=movie.obj_as_dict(movie.get_id()),
                           tickets=all_tickets,
                           subtotal=subtotal,
                           total=total,
                           fees=fees,
                           cards=cards)