diff --git a/frontend/package.json b/frontend/package.json index 467f5c0902..e624d9bc4f 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -15,6 +15,7 @@ "laravel-mix": "^5.0.9", "laravel-mix-bundle-analyzer": "^1.0.5", "lodash": "^4.17.20", + "lodash.clonedeep": "^4.5.0", "node-forge": ">=0.10.0", "resolve-url-loader": "^3.1.2", "sass": "^1.30.0", diff --git a/frontend/render.sh b/frontend/render.sh new file mode 100755 index 0000000000..704f5ae52b --- /dev/null +++ b/frontend/render.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +[ -d "~/Sites" ] && exit 1; + +# build translations. +php /sites/FF3/dev/tools/cli.php ff3:json-translations v2 diff --git a/frontend/src/components/accounts/Index.vue b/frontend/src/components/accounts/Index.vue index 61cd08676c..fc12f8c41f 100644 --- a/frontend/src/components/accounts/Index.vue +++ b/frontend/src/components/accounts/Index.vue @@ -103,7 +103,7 @@ export default { } }, created() { - console.log('mounted account list.'); + //console.log('mounted account list.'); axios.get('./api/v1/accounts?type=' + this.$props.accountTypes) .then(response => { this.loadAccounts(response.data.data); diff --git a/frontend/src/components/dashboard/TopBoxes.vue b/frontend/src/components/dashboard/TopBoxes.vue index f6ba5b2249..1f72c8243f 100644 --- a/frontend/src/components/dashboard/TopBoxes.vue +++ b/frontend/src/components/dashboard/TopBoxes.vue @@ -178,7 +178,7 @@ export default { let ret = []; for (const key in array) { if (array.hasOwnProperty(key)) { - console.log('Currency ID seems to be ' + this.currencyId); + // console.log('Currency ID seems to be ' + this.currencyId); if (array[key].currency_id === this.currencyId) { ret.push(array[key]); } diff --git a/frontend/src/components/store/index.js b/frontend/src/components/store/index.js index 603c269ed1..20c796968e 100644 --- a/frontend/src/components/store/index.js +++ b/frontend/src/components/store/index.js @@ -42,8 +42,9 @@ export default new Vuex.Store( locale: 'en-US' }, mutations: { - setCurrencyPreference(state, object) { - state.currencyPreference = object; + setCurrencyPreference(state, payload) { + console.log('setCurrencyPreference', payload); + state.currencyPreference = payload.payload; }, initialiseStore(state) { // if locale in local storage: @@ -63,6 +64,9 @@ export default new Vuex.Store( currencyCode: state => { return state.currencyPreference.code; }, + currencyPreference: state => { + return state.currencyPreference; + }, currencyId: state => { return state.currencyPreference.id; }, @@ -73,7 +77,10 @@ export default new Vuex.Store( actions: { updateCurrencyPreference(context) { if (localStorage.currencyPreference) { - context.commit('setCurrencyPreference', localStorage.currencyPreference); + console.log('set from local storage.'); + console.log(localStorage.currencyPreference); + console.log({payload: JSON.parse(localStorage.currencyPreference)}); + context.commit('setCurrencyPreference', {payload: JSON.parse(localStorage.currencyPreference)}); return; } axios.get('./api/v1/currencies/default') @@ -85,17 +92,21 @@ export default new Vuex.Store( code: response.data.data.attributes.code, decimal_places: parseInt(response.data.data.attributes.decimal_places), }; - localStorage.currencyPreference = currencyResponse; - context.commit('setCurrencyPreference', currencyResponse); + localStorage.currencyPreference = JSON.stringify(currencyResponse); + console.log('getCurrencyPreference from server') + console.log(JSON.stringify(currencyResponse)); + context.commit('setCurrencyPreference', {payload: currencyResponse}); }).catch(err => { - console.log('Got error response.'); + // console.log('Got error response.'); console.error(err); context.commit('setCurrencyPreference', { - id: 1, - name: 'Euro', - symbol: '€', - code: 'EUR', - decimal_places: 2 + payload: { + id: 1, + name: 'Euro', + symbol: '€', + code: 'EUR', + decimal_places: 2 + } }); }); diff --git a/frontend/src/components/store/modules/transactions/create.js b/frontend/src/components/store/modules/transactions/create.js index fb59ac23c8..895d59ddf1 100644 --- a/frontend/src/components/store/modules/transactions/create.js +++ b/frontend/src/components/store/modules/transactions/create.js @@ -20,11 +20,16 @@ let date = new Date; +const lodashClonedeep = require('lodash.clonedeep'); + // initial state const state = () => ({ transactionType: 'any', transactions: [], - sourceAllowedTypes: ['Asset account', 'Revenue account', 'Loan', 'Debt', 'Mortgage'], + allowedOpposingTypes: {}, + accountToTransaction: {}, + sourceAllowedTypes: ['Asset account','Loan','Debt','Mortgage','Revenue account'], + destinationAllowedTypes: ['Asset account','Loan','Debt','Mortgage','Expense account'], defaultTransaction: { // basic description: '', @@ -35,12 +40,23 @@ const state = () => ({ source_account: { id: 0, name: "", + name_with_balance: "", type: "", currency_id: 0, currency_name: '', currency_code: '', currency_decimal_places: 2 }, + destination_account: { + id: 0, + name: "", + type: "", + currency_id: 0, + currency_name: '', + currency_code: '', + currency_decimal_places: 2 + }, + source_allowed_types: ['Asset account', 'Revenue account', 'Loan', 'Debt', 'Mortgage'], // meta data @@ -64,6 +80,12 @@ const getters = { sourceAllowedTypes: state => { return state.sourceAllowedTypes; }, + destinationAllowedTypes: state => { + return state.destinationAllowedTypes; + }, + allowedOpposingTypes: state => { + return state.allowedOpposingTypes; + }, // // `getters` is localized to this module's getters // // you can use rootGetters via 4th argument of getters // someGetter (state, getters, rootState, rootGetters) { @@ -75,20 +97,74 @@ const getters = { } // actions -const actions = {} +const actions = { + calcTransactionType(context) { + let source = context.state.transactions[0].source_account; + let dest = context.state.transactions[0].destination_account; + if (null === source || null === dest) { + // console.log('transactionType any'); + context.commit('setTransactionType', 'any'); + return; + } + if ('' === source.type || '' === dest.type) { + // console.log('transactionType any'); + context.commit('setTransactionType', 'any'); + return; + } + + // ok so type is set on both: + let expectedDestinationTypes = context.state.accountToTransaction[source.type]; + if ('undefined' !== typeof expectedDestinationTypes) { + let transactionType = expectedDestinationTypes[dest.type]; + if ('undefined' !== typeof expectedDestinationTypes[dest.type]) { + // console.log('Found a type: ' + transactionType); + context.commit('setTransactionType', transactionType); + return; + } + } + // console.log('Found no type for ' + source.type + ' --> ' + dest.type); + if('Asset account' !== source.type) { + console.log('Drop ID from source. TODO'); + // source.id =null + // context.commit('updateField', {field: 'source_account',index: }) + // context.state.transactions[0].source_account.id = null; + } + if('Asset account' !== dest.type) { + console.log('Drop ID from destination. TODO'); + //context.state.transactions[0].destination_account.id = null; + } + + context.commit('setTransactionType', 'any'); + } +} // mutations const mutations = { addTransaction(state) { - state.transactions.push(state.defaultTransaction); + let newTransaction = lodashClonedeep(state.defaultTransaction); + state.transactions.push(newTransaction); }, deleteTransaction(state, index) { - this.state.transactions.splice(index, 1); + state.transactions.splice(index, 1); + }, + setTransactionType(state, transactionType) { + state.transactionType = transactionType; + }, + setAllowedOpposingTypes(state, allowedOpposingTypes) { + state.allowedOpposingTypes = allowedOpposingTypes; + }, + setAccountToTransaction(state, payload) { + state.accountToTransaction = payload; }, updateField(state, payload) { - console.log('I am update field'); - console.log(payload) state.transactions[payload.index][payload.field] = payload.value; + }, + setDestinationAllowedTypes(state, payload) { + // console.log('Destination allowed types was changed!'); + state.destinationAllowedTypes = payload; + }, + setSourceAllowedTypes(state, payload) { + state.sourceAllowedTypes = payload; } } diff --git a/frontend/src/components/transactions/Create.vue b/frontend/src/components/transactions/Create.vue index 96cafb2738..54f1cd3bda 100644 --- a/frontend/src/components/transactions/Create.vue +++ b/frontend/src/components/transactions/Create.vue @@ -36,7 +36,15 @@
XS
+SM
+MD
+LG
+XL
+XS
-SM
-MD
-LG
-XL
-