diff --git a/app/modules/clients/filters.py b/app/modules/clients/filters.py index e3cba75..32f0141 100644 --- a/app/modules/clients/filters.py +++ b/app/modules/clients/filters.py @@ -10,7 +10,7 @@ class ClientListFilters: partner_id: int | None = None include_archived: bool = False page: int = 1 - per_page: int = 10 + per_page: int = 25 sort_by: str = "client_name" sort_order: str = "asc" @@ -35,7 +35,7 @@ class ClientListFilters: partner_id=partner_id, include_archived=include_archived, page=max(int(kwargs.get("page", 1) or 1), 1), - per_page=min(max(int(kwargs.get("per_page", 10) or 10), 1), 100), + per_page=min(max(int(kwargs.get("per_page", 25) or 25), 1), 100), sort_by=kwargs.get("sort_by", "client_name") or "client_name", sort_order=kwargs.get("sort_order", "asc") or "asc", ) diff --git a/app/modules/clients/repository.py b/app/modules/clients/repository.py index e546cff..815821b 100644 --- a/app/modules/clients/repository.py +++ b/app/modules/clients/repository.py @@ -84,7 +84,7 @@ def list_clients( allow_cross_branch: bool = False, allow_all_clients: bool = False, partner_id: int | None = None, q: str = "", status: str = "", client_type: str = "", client_group_id: int | None = None, include_archived: bool = False, - page: int = 1, per_page: int = 10, sort_by: str = "client_name", sort_order: str = "asc", + page: int = 1, per_page: int = 25, sort_by: str = "client_name", sort_order: str = "asc", ) -> dict: stmt = build_clients_query( tenant_id=tenant_id, branch_id=branch_id, allow_cross_branch=allow_cross_branch, @@ -92,7 +92,13 @@ def list_clients( client_type=client_type, client_group_id=client_group_id, include_archived=include_archived, ) total = db.execute(select(func.count()).select_from(stmt.subquery())).scalar_one() - result = db.execute(stmt.order_by(_safe_sort(sort_by, sort_order)).offset((page - 1) * per_page).limit(per_page)).all() + per_page = min(max(int(per_page or 25), 1), 100) + pages = max(ceil(total / per_page), 1) + page = min(max(int(page or 1), 1), pages) + offset = (page - 1) * per_page + result = db.execute( + stmt.order_by(_safe_sort(sort_by, sort_order)).offset(offset).limit(per_page) + ).all() rows=[] for client, partner_name, branch_name, tenant_name, client_group_name, client_group_code, association_type, assoc_firm_tenant_id, assoc_consultant_id, assoc_partner_user_id, assoc_created_source in result: row={**client.__dict__}; row.pop("_sa_instance_state",None) @@ -109,8 +115,7 @@ def list_clients( if branch_id and not allow_cross_branch: stats_stmt=stats_stmt.where(Client.branch_id==branch_id) if partner_id: stats_stmt=stats_stmt.where(Client.partner_id==partner_id) total_all,active,inactive,archived=db.execute(stats_stmt).one() - pages=ceil(total/per_page) if per_page else 1 - return {"rows":rows,"meta":{"total":total,"page":page,"per_page":per_page,"pages":max(pages,1)},"stats":{"total":int(total_all or 0),"active":int(active or 0),"inactive":int(inactive or 0),"archived":int(archived or 0)}} + return {"rows":rows,"meta":{"total":total,"page":page,"per_page":per_page,"pages":pages},"stats":{"total":int(total_all or 0),"active":int(active or 0),"inactive":int(inactive or 0),"archived":int(archived or 0)}} def get_client_detail_payload(db: Session, client_id: int): diff --git a/app/modules/clients/templates/clients/list.html b/app/modules/clients/templates/clients/list.html index 28ac998..04d5fdd 100644 --- a/app/modules/clients/templates/clients/list.html +++ b/app/modules/clients/templates/clients/list.html @@ -7,9 +7,10 @@

Association-aware list view.

-
Client Groups +
+ Client Groups {% if can_export %} - Export CSV @@ -32,5 +33,82 @@
{% include "modules/clients/templates/clients/partials/table.html" %} + + {% if meta %} +
+
+ {% if meta.total > 0 %} + Showing {{ ((meta.page - 1) * meta.per_page) + 1 }} + to {% if meta.page * meta.per_page > meta.total %}{{ meta.total }}{% else %}{{ meta.page * meta.per_page }}{% endif %} + of {{ meta.total }} clients + {% else %} + No clients found + {% endif %} +
+ +
+
+ + + + + + + + + + + +
+ + {% if meta.pages > 1 %} + + {% endif %} +
+
+ {% endif %}
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/modules/clients/templates/clients/partials/table.html b/app/modules/clients/templates/clients/partials/table.html index 52b1982..6d89a8c 100644 --- a/app/modules/clients/templates/clients/partials/table.html +++ b/app/modules/clients/templates/clients/partials/table.html @@ -1,2 +1,55 @@ - -
{% for row in rows %}{% else %}{% endfor %}
CodeClientGroupAssociationPartnerBranchStatus
{{ row.client_code }}
{{ row.client_name }}
{{ row.pan or row.gstin or '-' }}
{% if row.client_group_name %}{{ row.client_group_name }}
{{ row.group_relationship or row.client_group_code }}
{% else %}-{% endif %}
{{ row.association_type or 'legacy_firm' }}
{{ row.assoc_created_source or 'legacy' }}
{{ row.partner_name or row.effective_partner_id or '-' }}{{ row.branch_name or row.assoc_firm_branch_id or row.branch_id or '-' }}{% if row.status == 'active' %}Active{% elif row.status == 'archived' %}Archived{% else %}Inactive{% endif %}Open
No clients found.
+
+ + + + + + + + + + + + + + + {% for row in rows %} + + + + + + + + + + + {% else %} + + + + {% endfor %} + +
CodeClientGroupAssociationPartnerBranchStatus
{{ row.client_code }} +
{{ row.client_name }}
+
{{ row.pan or row.gstin or '-' }}
+
+ {% if row.client_group_name %} + {{ row.client_group_name }} +
{{ row.group_relationship or row.client_group_code }}
+ {% else %}-{% endif %} +
+
{{ row.association_type or 'legacy_firm' }}
+
{{ row.assoc_created_source or 'legacy' }}
+
{{ row.partner_name or row.effective_partner_id or '-' }}{{ row.branch_name or row.assoc_firm_branch_id or row.branch_id or '-' }} + {% if row.status == 'active' %} + Active + {% elif row.status == 'archived' %} + Archived + {% else %} + Inactive + {% endif %} + + Open +
No clients found.
+
diff --git a/app/modules/clients/ui.py b/app/modules/clients/ui.py index 7498fc6..4fc018d 100644 --- a/app/modules/clients/ui.py +++ b/app/modules/clients/ui.py @@ -297,7 +297,7 @@ def clients_list( partner_id: int | None = None, include_archived: bool = False, page: int = 1, - per_page: int = 10, + per_page: int = 25, sort_by: str = "client_name", sort_order: str = "asc", ):