def populateInventoryInfo():

	print(sys._getframe().f_code.co_name + ": ")

	dao = InventoryDAO(gc_connector)

	entries = [
				(1, 0, 0, 50, 0, 0),
				(2, 0, 1, 50, 20, 0),
				(3, 0, 2, 50, 40, 0),
				(4, 0, 3, 50, 60, 0),
				(5, 1, 0, 100, 0, 0),
				(1, 1, 1, 100, 20, 0),
				(2, 2, 0, 150, 0, 0),
				(3, 2, 1, 150, 20, 0),
				(4, 2, 2, 150, 40, 0),
				(5, 2, 3, 150, 60, 0),
				(1, 2, 4, 150, 80, 0),
				(2, 2, 5, 150, 100, 0)
			  ]

	for entry in entries:
		dao.createAnEntry(entry)

	print(dao.selectAllEntries())

	print("===================================================")
	print("Testing populateInventoryInfo-------------------complete\n\n\n")
def testProcessRetrievedInventory():
	print(sys._getframe().f_code.co_name + ": ")

	dbConnect = DbConnect(InventoryDAO.getDbDir())
	connector = dbConnect.getConnection()

	customerId = 1
	barcode = 1
	quantity = 2

	androidService = AndroidService()
	inventoryReservation = androidService.reserveInventoryIfAvailable(customerId, barcode, quantity)
	print(inventoryReservation) # (True, reservedInventoryLoc, newVirtualCartRowId)


	arduinoService = ArduinoService()
	print( arduinoService.processRetrievedInventory(1, 1) )

	inventoryDAO = InventoryDAO(connector)
	print( inventoryDAO.selectAllEntries() )

	virtualCartDAO = VirtualCartDAO(connector)
	print( virtualCartDAO.selectAllEntries() )

	print("===================================================")
	print("Testing testProcessRetrievedInventory-------------------complete\n\n\n")
Beispiel #3
0
	def depositInventory(self, barcode, x_index, y_index, x_encoder, y_encoder):
		
		dbConnect = DbConnect(InventoryDAO.getDbDir())
		connector = dbConnect.getConnection()


		barcodeDAO = BarcodeDAO(connector)
		barcodeId = barcodeDAO.getPriKeys("Barcode", barcode)[0]


		inventoryDAO = InventoryDAO(connector)
		entry = (barcodeId, x_index, y_index, x_encoder, y_encoder, 0)
		inventoryDAO.createAnEntry(entry)
def populateInventoryInfo():

	print(sys._getframe().f_code.co_name + ": ")

	dao = InventoryDAO(gc_connector)

	entries = [
			  ]

	for entry in entries:
		dao.createAnEntry(entry)

	print(dao.selectAllEntries())

	print("===================================================")
	print("Testing populateInventoryInfo-------------------complete\n\n\n")
Beispiel #5
0
	def __numItemsAvailable(self, connector, barcode):

		barcodeDAO = BarcodeDAO(connector)
		barcodeColHeader = "Barcode"
		barcodePriKey = barcodeDAO.getPriKeys(barcodeColHeader, barcode)[0]

		inventoryDAO = InventoryDAO(connector)
		numItems = 0

		barcodesInInventory = inventoryDAO.getPriKeys("BarcodeDetailsFk", barcodePriKey)

		for barcodeInInventory in barcodesInInventory:
			if inventoryDAO.selectAColumn("CheckoutFlag", barcodeInInventory) == 0:
				numItems += 1

		return numItems
