Пример #1
0
def change_loan_account_status(request, pk):
    # if request.method == 'POST':
        loan_object = get_object_or_404(LoanAccount, id=pk)
        if loan_object:
            branch_id = loan_object.group.branch.id
        elif loan_object.client:
            branch_id = loan_object.client.branch.id
        else:
            branch_id = None
        if branch_id:
            if (request.user.is_admin or
                (request.user.has_perm("branch_manager") and
                 request.user.branch.id == branch_id)):
                status = request.GET.get("status")
                if status in ['Closed', 'Withdrawn', 'Rejected', 'Approved']:
                    loan_object.status = request.GET.get("status")
                    loan_object.approved_date = datetime.datetime.now()
                    loan_object.save()
                    if loan_object.client:
                        if loan_object.status == 'Approved':
                            if loan_object.client.email and loan_object.client.email.strip():
                                send_email_template(
                                    subject="Your application for the Personal Loan (ID: %s) has been Approved." % loan_object.account_no,
                                    template_name="emails/client/loan_approved.html",
                                    receipient=loan_object.client.email,
                                    ctx={
                                        "client": loan_object.client,
                                        "loan_account": loan_object,
                                        "link_prefix": settings.SITE_URL,
                                    },
                                )

                    elif loan_object.group:
                        group_member_loans = GroupMemberLoanAccount.objects.filter(group_loan_account=loan_object)
                        group_member_loans.update(status=loan_object.status)
                        group_member_loans.update(loan_issued_date=loan_object.loan_issued_date)
                        group_member_loans.update(interest_type=loan_object.interest_type)
                        for client in loan_object.group.clients.all():
                            if client.email and client.email.strip():
                                send_email_template(
                                    subject="Group Loan (ID: %s) application has been Approved."
                                            % loan_object.account_no,
                                    template_name="emails/group/loan_approved.html",
                                    receipient=client.email,
                                    ctx={
                                        "client": client,
                                        "loan_account": loan_object,
                                        "link_prefix": settings.SITE_URL,
                                    },
                                )
                    data = {"error": False}
                else:
                    data = {"error": True, "error_message": "Status is not in available choices"}
            else:
                data = {"error": True, "error_message": "You don't have permission to change the status."}
        else:
            data = {"error": True, "error_message": "Branch Id not Found"}

        data["success_url"] = reverse('loans:clientloanaccount', kwargs={"pk": loan_object.id})
        return JsonResponse(data)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
    def save(self, *args, **kwargs):
        company_invitation = super(CompanyInvitationForm, self).save(commit=False)
        company_invitation.inviter = self.inviter
        company_invitation.save()

        send_email_template(
            subject=_('Company Invitation, SquareBalloon'),
            template='companies/email/company_invitation.html',
            recipient=[company_invitation.invitee_email,],
            data={
                'company_invitation': company_invitation,
            },
        )

        return company_invitation
Пример #5
0
    def post(self, request, *args, **kwargs):
        project_name = request.data.get('project_name')
        project_key = request.data.get('project_key')
        repo = request.data.get('repo', "")
        pm_tool = request.data.get('pm_tool', "")
        template_type = request.data.get('template_type', 0)

        repo_service = Service.objects.filter(identifier__in=[repo, pm_tool])
        repo_serializer = ServiceSerializer(repo_service, many=True).data

        service_data = {}

        for rr in repo_serializer:
            rs_settings = rr.get('settings')
            service_data[rr.get('service_type')] = {}
            for r in rs_settings:
                service_data[rr.get('service_type')][r.get(
                    'identifier')] = r.get('value')

        template = Template.objects.get(template_type=template_type)

        js = Jumpstart(
            **{
                'project_name': project_name,
                'project_key': project_key,
                'repository': repo,
                'pm_tool': pm_tool,
                'template_url': template.repo_url,
                'service_data': service_data
            })

        email_subj = "{} PROJECT SUCCESSFULY CREATED".format(project_name)

        email_body = "Project Successfuly Created\n" \
                    "Repository URL: {}\nPM Tool URL: {}".format(js.get_repo_url(), js.get_pm_tool_url())

        send_email_template(email_subj, "", [request.user.email], email_body)

        return Response({
            'pm_tool_url': js.get_pm_tool_url(),
            'repo_url': js.get_repo_url()
        })
