예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
0
def deleteBar(bar):
    barRepo = BarRepo.BarRepo()
    return barRepo.deleteBar(bar)
예제 #7
0
def updateBar(bar, oldName):
    barRepo = BarRepo.BarRepo()
    return barRepo.updateBar(bar, oldName)
예제 #8
0
def insertBar(bar):
    barRepo = BarRepo.BarRepo()
    return barRepo.insertBar(bar)
예제 #9
0
def getTimeDistrubition(bar):
    barRepo = BarRepo.BarRepo()
    results = barRepo.getTimeDistrubition(bar)
    return jsonify([e.toJson() for e in results])
예제 #10
0
def getSaleDistributionDays(bar):
    barRepo = BarRepo.BarRepo()
    results = barRepo.getSaleDistributionDays(bar)
    return jsonify([e.toJson() for e in results])
예제 #11
0
def getAllBars():
    barRepo = BarRepo.BarRepo()
    results = barRepo.getAllBars()
    return jsonify([e.toJson() for e in results])
예제 #12
0
def getTopLargestSpenders(bar):
    barRepo = BarRepo.BarRepo()
    results = barRepo.getTopLargestSpenders(bar)
    return jsonify([e.toJson() for e in results])
예제 #13
0
def getbarTopBeerBrand(bar, dayOfWeek):
    barRepo = BarRepo.BarRepo()
    results = barRepo.getbarTopBeerBrand(bar, dayOfWeek)
    return jsonify([e.toJson() for e in results])
예제 #14
0
def getAllFractionsOfInventory(bar):
    barRepo = BarRepo.BarRepo()
    results = barRepo.getAllFractionsOfInventory(bar)
    return jsonify([e.toJson() for e in results])
예제 #15
0
def getTop10RankBySalesForDay(day):
    barRepo = BarRepo.BarRepo()
    results = barRepo.getTop10RankBySalesForDay(day)
    return jsonify([e.toJson() for e in results])
예제 #16
0
def getTop10RankBySalesOfManf(manf):
    barRepo = BarRepo.BarRepo()
    results = barRepo.getTop10RankBySalesOfManf(manf)
    return jsonify([e.toJson() for e in results])