Exemple #1
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)
Exemple #2
0
def getAllOperates(num):
    operatesRepo = OperatesRepo.OperatesRepo()
    results = operatesRepo.getAllOperates()
    if len(results) <= num:
        return jsonify([])
    if num + 5000 >= len(results):
        return jsonify([e.toJson() for e in results[num:]])
    else:
        return jsonify([e.toJson() for e in results[num:num + 5000]])
Exemple #3
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)
Exemple #4
0
def insertOperatesForToday():
    operatesRepo = OperatesRepo.OperatesRepo()
    date = str(operatesRepo.getLastInsertedDate())

    date_N_days_ago = datetime.now()
    if str(str(date_N_days_ago).split()[0]) == str(date):
        return "day already inserted"

    operatesRepo = OperatesRepo.OperatesRepo()
    items = operatesRepo.getLastOperates(date)

    datetime_object = datetime.strptime(date, "%Y-%m-%d")
    datetime_object = datetime_object + timedelta(days=1)

    for item in items:
        item.setDate(str(str(datetime_object).split()[0]))
        try:
            operatesRepo = OperatesRepo.OperatesRepo()
            operatesRepo.insertOperatesForToday(item)
        except:
            pass

    return "Success"
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)
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)
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)
Exemple #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)
Exemple #9
0
def getOperatesForBar(bar):
    operatesRepo = OperatesRepo.OperatesRepo()
    results = operatesRepo.getOperatesForBar(bar)
    return jsonify([e.toJson() for e in results])