import{l as c,m as i,p as r,t as n,q as u,o as l,a as v,n as d}from"./index-Cc987VYg.js";import{q as t}from"./query-keys-DGBjVswC.js";const o={getInvoices:async e=>{const s=e?{...e,status:e.status&&Array.isArray(e.status)?e.status.join(","):e.status}:void 0,{data:a}=await c.get(i.AP_INVOICES,{params:s});return a},getInvoice:async e=>{const{data:s}=await c.get(i.AP_INVOICE_DETAIL(e));return s},createInvoice:async e=>{const{data:s}=await c.post(i.AP_INVOICES,e);return s},updateInvoice:async(e,s)=>{const{data:a}=await c.patch(i.AP_INVOICE_DETAIL(e),s);return a},deleteInvoice:async e=>{await c.delete(i.AP_INVOICE_DETAIL(e))},calculateTotals:async(e,s)=>{const{data:a}=await c.post(i.AP_INVOICE_CALCULATE(e),{lines:s});return a},submitForApproval:async e=>{const{data:s}=await c.post(i.AP_INVOICE_SUBMIT(e));return s},postInvoice:async e=>{const{data:s}=await c.post(i.AP_INVOICE_POST(e));return s}},P=e=>d({queryKey:t.accountsPayable.invoices.list(JSON.stringify(e)),queryFn:()=>o.getInvoices(e),staleTime:60*1e3}),q=e=>d({queryKey:t.accountsPayable.invoices.detail(e),queryFn:()=>o.getInvoice(e),enabled:!!e,staleTime:60*1e3}),b=()=>{const e=l(),s=v();return r({mutationFn:o.createInvoice,onSuccess:a=>{e.invalidateQueries({queryKey:t.accountsPayable.invoices.lists()}),e.invalidateQueries({queryKey:t.accountsPayable.vendors.lists()}),n.success("Invoice created successfully"),s(`/accounts-payable/invoices/${a.id}`)},onError:a=>{n.error(u(a))}})},E=()=>{const e=l(),s=v();return r({mutationFn:({id:a,data:y})=>o.updateInvoice(a,y),onSuccess:(a,y)=>{e.invalidateQueries({queryKey:t.accountsPayable.invoices.lists()}),e.invalidateQueries({queryKey:t.accountsPayable.invoices.detail(String(y.id))}),e.invalidateQueries({queryKey:t.accountsPayable.vendors.lists()}),n.success("Invoice updated successfully"),s(`/accounts-payable/invoices/${y.id}`)},onError:a=>{n.error(u(a))}})},A=()=>{const e=l(),s=v();return r({mutationFn:o.deleteInvoice,onSuccess:()=>{e.invalidateQueries({queryKey:t.accountsPayable.invoices.lists()}),e.invalidateQueries({queryKey:t.accountsPayable.vendors.lists()}),n.success("Invoice deleted successfully"),s("/accounts-payable/invoices")},onError:a=>{n.error(u(a))}})},m=()=>{const e=l();return r({mutationFn:o.submitForApproval,onSuccess:s=>{e.invalidateQueries({queryKey:t.accountsPayable.invoices.lists()}),e.invalidateQueries({queryKey:t.accountsPayable.invoices.detail(String(s.id))}),n.success("Invoice submitted for approval")},onError:s=>{n.error(u(s))}})},C=()=>{const e=l();return r({mutationFn:o.postInvoice,onSuccess:s=>{e.invalidateQueries({queryKey:t.accountsPayable.invoices.lists()}),e.invalidateQueries({queryKey:t.accountsPayable.invoices.detail(String(s.id))}),e.invalidateQueries({queryKey:t.accountsPayable.vendors.lists()}),n.success("Invoice posted successfully")},onError:s=>{n.error(u(s))}})},g=()=>r({mutationFn:({id:e,lines:s})=>o.calculateTotals(e,s),onError:e=>{n.error(u(e))}});export{m as a,C as b,A as c,q as d,b as e,E as f,g,o as i,P as u};
