def my_bookings(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'],
                                request.session['role_id'])
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)
    except:
        return redirect("/login")
    if auth == True:
        if request.session['role_id'] == 4:
            book_id = []
            bd = booking_details.objects.filter(seller_detail=email)
            curr_date = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            curr_date = dt.datetime.now().strptime(curr_date,
                                                   "%Y-%m-%d %H:%M:%S")
            for i in bd:
                end_date = i.end_date
                end_date = dt.datetime.strptime(end_date, "%Y-%m-%d %H:%M:%S")
                if curr_date > end_date:
                    book_id.extend([i.booking_id])

            return render(request, "mybookings.html", {
                "bd": bd,
                "book_id": book_id
            })
        else:
            return redirect("/login")
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
def vehicle_company(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'], 1)
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)
    except:
        return redirect("/login")
    if auth == True:
        try:
            if (request.method == "POST"):
                form = VehicleCompanyForm(request.POST)
                if form.is_valid():
                    f1 = form.save(commit=False)
                    f1.company_name = (
                        request.POST['company_name']).capitalize()
                    f1.save()
                    return render(request, "vehiclecompanies.html",
                                  {'valid': True})
                else:
                    return render(request, "vehiclecompanies.html",
                                  {'invalid': True})
            return render(request, "vehiclecompanies.html")
        except:
            return render(request, "vehiclecompanies.html", {'exist': True})
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
Example #3
0
def pending_refunds(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'], 4)
        email = request.session['email']
    except:
        return redirect("/login")
    if auth == True:
        if request.method == "POST":
            try:
                sr = booking_details.objects.filter(
                    invoice__icontains=request.POST['invoice'],
                    seller_detail=email,
                    is_active=False,
                    refunded=False)
                return render(request, "pending_refunds.html", {"bd": sr})
            except:
                pass
        bd = booking_details.objects.filter(seller_detail=email,
                                            is_active=False,
                                            refunded=False)
        return render(request, 'pending_refunds.html', {'bd': bd})
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True, 'login': True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
Example #4
0
def refunded(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'], 4)
        email = request.session['email']
    except:
        return redirect("/login")
    if auth == True:

        id = request.GET['id']
        user = request.GET['user']
        bd = booking_details.objects.get(seller_detail=email,
                                         is_active=False,
                                         refunded=False,
                                         user_detail=user,
                                         invoice=id)
        update = booking_details(booking_id=bd.booking_id, refunded=True)
        update.save(update_fields=['refunded'])
        return redirect("/businessuser/pending_refunds")
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True, 'login': True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
def earnings(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'],
                                request.session['role_id'])
        email = request.session['email']
    except:
        return redirect("/login")
    if auth == True:
        total_earning = booking_details.objects.filter(
            seller_detail=email).aggregate(Sum("earnings"))
        total_fine = booking_details.objects.filter(
            seller_detail=email,
            cancellation_time="").aggregate(Sum("total_fine"))
        veh_amt = booking_details.objects.filter(
            seller_detail=email,
            cancellation_time="").aggregate(Sum("amount_exp"))
        cancel = booking_details.objects.filter(seller_detail=email,
                                                return_date="").aggregate(
                                                    Sum("total_fine"))
        return render(
            request, "Bank_Balance.html", {
                "earn": total_earning,
                "fine": total_fine,
                "amt": veh_amt,
                "cancel": cancel
            })

    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
def delete_data(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'], 1)
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)
    except:
        return redirect("/login")
    if auth == True:
        carid = request.GET['id']
        try:
            deleteUser = VehiclesDetails.objects.get(vehicle_ref_id=carid)
            deleteUser.delete()
            if request.session['role_id'] == 4:
                return redirect("businessuserapp:showdata")
            else:
                return redirect("managerapp:showdata")

        except:
            pass
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
Example #7
0
def show_bookings(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'],
                                request.session['role_id'])
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)
    except:
        return redirect("/login")
    if auth == True:

        try:
            id = request.GET['id']
            not_cancel = True
        except:
            not_cancel = False
            pass
        if request.session['role_id'] == 2:
            bd = booking_details.objects.all()

            return render(request, "bookingDetails.html", {"bd": bd})
        else:

            bd = booking_details.objects.filter(
                user_detail=request.session['email'])
            return render(request, "bookingDetails.html", {
                "bd": bd,
                "not_cancel": not_cancel
            })
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True, 'login': True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
Example #8
0
def view_current_book(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'],
                                request.session['role_id'])
        email = request.session['email']
    except:
        return redirect("/login")
    if auth == True:
        try:
            id = request.GET['id']
            bd = booking_details.objects.get(invoice=id)
            if email == bd.user_detail_id or email == bd.seller_detail:
                return render(request, "view_bookings.html", {"bd": bd})
            else:
                return redirect("/error")
        except:
            return redirect("/error")

    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True, 'login': True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
Example #9
0
def invoice(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'],
                                request.session['role_id'])
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)
    except:
        try:
            id = request.GET['id']
            bd = booking_details.objects.get(invoice=id)
            return render(request, "invoice.html", {"bd": bd})
        except:
            return redirect("/error")
    if auth == True:
        try:
            id = request.GET['id']
            bd = booking_details.objects.get(invoice=id)
            if email == bd.user_detail_id or email == bd.seller_detail:
                return render(request, "invoice.html", {"bd": bd})
            else:
                return redirect("/error")
        except:
            bd_new = booking_details.objects.filter(
                user_detail=email).latest("booking_id")
            return render(request, "invoice.html", {"bd_new": bd_new})

    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True, 'login': True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
