def main():

    ipop.cls()

    username = sys.argv[1]

    screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tWelcome to seat cancellation.\t\t\t\t|\n" + "|\tYou will need to provide the ticket number\t\t|\n" + "|\tof every reservation you wish cancel\t\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

    print(screen)

    while True:
        ticket_no = ipop.getUserData([str], "||\tEnter ticket number\n||\t",
                                     "Wrong data")
        details = mdb.ticketDetails(ticket_no, 1)
        if details == None:
            print("Ticket number does not exist.")

        elif username != details[2]:
            print("This ticket belongs to a different customer.")

        elif calc.isValidTransactionDate(details[5]):

            username = details[2]
            route_id = details[0]
            bus_id = details[1]
            starting = details[3]
            ending = details[4]
            reservation_date = details[5]
            amount = details[7]

            tickString = "_________________________________________________________________\n" + "||\n" + "||\tReservation in bus ID: " + bus_id + "\n" + "||\tOn route ID: " + route_id + "\n" + "||\tJourney starting from: " + starting + "\n" + "||\tJourney ending at: " + ending + "\n" + "||\tOn date: " + reservation_date + '\n' + "||\tNumber of reservations = 1" + '\n||\n' + "||\tTicket numbers:\n" + '||\t' + ticket_no + '\n' + "||\tTotal amounting to: " + str(
                amount
            ) + '\n' + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

            print(tickString + '\n')

            p = input(
                "To cancel this ticket, press any key or !q to go back....")
            if p != '!q':
                if (mdb.add_cancellation(ticket_no) != 1):
                    print("Ticket could not be cancelled.")
                else:
                    print("Ticket cancelled.")

        else:
            print("This ticket cannot be cancelled.")

        ip = ipop.getUserData(
            [int, str],
            "Enter 1 to enter another ticket number, !q to go to main menu.",
            "Wrong data")
        if ip == 1:
            continue
        else:
            exit1(username)
            break
Esempio n. 2
0
def add_cancellation(ticket_no, amount_forfeited = 0):

	r = 2

	r1, cancelTName = create_cancellation_table(0)
	r2, reservTName = create_reservation_table(0)

	details = ticketDetails(ticket_no, 1)

	if details == None:
		r = 0

	elif r1 != 2 and r2 != 2:

		try:
			
			username = details[2]
			route_id = details[0]
			bus_id = details[1]
			starting = details[3]
			ending = details[4]
			reservation_date = details[5]
			seat_no = details[6]
			amount = details[7]

			if calc.isValidTransactionDate(reservation_date):
				# removing from reservation_table
				tblremove = "DELETE FROM '" + reservTName + "' WHERE ticket_no='" + ticket_no + "'"
				curs.execute(tblremove)

				# adding to cancellation_table
				tbladd = "INSERT INTO '" + cancelTName + "' values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

				curs.execute(tbladd, (time.strftime("%d/%m/%Y"), username, route_id, bus_id, starting, ending, reservation_date, seat_no, ticket_no, amount_forfeited))
				conn.commit()

				# add to revenue_table
				if add_revenue('cancellation', username, ticket_no, -(amount - amount_forfeited), amount_forfeited) != 1:
					print('Error adding revenue.')


				# add to user_activities
				cancellation_string = ticket_no + '_' + time.strftime("%d/%m/%Y") + '_' + bus_id + '_' + starting + '_' + ending + '_' + reservation_date + '_' + str(seat_no) + '_' + str(amount)
				if change_user_activity(username, 'cancellations', cancellation_string, 1) != 1:
					print ('Error adding to user_activities.')

				r = 1

			else: r = -1
		
		except: r = 2

	return r
Esempio n. 3
0
def isReservationPossible(bus_id, starting, ending, date, seat_no):

	possibility = False
	route_id = getRouteFromBusID(bus_id)
	r1, reserveTName = create_reservation_table(0)

	if r1 != 2 and route_id != '' :

		r2, bus_table_name = create_bus_table(0)
		curs.execute("SELECT total_seats FROM " + bus_table_name + " WHERE bus_id='" + bus_id + "'")
		total_seats = curs.fetchall()
		total_seats = total_seats[0][0]

		indices = validate_route(route_id, starting, ending)

		if indices != None and calc.isValidTransactionDate(date) and 0 < seat_no <= total_seats:

			try:

				possibility = True			

				# getting probable clashable routes
				tblcmd = "SELECT starting, ending FROM '" + reserveTName + "' WHERE bus_id='" + bus_id + "' AND seat_no='" + str(seat_no) + "' AND date='" + date + "'"
				curs.execute(tblcmd)
				similarReservations = curs.fetchall()
			
				currentStartingIndex = indices[0]
				currentEndingIndex = indices[1]
				currentStops = set(range(currentStartingIndex, currentEndingIndex))	# a set is made with the range from starting index to ending index
			
				for similar in similarReservations:

					i = validate_route(route_id, similar[0], similar[1])

					similarStartingIndex = i[0]
					similarEndingIndex = i[1]
					similarStops = set(range(similarStartingIndex, similarEndingIndex))	# a set is made for all similar reservations

					# comparing the two sets. If no common is found, then reservation is possible
					if len(currentStops & similarStops) != 0:
						possibility = False
						break

			except:
				pass

	return possibility
