Exemple #1
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))
Exemple #2
0
def manage_showtime():
    showtime = Showtime()

    if request.method == 'POST':
        delete_showtime_id = request.form.get('delete_showtime_id')
        edit_showtime_id = request.form.get('edit_showtime_id')

        if delete_showtime_id is not None and showtime.fetch(
                delete_showtime_id):
            # logic for cancelling tickets will go here?
            if not safe_delete(showtime):
                flash("Cannot delete showtime, it has associated bookings")
        elif edit_showtime_id is not None and showtime.fetch(edit_showtime_id):
            return redirect(
                url_for('AdminShowtimeController.edit_showtime',
                        sid=edit_showtime_id))

    # get a list of all showtimes
    showtimes = showtime.get_all_showtimes()
    new_times = []

    for time in showtimes:
        time = dict(time)
        movie = Movie()
        movie.fetch(time['movie_id'])

        showroom = Showroom()
        showroom.fetch(time['showroom_id'])

        time['time'] = create_datetime_from_sql(time['time'])
        time['movie_title'] = movie.get_title()
        time['duration'] = movie.get_duration()
        time['showroom_name'] = showroom.get_showroom_name()

        new_times.append(time)

    # show newest times first
    new_times = sorted(new_times, key=lambda k: k['time'])

    return render_template('manage_showtime.html', showtimes=new_times)
Exemple #3
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
Exemple #4
0
def edit_showtime(sid):
    showtime_id = sid
    showtime = Showtime()
    if not showtime.fetch(showtime_id):
        print("Error fetching showtime??")

    movie = Movie()
    movies = movie.get_all_movies()
    movie.fetch(showtime.get_movie_id())
    showroom = Showroom()
    showrooms = showroom.get_all_showrooms()
    showroom.fetch(showtime.get_showroom_id())

    if request.method == 'POST':
        date = request.form.get('date')
        time = request.form.get('time')
        available_seats = request.form.get('available_seats')
        movie_id = request.form.get('movie_id')
        showroom_id = request.form.get('showroom_id')

        print(date)
        print(time)
        print(available_seats)
        print(movie_id)
        print(showroom_id)
        error = None

        dtime = create_datetime(date, time)

        if not validate_showtime_date(dtime):
            error = "The selected showroom is unavailable at that time"
        elif not validate_showroom_availability(showroom.get_id(),
                                                showtime_id, dtime,
                                                int(movie.get_duration())):
            error = "The selected showroom is unavailable at that time"
        else:
            showtime.set_time(dtime)

        if movie_id is not None and not validate_movie(movie_id):
            error = "There was an error processing the movie"
        elif movie_id is not None:
            showtime.set_movie_id(movie_id)

        if showroom_id is not None and not validate_showroom(showroom_id):
            error = "There was an error processing the showroom"
        elif showroom_id is not None:
            showtime.set_showroom_id(showroom_id)

        showtime.save()

        if error is not None:
            flash(error)
        else:
            return redirect(url_for('AdminShowtimeController.manage_showtime'))

    info = showtime.obj_as_dict(showtime_id)
    print("show_dtime")
    print(info['time'])
    show_dtime = create_datetime_from_sql(info['time'])
    return render_template('edit_showtime.html',
                           showtime=info,
                           movie_title=movie.get_title(),
                           showroom_name=showroom.get_showroom_name(),
                           show_dtime=show_dtime,
                           movies=movies,
                           showrooms=showrooms)