示例#1
0
def updateSellsBeer(sellsBeer, oldBeer, oldBar):
    sellsBeerRepo = SellsBeerRepo.SellsBeerRepo()
    if sellsBeerRepo.duplicate_entry(
            sellsBeer.getBeername(), sellsBeer.getBarname()) and (
                not oldBeer == sellsBeer.getBeername()
                or not oldBar == sellsBeer.getBarname()):
        raise Error("Duplicate Entry")
    if (not oldBeer == sellsBeer.getBeername()
            or not oldBar == sellsBeer.getBarname()):
        date_N_days_ago = datetime.now()

        curdate = str(str(date_N_days_ago).split()[0])
        inventoryRepo = InventoryRepo.InventoryRepo()
        result = inventoryRepo.getInventory(sellsBeer.getBarname(),
                                            sellsBeer.getBeername(), curdate)
        if len(result) == 0:
            startQuantity = 100
            #update inventory for current date for the new beer
            inventoryRepo = InventoryRepo.InventoryRepo()
            inventoryRepo.insertIntoInventory(sellsBeer.getBarname(),
                                              sellsBeer.getBeername(), curdate,
                                              startQuantity, startQuantity)

    sellsBeerRepo = SellsBeerRepo.SellsBeerRepo()
    return sellsBeerRepo.updateSellsBeer(sellsBeer, oldBeer, oldBar)
def insertSellsFood(sellsFood):
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    if sellsFoodRepo.duplicate_entry(sellsFood.getFoodname(),
                                     sellsFood.getBarname()):
        raise Error("Duplicate Entry")
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    return sellsFoodRepo.insertSellsFood(sellsFood)
示例#3
0
	def insertWithoutClose(self,sql,vals):
		try:
			self.cursor.execute(sql,vals)
		except mysql.connector.Error as err:
			self.close()
			raise Error(err.msg)
		self.mydb.commit()
		return "Success"
def updateSellsFood(sellsFood, oldFood, oldBar):
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    if sellsFoodRepo.duplicate_entry(
            sellsFood.getFoodname(), sellsFood.getBarname()) and (
                not oldFood == sellsFood.getFoodname()
                or not oldBar == sellsFood.getBarname()):
        raise Error("Duplicate Entry")
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    return sellsFoodRepo.updateSellsFood(sellsFood, oldFood, oldBar)
示例#5
0
def deleteShifts(shifts):
    billsRepo = BillsRepo.BillsRepo()
    transcations = billsRepo.getBillsByBartenderAndDate(
        shifts.getBartender(), shifts.getDate())
    if not variable.isEmptyArray(transcations):
        raise Error(
            "Bartender has transcations during the shift, please delete them before trying to delete shift"
        )
    shiftsRepo = ShiftsRepo.ShiftsRepo()
    return shiftsRepo.deleteShifts(shifts)
示例#6
0
def updateShifts(shifts, oldBar, oldBartender, oldDate):
    bartenderRepo = BartenderRepo.BartenderRepo()
    bartenderArray = bartenderRepo.getBartender(shifts.getBartender())
    if variable.isEmptyArray(bartenderArray):
        raise Error("Bartender does not exist")

    #pattern 5
    shiftsRepo = ShiftsRepo.ShiftsRepo()
    items = shiftsRepo.getShifts(shifts.getBartender(), shifts.getDate())
    if len(items) != 0 and (not (shifts.getBartender() == oldBartender)
                            or not (shifts.getBar() == oldBar)
                            or not (shifts.getDate() == oldDate)):
        raise Error("Bartender can only have one shift on a given date")

    barRepo = BarRepo.BarRepo()
    barArray = barRepo.getBar(shifts.getBar())
    if variable.isEmptyArray(barArray):
        raise Error("Bar does not exist")

    datetime_object = datetime.strptime(shifts.getDate(), "%Y-%m-%d")
    if str(calendar.day_name[datetime_object.weekday()]) != str(
            shifts.getDay()):
        raise Error("Day does not match date")

    if shifts.getStart() >= shifts.getEnd():
        raise Error("shifts hour error: start time cannot be before end time")

    operatesRepo = OperatesRepo.OperatesRepo()
    if not operatesRepo.shift_during_operating_hours(
            shifts.getStart(), shifts.getEnd(), shifts.getBar(),
            shifts.getDate()):
        raise Error("bar does not operate during that shift")

    if barArray[0].getState() != bartenderArray[0].getState():
        raise Error("bartender cannot live in a different state than the bar")

    billsRepo = BillsRepo.BillsRepo()
    transcations = billsRepo.getBillsByBartenderAndDate(
        shifts.getBartender(), shifts.getDate())

    for each in transcations:
        if not (shifts.getStart() <= each.getTime()
                and each.getTime() <= shifts.getEnd()):
            raise Error(
                "Bartender has transcations during the current shift that need to be deleted or updated before trying to update this shift"
            )

    shiftsRepo = ShiftsRepo.ShiftsRepo()
    return shiftsRepo.updateShifts(shifts, oldBar, oldBartender, oldDate)