Esempio n. 4
0
def disp_seats():

	source = ipop.getUserData([str], "||\tEnter source of journey:\n||\t", "Wrong data")
	if source == None:
		return 0

	destination = ipop.getUserData([str], "||\tEnter destination of journey:\n||\t", "Wrong data")
	if destination == None:
		return 0

	
	while True:
		date = ipop.getUserData([str], "||\tEnter date of journey: (as DD/MM/YYYY format):\n||\t", "Wrong data")
		if date == None:
			return 0
		else:
			if calc.isValidTransactionDate(date):
				break
			else: print("Invalid date or wrong date format given.")

	buses = mdb.buses_between_stops(source, destination)
	if buses != []:
		bus_details = []
		for b in buses:
			n_seats = len(mdb.availableSeats(b, source, destination, date))
			bus_details.append((b, n_seats))
		bh = ['Bus ID', 'Seats available']
		print ("\nFollowing buses are available:")
		ipop.print_table((bh, bus_details))
		print()

	bus_id = ipop.getUserData([str], "||\tEnter bus ID:\n||\t", "Wrong data")
	if bus_id == None:
		return 0

	buses = mdb.buses_between_stops(source, destination)
	if bus_id not in buses:
		print ("This journey does not exist!!")
		return 1
	
	seats = mdb.availableSeats(bus_id, source, destination, date)
	if seats == []: print ("No more seats are available in this bus for the given date!")
	else:
		print("||\tAvailable seats are:")
		print(seats)
		return 1
def main():

    ipop.cls()

    username = sys.argv[1]

    screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tWelcome to seat reservation.\t\t\t\t|\n" + "|\tYou will be guided through the reservation process.\t|\n" + "|\tPlease enter the relevant information as asked.\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

    print(screen)

    print(
        "\nOn entering the start and end of your journey\nwe will automatically list the available buses for you to choose.\nYou can quit the process anytime by entering !q\n"
    )

    routeFlag = False
    dateFlag = False
    seatFlag = False
    seatReserveFlag = False

    source = ''
    destination = ''
    bus_id = ''
    date = ''
    n = 0
    seats = []
    bookedSeats = []
    fare = 0
    amount = 0

    ts = '00:00'
    te = '00:00'

    tickets = []

    while True:
        date = ipop.getUserData(
            [str], "||\tEnter date of journey: (as DD/MM/YYYY format):\n||\t",
            "Wrong data")
        if date == None:
            return 0
        else:
            if calc.isValidTransactionDate(date):
                dateFlag = True
                break
            else:
                print("Invalid date or wrong date format given.")

    while dateFlag:

        source = ipop.getUserData([str], "||\tEnter source:\n||\t",
                                  "Wrong data")
        if source == None:
            exit1(username)
            break
        destination = ipop.getUserData([str], "||\tEnter destination:\n||\t",
                                       "Wrong data")
        if destination == None:
            exit1(username)
            break
        buses = mdb.buses_between_stops(source, destination)
        if buses == []:
            print(
                "Sorry, this route does not exist. Press 1 to re-enter start and destination, !q to cancel and go to main menu."
            )
            p = ipop.getUserData([str, int], "", "Wrong data")
            if p == 1: continue
            else:
                exit1(username)
                break
        else:
            bus_details = []
            for b in buses:
                bus_type = mdb.getBusType(b)
                bus_fare = mdb.getFare(b, source, destination)
                n_seats = len(mdb.availableSeats(b, source, destination, date))
                bus_details.append((b, bus_type, bus_fare, n_seats))
            bh = ['Bus ID', 'Type', 'Fare', 'Seats available']
            print("\nFollowing buses are available:")
            ipop.print_table((bh, bus_details))
            print()
            bus_id = ipop.getUserData([str], "||\tEnter bus id:\n||\t",
                                      "Choose among the available buses.",
                                      True, ['x in ' + str(buses)], True)
            if bus_id == None:
                exit1(username)
            else:
                routeFlag = True
            break

    if routeFlag:
        print("Almost there....")
        while True:
            n = ipop.getUserData(
                [int], "||\tEnter number of seats to be reserved:\n||\t",
                "Wrong data")
            if n == None:
                exit1(username)
            else:
                seats = mdb.availableSeats(bus_id, source, destination, date)
                if n > len(seats):
                    print(
                        "The requested number of seats is currently not available in "
                        + bus_id + " on " + date)
                    p = ipop.getUserData([
                        int, str
                    ], "||\tEnter 1 to decrease number of seats or !q to cancel:\n||\t",
                                         "Wrong data")
                    if p == 1: continue
                    else:
                        exit1(username)
                        break
                else:
                    seatFlag = True
                    break

    if seatFlag:
        p = ipop.getUserData([
            str
        ], "||\tEnter S to manually select seats or any other key for automatic selection:\n||\t",
                             "Wrong data")
        if p == None:
            exit1(username)
        elif p == 'S' or p == 's':
            print("||\tAvailable seats are:")
            print(seats)
            print("||\tEnter seat numbers for " + str(n) + " reservations")
            for i in range(n):
                s = ipop.getUserData([int], "", "Wrong data", True,
                                     ['x in ' + str(seats)], True)
                if s == None:
                    exit1(username)
                bookedSeats.append(s)
        else:
            for i in range(n):
                s = seats[i]
                bookedSeats.append(s)
        seatReserveFlag = True
        print("||\tBooked seats are: " + str(bookedSeats) + '\n')

    if seatReserveFlag:
        fare = mdb.getFare(bus_id, source, destination)
        amount = n * fare
        print("||\tAll set! Total Fare = " + str(n) + " * " + str(fare) +
              " = " + str(amount))
        print("||\tPress any key to book. !q to cancel")
        p = input()
        if p == None:
            exit1(username)
        else:
            for bs in bookedSeats:
                tickets.append(
                    mdb.add_reservation(bus_id, username, source, destination,
                                        date, bs, fare) + '\t' + str(bs))

            timetable = mdb.bus_timetable(bus_id)
            for place, time in timetable:
                if source == place: ts = time
                if destination == place: te = time

            ticket_print(username, tickets, bus_id,
                         mdb.getRouteFromBusID(bus_id), source, destination,
                         date, n, amount, ts, te)