Exemple #1
0
def cn(request):

    if request.method == 'POST':

        pnr = request.POST['id']
        a = Reservation.objects.filter(pnr=pnr)
        z = Payment.objects.filter(pnr=pnr, cancel='NO')
        for j in z:
            amt = j.amt
            j.cancel = 'YES'
            j.save()

        c = 0
        cls = 'X'

        for i in a:
            if i.status == 'C':
                c = c + i.nos
            cls = i.cls
        a.delete()
        a = Reservation.objects.all()
        f = 0
        for i in a:
            if i.status == 'W' and i.cls == cls:
                if i.nos <= c:
                    c = c - i.nos
                    i.status = 'C'
                    i.save()
                else:
                    f = 1
                    b = Reservation()
                    b.cls = i.cls
                    b.tno = i.tno
                    b.status = "C"
                    b.nos = c
                    b.amt = 1500
                    b.date = i.date
                    b.user = i.user
                    b.pnr = i.pnr
                    b.save()
                    i.nos = i.nos - c
                    i.save()
                    c = 0
                    break
        return HttpResponse(amt)
Exemple #2
0
def book(request):

    if request.method == 'POST':
        nos = int(request.POST['nos'])
        tno = request.POST['tno']
        dt = request.POST['date']
        tn1 = Trains.objects.get(tno=tno)
        cls = request.POST['cls']
        op = request.POST['select']
        tname = request.POST['tname']
        src = request.POST['src']
        des = request.POST['des']
        price = int(request.POST['price'])
        pp = price / nos
        mtd = 'Paytm'
        if op == 'option1':
            crd = request.POST['crd']
            nam = request.POST['nam']
            cvv = request.POST['cvv']
            exp = request.POST['exp']
            mtd = 'Credit/Debit Card'
            if len(crd) != 16 or len(cvv) != 3:
                return render(request, 'features/nopay.html')

        c = 0
        f = 0
        pay = Payment()
        pay.user = request.user
        pay.amt = price
        pay.date = dt
        pay.mtd = mtd
        pay.cancel = 'NO'

        a = Reservation.objects.filter(tno=tno, cls=cls, date=dt)
        c1 = Reservation.objects.all()
        cp = 0
        for i in c1:
            cp = max(cp, int(i.pnr))
        for i in a:
            c = c + i.nos
        if c < 30:
            if nos > (30 - c):
                b = Reservation()
                b.cls = cls
                b.tno = tn1
                b.status = "C"
                b.nos = 30 - c
                b.amt = 1500
                b.date = dt
                b.user = request.user
                b.pnr = cp + 1
                b.src = src
                b.des = des
                b.save()
                e = Reservation()
                e.cls = cls
                e.tno = tn1
                e.status = "W"
                e.nos = nos - (30 - c)
                e.amt = price
                e.date = dt
                e.user = request.user
                e.pnr = cp + 1
                e.src = src
                e.des = des
                e.save()
                f = 1
            else:
                b = Reservation()
                b.cls = cls
                b.tno = tn1
                b.status = "C"
                b.nos = nos
                b.amt = price
                b.date = dt
                b.user = request.user
                b.pnr = cp + 1
                b.src = src
                b.des = des
                b.save()
                f = 1
        else:
            b = Reservation()
            b.cls = cls
            b.tno = tn1
            b.status = "W"
            b.nos = nos
            b.amt = price
            b.date = dt
            b.user = request.user
            b.pnr = cp + 1
            b.save()
            f = 2
        c = 0
        a = Reservation.objects.filter(tno=tno, cls=cls, date=dt)
        for i in a:
            c = c + i.nos

        pay.pnr = cp + 1
        pay.save()
        return render(
            request, "features/final.html", {
                'tname': tname,
                'tno': tno,
                'date': dt,
                'src': src,
                'des': des,
                'cls': cls,
                'pnr': (cp + 1),
                'nos': nos,
                'dt': dt
            })