|
@@ -1,24 +1,58 @@
|
|
|
/* Actions */
|
|
|
import {
|
|
|
+ INIT_PAYMENTS_JOURNALS,
|
|
|
+ SELECT_PAYMENTS_JOURNALS,
|
|
|
ADD_PAYMENTS_MOVE_LINES,
|
|
|
- REMOVE_PAYMENTS_MOVE_LINES
|
|
|
+ REMOVE_PAYMENTS_MOVE_LINES,
|
|
|
+ CHANGE_INITIAL_PAID
|
|
|
} from '@/constants/actionTypes'
|
|
|
/* Mutations */
|
|
|
import {
|
|
|
+ SET_PAYMENTS_JOURNALS,
|
|
|
+ SELECTED_PAYMENTS_JOURNALS,
|
|
|
+ CALCULATE_PAYMENTS_TOTAL,
|
|
|
+ CALCULATE_CURRENCY_AMOUNT,
|
|
|
SET_ADD_PAYMENTS_MOVE_LINES,
|
|
|
- SET_REMOVE_PAYMENTS_MOVE_LINES
|
|
|
+ SET_REMOVE_PAYMENTS_MOVE_LINES,
|
|
|
+ SET_PAID_TOTAL
|
|
|
} from '@/constants/mutationTypes'
|
|
|
|
|
|
const initialState = {
|
|
|
+ paymentsJournals: [],
|
|
|
+ paymentsSelectedJournal: null,
|
|
|
paymentsMoveLines: [],
|
|
|
- paymentsTotal: 0
|
|
|
+ paymentsCurrencyAmount: [],
|
|
|
+ paymentsTotal: 0,
|
|
|
+ paidTotal: 0,
|
|
|
+ paymentsReturned: 0
|
|
|
}
|
|
|
const state = {
|
|
|
+ paymentsJournals: initialState.paymentsJournals,
|
|
|
+ paymentsSelectedJournal: initialState.paymentsSelectedJournal,
|
|
|
paymentsMoveLines: initialState.paymentsMoveLines,
|
|
|
- paymentsTotal: initialState.paymentsTotal
|
|
|
+ paymentsCurrencyAmount : initialState.paymentsCurrencyAmount,
|
|
|
+ paymentsTotal: initialState.paymentsTotal,
|
|
|
+ paidTotal: initialState.paidTotal,
|
|
|
+ paymentsReturned: initialState.paymentsReturned
|
|
|
}
|
|
|
|
|
|
const getters = {
|
|
|
+ /**
|
|
|
+ * [paymentsJournals description]
|
|
|
+ * @param {[type]} state [description]
|
|
|
+ * @return {[type]} [description]
|
|
|
+ */
|
|
|
+ paymentsJournals ( state ) {
|
|
|
+ return state.paymentsJournals
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [paymentsSelectedJournal description]
|
|
|
+ * @param {[type]} state [description]
|
|
|
+ * @return {[type]} [description]
|
|
|
+ */
|
|
|
+ paymentsSelectedJournal ( state ) {
|
|
|
+ return state.paymentsSelectedJournal
|
|
|
+ },
|
|
|
/**
|
|
|
* [paymentsMoveLines description]
|
|
|
* @param {[type]} state [description]
|
|
@@ -27,6 +61,14 @@ const getters = {
|
|
|
paymentsMoveLines ( state ) {
|
|
|
return state.paymentsMoveLines
|
|
|
},
|
|
|
+ /**
|
|
|
+ * [paymentsCurrencyAmount description]
|
|
|
+ * @param {[type]} state [description]
|
|
|
+ * @return {[type]} [description]
|
|
|
+ */
|
|
|
+ paymentsCurrencyAmount ( state ) {
|
|
|
+ return state.paymentsCurrencyAmount
|
|
|
+ },
|
|
|
/**
|
|
|
* [paymentsTotal description]
|
|
|
* @param {[type]} state [description]
|
|
@@ -34,10 +76,35 @@ const getters = {
|
|
|
*/
|
|
|
paymentsTotal ( state ) {
|
|
|
return state.paymentsTotal
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [paymentsReturned description]
|
|
|
+ * @param {[type]} state [description]
|
|
|
+ * @return {[type]} [description]
|
|
|
+ */
|
|
|
+ paymentsReturned ( state ) {
|
|
|
+ return state.paymentsReturned
|
|
|
+ },
|
|
|
+ paidTotal ( state ) {
|
|
|
+ return state.paidTotal
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const mutations = {
|
|
|
+ /**
|
|
|
+ * [paymentsJournals description]
|
|
|
+ * @type {[type]}
|
|
|
+ */
|
|
|
+ [SET_PAYMENTS_JOURNALS] ( state, payload ){
|
|
|
+ state.paymentsJournals = payload
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [paymentsSelectedJournal description]
|
|
|
+ * @type {[type]}
|
|
|
+ */
|
|
|
+ [SELECTED_PAYMENTS_JOURNALS] ( state, payload ) {
|
|
|
+ state.paymentsSelectedJournal = payload
|
|
|
+ },
|
|
|
/**
|
|
|
* [paymentsMoveLines description]
|
|
|
* @type {Array}
|
|
@@ -50,23 +117,117 @@ const mutations = {
|
|
|
* @type {Object}
|
|
|
*/
|
|
|
[SET_REMOVE_PAYMENTS_MOVE_LINES] (state, payload) {
|
|
|
- console.log('Opa ainda nao ');
|
|
|
- }
|
|
|
+ if (payload.mode === 'full') {
|
|
|
+ payload.moveLines.forEach(moves => {
|
|
|
+ // Remove Payments
|
|
|
+ let movesPaymentsIndex = state.paymentsMoveLines.findIndex(item => item.id === moves.id)
|
|
|
+ state.paymentsMoveLines.splice(movesPaymentsIndex)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // Remove Payments
|
|
|
+ let movesPaymentsIndex = state.paymentsMoveLines.findIndex(item => item.id === payload.moveLines.id)
|
|
|
+ state.paymentsMoveLines.splice(movesPaymentsIndex, 1)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [actions description]
|
|
|
+ * @type {Object}
|
|
|
+ */
|
|
|
+ [CALCULATE_CURRENCY_AMOUNT] ( state, payload ) {
|
|
|
+ let currency = payload.currency
|
|
|
+ let paymentsMoveLines = payload.paymentsMoveLines
|
|
|
+ let paymentsCurrencyAmount = []
|
|
|
+
|
|
|
+ currency.forEach(item => {
|
|
|
+ let amount = 0
|
|
|
+ paymentsMoveLines.forEach( currency => {
|
|
|
+ let currencyMoveLine = currency.currencyAmount.find(move => move.id === item.id)
|
|
|
+ amount = amount + currencyMoveLine.amountCurencyResidual
|
|
|
+ })
|
|
|
+ paymentsCurrencyAmount.push({
|
|
|
+ id: item.id,
|
|
|
+ symbolCurrency: item.symbol,
|
|
|
+ amount: amount,
|
|
|
+ symbol: ' ',
|
|
|
+ position: 'before',
|
|
|
+ thousandsSeparator: item.thousandsSeparator,
|
|
|
+ decimalSeparator: item.decimalSeparator,
|
|
|
+ decimalPlaces: item.decimalPlaces,
|
|
|
+ rateSilent: item.rateSilent
|
|
|
+ })
|
|
|
+ })
|
|
|
+ state.paymentsCurrencyAmount = paymentsCurrencyAmount
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [actions description]
|
|
|
+ * @type {Object}
|
|
|
+ */
|
|
|
+ [CALCULATE_PAYMENTS_TOTAL] ( state, payload){
|
|
|
+ let currencyJournal = payload.paymentsCurrencyAmount.find(item => item.id ===payload.currency.id)
|
|
|
+ let total = currencyJournal.amount
|
|
|
+ if (!currencyJournal)
|
|
|
+ total = 0
|
|
|
+ state.paymentsTotal = total
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [paidTotal description]
|
|
|
+ * @type {[type]}
|
|
|
+ */
|
|
|
+ [SET_PAID_TOTAL] (state, payload) {
|
|
|
+ state.paidTotal = payload
|
|
|
+ },
|
|
|
}
|
|
|
|
|
|
const actions = {
|
|
|
+ /**
|
|
|
+ * [INIT_PAYMENTS_JOURNALS]
|
|
|
+ */
|
|
|
+ [INIT_PAYMENTS_JOURNALS] ({ commit }, payload ) {
|
|
|
+ commit(SET_PAYMENTS_JOURNALS, payload)
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [SELECT_PAYMENTS_JOURNALS]
|
|
|
+ */
|
|
|
+ [SELECT_PAYMENTS_JOURNALS] ({ commit, getters }, payload ) {
|
|
|
+ commit(SELECTED_PAYMENTS_JOURNALS, payload)
|
|
|
+
|
|
|
+ let currency = []
|
|
|
+ if (payload.currency.id){
|
|
|
+ currency = payload.currency
|
|
|
+ } else {
|
|
|
+ currency = getters.currencyCompany
|
|
|
+ }
|
|
|
+ commit(CALCULATE_PAYMENTS_TOTAL, {
|
|
|
+ paymentsCurrencyAmount: getters.paymentsCurrencyAmount,
|
|
|
+ currency: currency
|
|
|
+ } )
|
|
|
+ },
|
|
|
/**
|
|
|
* [ADD_PAYMENTS_MOVE_LINES]
|
|
|
*/
|
|
|
- [ADD_PAYMENTS_MOVE_LINES] ({ commit}, payload ) {
|
|
|
+ [ADD_PAYMENTS_MOVE_LINES] ({ commit, getters }, payload ) {
|
|
|
commit(SET_ADD_PAYMENTS_MOVE_LINES, payload)
|
|
|
+ commit(CALCULATE_CURRENCY_AMOUNT, {
|
|
|
+ paymentsMoveLines: getters.paymentsMoveLines,
|
|
|
+ currency: getters.currency
|
|
|
+ })
|
|
|
},
|
|
|
/**
|
|
|
* [REMOVE_PAYMENTS_MOVE_LINES]
|
|
|
*/
|
|
|
- [REMOVE_PAYMENTS_MOVE_LINES] ({ commit }, payload ) {
|
|
|
+ [REMOVE_PAYMENTS_MOVE_LINES] ({ commit, getters }, payload ) {
|
|
|
commit(SET_REMOVE_PAYMENTS_MOVE_LINES, payload)
|
|
|
- }
|
|
|
+ commit(CALCULATE_CURRENCY_AMOUNT, {
|
|
|
+ paymentsMoveLines: getters.paymentsMoveLines,
|
|
|
+ currency: getters.currency
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ [CHANGE_INITIAL_PAID] ({ commit },payload) {
|
|
|
+ commit(SET_PAID_TOTAL, payload)
|
|
|
+ },
|
|
|
}
|
|
|
|
|
|
export default {
|