1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- const state = {
- currencies: [],
- selectedCurrency: null,
- loadingCurrencies: false,
- }
- const getters = {
- currencies(state) {
- return state.currencies
- },
- currencySymbols(state, { settings }) {
- if (!state.currencies || !state.selectedCurrency) {
- return []
- }
- if (settings && !settings.allowCurrencyExchange) {
- return []
- }
- return state.currencies.filter(c => state.selectedCurrency.id !== c.id).map(c => c.symbol)
- },
- baseCurrency(state) {
- return state.currencies.find(c => c.base === true)
- },
- selectedCurrency(state) {
- return state.selectedCurrency
- },
- currencySymbol(state) {
- return state.selectedCurrency && state.selectedCurrency.symbol
- },
- loadingCurrencies(state) {
- return state.loadingCurrencies
- }
- }
- const mutations = {
- setSelectedCurrency(state, currencySymbol) {
- if (currencySymbol) {
- state.selectedCurrency = state.currencies.find(c => c.symbol === currencySymbol)
- return
- }
-
- state.selectedCurrency = state.currencies.find(c => c.base === true)
- },
- setCurrencies(state, payload) {
- state.currencies = payload
- },
- setLoadingCurrencies(state, payload) {
- state.loadingCurrencies = !!payload
- }
- }
- const actions = {
- initCurrencies({ commit }, payload) {
- commit('setCurrencies', payload)
- commit('setSelectedCurrency')
- commit('setLoadingCurrencies')
- },
- resetCurrency({ commit }) {
- commit('setLoadingCurrencies', true)
- commit('setCurrencies', [])
- },
- changeCurrency({ commit, dispatch, getters }, currencySymbol) {
- commit('computePaymentInCurrency', {
- fromSymbol: getters.currencySymbol,
- toSymbol: currencySymbol
- });
- commit('setSelectedCurrency', currencySymbol)
- // commit('setInitialPayment', 0)
- // commit('setAmountResidual')
- if (getters.paymentType === 'credit') {
- dispatch('computePaymentLines')
- }
- dispatch('autoSelectJournal')
- }
- }
- export default {
- state,
- getters,
- mutations,
- actions
- }
|