Beispiel #6
0
	def reserveInventoryIfAvailable(self, customerId, barcode, quantity):

		dbConnect = DbConnect(BarcodeDAO.getDbDir())
		connector = dbConnect.getConnection()

		# the customer should order the exact amount. For example if there exists 1 item in the
		# back room and the customer ordered 2 items, then the whole transaction is rejected.
		# if returning false, the available quantity
		numAvailableItem = self.__numItemsAvailable(connector, barcode)
		if numAvailableItem < quantity:
			return (False, numAvailableItem)


		barcodeDAO = BarcodeDAO(connector)
		barcodePriKey = barcodeDAO.getPriKeys("Barcode", barcode)[0]


		inventoryDAO = InventoryDAO(connector)
		inventoryEntries = inventoryDAO.selectEntries("BarcodeDetailsFk", barcodePriKey)


		virtualCartDAO = VirtualCartDAO(connector)
		newVirtualCartRowId = virtualCartDAO.createAnEntry( (customerId, barcodePriKey, quantity, 0) )


		reservedInventoryLoc = list()

		reserveCount = 0
		for inventoryEntry in inventoryEntries:

			if reserveCount == quantity:
				break

			if inventoryEntry[6] != 0:
				continue

			inventoryDAO.update(inventoryEntry[0], "CheckoutFlag", 1)

			# [inventoryDetailsId, barcodeDetailsFk, X_index, Y_index, X_encoder, Y_encoder, checkoutFlag]
			entry = inventoryDAO.selectAnEntry(inventoryEntry[0])

			reservedInventoryLoc.append(entry[0:1]+entry[2:6]) # omit barcodeDetailsFk and checkoutFlag
			reserveCount += 1

		return (True, reservedInventoryLoc, newVirtualCartRowId)
def testDepositInventory():
	print(sys._getframe().f_code.co_name + ": ")

	dbConnect = DbConnect(InventoryDAO.getDbDir())
	connector = dbConnect.getConnection()

	arduinoService = ArduinoService()

	[newXIdx, newYIdx, newXEncoder, newYEncoder] = arduinoService.getDepositLocation()
	print([newXIdx, newYIdx, newXEncoder, newYEncoder])

	arduinoService.depositInventory(5, newXIdx, newYIdx, newXEncoder, newYEncoder)

	inventoryDAO = InventoryDAO(connector)
	print(inventoryDAO.selectAllEntries())

	print("===================================================")
	print("Testing testDepositInventory-------------------complete\n\n\n")
def testGetLocationBoxAbove():
	print(sys._getframe().f_code.co_name + ": ")

	dbConnect = DbConnect(InventoryDAO.getDbDir())
	connector = dbConnect.getConnection()

	arduinoService = ArduinoService()

	print(arduinoService.getLocationBoxAbove(1))

	print("===================================================")
	print("Testing testGetLocationBoxAbove-------------------complete\n\n\n")
def testGetDepositLocation():
	print(sys._getframe().f_code.co_name + ": ")

	dbConnect = DbConnect(InventoryDAO.getDbDir())
	connector = dbConnect.getConnection()

	arduinoService = ArduinoService()

	print(arduinoService.getDepositLocation())

	print("===================================================")
	print("Testing testProcessRetrievedInventory-------------------complete\n\n\n")
def testReserveInventoryIfAvailable():
	dbConnect = DbConnect(InventoryDAO.getDbDir())
	connector = dbConnect.getConnection()

	service = AndroidService()
	print(sys._getframe().f_code.co_name + ": ")
	print( service.reserveInventoryIfAvailable(1, 1, 1) )
	print( service.numItemsAvailable(1) )
	print( service.reserveInventoryIfAvailable(1, 1, 1) )
	print( service.numItemsAvailable(1) )
	print("===================================================")
	print("Testing reserveInventoryIfAvailable--------complete\n\n\n")
Beispiel #11
0
	def getLocationBoxAbove(self, inventoryDetailsId):

		dbConnect = DbConnect(InventoryDAO.getDbDir())
		connector = dbConnect.getConnection()

		inventoryDAO = InventoryDAO(connector)
		reservedInv = inventoryDAO.selectAnEntry(inventoryDetailsId)

		itemsOnStack = inventoryDAO.selectEntries("X_index", reservedInv[2])

		x_encoder = reservedInv[4]
		y_encoder = 0

		#if no box at the top, set to 0
		if len(itemsOnStack)-1 != reservedInv[3]:
			for item in itemsOnStack:
				if item[3] == reservedInv[3]+1:
					y_encoder = item[5]
					break

		return [x_encoder, y_encoder] 
