diff --git a/apps/api/src/customers/customers.service.ts b/apps/api/src/customers/customers.service.ts index b523737..22af4b3 100644 --- a/apps/api/src/customers/customers.service.ts +++ b/apps/api/src/customers/customers.service.ts @@ -96,6 +96,13 @@ export class CustomersService { /** Full unified customer view: identity + both business lines + ledger. */ async detail(id: string) { + // The movement list on the customer file is the same statement the office + // prints, so it follows the same rule as BillingService.statement: this + // calendar year, oldest-first. No `take` any more — the cap used to hide + // the end of a busy customer's year once the order flipped, and a single + // year is small (365 rows for the heaviest customer in the book). + const yearStart = new Date(Date.UTC(new Date().getUTCFullYear(), 0, 1)); + const customer = await this.prisma.customer.findUnique({ where: { id }, include: { @@ -117,8 +124,8 @@ export class CustomersService { }, }, transactions: { - orderBy: { transactionDate: "desc" }, - take: 100, + where: { transactionDate: { gte: yearStart } }, + orderBy: [{ transactionDate: "asc" }, { id: "asc" }], include: { type: true }, }, }, @@ -140,6 +147,8 @@ export class CustomersService { return { ...customer, + /** Calendar year the movement list covers. */ + transactionYear: yearStart.getUTCFullYear(), transactionSummary: summary.map((s) => ({ domain: s.domain, currency: s.currency, diff --git a/apps/web/src/app/clientes/[id]/page.tsx b/apps/web/src/app/clientes/[id]/page.tsx index df8e249..8d7c3dd 100644 --- a/apps/web/src/app/clientes/[id]/page.tsx +++ b/apps/web/src/app/clientes/[id]/page.tsx @@ -128,6 +128,7 @@ function Detail({ id }: { id: string }) { customerId={data.id} summary={data.transactionSummary} transactions={data.transactions} + year={data.transactionYear} /> @@ -746,16 +747,18 @@ function EstadoCuentaSection({ customerId, summary, transactions, + year, }: { customerId: string; summary: TransactionSummaryRow[]; transactions: Transaction[]; + year: number; }) { return (
@@ -782,7 +785,7 @@ function EstadoCuentaSection({
{transactions.length === 0 ? ( -
Sin movimientos registrados.
+
Sin movimientos en {year}.
) : (
@@ -804,11 +807,10 @@ function EstadoCuentaSection({
)} - {transactions.length >= 100 && ( -
- Mostrando los 100 movimientos más recientes. -
- )} +
+ Movimientos de {year}, del más antiguo al más reciente. Los saldos de + arriba son el acumulado histórico, no el del año. +
{transactions.length > 0 && (

diff --git a/apps/web/src/lib/types.ts b/apps/web/src/lib/types.ts index c694702..e9f0b67 100644 --- a/apps/web/src/lib/types.ts +++ b/apps/web/src/lib/types.ts @@ -1129,6 +1129,8 @@ export interface CustomerDetail { properties: Property[]; policies: Policy[]; transactions: Transaction[]; + /** Calendar year `transactions` covers. */ + transactionYear: number; transactionSummary: TransactionSummaryRow[]; }