Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
36fb3bbfb4
commit
d5abd69f24
@@ -317,10 +317,16 @@ function InvoiceDetail() {
|
||||
};
|
||||
|
||||
const deleteInvoice = async () => {
|
||||
if (!confirm("Delete this draft invoice and unbill its time/expenses?")) return;
|
||||
const msg = isDraft
|
||||
? "Delete this draft invoice and unbill its time/expenses?"
|
||||
: `Permanently delete invoice ${invoice.invoice_number}? This will remove all payments and unbill its time/expenses. This cannot be undone.`;
|
||||
if (!confirm(msg)) return;
|
||||
// Unlink time/expenses
|
||||
await supabase.from("time_entries").update({ invoice_id: null }).eq("invoice_id", invoiceId);
|
||||
await supabase.from("expenses").update({ invoice_id: null }).eq("invoice_id", invoiceId);
|
||||
// Remove payments first (no cascade guarantee)
|
||||
await supabase.from("invoice_payments").delete().eq("invoice_id", invoiceId);
|
||||
await supabase.from("invoice_line_items").delete().eq("invoice_id", invoiceId);
|
||||
const { error } = await supabase.from("invoices").delete().eq("id", invoiceId);
|
||||
if (error) return toast.error(error.message);
|
||||
toast.success("Invoice deleted");
|
||||
|
||||
Reference in New Issue
Block a user