Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add invoices rows to applicant dashboard with different kind of invoice statuses #3600

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions hypha/apply/dashboard/templates/dashboard/applicant_dashboard.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "base-apply.html" %}
{% load render_table from django_tables2 %}
{% load i18n static wagtailcore_tags workflow_tags statusbar_tags heroicons dashboard_statusbar_tags %}
{% load i18n static wagtailcore_tags workflow_tags statusbar_tags heroicons dashboard_statusbar_tags apply_tags invoice_tools %}

{% block title %}{% trans "Dashboard" %}{% endblock %}

Expand Down Expand Up @@ -35,7 +35,7 @@ <h2 class="font-light flex-1">{% trans "My active submissions" %}</h2>
<div class="wrapper wrapper--status-bar-outer">
<div class="wrapper wrapper--status-bar-inner">
<div class="mt-5 ml-4">
<h4 class="heading mb-2 font-bold"><a class="link link--underlined" href="{% url 'funds:submissions:detail' submission.id %}">{{ submission.title }}</a></h4>
<h4 class="heading mb-2 font-bold"><a class="link" href="{% url 'funds:submissions:detail' submission.id %}">{{ submission.title }}</a></h4>
<p class="m-0 text-gray-400">{% trans "Submitted on " %} {{ submission.submit_time.date }} {% trans "by" %} {{ submission.user.get_full_name }}</p>
</div>
{% status_bar submission.workflow submission.phase request.user css_class="status-bar--small" %}
Expand Down Expand Up @@ -65,7 +65,7 @@ <h2 class="font-light flex-1">{% trans "My active projects" %}</h2>
<div class="wrapper wrapper--status-bar-outer">
<div class="wrapper wrapper--status-bar-inner">
<div class="mt-5 ml-4">
<h4 class="heading mb-2 font-bold"><a class="link link--underlined" href="{% url 'apply:projects:detail' project.id %}">{{ project.title }}</a></h4>
<h4 class="heading mb-2 font-bold"><a class="link" href="{% url 'apply:projects:detail' project.id %}">{{ project.title }}</a></h4>
<p class="m-0 text-gray-400">{% trans "Project start date: " %} {{ project.created_at.date }}</p>
</div>
{% project_status_bar project.status request.user css_class="status-bar--small" %}
Expand All @@ -76,11 +76,43 @@ <h4 class="heading mb-2 font-bold"><a class="link link--underlined" href="{% url
{% endfor %}
</div>
{% endif %}

{% if active_invoices.count %}
<div class="mb-10">
<div class="flex">
<h2 class="font-light flex-1">{% trans "My active invoices" %}</h2>
</div>
{% for invoice in active_invoices.data %}
<div class="wrapper wrapper--status-bar-outer">
<div class="wrapper wrapper--status-bar-inner pl-4 pr-4">
<div class="max-w-[33%] w-full text-left my-auto">
<h4 class="heading heading--no-margin font-bold"><a class="link" href="{{ invoice.get_absolute_url }}">
{% if invoice.invoice_number %}{{ invoice.invoice_number }}{% else %}{{ invoice.vendor_document_number }}{% endif %}
</a></h4>
<p class="m-0 text-gray-400">{% trans "Date added: " %} {{ invoice.requested_at }}</p>
</div>
<div class="max-w-[33%] w-full text-center my-auto">
<p class="text-2xl">{% if invoice.invoice_amount %}{{ invoice.invoice_amount | format_number_as_currency }}{% else %}-{% endif %}</p>
</div>
<div class="max-w-[33%] w-full flex my-auto">
{% display_invoice_table_status_for_user invoice.status request.user as invoice_status %}
<div class="w-full flex-1"></div>
<div class="max-w-fit w-full text-right">
<p class="{{ invoice_status|invoice_status_bg_color }} text-base py-2 px-3 {{ invoice_status|invoice_status_fg_color }}">{{ invoice_status }}</p>
</div>
</div>
</div>
</div>
{% empty %}
{% trans "No active invoices" %}
{% endfor %}
</div>
{% endif %}
</div>

