diff --git a/src/api/__tests__/payments/payments.test.ts b/src/api/__tests__/payments/payments.test.ts new file mode 100644 index 0000000..dac1e7d --- /dev/null +++ b/src/api/__tests__/payments/payments.test.ts @@ -0,0 +1,121 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { + deletePaymentPlanById, + getMyPaymentBalance, + getMyPaymentStatement, + getPaymentBalanceByUserId, + getPaymentLedgerByUserId, + getPaymentPlanById, + getPaymentPlans, + getPaymentStatementByUserId, + getPlanAssignments, + patchPaymentPlanById, + postPaymentCredit, + postPaymentPlan, + postPaymentRefund, + postPaymentReversal, + postPlanAssignment, +} from "../../payments"; +import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; + +describe("payments API", () => { + afterEach(() => vi.restoreAllMocks()); + const json = () => mockFetchSuccess({}); + const page = () => mockFetchSuccess({ items: [], total: 0 }); + + it("creates a fee plan", async () => { + json(); + const body = { name: "2026-2027", installments: [{ amount_minor: 150000, due_at: 1_760_000_000_000 }] }; + await postPaymentPlan(body); + expect(lastFetchCall()).toMatchObject(["/api/payments/plans", { method: "POST", body: JSON.stringify(body) }]); + }); + + it("lists plans with pagination", async () => { + page(); + await getPaymentPlans({ limit: 12, offset: 24 }); + expect(lastFetchCall()[0]).toBe("/api/payments/plans?limit=12&offset=24"); + }); + + it("gets a plan by id", async () => { + json(); + await getPaymentPlanById("p/1"); + expect(lastFetchCall()[0]).toBe("/api/payments/plans/p%2F1"); + }); + + it("updates a plan", async () => { + json(); + const body = { name: "renamed" }; + await patchPaymentPlanById("p1", body); + expect(lastFetchCall()).toMatchObject(["/api/payments/plans/p1", { method: "PATCH", body: JSON.stringify(body) }]); + }); + + it("deletes a plan", async () => { + mockFetch204(); + await deletePaymentPlanById("p1"); + expect(lastFetchCall()).toMatchObject(["/api/payments/plans/p1", { method: "DELETE" }]); + }); + + it("assigns a plan to students", async () => { + mockFetchSuccess([]); + const body = { student_ids: ["s1", "s2"] }; + await postPlanAssignment("p1", body); + expect(lastFetchCall()).toMatchObject(["/api/payments/plans/p1/assignments", { method: "POST", body: JSON.stringify(body) }]); + }); + + it("lists plan assignments with pagination", async () => { + page(); + await getPlanAssignments("p1", { limit: 5 }); + expect(lastFetchCall()[0]).toBe("/api/payments/plans/p1/assignments?limit=5"); + }); + + it("records a payment with an idempotence key", async () => { + json(); + const body = { charge_id: "c1", amount_minor: 50000, method: "havale", request_key: "receipt-2026-114" }; + await postPaymentCredit(body); + expect(lastFetchCall()).toMatchObject(["/api/payments/credits", { method: "POST", body: JSON.stringify(body) }]); + }); + + it("records a refund with an idempotence key", async () => { + json(); + const body = { credit_id: "cr1", amount_minor: 50000, request_key: "refund-2026-114" }; + await postPaymentRefund(body); + expect(lastFetchCall()).toMatchObject(["/api/payments/refunds", { method: "POST", body: JSON.stringify(body) }]); + }); + + it("records a reversal", async () => { + json(); + const body = { line_id: "l1", note: "billed in error" }; + await postPaymentReversal(body); + expect(lastFetchCall()).toMatchObject(["/api/payments/reversals", { method: "POST", body: JSON.stringify(body) }]); + }); + + it("reads a student ledger with pagination", async () => { + page(); + await getPaymentLedgerByUserId("u/1", { limit: 20, offset: 20 }); + expect(lastFetchCall()[0]).toBe("/api/payments/ledger/u%2F1?limit=20&offset=20"); + }); + + it("reads my statement", async () => { + mockFetchSuccess({ student: {}, entries: { items: [], total: 0 }, balance_minor: 0 }); + await getMyPaymentStatement({ limit: 10 }); + expect(lastFetchCall()[0]).toBe("/api/payments/statement/me?limit=10"); + }); + + it("reads a student statement", async () => { + mockFetchSuccess({ student: {}, entries: { items: [], total: 0 }, balance_minor: 0 }); + await getPaymentStatementByUserId("u1"); + expect(lastFetchCall()[0]).toBe("/api/payments/statement/u1"); + }); + + it("reads my balance", async () => { + mockFetchSuccess({ student: {}, balance_minor: 0 }); + await getMyPaymentBalance(); + expect(lastFetchCall()[0]).toBe("/api/payments/balance/me"); + }); + + it("reads a student balance", async () => { + mockFetchSuccess({ student: {}, balance_minor: 0 }); + await getPaymentBalanceByUserId("u1"); + expect(lastFetchCall()[0]).toBe("/api/payments/balance/u1"); + }); +}); diff --git a/src/api/client/types.ts b/src/api/client/types.ts index 1e545d5..2af4ecf 100644 --- a/src/api/client/types.ts +++ b/src/api/client/types.ts @@ -541,6 +541,13 @@ export type Limits = { attendance_statuses: string[]; ledger_kinds: string[]; }; + payment: { + max_plan_name_len: number; + max_plan_installments: number; + max_assign_students: number; + max_request_key_len: number; + ledger_kinds: string[]; + }; chatbot: { max_message_len: number; max_thread_title_len: number; diff --git a/src/api/payments/deletePaymentPlanById.ts b/src/api/payments/deletePaymentPlanById.ts new file mode 100644 index 0000000..0209578 --- /dev/null +++ b/src/api/payments/deletePaymentPlanById.ts @@ -0,0 +1,5 @@ +import { client } from "../client"; + +export function deletePaymentPlanById(id: string): Promise { + return client(`/payments/plans/${encodeURIComponent(id)}`, { method: "DELETE" }); +} diff --git a/src/api/payments/getMyPaymentBalance.ts b/src/api/payments/getMyPaymentBalance.ts new file mode 100644 index 0000000..6c2025c --- /dev/null +++ b/src/api/payments/getMyPaymentBalance.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { PaymentBalance } from "./types"; + +export function getMyPaymentBalance(signal?: AbortSignal): Promise { + return client("/payments/balance/me", { signal }); +} diff --git a/src/api/payments/getMyPaymentStatement.ts b/src/api/payments/getMyPaymentStatement.ts new file mode 100644 index 0000000..51e1290 --- /dev/null +++ b/src/api/payments/getMyPaymentStatement.ts @@ -0,0 +1,10 @@ +import { client, pageQuery, type PageParams } from "../client"; +import type { PaymentStatement } from "./types"; + +// Statement is not itself a Page envelope: { student, entries: Page, balance_minor }. +export function getMyPaymentStatement( + params?: PageParams, + signal?: AbortSignal, +): Promise { + return client(`/payments/statement/me${pageQuery(params)}`, { signal }); +} diff --git a/src/api/payments/getPaymentBalanceByUserId.ts b/src/api/payments/getPaymentBalanceByUserId.ts new file mode 100644 index 0000000..6aaae6d --- /dev/null +++ b/src/api/payments/getPaymentBalanceByUserId.ts @@ -0,0 +1,9 @@ +import { client } from "../client"; +import type { PaymentBalance } from "./types"; + +export function getPaymentBalanceByUserId( + userId: string, + signal?: AbortSignal, +): Promise { + return client(`/payments/balance/${encodeURIComponent(userId)}`, { signal }); +} diff --git a/src/api/payments/getPaymentLedgerByUserId.ts b/src/api/payments/getPaymentLedgerByUserId.ts new file mode 100644 index 0000000..b0847ff --- /dev/null +++ b/src/api/payments/getPaymentLedgerByUserId.ts @@ -0,0 +1,14 @@ +import { client, normalizePage, pageQuery, type Page, type PageParams } from "../client"; +import type { PaymentLine } from "./types"; + +export async function getPaymentLedgerByUserId( + userId: string, + params?: PageParams, + signal?: AbortSignal, +): Promise> { + const data = await client( + `/payments/ledger/${encodeURIComponent(userId)}${pageQuery(params)}`, + { signal }, + ); + return normalizePage(data); +} diff --git a/src/api/payments/getPaymentPlanById.ts b/src/api/payments/getPaymentPlanById.ts new file mode 100644 index 0000000..a2a8f84 --- /dev/null +++ b/src/api/payments/getPaymentPlanById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { FeePlan } from "./types"; + +export function getPaymentPlanById(id: string, signal?: AbortSignal): Promise { + return client(`/payments/plans/${encodeURIComponent(id)}`, { signal }); +} diff --git a/src/api/payments/getPaymentPlans.ts b/src/api/payments/getPaymentPlans.ts new file mode 100644 index 0000000..8471a57 --- /dev/null +++ b/src/api/payments/getPaymentPlans.ts @@ -0,0 +1,10 @@ +import { client, normalizePage, pageQuery, type Page, type PageParams } from "../client"; +import type { FeePlan } from "./types"; + +export async function getPaymentPlans( + params?: PageParams, + signal?: AbortSignal, +): Promise> { + const data = await client(`/payments/plans${pageQuery(params)}`, { signal }); + return normalizePage(data); +} diff --git a/src/api/payments/getPaymentStatementByUserId.ts b/src/api/payments/getPaymentStatementByUserId.ts new file mode 100644 index 0000000..5353d6f --- /dev/null +++ b/src/api/payments/getPaymentStatementByUserId.ts @@ -0,0 +1,13 @@ +import { client, pageQuery, type PageParams } from "../client"; +import type { PaymentStatement } from "./types"; + +export function getPaymentStatementByUserId( + userId: string, + params?: PageParams, + signal?: AbortSignal, +): Promise { + return client( + `/payments/statement/${encodeURIComponent(userId)}${pageQuery(params)}`, + { signal }, + ); +} diff --git a/src/api/payments/getPlanAssignments.ts b/src/api/payments/getPlanAssignments.ts new file mode 100644 index 0000000..1c7e858 --- /dev/null +++ b/src/api/payments/getPlanAssignments.ts @@ -0,0 +1,14 @@ +import { client, normalizePage, pageQuery, type Page, type PageParams } from "../client"; +import type { FeePlanAssignment } from "./types"; + +export async function getPlanAssignments( + planId: string, + params?: PageParams, + signal?: AbortSignal, +): Promise> { + const data = await client( + `/payments/plans/${encodeURIComponent(planId)}/assignments${pageQuery(params)}`, + { signal }, + ); + return normalizePage(data); +} diff --git a/src/api/payments/index.ts b/src/api/payments/index.ts new file mode 100644 index 0000000..130229e --- /dev/null +++ b/src/api/payments/index.ts @@ -0,0 +1,16 @@ +export * from "./types"; +export * from "./postPaymentPlan"; +export * from "./getPaymentPlans"; +export * from "./getPaymentPlanById"; +export * from "./patchPaymentPlanById"; +export * from "./deletePaymentPlanById"; +export * from "./postPlanAssignment"; +export * from "./getPlanAssignments"; +export * from "./postPaymentCredit"; +export * from "./postPaymentRefund"; +export * from "./postPaymentReversal"; +export * from "./getPaymentLedgerByUserId"; +export * from "./getMyPaymentStatement"; +export * from "./getPaymentStatementByUserId"; +export * from "./getMyPaymentBalance"; +export * from "./getPaymentBalanceByUserId"; diff --git a/src/api/payments/patchPaymentPlanById.ts b/src/api/payments/patchPaymentPlanById.ts new file mode 100644 index 0000000..765518c --- /dev/null +++ b/src/api/payments/patchPaymentPlanById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { FeePlan, UpdateFeePlanBody } from "./types"; + +export function patchPaymentPlanById(id: string, body: UpdateFeePlanBody): Promise { + return client(`/payments/plans/${encodeURIComponent(id)}`, { method: "PATCH", body }); +} diff --git a/src/api/payments/postPaymentCredit.ts b/src/api/payments/postPaymentCredit.ts new file mode 100644 index 0000000..07103ea --- /dev/null +++ b/src/api/payments/postPaymentCredit.ts @@ -0,0 +1,7 @@ +import { client } from "../client"; +import type { PaymentLine, RecordPaymentBody } from "./types"; + +// Record a payment against a charge line. +export function postPaymentCredit(body: RecordPaymentBody): Promise { + return client("/payments/credits", { method: "POST", body }); +} diff --git a/src/api/payments/postPaymentPlan.ts b/src/api/payments/postPaymentPlan.ts new file mode 100644 index 0000000..f4283e7 --- /dev/null +++ b/src/api/payments/postPaymentPlan.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { CreateFeePlanBody, FeePlan } from "./types"; + +export function postPaymentPlan(body: CreateFeePlanBody): Promise { + return client("/payments/plans", { method: "POST", body }); +} diff --git a/src/api/payments/postPaymentRefund.ts b/src/api/payments/postPaymentRefund.ts new file mode 100644 index 0000000..2507870 --- /dev/null +++ b/src/api/payments/postPaymentRefund.ts @@ -0,0 +1,7 @@ +import { client } from "../client"; +import type { PaymentLine, RecordRefundBody } from "./types"; + +// Hand back a recorded payment (credit line). +export function postPaymentRefund(body: RecordRefundBody): Promise { + return client("/payments/refunds", { method: "POST", body }); +} diff --git a/src/api/payments/postPaymentReversal.ts b/src/api/payments/postPaymentReversal.ts new file mode 100644 index 0000000..d64dd2d --- /dev/null +++ b/src/api/payments/postPaymentReversal.ts @@ -0,0 +1,7 @@ +import { client } from "../client"; +import type { PaymentLine, RecordReversalBody } from "./types"; + +// Undo a charge or refund line for its exact amount. +export function postPaymentReversal(body: RecordReversalBody): Promise { + return client("/payments/reversals", { method: "POST", body }); +} diff --git a/src/api/payments/postPlanAssignment.ts b/src/api/payments/postPlanAssignment.ts new file mode 100644 index 0000000..e9c8d11 --- /dev/null +++ b/src/api/payments/postPlanAssignment.ts @@ -0,0 +1,12 @@ +import { client } from "../client"; +import type { AssignmentOutcome } from "./types"; + +export function postPlanAssignment( + planId: string, + body: { student_ids: string[] }, +): Promise { + return client( + `/payments/plans/${encodeURIComponent(planId)}/assignments`, + { method: "POST", body }, + ); +} diff --git a/src/api/payments/types.ts b/src/api/payments/types.ts new file mode 100644 index 0000000..862719d --- /dev/null +++ b/src/api/payments/types.ts @@ -0,0 +1,103 @@ +import type { Page, PersonRef } from "../client"; + +export type PaymentLedgerKind = "charge" | "credit" | "reversal" | "refund"; + +export type FeePlanInstallment = { + amount_minor: number; + due_at: number; +}; + +export type FeePlan = { + id: string; + name: string; + installments: FeePlanInstallment[]; + created_by: PersonRef; + created_at: number; +}; + +export type CreateFeePlanBody = { + name: string; + installments: FeePlanInstallment[]; +}; + +// Backend replaces the whole schedule; refused (409) once anyone is assigned. +export type UpdateFeePlanBody = { + name?: string; + installments?: FeePlanInstallment[]; +}; + +export type FeePlanAssignment = { + id: string; + plan: string; + student: PersonRef; + assigned_by: PersonRef; + created_at: number; +}; + +export type AssignmentOutcome = { + student_id: string; + status: "assigned" | "already_assigned" | "rejected"; + reason: string | null; +}; + +export type PaymentLine = { + id: string; + student: PersonRef; + kind: PaymentLedgerKind; + amount_minor: number; + source: string | null; + due_at: number | null; + method: string | null; + note: string | null; + recorded_by: PersonRef; + created_at: number; +}; + +// request_key: optional idempotence key, charset [A-Za-z0-9-]. Same key with a +// different amount_minor/charge_id → 409. +export type RecordPaymentBody = { + charge_id: string; + amount_minor: number; + method?: string; + note?: string; + request_key?: string; +}; + +export type RecordRefundBody = { + credit_id: string; + amount_minor: number; + method?: string; + note?: string; + request_key?: string; +}; + +export type RecordReversalBody = { + line_id: string; + note?: string; +}; + +export type StatementEntry = { + charge_id: string; + plan: string | null; + plan_name: string | null; + amount_minor: number; + due_at: number | null; + credited_minor: number; + refunded_minor: number; + outstanding_minor: number; + reversed: boolean; + overdue: boolean; +}; + +// entries is a Page envelope; balance_minor is folded from the full ledger +// regardless of paging. Negative balance means the family owes the school. +export type PaymentStatement = { + student: PersonRef; + entries: Page; + balance_minor: number; +}; + +export type PaymentBalance = { + student: PersonRef; + balance_minor: number; +}; diff --git a/src/components/layout/nav-items.ts b/src/components/layout/nav-items.ts index e6cca5e..62ea6fe 100644 --- a/src/components/layout/nav-items.ts +++ b/src/components/layout/nav-items.ts @@ -151,6 +151,7 @@ const NAV_GROUPS: NavGroup[] = [ Icon: IconGlobe, items: [ MEALS_ITEM, + { id: "payment-statement", to: "/payments", labelKey: "nav.paymentStatement", Icon: IconChart, maxRole: "student" }, { id: "messages", to: "/messages", labelKey: "nav.messages", Icon: IconMessage }, { id: "questions", to: "/questions", labelKey: "nav.questions", Icon: IconHelpCircle }, { id: "work", to: "/work", labelKey: "nav.work", Icon: IconBriefcase, minRole: "teacher", maxRole: "manager" }, @@ -165,6 +166,7 @@ const NAV_GROUPS: NavGroup[] = [ { id: "staff-work", to: "/management/staff-work", labelKey: "nav.staffWork", Icon: IconBriefcase, minRole: "manager" }, { id: "settings", to: "/management/settings", labelKey: "nav.settings", Icon: IconSettings, minRole: "manager" }, { id: "terms", to: "/management/terms", labelKey: "nav.terms", Icon: IconCalendarDays, minRole: "manager" }, + { id: "payments", to: "/management/payments", labelKey: "nav.payments", Icon: IconReportAnalytics, minRole: "manager" }, { id: "users", to: "/admin/users", labelKey: "nav.users", Icon: IconUserCog, minRole: "admin" }, ], }, diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index a6d013a..8b37f5f 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -937,6 +937,74 @@ export type MessageKey = | "meals.editDish" | "meals.dishName" | "meals.priceTry" + | "nav.payments" + | "nav.paymentStatement" + | "payments.title" + | "payments.subtitle" + | "payments.empty" + | "payments.createPlan" + | "payments.editPlan" + | "payments.deletePlan" + | "payments.planName" + | "payments.installments" + | "payments.addInstallment" + | "payments.amountTry" + | "payments.dueDate" + | "payments.total" + | "payments.assign" + | "payments.assignHelp" + | "payments.selectStudent" + | "payments.assignments" + | "payments.noAssignments" + | "payments.outcomeAssigned" + | "payments.outcomeAlready" + | "payments.outcomeRejected" + | "payments.studentLedger" + | "payments.balance" + | "payments.ledger" + | "payments.noLedger" + | "payments.recordPayment" + | "payments.recordRefund" + | "payments.reverse" + | "payments.method" + | "payments.note" + | "payments.reason" + | "payments.kindCharge" + | "payments.kindCredit" + | "payments.kindRefund" + | "payments.kindReversal" + | "payments.statementTitle" + | "payments.statementSubtitle" + | "payments.noStatement" + | "payments.due" + | "payments.credited" + | "payments.refunded" + | "payments.outstanding" + | "payments.status" + | "payments.overdue" + | "payments.reversed" + | "payments.paid" + | "payments.appendOnly" + | "payments.tabCollect" + | "payments.tabPlans" + | "payments.collect" + | "payments.collectFrom" + | "payments.totalDebt" + | "payments.collected" + | "payments.overdueCount" + | "payments.statusPending" + | "payments.statusPartial" + | "payments.statusCancelled" + | "payments.noDebt" + | "payments.noDebtHint" + | "payments.methodCash" + | "payments.methodTransfer" + | "payments.methodCard" + | "payments.methodCheck" + | "payments.ledgerAudit" + | "payments.showLedger" + | "payments.hideLedger" + | "payments.plan" | "terms.title" | "terms.subtitle" | "terms.create" @@ -2118,6 +2186,74 @@ const en: Dict = { "meals.editDish": "Edit dish", "meals.dishName": "Dish name", "meals.priceTry": "Price (TRY)", + "nav.payments": "Fees", + "nav.paymentStatement": "My Fees", + "payments.title": "School fees", + "payments.subtitle": "Fee plans, assignments, and the payment ledger.", + "payments.empty": "No fee plans yet.", + "payments.createPlan": "New plan", + "payments.editPlan": "Edit plan", + "payments.deletePlan": "Delete plan", + "payments.planName": "Plan name", + "payments.installments": "Installments", + "payments.addInstallment": "Add installment", + "payments.amountTry": "Amount (TRY)", + "payments.dueDate": "Due date", + "payments.total": "Total", + "payments.assign": "Assign", + "payments.assignHelp": "Assigning bills every installment as a charge at once. Students already on the plan are not billed again.", + "payments.selectStudent": "Select student", + "payments.assignments": "Assigned students", + "payments.noAssignments": "No students assigned yet.", + "payments.outcomeAssigned": "Assigned", + "payments.outcomeAlready": "Already assigned", + "payments.outcomeRejected": "Rejected", + "payments.studentLedger": "Student ledger", + "payments.balance": "Balance", + "payments.ledger": "Ledger", + "payments.noLedger": "No ledger entries.", + "payments.recordPayment": "Record payment", + "payments.recordRefund": "Refund", + "payments.reverse": "Reverse", + "payments.method": "Method", + "payments.note": "Note", + "payments.reason": "Reason", + "payments.kindCharge": "Charge", + "payments.kindCredit": "Payment", + "payments.kindRefund": "Refund", + "payments.kindReversal": "Reversal", + "payments.statementTitle": "My fees", + "payments.statementSubtitle": "What you owe the school and every charge behind it.", + "payments.noStatement": "No charges yet.", + "payments.due": "Due", + "payments.credited": "Paid", + "payments.refunded": "Refunded", + "payments.outstanding": "Outstanding", + "payments.status": "Status", + "payments.overdue": "Overdue", + "payments.reversed": "Reversed", + "payments.paid": "Paid", + "payments.appendOnly": "The ledger is append-only. A correction needs a balancing entry, never an edit.", + "payments.tabCollect": "Collection", + "payments.tabPlans": "Fee plans", + "payments.collect": "Collect", + "payments.collectFrom": "Collect payment", + "payments.totalDebt": "Total billed", + "payments.collected": "Collected", + "payments.overdueCount": "Overdue", + "payments.statusPending": "Pending", + "payments.statusPartial": "Partial", + "payments.statusCancelled": "Cancelled", + "payments.noDebt": "No charges for this student yet.", + "payments.noDebtHint": "Assign a fee plan from the Fee plans tab to bill this student.", + "payments.methodCash": "Cash", + "payments.methodTransfer": "Transfer / EFT", + "payments.methodCard": "Card", + "payments.methodCheck": "Cheque", + "payments.ledgerAudit": "Account activity", + "payments.showLedger": "Show account activity", + "payments.hideLedger": "Hide account activity", + "payments.plan": "Plan", "terms.title": "Academic terms", "terms.subtitle": "Manage academic terms and assign courses to each one.", "terms.create": "Create term", @@ -3225,6 +3361,74 @@ const tr: Dict = { "meals.editDish": "Yemeği düzenle", "meals.dishName": "Yemek adı", "meals.priceTry": "Fiyat (TRY)", + "nav.payments": "Ücretler", + "nav.paymentStatement": "Ücretlerim", + "payments.title": "Okul ücretleri", + "payments.subtitle": "Ücret planları, atamalar ve ödeme hareketleri.", + "payments.empty": "Henüz ücret planı yok.", + "payments.createPlan": "Yeni plan", + "payments.editPlan": "Planı düzenle", + "payments.deletePlan": "Planı sil", + "payments.planName": "Plan adı", + "payments.installments": "Taksitler", + "payments.addInstallment": "Taksit ekle", + "payments.amountTry": "Tutar (TRY)", + "payments.dueDate": "Vade tarihi", + "payments.total": "Toplam", + "payments.assign": "Ata", + "payments.assignHelp": "Atama, tüm taksitleri anında ücret olarak yansıtır. Planda olan öğrenciye tekrar ücret çıkmaz.", + "payments.selectStudent": "Öğrenci seç", + "payments.assignments": "Atanan öğrenciler", + "payments.noAssignments": "Henüz öğrenci atanmadı.", + "payments.outcomeAssigned": "Atandı", + "payments.outcomeAlready": "Zaten atanmış", + "payments.outcomeRejected": "Reddedildi", + "payments.studentLedger": "Öğrenci hesabı", + "payments.balance": "Bakiye", + "payments.ledger": "Hesap hareketleri", + "payments.noLedger": "Hesap hareketi yok.", + "payments.recordPayment": "Ödeme kaydet", + "payments.recordRefund": "İade et", + "payments.reverse": "Ters kaydet", + "payments.method": "Yöntem", + "payments.note": "Not", + "payments.reason": "Gerekçe", + "payments.kindCharge": "Ücret", + "payments.kindCredit": "Ödeme", + "payments.kindRefund": "İade", + "payments.kindReversal": "Ters kayıt", + "payments.statementTitle": "Ücretlerim", + "payments.statementSubtitle": "Okula borcunuz ve arkasındaki tüm ücretler.", + "payments.noStatement": "Henüz ücret yok.", + "payments.due": "Vade", + "payments.credited": "Ödenen", + "payments.refunded": "İade", + "payments.outstanding": "Kalan", + "payments.status": "Durum", + "payments.overdue": "Gecikmiş", + "payments.reversed": "Ters kaydedildi", + "payments.paid": "Ödendi", + "payments.appendOnly": "Hesap yalnızca eklenir. Düzeltme, düzenleme değil dengeleyici kayıt gerektirir.", + "payments.tabCollect": "Tahsilat", + "payments.tabPlans": "Ücret planları", + "payments.collect": "Tahsilat Al", + "payments.collectFrom": "Tahsilat al", + "payments.totalDebt": "Toplam borç", + "payments.collected": "Tahsil edilen", + "payments.overdueCount": "Gecikmiş", + "payments.statusPending": "Bekliyor", + "payments.statusPartial": "Kısmi", + "payments.statusCancelled": "İptal edildi", + "payments.noDebt": "Bu öğrenci için henüz borç yok.", + "payments.noDebtHint": "Bu öğrenciye borç çıkmak için Ücret planları sekmesinden bir plan atayın.", + "payments.methodCash": "Nakit", + "payments.methodTransfer": "Havale / EFT", + "payments.methodCard": "Kredi kartı", + "payments.methodCheck": "Çek", + "payments.ledgerAudit": "Hesap hareketleri", + "payments.showLedger": "Hesap hareketlerini göster", + "payments.hideLedger": "Hesap hareketlerini gizle", + "payments.plan": "Plan", "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/lib/payments.ts b/src/lib/payments.ts new file mode 100644 index 0000000..bb7fc28 --- /dev/null +++ b/src/lib/payments.ts @@ -0,0 +1,44 @@ +import type { StatementEntry } from "@/api/payments"; +import type { MessageKey } from "@/i18n/messages"; + +export type StatementStatus = { + key: MessageKey; + // Badge color classes (used with Badge variant="outline") and a matching dot. + class: string; + dot: string; +}; + +// A charge's status, mirrored from the backend rollup fields, in the finance +// operator's vocabulary (paid / partial / overdue / pending / cancelled), with +// receivables-aging colors: green current/paid, amber partial, red overdue. +export function statementStatus(entry: StatementEntry): StatementStatus { + if (entry.reversed) return { key: "payments.statusCancelled", class: "border-border bg-muted/40 text-muted-foreground", dot: "bg-muted-foreground/50" }; + if (entry.outstanding_minor <= 0) return { key: "payments.paid", class: "border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300", dot: "bg-emerald-500" }; + if (entry.overdue) return { key: "payments.overdue", class: "border-red-500/40 bg-red-500/10 text-red-700 dark:text-red-300", dot: "bg-red-500" }; + if (entry.credited_minor > 0) return { key: "payments.statusPartial", class: "border-amber-500/40 bg-amber-500/10 text-amber-800 dark:text-amber-200", dot: "bg-amber-500" }; + return { key: "payments.statusPending", class: "border-border bg-background/50 text-muted-foreground", dot: "bg-muted-foreground/40" }; +} + +// Sort rank for a receivables list: overdue first, then unpaid by due date, +// then settled, then cancelled last. +export function statementSortRank(entry: StatementEntry): number { + if (entry.reversed) return 3; + if (entry.outstanding_minor <= 0) return 2; + if (entry.overdue) return 0; + return 1; +} + +export function sortStatementEntries(entries: StatementEntry[]): StatementEntry[] { + return [...entries].sort( + (a, b) => statementSortRank(a) - statementSortRank(b) || (a.due_at ?? Infinity) - (b.due_at ?? Infinity), + ); +} + +// Common collection methods. Values are stored as free text on the ledger line, +// so the localized label is what a receipt shows. +export const PAYMENT_METHOD_KEYS: MessageKey[] = [ + "payments.methodCash", + "payments.methodTransfer", + "payments.methodCard", + "payments.methodCheck", +]; diff --git a/src/pages/payment-statement-page.tsx b/src/pages/payment-statement-page.tsx new file mode 100644 index 0000000..1601c47 --- /dev/null +++ b/src/pages/payment-statement-page.tsx @@ -0,0 +1,140 @@ +import { Show, Suspense, createEffect, createMemo, createResource, createSignal } from "solid-js"; +import type { ColumnDef } from "@tanstack/solid-table"; +import { + getMyPaymentBalance, + getMyPaymentStatement, + getPaymentBalanceByUserId, + getPaymentStatementByUserId, + type StatementEntry, +} from "@/api/payments"; +import { getMyStudents } from "@/api/parents"; +import { formatApiError } from "@/api/client"; +import { RouteGuard } from "@/components/layout/route-guard"; +import { PageHeader } from "@/components/layout/page-header"; +import { Badge } from "@/components/ui/badge"; +import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; +import { EmptyState } from "@/components/ui/empty-state"; +import { ErrorAlert } from "@/components/ui/error-alert"; +import { Label } from "@/components/ui/label"; +import { SearchableSelect } from "@/components/ui/searchable-select"; +import { formatDate } from "@/lib/format"; +import { formatTry } from "@/lib/meals"; +import { sortStatementEntries, statementStatus } from "@/lib/payments"; +import { personLabel } from "@/lib/person"; +import { useAuth } from "@/stores/auth-context"; +import { usePreferences, useT } from "@/stores/preferences-context"; + +const STATEMENT_PAGE_SIZE = 12; + +export default function PaymentStatementPage() { + return ( + + + + ); +} + +function StatementContent() { + const auth = useAuth(); + const t = useT(); + const { locale } = usePreferences(); + const moneyLocale = () => (locale() === "tr" ? "tr-TR" : "en-US"); + const isParent = () => auth.user()!.role === "parent"; + + const [children] = createResource(() => (isParent() ? getMyStudents({ limit: 100 }) : null)); + const [selectedChild, setSelectedChild] = createSignal(""); + createEffect(() => { + if (isParent() && !selectedChild() && children()?.items[0]) setSelectedChild(children()!.items[0].id); + }); + // Parent reads a child by id; everyone else reads their own record. + const targetId = () => (isParent() ? selectedChild() : ""); + + const [statement, { refetch }] = createResource( + () => (isParent() ? targetId() || null : "me"), + (key) => (key === "me" ? getMyPaymentStatement({ limit: 100 }) : getPaymentStatementByUserId(key, { limit: 100 })), + ); + const [balance] = createResource( + () => (isParent() ? targetId() || null : "me"), + (key) => (key === "me" ? getMyPaymentBalance() : getPaymentBalanceByUserId(key)), + ); + const entries = () => statement()?.entries.items ?? []; + const summary = createMemo(() => { + const rows = entries(); + return { + billed: rows.filter((row) => !row.reversed).reduce((sum, row) => sum + row.amount_minor, 0), + collected: rows.reduce((sum, row) => sum + row.credited_minor, 0), + balance: statement()?.balance_minor ?? balance()?.balance_minor ?? 0, + }; + }); + + const columns = createMemo[]>(() => [ + { + id: "plan", + header: t("payments.planName"), + cell: (cell) => {cell.row.original.plan_name ?? "—"}, + }, + { + accessorKey: "amount_minor", + header: t("payments.amountTry"), + cell: (cell) => {formatTry(cell.row.original.amount_minor, moneyLocale())}, + }, + { + accessorKey: "due_at", + header: t("payments.due"), + cell: (cell) => {cell.row.original.due_at == null ? "—" : formatDate(cell.row.original.due_at, locale())}, + }, + { + accessorKey: "credited_minor", + header: t("payments.credited"), + cell: (cell) => {formatTry(cell.row.original.credited_minor, moneyLocale())}, + }, + { + accessorKey: "outstanding_minor", + header: t("payments.outstanding"), + cell: (cell) => {formatTry(cell.row.original.outstanding_minor, moneyLocale())}, + }, + { + id: "status", + header: t("payments.status"), + cell: (cell) => { + const status = statementStatus(cell.row.original); + return {t(status.key)}; + }, + }, + ]); + + return ( +
+ + + +
+ + ({ value: child.id, label: personLabel(child) }))} /> +
+
+ +
+

