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:
		
							
								
								
									
										99
									
								
								resources/assets/js/store/modules/payment/actions.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								resources/assets/js/store/modules/payment/actions.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,99 @@ | ||||
| import * as types from './mutation-types' | ||||
|  | ||||
| export const fetchPayments = ({ commit, dispatch, state }, params) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.get(`/api/payments`, {params}).then((response) => { | ||||
|       commit(types.SET_PAYMENTS, response.data.payments.data) | ||||
|       commit(types.SET_TOTAL_PAYMENTS, response.data.payments.total) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const fetchCreatePayment = ({ commit, dispatch }, page) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.get(`/api/payments/create`).then((response) => { | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const fetchPayment = ({ commit, dispatch }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.get(`/api/payments/${id}/edit`).then((response) => { | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const addPayment = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post('/api/payments', data).then((response) => { | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const setSelectAllState = ({ commit, dispatch, state }, data) => { | ||||
|   commit(types.SET_SELECT_ALL_STATE, data) | ||||
| } | ||||
|  | ||||
| export const selectPayment = ({ commit, dispatch, state }, data) => { | ||||
|   commit(types.SET_SELECTED_PAYMENTS, data) | ||||
|   if (state.selectedPayments.length === state.payments.length) { | ||||
|     commit(types.SET_SELECT_ALL_STATE, true) | ||||
|   } else { | ||||
|     commit(types.SET_SELECT_ALL_STATE, false) | ||||
|   } | ||||
| } | ||||
|  | ||||
| export const updatePayment = ({ commit, dispatch, state }, data) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.put(`/api/payments/${data.id}`, data.editData).then((response) => { | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const deletePayment = ({ commit, dispatch, state }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.delete(`/api/payments/${id}`).then((response) => { | ||||
|       commit(types.DELETE_PAYMENT, id) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const deleteMultiplePayments = ({ commit, dispatch, state }, id) => { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     window.axios.post(`/api/payments/delete`, {'id': state.selectedPayments}).then((response) => { | ||||
|       commit(types.DELETE_MULTIPLE_PAYMENTS, state.selectedPayments) | ||||
|       resolve(response) | ||||
|     }).catch((err) => { | ||||
|       reject(err) | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const selectAllPayments = ({ commit, dispatch, state }) => { | ||||
|   if (state.selectedPayments.length === state.payments.length) { | ||||
|     commit(types.SET_SELECTED_PAYMENTS, []) | ||||
|     commit(types.SET_SELECT_ALL_STATE, false) | ||||
|   } else { | ||||
|     let allPaymentIds = state.payments.map(pay => pay.id) | ||||
|     commit(types.SET_SELECTED_PAYMENTS, allPaymentIds) | ||||
|     commit(types.SET_SELECT_ALL_STATE, true) | ||||
|   } | ||||
| } | ||||
							
								
								
									
										4
									
								
								resources/assets/js/store/modules/payment/getters.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								resources/assets/js/store/modules/payment/getters.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| export const payments = (state) => state.payments | ||||
| export const selectedPayments = (state) => state.selectedPayments | ||||
| export const selectAllField = (state) => state.selectAllField | ||||
| export const totalPayments = (state) => state.totalPayments | ||||
							
								
								
									
										22
									
								
								resources/assets/js/store/modules/payment/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								resources/assets/js/store/modules/payment/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | ||||
| import mutations from './mutations' | ||||
| import * as actions from './actions' | ||||
| import * as getters from './getters' | ||||
|  | ||||
| const initialState = { | ||||
|   payments: [], | ||||
|   totalPayments: 0, | ||||
|   selectAllField: false, | ||||
|   selectedPayments: [] | ||||
| } | ||||
|  | ||||
| export default { | ||||
|   namespaced: true, | ||||
|  | ||||
|   state: initialState, | ||||
|  | ||||
|   getters: getters, | ||||
|  | ||||
|   actions: actions, | ||||
|  | ||||
|   mutations: mutations | ||||
| } | ||||
| @ -0,0 +1,8 @@ | ||||
| export const SET_PAYMENTS = 'SET_PAYMENTS' | ||||
| export const ADD_PAYMENT = 'ADD_PAYMENT' | ||||
| export const UPDATE_PAYMENT = 'UPDATE_PAYMENT' | ||||
| export const DELETE_PAYMENT = 'DELETE_PAYMENT' | ||||
| export const DELETE_MULTIPLE_PAYMENTS = 'DELETE_MULTIPLE_PAYMENTS' | ||||
| export const SET_SELECTED_PAYMENTS = 'SET_SELECTED_PAYMENTS' | ||||
| export const SET_TOTAL_PAYMENTS = 'SET_TOTAL_PAYMENTS' | ||||
| export const SET_SELECT_ALL_STATE = 'SET_SELECT_ALL_STATE' | ||||
							
								
								
									
										37
									
								
								resources/assets/js/store/modules/payment/mutations.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								resources/assets/js/store/modules/payment/mutations.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,37 @@ | ||||
| import * as types from './mutation-types' | ||||
|  | ||||
| export default { | ||||
|   [types.SET_PAYMENTS] (state, payments) { | ||||
|     state.payments = payments | ||||
|   }, | ||||
|  | ||||
|   [types.SET_TOTAL_PAYMENTS] (state, totalPayments) { | ||||
|     state.totalPayments = totalPayments | ||||
|   }, | ||||
|  | ||||
|   [types.ADD_PAYMENT] (state, data) { | ||||
|     state.payments.push(data) | ||||
|   }, | ||||
|  | ||||
|   [types.DELETE_PAYMENT] (state, id) { | ||||
|     let index = state.payments.findIndex(payment => payment.id === id) | ||||
|     state.payments.splice(index, 1) | ||||
|   }, | ||||
|  | ||||
|   [types.DELETE_MULTIPLE_PAYMENTS] (state, selectedPayments) { | ||||
|     selectedPayments.forEach((payment) => { | ||||
|       let index = state.payments.findIndex(_inv => _inv.id === payment.id) | ||||
|       state.payments.splice(index, 1) | ||||
|     }) | ||||
|  | ||||
|     state.selectedPayments = [] | ||||
|   }, | ||||
|  | ||||
|   [types.SET_SELECTED_PAYMENTS] (state, data) { | ||||
|     state.selectedPayments = data | ||||
|   }, | ||||
|  | ||||
|   [types.SET_SELECT_ALL_STATE] (state, data) { | ||||
|     state.selectAllField = data | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user