Beispiel #1
0
def pay_back_generator(value):
    today = jdatetime.datetime.now().date()
    now_time = datetime.datetime.now().time()

    booking_object = get_object_or_404(BookingModel, pk=value)
    session = booking_object.session
    ceil_date = jdate(today.year, today.month, today.day) + jtimedelta(days=2)
    ceil_time = (datetime.datetime.combine(datetime.date(1, 1, 1), now_time) +
                 timedelta(hours=5)).time()
    if booking_object.session.day >= ceil_date:  # percent harm 3 for sportclub 2 for company
        if booking_object.is_contract:
            contract_discount = booking_object.contract_discount
            pay_back = (booking_object.final_price *
                        (100 - contract_discount - 5)) / 100
        else:
            pay_back = booking_object.final_price * (95 / 100)

    elif booking_object.session.day == today and booking_object.session.time < ceil_time:
        payback = False
    elif booking_object.session.day < today:
        payback = False
    else:
        if not booking_object.is_contract:
            pay_back = (booking_object.final_price * 85) / 100
        else:
            contract_discount = booking_object.contract_discount
            pay_back = (booking_object.final_price *
                        (85 - contract_discount)) / 100
    return pay_back
Beispiel #2
0
def CancellingView(request, pk):
    try:
        today = jdatetime.datetime.now().date()
        now_time = datetime.datetime.now().time()

        booking_object = get_object_or_404(BookingModel, pk=pk)
        session = booking_object.session
        ceil_date = jdate(today.year, today.month,
                          today.day) + jtimedelta(days=2)
        ceil_time = (
            datetime.datetime.combine(datetime.date(1, 1, 1), now_time) +
            timedelta(hours=5)).time()
        final_price = booking_object.final_price
        if booking_object.session.day >= ceil_date:
            if booking_object.is_contract:
                session.is_booked = False
                session.booker = None
                contract_discount = booking_object.contract_discount
                booking_object.pay_back = (booking_object.final_price *
                                           (92 - contract_discount)) / 100
                booking_object.company_portion = final_price * (3 / 100)
                booking_object.sportclub_portion = booking_object.pay_back + final_price * (
                    5 / 100)
                booking_object.cancelled = True
                booking_object.cancelled_at_date = today
                booking_object.cancelled_at_time = now_time
                booking_object.save()
            else:
                session.is_booked = False
                session.booker = None
                booking_object.pay_back = booking_object.final_price * (95 /
                                                                        100)
                booking_object.company_portion = final_price * (2 / 100)
                booking_object.sportclub_portion = booking_object.pay_back + final_price * (
                    3 / 100)
                booking_object.cancelled = True
                booking_object.cancelled_at_date = today
                booking_object.cancelled_at_time = now_time
                booking_object.save()
        elif booking_object.session.day == today and booking_object.session.time < ceil_time:
            return HttpResponseRedirect(reverse('booking:cantcancell'))
        elif booking_object.session.day < today:
            return HttpResponseRedirect(reverse('booking:cancellingerror'))
        else:
            if not booking_object.is_contract:
                session.is_booked = False
                session.booker = None
                booking_object.pay_back = (booking_object.final_price *
                                           85) / 100
                booking_object.company_portion = final_price * (3 / 100)
                booking_object.sportclub_portion = booking_object.pay_back + final_price * (
                    12 / 100)
                booking_object.cancelled = True
                booking_object.cancelled_at_date = today
                booking_object.save()
            else:
                session.is_booked = False
                session.booker = None
                contract_discount = booking_object.contract_discount
                booking_object.pay_back = (booking_object.final_price *
                                           (80 - contract_discount)) / 100
                booking_object.company_portion = final_price * (5 / 100)
                booking_object.sportclub_portion = booking_object.pay_back + final_price * (
                    15 / 100)
                booking_object.cancelled = True
                booking_object.cancelled_at_date = today
                booking_object.save()
        booking_object.cancelled_at_time = now_time
        booking_object.save()
        session.save()
        return HttpResponseRedirect(reverse('booking:cancelsuccess'))
    except:
        return HttpResponseRedirect(reverse('booking:cancellingerror'))
Beispiel #3
0
def jalali_daterange(start_time: jdatetime, end_time: jdatetime):
    for n in range(int((end_time - start_time).days)):
        yield start_time + jtimedelta(n)