mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-30 13:11:08 -04:00
build version 400
This commit is contained in:
@ -3,156 +3,181 @@ import * as dashboardTypes from '../dashboard/mutation-types'
|
||||
|
||||
export const fetchInvoices = ({ commit, dispatch, state }, params) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.get(`/api/invoices`, {params}).then((response) => {
|
||||
commit(types.SET_INVOICES, response.data.invoices.data)
|
||||
commit(types.SET_TOTAL_INVOICES, response.data.invoiceTotalCount)
|
||||
resolve(response)
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchCreateInvoice = ({ commit, dispatch, state }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.get(`/api/invoices/create`).then((response) => {
|
||||
resolve(response)
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
window.axios
|
||||
.get(`/api/v1/invoices`, { params })
|
||||
.then((response) => {
|
||||
commit(types.SET_INVOICES, response.data.invoices.data)
|
||||
commit(types.SET_TOTAL_INVOICES, response.data.invoiceTotalCount)
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchInvoice = ({ commit, dispatch, state }, id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.get(`/api/invoices/${id}/edit`).then((response) => {
|
||||
commit(types.SET_TEMPLATE_ID, response.data.invoice.invoice_template_id)
|
||||
resolve(response)
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchViewInvoice = ({ commit, dispatch, state }, id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.get(`/api/invoices/${id}`).then((response) => {
|
||||
resolve(response)
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
window.axios
|
||||
.get(`/api/v1/invoices/${id}`)
|
||||
.then((response) => {
|
||||
commit(types.SET_TEMPLATE_ID, response.data.invoice.invoice_template_id)
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const sendEmail = ({ commit, dispatch, state }, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.post(`/api/invoices/send`, data).then((response) => {
|
||||
if (response.data.success) {
|
||||
commit(types.UPDATE_INVOICE_STATUS, {id: data.id, status: 'SENT'})
|
||||
commit('dashboard/' + dashboardTypes.UPDATE_INVOICE_STATUS, {id: data.id, status: 'SENT'}, { root: true })
|
||||
}
|
||||
resolve(response)
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
window.axios
|
||||
.post(`/api/v1/invoices/${data.id}/send`, data)
|
||||
.then((response) => {
|
||||
if (response.data.success) {
|
||||
commit(types.UPDATE_INVOICE_STATUS, { id: data.id, status: 'SENT' })
|
||||
commit(
|
||||
'dashboard/' + dashboardTypes.UPDATE_INVOICE_STATUS,
|
||||
{ id: data.id, status: 'SENT' },
|
||||
{ root: true }
|
||||
)
|
||||
}
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// export const SentEmail = ({ commit, dispatch, state }, invoiceId) => {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// window.axios.post(`/api/invoices/sent/${invoiceId}`).then((response) => {
|
||||
// resolve(response)
|
||||
// }).catch((err) => {
|
||||
// reject(err)
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
|
||||
export const addInvoice = ({ commit, dispatch, state }, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.post('/api/invoices', data).then((response) => {
|
||||
commit(types.ADD_INVOICE, response.data)
|
||||
resolve(response)
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
window.axios
|
||||
.post('/api/v1/invoices', data)
|
||||
.then((response) => {
|
||||
commit(types.ADD_INVOICE, response.data)
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteInvoice = ({ commit, dispatch, state }, id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.delete(`/api/invoices/${id}`).then((response) => {
|
||||
if (response.data.error) {
|
||||
resolve(response)
|
||||
} else {
|
||||
commit(types.DELETE_INVOICE, id)
|
||||
commit('dashboard/' + dashboardTypes.DELETE_INVOICE, id, { root: true })
|
||||
resolve(response)
|
||||
}
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
window.axios
|
||||
.post(`/api/v1/invoices/delete`, id)
|
||||
.then((response) => {
|
||||
if (response.data.error) {
|
||||
resolve(response)
|
||||
} else {
|
||||
commit(types.DELETE_INVOICE, id)
|
||||
commit('dashboard/' + dashboardTypes.DELETE_INVOICE, id, {
|
||||
root: true,
|
||||
})
|
||||
resolve(response)
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteMultipleInvoices = ({ commit, dispatch, state }, id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.post(`/api/invoices/delete`, {'id': state.selectedInvoices}).then((response) => {
|
||||
if (response.data.error) {
|
||||
resolve(response)
|
||||
} else {
|
||||
commit(types.DELETE_MULTIPLE_INVOICES, state.selectedInvoices)
|
||||
resolve(response)
|
||||
}
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
window.axios
|
||||
.post(`/api/v1/invoices/delete`, { ids: state.selectedInvoices })
|
||||
.then((response) => {
|
||||
if (response.data.error) {
|
||||
resolve(response)
|
||||
} else {
|
||||
commit(types.DELETE_MULTIPLE_INVOICES, state.selectedInvoices)
|
||||
resolve(response)
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const updateInvoice = ({ commit, dispatch, state }, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.put(`/api/invoices/${data.id}`, data).then((response) => {
|
||||
if (response.data.invoice) {
|
||||
commit(types.UPDATE_INVOICE, response.data)
|
||||
}
|
||||
resolve(response)
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
window.axios
|
||||
.put(`/api/v1/invoices/${data.id}`, data)
|
||||
.then((response) => {
|
||||
if (response.data.invoice) {
|
||||
commit(types.UPDATE_INVOICE, response.data)
|
||||
}
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const markAsSent = ({ commit, dispatch, state }, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.post(`/api/invoices/mark-as-sent`, data).then((response) => {
|
||||
commit(types.UPDATE_INVOICE_STATUS, {id: data.id, status: 'SENT'})
|
||||
commit('dashboard/' + dashboardTypes.UPDATE_INVOICE_STATUS, {id: data.id, status: 'SENT'}, { root: true })
|
||||
resolve(response)
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
window.axios
|
||||
.post(`/api/v1/invoices/${data.id}/status`, data)
|
||||
.then((response) => {
|
||||
commit(types.UPDATE_INVOICE_STATUS, { id: data.id, status: 'SENT' })
|
||||
commit(
|
||||
'dashboard/' + dashboardTypes.UPDATE_INVOICE_STATUS,
|
||||
{ id: data.id, status: 'SENT' },
|
||||
{
|
||||
root: true,
|
||||
}
|
||||
)
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const cloneInvoice = ({ commit, dispatch, state }, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.post(`/api/invoices/clone`, data).then((response) => {
|
||||
resolve(response)
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
window.axios
|
||||
.post(`/api/v1/invoices/${data.id}/clone`, data)
|
||||
.then((response) => {
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const searchInvoice = ({ commit, dispatch, state }, data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.get(`/api/invoices?${data}`).then((response) => {
|
||||
// commit(types.UPDATE_INVOICE, response.data)
|
||||
resolve(response)
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
window.axios
|
||||
.get(`/api/v1/invoices?${data}`)
|
||||
.then((response) => {
|
||||
// commit(types.UPDATE_INVOICE, response.data)
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const getInvoiceNumber = ({ commit, dispatch, state }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios
|
||||
.get(`/api/v1/next-number?key=invoice`)
|
||||
.then((response) => {
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@ -174,7 +199,7 @@ export const selectAllInvoices = ({ commit, dispatch, state }) => {
|
||||
commit(types.SET_SELECTED_INVOICES, [])
|
||||
commit(types.SET_SELECT_ALL_STATE, false)
|
||||
} else {
|
||||
let allInvoiceIds = state.invoices.map(inv => inv.id)
|
||||
let allInvoiceIds = state.invoices.map((inv) => inv.id)
|
||||
commit(types.SET_SELECTED_INVOICES, allInvoiceIds)
|
||||
commit(types.SET_SELECT_ALL_STATE, true)
|
||||
}
|
||||
@ -201,16 +226,37 @@ export const setTemplate = ({ commit, dispatch, state }, data) => {
|
||||
|
||||
export const selectCustomer = ({ commit, dispatch, state }, id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.get(`/api/customers/${id}`).then((response) => {
|
||||
commit(types.RESET_SELECTED_CUSTOMER)
|
||||
commit(types.SELECT_CUSTOMER, response.data.customer)
|
||||
resolve(response)
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
window.axios
|
||||
.get(`/api/v1/customers/${id}`)
|
||||
.then((response) => {
|
||||
commit(types.RESET_SELECTED_CUSTOMER)
|
||||
commit(types.SELECT_CUSTOMER, response.data.customer)
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const resetSelectedCustomer = ({ commit, dispatch, state }, data) => {
|
||||
commit(types.RESET_SELECTED_CUSTOMER)
|
||||
}
|
||||
|
||||
export const setItem = ({ commit, dispatch, state }, data) => {
|
||||
commit(types.RESET_ITEM)
|
||||
commit(types.SET_ITEM, data)
|
||||
}
|
||||
|
||||
export const resetItem = ({ commit, dispatch, state }) => {
|
||||
commit(types.RESET_ITEM)
|
||||
}
|
||||
|
||||
export const selectNote = ({ commit, dispatch, state }, data) => {
|
||||
commit(types.RESET_SELECTED_NOTE)
|
||||
commit(types.SET_SELECTED_NOTE, data.notes)
|
||||
}
|
||||
|
||||
export const resetSelectedNote = ({ commit, dispatch, state }, data) => {
|
||||
commit(types.RESET_SELECTED_NOTE)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user