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,170 +3,249 @@ import * as dashboardTypes from '../dashboard/mutation-types' | ||||
|  | ||||
| export const fetchEstimates = ({ commit, dispatch, state }, params) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.get(`/api/estimates`, {params}).then((response) => { | ||||
|       commit(types.SET_ESTIMATES, response.data.estimates.data) | ||||
|       commit(types.SET_TOTAL_ESTIMATES, response.data.estimateTotalCount) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .get(`/api/v1/estimates`, { params }) | ||||
|       .then((response) => { | ||||
|         commit(types.SET_ESTIMATES, response.data.estimates.data) | ||||
|         commit(types.SET_TOTAL_ESTIMATES, response.data.estimateTotalCount) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const getRecord = ({ commit, dispatch, state }, record) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.get(`/api/estimates/records?record=${record}`).then((response) => { | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .get(`/api/v1/estimates/records?record=${record}`) | ||||
|       .then((response) => { | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const fetchCreateEstimate = ({ commit, dispatch, state }) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.get(`/api/estimates/create`).then((response) => { | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .get(`/api/v1/estimates`) | ||||
|       .then((response) => { | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const getEstimateNumber = ({ commit, dispatch, state }) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios | ||||
|       .get(`/api/v1/next-number?key=estimate`) | ||||
|       .then((response) => { | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const fetchEstimate = ({ commit, dispatch, state }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.get(`/api/estimates/${id}/edit`).then((response) => { | ||||
|       commit(types.SET_TEMPLATE_ID, response.data.estimate.estimate_template_id) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .get(`/api/v1/estimates/${id}`) | ||||
|       .then((response) => { | ||||
|         commit( | ||||
|           types.SET_TEMPLATE_ID, | ||||
|           response.data.estimate.estimate_template_id | ||||
|         ) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const fetchViewEstimate = ({ commit, dispatch, state }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.get(`/api/estimates/${id}`).then((response) => { | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .get(`/api/v1/estimates/${id}`) | ||||
|       .then((response) => { | ||||
|         commit(types.VIEW_ESTIMATE, response.data.estimate) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const sendEmail = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post(`/api/estimates/send`, data).then((response) => { | ||||
|       if (response.data.success) { | ||||
|         commit(types.UPDATE_ESTIMATE_STATUS, {id: data.id, status: 'SENT'}) | ||||
|         commit('dashboard/' + dashboardTypes.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'SENT' }, { root: true }) | ||||
|       } | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .post(`/api/v1/estimates/${data.id}/send`, data) | ||||
|       .then((response) => { | ||||
|         if (response.data.success) { | ||||
|           commit(types.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'SENT' }) | ||||
|           commit(types.VIEW_ESTIMATE) | ||||
|           commit( | ||||
|             'dashboard/' + dashboardTypes.UPDATE_ESTIMATE_STATUS, | ||||
|             { id: data.id, status: 'SENT' }, | ||||
|             { root: true } | ||||
|           ) | ||||
|         } | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const addEstimate = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post('/api/estimates', data).then((response) => { | ||||
|       commit(types.ADD_ESTIMATE, response.data.estimate) | ||||
|     window.axios | ||||
|       .post('/api/v1/estimates', data) | ||||
|       .then((response) => { | ||||
|         commit(types.ADD_ESTIMATE, response.data.estimate) | ||||
|  | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const deleteEstimate = ({ commit, dispatch, state }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.delete(`/api/estimates/${id}`).then((response) => { | ||||
|       commit(types.DELETE_ESTIMATE, id) | ||||
|       commit('dashboard/' + dashboardTypes.DELETE_ESTIMATE, id, { root: true }) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .post(`/api/v1/estimates/delete`, id) | ||||
|       .then((response) => { | ||||
|         commit(types.DELETE_ESTIMATE, id) | ||||
|         commit('dashboard/' + dashboardTypes.DELETE_ESTIMATE, id, { | ||||
|           root: true, | ||||
|         }) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const deleteMultipleEstimates = ({ commit, dispatch, state }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post(`/api/estimates/delete`, {'id': state.selectedEstimates}).then((response) => { | ||||
|       commit(types.DELETE_MULTIPLE_ESTIMATES, state.selectedEstimates) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .post(`/api/v1/estimates/delete`, { ids: state.selectedEstimates }) | ||||
|       .then((response) => { | ||||
|         commit(types.DELETE_MULTIPLE_ESTIMATES, state.selectedEstimates) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const updateEstimate = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.put(`/api/estimates/${data.id}`, data).then((response) => { | ||||
|       commit(types.UPDATE_ESTIMATE, response.data) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .put(`/api/v1/estimates/${data.id}`, data) | ||||
|       .then((response) => { | ||||
|         commit(types.UPDATE_ESTIMATE, response.data) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const markAsAccepted = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post(`/api/estimates/accept`, data).then((response) => { | ||||
|       commit('dashboard/' + dashboardTypes.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'ACCEPTED' }, { root: true }) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .post(`/api/v1/estimates/${data.id}/status`, data) | ||||
|       .then((response) => { | ||||
|         commit( | ||||
|           'dashboard/' + dashboardTypes.UPDATE_ESTIMATE_STATUS, | ||||
|           { id: data.id, status: 'ACCEPTED' }, | ||||
|           { root: true } | ||||
|         ) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const markAsRejected = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post(`/api/estimates/reject`, data).then((response) => { | ||||
|       commit('dashboard/' + dashboardTypes.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'REJECTED' }, { root: true }) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .post(`/api/v1/estimates/${data.id}/status`, data) | ||||
|       .then((response) => { | ||||
|         commit( | ||||
|           'dashboard/' + dashboardTypes.UPDATE_ESTIMATE_STATUS, | ||||
|           { id: data.id, status: 'REJECTED' }, | ||||
|           { root: true } | ||||
|         ) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const markAsSent = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post(`/api/estimates/mark-as-sent`, data).then((response) => { | ||||
|       commit(types.UPDATE_ESTIMATE_STATUS, {id: data.id, status: 'SENT'}) | ||||
|       commit('dashboard/' + dashboardTypes.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'SENT' }, { root: true }) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .post(`/api/v1/estimates/${data.id}/status`, data) | ||||
|       .then((response) => { | ||||
|         commit(types.UPDATE_ESTIMATE_STATUS, { id: data.id, status: 'SENT' }) | ||||
|         commit( | ||||
|           'dashboard/' + dashboardTypes.UPDATE_ESTIMATE_STATUS, | ||||
|           { id: data.id, status: 'SENT' }, | ||||
|           { root: true } | ||||
|         ) | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const convertToInvoice = ({ commit, dispatch, state }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post(`/api/estimates/${id}/convert-to-invoice`).then((response) => { | ||||
|       // commit(types.UPDATE_INVOICE, response.data) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .post(`/api/v1/estimates/${id}/convert-to-invoice`) | ||||
|       .then((response) => { | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const searchEstimate = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.get(`/api/estimates?${data}`).then((response) => { | ||||
|       // commit(types.UPDATE_INVOICE, response.data) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|     window.axios | ||||
|       .get(`/api/v1/estimates?${data}`) | ||||
|       .then((response) => { | ||||
|         resolve(response) | ||||
|       }) | ||||
|       .catch((err) => { | ||||
|         reject(err) | ||||
|       }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| @ -188,7 +267,7 @@ export const selectAllEstimates = ({ commit, dispatch, state }) => { | ||||
|     commit(types.SET_SELECTED_ESTIMATES, []) | ||||
|     commit(types.SET_SELECT_ALL_STATE, false) | ||||
|   } else { | ||||
|     let allEstimateIds = state.estimates.map(estimt => estimt.id) | ||||
|     let allEstimateIds = state.estimates.map((estimt) => estimt.id) | ||||
|     commit(types.SET_SELECTED_ESTIMATES, allEstimateIds) | ||||
|     commit(types.SET_SELECT_ALL_STATE, true) | ||||
|   } | ||||
| @ -225,16 +304,28 @@ 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 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,8 @@ export const getTemplateId = (state) => state.estimateTemplateId | ||||
| export const selectedEstimates = (state) => state.selectedEstimates | ||||
| export const totalEstimates = (state) => state.totalEstimates | ||||
| export const selectedCustomer = (state) => state.selectedCustomer | ||||
| export const selectedNote = (state) => state.selectedNote | ||||
| export const getEstimate = (state) => (id) => { | ||||
|   let invId = parseInt(id) | ||||
|   return state.estimates.find(estimate => estimate.id === invId) | ||||
|   return state.estimates.find((estimate) => estimate.id === invId) | ||||
| } | ||||
|  | ||||
| @ -8,7 +8,9 @@ const initialState = { | ||||
|   selectAllField: false, | ||||
|   selectedEstimates: [], | ||||
|   totalEstimates: 0, | ||||
|   selectedCustomer: null | ||||
|   selectedCustomer: null, | ||||
|   selectedEstimate: null, | ||||
|   selectedNote: null, | ||||
| } | ||||
|  | ||||
| export default { | ||||
| @ -20,5 +22,5 @@ export default { | ||||
|  | ||||
|   actions: actions, | ||||
|  | ||||
|   mutations: mutations | ||||
|   mutations: mutations, | ||||
| } | ||||
|  | ||||
| @ -15,3 +15,7 @@ export const RESET_SELECTED_CUSTOMER = 'RESET_SELECTED_CUSTOMER' | ||||
| export const SET_SELECT_ALL_STATE = 'SET_SELECT_ALL_STATE' | ||||
| export const RESET_SELECTED_ESTIMATES = 'RESET_SELECTED_ESTIMATES' | ||||
| export const UPDATE_ESTIMATE_STATUS = 'UPDATE_ESTIMATE_STATUS' | ||||
| export const VIEW_ESTIMATE = 'VIEW_ESTIMATE' | ||||
|  | ||||
| export const SET_SELECTED_NOTE = 'SET_SELECTED_NOTE' | ||||
| export const RESET_SELECTED_NOTE = 'RESET_SELECTED_NOTE' | ||||
|  | ||||
| @ -1,68 +1,82 @@ | ||||
| import * as types from './mutation-types' | ||||
|  | ||||
| export default { | ||||
|   [types.SET_ESTIMATES] (state, data) { | ||||
|   [types.SET_ESTIMATES](state, data) { | ||||
|     state.estimates = data | ||||
|   }, | ||||
|  | ||||
|   [types.SET_TOTAL_ESTIMATES] (state, totalEstimates) { | ||||
|   [types.SET_TOTAL_ESTIMATES](state, totalEstimates) { | ||||
|     state.totalEstimates = totalEstimates | ||||
|   }, | ||||
|  | ||||
|   [types.ADD_ESTIMATE] (state, data) { | ||||
|   [types.ADD_ESTIMATE](state, data) { | ||||
|     state.estimates = [...state.estimates, data] | ||||
|   }, | ||||
|  | ||||
|   [types.DELETE_ESTIMATE] (state, id) { | ||||
|     let index = state.estimates.findIndex(estimate => estimate.id === id) | ||||
|   [types.DELETE_ESTIMATE](state, id) { | ||||
|     let index = state.estimates.findIndex((estimate) => estimate.id === id) | ||||
|     state.estimates.splice(index, 1) | ||||
|   }, | ||||
|  | ||||
|   [types.SET_SELECTED_ESTIMATES] (state, data) { | ||||
|   [types.SET_SELECTED_ESTIMATES](state, data) { | ||||
|     state.selectedEstimates = data | ||||
|   }, | ||||
|  | ||||
|   [types.DELETE_MULTIPLE_ESTIMATES] (state, selectedEstimates) { | ||||
|   [types.DELETE_MULTIPLE_ESTIMATES](state, selectedEstimates) { | ||||
|     selectedEstimates.forEach((estimate) => { | ||||
|       let index = state.estimates.findIndex(_est => _est.id === estimate.id) | ||||
|       let index = state.estimates.findIndex((_est) => _est.id === estimate.id) | ||||
|       state.estimates.splice(index, 1) | ||||
|     }) | ||||
|  | ||||
|     state.selectedEstimates = [] | ||||
|   }, | ||||
|  | ||||
|   [types.UPDATE_ESTIMATE] (state, data) { | ||||
|     let pos = state.estimates.findIndex(estimate => estimate.id === data.estimate.id) | ||||
|   [types.UPDATE_ESTIMATE](state, data) { | ||||
|     let pos = state.estimates.findIndex( | ||||
|       (estimate) => estimate.id === data.estimate.id | ||||
|     ) | ||||
|  | ||||
|     state.estimates[pos] = data.estimate | ||||
|   }, | ||||
|  | ||||
|   [types.UPDATE_ESTIMATE_STATUS] (state, data) { | ||||
|     let pos = state.estimates.findIndex(estimate => estimate.id === data.id) | ||||
|  | ||||
|   [types.UPDATE_ESTIMATE_STATUS](state, data) { | ||||
|     let pos = state.estimates.findIndex((estimate) => estimate.id === data.id) | ||||
|     if (state.estimates[pos]) { | ||||
|       // state.estimates[pos] = { ...state.estimates[pos], status: data.status } | ||||
|       state.estimates[pos].status = data.status | ||||
|     } | ||||
|   }, | ||||
|  | ||||
|   [types.RESET_SELECTED_ESTIMATES] (state, data) { | ||||
|   [types.RESET_SELECTED_ESTIMATES](state, data) { | ||||
|     state.selectedEstimates = [] | ||||
|     state.selectAllField = false | ||||
|   }, | ||||
|  | ||||
|   [types.SET_TEMPLATE_ID] (state, templateId) { | ||||
|   [types.SET_TEMPLATE_ID](state, templateId) { | ||||
|     state.estimateTemplateId = 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.VIEW_ESTIMATE](state, estimate) { | ||||
|     state.selectedEstimate = estimate | ||||
|   }, | ||||
|  | ||||
|   [types.SET_SELECTED_NOTE](state, data) { | ||||
|     state.selectedNote = data | ||||
|   }, | ||||
|  | ||||
|   [types.RESET_SELECTED_NOTE](state, data) { | ||||
|     state.selectedNote = null | ||||
|   }, | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user