Example #10
0
def vehicle_category(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'], 2)
    except:
        return redirect("/login")
    if auth == True:
        try:
            if (request.method == "POST"):
                form = VehicleCategoryForm(request.POST)
                if form.is_valid():
                    f1 = form.save(commit=False)
                    f1.vehicle_category_name = (
                        request.POST['vehicle_category_name']).capitalize()
                    f1.vehicle_category_price = request.POST[
                        'vehicle_category_price']
                    f1.save()
                    return render(request, "vehiclecategories.html",
                                  {'valid': True})
                else:
                    return render(request, "vehiclecategories.html",
                                  {'invalid': True})
            return render(request, "vehiclecategories.html")
        except:
            return render(request, "vehiclecategories.html", {'exist': True})
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return redirect("/login")
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
    return render(request, "superuser.html")
Example #11
0
def updatedata(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'], 2)
    except:
        return redirect("/login")
    if auth == True:

        year = int(dt.datetime.now().strftime(" %Y "))
        companydata = VehicleCompany.objects.all()
        companycategorydata = VehicleCategories.objects.all()
        userdata = VehiclesDetails.objects.all()
        get_id = request.GET['id']
        userdata = VehiclesDetails.objects.get(vehicle_ref_id=get_id)
        if request.method == "POST":
            user_image = userdata.vehicle_image
            if request.FILES:
                myfile = request.FILES['vehicle_image']
                fs = FileSystemStorage()
                filename = fs.save(myfile.name, myfile)
                fs.url(filename)
                user_image = myfile.name

            name = (request.POST["vehicle_name"]).capitalize()
            model = request.POST['vehicle_model']
            price = request.POST['vehicle_price']
            desc = request.POST["vehicle_description"]
            image = user_image

            update = VehiclesDetails(vehicle_ref_id=get_id,
                                     vehicle_name=name,
                                     vehicle_description=desc,
                                     vehicle_image=image,
                                     vehicle_price=price,
                                     vehicle_model=model)
            update.save(update_fields=[
                "vehicle_name", "vehicle_description", "vehicle_image",
                "vehicle_price", "vehicle_model"
            ])
            if request.session['role_id'] == 4:
                return redirect("businessuserapp:showdata")
            elif request.session['role_id'] == 1:
                return redirect("managerapp:showdata")
            else:
                return redirect("superuser:showdata")

        return render(
            request, "update_cars.html", {
                'vd': userdata,
                'yr': year,
                'ccd': companycategorydata,
                'cd': companydata
            })
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return redirect("/login")
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
    return render(request, "superuser.html")
Example #12
0
def vehicle_details(request):


    try:
        auth = au.authorizeuser(request.session['authenticate'],request.session['role_id'],1)
        email = request.session['email']
        
    except:
        return redirect("/login")
    if auth==True :
        year = int(dt.datetime.now().strftime(" %Y "))
        get_role = request.session['role_id']
        get_email = request.session['email']
        companydata = VehicleCompany.objects.all()
        companycategorydata = VehicleCategories.objects.all()
        userdata = VehiclesDetails.objects.all()
        if get_role == 4:
            for i in userdata:
                if get_email == i.u_email:
                    return redirect("/businessuser/showdata")
        if request.method == "POST":
            user_image = None
            if request.FILES:
                myfile = request.FILES['vehicle_image']  # type of file control name ??
                fs = FileSystemStorage()
                filename = fs.save(myfile.name, myfile)
                fs.url(filename)
                user_image = myfile.name

            form = VehicleDetailsForm(request.POST)
            if form.is_valid():
                f = form.save(commit=False)
                f.vehicle_name = request.POST['vehicle_name']
                f.u_email = request.session['email']
                f.vehicle_id_id = request.POST['veh_id']
                f.company_id_id = request.POST['sel']
                f.vehicle_description = request.POST['vehicle_description']
                f.vehicle_price = request.POST['vehicle_price']
                f.vehicle_model = request.POST['vehicle_model']
                f.abs = request.POST['abs']
                f.transmission = request.POST['transmission']
                f.airbags = request.POST['airbags']
                f.seats = request.POST['seats']
                # f.vehicle_price= int(f.vehicle_price) + int(base_price)
                f.vehicle_image = user_image
                f.role_id = int(request.session['role_id'])
                f.save()
                return render(request, "vehicledetails.html",
                              {'valid': True, 'cd': companydata, "ccd": companycategorydata, 'yr': year})
            else:
                return render(request, "vehiclecategories.html", {'invalid': True})

        return render(request, "vehicledetails.html", {'cd': companydata, "ccd": companycategorydata, 'yr': year})
    else:
        auth,message = auth
        if (message=="Not Logged In"):
            return render(request,"login.html",{"pass":True,'login':True})
        elif(message=="Wrong Level"):
            return render(request,"404.html",{"pass":True})
Example #13
0
def payment_done(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'],
                                request.session['role_id'])
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)
    except:
        return redirect("/login")
    if auth == True:
        try:
            token = request.GET['token']
            payment_done = payment_token.objects.get(token=token)
            dbtoken = payment_done.token

            if token == dbtoken:
                form = BookingForm(request.POST)
                if form.is_valid():
                    f1 = form.save(commit=False)
                    # return render(request,"abcd.html")
                    f1.booking_date = dt.datetime.now().strftime(
                        "%Y-%m-%d %H:%M:%S")
                    f1.start_date = request.session['start_date']
                    f1.end_date = request.session['end_date']
                    f1.user_detail_id = request.session['email']
                    f1.vehicle_detail = request.session['vehicle_name']
                    f1.security_amount = int(10000)
                    f1.vehicle_info_id = request.session['vehicle_id']
                    f1.amount_exp = request.session['amt']
                    f1.invoice = request.session['invoice']
                    f1.seller_detail = request.session['seller']
                    f1.total = request.session['total']
                    f1.cancel_token = str(random.randint(
                        1000000, 100000000)) + str(request.session['email'])
                    # email_send(f1.user_email, request.POST['user_password'], verify)
                    f1.save()
                    link = " http://127.0.0.1:8000/invoice/?id=" + request.session[
                        'invoice']
                    email_invoice(email, request.session['invoice'],
                                  request.session['name'], link)
                    clear_sessions(request)

                    # update = booking_details(booking_id=f1.booking_id, invoice=str(f1.booking_id) +"-"+ str(f1.invoice))
                    # update.save(update_fields=['invoice'])

                bd_new = booking_details.objects.filter(
                    user_detail=email).latest("booking_id")
                return render(request, "invoice.html", {"bd_new": bd_new})
        except:
            return redirect("/error")

    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
def my_bookings(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'],
                                request.session['role_id'])
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)
    except:
        return redirect("/login")
    if auth == True:
        if request.session['role_id'] == 1:
            book_id = []
            try:
                if request.method == "POST":
                    sr = booking_details.objects.filter(
                        invoice__icontains=request.POST['search'])
                    return render(request, "mybookings.html", {
                        "bd": sr,
                        "book_id": book_id
                    })
            except:
                pass

            bd = booking_details.objects.filter(seller_detail=email)

            curr_date = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            curr_date = dt.datetime.now().strptime(curr_date,
                                                   "%Y-%m-%d %H:%M:%S")
            for i in bd:
                end_date = i.end_date
                end_date = dt.datetime.strptime(end_date, "%Y-%m-%d %H:%M:%S")
                return_date = i.return_date
                try:
                    return_date = dt.datetime.strptime(return_date,
                                                       "%Y-%m-%d %H:%M:%S")
                except:
                    return_date = "2001-01-01 00:00:00"
                    return_date = dt.datetime.strptime(return_date,
                                                       "%Y-%m-%d %H:%M:%S")

                if curr_date > end_date and i.is_active == True:
                    book_id.extend([i.booking_id])
                if return_date > end_date:
                    book_id.extend([i.booking_id])

            return render(request, "mybookings.html", {
                "bd": bd,
                "book_id": book_id
            })
        else:
            return redirect("/error")
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
Example #15
0
def confirm_booking(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'],
                                request.session['role_id'])
        email = request.session['email']
    except:
        return redirect("/login")
    if auth == True:
        exist = False
        pay_tok = payment_token.objects.all()
        for i in pay_tok:
            if i.invoice == request.session['invoice']:
                exist = True
        if exist == False:
            tk = random.randint(100000, 100000000)
            tk = str(tk) + str(request.session['invoice'])
            form = PaymentTokenForm()
            #if form.is_valid():
            f = form.save(commit=False)
            f.user_email = email
            f.invoice = request.session['invoice']
            f.token = tk
            f.save()
        else:
            pass
        tok = payment_token.objects.get(invoice=request.session['invoice'])
        host = request.get_host()
        paypal_dict = {
            'business':
            settings.PAYPAL_RECEIVER_EMAIL,
            'amount':
            request.session['total'],
            'item_name':
            request.session['vehicle_name'],
            'invoice':
            request.session['invoice'],
            'currency_code':
            "INR",
            'notify_url':
            'http://{}{}'.format(host, reverse('paypal-ipn')),
            'return_url':
            'http://{}{}?token={}'.format(host, reverse('payment_done'),
                                          tok.token)
        }
        form1 = PayPalPaymentsForm(initial=paypal_dict)

        return render(request, "confirm_booking.html", {'form': form1})
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True, 'login': True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
def confirm_booking(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],request.session['role_id'],request.session['role_id'])
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)
    except:
        return redirect("/login")
    if auth==True:
        if (request.method == "POST"):
            form = BookingForm(request.POST)
            if form.is_valid():
                f1 = form.save(commit=False)
                # return render(request,"abcd.html")
                f1.booking_date = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                f1.start_date = request.session['start_date']
                f1.end_date = request.session['end_date']
                f1.user_detail_id = request.session['email']
                f1.vehicle_detail = request.session['vehicle_name']
                f1.security_amount = int(10000)
                f1.vehicle_info_id = request.session['vehicle_id']
                f1.amount_exp = request.session['amt']
                f1.invoice = request.session['invoice']
                f1.seller_detail = request.session['seller']
                f1.total = request.session['total']
                f1.cancel_token = str(random.randint(1000000, 100000000)) + str(request.session['email'])
                # email_send(f1.user_email, request.POST['user_password'], verify)
                f1.save()
                update = booking_details(booking_id=f1.booking_id, invoice=str(f1.booking_id) + str(f1.invoice))
                update.save(update_fields=['invoice'])
                request.session['invoice'] = ""
                request.session['vehicle_name'] = ""
                request.session['vehicle_description'] = ""
                request.session['vehicle_id'] = ""
                request.session['start_date'] = ""
                request.session['category'] = ""
                request.session['user_name'] = ""
                request.session['seller'] = ""
                request.session['end_date'] = ""
                request.session['amt'] = ""
                request.session['total'] = ""
                request.session['booking_date'] = ""

                return redirect("/invoice")
            else:
                return redirect("/login")
        return render(request, "confirm_booking.html")
    else:
        auth,message = auth
        if (message=="Not Logged In"):
            return render(request,"login.html",{"pass":True})
        elif(message=="Wrong Level"):
            return render(request,"404.html",{"pass":True})