示例#7
0
def insertOperates(operates):
    barRepo = BarRepo.BarRepo()
    if not barRepo.bar_exists(operates.getBar()):
        raise Error("bar does not exist")

    dayRepo = DayRepo.DayRepo()
    if not dayRepo.day_exists(operates.getDay()):
        raise Error("day does not exist")

    operatesRepo = OperatesRepo.OperatesRepo()
    if operatesRepo.duplicate_entry(operates.getBar(), operates.getDate()):
        raise Error("Duplicate Entry")

    if not (operates.getEnd() <= "24:00"
            and operates.getStart() < operates.getEnd()):
        raise Error("Invalid hours provided")

    datetime_object = datetime.strptime(operates.getDate(), "%Y-%m-%d")
    if not calendar.day_name[datetime_object.weekday()] == operates.getDay():
        raise Error("Day does not match date")

    operatesRepo = OperatesRepo.OperatesRepo()
    return operatesRepo.insertOperates(operates)
示例#8
0
def deleteOperates(operates):
    #check if any bartenders at that bar on that date have shifts when bar is not open
    shiftsRepo = ShiftsRepo.ShiftsRepo()
    shifts = shiftsRepo.getShiftsForBar(operates.getBar(), operates.getDate())
    for s in shifts:
        if s.getStart() < operates.getStart() or s.getEnd() > operates.getEnd(
        ):
            raise Error(
                "Deleting these operating hours would result in bartender(s) having shift when bar is closed. Please update Shifts table first."
            )

    #check if any bills at that bar on that date have a time when bar is not open
    billsRepo = BillsRepo.BillsRepo()
    bills = billsRepo.getBillsByBarAndDate(operates.getBar(),
                                           operates.getDate())
    for b in bills:
        if b.getTime() < operates.getStart() or b.getTime() > operates.getEnd(
        ):
            raise Error(
                "Deleting these operating hours in bill(s) would result in a time stamp when bar is closed. Please update Bills table first."
            )

    operatesRepo = OperatesRepo.OperatesRepo()
    return operatesRepo.deleteOperates(operates)