{% if historical_submissions.count %}
<div class="wrapper wrapper--large wrapper--inner-space-medium mb-8">
<h2 class="text-xl mb-2">{% trans "Submission history" %}</h3>
<h2 class="text-xl mb-2">{% trans "Submission history" %}</h2>
{% render_table historical_submissions.table %}
</div>
{% endif %}
Expand Down
10 changes: 10 additions & 0 deletions hypha/apply/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
from hypha.apply.projects.filters import ProjectListFilter
from hypha.apply.projects.models import Invoice, PAFApprovals, Project, ProjectSettings
from hypha.apply.projects.models.payment import DECLINED, PAID
from hypha.apply.projects.models.project import INTERNAL_APPROVAL
from hypha.apply.projects.permissions import has_permission
from hypha.apply.projects.tables import (
Expand Down Expand Up @@ -772,6 +773,7 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["my_active_submissions"] = my_active_submissions
context["active_projects"] = self.active_project_data()
context["active_invoices"] = self.active_invoices()
context["historical_projects"] = self.historical_project_data()
context["historical_submissions"] = self.historical_submission_data()
return context
Expand Down Expand Up @@ -801,6 +803,14 @@ def my_active_submissions(self, user):
for submission in active_subs:
yield submission.from_draft()

def active_invoices(self):
active_invoices = (
Invoice.objects.filter(project__user=self.request.user)
.exclude(status__in=[PAID, DECLINED])
.order_by("-requested_at")
)
return {"count": active_invoices.count(), "data": active_invoices}

def historical_project_data(self):
historical_projects = (
Project.objects.filter(user=self.request.user).complete().for_table()
Expand Down
38 changes: 38 additions & 0 deletions hypha/apply/projects/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.conf import settings
from django.utils.translation import gettext_lazy as _

# INT refers Invoice table
INT_STAFF_PENDING = _("Staff pending")
INT_FINANCE_PENDING = _("Finance pending")
INT_VENDOR_PENDING = _("Vendor pending")

# duplicate statuses
INT_DECLINED = _("Declined")
INT_PAID = _("Paid")
INT_PAYMENT_FAILED = _("Payment failed")

# INVOICE_TABLE_STATUSES = [INT_STAFF_PENDING, INT_FINANCE_PENDING, INT_VENDOR_PENDING, INT_DECLINED,
# INT_PAID, INT_PAYMENT_FAILED]

INT_ORG_PENDING = _("{} pending").format(settings.ORG_SHORT_NAME)
INT_REQUEST_FOR_CHANGE = _("Request for change")

# INVOICE_TABLE_PUBLIC_STATUSES = [INT_ORG_PENDING, INT_REQUEST_FOR_CHANGE,
# INT_DECLINED, INT_PAID, INT_PAYMENT_FAILED]


INVOICE_STATUS_BG_COLORS = {
INT_ORG_PENDING: "bg-yellow-100",
INT_PAID: "bg-green-100",
INT_REQUEST_FOR_CHANGE: "bg-blue-100",
INT_PAYMENT_FAILED: "bg-red-100",
INT_DECLINED: "bg-pink-100",
}

INVOICE_STATUS_FG_COLORS = {
INT_ORG_PENDING: "text-yellow-700",
INT_PAID: "text-green-700",
INT_REQUEST_FOR_CHANGE: "text-blue-700",
INT_PAYMENT_FAILED: "text-red-700",
INT_DECLINED: "text-pink-700",
}
24 changes: 23 additions & 1 deletion hypha/apply/projects/templatetags/invoice_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@

from hypha.apply.activity.models import Activity
from hypha.apply.activity.templatetags.activity_tags import display_for
from hypha.apply.projects.constants import (
INVOICE_STATUS_BG_COLORS,
INVOICE_STATUS_FG_COLORS,
)
from hypha.apply.projects.models.project import (
CLOSING,
COMPLETE,
INVOICING_AND_REPORTING,
ProjectSettings,
)
from hypha.apply.projects.utils import get_invoice_public_status
from hypha.apply.projects.utils import (
get_invoice_public_status,
get_invoice_table_status,
)

register = template.Library()

Expand Down Expand Up @@ -135,3 +142,18 @@ def get_comment_for_invoice_action(invoice, action):
related_content_type__model="invoice",
related_object_id=invoice.id,
).first()


@register.filter
def invoice_status_bg_color(invoice_status):
return INVOICE_STATUS_BG_COLORS.get(invoice_status, "bg-gray-100")


@register.filter
def invoice_status_fg_color(invoice_status):
return INVOICE_STATUS_FG_COLORS.get(invoice_status, "text-gray-700")


@register.simple_tag
def display_invoice_table_status_for_user(status, user):
return get_invoice_table_status(status, user)
38 changes: 38 additions & 0 deletions hypha/apply/projects/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from django.conf import settings
from django.utils.translation import gettext_lazy as _

from .constants import (
INT_DECLINED,
INT_FINANCE_PENDING,
INT_ORG_PENDING,
INT_PAID,
INT_PAYMENT_FAILED,
INT_REQUEST_FOR_CHANGE,
INT_STAFF_PENDING,
INT_VENDOR_PENDING,
)
from .models import Deliverable, Project
from .models.payment import (
APPROVED_BY_FINANCE,
Expand Down Expand Up @@ -147,3 +157,31 @@ def get_project_status_display_value(project_status):

def get_project_public_status(project_status):
return dict(PROJECT_PUBLIC_STATUSES)[project_status]


def get_invoice_table_status(invoice_status, user):
if invoice_status in [SUBMITTED, RESUBMITTED]:
if user.is_applicant:
return INT_ORG_PENDING
return INT_STAFF_PENDING
if invoice_status == CHANGES_REQUESTED_BY_STAFF:
if user.is_applicant:
return INT_REQUEST_FOR_CHANGE
return INT_VENDOR_PENDING
if invoice_status in [APPROVED_BY_STAFF, CHANGES_REQUESTED_BY_FINANCE]:
if user.is_applicant:
return INT_ORG_PENDING
return INT_FINANCE_PENDING
if settings.INVOICE_EXTENDED_WORKFLOW and invoice_status in [
APPROVED_BY_FINANCE,
CHANGES_REQUESTED_BY_FINANCE_2,
]:
if user.is_applicant:
return INT_ORG_PENDING
return INT_FINANCE_PENDING
if invoice_status == PAID:
return INT_PAID
if invoice_status == DECLINED:
return INT_DECLINED
if invoice_status == PAYMENT_FAILED:
return INT_PAYMENT_FAILED