{t("payments.totalDebt")}

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

+

{t("payments.collected")}

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

+

{t("payments.balance")}

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

+
+ +
+ }> + + void refetch()} /> + + 0} fallback={}> + + + +
+
+ ); +} diff --git a/src/pages/payments-page.tsx b/src/pages/payments-page.tsx new file mode 100644 index 0000000..e3f94a9 --- /dev/null +++ b/src/pages/payments-page.tsx @@ -0,0 +1,632 @@ +import { For, Index, Show, Suspense, createMemo, createResource, createSignal } from "solid-js"; +import type { ColumnDef } from "@tanstack/solid-table"; +import { + deletePaymentPlanById, + getPaymentLedgerByUserId, + getPaymentPlans, + getPaymentStatementByUserId, + getPlanAssignments, + patchPaymentPlanById, + postPaymentCredit, + postPaymentPlan, + postPaymentRefund, + postPaymentReversal, + postPlanAssignment, + type FeePlan, + type FeePlanInstallment, + type PaymentLine, + type StatementEntry, +} from "@/api/payments"; +import { formatApiError } from "@/api/client"; +import { RouteGuard } from "@/components/layout/route-guard"; +import { PageHeader } from "@/components/layout/page-header"; +import { Alert } from "@/components/ui/alert"; +import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; +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 { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Select } from "@/components/ui/select"; +import { SidePanel } from "@/components/ui/side-panel"; +import { TableRowActions } from "@/components/ui/table-row-actions"; +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import { Textarea } from "@/components/ui/textarea"; +import { UserSearchSelect } from "@/components/users/user-search-select"; +import { createFlash } from "@/lib/flash"; +import { formatDate, formatDateTime } from "@/lib/format"; +import { formatTry } from "@/lib/meals"; +import { PAYMENT_METHOD_KEYS, sortStatementEntries, statementStatus } from "@/lib/payments"; +import { personLabel } from "@/lib/person"; +import { usePreferences, useT } from "@/stores/preferences-context"; + +const PLAN_PAGE_SIZE = 12; +const STATEMENT_PAGE_SIZE = 15; + +function dateInputFromMs(ms: number): string { + const date = new Date(ms); + const pad = (n: number) => String(n).padStart(2, "0"); + return `${pad(date.getDate())}/${pad(date.getMonth() + 1)}/${date.getFullYear()}`; +} + +function dateInputToMs(value: string): number | null { + const match = value.trim().match(/^(\d{2})\/(\d{2})\/(\d{4})$/); + if (!match) return null; + const [, dayRaw, monthRaw, yearRaw] = match; + const day = Number(dayRaw); + const month = Number(monthRaw); + const year = Number(yearRaw); + const date = new Date(year, month - 1, day, 0, 0, 0, 0); + if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) return null; + return date.getTime(); +} + +type LineAction = { line: PaymentLine; kind: "refund" | "reverse" }; + +export default function PaymentsPage() { + return ( + + + + ); +} + +function PaymentsContent() { + const t = useT(); + const { locale } = usePreferences(); + const moneyLocale = () => (locale() === "tr" ? "tr-TR" : "en-US"); + const [tab, setTab] = createSignal("collect"); + const [error, setError] = createSignal(""); + const [flash, setFlash] = createFlash(); + const [pending, setPending] = createSignal(false); + + // ============================ Collection ============================ + const [student, setStudent] = createSignal(""); + const [statement, { refetch: refetchStatement }] = createResource( + () => student() || null, + (userId) => getPaymentStatementByUserId(userId, { limit: 500 }), + ); + const [ledger, { refetch: refetchLedger }] = createResource( + () => student() || null, + (userId) => getPaymentLedgerByUserId(userId, { limit: 200 }), + ); + const entries = () => statement()?.entries.items ?? []; + const sortedEntries = () => sortStatementEntries(entries()); + const summary = createMemo(() => { + const rows = entries(); + return { + billed: rows.filter((row) => !row.reversed).reduce((sum, row) => sum + row.amount_minor, 0), + collected: rows.reduce((sum, row) => sum + row.credited_minor, 0), + overdue: rows.filter((row) => row.overdue).length, + balance: statement()?.balance_minor ?? 0, + }; + }); + + const [collectEntry, setCollectEntry] = createSignal(null); + const [collectAmount, setCollectAmount] = createSignal(""); + const [collectMethod, setCollectMethod] = createSignal(""); + const [collectNote, setCollectNote] = createSignal(""); + + const openCollect = (entry: StatementEntry) => { + setCollectEntry(entry); + setCollectAmount(entry.outstanding_minor > 0 ? String(entry.outstanding_minor / 100) : ""); + setCollectMethod(t("payments.methodCash")); + setCollectNote(""); + setError(""); + }; + const submitCollect = async (e: SubmitEvent) => { + e.preventDefault(); + const entry = collectEntry(); + if (!entry) return; + const amount_minor = Math.round(Number(collectAmount()) * 100); + if (!(amount_minor > 0)) { + setError(t("payments.amountTry")); + return; + } + setPending(true); + setError(""); + try { + await postPaymentCredit({ + charge_id: entry.charge_id, + amount_minor, + method: collectMethod().trim() || undefined, + note: collectNote().trim() || undefined, + request_key: crypto.randomUUID(), + }); + setCollectEntry(null); + setFlash(t("common.saved")); + await Promise.all([refetchStatement(), refetchLedger()]); + } catch (err) { + setError(formatApiError(err)); + } finally { + setPending(false); + } + }; + + const statementColumns = createMemo[]>(() => [ + { + id: "plan", + header: t("payments.plan"), + cell: (cell) => {cell.row.original.plan_name ?? "—"}, + }, + { + accessorKey: "due_at", + header: t("payments.due"), + cell: (cell) => {cell.row.original.due_at == null ? "—" : formatDate(cell.row.original.due_at, locale())}, + }, + { + accessorKey: "amount_minor", + header: t("payments.amountTry"), + cell: (cell) => {formatTry(cell.row.original.amount_minor, moneyLocale())}, + }, + { + accessorKey: "credited_minor", + header: t("payments.collected"), + cell: (cell) => {formatTry(cell.row.original.credited_minor, moneyLocale())}, + }, + { + accessorKey: "outstanding_minor", + header: t("payments.outstanding"), + cell: (cell) => {formatTry(cell.row.original.outstanding_minor, moneyLocale())}, + }, + { + id: "status", + header: t("payments.status"), + cell: (cell) => { + const status = statementStatus(cell.row.original); + return {t(status.key)}; + }, + }, + { + id: "actions", + header: "", + meta: { headerClass: "w-32 min-w-32 text-right", cellClass: "text-right" }, + cell: (cell) => ( + 0}> + + + ), + }, + ]); + + // ---- account activity (advanced corrections) ---- + const [showLedger, setShowLedger] = createSignal(false); + const [lineAction, setLineAction] = createSignal(null); + const [actionAmount, setActionAmount] = createSignal(""); + const [actionNote, setActionNote] = createSignal(""); + const kindLabel = (kind: PaymentLine["kind"]) => t(`payments.kind${kind.charAt(0).toUpperCase()}${kind.slice(1)}` as never); + const openLineAction = (line: PaymentLine, kind: LineAction["kind"]) => { + setLineAction({ line, kind }); + setActionAmount(kind === "refund" ? String(line.amount_minor / 100) : ""); + setActionNote(""); + setError(""); + }; + const submitLineAction = async (e: SubmitEvent) => { + e.preventDefault(); + const action = lineAction(); + if (!action) return; + const note = actionNote().trim() || undefined; + setPending(true); + setError(""); + try { + if (action.kind === "reverse") { + await postPaymentReversal({ line_id: action.line.id, note }); + } else { + const amount_minor = Math.round(Number(actionAmount()) * 100); + if (!(amount_minor > 0)) { + setError(t("payments.amountTry")); + setPending(false); + return; + } + await postPaymentRefund({ credit_id: action.line.id, amount_minor, note, request_key: crypto.randomUUID() }); + } + setLineAction(null); + setFlash(t("common.saved")); + await Promise.all([refetchStatement(), refetchLedger()]); + } catch (err) { + setError(formatApiError(err)); + } finally { + setPending(false); + } + }; + + // ============================ Fee plans ============================ + const [plans, { refetch: refetchPlans }] = createResource(async () => (await getPaymentPlans({ limit: 100 })).items); + const planList = () => plans() ?? []; + const [panelOpen, setPanelOpen] = createSignal(false); + const [editing, setEditing] = createSignal(null); + const [planName, setPlanName] = createSignal(""); + const [rows, setRows] = createSignal<{ amount: string; due: string }[]>([{ amount: "", due: "" }]); + const [deleteTarget, setDeleteTarget] = createSignal(null); + const [assignPlan, setAssignPlan] = createSignal(null); + const [assignStudent, setAssignStudent] = createSignal(""); + const [assignments, { refetch: refetchAssignments }] = createResource( + () => assignPlan()?.id ?? null, + (planId) => getPlanAssignments(planId, { limit: 200 }), + ); + + const planTotal = (plan: FeePlan) => plan.installments.reduce((sum, item) => sum + item.amount_minor, 0); + const planColumns = createMemo[]>(() => [ + { accessorKey: "name", header: t("payments.planName"), cell: (cell) => {cell.row.original.name} }, + { id: "installments", header: t("payments.installments"), cell: (cell) => {cell.row.original.installments.length} }, + { id: "total", header: t("payments.total"), cell: (cell) => {formatTry(planTotal(cell.row.original), moneyLocale())} }, + { + id: "actions", + header: t("common.actions"), + meta: { headerClass: "w-40 min-w-40 text-right whitespace-nowrap", cellClass: "text-right" }, + cell: (cell) => ( +
+ + , onSelect: () => startEdit(cell.row.original) }, + { label: t("common.delete"), icon: , destructive: true, onSelect: () => setDeleteTarget(cell.row.original) }, + ]} + /> +
+ ), + }, + ]); + + const resetPlanForm = () => { + setPlanName(""); + setRows([{ amount: "", due: "" }]); + setEditing(null); + setError(""); + }; + const openCreate = () => { + resetPlanForm(); + setPanelOpen(true); + }; + const startEdit = (plan: FeePlan) => { + setEditing(plan); + setPlanName(plan.name); + setRows(plan.installments.map((item) => ({ amount: String(item.amount_minor / 100), due: dateInputFromMs(item.due_at) }))); + setError(""); + setPanelOpen(true); + }; + const addRow = () => setRows([...rows(), { amount: "", due: "" }]); + const removeRow = (idx: number) => setRows(rows().filter((_, i) => i !== idx)); + const setRowAmount = (idx: number, value: string) => setRows(rows().map((r, i) => (i === idx ? { ...r, amount: value } : r))); + const setRowDue = (idx: number, value: string) => setRows(rows().map((r, i) => (i === idx ? { ...r, due: value } : r))); + + const savePlan = async (e: SubmitEvent) => { + e.preventDefault(); + setError(""); + const installments: FeePlanInstallment[] = []; + for (const row of rows()) { + const amount_minor = Math.round(Number(row.amount) * 100); + const due_at = dateInputToMs(row.due); + if (!(amount_minor > 0) || due_at == null) { + setError(t("terms.dateRequired")); + return; + } + installments.push({ amount_minor, due_at }); + } + setPending(true); + try { + const current = editing(); + if (current) { + await patchPaymentPlanById(current.id, { name: planName().trim(), installments }); + setFlash(t("common.saved")); + } else { + await postPaymentPlan({ name: planName().trim(), installments }); + setFlash(t("common.created")); + } + resetPlanForm(); + setPanelOpen(false); + await refetchPlans(); + } catch (err) { + setError(formatApiError(err)); + } finally { + setPending(false); + } + }; + + const openAssign = (plan: FeePlan) => { + setAssignPlan(plan); + setAssignStudent(""); + setError(""); + }; + const submitAssign = async () => { + const plan = assignPlan(); + const target = assignStudent(); + if (!plan || !target) return; + setPending(true); + setError(""); + try { + const outcomes = await postPlanAssignment(plan.id, { student_ids: [target] }); + const outcome = outcomes[0]; + const key = outcome?.status === "assigned" ? "payments.outcomeAssigned" : outcome?.status === "already_assigned" ? "payments.outcomeAlready" : "payments.outcomeRejected"; + setFlash(t(key as never)); + setAssignStudent(""); + await refetchAssignments(); + } catch (err) { + setError(formatApiError(err)); + } finally { + setPending(false); + } + }; + + const globalError = () => error() && !panelOpen() && !assignPlan() && !collectEntry() && !lineAction(); + + return ( +
+ + + + {flash()} + + + {error()} + + + + + {t("payments.tabCollect")} + {t("payments.tabPlans")} + + + {/* ---------------- Collection ---------------- */} + +
+ +
+ + +
+

{t("payments.totalDebt")}

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

+

{t("payments.collected")}

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

+

{t("payments.balance")}

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

+

{t("payments.overdueCount")}

0 }}>{summary().overdue}

