Filter partner workload to staff and managers
This commit is contained in:
@@ -258,10 +258,23 @@ def _load_clients(db: Session, tenant_id: int | None, branch_id: int | None, cur
|
|||||||
def _staff_rows(db: Session, tenant_id: int | None, branch_id: int | None, tasks: list[ClientServiceTaskInstance]) -> list[dict[str, Any]]:
|
def _staff_rows(db: Session, tenant_id: int | None, branch_id: int | None, tasks: list[ClientServiceTaskInstance]) -> list[dict[str, Any]]:
|
||||||
if not tenant_id:
|
if not tenant_id:
|
||||||
return []
|
return []
|
||||||
stmt = select(User).where(User.tenant_id == tenant_id, User.is_active.is_(True))
|
stmt = (
|
||||||
|
select(User)
|
||||||
|
.join(UserRole, UserRole.user_id == User.id)
|
||||||
|
.join(Role, Role.id == UserRole.role_id)
|
||||||
|
.where(
|
||||||
|
User.tenant_id == tenant_id,
|
||||||
|
User.is_active.is_(True),
|
||||||
|
Role.is_active.is_(True),
|
||||||
|
Role.name.in_(("Staff", "Branch Manager")),
|
||||||
|
)
|
||||||
|
.distinct()
|
||||||
|
)
|
||||||
if branch_id is not None:
|
if branch_id is not None:
|
||||||
stmt = stmt.where(User.branch_id == branch_id)
|
stmt = stmt.where(User.branch_id == branch_id)
|
||||||
users = db.execute(stmt.order_by(User.full_name.asc(), User.email.asc()).limit(100)).scalars().all()
|
users = db.execute(
|
||||||
|
stmt.order_by(User.full_name.asc(), User.email.asc()).limit(100)
|
||||||
|
).scalars().all()
|
||||||
by_user: dict[int, dict[str, int]] = {}
|
by_user: dict[int, dict[str, int]] = {}
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
uid = getattr(task, "assigned_to_user_id", None)
|
uid = getattr(task, "assigned_to_user_id", None)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<div class="rounded-3xl border border-slate-200 bg-white p-5 shadow-soft">
|
<div class="rounded-3xl border border-slate-200 bg-white p-5 shadow-soft">
|
||||||
<h2 class="text-lg font-semibold text-slate-900">Branch Staff Workload</h2><p class="mt-1 text-sm text-slate-500">Workload is calculated from current branch task assignments.</p>
|
<h2 class="text-lg font-semibold text-slate-900">Branch Staff Workload</h2><p class="mt-1 text-sm text-slate-500">Workload is calculated from current branch task assignments.</p>
|
||||||
<div class="mt-5 overflow-x-auto"><table class="min-w-full text-left text-sm"><thead class="text-xs uppercase tracking-wide text-slate-400"><tr><th class="px-3 py-2">Staff</th><th class="px-3 py-2">Active</th><th class="px-3 py-2">Overdue</th><th class="px-3 py-2">Client Pending</th><th class="px-3 py-2">Review</th><th class="px-3 py-2">Load</th></tr></thead><tbody class="divide-y divide-slate-100">
|
<div class="mt-5 overflow-x-auto"><table class="min-w-full text-left text-sm"><thead class="text-xs uppercase tracking-wide text-slate-400"><tr><th class="px-3 py-2">Staff / Manager</th><th class="px-3 py-2">Active</th><th class="px-3 py-2">Overdue</th><th class="px-3 py-2">Client Pending</th><th class="px-3 py-2">Review</th><th class="px-3 py-2">Load</th></tr></thead><tbody class="divide-y divide-slate-100">
|
||||||
{% for s in staff_rows %}<tr class="hover:bg-slate-50"><td class="px-3 py-3"><div class="font-semibold text-slate-900">{{ s.name }}</div><div class="text-xs text-slate-500">{{ s.designation or s.email }}</div></td><td class="px-3 py-3">{{ s.active }}</td><td class="px-3 py-3">{{ s.overdue }}</td><td class="px-3 py-3">{{ s.client_pending }}</td><td class="px-3 py-3">{{ s.review }}</td><td class="px-3 py-3"><span class="rounded-full bg-slate-100 px-2.5 py-1 text-xs font-semibold text-slate-700">{{ s.load_status }}</span></td></tr>{% else %}<tr><td colspan="6" class="px-3 py-8 text-center text-slate-500">No branch users found.</td></tr>{% endfor %}
|
{% for s in staff_rows %}<tr class="hover:bg-slate-50"><td class="px-3 py-3"><div class="font-semibold text-slate-900">{{ s.name }}</div><div class="text-xs text-slate-500">{{ s.designation or s.email }}</div></td><td class="px-3 py-3">{{ s.active }}</td><td class="px-3 py-3">{{ s.overdue }}</td><td class="px-3 py-3">{{ s.client_pending }}</td><td class="px-3 py-3">{{ s.review }}</td><td class="px-3 py-3"><span class="rounded-full bg-slate-100 px-2.5 py-1 text-xs font-semibold text-slate-700">{{ s.load_status }}</span></td></tr>{% else %}<tr><td colspan="6" class="px-3 py-8 text-center text-slate-500">No active Staff or Branch Manager users found for this branch.</td></tr>{% endfor %}
|
||||||
</tbody></table></div>
|
</tbody></table></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user