Example #17
0
def balance(request):

    try:
        auth = au.authorizeuser(request.session['authenticate'],request.session['role_id'],1)
        email = request.session['email']
        

    except:
        return redirect("/login")
    if auth==True:
        try:
            bd=booking_details.objects.get(invoice=request.session['id'])

            if bd.seller_detail==email:
                return_date = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                return_date = dt.datetime.now().strptime(return_date, "%Y-%m-%d %H:%M:%S")

                if request.method == "POST":
                    update = booking_details(booking_id=bd.booking_id, is_active=False, return_date=return_date,is_returned=True,cancel_token="")
                    update.save(update_fields=["is_active", "is_returned", "cancel_token", "return_date"])
                    return redirect("/manager/mybookings")
                excess_amount=bd.extension*4*bd.vehicle_info.vehicle_price
                total_fine = bd.fine_amount + bd.damage_amount + bd.extension*4*bd.vehicle_info.vehicle_price
                security=bd.security_amount


                if total_fine > security:
                    pay=total_fine-security
                    earnings=bd.total + pay
                    update = booking_details(booking_id=bd.booking_id, ext_amount=excess_amount, balance_amount=pay,total_fine=total_fine,earnings=earnings,refunded=True)
                    update.save(update_fields=["ext_amount", "total_fine","balance_amount","earnings","refunded"])
                elif total_fine < security :
                    mgr_pay = security - total_fine
                    earnings = bd.total - mgr_pay
                    update = booking_details(booking_id=bd.booking_id, ext_amount=excess_amount, balance_amount=mgr_pay,total_fine=total_fine,earnings=earnings)
                    update.save(update_fields=["ext_amount", "total_fine","balance_amount","earnings"])

                bd = booking_details.objects.get(invoice=request.session['id'])


                return render (request,"balance.html",{"bd":bd,"ea":excess_amount})
            else:
                return redirect("/error")
        except:
            return  redirect("/error")
    else:
        auth,message = auth
        if (message=="Not Logged In"):
            return render(request,"login.html",{"pass":True,'login':True})
        elif(message=="Wrong Level"):
            return render(request,"404.html",{"pass":True})
