芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/public_html/invoicer.pulsehost.co.uk/public/build/assets/expense-BPtkoXBs.js
import{ab as E,a4 as _,s as c,a1 as p,aH as h,u as o}from"./main-WS8l16KQ.js";const r={expense_category_id:null,expense_date:E().format("YYYY-MM-DD"),amount:100,notes:"",attachment_receipt:null,customer_id:"",currency_id:"",payment_method_id:"",receiptFiles:[],customFields:[],fields:[],in_use:!1,selectedCurrency:null},w=(x=!1)=>{const m=x?window.pinia.defineStore:_,{global:d}=window.i18n;return m({id:"expense",state:()=>({expenses:[],totalExpenses:0,selectAllField:!1,selectedExpenses:[],paymentModes:[],showExchangeRate:!1,currentExpense:{...r}}),getters:{getCurrentExpense:t=>t.currentExpense,getSelectedExpenses:t=>t.selectedExpenses},actions:{resetCurrentExpenseData(){this.currentExpense={...r}},fetchExpenses(t){return new Promise((s,a)=>{c.get("/api/v1/expenses",{params:t}).then(e=>{this.expenses=e.data.data,this.totalExpenses=e.data.meta.expense_total_count,s(e)}).catch(e=>{p(e),a(e)})})},fetchExpense(t){return new Promise((s,a)=>{c.get(`/api/v1/expenses/${t}`).then(e=>{e.data&&(Object.assign(this.currentExpense,e.data.data),this.currentExpense.selectedCurrency=e.data.data.currency,this.currentExpense.attachment_receipt=null,e.data.data.attachment_receipt_url?h.isImageFile(e.data.data.attachment_receipt_meta.mime_type)?this.currentExpense.receiptFiles=[{image:`/reports/expenses/${t}/receipt?${e.data.data.attachment_receipt_meta.uuid}`}]:this.currentExpense.receiptFiles=[{type:"document",name:e.data.data.attachment_receipt_meta.file_name}]:this.currentExpense.receiptFiles=[]),s(e)}).catch(e=>{p(e),a(e)})})},addExpense(t){const s=h.toFormData(t);return new Promise((a,e)=>{c.post("/api/v1/expenses",s).then(n=>{this.expenses.push(n.data),o().showNotification({type:"success",message:d.t("expenses.created_message")}),a(n)}).catch(n=>{p(n),e(n)})})},updateExpense({id:t,data:s,isAttachmentReceiptRemoved:a}){const e=o(),n=h.toFormData(s);return n.append("_method","PUT"),n.append("is_attachment_receipt_removed",a),new Promise(i=>{c.post(`/api/v1/expenses/${t}`,n).then(l=>{let u=this.expenses.findIndex(f=>f.id===l.data.id);this.expenses[u]=s.expense,e.showNotification({type:"success",message:d.t("expenses.updated_message")}),i(l)})}).catch(i=>{p(i),reject(i)})},setSelectAllState(t){this.selectAllField=t},selectExpense(t){this.selectedExpenses=t,this.selectedExpenses.length===this.expenses.length?this.selectAllField=!0:this.selectAllField=!1},selectAllExpenses(t){if(this.selectedExpenses.length===this.expenses.length)this.selectedExpenses=[],this.selectAllField=!1;else{let s=this.expenses.map(a=>a.id);this.selectedExpenses=s,this.selectAllField=!0}},deleteExpense(t){const s=o();return new Promise((a,e)=>{c.post("/api/v1/expenses/delete",t).then(n=>{let i=this.expenses.findIndex(l=>l.id===t);this.expenses.splice(i,1),s.showNotification({type:"success",message:d.tc("expenses.deleted_message",1)}),a(n)}).catch(n=>{p(n),e(n)})})},deleteMultipleExpenses(){const t=o();return new Promise((s,a)=>{c.post("/api/v1/expenses/delete",{ids:this.selectedExpenses}).then(e=>{this.selectedExpenses.forEach(n=>{let i=this.expenses.findIndex(l=>l.id===n.id);this.expenses.splice(i,1)}),t.showNotification({type:"success",message:d.tc("expenses.deleted_message",2)}),s(e)}).catch(e=>{p(e),a(e)})})},fetchPaymentModes(t){return new Promise((s,a)=>{c.get("/api/v1/payment-methods",{params:t}).then(e=>{this.paymentModes=e.data.data,s(e)}).catch(e=>{p(e),a(e)})})}}})()};export{w as u};