Ejemplo n.º 1
0
def add_acc_validity_date(request):
    if request.user.is_authenticated():
        json_obj = json.loads(request.body)
        start_year = json_obj['start_year']
        accountingyears = AccountingYear.objects.filter(user__id=request.user.id)
        for i in accountingyears:
            if i.start_date.year == start_year:
                return HttpResponse(json.dumps({'validation':"This year for Financial transactions is already used by you...Please select another year..","status":False}), content_type="application/json")
        end_year = start_year + 1
        start_date = datetime.datetime(start_year, 04, 01, 00, 00, 00)
        end_date = datetime.datetime(end_year, 03, 31, 23, 59, 59)
        user_obj = User.objects.get(id=request.user.id)
        accountingyear_obj = AccountingYear(start_date=start_date,end_date=end_date,duration=1,user=user_obj)
        accountingyear_obj.save()
        return HttpResponse(json.dumps({'validation':"New Financial Year created for your transactions...","redirecturl":"#/myAccMaster","status":True}), content_type="application/json")
    else:
        return HttpResponse(json.dumps({"validation":"You are not logged in yet.Please login to continue."}), content_type="application/json")
Ejemplo n.º 2
0
def transaction_for_account(request):
    if request.user.is_authenticated():
        json_obj = json.loads(request.body)
        data = json_obj['data']
        Acc_list = data.get("Acc_list")
        transaction_date = data.get("transaction_date")
        transactiontype = data.get("transactiontype")
        transactiontype_obj = TransactionType(optionType=transactiontype)
        transactiontype_obj.save()
        user_obj = User.objects.get(id=request.user.id)
        transaction_date = datetime.datetime.fromtimestamp(transaction_date/1000)
        description = data.get("description")
        try:
            accountingyear_obj = AccountingYear.objects.get(start_date__lte=transaction_date,end_date__gte=transaction_date,user__id=request.user.id)
        except AccountingYear.DoesNotExist:
            if transaction_date <= datetime.datetime(transaction_date.year, 03, 31, 23, 59, 59):
                start_date = datetime.datetime(transaction_date.year-1, 04, 01, 00, 00, 00)
                end_date = datetime.datetime(transaction_date.year, 03, 31, 23, 59, 59)
                user_obj = User.objects.get(id=request.user.id)
                accountingyear_obj = AccountingYear(start_date=start_date,end_date=end_date,duration=1,user=user_obj)
                accountingyear_obj.save()
            else:
                year = int(transaction_date.year)
                start_date = datetime.datetime(transaction_date.year, 04, 01, 00, 00, 00)
                end_date = datetime.datetime(transaction_date.year+1, 03, 31, 23, 59, 59)
                user_obj = User.objects.get(id=request.user.id)
                accountingyear_obj = AccountingYear(start_date=start_date,end_date=end_date,duration=1,user=user_obj)
                accountingyear_obj.save()
        transaction_obj = Transaction(transaction_date=transaction_date,description=description,transactiontype=transactiontype_obj,user=user_obj)
        transaction_obj.save()
        accountingyear_obj.transaction.add(transaction_obj)
        accountingyear_obj.save()
        for i in Acc_list:
            amount = i['amount']
            account = i['account']
            account_id = account.get("id")
            is_debit = i['is_debit']
            print is_debit.capitalize()
            if is_debit == "D":
                is_debit = True
            else:
                is_debit = False
            account_obj = Account.objects.get(id=account_id)
            print account_obj
            transactionrecord_queries = TransactionRecord(amount=amount,is_debit=is_debit,account=account_obj)
            transactionrecord_queries.save()
            transaction_obj.transaction_record.add(transactionrecord_queries)
            transaction_obj.save()
        print "Transaction saved Successfully..."
        return HttpResponse(json.dumps({"validation":"Transaction Saved Successfully","status":True}), content_type="application/json")
