[UPDT] Added condition in leave dashboard if today is a holiday

This commit is contained in:
Horilla
2023-09-22 16:29:50 +05:30
parent 7e5dac7c71
commit ca3bf2a066
6 changed files with 131 additions and 71 deletions

View File

@@ -20,6 +20,18 @@ $(document).ready(function(){
year = today.getFullYear()
$(".month").val(`${year}-${month}`)
$("#dash_month").val(`${year}-${month}`)
function isPieChartEmpty(chartData) {
if (!chartData || !chartData.dataset || chartData.dataset.length === 0) {
return true;
}
for (var i = 0; i < chartData.dataset[0].data.length; i++) {
if (chartData.dataset[0].data[i] != 0) {
return false;
}
}
return true;
}
//Employee wise chart for available leaves
function available_leave_chart (dataSet){
@@ -119,7 +131,7 @@ $(document).ready(function(){
// stacked: true,
title: {
display: true,
text: "Number of leaves",
text: "Number of days",
font: {
weight: "bold",
size: 16,
@@ -162,8 +174,17 @@ $(document).ready(function(){
url: "/leave/available-leaves",
dataType: "json",
success: function (response) {
available_leave_chart(response)
if (isPieChartEmpty(response)){
$("#availableLeaveContainer").html(
`<div style="height: 310px; display:flex;align-items: center;justify-content: center;" class="">
<div style="" class="">
<h3 style="font-size:16px" class="oh-404__subtitle">${response.message}</h3>
</div>
</div>`
)
}else{
available_leave_chart(response)
}
},
error: (error) => {
console.log('Error', error);

View File

@@ -2,6 +2,9 @@
{% load static %}
{% load i18n %}
{% block content %}
{% load tz %}
{% now "Y-m-d" as current_date %}
<div class="oh-wrapper">
<div class="d-none mt-5" id="back_button" style="width:10%">
@@ -23,7 +26,7 @@
<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" hx-get="{% url "request-filter" %}?status=requested&dashboard=true" hx-target="#dashboard" >
<div class="oh-card-dashboard__header">
<span class="oh-card-dashboard__title">New Requests</span>
<span class="oh-card-dashboard__title">{% trans "New Requests" %}</span>
</div>
<div class="oh-card-dashboard__body">
<div class="oh-card-dashboard__counts">
@@ -35,7 +38,7 @@
<div class="col-12 col-sm-12 col-md-6 col-lg-4">
<div class="oh-card-dashboard oh-card-dashboard--success filter" hx-get="{% url "request-filter" %}?status=approved&dashboard=true" hx-target="#dashboard">
<div class="oh-card-dashboard__header">
<span class="oh-card-dashboard__title">Approved Requests</span>
<span class="oh-card-dashboard__title">{% trans "Approved Requests" %}</span>
</div>
<div class="oh-card-dashboard__body">
<div class="oh-card-dashboard__counts">
@@ -47,7 +50,7 @@
<div class="col-12 col-sm-12 col-md-6 col-lg-4">
<div class="oh-card-dashboard oh-card-dashboard--danger filter" hx-get="{% url "request-filter" %}?status=cancelled&dashboard=true" hx-target="#dashboard">
<div class="oh-card-dashboard__header">
<span class="oh-card-dashboard__title">Rejected Requests</span>
<span class="oh-card-dashboard__title">{% trans "Rejected Requests" %}</span>
</div>
<div class="oh-card-dashboard__body">
<div class="oh-card-dashboard__counts">
@@ -63,7 +66,7 @@
<div class="oh-card-dashboard oh-card-dashboard--no-scale oh-card-dashboard--transparent">
<div class="oh-card-dashboard__header oh-card-dashboard__header--divider">
<span class="oh-card-dashboard__title" id="employee-previous" title="{% trans "Previous" %}"><ion-icon name="caret-back-outline"></ion-icon></span>
<span class="oh-card-dashboard__title">Employee Leaves</span>
<span class="oh-card-dashboard__title">{% trans "Employee Leaves" %}</span>
<span class="oh-card-dashboard__title float-end" id="employee-next" title="{% trans "next" %}"><ion-icon name="caret-forward"></ion-icon></span>
</div>
<input type="month" class="mb-2 float-end " name="" id="dash_month" />
@@ -95,13 +98,21 @@
{% endfor %}
</ul>
</div>
{% else %}
{% elif current_date == next_holiday.start_date|date:"Y-m-d" %}
<div style="height: 380px; 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 "Today, all employees are present." %}</h3>
<img style=" display: block;width: 70px;margin: 20px auto ;" src="{% static 'images/ui/sunbed outline.png' %}" class="" alt=""/>
<h3 style="font-size:16px" class="oh-404__subtitle">{% trans "Today is a holiday." %}</h3>
</div>
</div>
</div>
{% else %}
<div style="height: 380px; 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 "No leave requests for today." %}</h3>
</div>
</div>
{% endif %}
</div>
</div>
@@ -110,22 +121,21 @@
</div>
<div class="oh-dashboard__right col-12 col-sm-12 col-md-12 col-lg-3">
<div class="oh-dashboard__events">
<div class="oh-dashboard__event oh-dashboard__event--purple mb-2">
<div class="oh-dasboard__event-photo" style="background-color:white">
<img src="/static/images/ui/sunbed.png" class="oh-dashboard__event-userphoto" />
</div>
<div class="oh-dasboard__event-details">
<span class="oh-dashboard__event-title">Next Holiday</span>
<span class="oh-dashboard__event-main">{{next_holiday.name}}</span>
<span class="oh-dashboard__event-date">{{next_holiday.start_date}}</span>
</div>
<div class="oh-dashboard__event oh-dashboard__event--purple mb-2">
<div class="oh-dasboard__event-photo" style="background-color:white">
<img src="/static/images/ui/sunbed.png" class="oh-dashboard__event-userphoto" />
</div>
<div class="oh-dasboard__event-details">
<span class="oh-dashboard__event-title">{% trans "Next Holiday" %}</span>
<span class="oh-dashboard__event-main">{{next_holiday.name}}</span>
<span class="oh-dashboard__event-date">{{next_holiday.start_date}}</span>
</div>
</div>
</div>
<div class="oh-card-dashboard oh-card-dashboard--no-scale oh-card-dashboard--transparent mt-5 mb-3" style="height:480px;overflow-y:auto">
<div class="oh-card-dashboard__header oh-card-dashboard__header--divider">
<span class="oh-card-dashboard__title">Up coming holidays</span>
<span class="oh-card-dashboard__title">{% trans "Up coming holidays" %}</span>
</div>
<div class="oh-card-dashboard__body">
<ul class="oh-card-dashboard__user-list">
@@ -153,16 +163,23 @@
<div class="col-12 col-sm-12 col-md-12 col-lg-3 mt-3">
<div class="oh-card-dashboard oh-card-dashboard--no-scale oh-card-dashboard--transparent">
<div class="oh-card-dashboard__header oh-card-dashboard__header--divider">
<span class="oh-card-dashboard__title">Department Leaves</span>
<span class="oh-card-dashboard__title">{% trans "Department Leaves" %}</span>
</div>
<div class="oh-card-dashboard__body">
{% if leave_today_employees %}
<canvas id="departmentLeave"></canvas>
{% elif current_date == next_holiday.start_date|date:"Y-m-d" %}
<div style="height: 380px; display:flex;align-items: center;justify-content: center;" class="">
<div style="" class="">
<img style=" display: block;width: 70px;margin: 20px auto ;" src="{% static 'images/ui/sunbed outline.png' %}" class="" alt=""/>
<h3 style="font-size:16px" class="oh-404__subtitle">{% trans "Today is a holiday." %}</h3>
</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 "Today, all employees are present." %}</h3>
<h3 style="font-size:16px" class="oh-404__subtitle">{% trans "No leave requests for today." %}</h3>
</div>
</div>
{% endif %}
@@ -172,7 +189,7 @@
<div class="col-12 col-sm-12 col-md-12 col-lg-3 mt-3">
<div class="oh-card-dashboard oh-card-dashboard--no-scale oh-card-dashboard--transparent">
<div class="oh-card-dashboard__header oh-card-dashboard__header--divider">
<span class="oh-card-dashboard__title">Leave Type</span>
<span class="oh-card-dashboard__title">{% trans "Leave Type" %}</span>
</div>
<div class="oh-card-dashboard__body">
{% if leave_requests %}
@@ -191,7 +208,7 @@
<div class="col-12 col-sm-12 col-md-12 col-lg-6 mt-3">
<div class="oh-card-dashboard oh-card-dashboard--no-scale oh-card-dashboard--transparent">
<div class="oh-card-dashboard__header oh-card-dashboard__header--divider">
<span class="oh-card-dashboard__title">Leave trend this week</span>
<span class="oh-card-dashboard__title">{% trans "Leave trend this week" %}</span>
</div>
<div class="oh-card-dashboard__body">
<canvas id="leavePeriod"></canvas>

View File

@@ -1,14 +1,28 @@
{% extends 'index.html' %}
{% load static %}
{% block content %}
{% load i18n %}
<div class="oh-wrapper">
<div class="oh-dashboard row">
<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">
<div class="oh-card-dashboard oh-card-dashboard oh-card-dashboard--neutral filter" 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__header">
<span class="oh-card-dashboard__title">New Requests</span>
<span class="oh-card-dashboard__title">{% trans "New Requests" %}</span>
</div>
<div class="oh-card-dashboard__body">
<div class="oh-card-dashboard__counts">
@@ -20,9 +34,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">
<div class="oh-card-dashboard oh-card-dashboard--success filter" 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__header">
<span class="oh-card-dashboard__title">Approved Requests</span>
<span class="oh-card-dashboard__title">{% trans "Approved Requests" %}</span>
</div>
<div class="oh-card-dashboard__body">
<div class="oh-card-dashboard__counts">
@@ -32,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--danger">
<div class="oh-card-dashboard oh-card-dashboard--danger filter" hx-get="{% url "request-filter" %}?status=cancelled&dashboard=true&employee_id={{request.user.employee_get.employee_first_name}}" hx-target="#dashboard">
<div class="oh-card-dashboard__header">
<span class="oh-card-dashboard__title">Rejected Requests</span>
<span class="oh-card-dashboard__title">{% trans "Rejected Requests" %}</span>
</div>
<div class="oh-card-dashboard__body">
<div class="oh-card-dashboard__counts">
@@ -49,9 +63,9 @@
<div class="col-12 col-sm-12 col-md-12 col-lg-4 mt-2">
<div class="oh-card-dashboard oh-card-dashboard--no-scale oh-card-dashboard--transparent">
<div class="oh-card-dashboard__header oh-card-dashboard__header--divider">
<span class="oh-card-dashboard__title" >Overall Conversions</span>
<span class="oh-card-dashboard__title" >{% trans "Available Leaves" %}</span>
</div>
<div class="oh-card-dashboard__body">
<div class="oh-card-dashboard__body" id="availableLeaveContainer">
<canvas id="availableLeave" ></canvas>
</div>
</div>
@@ -59,7 +73,7 @@
<div class="col-12 col-sm-12 col-md-12 col-lg-8">
<div class="oh-card-dashboard oh-card-dashboard--no-scale oh-card-dashboard--transparent">
<div class="oh-card-dashboard__header oh-card-dashboard__header--divider">
<span class="oh-card-dashboard__title">Total Leave Requests</span>
<span class="oh-card-dashboard__title">{% trans "Total Leave Requests" %}</span>
<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">
@@ -80,7 +94,7 @@
<img src="/static/images/ui/sunbed.png" class="oh-dashboard__event-userphoto" />
</div>
<div class="oh-dasboard__event-details">
<span class="oh-dashboard__event-title">Next Holiday</span>
<span class="oh-dashboard__event-title">{% trans "Next Holiday" %}</span>
<span class="oh-dashboard__event-main">{{next_holiday.name}}</span>
<span class="oh-dashboard__event-date">{{next_holiday.start_date}}</span>
</div>
@@ -89,7 +103,7 @@
<div class="oh-card-dashboard oh-card-dashboard--no-scale oh-card-dashboard--transparent mt-3">
<div class="oh-card-dashboard__header oh-card-dashboard__header--divider">
<span class="oh-card-dashboard__title">Up coming holidays</span>
<span class="oh-card-dashboard__title">{% trans "Up coming holidays" %}</span>
</div>
<div class="oh-card-dashboard__body">
<ul class="oh-card-dashboard__user-list">

View File

@@ -11,6 +11,22 @@
</div>
{% endif %}
{% include 'filter_tags.html' %}
{% if not dashboard %}
<div class="d-flex flex-row-reverse">
<span class="m-3 review_ongoing" hx-get="{% url "request-filter" %}?{{pd}}&status=cancelled" hx-target="#leaveRequest" style="cursor: pointer">
<span class="oh-dot oh-dot--small me-1" style="background-color:red"></span>
{% trans "Cancelled" %}
</span>
<span class="m-3 confirmed" hx-get="{% url "request-filter" %}?{{pd}}&status=requested" hx-target="#leaveRequest" style="cursor: pointer">
<span class="oh-dot oh-dot--small me-1" style="background-color:rgb(103, 171, 238)"></span>
{% trans "Requested" %}
</span>
<span class="m-3 paid" hx-get="{% url "request-filter" %}?{{pd}}&status=approved" hx-target="#leaveRequest" style="cursor: pointer">
<span class="oh-dot oh-dot--small me-1" style="background-color:yellowgreen"></span>
{% trans "Approved" %}
</span>
</div>
{% endif %}
<div class="oh-sticky-table">
<div class="oh-sticky-table__table ">
<div class="oh-sticky-table__thead">
@@ -31,15 +47,15 @@
{% 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 %}" hx-target="#requestView">
<div class="oh-sticky-table__sd" >
<div class="oh-sticky-table__sd {% if leave_request.status == "requested" %} row-status--blue {% elif leave_request.status == "approved" %} row-status--yellow {% elif leave_request.status == "cancelled" %} row-status--red{% endif %}" >
<div class="oh-profile oh-profile--md">
<div class="oh-profile__avatar mr-1">
{% if leave_request.employee_id.employee_profile %}
<img src="{{leave_request.employee_id.employee_profile.url}}" class="oh-profile__image"
alt="{{leave_request.employee_id}}" />
alt="" />
{% else %}
<img src="https://ui-avatars.com/api/?name={{leave_request.employee_id}}&background=random"
class="oh-profile__image" alt="{{leave_request.employee_id}}" />
class="oh-profile__image" alt="" />
{% endif %}
</div>
<span class="oh-profile__name oh-text--dark">{{leave_request.employee_id}}</span>

View File

@@ -289,10 +289,14 @@ def leave_request_filter(request):
if not request.GET.get("dashboard"):
data_dict = parse_qs(previous_data)
get_key_instances(LeaveRequest, data_dict)
if 'status' in data_dict:
status_list = data_dict['status']
if len(status_list) > 1:
data_dict['status'] = [status_list[-1]]
return render(
request,
"leave/leave_request/leave-requests.html",
{"leave_requests": page_obj, "pd": previous_data, "filter_dict": data_dict},
{"leave_requests": page_obj, "pd": previous_data, "filter_dict": data_dict,"dashboard":request.GET.get("dashboard")},
)
@@ -1515,7 +1519,7 @@ def dashboard(request):
approved=leave_requests.filter(status="approved")
cancelled=leave_requests.filter(status="cancelled")
holidays = Holiday.objects.filter(start_date__gte = today)
next_holiday = holidays[0] if holidays else None
next_holiday = holidays.order_by('start_date').first() if holidays.exists() else None
holidays = holidays.filter(start_date__gte = today,start_date__month=today.month).order_by('start_date')[1:]
@@ -1538,16 +1542,17 @@ def dashboard(request):
def employee_dashboard(request):
today = date.today()
user=Employee.objects.get(employee_user_id = request.user)
leave_requests = LeaveRequest.objects.filter(employee_id=user,start_date__month=today.month,start_date__year=today.year)
leave_requests = LeaveRequest.objects.filter(employee_id=user)
requested=leave_requests.filter(status="requested")
approved=leave_requests.filter(status="approved")
cancelled=leave_requests.filter(status="cancelled")
holidays = Holiday.objects.filter(start_date__gte = today,start_date__month=today.month).order_by('start_date')
next_holiday, holidays = (holidays[0], holidays[1:]) if holidays else (None, [])
holidays = Holiday.objects.filter(start_date__gte = today)
next_holiday = holidays.order_by('start_date').first() if holidays.exists() else None
holidays = holidays.filter(start_date__gte = today,start_date__month=today.month).order_by('start_date')[1:]
context = {
"leave_requests":leave_requests,
"leave_requests":leave_requests.filter(start_date__month=today.month,start_date__year=today.year),
"requested":requested,
"approved":approved,
"cancelled":cancelled,
@@ -1592,12 +1597,13 @@ def available_leave_chart(request):
response={
"labels":labels,
"dataset":dataset,
"message":_("Oops!! No leaves available for you this month...")
}
return JsonResponse(response)
@login_required
def employee_leave_chart(request):
leave_requests=LeaveRequest.objects.all()
leave_requests=LeaveRequest.objects.filter(status="approved")
leave_types = LeaveType.objects.all()
day = date.today()
if request.GET.get("date"):
@@ -1683,37 +1689,23 @@ def department_leave_chart(request):
@login_required
def leave_type_chart(request):
today=date.today()
leave_types=LeaveType.objects.all()
leave_type_count = {types.name: 0 for types in leave_types}
leave_request=LeaveRequest.objects.filter(status="approved")
company_leave_dates = company_leave_dates_list(CompanyLeave.objects.all(),datetime.today().replace(day=1))
holidays=holiday_dates_list(Holiday.objects.all())
for leave in leave_request:
leave_dates = []
for leave_date in leave.requested_dates():
leave_dates.append(leave_date)
filtered_dates = [date for date in leave_dates if date.month == today.month and date.year == today.year]
leave_type_dates = []
for filtered in filtered_dates:
if filtered not in company_leave_dates and filtered not in holidays:
leave_type_dates.append(filtered)
for lev in leave_types:
if lev ==leave.leave_type_id:
leave_type_count[lev.name] += len(leave_type_dates)
if lev ==leave.leave_type_id:
leave_type_count[lev.name] += leave.requested_days
labels= [leave_type.name for leave_type in leave_types]
dataset=[
{
"label":_(""),
"data":list(leave_type_count.values()),
},
]
response={
"labels":labels,
"dataset":dataset,
"dataset":[
{
"data":list(leave_type_count.values()),
},
],
}
return JsonResponse(response)

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB