import{l as o,m as n,o as u,a as l,p as c,t as r,q as d,n as N}from"./index-Cc987VYg.js";import{q as a}from"./query-keys-DGBjVswC.js";const i={getCreditNotes:async e=>{const t=e?{...e,status:e.status&&Array.isArray(e.status)?e.status.join(","):e.status}:void 0,{data:s}=await o.get(n.VENDOR_CREDIT_NOTES,{params:t});return s},getCreditNote:async e=>{const{data:t}=await o.get(n.VENDOR_CREDIT_NOTE_DETAIL(e));return t},createCreditNote:async e=>{const{data:t}=await o.post(n.VENDOR_CREDIT_NOTES,e);return t},updateCreditNote:async(e,t)=>{const{data:s}=await o.put(n.VENDOR_CREDIT_NOTE_DETAIL(e),t);return s},patchCreditNote:async(e,t)=>{const{data:s}=await o.patch(n.VENDOR_CREDIT_NOTE_DETAIL(e),t);return s},deleteCreditNote:async e=>{await o.delete(n.VENDOR_CREDIT_NOTE_DETAIL(e))},postCreditNoteToGL:async e=>{const{data:t}=await o.post(n.VENDOR_CREDIT_NOTE_POST(e));return t}},T=e=>N({queryKey:a.accountsPayable.creditNotes.list(JSON.stringify(e)),queryFn:()=>i.getCreditNotes(e),staleTime:60*1e3}),q=e=>N({queryKey:a.accountsPayable.creditNotes.detail(e),queryFn:()=>i.getCreditNote(e),enabled:!!e,staleTime:60*1e3}),p=()=>{const e=u(),t=l();return c({mutationFn:i.createCreditNote,onSuccess:s=>{e.invalidateQueries({queryKey:a.accountsPayable.creditNotes.lists()}),e.invalidateQueries({queryKey:a.accountsPayable.vendors.lists()}),r.success("Credit note created successfully"),t(`/accounts-payable/credit-notes/${s.id}`)},onError:s=>{r.error(d(s))}})},v=()=>{const e=u(),t=l();return c({mutationFn:({id:s,data:y})=>i.updateCreditNote(s,y),onSuccess:(s,y)=>{e.invalidateQueries({queryKey:a.accountsPayable.creditNotes.lists()}),e.invalidateQueries({queryKey:a.accountsPayable.creditNotes.detail(String(y.id))}),e.invalidateQueries({queryKey:a.accountsPayable.vendors.lists()}),r.success("Credit note updated successfully"),t(`/accounts-payable/credit-notes/${y.id}`)},onError:s=>{r.error(d(s))}})},D=()=>{const e=u();return c({mutationFn:({id:t,data:s})=>i.patchCreditNote(t,s),onSuccess:(t,s)=>{e.invalidateQueries({queryKey:a.accountsPayable.creditNotes.lists()}),e.invalidateQueries({queryKey:a.accountsPayable.creditNotes.detail(String(s.id))}),r.success("Credit note updated successfully")},onError:t=>{r.error(d(t))}})},_=()=>{const e=u();return c({mutationFn:i.deleteCreditNote,onSuccess:()=>{e.invalidateQueries({queryKey:a.accountsPayable.creditNotes.lists()}),e.invalidateQueries({queryKey:a.accountsPayable.vendors.lists()}),r.success("Credit note deleted successfully")},onError:t=>{r.error(d(t))}})},P=()=>{const e=u();return c({mutationFn:i.postCreditNoteToGL,onSuccess:t=>{e.invalidateQueries({queryKey:a.accountsPayable.creditNotes.lists()}),e.invalidateQueries({queryKey:a.accountsPayable.creditNotes.detail(String(t.id))}),e.invalidateQueries({queryKey:a.generalLedger.journalEntries.lists()}),r.success("Credit note posted to GL successfully")},onError:t=>{r.error(d(t))}})};export{_ as a,P as b,D as c,q as d,p as e,v as f,T as u,i as v};
