From c39779552d38f83572d80cebe1c92e9b62ba5928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Wed, 29 Jul 2026 20:19:18 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=92=B3=20payments=20collect=20tab?= =?UTF-8?q?=20=E2=80=94=20student=20roster=20with=20debt=20status=20&=20pl?= =?UTF-8?q?an=20filter=20-=20replace=20the=20lone=20student=20search=20box?= =?UTF-8?q?=20with=20a=20sortable=20student=20DataTable=20=20=20(name,=20u?= =?UTF-8?q?sername,=20in-debt/settled=20badge,=20balance);=20row=20click?= =?UTF-8?q?=20opens=20the=20=20=20student's=20collection=20detail=20with?= =?UTF-8?q?=20a=20back-to-roster=20action=20-=20fee-plan=20filter=20dropdo?= =?UTF-8?q?wn;=20clicking=20a=20plan=20row=20jumps=20to=20the=20collect=20?= =?UTF-8?q?tab=20=20=20pre-filtered=20to=20that=20plan's=20assignment=20ro?= =?UTF-8?q?ster=20-=20per-student=20balance=20fetched=20for=20the=20listed?= =?UTF-8?q?=20set=20(capped=20at=20200)=20to=20show=20=20=20and=20sort=20b?= =?UTF-8?q?y=20debt=20status=20-=20drop=20the=20tinted=20card=20wrappers?= =?UTF-8?q?=20behind=20the=20payments/statement=20tables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/i18n/messages.ts | 18 ++++ src/pages/payment-statement-page.tsx | 2 +- src/pages/payments-page.tsx | 140 ++++++++++++++++++++++++--- 3 files changed, 148 insertions(+), 12 deletions(-) diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index 8b37f5f..c241532 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -1005,6 +1005,12 @@ export type MessageKey = | "payments.showLedger" | "payments.hideLedger" | "payments.plan" + | "payments.student" + | "payments.username" + | "payments.allStudents" + | "payments.allPlans" + | "payments.inDebt" + | "payments.settled" | "terms.title" | "terms.subtitle" | "terms.create" @@ -2254,6 +2260,12 @@ const en: Dict = { "payments.showLedger": "Show account activity", "payments.hideLedger": "Hide account activity", "payments.plan": "Plan", + "payments.student": "Student", + "payments.username": "Username", + "payments.allStudents": "All students", + "payments.allPlans": "All plans", + "payments.inDebt": "In debt", + "payments.settled": "Settled", "terms.title": "Academic terms", "terms.subtitle": "Manage academic terms and assign courses to each one.", "terms.create": "Create term", @@ -3429,6 +3441,12 @@ const tr: Dict = { "payments.showLedger": "Hesap hareketlerini göster", "payments.hideLedger": "Hesap hareketlerini gizle", "payments.plan": "Plan", + "payments.student": "Öğrenci", + "payments.username": "Kullanıcı adı", + "payments.allStudents": "Tüm öğrenciler", + "payments.allPlans": "Tüm planlar", + "payments.inDebt": "Borçlu", + "payments.settled": "Borçsuz", "terms.title": "Akademik dönemler", "terms.subtitle": "Akademik dönemleri yönetin ve dersleri ilgili dönemlere atayın.", "terms.create": "Dönem oluştur", diff --git a/src/pages/payment-statement-page.tsx b/src/pages/payment-statement-page.tsx index 1601c47..a8d7366 100644 --- a/src/pages/payment-statement-page.tsx +++ b/src/pages/payment-statement-page.tsx @@ -125,7 +125,7 @@ function StatementContent() {

{t("payments.balance")}

{formatTry(summary().balance, moneyLocale())}

-
+
}> void refetch()} /> diff --git a/src/pages/payments-page.tsx b/src/pages/payments-page.tsx index e3f94a9..5fc424c 100644 --- a/src/pages/payments-page.tsx +++ b/src/pages/payments-page.tsx @@ -2,6 +2,7 @@ import { For, Index, Show, Suspense, createMemo, createResource, createSignal } import type { ColumnDef } from "@tanstack/solid-table"; import { deletePaymentPlanById, + getPaymentBalanceByUserId, getPaymentLedgerByUserId, getPaymentPlans, getPaymentStatementByUserId, @@ -17,7 +18,8 @@ import { type PaymentLine, type StatementEntry, } from "@/api/payments"; -import { formatApiError } from "@/api/client"; +import { getUsers } from "@/api/users"; +import { formatApiError, type User } from "@/api/client"; import { RouteGuard } from "@/components/layout/route-guard"; import { PageHeader } from "@/components/layout/page-header"; import { Alert } from "@/components/ui/alert"; @@ -28,7 +30,7 @@ import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; import { DatePicker } from "@/components/ui/date-picker"; import { EmptyState } from "@/components/ui/empty-state"; import { ErrorAlert } from "@/components/ui/error-alert"; -import { IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; +import { IconChevronLeft, IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select } from "@/components/ui/select"; @@ -85,7 +87,85 @@ function PaymentsContent() { const [pending, setPending] = createSignal(false); // ============================ Collection ============================ - const [student, setStudent] = createSignal(""); + const [selectedStudent, setSelectedStudent] = createSignal(null); + const student = () => selectedStudent()?.id ?? ""; + const studentLabel = (user: User) => `${user.name ?? ""} ${user.surname ?? ""}`.trim() || user.username; + + const [students, { refetch: refetchStudents }] = createResource(async () => + (await getUsers({ limit: 500 })).items.filter((user) => user.role === "student"), + ); + const studentList = () => students() ?? []; + + // Filter the student list by fee plan (via that plan's assignment roster). + const [planFilter, setPlanFilter] = createSignal(""); + const [filterAssignments] = createResource( + () => planFilter() || null, + (planId) => getPlanAssignments(planId, { limit: 500 }), + ); + const filteredStudents = createMemo(() => { + const all = studentList(); + if (!planFilter()) return all; + const ids = new Set((filterAssignments()?.items ?? []).map((row) => row.student.id)); + return all.filter((user) => ids.has(user.id)); + }); + + // Per-student balance for the "in debt / settled" column. No bulk endpoint + // exists, so this is one call per listed student — bounded to a plan-sized + // list. ponytail: N+1 balance fetch, capped at 200; add a bulk + // /payments/balances endpoint if whole-school unfiltered debt is needed. + const BALANCE_FETCH_CAP = 200; + const [balances] = createResource( + () => { + const ids = filteredStudents().map((user) => user.id); + return ids.length > 0 && ids.length <= BALANCE_FETCH_CAP ? ids : null; + }, + async (ids) => { + const pairs = await Promise.all( + ids.map(async (id) => [id, (await getPaymentBalanceByUserId(id)).balance_minor] as const), + ); + return Object.fromEntries(pairs) as Record; + }, + ); + const balanceOf = (id: string) => balances()?.[id]; + + const studentColumns = createMemo[]>(() => [ + { + id: "name", + header: t("payments.student"), + cell: (cell) => {studentLabel(cell.row.original)}, + }, + { + accessorKey: "username", + header: t("payments.username"), + cell: (cell) => @{cell.row.original.username}, + }, + { + id: "debt", + header: t("payments.status"), + accessorFn: (user) => balanceOf(user.id) ?? 0, + cell: (cell) => { + const bal = balanceOf(cell.row.original.id); + if (bal === undefined) return —; + const inDebt = bal < 0; + return ( + + + {inDebt ? t("payments.inDebt") : t("payments.settled")} + + ); + }, + }, + { + id: "balance", + header: t("payments.balance"), + accessorFn: (user) => balanceOf(user.id) ?? 0, + cell: (cell) => { + const bal = balanceOf(cell.row.original.id); + return {bal === undefined ? "—" : formatTry(bal, moneyLocale())}; + }, + }, + ]); + const [statement, { refetch: refetchStatement }] = createResource( () => student() || null, (userId) => getPaymentStatementByUserId(userId, { limit: 500 }), @@ -377,11 +457,48 @@ function PaymentsContent() { {/* ---------------- Collection ---------------- */} -
- -
- - + + }> + + void refetchStudents()} /> + + 0} fallback={}> + setSelectedStudent(user)} + searchPredicate={(user, q) => `${studentLabel(user)} ${user.username} ${user.email ?? ""}`.toLowerCase().includes(q.toLowerCase())} + filterPlaceholder={t("payments.selectStudent")} + title={t("payments.selectStudent")} + filters={ + + } + tableClass="min-w-160" + enableSorting + enablePagination + pageSize={STATEMENT_PAGE_SIZE} + /> + + +
+ } + > + {(current) => (<> +
+
+

{studentLabel(current())}

+

@{current().username}

+
+ +

{t("payments.totalDebt")}

{formatTry(summary().billed, moneyLocale())}

{t("payments.collected")}

{formatTry(summary().collected, moneyLocale())}

@@ -389,7 +506,7 @@ function PaymentsContent() {

{t("payments.overdueCount")}

0 }}>{summary().overdue}

-
+
}> void refetchStatement()} /> @@ -446,6 +563,7 @@ function PaymentsContent() {
+ )} @@ -457,13 +575,13 @@ function PaymentsContent() { {t("payments.createPlan")} -
+
}> void refetchPlans()} /> 0} fallback={}> - + { setPlanFilter(plan.id); setTab("collect"); }} tableClass="min-w-160" filterColumn="name" enablePagination pageSize={PLAN_PAGE_SIZE} />