1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- const state = {
- journals: [],
- loadingJournals: false,
- selectedJournal: null
- }
- const getters = {
- journals(state) {
- return state.journals
- },
- bankJournals(state, getters) {
- return state.journals.filter(j => j.type === 'bank' && j.currencyId === getters.selectedCurrency.id)
- },
- loadingJournals(state) {
- return state.loadingJournals
- },
- selectedJournal(state) {
- return state.selectedJournal
- },
- hasJournalSelected(state) {
- return !!state.selectedJournal
- },
- hasCashJournalSelected(state) {
- return !!state.selectedJournal && state.selectedJournal.type === 'cash'
- },
- hasBankJournalSelected(state) {
- return !!state.selectedJournal && state.selectedJournal.type === 'bank'
- }
- }
- const mutations = {
- setJournals (state, payload) {
- state.journals = payload
- },
- setLoadingJournals (state, payload) {
- state.loadingJournals = !!payload
- },
- autoSelectJournal (state) {
- const { selectedCurrency } = this.getters
- state.selectedJournal = state.journals.find(j => j.type === 'cash' && j.currencyId === selectedCurrency.id)
- },
- setSelectedJournal (state, journalId) {
- if (!journalId) {
- state.selectedJournal = null
- return
- }
- state.selectedJournal = state.journals.find(item => item.id === journalId)
- }
- }
- const actions = {
- initJournals ({ commit }, payload) {
- commit('setJournals', payload)
- commit('autoSelectJournal')
- commit('setLoadingJournals')
- },
- autoSelectJournal({ commit }) {
- commit('autoSelectJournal')
- },
- selectJournal ({ commit }, journalId) {
- commit('setSelectedJournal', journalId)
- },
- resetJournal ({ getters, commit }) {
- if (getters.isWired) {
- commit('setLoadingJournals', true)
- commit('setJournals', [])
- }
- commit('setSelectedJournal', null)
- commit('autoSelectJournal')
- }
- }
- export default {
- state,
- getters,
- mutations,
- actions
- }
|