def user_index(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],request.session['role_id'],3)
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)
    except:
        return redirect("/login")
    if auth==True:
        return render(request,"user.html",{"su":siteuserdata})
    else:
        auth,message = auth
        if (message=="Not Logged In"):
            return render(request,"login.html",{"pass":True})
        elif(message=="Wrong Level"):
            return render(request,"404.html",{"pass":True})
Example #19
0
def manager_index(request):

    try:
        auth = au.authorizeuser(request.session['authenticate'],request.session['role_id'],1)
        email = request.session['email']
        
    except:
        return redirect("/login")
    if auth==True:
        return render(request,"manager.html")
    else:
        auth,message = auth
        if (message=="Not Logged In"):
            return render(request,"login.html",{"pass":True,'login':True})
        elif(message=="Wrong Level"):
            return render(request,"404.html",{"pass":True})
Example #20
0
def index(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'], 2)

    except:
        return redirect("/login")
    if auth == True:

        return render(request, "superuser.html")
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return redirect("/login")
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
    return render(request, "superuser.html")
Example #21
0
def show_other(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],request.session['role_id'],1)
        email = request.session['email']
    except:
        return redirect("/login")
    if auth==True:
        ccd=VehicleCategories.objects.all()

        ud=VehiclesDetails.objects.filter(role_id=4)
        return render(request, "view_cars.html", {'ud': ud, 'ccd': ccd})
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True,'login':True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
Example #22
0
def my_bookings(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'], 4)
        email = request.session['email']

    except:
        return redirect("/login")
    if auth == True:
        request.session['id'] = ""
        if request.session['role_id'] == 4:
            book_id = []
            bd = booking_details.objects.filter(seller_detail=email)
            curr_date = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            curr_date = dt.datetime.now().strptime(curr_date,
                                                   "%Y-%m-%d %H:%M:%S")
            for i in bd:
                end_date = i.end_date
                end_date = dt.datetime.strptime(end_date, "%Y-%m-%d %H:%M:%S")
                if curr_date > end_date:
                    book_id.extend([i.booking_id])
            if request.method == "POST":
                try:
                    sr = booking_details.objects.filter(
                        invoice__icontains=request.POST['invoice'],
                        seller_detail=email)
                    return render(request, "mybookings.html", {
                        "bd": sr,
                        "book_id": book_id
                    })
                except:
                    pass

            return render(request, "mybookings.html", {
                "bd": bd,
                "book_id": book_id
            })
        else:
            return redirect("/error")
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True, 'login': True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
def queries(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],request.session['role_id'],request.session['role_id'])
        email = request.session['email']
    except:
        return redirect("/login")
    if auth==True:
        if request.session['role_id'] == 1:
            query = contact_us.objects.all()
            return render(request, "Queries.html", {"q": query})
        else:
            query = contact_us.objects.filter(user_email=request.session['email'])
            return render(request, "Queries.html", {"q": query})
    else:
        auth,message = auth
        if (message=="Not Logged In"):
            return render(request,"login.html",{"pass":True})
        elif(message=="Wrong Level"):
            return render(request,"404.html",{"pass":True})
