Added Collections indicator

X-Lovable-Edit-ID: edt-6fff85ba-13fb-495f-99aa-78b63f9730f7
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-20 00:28:00 +00:00
co-authored by renee-png
2 changed files with 38 additions and 1 deletions
+8 -1
View File
@@ -482,7 +482,14 @@ function CasesList() {
</Link>
<StatusFlagBadges bk={c.in_bankruptcy} pp={c.on_payment_plan} />
</span>
<div className="text-xs text-muted-foreground">{c.case_number}</div>
<div className="text-xs text-muted-foreground flex items-center gap-2">
<span>{c.case_number}</span>
{c.practice_area === "Community Ass'n Law - Collections" && (
<span className="text-[10px] font-semibold uppercase tracking-wide text-red-600 dark:text-red-400">
Collections
</span>
)}
</div>
</td>
<td className="px-4 py-3 text-muted-foreground">{c.client?.name ?? "—"}</td>
<td className="px-4 py-3">
@@ -0,0 +1,30 @@
-- Function: ensure a case with the Collections practice area has at least one collection row.
CREATE OR REPLACE FUNCTION public.tg_ensure_collection_for_collections_case()
RETURNS trigger
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = public
AS $$
BEGIN
IF NEW.practice_area = 'Community Ass''n Law - Collections' THEN
IF NOT EXISTS (SELECT 1 FROM public.collections WHERE case_id = NEW.id) THEN
INSERT INTO public.collections (case_id, status, opened_at, created_by)
VALUES (NEW.id, 'late_notice', COALESCE(NEW.opened_at, CURRENT_DATE), NEW.created_by);
END IF;
END IF;
RETURN NEW;
END;
$$;
DROP TRIGGER IF EXISTS trg_ensure_collection_for_collections_case ON public.cases;
CREATE TRIGGER trg_ensure_collection_for_collections_case
AFTER INSERT OR UPDATE OF practice_area ON public.cases
FOR EACH ROW
EXECUTE FUNCTION public.tg_ensure_collection_for_collections_case();
-- One-time backfill for existing cases.
INSERT INTO public.collections (case_id, status, opened_at, created_by)
SELECT c.id, 'late_notice', COALESCE(c.opened_at, CURRENT_DATE), c.created_by
FROM public.cases c
WHERE c.practice_area = 'Community Ass''n Law - Collections'
AND NOT EXISTS (SELECT 1 FROM public.collections col WHERE col.case_id = c.id);