Ejemplo n.º 3
0
def add_acc_validity_date(request):
    if request.user.is_authenticated():
        json_obj = json.loads(request.body)
        start_year = json_obj['start_year']
        accountingyears = AccountingYear.objects.filter(
            user__id=request.user.id)
        for i in accountingyears:
            if i.start_date.year == start_year:
                return HttpResponse(json.dumps({
                    'validation':
                    "This year for Financial transactions is already used by you...Please select another year..",
                    "status": False
                }),
                                    content_type="application/json")
        end_year = start_year + 1
        start_date = datetime.datetime(start_year, 04, 01, 00, 00, 00)
        end_date = datetime.datetime(end_year, 03, 31, 23, 59, 59)
        user_obj = User.objects.get(id=request.user.id)
        accountingyear_obj = AccountingYear(start_date=start_date,
                                            end_date=end_date,
                                            duration=1,
                                            user=user_obj)
        accountingyear_obj.save()
        return HttpResponse(json.dumps({
            'validation':
            "New Financial Year created for your transactions...",
            "redirecturl": "#/myAccMaster",
            "status": True
        }),
                            content_type="application/json")
    else:
        return HttpResponse(json.dumps({
            "validation":
            "You are not logged in yet.Please login to continue."
        }),
                            content_type="application/json")
Ejemplo n.º 4
0
def transaction_for_account(request):
    if request.user.is_authenticated():
        json_obj = json.loads(request.body)
        data = json_obj['data']
        Acc_list = data.get("Acc_list")
        transaction_date = data.get("transaction_date")
        transactiontype = data.get("transactiontype")
        transactiontype_obj = TransactionType(optionType=transactiontype)
        transactiontype_obj.save()
        user_obj = User.objects.get(id=request.user.id)
        transaction_date = datetime.datetime.fromtimestamp(transaction_date /
                                                           1000)
        description = data.get("description")
        try:
            accountingyear_obj = AccountingYear.objects.get(
                start_date__lte=transaction_date,
                end_date__gte=transaction_date,
                user__id=request.user.id)
        except AccountingYear.DoesNotExist:
            if transaction_date <= datetime.datetime(transaction_date.year, 03,
                                                     31, 23, 59, 59):
                start_date = datetime.datetime(transaction_date.year - 1, 04,
                                               01, 00, 00, 00)
                end_date = datetime.datetime(transaction_date.year, 03, 31, 23,
                                             59, 59)
                user_obj = User.objects.get(id=request.user.id)
                accountingyear_obj = AccountingYear(start_date=start_date,
                                                    end_date=end_date,
                                                    duration=1,
                                                    user=user_obj)
                accountingyear_obj.save()
            else:
                year = int(transaction_date.year)
                start_date = datetime.datetime(transaction_date.year, 04, 01,
                                               00, 00, 00)
                end_date = datetime.datetime(transaction_date.year + 1, 03, 31,
                                             23, 59, 59)
                user_obj = User.objects.get(id=request.user.id)
                accountingyear_obj = AccountingYear(start_date=start_date,
                                                    end_date=end_date,
                                                    duration=1,
                                                    user=user_obj)
                accountingyear_obj.save()
        transaction_obj = Transaction(transaction_date=transaction_date,
                                      description=description,
                                      transactiontype=transactiontype_obj,
                                      user=user_obj)
        transaction_obj.save()
        accountingyear_obj.transaction.add(transaction_obj)
        accountingyear_obj.save()
        for i in Acc_list:
            amount = i['amount']
            account = i['account']
            account_id = account.get("id")
            is_debit = i['is_debit']
            print is_debit.capitalize()
            if is_debit == "D":
                is_debit = True
            else:
                is_debit = False
            account_obj = Account.objects.get(id=account_id)
            print account_obj
            transactionrecord_queries = TransactionRecord(amount=amount,
                                                          is_debit=is_debit,
                                                          account=account_obj)
            transactionrecord_queries.save()
            transaction_obj.transaction_record.add(transactionrecord_queries)
            transaction_obj.save()
        print "Transaction saved Successfully..."
        return HttpResponse(json.dumps({
            "validation": "Transaction Saved Successfully",
            "status": True
        }),
                            content_type="application/json")