示例#9
0
def insertBills(bills):

    barRepo = BarRepo.BarRepo()
    if not barRepo.bar_exists(bills.getBar()):
        raise Error("bar does not exist")

    bartenderRepo = BartenderRepo.BartenderRepo()
    if not bartenderRepo.bartender_exists(bills.getBartender()):
        raise Error("bartender does not exist")

    drinkerRepo = DrinkersRepo.DrinkersRepo()
    if not drinkerRepo.drinker_exists(bills.getDrinker()):
        raise Error("drinker does not exist")

    datetime_object = datetime.strptime(bills.getDate(), "%Y-%m-%d")
    if not calendar.day_name[datetime_object.weekday()] == bills.getDay():
        raise Error("Day does not match date")

    billsRepo = BillsRepo.BillsRepo()
    if billsRepo.duplicate_entry(bills.getBillId()):
        raise Error("duplicate entry")

    operatesRepo = OperatesRepo.OperatesRepo()
    if not operatesRepo.time_during_operating_hours(
            bills.getTime(), bills.getBar(), bills.getDate()):
        raise Error("Bar is not open during that time")

    shiftsRepo = ShiftsRepo.ShiftsRepo()
    if not shiftsRepo.time_during_shift(bills.getTime(), bills.getBartender(),
                                        bills.getBar(), bills.getDate()):
        raise Error(
            "Bartender does not have shift at the bar and/or on that date and/or during that time"
        )

    # if not float(bills.getTaxPrice()) == round(float(bills.getItemsPrice())*0.07,2):
    # 	raise Error("Tax is not 7 percent of the items price")

    # if not float(bills.getTaxPrice()) + float(bills.getTip()) + float(bills.getItemsPrice()) == float(bills.getTotalPrice()):
    # 	raise Error("Incorrect total price")

    # billsRepo = BillsRepo.BillsRepo()
    # if not billsRepo.check_items_price(bills.getBillId(), bills.getItemsPrice()):
    # 	raise Error("Price of all the items doesn't match the total of the corresponding transactions")

    # bills.setTaxPrice(0)
    # bills.setItemsPrice(0)
    # bills.setTip(0)
    # bills.setTotalPrice(0)
    billsRepo = BillsRepo.BillsRepo()
    return billsRepo.insertBills(bills)
示例#10
0
	def query(self,sql_query,Obj):
		try:
			self.cursor.execute(sql_query)
			myresult = self.cursor.fetchall()
		except mysql.connector.Error as err:
			self.close()
			raise Error(err.msg)
		result = []
		columns = tuple( [d[0].decode('utf8') for d in self.cursor.description] )
		for row in myresult:
			result.append(dict(zip(columns, row)))
		final_results = []
		for item in result:
			obj = Obj()
			obj.map(item)
			final_results.append(obj)
		self.close()
		return final_results
示例#11
0
def insertSellsBeer(sellsBeer):
    sellsBeerRepo = SellsBeerRepo.SellsBeerRepo()
    if sellsBeerRepo.duplicate_entry(sellsBeer.getBeername(),
                                     sellsBeer.getBarname()):
        raise Error("Duplicate Entry")

    startQuantity = 100
    #update inventory for current date for the new beer
    date_N_days_ago = datetime.now()

    curdate = str(str(date_N_days_ago).split()[0])
    inventoryRepo = InventoryRepo.InventoryRepo()
    inventoryRepo.insertIntoInventory(sellsBeer.getBarname(),
                                      sellsBeer.getBeername(), curdate,
                                      startQuantity, startQuantity)

    sellsBeerRepo = SellsBeerRepo.SellsBeerRepo()
    return sellsBeerRepo.insertSellsBeer(sellsBeer)
示例#12
0
def updateOperates(operates, oldDate, oldBar):
    barRepo = BarRepo.BarRepo()
    if not barRepo.bar_exists(operates.getBar()):
        raise Error("bar does not exist")

    dayRepo = DayRepo.DayRepo()
    if not dayRepo.day_exists(operates.getDay()):
        raise Error("day does not exist")

    operatesRepo = OperatesRepo.OperatesRepo()
    if operatesRepo.duplicate_entry(
            operates.getBar(),
            operates.getDate()) and (not operates.getBar() == oldBar
                                     or not operates.getDate() == oldDate):
        raise Error("Duplicate Entry")

    if not (operates.getEnd() <= "24:00"
            and operates.getStart() < operates.getEnd()):
        raise Error("Invalid hours provided")

    datetime_object = datetime.strptime(operates.getDate(), "%Y-%m-%d")
    if not calendar.day_name[datetime_object.weekday()] == operates.getDay():
        raise Error("Day does not match date")

    #check if any bartenders at that bar on that date have shifts when bar is not open
    shiftsRepo = ShiftsRepo.ShiftsRepo()
    shifts = shiftsRepo.getShiftsForBar(operates.getBar(), operates.getDate())
    for s in shifts:
        if s.getStart() < operates.getStart() or s.getEnd() > operates.getEnd(
        ):
            raise Error(
                "Update would result in bartender(s) having shift when bar is closed. Please update Shifts table first."
            )
    #check if any bills at that bar on that date have a time when bar is not open
    billsRepo = BillsRepo.BillsRepo()
    bills = billsRepo.getBillsByBarAndDate(operates.getBar(),
                                           operates.getDate())
    for b in bills:
        if b.getTime() < operates.getStart() or b.getTime() > operates.getEnd(
        ):
            raise Error(
                "Update would result in bill(s) would result in a time stamp when bar is closed. Please update Bills table first."
            )

    operatesRepo = OperatesRepo.OperatesRepo()
    return operatesRepo.updateOperates(operates, oldDate, oldBar)
