mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-31 05:31:10 -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) | ||||
| } | ||||
|  | ||||
| @ -4,7 +4,9 @@ export const getTemplateId = (state) => state.invoiceTemplateId | ||||
| export const selectedInvoices = (state) => state.selectedInvoices | ||||
| export const totalInvoices = (state) => state.totalInvoices | ||||
| export const selectedCustomer = (state) => state.selectedCustomer | ||||
| export const selectedNote = (state) => state.selectedNote | ||||
| export const selectedItem = (state) => state.selectedItem | ||||
| export const getInvoice = (state) => (id) => { | ||||
|   let invId = parseInt(id) | ||||
|   return state.invoices.find(invoice => invoice.id === invId) | ||||
|   return state.invoices.find((invoice) => invoice.id === invId) | ||||
| } | ||||
|  | ||||
| @ -8,7 +8,9 @@ const initialState = { | ||||
|   selectedInvoices: [], | ||||
|   selectAllField: false, | ||||
|   totalInvoices: 0, | ||||
|   selectedCustomer: null | ||||
|   selectedCustomer: null, | ||||
|   selectedNote: null, | ||||
|   selectedItem: null, | ||||
| } | ||||
|  | ||||
| export default { | ||||
| @ -20,5 +22,5 @@ export default { | ||||
|  | ||||
|   actions: actions, | ||||
|  | ||||
|   mutations: mutations | ||||
|   mutations: mutations, | ||||
| } | ||||
|  | ||||
| @ -5,13 +5,21 @@ export const DELETE_INVOICE = 'DELETE_INVOICE' | ||||
| export const DELETE_MULTIPLE_INVOICES = 'DELETE_MULTIPLE_INVOICES' | ||||
| export const SET_SELECTED_INVOICES = 'SET_SELECTED_INVOICES' | ||||
| export const SET_TOTAL_INVOICES = 'SET_TOTAL_INVOICES' | ||||
|  | ||||
| export const RESET_CUSTOMER = 'RESET_CUSTOMER' | ||||
| export const RESET_ITEM = 'RESET_ITEM' | ||||
| export const SET_CUSTOMER = 'SET_CUSTOMER' | ||||
|  | ||||
| export const RESET_ITEM = 'RESET_ITEM' | ||||
| export const SET_ITEM = 'SET_ITEM' | ||||
|  | ||||
| export const SET_TEMPLATE_ID = 'SET_TEMPLATE_ID' | ||||
|  | ||||
| export const SELECT_CUSTOMER = 'SELECT_CUSTOMER' | ||||
| export const RESET_SELECTED_CUSTOMER = 'RESET_SELECTED_CUSTOMER' | ||||
|  | ||||
| export const SET_SELECT_ALL_STATE = 'SET_SELECT_ALL_STATE' | ||||
| export const RESET_SELECTED_INVOICES = 'RESET_SELECTED_INVOICES' | ||||
| export const UPDATE_INVOICE_STATUS = 'UPDATE_INVOICE_STATUS' | ||||
|  | ||||
| export const RESET_SELECTED_NOTE = 'RESET_SELECTED_NOTE' | ||||
| export const SET_SELECTED_NOTE = 'SET_SELECTED_NOTE' | ||||
|  | ||||
| @ -1,67 +1,85 @@ | ||||
| import * as types from './mutation-types' | ||||
|  | ||||
| export default { | ||||
|   [types.SET_INVOICES] (state, invoices) { | ||||
|   [types.SET_INVOICES](state, invoices) { | ||||
|     state.invoices = invoices | ||||
|   }, | ||||
|  | ||||
|   [types.SET_TOTAL_INVOICES] (state, totalInvoices) { | ||||
|   [types.SET_TOTAL_INVOICES](state, totalInvoices) { | ||||
|     state.totalInvoices = totalInvoices | ||||
|   }, | ||||
|  | ||||
|   [types.ADD_INVOICE] (state, data) { | ||||
|   [types.ADD_INVOICE](state, data) { | ||||
|     state.invoices.push(data) | ||||
|   }, | ||||
|  | ||||
|   [types.DELETE_INVOICE] (state, id) { | ||||
|     let index = state.invoices.findIndex(invoice => invoice.id === id) | ||||
|   [types.DELETE_INVOICE](state, data) { | ||||
|     let index = state.invoices.findIndex((invoice) => invoice.id === data.id) | ||||
|     state.invoices.splice(index, 1) | ||||
|   }, | ||||
|  | ||||
|   [types.SET_SELECTED_INVOICES] (state, data) { | ||||
|   [types.SET_SELECTED_INVOICES](state, data) { | ||||
|     state.selectedInvoices = data | ||||
|   }, | ||||
|  | ||||
|   [types.UPDATE_INVOICE] (state, data) { | ||||
|     let pos = state.invoices.findIndex(invoice => invoice.id === data.invoice.id) | ||||
|   [types.UPDATE_INVOICE](state, data) { | ||||
|     let pos = state.invoices.findIndex( | ||||
|       (invoice) => invoice.id === data.invoice.id | ||||
|     ) | ||||
|  | ||||
|     state.invoices[pos] = data.invoice | ||||
|   }, | ||||
|  | ||||
|   [types.UPDATE_INVOICE_STATUS] (state, data) { | ||||
|     let pos = state.invoices.findIndex(invoice => invoice.id === data.id) | ||||
|   [types.UPDATE_INVOICE_STATUS](state, data) { | ||||
|     let pos = state.invoices.findIndex((invoice) => invoice.id === data.id) | ||||
|  | ||||
|     if (state.invoices[pos]) { | ||||
|       state.invoices[pos].status = data.status | ||||
|     } | ||||
|   }, | ||||
|  | ||||
|   [types.RESET_SELECTED_INVOICES] (state, data) { | ||||
|   [types.RESET_SELECTED_INVOICES](state, data) { | ||||
|     state.selectedInvoices = [] | ||||
|     state.selectAllField = false | ||||
|   }, | ||||
|  | ||||
|   [types.DELETE_MULTIPLE_INVOICES] (state, selectedInvoices) { | ||||
|   [types.DELETE_MULTIPLE_INVOICES](state, selectedInvoices) { | ||||
|     selectedInvoices.forEach((invoice) => { | ||||
|       let index = state.invoices.findIndex(_inv => _inv.id === invoice.id) | ||||
|       let index = state.invoices.findIndex((_inv) => _inv.id === invoice.id) | ||||
|       state.invoices.splice(index, 1) | ||||
|     }) | ||||
|     state.selectedInvoices = [] | ||||
|   }, | ||||
|  | ||||
|   [types.SET_TEMPLATE_ID] (state, templateId) { | ||||
|   [types.SET_TEMPLATE_ID](state, templateId) { | ||||
|     state.invoiceTemplateId = templateId | ||||
|   }, | ||||
|  | ||||
|   [types.SELECT_CUSTOMER] (state, data) { | ||||
|   [types.SELECT_CUSTOMER](state, data) { | ||||
|     state.selectedCustomer = data | ||||
|   }, | ||||
|  | ||||
|   [types.RESET_SELECTED_CUSTOMER] (state, data) { | ||||
|   [types.RESET_SELECTED_CUSTOMER](state, data) { | ||||
|     state.selectedCustomer = null | ||||
|   }, | ||||
|  | ||||
|   [types.SET_SELECT_ALL_STATE] (state, data) { | ||||
|   [types.SET_SELECT_ALL_STATE](state, data) { | ||||
|     state.selectAllField = data | ||||
|   } | ||||
|   }, | ||||
|  | ||||
|   [types.RESET_SELECTED_NOTE](state, data) { | ||||
|     state.selectedNote = null | ||||
|   }, | ||||
|  | ||||
|   [types.SET_SELECTED_NOTE](state, data) { | ||||
|     state.selectedNote = data | ||||
|   }, | ||||
|  | ||||
|   [types.RESET_ITEM](state, data) { | ||||
|     state.selectedItem = null | ||||
|   }, | ||||
|  | ||||
|   [types.SET_ITEM](state, data) { | ||||
|     state.selectedItem = data | ||||
|   }, | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user