const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/payment.service-Q07Sp9sM.js","assets/payment.service-CJ5dn5gC.js","assets/client-hbcFGf8j.js","assets/local-storage-DuQCXLd0.js","assets/chunk-BEqpzyXh.js","assets/endpoints-Bdye5CiX.js"])))=>i.map(i=>d[i]);
import{n as e}from"./client-hbcFGf8j.js";import{n as t}from"./pinia-C4FTeoHo.js";import{t as n}from"./expense.service-CwzJ5sGm.js";function r(){return{id:null,expense_date:``,expense_number:``,amount:0,notes:``,customer_id:null,expense_category_id:null,payment_method_id:null,currency_id:null,exchange_rate:null,selectedCurrency:null,attachment_receipt:null,attachment_receipt_url:null,receiptFiles:[],customFields:[],fields:[]}}var i=t(`expense`,{state:()=>({expenses:[],totalExpenses:0,selectAllField:!1,selectedExpenses:[],paymentModes:[],showExchangeRate:!1,currentExpense:r()}),getters:{getCurrentExpense:e=>e.currentExpense,getSelectedExpenses:e=>e.selectedExpenses},actions:{resetCurrentExpenseData(){this.currentExpense=r()},async fetchExpenses(e){let t=await n.list(e);return this.expenses=t.data,this.totalExpenses=t.meta.expense_total_count,{data:t}},async fetchExpense(e){let t=await n.get(e),r=t.data;return Object.assign(this.currentExpense,r),this.currentExpense.selectedCurrency=r.currency??null,this.currentExpense.attachment_receipt=null,r.attachment_receipt_url?r.attachment_receipt_meta?.mime_type?.startsWith(`image/`)?this.currentExpense.receiptFiles=[{image:`/reports/expenses/${e}/receipt?${r.attachment_receipt_meta.uuid}`}]:r.attachment_receipt_meta&&(this.currentExpense.receiptFiles=[{type:`document`,name:r.attachment_receipt_meta.file_name}]):this.currentExpense.receiptFiles=[],{data:t}},async addExpense(e){let t=a(e),r=await n.create(t);return this.expenses.push(r.data),{data:r}},async updateExpense(e){let t=a(e.data);t.append(`_method`,`PUT`),t.append(`is_attachment_receipt_removed`,String(e.isAttachmentReceiptRemoved));let r=await n.update(e.id,t),i=this.expenses.findIndex(e=>e.id===r.data.id);return i!==-1&&(this.expenses[i]=r.data),{data:r}},async deleteExpense(e){let t=await n.delete(e),r=e.ids[0],i=this.expenses.findIndex(e=>e.id===r);return i!==-1&&this.expenses.splice(i,1),{data:t}},async deleteMultipleExpenses(){let e=await n.delete({ids:this.selectedExpenses});return this.selectedExpenses.forEach(e=>{let t=this.expenses.findIndex(t=>t.id===e);t!==-1&&this.expenses.splice(t,1)}),this.selectedExpenses=[],{data:e}},async fetchPaymentModes(t){let{paymentService:n}=await e(async()=>{let{paymentService:e}=await import(`./payment.service-Q07Sp9sM.js`);return{paymentService:e}},__vite__mapDeps([0,1,2,3,4,5])),r=await n.listMethods(t);return this.paymentModes=r.data,{data:r}},setSelectAllState(e){this.selectAllField=e},selectExpense(e){this.selectedExpenses=e,this.selectAllField=this.selectedExpenses.length===this.expenses.length},selectAllExpenses(){this.selectedExpenses.length===this.expenses.length?(this.selectedExpenses=[],this.selectAllField=!1):(this.selectedExpenses=this.expenses.map(e=>e.id),this.selectAllField=!0)}}});function a(e){let t=new FormData;for(let n of Object.keys(e)){let r=e[n];r!=null&&(r instanceof File?t.append(n,r):typeof r==`object`&&!(r instanceof Blob)?t.append(n,JSON.stringify(r)):t.append(n,String(r)))}return t}export{i as t};