- Teacher picks a day of the month in Settings; an hourly job creates the fees of all monthly groups on that day in the teacher's time zone (one run per teacher and month, partial unique index per attendee/period). - One Mercado Pago link per payer (PaymentCheckout): the adult in charge bundles their kids and their own fees; external_reference chk_<id>, dedicated webhook and reconciliation mark every fee PAID at once. - Person.payWithMercadoPago toggle (default on): off creates the fee without a link so the student pays by transfer. - A fee paid some other way supersedes its combined link and expires the preference; renewing rebuilds the combined link or a single one. - Optional WhatsApp delivery (PAYMENT_LINK kind, new Kapso template); weekly reminders now go once per combined link. - Web: auto charge settings card, per-student toggle, combined link label in Cobros and "Pay all" in the student app, in the four locales. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import type { PaymentDto } from '@gruperly/shared'
|
|
import type { BadgeVariant } from '../../components/ui'
|
|
import { i18n } from '../../i18n/instance'
|
|
|
|
export const PAYMENT_STATUS_BADGE: Record<PaymentDto['status'], BadgeVariant> = {
|
|
PENDING: 'neutral',
|
|
PAID: 'success',
|
|
OVERDUE: 'danger',
|
|
CANCELLED: 'warning',
|
|
}
|
|
|
|
export function paymentPeriodLabel(payment: PaymentDto): string {
|
|
if (payment.description) return payment.description
|
|
if (payment.periodKey) return periodKeyLabel(payment.periodKey)
|
|
return payment.groupName
|
|
}
|
|
|
|
/* "2026-12" → "Diciembre 2026", en el idioma de la UI. */
|
|
export function periodKeyLabel(periodKey: string): string {
|
|
const [year, month] = periodKey.split('-').map(Number)
|
|
const text = new Date(Date.UTC(year ?? 2000, (month ?? 1) - 1, 15)).toLocaleDateString(i18n.language, {
|
|
month: 'long',
|
|
year: 'numeric',
|
|
timeZone: 'UTC',
|
|
})
|
|
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
}
|
|
|
|
export function paymentDateLabel(payment: PaymentDto): string {
|
|
if (payment.status === 'PAID' && payment.paidAt) {
|
|
return i18n.t('payments:row.paidOn', { date: formatDay(payment.paidAt) })
|
|
}
|
|
return i18n.t('payments:row.dueOn', { date: formatDay(payment.dueDate) })
|
|
}
|
|
|
|
/* Fechas sin hora: el vencimiento es un día, no un instante. */
|
|
function formatDay(iso: string): string {
|
|
const date = new Date(iso)
|
|
const today = new Date()
|
|
const sameYear = date.getFullYear() === today.getFullYear()
|
|
return date.toLocaleDateString(i18n.language, {
|
|
day: 'numeric',
|
|
month: 'short',
|
|
...(sameYear ? {} : { year: 'numeric' }),
|
|
})
|
|
} |