Beispiel #12
0
	def getSecondPageInfo(self, selection):

		dbConnect = DbConnect(FootwearSelectionDAO.getDbDir())
		connector = dbConnect.getConnection()

		footwearSelectionDAO = FootwearSelectionDAO(connector)
		footwearSelectionPriKeys = footwearSelectionDAO.getPriKeys("Selection", selection)

		retVal = list()

		barcodeDAO = BarcodeDAO(connector)
		for footwearSelectionPriKey in footwearSelectionPriKeys:
			entries = barcodeDAO.selectEntries("FootwearSelectionDetailsFk", footwearSelectionPriKey)

			barcodePriKey = entries[0]

			inventoryDAO = InventoryDAO(connector)
			inventories = inventoryDAO.getPriKeys("BarcodeDetailsFk", barcodePriKey)

			for entry in entries:
				retVal.append((entry[1], entry[3], entry[4], entry[5], entry[6], len(inventories) ) )

		return retVal
Beispiel #13
0
	def getDepositLocation(self):

		dbConnect = DbConnect(InventoryDAO.getDbDir())
		connector = dbConnect.getConnection()


		inventoryDAO = InventoryDAO(connector)
		c_maxXIndex = InventoryInfo.sc_maxXIndex
		c_maxYIndex = InventoryInfo.sc_maxYIndex

		oneStackEntries = list()
		x_idx = 0
		for x_idx in range(0, c_maxXIndex):
			oneStackEntries = inventoryDAO.selectEntries("X_index", x_idx)
			if(len(oneStackEntries) <= c_maxYIndex):
				break

		newXIdx = x_idx
		newYIdx = len(oneStackEntries)
		x_encoder = ArduinoService.sc_xEncodingValues[newXIdx]
		y_encoder = 6700

		# the way stocking works for column 0 is different from column 1 and 2
		if newXIdx != 0 and newYIdx == 2:
			return [newxIdx, newYIdx, x_encoder, 36000]

		# !TODO: CHANGE THIS
		maxBoxSize = InventoryInfo.sc_maxBoxSize

		maxY_encoder = 6700
		if newYIdx > 0:
			for item in oneStackEntries:
				if maxY_encoder < item[5]:
					maxY_encoder = item[5]
			y_encoder = maxY_encoder + maxBoxSize

		return [newXIdx, newYIdx, x_encoder, y_encoder]
Beispiel #14
0
	def processRetrievedInventory(self, inventoryInfoRowId, virtualCartRowId):

		dbConnect = DbConnect(InventoryDAO.getDbDir())
		connector = dbConnect.getConnection()

		# TODO: after debugging this code is done, there should be a check ensuring that there exists
		# such ids

		inventoryDAO = InventoryDAO(connector)
		yIdxColHeader = "Y_index"

		retrievedItemYIndex = inventoryDAO.selectAColumn(yIdxColHeader, inventoryInfoRowId)

		# if the retrieved box is at the top, no need to do updates on y_encoders and y_index
		if retrievedItemYIndex != inventoryDAO.selectMax(yIdxColHeader):
			idBoxAbove = inventoryDAO.getPriKeys(yIdxColHeader, retrievedItemYIndex+1)[0]

			yEncoderColHeader = "Y_encoder"
			encoderOffset = (inventoryDAO.selectAColumn(yEncoderColHeader, idBoxAbove) - 
							 inventoryDAO.selectAColumn(yEncoderColHeader, inventoryInfoRowId))
			
			# update the y_encoder and y_index values for the boxes above the retrieved box
			xIdxColHeader = "X_index"
			retrievedItemXIdx = inventoryDAO.selectAColumn(xIdxColHeader, inventoryInfoRowId)
			sameStackItemIds = inventoryDAO.getPriKeys(xIdxColHeader, retrievedItemXIdx)
			for sameStackItemId in sameStackItemIds:
				curYIdx = inventoryDAO.selectAColumn(yIdxColHeader, sameStackItemId)

				if curYIdx > retrievedItemYIndex:
					inventoryDAO.update(sameStackItemId, yIdxColHeader, curYIdx-1)

					curYEncoder = inventoryDAO.selectAColumn(yEncoderColHeader, sameStackItemId)
					inventoryDAO.update(sameStackItemId, yEncoderColHeader, curYEncoder-encoderOffset)

		inventoryDAO.delete(inventoryInfoRowId)
		print("inventory deleted!!!")


		virtualCartDAO = VirtualCartDAO(connector)

		numItemsForPickup = virtualCartDAO.selectAColumn("NumItemAvailableForPickup", virtualCartRowId)
		virtualCartDAO.update(virtualCartRowId, "NumItemAvailableForPickup", numItemsForPickup+1)