Prepare ERP source for Gitea deployment
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Manager workspace UI module."""
|
||||
@@ -0,0 +1,12 @@
|
||||
{% set manager_path = request.url.path %}
|
||||
<div class="mb-6 overflow-x-auto rounded-2xl border border-slate-200 bg-white p-2 shadow-soft">
|
||||
<div class="flex min-w-max items-center gap-2">
|
||||
<a href="/manager/dashboard" class="rounded-xl px-4 py-2 text-sm font-semibold transition {% if manager_path == '/manager/dashboard' %}bg-brand-600 text-white{% else %}text-slate-700 hover:bg-slate-100{% endif %}">Overview</a>
|
||||
<a href="/manager/work" class="rounded-xl px-4 py-2 text-sm font-semibold transition {% if manager_path.startswith('/manager/work') %}bg-brand-600 text-white{% else %}text-slate-700 hover:bg-slate-100{% endif %}">Team Work Board</a>
|
||||
<a href="/employees/work" class="rounded-xl px-4 py-2 text-sm font-semibold transition {% if manager_path.startswith('/employees/work') %}bg-brand-600 text-white{% else %}text-slate-700 hover:bg-slate-100{% endif %}">Detailed Allocation</a>
|
||||
<a href="/employees/progress" class="rounded-xl px-4 py-2 text-sm font-semibold transition {% if manager_path.startswith('/employees/progress') %}bg-brand-600 text-white{% else %}text-slate-700 hover:bg-slate-100{% endif %}">Engagement Progress</a>
|
||||
<a href="/employees/attendance" class="rounded-xl px-4 py-2 text-sm font-semibold transition {% if manager_path.startswith('/employees/attendance') %}bg-brand-600 text-white{% else %}text-slate-700 hover:bg-slate-100{% endif %}">Team Attendance</a>
|
||||
<a href="/employees/leave" class="rounded-xl px-4 py-2 text-sm font-semibold transition {% if manager_path.startswith('/employees/leave') %}bg-brand-600 text-white{% else %}text-slate-700 hover:bg-slate-100{% endif %}">Team Leave</a>
|
||||
<a href="/alerts" class="rounded-xl px-4 py-2 text-sm font-semibold transition {% if manager_path.startswith('/alerts') %}bg-brand-600 text-white{% else %}text-slate-700 hover:bg-slate-100{% endif %}">My Alert</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,92 @@
|
||||
{% extends "ui/templates/base/layout.html" %}
|
||||
{% block content %}
|
||||
{% include "modules/managers/templates/managers/_manager_tabs.html" %}
|
||||
<div class="space-y-6">
|
||||
<section class="rounded-3xl bg-gradient-to-r from-slate-900 via-brand-700 to-brand-600 p-6 text-white shadow-soft">
|
||||
<div class="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
|
||||
<div>
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.22em] text-brand-100">Team Workspace</p>
|
||||
<h2 class="mt-2 text-2xl font-semibold">Allocation, follow-up and team execution control</h2>
|
||||
<p class="mt-2 max-w-3xl text-sm text-brand-100">Focus on unassigned work, blocked assignments, due dates, team attendance and review-ready tasks.</p>
|
||||
{% if current_user_roles and ('Partner' in current_user_roles or 'Firm Admin' in current_user_roles) %}
|
||||
<p class="mt-3 inline-flex rounded-full bg-white/10 px-3 py-1 text-xs font-semibold text-white">Multi-role view enabled: partner/admin responsibilities may also apply.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<a href="/manager/work" class="rounded-xl bg-white px-4 py-2 text-sm font-semibold text-brand-700 hover:bg-brand-50">Open Team Work Board</a>
|
||||
{% if current_user_roles and 'Partner' in current_user_roles %}<a href="/partner/dashboard" class="rounded-xl border border-white/40 px-4 py-2 text-sm font-semibold text-white hover:bg-white/10">Partner Dashboard</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="grid gap-4 md:grid-cols-2 xl:grid-cols-6">
|
||||
<a href="/manager/work" class="af-metric-card hover:border-brand-200"><div class="text-xs font-semibold uppercase text-slate-500">Total Tasks</div><div class="mt-2 text-3xl font-semibold text-slate-900">{{ payload.summary.total }}</div><div class="mt-1 text-xs text-slate-500">All visible work</div></a>
|
||||
<a href="/manager/work?status=unassigned" class="af-metric-card border-orange-200 bg-orange-50 hover:border-orange-300"><div class="text-xs font-semibold uppercase text-orange-700">Unassigned</div><div class="mt-2 text-3xl font-semibold text-orange-700">{{ payload.summary.unassigned }}</div><div class="mt-1 text-xs text-orange-700">Allocate first</div></a>
|
||||
<a href="/manager/work?status=in_progress" class="af-metric-card border-blue-200 bg-blue-50 hover:border-blue-300"><div class="text-xs font-semibold uppercase text-blue-700">In Progress</div><div class="mt-2 text-3xl font-semibold text-blue-700">{{ payload.summary.in_progress }}</div><div class="mt-1 text-xs text-blue-700">Being worked</div></a>
|
||||
<a href="/manager/work?status=blocked" class="af-metric-card border-amber-200 bg-amber-50 hover:border-amber-300"><div class="text-xs font-semibold uppercase text-amber-700">Blocked</div><div class="mt-2 text-3xl font-semibold text-amber-700">{{ payload.summary.blocked }}</div><div class="mt-1 text-xs text-amber-700">Needs help</div></a>
|
||||
<a href="/manager/work?date_bucket=overdue" class="af-metric-card border-red-200 bg-red-50 hover:border-red-300"><div class="text-xs font-semibold uppercase text-red-700">Overdue</div><div class="mt-2 text-3xl font-semibold text-red-700">{{ payload.summary.overdue }}</div><div class="mt-1 text-xs text-red-700">Escalate</div></a>
|
||||
<a href="/employees/progress" class="af-metric-card border-emerald-200 bg-emerald-50 hover:border-emerald-300"><div class="text-xs font-semibold uppercase text-emerald-700">Completed</div><div class="mt-2 text-3xl font-semibold text-emerald-700">{{ payload.summary.completed }}</div><div class="mt-1 text-xs text-emerald-700">Closed tasks</div></a>
|
||||
</section>
|
||||
|
||||
<section class="grid gap-6 xl:grid-cols-[minmax(0,1fr)_380px]">
|
||||
<div class="af-card">
|
||||
<div class="mb-5 flex items-center justify-between gap-3">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-slate-900">Attention Required</h3>
|
||||
<p class="mt-1 text-sm text-slate-500">Unassigned, blocked and overdue work should be handled first.</p>
|
||||
</div>
|
||||
<a href="/manager/work" class="af-btn af-btn-primary">View All</a>
|
||||
</div>
|
||||
<div class="space-y-5">
|
||||
{% set shown = namespace(count=0) %}
|
||||
{% for column in payload.columns %}
|
||||
{% if column.code in ['unassigned', 'blocked'] and column.tasks %}
|
||||
<div>
|
||||
<div class="mb-2 flex items-center justify-between"><div class="text-xs font-semibold uppercase tracking-wide text-slate-500">{{ column.label }}</div><div class="text-xs text-slate-400">{{ column.tasks|length }} item(s)</div></div>
|
||||
<div class="grid gap-3 lg:grid-cols-2">
|
||||
{% for task in column.tasks[:6] %}
|
||||
{% set shown.count = shown.count + 1 %}
|
||||
<div class="rounded-2xl border border-slate-200 p-4 {% if task.is_overdue %}bg-red-50{% elif task.is_due_today %}bg-amber-50{% else %}bg-slate-50{% endif %}">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<div class="font-semibold text-slate-900">{{ task.task_name }}</div>
|
||||
<div class="mt-1 text-xs text-slate-500">{{ task.client_display }} · {{ task.engagement_label }}</div>
|
||||
<div class="mt-1 text-xs text-slate-500">Target: {{ task.internal_target_date or '-' }} · {{ task.date_bucket }}</div>
|
||||
</div>
|
||||
<a href="/employees/work/tasks/{{ task.id }}/communication" class="rounded-lg border border-slate-300 bg-white px-2.5 py-1 text-xs font-semibold text-slate-700 hover:bg-slate-50">Timeline</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if shown.count == 0 %}<div class="rounded-2xl border border-dashed border-slate-300 p-8 text-center text-sm text-slate-600">No team assignments require manager attention right now.</div>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<aside class="space-y-6">
|
||||
<div class="af-card">
|
||||
<h3 class="font-semibold text-slate-900">Team Snapshot</h3>
|
||||
<div class="mt-4 grid grid-cols-2 gap-3 text-sm">
|
||||
<div class="rounded-2xl bg-slate-50 p-4"><div class="text-xs text-slate-500">Clients touched</div><div class="mt-1 text-2xl font-semibold">{{ payload.summary.clients }}</div></div>
|
||||
<div class="rounded-2xl bg-slate-50 p-4"><div class="text-xs text-slate-500">Active assignees</div><div class="mt-1 text-2xl font-semibold">{{ payload.summary.assignees }}</div></div>
|
||||
<div class="rounded-2xl bg-amber-50 p-4"><div class="text-xs text-amber-700">Due today</div><div class="mt-1 text-2xl font-semibold text-amber-700">{{ payload.summary.due_today }}</div></div>
|
||||
<div class="rounded-2xl bg-brand-50 p-4"><div class="text-xs text-brand-700">Open tasks</div><div class="mt-1 text-2xl font-semibold text-brand-700">{{ payload.summary.open }}</div></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="af-card">
|
||||
<h3 class="font-semibold text-slate-900">Manager Actions</h3>
|
||||
<div class="mt-4 space-y-2">
|
||||
<a href="/manager/work" class="block rounded-xl border border-slate-200 px-4 py-3 text-sm font-semibold text-slate-700 hover:bg-slate-50">Allocate or reassign work</a>
|
||||
<a href="/employees/progress" class="block rounded-xl border border-slate-200 px-4 py-3 text-sm font-semibold text-slate-700 hover:bg-slate-50">Review engagement progress</a>
|
||||
<a href="/employees/attendance" class="block rounded-xl border border-slate-200 px-4 py-3 text-sm font-semibold text-slate-700 hover:bg-slate-50">Check team attendance</a>
|
||||
<a href="/employees/leave" class="block rounded-xl border border-slate-200 px-4 py-3 text-sm font-semibold text-slate-700 hover:bg-slate-50">Review leave requests</a>
|
||||
{% if current_user_roles and 'Partner' in current_user_roles %}<a href="/partner/reviews" class="block rounded-xl border border-brand-200 bg-brand-50 px-4 py-3 text-sm font-semibold text-brand-700 hover:bg-brand-100">Open partner review board</a>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
</section>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,90 @@
|
||||
{% extends "ui/templates/base/layout.html" %}
|
||||
{% block content %}
|
||||
{% include "modules/managers/templates/managers/_manager_tabs.html" %}
|
||||
<div class="space-y-6">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<h2 class="text-2xl font-semibold text-slate-900">Team Work Board</h2>
|
||||
<p class="mt-1 text-sm text-slate-500">Assign, monitor and follow up on engagement/service tasks by operational status.</p>
|
||||
</div>
|
||||
<a href="/employees/work" class="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700 hover:bg-slate-50">Open Detailed Allocation</a>
|
||||
</div>
|
||||
|
||||
<form method="get" action="/manager/work" class="rounded-2xl border border-slate-200 bg-white p-4 shadow-soft">
|
||||
<div class="grid gap-3 md:grid-cols-[1fr_260px_auto]">
|
||||
<input type="search" name="q" value="{{ q or '' }}" placeholder="Search task, client or engagement" class="rounded-xl border border-slate-300 px-3 py-2 text-sm focus:border-brand-500 focus:outline-none focus:ring-2 focus:ring-brand-100">
|
||||
<select name="assigned_to_user_id" class="rounded-xl border border-slate-300 px-3 py-2 text-sm">
|
||||
<option value="0">All assignees</option>
|
||||
{% for user in assignable_users %}
|
||||
<option value="{{ user.id }}" {% if selected_assigned_to_user_id == user.id %}selected{% endif %}>{{ user.full_name or user.email }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button type="submit" class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-semibold text-white hover:bg-brand-700">Filter</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2 xl:grid-cols-5">
|
||||
{% for column in payload.columns %}
|
||||
<section class="min-h-[420px] rounded-2xl border border-slate-200 bg-slate-50 p-3 shadow-soft">
|
||||
<div class="mb-3 flex items-start justify-between gap-2">
|
||||
<div>
|
||||
<h3 class="font-semibold text-slate-900">{{ column.label }}</h3>
|
||||
<p class="text-xs text-slate-500">{{ column.hint }}</p>
|
||||
</div>
|
||||
<span class="rounded-full bg-white px-2.5 py-1 text-xs font-semibold text-slate-700">{{ column.count }}</span>
|
||||
</div>
|
||||
<div class="space-y-3">
|
||||
{% for task in column.tasks %}
|
||||
<article class="rounded-xl border border-slate-200 bg-white p-3 shadow-sm {% if task.is_overdue %}ring-1 ring-red-200{% elif task.is_due_today %}ring-1 ring-amber-200{% endif %}">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<div>
|
||||
<div class="text-sm font-semibold text-slate-900">{{ task.task_name }}</div>
|
||||
<div class="mt-1 text-xs text-slate-500">{{ task.client_display }}</div>
|
||||
<div class="mt-1 text-xs text-slate-500">{{ task.engagement_label }}</div>
|
||||
</div>
|
||||
{% if task.is_overdue %}<span class="rounded-full bg-red-100 px-2 py-0.5 text-[10px] font-semibold text-red-700">Overdue</span>{% elif task.is_due_today %}<span class="rounded-full bg-amber-100 px-2 py-0.5 text-[10px] font-semibold text-amber-700">Today</span>{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="mt-3 grid grid-cols-2 gap-2 text-xs text-slate-600">
|
||||
<div><span class="font-semibold">Status:</span> {{ task.status_label }}</div>
|
||||
<div><span class="font-semibold">Priority:</span> {{ task.priority_label }}</div>
|
||||
<div class="col-span-2"><span class="font-semibold">Assigned:</span> {{ task.assignee_display }}</div>
|
||||
<div class="col-span-2"><span class="font-semibold">Target:</span> {{ task.internal_target_date or '-' }} · {{ task.date_bucket }}</div>
|
||||
</div>
|
||||
|
||||
<form method="post" action="/employees/work/tasks/{{ task.id }}/assign" class="mt-3 space-y-2 rounded-xl border border-slate-100 bg-slate-50 p-2">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<input type="hidden" name="return_url" value="/manager/work{% if q or selected_assigned_to_user_id %}?q={{ q|urlencode }}&assigned_to_user_id={{ selected_assigned_to_user_id or 0 }}{% endif %}">
|
||||
<select name="assigned_to_user_id" class="w-full rounded-lg border border-slate-300 px-2 py-1.5 text-xs">
|
||||
<option value="">Unassigned</option>
|
||||
{% for user in assignable_users %}
|
||||
<option value="{{ user.id }}" {% if task.assigned_to_user_id == user.id %}selected{% endif %}>{{ user.full_name or user.email }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<select name="status" class="rounded-lg border border-slate-300 px-2 py-1.5 text-xs">
|
||||
{% for code, label in task_statuses %}<option value="{{ code }}" {% if task.status == code %}selected{% endif %}>{{ label }}</option>{% endfor %}
|
||||
</select>
|
||||
<select name="priority" class="rounded-lg border border-slate-300 px-2 py-1.5 text-xs">
|
||||
{% for code, label in task_priorities %}<option value="{{ code }}" {% if task.priority == code %}selected{% endif %}>{{ label }}</option>{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<input type="date" name="internal_target_date" value="{{ task.internal_target_date or '' }}" class="w-full rounded-lg border border-slate-300 px-2 py-1.5 text-xs">
|
||||
<textarea name="remarks" rows="2" placeholder="Manager note / allocation remark" class="w-full rounded-lg border border-slate-300 px-2 py-1.5 text-xs">{{ task.remarks or '' }}</textarea>
|
||||
<button type="submit" class="w-full rounded-lg bg-brand-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-brand-700">Save Allocation</button>
|
||||
</form>
|
||||
|
||||
<div class="mt-3 flex items-center justify-between gap-2">
|
||||
<a href="/employees/work/tasks/{{ task.id }}/communication" class="rounded-lg border border-slate-300 px-2.5 py-1 text-xs font-semibold text-slate-700 hover:bg-slate-50">Timeline{% if task.comment_count %} · {{ task.comment_count }}{% endif %}</a>
|
||||
{% if task.subscription_id %}<a href="/work/engagements/{{ task.subscription_id }}" class="rounded-lg border border-slate-300 px-2.5 py-1 text-xs font-semibold text-slate-700 hover:bg-slate-50">Work Details</a>{% endif %}
|
||||
</div>
|
||||
</article>
|
||||
{% else %}
|
||||
<div class="rounded-xl border border-dashed border-slate-300 bg-white p-4 text-center text-sm text-slate-500">No tasks</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,287 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Request
|
||||
from fastapi.responses import RedirectResponse
|
||||
from sqlalchemy import or_, select
|
||||
from sqlalchemy.orm import Session, selectinload
|
||||
|
||||
from app.core.db.common import CommonSessionLocal
|
||||
from app.core.security.csrf import get_or_create_csrf_token
|
||||
from app.core.security.session_auth import get_current_user
|
||||
from app.core.templating import templates
|
||||
from app.modules.core.rbac.deps import get_user_permissions, get_user_roles
|
||||
from app.modules.core.rbac.permission_guard import require_permission
|
||||
from app.modules.employees.service import (
|
||||
build_employee_scope,
|
||||
list_employee_work_assignable_users,
|
||||
)
|
||||
from app.modules.services.execution import CLOSED_TASK_STATUSES, TASK_PRIORITIES, TASK_STATUSES
|
||||
from app.modules.services.models import ClientServiceSubscription, ClientServiceTaskInstance, ServiceCatalogue, ServiceTaskComment
|
||||
from app.modules.clients.models import Client
|
||||
|
||||
router = APIRouter(prefix="/manager", tags=["manager-workspace-ui"])
|
||||
|
||||
|
||||
def _redirect_login():
|
||||
return RedirectResponse(url="/login", status_code=303)
|
||||
|
||||
|
||||
def _redirect_denied():
|
||||
return RedirectResponse(url="/employee/dashboard", status_code=303)
|
||||
|
||||
|
||||
def _base_ctx(request: Request, db: Session, current_user, **ctx):
|
||||
base = {
|
||||
"request": request,
|
||||
"current_user": current_user,
|
||||
"current_user_roles": get_user_roles(db, current_user.id),
|
||||
"current_user_permissions": get_user_permissions(db, current_user.id),
|
||||
"csrf_token": get_or_create_csrf_token(request),
|
||||
"task_statuses": TASK_STATUSES,
|
||||
"task_priorities": TASK_PRIORITIES,
|
||||
}
|
||||
base.update(ctx)
|
||||
return base
|
||||
|
||||
|
||||
def _render(request: Request, template_name: str, db: Session, current_user, **ctx):
|
||||
return templates.TemplateResponse(template_name, _base_ctx(request, db, current_user, **ctx))
|
||||
|
||||
|
||||
def _task_status_label(task: ClientServiceTaskInstance) -> str:
|
||||
return dict(TASK_STATUSES).get(getattr(task, "status", ""), (getattr(task, "status", "") or "-").replace("_", " ").title())
|
||||
|
||||
|
||||
def _task_priority_label(task: ClientServiceTaskInstance) -> str:
|
||||
return dict(TASK_PRIORITIES).get(getattr(task, "priority", ""), (getattr(task, "priority", "") or "normal").replace("_", " ").title())
|
||||
|
||||
|
||||
|
||||
|
||||
def _active_financial_year(request: Request) -> str | None:
|
||||
value = request.session.get("active_financial_year") or getattr(request.state, "year_code", None)
|
||||
value = (value or "").strip()
|
||||
return value or None
|
||||
|
||||
def _subscription_label(subscription: ClientServiceSubscription | None, task: ClientServiceTaskInstance) -> str:
|
||||
catalogue = getattr(subscription, "catalogue", None) if subscription else getattr(task, "catalogue", None)
|
||||
service_name = getattr(catalogue, "service_name", None) or getattr(catalogue, "name", None) or getattr(task, "task_name", "Engagement")
|
||||
fy = getattr(subscription, "financial_year", None) or getattr(task, "financial_year", None)
|
||||
return f"{service_name} · FY {fy}" if fy else str(service_name)
|
||||
|
||||
|
||||
def _date_bucket(task: ClientServiceTaskInstance, today: date) -> str:
|
||||
target = getattr(task, "internal_target_date", None)
|
||||
if not target:
|
||||
return "No target date"
|
||||
if target < today and (task.status or "") not in CLOSED_TASK_STATUSES:
|
||||
return "Overdue"
|
||||
if target == today and (task.status or "") not in CLOSED_TASK_STATUSES:
|
||||
return "Due today"
|
||||
if target > today and (task.status or "") not in CLOSED_TASK_STATUSES:
|
||||
return "Upcoming"
|
||||
return "Closed"
|
||||
|
||||
|
||||
def _manager_task_query(db: Session, scope, *, q: str = "", assigned_to_user_id: int | None = None, financial_year: str | None = None):
|
||||
stmt = (
|
||||
select(ClientServiceTaskInstance)
|
||||
.options(
|
||||
selectinload(ClientServiceTaskInstance.client),
|
||||
selectinload(ClientServiceTaskInstance.catalogue),
|
||||
selectinload(ClientServiceTaskInstance.subscription).selectinload(ClientServiceSubscription.catalogue),
|
||||
selectinload(ClientServiceTaskInstance.subscription).selectinload(ClientServiceSubscription.assigned_partner),
|
||||
selectinload(ClientServiceTaskInstance.subscription).selectinload(ClientServiceSubscription.assigned_manager),
|
||||
selectinload(ClientServiceTaskInstance.subscription).selectinload(ClientServiceSubscription.assigned_staff),
|
||||
selectinload(ClientServiceTaskInstance.assigned_to),
|
||||
selectinload(ClientServiceTaskInstance.comments).selectinload(ServiceTaskComment.created_by),
|
||||
)
|
||||
.where(
|
||||
ClientServiceTaskInstance.tenant_id == scope.tenant_id,
|
||||
ClientServiceTaskInstance.is_active.is_(True),
|
||||
)
|
||||
)
|
||||
if scope.branch_id is not None:
|
||||
stmt = stmt.where(ClientServiceTaskInstance.branch_id == scope.branch_id)
|
||||
if financial_year:
|
||||
stmt = stmt.where(ClientServiceTaskInstance.financial_year == financial_year.strip())
|
||||
if assigned_to_user_id:
|
||||
stmt = stmt.where(ClientServiceTaskInstance.assigned_to_user_id == int(assigned_to_user_id))
|
||||
if q.strip():
|
||||
like = f"%{q.strip()}%"
|
||||
stmt = stmt.where(
|
||||
or_(
|
||||
ClientServiceTaskInstance.task_name.ilike(like),
|
||||
ClientServiceTaskInstance.description.ilike(like),
|
||||
ClientServiceTaskInstance.client.has(or_(Client.client_name.ilike(like), Client.client_code.ilike(like))),
|
||||
ClientServiceTaskInstance.catalogue.has(or_(ServiceCatalogue.service_name.ilike(like), ServiceCatalogue.service_code.ilike(like))),
|
||||
)
|
||||
)
|
||||
return db.execute(
|
||||
stmt.order_by(
|
||||
ClientServiceTaskInstance.internal_target_date.is_(None),
|
||||
ClientServiceTaskInstance.internal_target_date.asc(),
|
||||
ClientServiceTaskInstance.priority.desc(),
|
||||
ClientServiceTaskInstance.sequence_no.asc(),
|
||||
ClientServiceTaskInstance.id.desc(),
|
||||
)
|
||||
).scalars().all()
|
||||
|
||||
|
||||
def build_manager_workspace_payload(db: Session, scope, *, q: str = "", assigned_to_user_id: int | None = None, financial_year: str | None = None) -> dict[str, Any]:
|
||||
today = date.today()
|
||||
tasks = _manager_task_query(db, scope, q=q, assigned_to_user_id=assigned_to_user_id, financial_year=financial_year)
|
||||
|
||||
columns = [
|
||||
{"code": "unassigned", "label": "Unassigned", "hint": "Needs manager allocation", "tasks": []},
|
||||
{"code": "assigned", "label": "Assigned", "hint": "Assigned but not started", "tasks": []},
|
||||
{"code": "in_progress", "label": "In Progress", "hint": "Currently being worked on", "tasks": []},
|
||||
{"code": "blocked", "label": "Blocked", "hint": "Needs intervention", "tasks": []},
|
||||
{"code": "ready_review", "label": "Completed / Review", "hint": "Completed by staff, review if required", "tasks": []},
|
||||
]
|
||||
lookup = {c["code"]: c for c in columns}
|
||||
summary = {
|
||||
"total": len(tasks),
|
||||
"unassigned": 0,
|
||||
"open": 0,
|
||||
"in_progress": 0,
|
||||
"blocked": 0,
|
||||
"completed": 0,
|
||||
"overdue": 0,
|
||||
"due_today": 0,
|
||||
"clients": set(),
|
||||
"assignees": set(),
|
||||
}
|
||||
|
||||
for task in tasks:
|
||||
status = (task.status or "pending").strip().lower()
|
||||
is_closed = status in CLOSED_TASK_STATUSES
|
||||
target = getattr(task, "internal_target_date", None)
|
||||
client = getattr(task, "client", None)
|
||||
assignee = getattr(task, "assigned_to", None)
|
||||
subscription = getattr(task, "subscription", None)
|
||||
|
||||
if client and getattr(client, "id", None):
|
||||
summary["clients"].add(client.id)
|
||||
if assignee and getattr(assignee, "id", None):
|
||||
summary["assignees"].add(assignee.id)
|
||||
if not is_closed:
|
||||
summary["open"] += 1
|
||||
if not getattr(task, "assigned_to_user_id", None) and not is_closed:
|
||||
summary["unassigned"] += 1
|
||||
if status == "in_progress":
|
||||
summary["in_progress"] += 1
|
||||
if status == "blocked":
|
||||
summary["blocked"] += 1
|
||||
if status == "completed":
|
||||
summary["completed"] += 1
|
||||
if target and target < today and not is_closed:
|
||||
summary["overdue"] += 1
|
||||
if target and target == today and not is_closed:
|
||||
summary["due_today"] += 1
|
||||
|
||||
task.status_label = _task_status_label(task)
|
||||
task.priority_label = _task_priority_label(task)
|
||||
task.date_bucket = _date_bucket(task, today)
|
||||
task.is_overdue = bool(target and target < today and not is_closed)
|
||||
task.is_due_today = bool(target and target == today and not is_closed)
|
||||
task.engagement_label = _subscription_label(subscription, task)
|
||||
task.client_display = getattr(client, "client_name", None) or "Unlinked Client"
|
||||
task.client_code_display = getattr(client, "client_code", None) or ""
|
||||
task.assignee_display = getattr(assignee, "full_name", None) or getattr(assignee, "email", None) or "Unassigned"
|
||||
task.comment_count = len([c for c in getattr(task, "comments", []) if not getattr(c, "is_deleted", False)])
|
||||
|
||||
if not getattr(task, "assigned_to_user_id", None) and not is_closed:
|
||||
bucket = "unassigned"
|
||||
elif status == "pending":
|
||||
bucket = "assigned"
|
||||
elif status == "in_progress":
|
||||
bucket = "in_progress"
|
||||
elif status == "blocked":
|
||||
bucket = "blocked"
|
||||
else:
|
||||
bucket = "ready_review"
|
||||
lookup[bucket]["tasks"].append(task)
|
||||
|
||||
summary["clients"] = len(summary["clients"])
|
||||
summary["assignees"] = len(summary["assignees"])
|
||||
for column in columns:
|
||||
column["count"] = len(column["tasks"])
|
||||
return {"summary": summary, "columns": columns, "q": q, "selected_assigned_to_user_id": assigned_to_user_id, "today": today, "financial_year": financial_year}
|
||||
|
||||
|
||||
@router.get("/dashboard")
|
||||
def manager_dashboard(request: Request, q: str = "", assigned_to_user_id: int = 0):
|
||||
db = CommonSessionLocal()
|
||||
try:
|
||||
current_user = get_current_user(request, db=db)
|
||||
if not current_user:
|
||||
return _redirect_login()
|
||||
try:
|
||||
require_permission(db, current_user, "employees.work.manage")
|
||||
except Exception:
|
||||
return _redirect_denied()
|
||||
scope = build_employee_scope(
|
||||
db,
|
||||
current_user,
|
||||
tenant_id=request.session.get("active_tenant_id") or current_user.tenant_id,
|
||||
branch_id=request.session.get("active_branch_id"),
|
||||
)
|
||||
assignee_id = int(assigned_to_user_id or 0) or None
|
||||
financial_year = _active_financial_year(request)
|
||||
payload = build_manager_workspace_payload(db, scope, q=q, assigned_to_user_id=assignee_id, financial_year=financial_year)
|
||||
return _render(
|
||||
request,
|
||||
"modules/managers/templates/managers/dashboard.html",
|
||||
db,
|
||||
current_user,
|
||||
title="Manager Workspace",
|
||||
payload=payload,
|
||||
assignable_users=list_employee_work_assignable_users(db, scope),
|
||||
q=q,
|
||||
selected_assigned_to_user_id=assignee_id,
|
||||
errors=[],
|
||||
financial_year=financial_year,
|
||||
)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@router.get("/work")
|
||||
def manager_work_board(request: Request, q: str = "", assigned_to_user_id: int = 0):
|
||||
db = CommonSessionLocal()
|
||||
try:
|
||||
current_user = get_current_user(request, db=db)
|
||||
if not current_user:
|
||||
return _redirect_login()
|
||||
try:
|
||||
require_permission(db, current_user, "employees.work.manage")
|
||||
except Exception:
|
||||
return _redirect_denied()
|
||||
scope = build_employee_scope(
|
||||
db,
|
||||
current_user,
|
||||
tenant_id=request.session.get("active_tenant_id") or current_user.tenant_id,
|
||||
branch_id=request.session.get("active_branch_id"),
|
||||
)
|
||||
assignee_id = int(assigned_to_user_id or 0) or None
|
||||
financial_year = _active_financial_year(request)
|
||||
payload = build_manager_workspace_payload(db, scope, q=q, assigned_to_user_id=assignee_id, financial_year=financial_year)
|
||||
return _render(
|
||||
request,
|
||||
"modules/managers/templates/managers/work_board.html",
|
||||
db,
|
||||
current_user,
|
||||
title="Team Work Board",
|
||||
payload=payload,
|
||||
assignable_users=list_employee_work_assignable_users(db, scope),
|
||||
q=q,
|
||||
selected_assigned_to_user_id=assignee_id,
|
||||
errors=[],
|
||||
financial_year=financial_year,
|
||||
)
|
||||
finally:
|
||||
db.close()
|
||||
Reference in New Issue
Block a user