mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-30 21:21:09 -04:00 
			
		
		
		
	init crater
This commit is contained in:
		
							
								
								
									
										231
									
								
								resources/assets/js/store/modules/estimate/actions.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										231
									
								
								resources/assets/js/store/modules/estimate/actions.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,231 @@ | ||||
| import * as types from './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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| 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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| 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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| 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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| 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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const sendEmail = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post(`/api/estimates/send`, data).then((response) => { | ||||
|       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) | ||||
|  | ||||
|       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) | ||||
|       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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| 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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const markAsAccepted = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post(`/api/estimates/accept`, data).then((response) => { | ||||
|       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) => { | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const markAsSent = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post(`/api/estimates/sent`, data).then((response) => { | ||||
|       // commit(types.UPDATE_INVOICE, response.data) | ||||
|       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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| 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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const selectEstimate = ({ commit, dispatch, state }, data) => { | ||||
|   commit(types.SET_SELECTED_ESTIMATES, data) | ||||
|   if (state.selectedEstimates.length === state.estimates.length) { | ||||
|     commit(types.SET_SELECT_ALL_STATE, true) | ||||
|   } else { | ||||
|     commit(types.SET_SELECT_ALL_STATE, false) | ||||
|   } | ||||
| } | ||||
|  | ||||
| export const setSelectAllState = ({ commit, dispatch, state }, data) => { | ||||
|   commit(types.SET_SELECT_ALL_STATE, data) | ||||
| } | ||||
|  | ||||
| export const selectAllEstimates = ({ commit, dispatch, state }) => { | ||||
|   if (state.selectedEstimates.length === state.estimates.length) { | ||||
|     commit(types.SET_SELECTED_ESTIMATES, []) | ||||
|     commit(types.SET_SELECT_ALL_STATE, false) | ||||
|   } else { | ||||
|     let allEstimateIds = state.estimates.map(estimt => estimt.id) | ||||
|     commit(types.SET_SELECTED_ESTIMATES, allEstimateIds) | ||||
|     commit(types.SET_SELECT_ALL_STATE, true) | ||||
|   } | ||||
| } | ||||
|  | ||||
| export const resetSelectedEstimates = ({ commit, dispatch, state }) => { | ||||
|   commit(types.RESET_SELECTED_ESTIMATES) | ||||
| } | ||||
|  | ||||
| export const setCustomer = ({ commit, dispatch, state }, data) => { | ||||
|   commit(types.RESET_CUSTOMER) | ||||
|   commit(types.SET_CUSTOMER, data) | ||||
| } | ||||
|  | ||||
| export const setItem = ({ commit, dispatch, state }, data) => { | ||||
|   commit(types.RESET_ITEM) | ||||
|   commit(types.SET_ITEM, data) | ||||
| } | ||||
|  | ||||
| export const resetCustomer = ({ commit, dispatch, state }) => { | ||||
|   commit(types.RESET_CUSTOMER) | ||||
| } | ||||
|  | ||||
| export const resetItem = ({ commit, dispatch, state }) => { | ||||
|   commit(types.RESET_ITEM) | ||||
| } | ||||
|  | ||||
| export const setTemplate = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     commit(types.SET_TEMPLATE_ID, data) | ||||
|     resolve({}) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| 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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const resetSelectedCustomer = ({ commit, dispatch, state }, data) => { | ||||
|   commit(types.RESET_SELECTED_CUSTOMER) | ||||
| } | ||||
							
								
								
									
										6
									
								
								resources/assets/js/store/modules/estimate/getters.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								resources/assets/js/store/modules/estimate/getters.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | ||||
| export const estimates = (state) => state.estimates | ||||
| export const selectAllField = (state) => state.selectAllField | ||||
| export const getTemplateId = (state) => state.estimateTemplateId | ||||
| export const selectedEstimates = (state) => state.selectedEstimates | ||||
| export const totalEstimates = (state) => state.totalEstimates | ||||
| export const selectedCustomer = (state) => state.selectedCustomer | ||||
							
								
								
									
										24
									
								
								resources/assets/js/store/modules/estimate/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								resources/assets/js/store/modules/estimate/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| import mutations from './mutations' | ||||
| import * as actions from './actions' | ||||
| import * as getters from './getters' | ||||
|  | ||||
| const initialState = { | ||||
|   estimates: [], | ||||
|   estimateTemplateId: 1, | ||||
|   selectAllField: false, | ||||
|   selectedEstimates: [], | ||||
|   totalEstimates: 0, | ||||
|   selectedCustomer: null | ||||
| } | ||||
|  | ||||
| export default { | ||||
|   namespaced: true, | ||||
|  | ||||
|   state: initialState, | ||||
|  | ||||
|   getters: getters, | ||||
|  | ||||
|   actions: actions, | ||||
|  | ||||
|   mutations: mutations | ||||
| } | ||||
							
								
								
									
										16
									
								
								resources/assets/js/store/modules/estimate/mutation-types.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								resources/assets/js/store/modules/estimate/mutation-types.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| export const SET_ESTIMATES = 'SET_ESTIMATES' | ||||
| export const ADD_ESTIMATE = 'ADD_ESTIMATE' | ||||
| export const UPDATE_ESTIMATE = 'UPDATE_ESTIMATE' | ||||
| export const DELETE_ESTIMATE = 'DELETE_ESTIMATE' | ||||
| export const DELETE_MULTIPLE_ESTIMATES = 'DELETE_MULTIPLE_ESTIMATES' | ||||
| export const SET_SELECTED_ESTIMATES = 'SET_SELECTED_ESTIMATES' | ||||
| export const SET_TOTAL_ESTIMATES = 'SET_TOTAL_ESTIMATES' | ||||
| export const RESET_CUSTOMER = 'RESET_CUSTOMER' | ||||
| export const RESET_ITEM = 'RESET_ITEM' | ||||
| export const SET_CUSTOMER = 'SET_CUSTOMER' | ||||
| 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_ESTIMATES = 'RESET_SELECTED_ESTIMATES' | ||||
							
								
								
									
										60
									
								
								resources/assets/js/store/modules/estimate/mutations.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								resources/assets/js/store/modules/estimate/mutations.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,60 @@ | ||||
| import * as types from './mutation-types' | ||||
|  | ||||
| export default { | ||||
|   [types.SET_ESTIMATES] (state, data) { | ||||
|     state.estimates = data | ||||
|   }, | ||||
|  | ||||
|   [types.SET_TOTAL_ESTIMATES] (state, totalEstimates) { | ||||
|     state.totalEstimates = totalEstimates | ||||
|   }, | ||||
|  | ||||
|   [types.ADD_ESTIMATE] (state, data) { | ||||
|     state.estimates = [...state.estimates, data] | ||||
|   }, | ||||
|  | ||||
|   [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) { | ||||
|     state.selectedEstimates = data | ||||
|   }, | ||||
|  | ||||
|   [types.DELETE_MULTIPLE_ESTIMATES] (state, selectedEstimates) { | ||||
|     selectedEstimates.forEach((estimate) => { | ||||
|       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) | ||||
|  | ||||
|     state.estimates[pos] = data.estimate | ||||
|   }, | ||||
|  | ||||
|   [types.RESET_SELECTED_ESTIMATES] (state, data) { | ||||
|     state.selectedEstimates = [] | ||||
|     state.selectAllField = false | ||||
|   }, | ||||
|  | ||||
|   [types.SET_TEMPLATE_ID] (state, templateId) { | ||||
|     state.estimateTemplateId = templateId | ||||
|   }, | ||||
|  | ||||
|   [types.SELECT_CUSTOMER] (state, data) { | ||||
|     state.selectedCustomer = data | ||||
|   }, | ||||
|  | ||||
|   [types.RESET_SELECTED_CUSTOMER] (state, data) { | ||||
|     state.selectedCustomer = null | ||||
|   }, | ||||
|  | ||||
|   [types.SET_SELECT_ALL_STATE] (state, data) { | ||||
|     state.selectAllField = data | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user