mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-31 05:31:10 -04:00 
			
		
		
		
	init crater
This commit is contained in:
		
							
								
								
									
										196
									
								
								resources/assets/js/store/modules/invoice/actions.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										196
									
								
								resources/assets/js/store/modules/invoice/actions.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,196 @@ | ||||
| import * as types from './mutation-types' | ||||
| // import moment from 'moment' | ||||
|  | ||||
| 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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| 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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const sendEmail = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post(`/api/invoices/send`, data).then((response) => { | ||||
|       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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const deleteInvoice = ({ commit, dispatch, state }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.delete(`/api/invoices/${id}`).then((response) => { | ||||
|       commit(types.DELETE_INVOICE, id) | ||||
|       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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| 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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| 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, response.data) | ||||
|       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) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const selectInvoice = ({ commit, dispatch, state }, data) => { | ||||
|   commit(types.SET_SELECTED_INVOICES, data) | ||||
|   if (state.selectedInvoices.length === state.invoices.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 selectAllInvoices = ({ commit, dispatch, state }) => { | ||||
|   if (state.selectedInvoices.length === state.invoices.length) { | ||||
|     commit(types.SET_SELECTED_INVOICES, []) | ||||
|     commit(types.SET_SELECT_ALL_STATE, false) | ||||
|   } else { | ||||
|     let allInvoiceIds = state.invoices.map(inv => inv.id) | ||||
|     commit(types.SET_SELECTED_INVOICES, allInvoiceIds) | ||||
|     commit(types.SET_SELECT_ALL_STATE, true) | ||||
|   } | ||||
| } | ||||
|  | ||||
| export const resetSelectedInvoices = ({ commit, dispatch, state }) => { | ||||
|   commit(types.RESET_SELECTED_INVOICES) | ||||
| } | ||||
| export const setCustomer = ({ commit, dispatch, state }, data) => { | ||||
|   commit(types.RESET_CUSTOMER) | ||||
|   commit(types.SET_CUSTOMER, data) | ||||
| } | ||||
|  | ||||
| export const resetCustomer = ({ commit, dispatch, state }) => { | ||||
|   commit(types.RESET_CUSTOMER) | ||||
| } | ||||
|  | ||||
| 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/invoice/getters.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								resources/assets/js/store/modules/invoice/getters.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | ||||
| export const invoices = (state) => state.invoices | ||||
| export const selectAllField = (state) => state.selectAllField | ||||
| export const getTemplateId = (state) => state.invoiceTemplateId | ||||
| export const selectedInvoices = (state) => state.selectedInvoices | ||||
| export const totalInvoices = (state) => state.totalInvoices | ||||
| export const selectedCustomer = (state) => state.selectedCustomer | ||||
							
								
								
									
										24
									
								
								resources/assets/js/store/modules/invoice/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								resources/assets/js/store/modules/invoice/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| import mutations from './mutations' | ||||
| import * as actions from './actions' | ||||
| import * as getters from './getters' | ||||
|  | ||||
| const initialState = { | ||||
|   invoices: [], | ||||
|   invoiceTemplateId: 1, | ||||
|   selectedInvoices: [], | ||||
|   selectAllField: false, | ||||
|   totalInvoices: 0, | ||||
|   selectedCustomer: null | ||||
| } | ||||
|  | ||||
| export default { | ||||
|   namespaced: true, | ||||
|  | ||||
|   state: initialState, | ||||
|  | ||||
|   getters: getters, | ||||
|  | ||||
|   actions: actions, | ||||
|  | ||||
|   mutations: mutations | ||||
| } | ||||
							
								
								
									
										16
									
								
								resources/assets/js/store/modules/invoice/mutation-types.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								resources/assets/js/store/modules/invoice/mutation-types.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| export const SET_INVOICES = 'SET_INVOICES' | ||||
| export const ADD_INVOICE = 'ADD_INVOICE' | ||||
| export const UPDATE_INVOICE = 'UPDATE_INVOICE' | ||||
| 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 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' | ||||
							
								
								
									
										59
									
								
								resources/assets/js/store/modules/invoice/mutations.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								resources/assets/js/store/modules/invoice/mutations.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,59 @@ | ||||
| import * as types from './mutation-types' | ||||
|  | ||||
| export default { | ||||
|   [types.SET_INVOICES] (state, invoices) { | ||||
|     state.invoices = invoices | ||||
|   }, | ||||
|  | ||||
|   [types.SET_TOTAL_INVOICES] (state, totalInvoices) { | ||||
|     state.totalInvoices = totalInvoices | ||||
|   }, | ||||
|  | ||||
|   [types.ADD_INVOICE] (state, data) { | ||||
|     state.invoices.push(data) | ||||
|   }, | ||||
|  | ||||
|   [types.DELETE_INVOICE] (state, id) { | ||||
|     let index = state.invoices.findIndex(invoice => invoice.id === id) | ||||
|     state.invoices.splice(index, 1) | ||||
|   }, | ||||
|  | ||||
|   [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) | ||||
|  | ||||
|     state.invoices[pos] = data.invoice | ||||
|   }, | ||||
|  | ||||
|   [types.RESET_SELECTED_INVOICES] (state, data) { | ||||
|     state.selectedInvoices = [] | ||||
|     state.selectAllField = false | ||||
|   }, | ||||
|  | ||||
|   [types.DELETE_MULTIPLE_INVOICES] (state, selectedInvoices) { | ||||
|     selectedInvoices.forEach((invoice) => { | ||||
|       let index = state.invoices.findIndex(_inv => _inv.id === invoice.id) | ||||
|       state.invoices.splice(index, 1) | ||||
|     }) | ||||
|     state.selectedInvoices = [] | ||||
|   }, | ||||
|  | ||||
|   [types.SET_TEMPLATE_ID] (state, templateId) { | ||||
|     state.invoiceTemplateId = 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