import{l as n,m as i,o as u,a as l,p as c,t as o,q as y,n as b}from"./index-C-gKvEDq.js";import{q as a}from"./query-keys-DGBjVswC.js";const r={getDebitNotes:async e=>{const t=e?{...e,status:e.status&&Array.isArray(e.status)?e.status.join(","):e.status}:void 0,{data:s}=await n.get(i.VENDOR_DEBIT_NOTES,{params:t});return s},getDebitNote:async e=>{const{data:t}=await n.get(i.VENDOR_DEBIT_NOTE_DETAIL(e));return t},createDebitNote:async e=>{const{data:t}=await n.post(i.VENDOR_DEBIT_NOTES,e);return t},updateDebitNote:async(e,t)=>{const{data:s}=await n.put(i.VENDOR_DEBIT_NOTE_DETAIL(e),t);return s},patchDebitNote:async(e,t)=>{const{data:s}=await n.patch(i.VENDOR_DEBIT_NOTE_DETAIL(e),t);return s},deleteDebitNote:async e=>{await n.delete(i.VENDOR_DEBIT_NOTE_DETAIL(e))},postDebitNoteToGL:async e=>{const{data:t}=await n.post(i.VENDOR_DEBIT_NOTE_POST(e));return t}},E=e=>b({queryKey:a.accountsPayable.debitNotes.list(JSON.stringify(e)),queryFn:()=>r.getDebitNotes(e),staleTime:60*1e3}),T=e=>b({queryKey:a.accountsPayable.debitNotes.detail(e),queryFn:()=>r.getDebitNote(e),enabled:!!e,staleTime:60*1e3}),q=()=>{const e=u(),t=l();return c({mutationFn:r.createDebitNote,onSuccess:s=>{e.invalidateQueries({queryKey:a.accountsPayable.debitNotes.lists()}),e.invalidateQueries({queryKey:a.accountsPayable.vendors.lists()}),o.success("Debit note created successfully"),t(`/accounts-payable/debit-notes/${s.id}`)},onError:s=>{o.error(y(s))}})},p=()=>{const e=u(),t=l();return c({mutationFn:({id:s,data:d})=>r.updateDebitNote(s,d),onSuccess:(s,d)=>{e.invalidateQueries({queryKey:a.accountsPayable.debitNotes.lists()}),e.invalidateQueries({queryKey:a.accountsPayable.debitNotes.detail(String(d.id))}),e.invalidateQueries({queryKey:a.accountsPayable.vendors.lists()}),o.success("Debit note updated successfully"),t(`/accounts-payable/debit-notes/${d.id}`)},onError:s=>{o.error(y(s))}})},v=()=>{const e=u();return c({mutationFn:({id:t,data:s})=>r.patchDebitNote(t,s),onSuccess:(t,s)=>{e.invalidateQueries({queryKey:a.accountsPayable.debitNotes.lists()}),e.invalidateQueries({queryKey:a.accountsPayable.debitNotes.detail(String(s.id))}),o.success("Debit note updated successfully")},onError:t=>{o.error(y(t))}})},_=()=>{const e=u();return c({mutationFn:r.deleteDebitNote,onSuccess:()=>{e.invalidateQueries({queryKey:a.accountsPayable.debitNotes.lists()}),e.invalidateQueries({queryKey:a.accountsPayable.vendors.lists()}),o.success("Debit note deleted successfully")},onError:t=>{o.error(y(t))}})},P=()=>{const e=u();return c({mutationFn:r.postDebitNoteToGL,onSuccess:t=>{e.invalidateQueries({queryKey:a.accountsPayable.debitNotes.lists()}),e.invalidateQueries({queryKey:a.accountsPayable.debitNotes.detail(String(t.id))}),e.invalidateQueries({queryKey:a.generalLedger.journalEntries.lists()}),o.success("Debit note posted to GL successfully")},onError:t=>{o.error(y(t))}})};export{_ as a,P as b,v as c,T as d,q as e,p as f,E as u,r as v};
