[FIX] LEAVE: Leave chart tile redirection and unwanted labels in the pie chart
This commit is contained in:
@@ -383,7 +383,4 @@ $(document).ready(function () {
|
||||
});
|
||||
});
|
||||
|
||||
$(".filter").on("click", function () {
|
||||
$("#back_button").removeClass("d-none");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,9 +34,9 @@
|
||||
<div class="oh-dashboard__left col-12 col-sm-12 col-md-12 col-lg-9">
|
||||
<div class="oh-dashboard__cards row">
|
||||
<div class="col-12 col-sm-12 col-md-6 col-lg-4">
|
||||
<div class="oh-card-dashboard oh-card-dashboard oh-card-dashboard--neutral filter pointer dash-card" hx-get="{% url "request-filter" %}?status=requested&dashboard=card" hx-target="#dashboard" >
|
||||
<div class="oh-card-dashboard oh-card-dashboard oh-card-dashboard--neutral filter pointer dash-card" id="requestedLeaves" >
|
||||
<div class="oh-card-dashboard__header">
|
||||
<span class="oh-card-dashboard__title">{% trans "New Requests" %}</span>
|
||||
<span class="oh-card-dashboard__title">{% trans "Requests to Approve" %}</span>
|
||||
</div>
|
||||
<div class="oh-card-dashboard__body">
|
||||
<div class="oh-card-dashboard__counts">
|
||||
@@ -46,9 +46,9 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12 col-md-6 col-lg-4">
|
||||
<div class="oh-card-dashboard oh-card-dashboard--success filter pointer dash-card" hx-get="{% url "request-filter" %}?status=approved&dashboard=card" hx-target="#dashboard">
|
||||
<div class="oh-card-dashboard oh-card-dashboard--success filter pointer dash-card" id="approvedLeaves">
|
||||
<div class="oh-card-dashboard__header">
|
||||
<span class="oh-card-dashboard__title">{% trans "Approved Requests" %}</span>
|
||||
<span class="oh-card-dashboard__title">{% trans "Approved Leaves In This Month" %}</span>
|
||||
</div>
|
||||
<div class="oh-card-dashboard__body">
|
||||
<div class="oh-card-dashboard__counts">
|
||||
@@ -58,9 +58,9 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12 col-md-6 col-lg-4">
|
||||
<div class="oh-card-dashboard oh-card-dashboard--danger filter pointer dash-card" hx-get="{% url "request-filter" %}?status=rejected&dashboard=card" hx-target="#dashboard">
|
||||
<div class="oh-card-dashboard oh-card-dashboard--danger filter pointer dash-card" id="rejectedLeaves">
|
||||
<div class="oh-card-dashboard__header">
|
||||
<span class="oh-card-dashboard__title">{% trans "Rejected Requests" %}</span>
|
||||
<span class="oh-card-dashboard__title">{% trans "Rejected Leaves In This Month" %}</span>
|
||||
</div>
|
||||
<div class="oh-card-dashboard__body">
|
||||
<div class="oh-card-dashboard__counts">
|
||||
@@ -259,5 +259,18 @@
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script src="{% static "dashboard/dashboard.js" %}"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("#requestedLeaves").on("click", function(){
|
||||
window.location.href='{% url "request-view" %}?status=requested'
|
||||
})
|
||||
$("#approvedLeaves").on("click", function(){
|
||||
window.location.href='{% url "request-view" %}?status=approved&from_date={{first_day}}&to_date={{last_day}}'
|
||||
})
|
||||
$("#rejectedLeaves").on("click", function(){
|
||||
window.location.href='{% url "request-view" %}?status=rejected&from_date={{first_day}}&to_date={{last_day}}'
|
||||
})
|
||||
})
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -14,24 +14,11 @@
|
||||
}
|
||||
</style>
|
||||
<div class="oh-wrapper">
|
||||
<div class="d-none mt-5" id="back_button" style="width:10%">
|
||||
<a href=""
|
||||
class="oh-btn oh-btn--secondary oh-btn--shadow ms-3"
|
||||
>
|
||||
<ion-icon
|
||||
class="me-2 md hydrated"
|
||||
name="arrow-back-outline"
|
||||
role="img"
|
||||
aria-label="arrow-back-outline"
|
||||
></ion-icon
|
||||
>{% trans "Back" %}</a
|
||||
>
|
||||
</div>
|
||||
<div class="oh-dashboard row" id="dashboard">
|
||||
<div class="oh-dashboard__left col-12 col-sm-12 col-md-12 col-lg-9">
|
||||
<div class="oh-dashboard__cards row">
|
||||
<div class="col-12 col-sm-12 col-md-6 col-lg-4">
|
||||
<div class="oh-card-dashboard oh-card-dashboard oh-card-dashboard--neutral filter pointer dash-card" hx-get="{% url "request-filter" %}?status=requested&dashboard=true&employee_id={{request.user.employee_get.employee_first_name}}" hx-target="#dashboard" >
|
||||
<div class="oh-card-dashboard oh-card-dashboard oh-card-dashboard--neutral filter pointer dash-card"id="requestedLeaves" >
|
||||
<div class="oh-card-dashboard__header">
|
||||
<span class="oh-card-dashboard__title">{% trans "New Requests" %}</span>
|
||||
</div>
|
||||
@@ -45,7 +32,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12 col-md-6 col-lg-4">
|
||||
<div class="oh-card-dashboard oh-card-dashboard--success filter pointer dash-card" hx-get="{% url "request-filter" %}?status=approved&dashboard=true&employee_id={{request.user.employee_get.employee_first_name}}" hx-target="#dashboard">
|
||||
<div class="oh-card-dashboard oh-card-dashboard--success filter pointer dash-card" id="approvedLeaves">
|
||||
<div class="oh-card-dashboard__header">
|
||||
<span class="oh-card-dashboard__title">{% trans "Approved Requests" %}</span>
|
||||
</div>
|
||||
@@ -57,7 +44,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12 col-md-6 col-lg-4">
|
||||
<div class="oh-card-dashboard oh-card-dashboard--danger filter pointer dash-card" hx-get="{% url "request-filter" %}?status=rejected&dashboard=true&employee_id={{request.user.employee_get.employee_first_name}}" hx-target="#dashboard">
|
||||
<div class="oh-card-dashboard oh-card-dashboard--danger filter pointer dash-card" id="rejectedLeaves">
|
||||
<div class="oh-card-dashboard__header">
|
||||
<span class="oh-card-dashboard__title">{% trans "Rejected Requests" %}</span>
|
||||
</div>
|
||||
@@ -88,7 +75,7 @@
|
||||
<input type="month" hx-trigger="change delay:100ms" class="float-end month" hx-get="{% url 'dashboard-leave-requests' %}" hx-target="#leaveRequest">
|
||||
</div>
|
||||
<div class="oh-card-dashboard__body" id="leaveRequest" style="height:35vh;overflow-y:auto">
|
||||
{% include 'leave/leave_request/leave_requests.html' %}
|
||||
{% include 'leave/leave_request/dashboard_leave_requests.html' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -161,4 +148,18 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
|
||||
<script src="{% static "dashboard/dashboard.js" %}"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("#requestedLeaves").on("click", function(){
|
||||
window.location.href='{% url "user-request-view" %}?status=requested'
|
||||
})
|
||||
$("#approvedLeaves").on("click", function(){
|
||||
window.location.href='{% url "user-request-view" %}?status=approved'
|
||||
})
|
||||
$("#rejectedLeaves").on("click", function(){
|
||||
window.location.href='{% url "user-request-view" %}?status=rejected'
|
||||
})
|
||||
})
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,91 @@
|
||||
{% load i18n %}
|
||||
{% load static %}
|
||||
{% load basefilters %}
|
||||
{% load attendancefilters %}
|
||||
{% include 'filter_tags.html' %}
|
||||
{% if leave_requests %}
|
||||
<div class="oh-sticky-table">
|
||||
<div class="oh-sticky-table__table ">
|
||||
<div class="oh-sticky-table__thead">
|
||||
<div class="oh-sticky-table__tr">
|
||||
<div class="oh-sticky-table__th" >{% trans "Employee" %}</div>
|
||||
<div class="oh-sticky-table__th" >{% trans "Leave Type" %}</div>
|
||||
<div class="oh-sticky-table__th" >{% trans "Start Date" %}</div>
|
||||
<div class="oh-sticky-table__th" >{% trans "End Date" %}</div>
|
||||
<div class="oh-sticky-table__th" >{% trans "Requested Days" %}</div>
|
||||
<div class="oh-sticky-table__th" >{% trans "Status" %}</div>
|
||||
<div class="oh-sticky-table__th oh-sticky-table__right" >{% trans "Actions" %}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="oh-sticky-table__tbody" id="leaveRequestTableBody">
|
||||
{% for leave_request in leave_requests %}
|
||||
<div class="oh-sticky-table__tr" draggable="true" data-toggle="oh-modal-toggle" data-target="#tableTimeOff"
|
||||
hx-get="{% url 'one-request-view' leave_request.id %}?instances_ids={{requests_ids}}" hx-target="#requestView">
|
||||
|
||||
<div class="oh-sticky-table__sd">
|
||||
<div class="oh-profile oh-profile--md">
|
||||
<div class="oh-profile__avatar mr-1">
|
||||
<img src="{{leave_request.employee_id.get_avatar}}" class="oh-profile__image"
|
||||
alt="" />
|
||||
</div>
|
||||
<span class="oh-profile__name oh-text--dark">{{leave_request.employee_id}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="oh-sticky-table__td {% if leave_request.status == 'cancelled' %} diff-cell{% endif %}">{{leave_request.leave_type_id}}</div>
|
||||
<div class="oh-sticky-table__td {% if leave_request.status == 'cancelled' %} diff-cell{% endif %} dateformat_changer">{{leave_request.start_date}}</div>
|
||||
<div class="oh-sticky-table__td {% if leave_request.status == 'cancelled' %} diff-cell{% endif %} dateformat_changer">{{leave_request.end_date}}</div>
|
||||
<div class="oh-sticky-table__td {% if leave_request.status == 'cancelled' %} diff-cell{% endif %}">{{leave_request.requested_days}}</div>
|
||||
<div class="oh-sticky-table__td {% if leave_request.status == 'cancelled' %} diff-cell{% endif %}">
|
||||
{% if leave_request.multiple_approvals and leave_request.status == "requested" %}
|
||||
<div class="oh-checkpoint-badge oh-checkpoint-badge--secondary" title="{% for manager in leave_request.multiple_approvals.managers %}{{ manager }}{% if not forloop.last %} , {% endif %}{% endfor %}">
|
||||
{{leave_request.multiple_approvals.approved|length}} / {{leave_request.multiple_approvals.managers|length}} {% trans "Approved" %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{leave_request.get_status_display}}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="oh-sticky-table__td oh-sticky-table__right" onclick="event.stopPropagation()">
|
||||
<div class="oh-btn-group" >
|
||||
{% if leave_request.is_approved and leave_request.status == 'requested' and leave_request.end_date >= current_date %}
|
||||
<a href="{% url 'request-approve' leave_request.id %}" title="{% trans 'Approve' %}"
|
||||
class="oh-btn oh-btn--success w-100" {% if leave_request.end_date.month > current_date.month %} onclick = "leaveRequestConfirm('This leave request is for the month of {{leave_request.start_date|date:'F'}}. Approval depends on the {{leave_request.employee_id.get_full_name}} having available leave days for this month.',event);" {% else %} onclick = "return confirm('Do You really want to Approve this request?')"; {% endif %}>
|
||||
<ion-icon class="me-1" name="checkmark-outline"></ion-icon>
|
||||
</a>
|
||||
{% else %}
|
||||
<a type="submit" href="#" title="{% trans 'Approve' %}"
|
||||
class="oh-btn oh-btn--success oh-btn--disabled
|
||||
w-100">
|
||||
<ion-icon class="me-1" name="checkmark-outline"></ion-icon>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if leave_request.status != 'rejected' and leave_request.end_date >= current_date %}
|
||||
<a type="submit" data-toggle="oh-modal-toggle"
|
||||
data-target="#rejectModal" hx-get="{% url 'request-cancel' leave_request.id %}" hx-target="#rejectForm" title="{% trans 'Reject' %}"
|
||||
class="oh-btn oh-btn--danger w-100">
|
||||
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
|
||||
|
||||
</a>
|
||||
{% else %}
|
||||
<a type="submit" href="#" title="{% trans 'Reject' %}"
|
||||
class="oh-btn oh-btn--danger oh-btn--disabled
|
||||
w-100" >
|
||||
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
|
||||
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div style="height: 310px; display:flex;align-items: center;justify-content: center;" class="">
|
||||
<div style="" class="">
|
||||
<img style=" display: block;width: 70px;margin: 10px auto ;" src="{% static 'images/ui/attendance.png' %}" class="" alt=""/>
|
||||
<h3 style="font-size:16px" class="oh-404__subtitle">{% trans "You have No leave requests for this month." %}</h3>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -41,6 +41,7 @@ from leave.forms import *
|
||||
from leave.decorators import *
|
||||
from leave.filters import *
|
||||
from employee.models import Employee
|
||||
from attendance.methods.group_by import group_by_queryset
|
||||
from .methods import (
|
||||
calculate_requested_days,
|
||||
leave_requested_dates,
|
||||
@@ -865,6 +866,15 @@ def leave_assign_view(request):
|
||||
export_filter = AssignedLeaveFilter()
|
||||
export_column = AvailableLeaveColumnExportForm()
|
||||
assign_form = AssignLeaveForm()
|
||||
|
||||
# default group by configuration
|
||||
data_dict = {"field":["leave_type_id"]}
|
||||
|
||||
# to check condition on the template
|
||||
setattr(request.GET,"field",True)
|
||||
|
||||
page_obj = group_by_queryset(queryset.order_by("-id"),"leave_type_id",page_number)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"leave/leave_assign/assign_view.html",
|
||||
@@ -874,6 +884,7 @@ def leave_assign_view(request):
|
||||
"export_filter": export_filter,
|
||||
"export_column": export_column,
|
||||
"pd": previous_data,
|
||||
"filter_dict":data_dict,
|
||||
"gp_fields": LeaveAssignReGroup.fields,
|
||||
"assign_form": assign_form,
|
||||
},
|
||||
@@ -901,12 +912,15 @@ def leave_assign_filter(request):
|
||||
field = request.GET.get("field")
|
||||
page_number = request.GET.get("page")
|
||||
template = ("leave/leave_assign/assigned_leave.html",)
|
||||
available_leaves = assigned_leave_filter.order_by("-id")
|
||||
if request.GET.get("sortby"):
|
||||
available_leaves = sortby(request,available_leaves,"sortby")
|
||||
if field != "" and field is not None:
|
||||
field_copy = field.replace(".", "__")
|
||||
assigned_leave_filter = assigned_leave_filter.order_by(field_copy)
|
||||
page_obj = group_by_queryset(available_leaves,field,page_number)
|
||||
template = "leave/leave_assign/group_by.html"
|
||||
else:
|
||||
page_obj = paginator_qry(available_leaves, page_number)
|
||||
|
||||
page_obj = paginator_qry(assigned_leave_filter.order_by("-id"), page_number)
|
||||
data_dict = parse_qs(previous_data)
|
||||
get_key_instances(AvailableLeave, data_dict)
|
||||
return render(
|
||||
@@ -2104,8 +2118,8 @@ def dashboard(request):
|
||||
today = date.today()
|
||||
leave_requests = LeaveRequest.objects.filter(start_date__month=today.month)
|
||||
requested = LeaveRequest.objects.filter(status="requested")
|
||||
approved = LeaveRequest.objects.filter(status="approved")
|
||||
rejected = LeaveRequest.objects.filter(status="rejected")
|
||||
approved = LeaveRequest.objects.filter(status="approved",start_date__month=today.month)
|
||||
rejected = LeaveRequest.objects.filter(status="rejected",start_date__month=today.month)
|
||||
holidays = Holiday.objects.filter(start_date__gte=today)
|
||||
next_holiday = (
|
||||
holidays.order_by("start_date").first() if holidays.exists() else None
|
||||
@@ -2132,6 +2146,8 @@ def dashboard(request):
|
||||
"holidays": holidays,
|
||||
"leave_today_employees": leave_today,
|
||||
"dashboard": "dashboard",
|
||||
"first_day":today.replace(day=1).strftime("%Y-%m-%d"),
|
||||
"last_day":date(today.year, today.month, calendar.monthrange(today.year, today.month)[1]).strftime("%Y-%m-%d"),
|
||||
}
|
||||
return render(request, "leave/dashboard.html", context)
|
||||
|
||||
@@ -2214,12 +2230,13 @@ def available_leave_chart(request):
|
||||
GET : return Json response of labels, dataset, message.
|
||||
"""
|
||||
user = Employee.objects.get(employee_user_id=request.user)
|
||||
available_leaves = AvailableLeave.objects.filter(employee_id=user)
|
||||
available_leaves = AvailableLeave.objects.filter(employee_id=user).exclude(available_days=0)
|
||||
leave_count = []
|
||||
labels = []
|
||||
for leave in available_leaves:
|
||||
leave_count.append(leave.available_days + leave.carryforward_days)
|
||||
|
||||
labels = [available.leave_type_id.name for available in available_leaves]
|
||||
labels.append(leave.leave_type_id.name)
|
||||
dataset = [
|
||||
{
|
||||
"label": _("Total leaves available"),
|
||||
@@ -2245,15 +2262,23 @@ def employee_leave_chart(request):
|
||||
Returns:
|
||||
GET : return Json response of labels, dataset, message.
|
||||
"""
|
||||
leave_requests = LeaveRequest.objects.filter(
|
||||
employee_id__is_active=True, status="approved"
|
||||
)
|
||||
leave_types = LeaveType.objects.all()
|
||||
|
||||
day = date.today()
|
||||
if request.GET.get("date"):
|
||||
day = request.GET.get("date")
|
||||
day = datetime.strptime(day, "%Y-%m")
|
||||
|
||||
leave_requests = LeaveRequest.objects.filter(
|
||||
employee_id__is_active=True, status="approved"
|
||||
)
|
||||
leave_requests=leave_requests.filter(
|
||||
start_date__month=day.month, start_date__year=day.year
|
||||
)
|
||||
# leave_types = LeaveType.objects.filter(leaverequest__in=leave_requests.filter(
|
||||
# start_date__month=day.month, start_date__year=day.year
|
||||
# )).distinct()
|
||||
leave_types = leave_requests.values_list('leave_type_id__name', flat=True).distinct()
|
||||
|
||||
labels = []
|
||||
dataset = []
|
||||
for employee in leave_requests.filter(
|
||||
@@ -2264,7 +2289,7 @@ def employee_leave_chart(request):
|
||||
for leave_type in leave_types:
|
||||
dataset.append(
|
||||
{
|
||||
"label": leave_type.name,
|
||||
"label": leave_type,
|
||||
"data": [],
|
||||
}
|
||||
)
|
||||
@@ -2316,7 +2341,7 @@ def department_leave_chart(request):
|
||||
department_counts = {dep.department: 0 for dep in departments}
|
||||
leave_request = LeaveRequest.objects.filter(status="approved")
|
||||
leave_dates = []
|
||||
|
||||
labels=[]
|
||||
for leave in leave_request:
|
||||
for leave_date in leave.requested_dates():
|
||||
leave_dates.append(leave_date.strftime("%Y-%m-%d"))
|
||||
@@ -2325,12 +2350,16 @@ def department_leave_chart(request):
|
||||
for dep in departments:
|
||||
if dep == leave.employee_id.employee_work_info.department_id:
|
||||
department_counts[dep.department] += 1
|
||||
|
||||
labels = [department.department for department in departments]
|
||||
|
||||
for department, count in department_counts.items():
|
||||
if count != 0:
|
||||
labels.append(department)
|
||||
values = list(department_counts.values())
|
||||
values = [value for value in values if value != 0]
|
||||
dataset = [
|
||||
{
|
||||
"label": _(""),
|
||||
"data": list(department_counts.values()),
|
||||
"data": values,
|
||||
},
|
||||
]
|
||||
response = {
|
||||
@@ -2359,13 +2388,19 @@ def leave_type_chart(request):
|
||||
if lev == leave.leave_type_id:
|
||||
leave_type_count[lev.name] += leave.requested_days
|
||||
|
||||
labels = [leave_type.name for leave_type in leave_types]
|
||||
|
||||
# labels = [leave_type.name for leave_type in leave_types]
|
||||
labels = []
|
||||
for leave_type, count in leave_type_count.items():
|
||||
if count != 0:
|
||||
labels.append(leave_type)
|
||||
values = list(leave_type_count.values())
|
||||
values = [value for value in values if value != 0]
|
||||
|
||||
response = {
|
||||
"labels": labels,
|
||||
"dataset": [
|
||||
{
|
||||
"data": list(leave_type_count.values()),
|
||||
"data": values,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user