|
|
|
@ -6,7 +6,7 @@ from django.contrib import messages
|
|
|
|
|
from .forms import *
|
|
|
|
|
from django.utils import timezone
|
|
|
|
|
from django.urls import reverse
|
|
|
|
|
from django.http import HttpResponse, HttpResponseServerError, Http404
|
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
from django.db.models import Q
|
|
|
|
|
from django.http import JsonResponse
|
|
|
|
|
from .models import Task, Epic
|
|
|
|
@ -75,16 +75,16 @@ def home(request, *args, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from django.db.models import Sum, F
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from django.db.models import Subquery, OuterRef
|
|
|
|
|
|
|
|
|
|
#Listing Pages
|
|
|
|
|
@login_required
|
|
|
|
|
def my_projects(request, *args, **kwargs):
|
|
|
|
|
user = request.user
|
|
|
|
|
|
|
|
|
|
if user.is_superuser:
|
|
|
|
|
# Superadmin can see all projects
|
|
|
|
|
# Superadmin can see all projects with total time worked on each project
|
|
|
|
|
projects = Project.objects.all().order_by('-project_id')
|
|
|
|
|
else:
|
|
|
|
|
# Non-superuser, filter projects where the user is either the manager or a member
|
|
|
|
@ -92,25 +92,25 @@ def my_projects(request, *args, **kwargs):
|
|
|
|
|
Q(manager=user.staffprofile) | Q(members=user.staffprofile)
|
|
|
|
|
).distinct().order_by('-project_id')
|
|
|
|
|
|
|
|
|
|
# Calculate total time for each project
|
|
|
|
|
for project in projects:
|
|
|
|
|
total_hours, total_minutes, total_seconds = 0, 0, 0
|
|
|
|
|
|
|
|
|
|
for task in project.task_set.all():
|
|
|
|
|
for point in task.point_set.all():
|
|
|
|
|
hours, minutes, seconds = point.total_time()
|
|
|
|
|
total_hours += hours
|
|
|
|
|
total_minutes += minutes
|
|
|
|
|
total_seconds += seconds
|
|
|
|
|
total_time_seconds = 0
|
|
|
|
|
# Modify task queryset based on user role
|
|
|
|
|
if user.is_superuser:
|
|
|
|
|
tasks = project.task_set.all()
|
|
|
|
|
else:
|
|
|
|
|
tasks = project.task_set.filter(assigned_to=user.staffprofile)
|
|
|
|
|
|
|
|
|
|
# Convert excess seconds to minutes and excess minutes to hours
|
|
|
|
|
total_minutes += total_seconds // 60
|
|
|
|
|
total_seconds %= 60
|
|
|
|
|
total_hours += total_minutes // 60
|
|
|
|
|
total_minutes %= 60
|
|
|
|
|
for task in tasks:
|
|
|
|
|
total_time_hours, total_time_minutes, total_time_seconds_task = task.total_task_time()
|
|
|
|
|
total_time_seconds += (total_time_hours * 3600) + (total_time_minutes * 60) + total_time_seconds_task
|
|
|
|
|
|
|
|
|
|
project.total_time = f"{total_hours}hr {total_minutes}min {total_seconds}sec"
|
|
|
|
|
total_time_hours = total_time_seconds // 3600
|
|
|
|
|
total_time_minutes = (total_time_seconds % 3600) // 60
|
|
|
|
|
total_time_seconds = total_time_seconds % 60
|
|
|
|
|
|
|
|
|
|
project.total_time_worked_hours = total_time_hours
|
|
|
|
|
project.total_time_worked_minutes = total_time_minutes
|
|
|
|
|
project.total_time_worked_seconds = total_time_seconds
|
|
|
|
|
|
|
|
|
|
context = {
|
|
|
|
|
'projects': projects,
|
|
|
|
@ -119,6 +119,9 @@ def my_projects(request, *args, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def my_tasks(request, *args, **kwargs):
|
|
|
|
|
if request.user.is_superuser:
|
|
|
|
@ -1822,27 +1825,26 @@ def mark_point_working_on_task_page(request, point_id, task_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def mark_point_paused(request, point_id, task_id):
|
|
|
|
|
task = get_object_or_404(Task, id=task_id)
|
|
|
|
|
point = get_object_or_404(Point, id=point_id)
|
|
|
|
|
point.status = 'Paused'
|
|
|
|
|
current_datetime = datetime.now()
|
|
|
|
|
|
|
|
|
|
current_datetime = timezone.now()
|
|
|
|
|
|
|
|
|
|
point.save()
|
|
|
|
|
|
|
|
|
|
last_activity = PointActivity.objects.filter(point=point).last()
|
|
|
|
|
last_activity.end_time = datetime.now()
|
|
|
|
|
last_activity.save()
|
|
|
|
|
|
|
|
|
|
if last_activity:
|
|
|
|
|
last_activity.end_time = current_datetime
|
|
|
|
|
last_activity.save()
|
|
|
|
|
|
|
|
|
|
status_text = f'{point.text} - Paused'
|
|
|
|
|
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
|
|
|
|
|
status.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
task_id_str = task.task_id
|
|
|
|
|
|
|
|
|
|
showpoints_url = reverse('showpoints', args=[task_id_str])
|
|
|
|
@ -1852,31 +1854,33 @@ def mark_point_paused(request, point_id, task_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def mark_point_completed(request, point_id, task_id):
|
|
|
|
|
task = get_object_or_404(Task, id=task_id)
|
|
|
|
|
point = get_object_or_404(Point, id=point_id)
|
|
|
|
|
point.status = 'Completed'
|
|
|
|
|
current_datetime = datetime.now()
|
|
|
|
|
|
|
|
|
|
current_datetime = timezone.now()
|
|
|
|
|
|
|
|
|
|
point.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Update the end time of the last activity to the current time
|
|
|
|
|
last_activity = PointActivity.objects.filter(point=point).last()
|
|
|
|
|
if last_activity:
|
|
|
|
|
last_activity.end_time = datetime.now()
|
|
|
|
|
last_activity.end_time = current_datetime
|
|
|
|
|
last_activity.save()
|
|
|
|
|
|
|
|
|
|
total_time = point.total_time()
|
|
|
|
|
|
|
|
|
|
total_time_hours, total_time_minutes, total_time_seconds = point.total_activity_time()
|
|
|
|
|
|
|
|
|
|
formatted_time = ""
|
|
|
|
|
if total_time[0] > 0:
|
|
|
|
|
formatted_time += f"{total_time[0]}{'hr' if total_time[0] == 1 else 'hrs'}"
|
|
|
|
|
if total_time[1] > 0:
|
|
|
|
|
formatted_time += f" {total_time[1]}{'min' if total_time[1] == 1 else 'mins'}"
|
|
|
|
|
if total_time[2] > 0:
|
|
|
|
|
formatted_time += f" {total_time[2]}{'sec' if total_time[2] == 1 else 'secs'}"
|
|
|
|
|
if total_time_hours > 0:
|
|
|
|
|
formatted_time += f"{total_time_hours}{'hr' if total_time_hours == 1 else 'hrs'}"
|
|
|
|
|
if total_time_minutes > 0:
|
|
|
|
|
formatted_time += f" {total_time_minutes}{'min' if total_time_minutes == 1 else 'mins'}"
|
|
|
|
|
if total_time_seconds > 0:
|
|
|
|
|
formatted_time += f" {total_time_seconds}{'sec' if total_time_seconds == 1 else 'secs'}"
|
|
|
|
|
|
|
|
|
|
status_text = f'{point.text} - Completed'
|
|
|
|
|
if formatted_time:
|
|
|
|
@ -1920,9 +1924,6 @@ def mark_point_completed_task_page(request, point_id, task_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# CUSTOMER DASHBOARD
|
|
|
|
|
@login_required
|
|
|
|
|
def customer_index(request, *args, **kwargs):
|
|
|
|
|