예제 #1
0
def add_impress(request,firm_id):
    #delete_all()
    firm = Firm.objects.get(id=int(firm_id))
    firm_id = int(firm_id)
    if 'name' in request.session:
        ledger_name = request.session['name']
        del request.session['name']
        return render(request, 'transaction/add_impress.html',
                      {'name': firm.name, 'year': firm.year, 'id': firm.id, 'ledger_name': ledger_name})

    if request.user.is_authenticated():
        if request.method == 'POST':
            ledger = Ledger.objects.filter(firm_id=int(firm_id), name=request.POST['ledger'])[0]
            input_impress = Transaction()
            input_impress.ledger_id = ledger.id
            input_impress.amount = request.POST['amount']
            input_impress.mode = request.POST['mode']
            v_no = request.POST['voucher_no']
            ledgers = Ledger.objects.filter(firm_id=firm_id)
            data = check_voucher_no(v_no, firm_id)
            if data[0]:
                obj = Transaction.objects.filter(voucher__voucher_no=v_no,ledger__firm_id=firm_id)[0]
                return render(request, 'transaction/add_impress.html',
                              {'name': firm.name, 'year': firm.year, 'id': firm.id,
                                'failure': 'True', 'obj': obj,
                               'input_impress':input_impress,'v_no':v_no
                               })
            for ledger in ledgers:
                if ledger.name == request.POST['ledger']:
                    voucher_new = Voucher()
                    voucher_new.voucher_no = request.POST['voucher_no']
                    voucher_new.save()
                    impress = Transaction()
                    impress.ledger_id = ledger.pk
                    impress.amount = request.POST['amount']
                    impress.mode = request.POST['mode']
                    impress.description = request.POST['description']
                    impress.voucher_id = voucher_new.pk
                    impress.type = 'Credit'
                    impress.voucher_type = 'Impress'
                    impress.save()
                    cash = Transaction()
                    CASH = Ledger.objects.filter(firm_id=int(firm_id), name='Cash')[0]
                    cash.ledger_id = CASH.id
                    cash.voucher_type = 'Journal'
                    cash.description = impress.description
                    cash.amount = impress.amount
                    cash.mode = impress.mode
                    cash.type = 'Debit'
                    cash.save()
                    message = "Imprest Data has been saved !"
                    impresses = Transaction.objects.filter(ledger__firm_id=int(firm_id),voucher_type='Impress')
                    return render(request, 'transaction/impress_home.html', {'impresses':impresses,'message': message,'name':firm.name,'year':firm.year,'id':firm.id})

            return render(request, 'transaction/impress_home.html',{'name':firm.name,'year':firm.year,'id':firm.id})
        else:
            return render(request,'transaction/add_impress.html',{'name':firm.name,'year':firm.year,'id':firm.id})
    else:
        return redirect('/login')