示例#13
0
def insertShifts(shifts):

    bartenderRepo = BartenderRepo.BartenderRepo()
    bartenderArray = bartenderRepo.getBartender(shifts.getBartender())
    if variable.isEmptyArray(bartenderArray):
        raise Error("Bartender does not exist")

    shiftsRepo = ShiftsRepo.ShiftsRepo()
    items = shiftsRepo.getShifts(shifts.getBartender(), shifts.getDate())
    if len(items) != 0:
        raise Error("Bartender can only have one shift on a given date")

    barRepo = BarRepo.BarRepo()
    barArray = barRepo.getBar(shifts.getBar())
    if variable.isEmptyArray(barArray):
        raise Error("Bar does not exist")

    datetime_object = datetime.strptime(shifts.getDate(), "%Y-%m-%d")
    if str(calendar.day_name[datetime_object.weekday()]) != str(
            shifts.getDay()):
        raise Error("Day does not match date")

    if shifts.getStart() >= shifts.getEnd():
        raise Error("shifts hour error: start time cannot be before end time")

    operatesRepo = OperatesRepo.OperatesRepo()
    if not operatesRepo.shift_during_operating_hours(
            shifts.getStart(), shifts.getEnd(), shifts.getBar(),
            shifts.getDate()):
        raise Error("bar does not operate during that shift")

    if barArray[0].getState() != bartenderArray[0].getState():
        raise Error("bartender cannot live in a different state than the bar")

    shiftsRepo = ShiftsRepo.ShiftsRepo()
    return shiftsRepo.insertShifts(shifts)
