def client_savings_application_view(request, client_id): client = get_object_or_404(Client, id=client_id) form = SavingsAccountForm() if SavingsAccount.objects.filter(client=client).exists(): return HttpResponseRedirect( reverse(request, "savings:clientsavingsaccount", kwargs={'client_id': client.id})) if request.method == 'POST': form = SavingsAccountForm(request.POST, instance=client) if form.is_valid(): obj_sav_acc = form.save(commit=False) obj_sav_acc.status = "Applied" obj_sav_acc.created_by = request.user obj_sav_acc.client = client obj_sav_acc.save() return HttpResponseRedirect( reverse(request, "savings:clientsavingsaccount", kwargs={'client_id': client.id})) else: return JsonResponse({"error": True, "errors": form.errors}) else: account_no = unique_random_number(SavingsAccount) return render(request, "client/savings/application.html", { 'client': client, 'account_no': account_no })
def group_savings_application_view(request, group_id): group = get_object_or_404(Group, id=group_id) form = SavingsAccountForm() if SavingsAccount.objects.filter(group=group).exists(): return HttpResponseRedirect( reverse("savings:groupsavingsaccount", kwargs={'group_id': group.id})) if request.method == 'POST': form = SavingsAccountForm(request.POST) if form.is_valid(): obj_sav_acc = form.save(commit=False) obj_sav_acc.status = "Applied" obj_sav_acc.created_by = request.user obj_sav_acc.group = group obj_sav_acc.save() return HttpResponseRedirect( reverse("savings:groupsavingsaccount", kwargs={'group_id': group.id})) else: return JsonResponse({"error": True, "errors": form.errors}) else: account_no = unique_random_number(SavingsAccount) return render(request, "group/savings/application.html", { 'group': group, 'account_no': account_no })
def get_context_data(self, **kwargs): context = super(GroupLoanApplicationView, self).get_context_data(**kwargs) context["account_no"] = unique_random_number(LoanAccount) context["loan_repayment_every"] = LoanRepaymentEvery.objects.all() context["group"] = self.group return context
def client_loan_application(request, client_id): form = LoanAccountForm() client = get_object_or_404(Client, id=client_id) group = Group.objects.filter(clients__id__in=client_id).first() account_no = unique_random_number(LoanAccount) loan_pay = LoanRepaymentEvery.objects.all() if request.method == 'POST': form = LoanAccountForm(request.POST) if form.is_valid(): loan_account = form.save(commit=False) loan_account.status = "Applied" loan_account.created_by = User.objects.get(username=request.user) loan_account.client = client interest_charged = d( (d(loan_account.loan_amount) * (d(loan_account.annual_interest_rate) / 12)) / 100) loan_account.principle_repayment = d( int(loan_account.loan_repayment_every) * (d(loan_account.loan_amount) / d(loan_account.loan_repayment_period))) loan_account.interest_charged = d( int(loan_account.loan_repayment_every) * d(interest_charged)) loan_account.loan_repayment_amount = d( d(loan_account.principle_repayment) + d(loan_account.interest_charged)) loan_account.total_loan_balance = d(d(loan_account.loan_amount)) if group: loan_account.group = group loan_account.save() if client.email and client.email.strip(): send_email_template( subject= "Your application for the Personal Loan (ID: %s) has been Received." % loan_account.account_no, template_name="emails/client/loan_applied.html", receipient=client.email, ctx={ "client": client, "loan_account": loan_account, "link_prefix": settings.SITE_URL, }, ) return JsonResponse({ "error": False, "loanaccount_id": loan_account.id }) else: return JsonResponse({"error": True, "message": form.errors}) context = { 'form': form, 'client': client, 'account_no': account_no, 'loan_repayment_every': loan_pay } return render(request, "client/loan/application.html", context)
def client_loan_application(request, client_id): form = LoanAccountForm() client = get_object_or_404(Client, id=client_id) group = Group.objects.filter(clients__id__in=client_id).first() account_no = unique_random_number(LoanAccount) loan_pay = LoanRepaymentEvery.objects.all() if request.method == 'POST': form = LoanAccountForm(request.POST) if form.is_valid(): loan_account = form.save(commit=False) loan_account.status = "Applied" loan_account.created_by = User.objects.get(username=request.user) loan_account.client = client interest_charged = d( ( d(loan_account.loan_amount) * ( d(loan_account.annual_interest_rate) / 12) ) / 100 ) loan_account.principle_repayment = d( int(loan_account.loan_repayment_every) * ( d(loan_account.loan_amount) / d( loan_account.loan_repayment_period) ) ) loan_account.interest_charged = d( int(loan_account.loan_repayment_every) * d(interest_charged)) loan_account.loan_repayment_amount = d( d(loan_account.principle_repayment) + d( loan_account.interest_charged) ) loan_account.total_loan_balance = d(d(loan_account.loan_amount)) if group: loan_account.group = group loan_account.save() if client.email and client.email.strip(): send_email_template( subject="Your application for the Personal Loan (ID: %s) has been Received." % loan_account.account_no, template_name="emails/client/loan_applied.html", receipient=client.email, ctx={ "client": client, "loan_account": loan_account, "link_prefix": settings.SITE_URL, }, ) return JsonResponse({"error": False, "loanaccount_id": loan_account.id}) else: return JsonResponse({"error": True, "message": form.errors}) context = { 'form': form, 'client': client, 'account_no': account_no, 'loan_repayment_every': loan_pay } return render(request, "client/loan/application.html", context)
def group_savings_application_view(request, group_id): group = get_object_or_404(Group, id=group_id) form = SavingsAccountForm() if SavingsAccount.objects.filter(group=group).exists(): return HttpResponseRedirect(reverse("savings:groupsavingsaccount", kwargs={'group_id': group.id})) if request.method == 'POST': form = SavingsAccountForm(request.POST) if form.is_valid(): obj_sav_acc = form.save(commit=False) obj_sav_acc.status = "Applied" obj_sav_acc.created_by = request.user obj_sav_acc.group = group obj_sav_acc.save() return HttpResponseRedirect(reverse("savings:groupsavingsaccount", kwargs={'group_id': group.id})) else: return JsonResponse({"error": True, "errors": form.errors}) else: account_no = unique_random_number(SavingsAccount) return render(request, "group/savings/application.html", {'group': group, 'account_no': account_no})
def client_savings_application_view(request, client_id): client = get_object_or_404(Client, id=client_id) form = SavingsAccountForm() if SavingsAccount.objects.filter(client=client).exists(): return HttpResponseRedirect(reverse(request, "savings:clientsavingsaccount", kwargs={'client_id': client.id})) if request.method == 'POST': form = SavingsAccountForm(request.POST, instance=client) if form.is_valid(): obj_sav_acc = form.save(commit=False) obj_sav_acc.status = "Applied" obj_sav_acc.created_by = request.user obj_sav_acc.client = client obj_sav_acc.save() return HttpResponseRedirect(reverse(request, "savings:clientsavingsaccount", kwargs={'client_id': client.id})) else: return JsonResponse({"error": True, "errors": form.errors}) else: account_no = unique_random_number(SavingsAccount) return render(request, "client/savings/application.html", {'client': client, 'account_no': account_no})
def group_loan_application(request, group_id): group = get_object_or_404(Group, id=group_id) account_no = unique_random_number(LoanAccount) loan_repayment_every = LoanRepaymentEvery.objects.all() form = LoanAccountForm() if request.method == 'POST': form = LoanAccountForm(request.POST) if form.is_valid(): loan_account = form.save(commit=False) if len(group.clients.all()): loan_account.status = "Applied" loan_account.created_by = User.objects.get( username=request.user) loan_account.group = group interest_charged = d( (d(loan_account.loan_amount) * (d(loan_account.annual_interest_rate) / 12)) / 100) loan_account.principle_repayment = d( int(loan_account.loan_repayment_every) * (d(loan_account.loan_amount) / d(loan_account.loan_repayment_period))) loan_account.interest_charged = d( int(loan_account.loan_repayment_every) * d(interest_charged)) loan_account.loan_repayment_amount = d( d(loan_account.principle_repayment) + d(loan_account.interest_charged)) loan_account.total_loan_balance = d(d( loan_account.loan_amount)) loan_account.save() loan_amount = (loan_account.loan_amount) / \ group.clients.all().count() for client in group.clients.all(): if client.email and client.email.strip(): send_email_template( subject= "Group Loan (ID: %s) application has been Received." % loan_account.account_no, template_name="emails/group/loan_applied.html", receipient=client.email, ctx={ "client": client, "loan_account": loan_account, "link_prefix": settings.SITE_URL, }, ) group_member = GroupMemberLoanAccount.objects.create( account_no=loan_account.account_no, client=client, loan_amount=loan_amount, group_loan_account=loan_account, loan_repayment_period=loan_account. loan_repayment_period, loan_repayment_every=loan_account.loan_repayment_every, total_loan_balance=d(loan_amount), status=loan_account.status, annual_interest_rate=loan_account.annual_interest_rate, interest_type=loan_account.interest_type) interest_charged = d( (d(group_member.loan_amount) * (d(loan_account.annual_interest_rate) / 12)) / 100) group_member.principle_repayment = d( int(group_member.loan_repayment_every) * (d(group_member.loan_amount) / d(group_member.loan_repayment_period))) group_member.interest_charged = d( int(group_member.loan_repayment_every) * d(interest_charged)) group_member.loan_repayment_amount = d( d(group_member.principle_repayment) + d(group_member.interest_charged)) group_member.save() return JsonResponse({ "error": False, "loanaccount_id": loan_account.id }) else: return JsonResponse({ "error": True, "error_message": "Group does not contains any members." }) else: return JsonResponse({"error": True, "message": form.errors}) context = { 'form': form, 'group': group, 'account_no': account_no, 'loan_repayment_every': loan_repayment_every } return render(request, 'group/loan/application.html', context)
def get_context_data(self, **kwargs): context = super(ClientSavingsApplicationView, self).get_context_data(**kwargs) context["client"] = self.client context["account_no"] = unique_random_number(SavingsAccount) return context
def get_context_data(self, **kwargs): context = super(GroupSavingsApplicationView, self).get_context_data(**kwargs) context["group"] = self.group context["account_no"] = unique_random_number(SavingsAccount) return context
def group_loan_application(request, group_id): group = get_object_or_404(Group, id=group_id) account_no = unique_random_number(LoanAccount) loan_repayment_every = LoanRepaymentEvery.objects.all() form = LoanAccountForm() if request.method == 'POST': form = LoanAccountForm(request.POST) if form.is_valid(): loan_account = form.save(commit=False) if len(group.clients.all()): loan_account.status = "Applied" loan_account.created_by = User.objects.get(username=request.user) loan_account.group = group interest_charged = d( ( d(loan_account.loan_amount) * ( d(loan_account.annual_interest_rate) / 12) ) / 100 ) loan_account.principle_repayment = d( int(loan_account.loan_repayment_every) * ( d(loan_account.loan_amount) / d( loan_account.loan_repayment_period) ) ) loan_account.interest_charged = d( int(loan_account.loan_repayment_every) * d(interest_charged)) loan_account.loan_repayment_amount = d( d(loan_account.principle_repayment) + d( loan_account.interest_charged) ) loan_account.total_loan_balance = d(d(loan_account.loan_amount)) loan_account.save() loan_amount = (loan_account.loan_amount) / group.clients.all().count() for client in group.clients.all(): if client.email and client.email.strip(): send_email_template( subject="Group Loan (ID: %s) application has been Received." % loan_account.account_no, template_name="emails/group/loan_applied.html", receipient=client.email, ctx={ "client": client, "loan_account": loan_account, "link_prefix": settings.SITE_URL, }, ) group_member = GroupMemberLoanAccount.objects.create( account_no=loan_account.account_no, client=client, loan_amount=loan_amount, group_loan_account=loan_account, loan_repayment_period=loan_account.loan_repayment_period, loan_repayment_every=loan_account.loan_repayment_every, total_loan_balance=d(loan_amount), status=loan_account.status, annual_interest_rate=loan_account.annual_interest_rate, interest_type=loan_account.interest_type ) interest_charged = d( ( d(group_member.loan_amount) * ( d(loan_account.annual_interest_rate) / 12) ) / 100 ) group_member.principle_repayment = d( int(group_member.loan_repayment_every) * ( d(group_member.loan_amount) / d( group_member.loan_repayment_period) ) ) group_member.interest_charged = d( int(group_member.loan_repayment_every) * d(interest_charged)) group_member.loan_repayment_amount = d( d(group_member.principle_repayment) + d( group_member.interest_charged) ) group_member.save() return JsonResponse({"error": False, "loanaccount_id": loan_account.id}) else: return JsonResponse({"error": True, "error_message": "Group does not contains any members."}) else: return JsonResponse({"error": True, "message": form.errors}) context = { 'form': form, 'group': group, 'account_no': account_no, 'loan_repayment_every': loan_repayment_every } return render(request, 'group/loan/application.html', context)