예제 #2
0
def add_firm(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            print('INside POSt')
            name = request.POST['firm_name']
            year = request.POST['firm_year']
            password = request.POST['pass']
            password_1 = request.POST['pass_1']
            if password == password_1:
                firm = Firm()
                firm.name = name
                firm.year = year
                firm.password = password
                firm.save()
                print('Firm Data saved')
                ledger = Ledger()
                ledger.name = 'Cash'
                ledger.address = 'none'
                ledger.mobile_no = 'none'
                ledger.pan_no = 'none'
                ledger.type = 'Personal'
                ledger.firm_id = firm.id
                ledger.save()
                if request.POST['cash'] != "True":
                    amount = request.POST['balance']
                    type = request.POST['type']
                    entry = Transaction()
                    entry.ledger_id = ledger.id
                    entry.description = "opening balance entered"
                    if type == 'D':
                        entry.type = 'Debit'
                    else:
                        entry.type = 'Credit'
                    voucher = Voucher()
                    voucher.voucher_no = -1
                    voucher.save()
                    entry.voucher_id = voucher.id
                    entry.voucher_type = 'Opening'
                    entry.amount = amount
                    entry.save()
                    return redirect('/firm/firm_login')
                else:
                    print('no opening balance')
                return redirect('/firm/firm_login')
            else:
                return render(request, 'firm/add_firm.html',
                              {'message': 'Your passwords do not match !'})
        else:
            return render(request, 'firm/add_firm.html')
    else:
        return redirect('/login')
예제 #3
0
def transaction_add(request,firm_id,ledger_id):
    if request.method == 'POST':
        amount = request.POST['amount']
        v_no = request.POST['voucher']
        description = request.POST['description']
        type = request.POST['type']
        date = request.POST['date']
        voucher = Transaction.objects.filter(ledger__firm__id=int(firm_id),voucher__voucher_no=int(v_no))
        if len(voucher) > 0 :
            amount = 0.0
            type = 'Credit'
            firm = Firm.objects.get(id=int(firm_id))
            firm_id = int(firm_id)
            ledger = Ledger.objects.get(id=int(ledger_id))
            transactions = Transaction.objects.filter(ledger__firm_id=firm_id, ledger__name=ledger.name)
            transactions = sorted(transactions, key=lambda x: x.created,reverse=True)
            for transaction in transactions:
                if transaction.type == 'Credit':
                    amount += transaction.amount
                else:
                    amount -= transaction.amount
            if amount < 0.0:
                amount = float(0 - amount)
                type = 'Debit'

            return render(request, 'transaction/ledger_details.html', {'transactions': transactions,
                                                                       'name': firm.name, 'year': firm.year,'id':firm.id,
                                                                       'error':'Voucher number already exists',
                                                                       'ledger': ledger, 'amount': amount, 'type': type
                                                                       })
        ledger = Ledger.objects.get(id=int(ledger_id))
        transaction = Transaction()
        transaction.ledger_id = ledger.id
        voucher = Voucher()
        voucher.voucher_no = v_no
        voucher.save()
        transaction.voucher_id = voucher.id
        transaction.amount = float(amount)
        transaction.voucher_type = type
        transaction.description = description
        transaction.save()
        if type=='Impress' or type == 'Expense':
            transaction.type = 'Credit'
            cash_ledger = Ledger.objects.filter(name="Cash",firm_id=int(firm_id))[0]
            cash = Transaction()
            voucher = Voucher()
            voucher.voucher_no = -1
            voucher.save()
            cash.voucher_id = voucher.id
            cash.ledger_id = cash_ledger.id
            cash.amount = float(amount)
            cash.type = 'Debit'
            cash.save()
        else:
            transaction.type = 'Debit'
            cash_ledger = Ledger.objects.filter(name="Cash", firm_id=int(firm_id))[0]
            cash = Transaction()
            voucher = Voucher()
            voucher.voucher_no = -1
            voucher.save()
            cash.voucher_id = voucher.id
            cash.ledger_id = cash_ledger.id
            cash.amount = float(amount)
            cash.type = 'Credit'
            cash.save()
        if date != '':
            transaction.created = date
        transaction.save()
        amount = 0.0
        type = 'Credit'
        firm = Firm.objects.get(id=int(firm_id))
        firm_id = int(firm_id)
        ledger = Ledger.objects.get(id=int(ledger_id))
        transactions = Transaction.objects.filter(ledger__firm__id=firm_id, ledger__name=ledger.name)
        transactions = sorted(transactions, key=lambda x: x.created,reverse=True)
        for transaction in transactions:
            if transaction.type == 'Credit':
                amount += transaction.amount
            else:
                amount -= transaction.amount
        if amount < 0.0:
            amount = float(0 - amount)
            type = 'Debit'

        return render(request, 'transaction/ledger_details.html', {'transactions': transactions,
                                                                   'name': firm.name, 'year': firm.year, 'id': firm.id,
                                                                   'ledger': ledger, 'amount': amount, 'type': type,
                                                                   'error':"Success"
                                                                   })
    else:
        url = "/home/" + str(firm_id) + "/ledger_home"
        return redirect(url)
예제 #4
0
def add_journal(request,firm_id):
    if request.method == 'POST':
        ledger_main = request.POST['ledger_main']
        try:
            ledger = Ledger.objects.filter(firm_id=int(firm_id),name=ledger_main)[0]
        except Exception as e:
            print(e)
            return render(request, 'transaction/add_journal.html',
                          {'id': int(firm_id), 'message': 'Main Ledger does not exist'})

        description_main = request.POST['description_main']
        type_main  = request.POST['type_main']

        names = request.POST.getlist('name')
        vouchers = request.POST.getlist('voucher')
        dates = request.POST.getlist('date')
        del vouchers[len(names)-1]
        amounts = request.POST.getlist('amount')
        descriptions = request.POST.getlist('description')
        transactions = Transaction.objects.filter(ledger__firm__id=int(firm_id),voucher__voucher_no__in=vouchers)
        if len(transactions) > 0 :
            return render(request, 'transaction/add_journal.html',
                          {'id': int(firm_id), 'message': 'A Voucher Number already exists'})

        for i in range(len(names)-1):  #check if all ledgers are valid
            try:
                ledger = Ledger.objects.filter(firm_id=int(firm_id),name=names[i])[0]
            except Exception as e:
                print(e)
                return render(request,'transaction/add_journal.html', {'id': int(firm_id),'message':'Ledger does not exist'})

        print('ready to save journal entry')
        amount = 0.0
        type = 'Credit'
        if type_main != 'Debit' :
            type = 'Debit'
        for i in range(len(vouchers)):
            amount += float(amounts[i])
            ledger = Ledger.objects.filter(firm_id=int(firm_id),name=names[i])[0]
            transaction = Transaction()
            transaction.ledger_id = ledger.id
            transaction.type = type
            transaction.description = descriptions[i]
            voucher = Voucher()
            voucher.voucher_no = vouchers[i]
            voucher.save()
            transaction.voucher_id = voucher.id
            transaction.amount = amounts[i]
            transaction.save()
            if dates[i] != '':
                transaction.created = dates[i]
            transaction.save()
        ledger = Ledger.objects.filter(firm_id=int(firm_id), name=ledger_main)[0]
        transaction = Transaction()
        transaction.ledger_id = ledger.id
        transaction.type = type_main
        transaction.description = description_main
        voucher = Voucher()
        voucher.voucher_no = -1
        voucher.save()
        transaction.voucher_id = voucher.id
        transaction.amount = amount
        transaction.save()
        return render(request, 'transaction/add_journal.html', {'id': int(firm_id), 'message': 'Success. Transactions have been saved'})
    else:
        if request.user.is_authenticated():
            return render(request,'transaction/add_journal.html',{'id':int(firm_id)})
        else:
            return redirect('/login')