def insertTransactions(transactions):
    if int(transactions.getQuantity()) <= 0:
        raise Error("Invalid Quantity")

    billsRepo = BillsRepo.BillsRepo()
    bill = billsRepo.getBillArray(transactions.getBillId())
    if len(bill) == 0:
        raise Error(
            "No bill has been created for this transaction. Please insert a bill and try again."
        )
    bill = bill[0]

    transactionsRepo = TransactionsRepo.TransactionsRepo()
    if transactionsRepo.duplicate_entry(transactions.getBillId(),
                                        transactions.getItem()):
        raise Error(
            "item is already a transactions for the current bill please use update to change amount of the item"
        )

    if transactions.getType() == "food":
        barFoodRepo = BarFoodRepo.BarFoodRepo()
        if not barFoodRepo.barFood_exists(transactions.getItem()):
            raise Error("Food does not exist")

        sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
        if not sellsFoodRepo.bar_sells_food(bill.getBar(),
                                            transactions.getItem()):
            raise Error("Bar doesn't sell the food")

        sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
        price = sellsFoodRepo.get_price(bill.getBar(), transactions.getItem())

    if transactions.getType() == "beer":

        beerRepo = BeerRepo.BeerRepo()
        if not beerRepo.beer_exists(transactions.getItem()):
            raise Error("Beer does not exist")

        sellsBeerRepo = SellsBeerRepo.SellsBeerRepo()
        if not sellsBeerRepo.bar_sells_beer(bill.getBar(),
                                            transactions.getItem()):
            raise Error("Bar doesn't sell the beer")

        sellsBeerRepo = SellsBeerRepo.SellsBeerRepo()
        price = sellsBeerRepo.get_price(bill.getBar(), transactions.getItem())

        inventoryRepo = InventoryRepo.InventoryRepo()
        #gets all inventory from date and after for a bar and beer
        results = inventoryRepo.getInventoryForToday(bill.getBar(),
                                                     transactions.getItem(),
                                                     bill.getDate())
        if len(results) == 0:
            raise Error("no inventory found for the bar")

        #see if can update inventory
        inventoryRepo = InventoryRepo.InventoryRepo()
        #gets all inventory from date and after for a bar and beer
        results = inventoryRepo.getInventory(bill.getBar(),
                                             transactions.getItem(),
                                             bill.getDate())
        if len(results) == 0:
            raise Error("no inventory found for the bar")

        #see if violates pattern
        results[0].setEndQuantity(
            int(results[0].getEndQuantity()) - int(transactions.getQuantity()))
        if int(results[0].getEndQuantity()) < 0:
            raise Error("Violates Pattern 4: not enough inventory")
        for r in range(1, len(results)):
            results[r].setStartQuantity(int(results[r - 1].getEndQuantity()))
            results[r].setEndQuantity(
                int(results[r].getEndQuantity()) -
                int(transactions.getQuantity()))
            if int(results[r].getEndQuantity()) < 0:
                raise Error("Violates Pattern 4: not enough inventory")

        #doesn't violate pattern 4
        inventoryRepo = InventoryRepo.InventoryRepo()
        #gets all inventory from date and after for a bar and beer
        results = inventoryRepo.getInventory(bill.getBar(),
                                             transactions.getItem(),
                                             bill.getDate())

        #update inventory
        results[0].setEndQuantity(
            int(results[0].getEndQuantity()) - int(transactions.getQuantity()))
        inventoryService.updateInventory(results[0], results[0].getDate(),
                                         results[0].getBar(),
                                         results[0].getBeer())
        for r in range(1, len(results)):
            results[r].setStartQuantity(results[r - 1].getEndQuantity())
            results[r].setEndQuantity(
                int(results[r].getEndQuantity()) -
                int(transactions.getQuantity()))
            inventoryService.updateInventory(results[r], results[r].getDate(),
                                             results[r].getBar(),
                                             results[r].getBeer())

    transactionsRepo = TransactionsRepo.TransactionsRepo()
    transactionsRepo.insertTransactions(transactions)

    #update bills
    billsRepo = BillsRepo.BillsRepo()
    bill = billsRepo.getBill(transactions.getBillId())
    items_price = float(transactions.getPrice())
    bill.setItemsPrice(items_price + float(bill.getItemsPrice()))
    bill.setTaxPrice(round(float(bill.getItemsPrice()) * 0.07, 2))
    bill.setTotalPrice(
        float(bill.getItemsPrice()) + float(bill.getTaxPrice()) +
        float(bill.getTip()))
    billsService.updateBills(bill, bill.getBillId())

    return "success"