def showdata(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'], 1)
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)
    except:
        return redirect("/login")
    if auth == True:
        email = request.session['email']
        ccd = VehicleCategories.objects.all()
        userdata = VehiclesDetails.objects.filter(u_email=email)
        return render(request, "view_cars.html", {'ud': userdata, 'ccd': ccd})
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
Example #25
0
def showdata(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'], 2)

    except:
        return redirect("/login")
    if auth == True:

        try:
            if request.session["role_id"] == 2:
                vehicle_id = request.GET['id']
                ccd = VehicleCategories.objects.all()
                cd = VehicleCompany.objects.all()
                userdata = VehiclesDetails.objects.filter(
                    vehicle_id_id=vehicle_id)
                return render(request, "view_cars.html", {
                    'ud': userdata,
                    'ccd': ccd,
                    "cd": cd
                })
        except:
            ccd = VehicleCategories.objects.all()
            cd = VehicleCompany.objects.all()
            userdata = VehiclesDetails.objects.all()
            return render(request, "view_cars.html", {
                'ud': userdata,
                'ccd': ccd,
                "cd": cd
            })
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return redirect("/login")
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
    return render(request, "superuser.html")
Example #26
0
def booking(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'],
                                request.session['role_id'])
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)
    except:
        return redirect("/login")
    if auth == True:
        try:
            data = request.GET['id']
            start_date = request.GET['sd']
            end_date = request.GET['ed']
            userdata = VehiclesDetails.objects.get(vehicle_ref_id=data)

            bd = booking_details.objects.all()
            try:
                email = request.session['email']
                siteuserdata = MySiteUser.objects.get(user_email=email)

                if request.method == "POST":
                    userbooking = booking_details.objects.filter(
                        user_detail=email).order_by("-booking_id")[0:1]
                    for i in userbooking:
                        if i.is_returned == False:
                            return render(
                                request, 'bookings.html', {
                                    "ud": userdata,
                                    'su': siteuserdata,
                                    "bd": bd,
                                    "sd": start_date,
                                    "ed": end_date,
                                    "nt": True
                                })

                    type = userdata.vehicle_id_id

                    start_duration = start_date
                    start_du = dt.datetime.strptime(start_duration,
                                                    '%Y-%m-%d %H:%M:%S')
                    # end_duration = end_date +" "+ request.POST['end_time']
                    end_duration = end_date
                    end_du = dt.datetime.strptime(end_duration,
                                                  '%Y-%m-%d %H:%M:%S')
                    duration = end_du - start_du
                    duration = int(duration.total_seconds() / 3600)
                    if duration <= 4:
                        amt = userdata.vehicle_id.vehicle_category_price
                        security = int(10000)
                        total = security + amt
                        request.session['invoice'] = str(
                            random.randint(100000, 10000000)) + str(amt)[1:3]
                        request.session['vehicle_name'] = request.POST[
                            "vehicle_name"]
                        request.session['vehicle_description'] = request.POST[
                            "vehicle_description"]
                        request.session['vehicle_id'] = userdata.vehicle_ref_id
                        request.session['start_date'] = start_date
                        request.session[
                            'category'] = userdata.vehicle_id.vehicle_category_name
                        request.session[
                            'user_name'] = siteuserdata.user_fname + " " + siteuserdata.user_lname
                        request.session['seller'] = userdata.u_email
                        request.session['end_date'] = end_date
                        request.session['amt'] = amt
                        request.session['total'] = total
                        request.session['booking_date'] = dt.datetime.now(
                        ).strftime("%Y-%m-%d %H:%M:%S")

                        return redirect("/confirm_booking")
                        # return render(request, 'bookings.html',
                        # {"ud": userdata, 'su': siteuserdata, "bd": bd, "sd": start_date, "ed": end_date,
                        # "amt": amt,"security":security,"t":total})
                    else:
                        veh_id = userdata.vehicle_ref_id
                        security, amt = price_calc(duration, type, veh_id)
                        total = security + amt

                        request.session['vehicle_name'] = request.POST[
                            "vehicle_name"]
                        request.session['vehicle_description'] = request.POST[
                            "vehicle_description"]
                        request.session['vehicle_id'] = userdata.vehicle_ref_id
                        request.session['start_date'] = start_date
                        request.session[
                            'category'] = userdata.vehicle_id.vehicle_category_name
                        request.session[
                            'user_name'] = siteuserdata.user_fname + " " + siteuserdata.user_lname
                        request.session['seller'] = userdata.u_email
                        request.session['end_date'] = end_date
                        request.session['amt'] = amt
                        request.session['total'] = total
                        request.session['booking_date'] = dt.datetime.now(
                        ).strftime("%Y-%m-%d %H:%M:%S")
                        request.session['invoice'] = str(
                            random.randint(100000, 10000000)) + str(amt)[1:3]

                        return redirect("/confirm_booking")
                        # return render(request, 'bookings.html',
                        # {"ud": userdata, 'su': siteuserdata, "bd": bd, "sd": start_date, "ed": end_date,
                        # "amt":amt,"security":security,"t":total})

                return render(
                    request, 'bookings.html', {
                        "ud": userdata,
                        'su': siteuserdata,
                        "bd": bd,
                        "sd": start_date,
                        "ed": end_date
                    })
            except:

                return redirect("/login")
        except:
            return redirect("/error")
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True, 'login': True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
def chkreturn(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'],
                                request.session['role_id'])
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)

    except:
        return redirect("/login")
    if auth == True:
        id = request.GET['id']
        bd = booking_details.objects.get(invoice=id)
        curr_date = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        curr_date = dt.datetime.now().strptime(curr_date, "%Y-%m-%d %H:%M:%S")
        end_date = bd.end_date
        end_date = dt.datetime.now().strptime(end_date, "%Y-%m-%d %H:%M:%S")
        if request.session['email'] == bd.seller_detail:

            if request.method == "POST":

                if request.POST['documents'] == "no":
                    fine = request.POST['fine']
                    is_fine = True
                else:
                    fine = 0
                    is_fine = False

                if request.POST['damage'] == "damage":
                    if request.POST['covered'] == "notcovered":
                        damage_amount = request.POST['damage_amount']
                    else:
                        damage_amount = 1000
                else:
                    damage_amount = 0

                if request.POST["exceed"] == "1" and curr_date > end_date:
                    duration = float(
                        (curr_date - end_date).total_seconds() / 3600)
                    if duration > 0.5:
                        duration = math.ceil(duration)
                    else:
                        duration = math.floor(duration)
                else:
                    duration = 0

                update = booking_details(booking_id=bd.booking_id,
                                         is_fine=is_fine,
                                         fine_amount=fine,
                                         damage_amount=damage_amount,
                                         extension=duration)
                update.save(update_fields=[
                    "is_fine", "fine_amount", "damage_amount", "extension"
                ])
                request.session['id'] = id
                return redirect("/manager/balance")

            return render(request, "chkreturn.html", {"bd": bd})
        else:
            return redirect("/error")

    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})
