Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
46287c4867
commit
ff5e62b673
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user