diff --git a/apps/client/locales/en/leo.json b/apps/client/locales/en/leo.json index a9f5cb8fb..5ef9306af 100644 --- a/apps/client/locales/en/leo.json +++ b/apps/client/locales/en/leo.json @@ -385,7 +385,8 @@ "arrestReportLogs": "Arrest report logs", "all": "All", "ungrouped": "Ungrouped", - "counts": "Counts" + "counts": "Counts", + "stats": "Stats" }, "Bolos": { "activeBolos": "Active Bolos", diff --git a/apps/client/src/components/leo/citizen-logs/arrest-reports-tab.tsx b/apps/client/src/components/leo/citizen-logs/arrest-reports-tab.tsx index 48bf4454e..a587dfa90 100644 --- a/apps/client/src/components/leo/citizen-logs/arrest-reports-tab.tsx +++ b/apps/client/src/components/leo/citizen-logs/arrest-reports-tab.tsx @@ -24,6 +24,7 @@ import type { } from "@snailycad/types/api"; import { useQuery } from "@tanstack/react-query"; import { RecordsCaseNumberColumn } from "../records-case-number-column"; +import { RecordsStatsColumn } from "../records-stats-column"; interface Props { arrestReports: GetManagePendingArrestReports; @@ -134,6 +135,7 @@ export function PendingCitizenRecordsTab({ arrestReports }: Props) { {record.notes} ), + stats: , violations: , createdAt: createdAt ? {createdAt} : "—", status: {record.status}, @@ -172,6 +174,7 @@ export function PendingCitizenRecordsTab({ arrestReports }: Props) { { header: t("postal"), accessorKey: "postal" }, { header: t("status"), accessorKey: "status" }, { header: t("notes"), accessorKey: "notes" }, + { header: t("notes"), accessorKey: "stats" }, { header: t("violations"), accessorKey: "violations" }, { header: common("createdAt"), accessorKey: "createdAt" }, { header: common("actions"), accessorKey: "actions" }, diff --git a/apps/client/src/components/leo/records-stats-column.tsx b/apps/client/src/components/leo/records-stats-column.tsx new file mode 100644 index 000000000..ddd348b69 --- /dev/null +++ b/apps/client/src/components/leo/records-stats-column.tsx @@ -0,0 +1,45 @@ +import { Record, Violation } from "@snailycad/types"; +import { useTranslations } from "use-intl"; + +interface Props { + record: Record; +} + +function sumOf(violations: Violation[], type: "fine" | "jailTime" | "bail"): number { + let sum = 0; + + for (const violation of violations) { + const counts = violation.counts || 1; + const fine = violation[type]; + + if (fine) { + sum += fine * counts; + } + } + + return sum; +} + +function formatSum(sum: number) { + return Intl.NumberFormat().format(sum); +} + +export function RecordsStatsColumn(props: Props) { + const totalBail = formatSum(sumOf(props.record.violations, "bail")); + const totalJail = formatSum(sumOf(props.record.violations, "jailTime")); + const totalFines = formatSum(sumOf(props.record.violations, "fine")); + const t = useTranslations("Leo"); + const common = useTranslations("Common"); + + return ( + <> + {t("fines")}: {common("currency")} + {totalFines} +
+ {t("jail")}: {totalJail} +
+ {t("bail")}: {common("currency")} + {totalBail} + + ); +} diff --git a/apps/client/src/pages/officer/supervisor/citizen-logs/[citizenId].tsx b/apps/client/src/pages/officer/supervisor/citizen-logs/[citizenId].tsx index 40bd4e4d2..0138d386e 100644 --- a/apps/client/src/pages/officer/supervisor/citizen-logs/[citizenId].tsx +++ b/apps/client/src/pages/officer/supervisor/citizen-logs/[citizenId].tsx @@ -16,6 +16,7 @@ import Link from "next/link"; import { FullDate, Status, buttonVariants } from "@snailycad/ui"; import { ArrowLeft } from "react-bootstrap-icons"; import { RecordsCaseNumberColumn } from "components/leo/records-case-number-column"; +import { RecordsStatsColumn } from "components/leo/records-stats-column"; export type CitizenLog = RecordLog & { citizen: Citizen }; interface Props { @@ -79,6 +80,7 @@ export default function CitizenLogs(props: Props) { status: {item.records.status}, postal: item.records.postal || common("none"), notes: item.records.notes || common("none"), + stats: , violations: , paymentStatus: {item.records.paymentStatus}, } @@ -107,6 +109,7 @@ export default function CitizenLogs(props: Props) { { header: t("postal"), accessorKey: "postal" }, { header: t("status"), accessorKey: "status" }, { header: t("paymentStatus"), accessorKey: "paymentStatus" }, + { header: t("stats"), accessorKey: "stats" }, { header: t("notes"), accessorKey: "notes" }, { header: t("violations"), accessorKey: "violations" }, { header: common("createdAt"), accessorKey: "createdAt" },