hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import type { StatementEntry } from "@/api/payments"; |
| 2 | import type { MessageKey } from "@/i18n/messages"; |
| 3 | |
| 4 | export type StatementStatus = { |
| 5 | key: MessageKey; |
| 6 | // Badge color classes (used with Badge variant="outline") and a matching dot. |
| 7 | class: string; |
| 8 | dot: string; |
| 9 | }; |
| 10 | |
| 11 | // A charge's status, mirrored from the backend rollup fields, in the finance |
| 12 | // operator's vocabulary (paid / partial / overdue / pending / cancelled), with |
| 13 | // receivables-aging colors: green current/paid, amber partial, red overdue. |
| 14 | export function statementStatus(entry: StatementEntry): StatementStatus { |
| 15 | if (entry.reversed) return { key: "payments.statusCancelled", class: "border-border bg-muted/40 text-muted-foreground", dot: "bg-muted-foreground/50" }; |
| 16 | if (entry.outstanding_minor <= 0) return { key: "payments.paid", class: "border-success/50 bg-success/10 text-success-text", dot: "bg-success" }; |
| 17 | if (entry.overdue) return { key: "payments.overdue", class: "border-destructive/50 bg-destructive/10 text-destructive-text", dot: "bg-destructive" }; |
| 18 | if (entry.credited_minor > 0) return { key: "payments.statusPartial", class: "border-warning/50 bg-warning/10 text-warning-text", dot: "bg-warning" }; |
| 19 | return { key: "payments.statusPending", class: "border-border bg-background/50 text-muted-foreground", dot: "bg-muted-foreground/40" }; |
| 20 | } |
| 21 | |
| 22 | // Sort rank for a receivables list: overdue first, then unpaid by due date, |
| 23 | // then settled, then cancelled last. |
| 24 | export function statementSortRank(entry: StatementEntry): number { |
| 25 | if (entry.reversed) return 3; |
| 26 | if (entry.outstanding_minor <= 0) return 2; |
| 27 | if (entry.overdue) return 0; |
| 28 | return 1; |
| 29 | } |
| 30 | |
| 31 | export function sortStatementEntries(entries: StatementEntry[]): StatementEntry[] { |
| 32 | return [...entries].sort( |
| 33 | (a, b) => statementSortRank(a) - statementSortRank(b) || (a.due_at ?? Infinity) - (b.due_at ?? Infinity), |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | // Common collection methods. Values are stored as free text on the ledger line, |
| 38 | // so the localized label is what a receipt shows. |
| 39 | export const PAYMENT_METHOD_KEYS: MessageKey[] = [ |
| 40 | "payments.methodCash", |
| 41 | "payments.methodTransfer", |
| 42 | "payments.methodCard", |
| 43 | "payments.methodCheck", |
| 44 | ]; |