Exemplo n.º 1
0
def paymentConfirm(request, id):
    if request.user.is_staff or request.user.is_superuser:
        try: 
            tagihan = Tagihan.objects.get(pk=id, status=False)
        except:
            return notFound(request)
        custommer = User.objects.get(username=tagihan.custommer)
        tarif = Tarif.objects.get(pk=custommer.id)
        new = PayMent()
        new.tagihan = tagihan
        new.custommer = custommer
        new.month = tagihan.month
        new.biaya_admin = 5000
        new.sumPayment = (int(tagihan.sum_meter) * int(tarif.tarif)) + new.biaya_admin
        if request.method == "POST":
            tagihan.status = True
            tagihan.save()
            new.save()
            messages.success(request, 'Data Submited')
            return redirect('staff:paymentlist')
        return render(request, 'staff/payment/confirm.html', {
            'tagihan': tagihan,
            'new': new,
            'tarif': tarif
        })
    else:
        return dont_have_acces(request)
Exemplo n.º 2
0
def paymentlist(request):
    if request.user.is_staff or request.user.is_superuser:
        data = PayMent.objects.all()
        page = Paginator(data, 50)
        pageNum = request.GET.get('page')
        data_result = page.get_page(pageNum)
        return render(request, 'staff/payment/list.html', {'data': data_result})
    else:
        return dont_have_acces(request)
Exemplo n.º 3
0
def add_uses_id(request):
    if request.user.is_staff or request.user.is_superuser:
        if request.method == 'POST':
            try:
                user = User.objects.get(username=request.POST['user'])
                return HttpResponseRedirect(f'../add/{user}/')
            except (KeyError, User.DoesNotExist):
                messages.error(request, 'custommer not found')
            
        return render(request, 'staff/power-used/add-uses-id.html')
    else:
        return dont_have_acces(request)
Exemplo n.º 4
0
def autoAddBill(request):
    if request.user.is_staff or request.user.is_superuser:
        uses = Uses.objects.all()
        tagihan = Tagihan.objects.all()
        for i in uses:
            try:
                tagihan_item = Tagihan.objects.get(uses=i.id)
            except:
                new = Tagihan()
                new.custommer = i.custommer
                new.uses = i
                new.month = i.month
                new.year = i.year
                new.sum_meter = int(i.meter_end) - int(i.meter_start)
                new.save()
        tagihan = Tagihan.objects.filter(status=False)
        page = Paginator(tagihan, 50)
        pageNum = request.GET.get('page')
        data = page.get_page(pageNum)
        return render(request, 'staff/bill/list.html', {'tagihan': data})
    else:
        return dont_have_acces(request)
Exemplo n.º 5
0
def editPowerUsed(request, id):
    if request.user.is_staff or request.user.is_superuser:
        month = Months.objects.all()
        try:
            data = Uses.objects.get(pk=id)
        except:
            return notFound(request)
        user = User.objects.get(username=data.custommer)
        if request.method == "POST":
            data.month = Months.objects.get(pk=request.POST['month'])
            data.year = request.POST['year']
            data.meter_start = request.POST['meter_start']
            data.meter_end = request.POST['meter_end']
            data.save()
            messages.success(request, 'Data Updated')
            return redirect('staff:powerUsedList')

        return render(request, 'staff/power-used/edit.html', {
            'data': data,
            'month': month,
        })
    else:
        return dont_have_acces(request)
Exemplo n.º 6
0
def addUses(request, username):
    if request.user.is_staff or request.user.is_superuser:
        try:
            user = User.objects.get(username=username)
        except:
            messages.error(request, 'custemmer not found')
            return redirect('staff:add_uses_id')
        if request.method == 'POST':
            form = UsesForm(request.POST)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.custommer = user
                instance.save()
                messages.success(request, 'Data Saved')
                return redirect('staff:powerUsedList')
        else:
            form = UsesForm()
        return render(request, 'staff/power-used/add-uses.html', {
            'user': user,
            'form': form,
        })
    else:
        return dont_have_acces(request)
Exemplo n.º 7
0
def index(request):
    if request.user.is_staff or request.user.is_superuser:
        return render(request, 'staff/index.html')
    else:
        return dont_have_acces(request)