Ejemplo n.º 1
0
def mercIDValidation(option):
    # mercID validation/confirmation
    while True:
        try:
            mercID = int(input('Enter a merchandiseID to {}: '.format(option)))
            # Check if mercID is found in the database

            if mercID not in [
                    item['mercID'] for item in globalData['merchandise']
            ]:
                message(
                    'MerchandiseID:{} does not exist in the database'.format(
                        mercID))
            else:
                mercName, mercPrice = data.getMercInfo(mercID)

                confirm = False
                while confirm == False:
                    yn = input(
                        'MerchandiseID:{} {} for ${}. Is this what you want to {}?(Y/N) '
                        .format(mercID, mercName, mercPrice, option)).upper()
                    confirm = ui.confirm(yn)
                if yn == 'Y':
                    break
        except ValueError:
            message('Enter a valid merchandiseID')

    return mercID
Ejemplo n.º 2
0
def createMercReportData():
    mercID = mercIDValidation('generate report on')
    mercName, price = data.getMercInfo(mercID)

    mercSalesList = []
    for row in globalData['sales']:
        if row['mercID'] == mercID:
            mercSalesList.append(row)

    if len(mercSalesList) > 0:
        reportData = {}

        maxSold = max([x['sold'] for x in mercSalesList])
        minSold = min([x['sold'] for x in mercSalesList])
        totalSold = sum([x['sold'] for x in mercSalesList])
        totalPrice = totalSold * price
        print(maxSold, minSold, totalSold)

        minGameList = []
        maxGameList = []
        for row in globalData['sales']:
            if row['sold'] == minSold and row['mercID'] == mercID:
                minGameList.append(row['gameID'])
            elif row['sold'] == maxSold and row['mercID'] == mercID:
                maxGameList.append(row['gameID'])

        minGameDays = []
        maxGameDays = []
        for row in globalData['games']:
            if row['gameID'] in minGameList:
                minGameDays.append(row['dates'])
            elif row['gameID'] in maxGameList:
                maxGameDays.append(row['dates'])

        reportData['name'] = mercName
        reportData['price'] = price
        reportData['min'] = minSold
        reportData['max'] = maxSold
        reportData['minDateID'] = minGameList
        reportData['maxDateID'] = maxGameList
        reportData['minDate'] = minGameDays
        reportData['maxDate'] = maxGameDays
        reportData['total'] = totalSold
        reportData['totalPrice'] = totalPrice

        ui.displayMercReport(reportData)
Ejemplo n.º 3
0
def salesDataValidation():
    # GameID validation/confirmation
    while True:
        try:
            gameID = int(input('Enter a gameID: '))
            gameDate = data.getDates(gameID)
            if gameDate is None:
                message("There are no data with that GameID")
            else:
                confirm = False
                while confirm == False:
                    yn = input(
                        'ID:{} is for the game on {}. Is this correct?(Y/N) '.
                        format(gameID, gameDate)).upper()
                    confirm = ui.confirm(yn)
                if yn == 'Y':
                    yn = ''
                    break
        except ValueError:
            message('Enter a valid merchandiseID')

    # mercID validation/confirmation
    while True:
        try:
            mercID = int(input('Enter a merchandiseID: '))
            mercName, mercPrice = data.getMercInfo(mercID)
            if (mercName or mercPrice) is None:
                message("There are no data with that merchandiseID")
            else:
                confirm = False
                while confirm == False:
                    yn = input(
                        'ID:{} is for the {} that costs ${}. Is this correct?(Y/N) '
                        .format(mercID, mercName, mercPrice)).upper()
                    confirm = ui.confirm(yn)
                if yn == 'Y':
                    break
        except ValueError:
            message('Enter a valid merchandiseID')

    # create a temporary sales object to check if the sales record with the same gameID and mercID already exist
    tempSalesObj = Sales(gameID, mercID, 0)

    exist = data.checkSalesExist(tempSalesObj)

    return gameID, mercID, exist
Ejemplo n.º 4
0
def createDailyReportData():
    gameID = gameIDValidation('generate report on')
    daySaleData = data.getDailySales(gameID)
    date = data.getDates(gameID)

    if len(daySaleData) > 0:
        reportData = {}
        reportData[date] = []
        dailySold = 0
        dailyPrice = 0
        dailyTotal = 0
        for row in daySaleData:
            mercID = row[0]
            sold = row[1]
            name, price = data.getMercInfo(mercID)
            total = price * sold
            dailySold += sold
            dailyPrice += price
            dailyTotal += total
            reportData[date].append({
                'MERCHANDISE': name,
                'SOLD': sold,
                'PRICE': price,
                'TOTAL': total
            })
        # append daily grandtotal line
        reportData[date].append({
            'MERCHANDISE': 'DAILY TOTAL',
            'SOLD': dailySold,
            'PRICE': dailyPrice,
            'TOTAL': dailyTotal
        })

        ui.displayDailyReport(reportData)

    else:
        message('There are no sales records on GameID:{} on {}'.format(
            gameID, date))