+
+ +
+ }> + + void refetchStatement()} /> + + 0} + fallback={ +
+ +
+ +
+
+ } + > + +
+
+
+ + {/* advanced corrections, folded away */} +
+ + +
+
+

{t("payments.ledgerAudit")}

+

{t("payments.appendOnly")}

+
+
+ + {(line) => ( +
+
+

{kindLabel(line.kind)}

+

{line.note || line.method || "—"} · {formatDateTime(line.created_at, locale())}

+
+
+ {line.kind === "charge" || line.kind === "refund" ? "−" : "+"}{formatTry(line.amount_minor, moneyLocale())} + + + + + + +
+
+ )} +
+ +

{t("payments.noLedger")}

+
+
+
+
+
+
+
+ + {/* ---------------- Fee plans ---------------- */} + +
+ +
+
+ }> + + void refetchPlans()} /> + + 0} fallback={}> + + + +
+
+
+ + {/* ---------------- Collect payment panel ---------------- */} + { if (!open) setCollectEntry(null); }} + title={t("payments.collectFrom")} + description={collectEntry() ? `${collectEntry()!.plan_name ?? "—"} · ${t("payments.outstanding")}: ${formatTry(collectEntry()!.outstanding_minor, moneyLocale())}` : ""} + > +
+ + {error()} + +
+ + setCollectAmount(e.currentTarget.value)} /> +
+
+ + +
+
+ +