Example #28
0
def cancel_booking(request):
    try:
        auth = au.authorizeuser(request.session['authenticate'],
                                request.session['role_id'],
                                request.session['role_id'])
        email = request.session['email']
        siteuserdata = MySiteUser.objects.get(user_email=email)
    except:
        return redirect("/login")
    if auth == True:
        try:
            id = request.GET['id']
            try:
                bd = booking_details.objects.get(cancel_token=id)
            except:
                return redirect("/error")
            if email == bd.user_detail_id:
                cancel_date = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                cancel_date = dt.datetime.strptime(cancel_date,
                                                   '%Y-%m-%d %H:%M:%S')
                start_date = dt.datetime.strptime(bd.start_date,
                                                  '%Y-%m-%d %H:%M:%S')

                if start_date > cancel_date:
                    duration = float(
                        (start_date - cancel_date).total_seconds() / 3600)

                    if duration >= 36:
                        balance = bd.total - 1000
                        request.session["cancel"] = 1000

                    elif duration >= 24:
                        balance = bd.total - 5000
                        request.session["cancel"] = 5000

                    else:
                        balance = bd.total - 10000
                        request.session["cancel"] = 10000

                else:
                    """earning=bd.total
                    update = booking_details(booking_id=bd.booking_id, balance_amount=0, earnings=earning, total_fine=bd.total)
                    update.save(update_fields=['balance_amount', "earnings","total_fine"])"""

                    return redirect("/show_bookings/?id=00")

                bd = booking_details.objects.get(cancel_token=id)
                request.session['duration'] = False
                request.session['date_greater'] = False
                request.session['cancelled'] = False
                if bd.is_active == True:

                    if (request.method == "POST"):

                        request.session['not_cancel'] = False

                        update = booking_details(
                            booking_id=bd.booking_id,
                            total_fine=request.session['cancel'],
                            balance_amount=balance,
                            earnings=request.session['cancel'],
                            is_active=False,
                            cancel_token="",
                            cancellation_time=cancel_date,
                            is_returned=True)
                        update.save(update_fields=[
                            'balance_amount', "total_fine", "earnings",
                            'is_active', 'cancellation_time', 'is_returned',
                            "cancel_token"
                        ])
                        update = booking_details(booking_id=bd.booking_id)

                        return render(request, "cancel_booking.html", {
                            "bd": bd,
                            "cancel": True,
                            "balance": balance
                        })
                    else:
                        return render(request, "cancel_booking.html", {
                            "bd": bd,
                            "not_cancel": True,
                            "balance": balance
                        })

                else:
                    return redirect("/show_bookings")
            else:
                return redirect("/error")

        except:
            return render(request, "cancel_booking.html")
    else:
        auth, message = auth
        if (message == "Not Logged In"):
            return render(request, "login.html", {"pass": True, 'login': True})
        elif (message == "Wrong Level"):
            return render(request, "404.html", {"pass": True})