Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
8373be860c
commit
36fb3bbfb4
@@ -131,6 +131,26 @@ function InvoiceDetail() {
|
||||
const balance = Number(invoice.total) - Number(invoice.amount_paid);
|
||||
|
||||
const setStatus = async (status: string) => {
|
||||
if (status === "void") {
|
||||
if (!confirm("Void this invoice? Totals will be zeroed out and time/expenses will be unbilled.")) return;
|
||||
// Unlink time/expenses so they go back to unbilled
|
||||
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);
|
||||
// Zero out line item amounts/rates so the invoice reads as $0
|
||||
await supabase
|
||||
.from("invoice_line_items")
|
||||
.update({ amount: 0, rate: 0, quantity: 0 })
|
||||
.eq("invoice_id", invoiceId);
|
||||
// Zero invoice totals + set status
|
||||
const { error } = await supabase
|
||||
.from("invoices")
|
||||
.update({ status: "void" as any, subtotal: 0, tax: 0, total: 0 })
|
||||
.eq("id", invoiceId);
|
||||
if (error) return toast.error(error.message);
|
||||
toast.success("Invoice voided and zeroed out");
|
||||
load();
|
||||
return;
|
||||
}
|
||||
const { error } = await supabase.from("invoices").update({ status: status as any }).eq("id", invoiceId);
|
||||
if (error) toast.error(error.message);
|
||||
else { toast.success(`Marked ${status}`); load(); }
|
||||
|
||||
Reference in New Issue
Block a user