Ejemplo n.º 5
0
def insertData(option):
    # games
    if option == '1':
        date, venueID, exist = gameDataValidation()
        # if there are no games data with the same date, create a new game object
        if not exist:
            # newGameID is the max gameID + 1
            newGameID = max([x['gameID'] for x in globalData['games']]) + 1
            newGameObj = Game(newGameID, date, venueID)

            # if added to the database successfully, append to the globalData as well
            if data.gameManipulate(newGameObj, 1):
                globalData['games'].append({
                    'gameID': newGameID,
                    'dates': date,
                    'venueID': venueID
                })
                globalData['games'] = sorted(globalData['games'],
                                             key=itemgetter('gameID'))

    # merchandise
    elif option == '2':
        mercName, price, exist = mercDataValidation()
        # if there are no merchandise data with the same name, create a new merchandise object
        if not exist:
            # newMercID is the max mercID + 1
            newMercID = max([x['mercID']
                             for x in globalData['merchandise']]) + 1
            newMercObj = Merchandise(newMercID, mercName, price)

            # if added to the database successfully, append to the globalData as well
            if data.merchandiseManipulate(newMercObj, 1):
                globalData['merchandise'].append({
                    'mercID': newMercID,
                    'name': mercName,
                    'price': price
                })
                globalData['merchandise'] = sorted(globalData['merchandise'],
                                                   key=itemgetter('mercID'))

    # sales
    elif option == '3':
        newGameID, newMercID, exist = salesDataValidation()
        # if it doesn't exist, continue on to gather information about the number of item sold. Otherwise, back to the main menu
        if not exist:
            mercName, price = data.getMercInfo(newMercID)
            sold = soldValidation(mercName)
            # create a new Sales object
            newSalesObj = Sales(newGameID, newMercID, sold)

            # if added to the database successfully, append to the globalData as well
            if data.salesManipulate(newSalesObj, 1):
                globalData['sales'].append({
                    'gameID': newGameID,
                    'mercID': newMercID,
                    'sold': sold
                })
                globalData['sales'] = sorted(globalData['sales'],
                                             key=itemgetter('gameID'))
        else:
            message(
                'Sale record with the same GameID and MerchandiseID already exist!'
            )

    # venues
    elif option == '4':
        venueName, exist = venuesDataValidation()
        # create new Venues object if the record with the same venue name does not exist
        if not exist:
            # newVenueID is the max VenueID + 1
            newVenueID = max([x['venueID'] for x in globalData['venues']]) + 1
            newVenueObj = Venue(newVenueID, venueName)

            # if added to the database successfully, append to the globalData as well
            if data.venuesManipulate(newVenueObj, 1):
                globalData['venues'].append({
                    'venueID': newVenueID,
                    'name': venueName
                })
                globalData['venues'] = sorted(globalData['venues'],
                                              key=itemgetter('venueID'))
Ejemplo n.º 6
0
def updateData(option):
    # games
    if option == '1':
        gameID = gameIDValidation('update')
        newDate, newVenueID, exist = gameDataValidation()
        # create a game object if the record with the same date does not exist
        if not exist:
            updateGamesObj = Game(gameID, newDate, newVenueID)

            # if updated database successfully, modify the globalData with the new values as well
            if data.gameManipulate(updateGamesObj, 2):
                for game in globalData['games']:
                    if game['gameID'] == gameID:
                        game['dates'] = newDate
                        game['venueID'] = newVenueID

    # merchandise
    elif option == '2':
        mercID = mercIDValidation('update')
        newMercName, newPrice, exist = mercDataValidation()
        # create a merchandise object if the record with the same name does not exist
        if not exist:
            updateMercObj = Merchandise(mercID, newMercName, newPrice)

            # if updated database successfully, modify the globalData with the new values as well
            if data.merchandiseManipulate(updateMercObj, 2):
                for item in globalData['merchandise']:
                    if item['mercID'] == mercID:
                        item['name'] = newMercName
                        item['price'] = newPrice

    # sales
    elif option == '3':
        gameID, mercID, exist = salesDataValidation()
        # continue updating if the data with the same gameID and mercID combination
        if exist:
            mercName, price = data.getMercInfo(newMercID)
            sold = soldValidation(mercName)

            updateSalesObj = Sales(gameID, mercID, sold)

            # if updated database successfully, modify the globalData with the new values as well
            if data.salesManipulate(updateSalesObj, 2):
                for sale in globalData['sales']:
                    if sale['gameID'] == gameID and sale['mercID'] == mercID:
                        sale['sold'] = sold
        else:
            message(
                'Sales record with the same GameID and MerchandiseID does not exist!'
            )

    # venues
    elif option == '4':
        venueID = venueIDValidation('update')
        newVenueName, exist = venuesDataValidation()
        if not exist:
            updateVenueObj = Venue(venueID, newVenueName)

            # if updated database successfully, modify the globalData with the new values as well
            if data.venuesManipulate(updateVenueObj, 2):
                for venue in globalData['venues']:
                    if venue['venueID'] == venueID:
                        venue['name'] = newVenueName