def updateTransactions(transactions, oldBillId, oldItem):
    if int(transactions.getQuantity()) <= 0:
        raise Error("Invalid Quantity")

    transactionsRepo = TransactionsRepo.TransactionsRepo()
    if transactionsRepo.duplicate_entry(
            transactions.getBillId(), transactions.getItem()) and (
                not transactions.getBillId() == oldBillId
                or not transactions.getItem() == oldItem):
        raise Error("Duplicate Entry")

    billsRepo = BillsRepo.BillsRepo()
    bill = billsRepo.getBillArray(transactions.getBillId())
    if len(bill) == 0:
        raise Error(
            "No bill has been created for this transaction. Please insert a bill and try again."
        )
    bill = bill[0]

    transactionsRepo = TransactionsRepo.TransactionsRepo()
    trans = transactionsRepo.get_transaction(oldBillId, oldItem)
    if len(trans) == 0:
        raise Error("no transcation found")
    trans = trans[0]

    if transactions.getType() == "food":
        barFoodRepo = BarFoodRepo.BarFoodRepo()
        if not barFoodRepo.barFood_exists(transactions.getItem()):
            raise Error("Food does not exist")
        sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
        if not sellsFoodRepo.bar_sells_food(bill.getBar(),
                                            transactions.getItem()):
            raise Error("Bar doesn't sell the food")

    if transactions.getType() == "beer":
        beerRepo = BeerRepo.BeerRepo()
        if not beerRepo.beer_exists(transactions.getItem()):
            raise Error("Beer does not exist")

        sellsBeerRepo = SellsBeerRepo.SellsBeerRepo()
        if not sellsBeerRepo.bar_sells_beer(bill.getBar(),
                                            transactions.getItem()):
            raise Error("Bar doesn't sell the beer")

        # sellsBeerRepo = SellsBeerRepo.SellsBeerRepo()
        # price = sellsBeerRepo.get_price(transactions.getBar(), transactions.getItem())
        # if not price*int(transactions.getQuantity()) == transactions.getPrice():
        # 	raise Error("Incorrect price")

        inventoryRepo = InventoryRepo.InventoryRepo()
        #gets all inventory from date and after for a bar and beer
        results = inventoryRepo.getInventory(bill.getBar(),
                                             transactions.getItem(),
                                             bill.getDate())
        if len(results) == 0:
            raise Error("no inventory found for the bar")

        #number of the beer trying to sell
        # transactionsRepo = TransactionsRepo.TransactionsRepo()
        # quantity = transactionsRepo.get_quantity(transactions.getBillId(), transactions.getItem())

        quantity = int(transactions.getQuantity()) - int(trans.getQuantity())

        #see if violates pattern
        results[0].setEndQuantity(int(results[0].getEndQuantity()) - quantity)
        if int(results[0].getEndQuantity()) < 0:
            raise Error("Violates Pattern 4: not enough inventory")
        for r in range(1, len(results)):
            results[r].setStartQuantity(results[r - 1].getEndQuantity())
            results[r].setEndQuantity(
                int(results[r].getEndQuantity()) - quantity)
            if int(results[r].getEndQuantity()) < 0:
                raise Error("Violates Pattern 4: not enough inventory")

        #doesn't violate pattern 4
        inventoryRepo = InventoryRepo.InventoryRepo()
        #gets all inventory from date and after for a bar and beer
        results = inventoryRepo.getInventory(bill.getBar(),
                                             transactions.getItem(),
                                             bill.getDate())

        #number of the beer trying to sell
        # transactionsRepo = TransactionsRepo.TransactionsRepo()
        # quantity = transactionsRepo.get_quantity(transactions.getBillId(), transactions.getItem())

        #update inventory
        results[0].setEndQuantity(int(results[0].getEndQuantity()) - quantity)
        inventoryService.updateInventory(results[0], results[0].getDate(),
                                         results[0].getBar(),
                                         results[0].getBeer())
        for r in range(1, len(results)):
            results[r].setStartQuantity(results[r - 1].getEndQuantity())
            results[r].setEndQuantity(
                int(results[r].getEndQuantity()) - quantity)
            inventoryService.updateInventory(results[r], results[r].getDate(),
                                             results[r].getBar(),
                                             results[r].getBeer())

    #update transaction
    transactionsRepo = TransactionsRepo.TransactionsRepo()
    transactionsRepo.updateTransactions(transactions, oldBillId, oldItem)

    #remove all item price from bill
    bill.setItemsPrice(float(bill.getItemsPrice()) - float(trans.getPrice()))

    #update bills
    items_price = float(bill.getItemsPrice())
    bill.setItemsPrice(items_price + float(transactions.getPrice()))
    bill.setTaxPrice(round(float(bill.getItemsPrice()) * 0.07, 2))
    bill.setTotalPrice(
        float(bill.getItemsPrice()) + float(bill.getTaxPrice()) +
        float(bill.getTip()))
    billsService.updateBills(bill, bill.getBillId())

    return "success"