Files
vuefilemanager/resources/js/store/modules/oasisInvoices
Peter Papp 722eceb0c1 bug fixes
2021-05-14 10:29:46 +02:00

125 lines
3.1 KiB
Plaintext

import {events} from '@/bus'
import axios from "axios"
import Vue from "vue"
const defaultState = {
invoiceSorting: {
sort: localStorage.getItem('sorting') ? JSON.parse(localStorage.getItem('sorting')).sort : 'DESC',
field: localStorage.getItem('sorting') ? JSON.parse(localStorage.getItem('sorting')).field : 'created_at',
},
}
const actions = {
getRegularInvoices: ({commit, getters}) => {
commit('LOADING_STATE', {loading: true, data: []})
commit('STORE_CURRENT_FOLDER', {
name: 'Invoices',
id: undefined,
location: 'regular-invoice',
})
axios
.get('/api/v1/invoicing/invoices/regular' + getters.invoiceSorting.URI)
.then(response => {
commit('LOADING_STATE', {loading: false, data: response.data})
})
.catch(() => {
Vue.prototype.$isSomethingWrong()
})
.finally(() => {
events.$emit('scrollTop')
})
},
getAdvanceInvoices: ({commit, getters}) => {
commit('LOADING_STATE', {loading: true, data: []})
commit('STORE_CURRENT_FOLDER', {
name: 'Advance Invoices',
id: undefined,
location: 'advance-invoice',
})
axios
.get('/api/v1/invoicing/invoices/advance' + getters.invoiceSorting.URI)
.then(response => {
commit('LOADING_STATE', {loading: false, data: response.data})
})
.catch(() => {
Vue.prototype.$isSomethingWrong()
})
.finally(() => {
events.$emit('scrollTop')
})
},
getClients: ({commit, getters}) => {
commit('LOADING_STATE', {loading: true, data: []})
commit('STORE_CURRENT_FOLDER', {
name: 'Clients',
id: undefined,
location: 'clients',
})
axios
.get('/api/v1/invoicing/clients' + getters.invoiceSorting.URI)
.then(response => {
commit('LOADING_STATE', {loading: false, data: response.data})
})
.catch(() => {
Vue.prototype.$isSomethingWrong()
})
.finally(() => {
events.$emit('scrollTop')
})
},
getSearchResultForInvoices: ({commit, getters}, query) => {
commit('LOADING_STATE', {loading: true, data: []})
commit('CHANGE_SEARCHING_STATE', true)
axios
.get('/api/v1/invoicing/invoices/search', {
params: {
query: query,
type: getters.currentFolder.location,
}
})
.then(response => {
commit('LOADING_STATE', {loading: false, data: response.data})
})
.catch(() => Vue.prototype.$isSomethingWrong())
},
getSearchResultForClients: ({commit, getters}, query) => {
commit('LOADING_STATE', {loading: true, data: []})
commit('CHANGE_SEARCHING_STATE', true)
axios
.get('/api/v1/invoicing/clients/search', {
params: {query: query}
})
.then(response => {
commit('LOADING_STATE', {loading: false, data: response.data})
})
.catch(() => Vue.prototype.$isSomethingWrong())
},
}
const mutations = {
UPDATE_INVOICE_SORTING(state) {
state.invoiceSorting.field = JSON.parse(localStorage.getItem('sorting-invoices')).field
state.invoiceSorting.sort = JSON.parse(localStorage.getItem('sorting-invoices')).sort
},
}
const getters = {
invoiceSorting: (state) => {
return {sorting: state.invoiceSorting, URI: '?sort=' + state.invoiceSorting.field + '&direction=' + state.invoiceSorting.sort}
},
}
export default {
state: defaultState,
getters,
actions,
mutations
}