diff --git a/src/components/cases/time-tab.tsx b/src/components/cases/time-tab.tsx index 0c3b79b..c22fb93 100644 --- a/src/components/cases/time-tab.tsx +++ b/src/components/cases/time-tab.tsx @@ -135,6 +135,28 @@ export function CaseTimeTab({ caseRecord, onInvoice }: CaseTimeTabProps) { if (error) toast.error(error.message); else { toast.success("Deleted"); load(); } }; + const toggleInvoiced = async (entry: any) => { + if (entry.invoice_id) { + // Unmark + const { error } = await supabase.from("time_entries").update({ invoice_id: null }).eq("id", entry.id); + if (error) { toast.error(error.message); return; } + toast.success("Marked as unbilled"); + load(); + } else { + if (!user?.id) { toast.error("Not signed in"); return; } + if (!caseRecord.client_id) { toast.error("Case has no client to invoice against"); return; } + try { + const invId = await ensureMarkedInvoicedPlaceholder(caseRecord.client_id, caseRecord.id, user.id); + const { error } = await supabase.from("time_entries").update({ invoice_id: invId }).eq("id", entry.id); + if (error) throw error; + toast.success("Marked as invoiced"); + load(); + } catch (err: any) { + toast.error(err?.message ?? "Could not mark as invoiced"); + } + } + }; + const totals = entries.reduce( (acc, e) => ({ hours: acc.hours + Number(e.hours),