Пример #6
0
    def save(self, *args, **kwargs):
        connection_invite = super(ConnectionInviteForm, self).save(commit=False)

        with transaction.atomic():
            if not self.instance.pk:
                connection_invite.connecter = self.user
                connection_invites = ConnectionInvite.objects.filter(connectee_email=connection_invite.connectee_email)
                if connection_invites.exists():
                    connection_invite.pk = connection_invites.first().pk
            connection_invite.save()

            send_email_template(
                subject=_('Invitation, SquareBalloon'),
                template='recruit/email/connection_invitation.html',
                recipient=[connection_invite.connectee_email,],
                data={
                    'connection_invite': connection_invite,
                    'user': User,
                },
            )

        return connection_invite
Пример #7
0
    def form_valid(self, form):
        loan_account = form.save(commit=False)
        loan_account.status = "Applied"
        loan_account.created_by = User.objects.get(username=self.request.user)
        loan_account.client = self.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))
        loan_account.save()

        if self.client.email and self.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=self.client.email,
                ctx={
                    "client": self.client,
                    "loan_account": loan_account,
                    "link_prefix": settings.SITE_URL,
                },
            )
        return JsonResponse({
            "error": False,
            "loanaccount_id": loan_account.id
        })
Пример #8
0
def change_loan_account_status(request, pk):
    # if request.method == 'POST':
    loan_object = get_object_or_404(LoanAccount, id=pk)
    if loan_object:
        branch_id = loan_object.group.branch.id
    elif loan_object.client:
        branch_id = loan_object.client.branch.id
    else:
        branch_id = None
    if branch_id:
        if (request.user.is_admin
                or (request.user.has_perm("branch_manager")
                    and request.user.branch.id == branch_id)):
            status = request.GET.get("status")
            if status in ['Closed', 'Withdrawn', 'Rejected', 'Approved']:
                loan_object.status = request.GET.get("status")
                loan_object.approved_date = datetime.datetime.now()
                loan_object.save()
                if loan_object.client:
                    if loan_object.status == 'Approved':
                        if loan_object.client.email and loan_object.client.email.strip(
                        ):
                            send_email_template(
                                subject=
                                "Your application for the Personal Loan (ID: %s) has been Approved."
                                % loan_object.account_no,
                                template_name=
                                "emails/client/loan_approved.html",
                                receipient=loan_object.client.email,
                                ctx={
                                    "client": loan_object.client,
                                    "loan_account": loan_object,
                                    "link_prefix": settings.SITE_URL,
                                },
                            )

                elif loan_object.group:
                    group_member_loans = GroupMemberLoanAccount.objects.filter(
                        group_loan_account=loan_object)
                    group_member_loans.update(status=loan_object.status)
                    group_member_loans.update(
                        loan_issued_date=loan_object.loan_issued_date)
                    group_member_loans.update(
                        interest_type=loan_object.interest_type)
                    for client in loan_object.group.clients.all():
                        if client.email and client.email.strip():
                            send_email_template(
                                subject=
                                "Group Loan (ID: %s) application has been Approved."
                                % loan_object.account_no,
                                template_name="emails/group/loan_approved.html",
                                receipient=client.email,
                                ctx={
                                    "client": client,
                                    "loan_account": loan_object,
                                    "link_prefix": settings.SITE_URL,
                                },
                            )
                data = {"error": False}
            else:
                data = {
                    "error": True,
                    "error_message": "Status is not in available choices"
                }
        else:
            data = {
                "error": True,
                "error_message":
                "You don't have permission to change the status."
            }
    else:
        data = {"error": True, "error_message": "Branch Id not Found"}

    data["success_url"] = reverse('loans:clientloanaccount',
                                  kwargs={"pk": loan_object.id})
    return JsonResponse(data)
Пример #9
0
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)
Пример #10
0
    def form_valid(self, form):
        loan_account = form.save(commit=False)
        if len(self.group.clients.all()):
            loan_account.status = "Applied"
            loan_account.created_by = User.objects.get(
                username=self.request.user)
            loan_account.group = self.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) / self.group.clients.all().count()
            for client in self.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."
            })
Пример #11
0
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)