123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- import { SELECT_MOVE_INVOICE, SELECT_MOVE, REMOVE_MOVE_PAYMENTS, ADD_MOVE_IN_INVOICE, REMOVE_MOVE_PAYMENTS_ALL } from '@/constants/actionTypes'
- import { SET_MOVES, SET_SELECTED_MOVE_LINE, SET_SELECTED_MOVE_PAYMENTS, REMOVE_MOVE_LINE, REMOVE_PAYMENTS_MOVE, SET_TOTAL_MOVE_PAYMENTS } from '@/constants/mutationTypes'
- const initialState = {
- moves : null,
- selectedMoveLine: null,
- movesPayments: [],
- movesPaymentsTotal: 0,
- movesPaymentsBalance: 0,
- }
- const state = {
- moves: initialState.moves,
- selectedMoveLine: initialState.selectedMoveLine,
- movesPayments: initialState.movesPayments,
- movesPaymentsTotal: initialState.movesPaymentsTotal,
- movesPaymentsBalance: initialState.movesPaymentsBalance,
- }
- const getters = {
- /**
- * [moves description]
- * @param {[type]} state [description]
- * @return {[type]} [description]
- */
- moves (state) {
- return state.moves
- },
- /**
- * [selectedMoveLine description]
- * @param {[type]} state [description]
- * @return {[type]} [description]
- */
- selectedMoveLine (state){
- return state.selectedMoveLine
- },
- /**
- * [movesPayments description]
- * @param {[type]} state [description]
- * @return {[type]} [description]
- */
- movesPayments (state) {
- return state.movesPayments
- },
- /**
- * [movesPaymentsTotal description]
- * @param {[type]} state [description]
- * @return {[type]} [description]
- */
- movesPaymentsTotal (state) {
- return state.movesPaymentsTotal
- },
- /**
- * [movesPaymentsBalance description]
- * @param {[type]} state [description]
- * @return {[type]} [description]
- */
- movesPaymentsBalance (state) {
- return state.movesPaymentsBalance
- }
- }
- const mutations = {
- /**
- * [moves description]
- * @type {[type]}
- * @param {[type]} state [description]
- * @param {[type]} payload [description]
- */
- [SET_MOVES] (state, payload) {
- state.moves = payload
- },
- /**
- * [selectedMoveLine description]
- * @type {[type]}
- * @param {[type]} state [description]
- * @param {[type]} payload [description]
- */
- [SET_SELECTED_MOVE_LINE] (state, payload) {
- state.selectedMoveLine = payload
- },
- /**
- * [movesPayments description]
- * @type {[type]}
- * @param {[type]} state [description]
- * @param {[type]} payload [description]
- */
- [SET_SELECTED_MOVE_PAYMENTS] (state, payload) {
- state.movesPayments = [payload, ...state.movesPayments]
- },
- /**
- * [actions description]
- * @type {Object}
- * @param {[type]} state [description]
- * @param {[type]} payload [description]
- */
- [REMOVE_MOVE_LINE] (state, payload) {
- let moveFoundIndex = state.moves.findIndex(item => item.id === payload.id)
- state.moves.splice(moveFoundIndex, 1)
- },
- /**
- * [actions description]
- * @type {Object}
- * @param {[type]} state [description]
- * @param {[type]} payload [description]
- */
- [REMOVE_PAYMENTS_MOVE]( state, payload) {
- if (payload.mode ==='full') {
- payload.moveLine.forEach(moves => {
- let movesFoundIndex = state.moves.find(item => item.id === moves.id)
- if (movesFoundIndex) return
- /*ADD MOVE LINE*/
- state.moves = [moves, ...state.moves]
- /* REMOVE MOVE CARD*/
- let movesPaymentsFoundIndex = state.movesPayments.findIndex(item => item.id === moves.id)
- state.movesPayments.splice(movesPaymentsFoundIndex, 1)
- })
- } else {
- let movesFound = state.moves.find(item => item.id === payload.moveLine.id)
- if (movesFound) return
- state.moves = [payload.moveLine, ...state.moves]
- let movesFoundIndex = state.movesPayments.findIndex(item => item.id === payload.moveLine.id)
- state.movesPayments.splice(movesFoundIndex, 1)
- }
- },
- /**
- * [total description]
- * @type {[type]}
- * @param {[type]} state [description]
- * @param {[type]} payload [description]
- */
- [SET_TOTAL_MOVE_PAYMENTS] (state) {
- let total =0
- state.movesPayments.forEach(item => {
- total = total + item.amountResidual
- })
- state.movesPaymentsTotal = total
- }
- }
- const actions = {
- /**
- * [SELECT_MOVE_INVOICE]
- * @param {*} param0
- * @param {*} payload
- */
- [SELECT_MOVE_INVOICE] ({ commit }, payload) {
- commit(SET_MOVES, payload)
- },
- /**
- * [SELECT_MOVE]
- * @param {*} param0
- * @param {*} payload
- */
- [SELECT_MOVE] ({ commit }, payload) {
- commit(SET_SELECTED_MOVE_PAYMENTS, payload)
- commit(SET_SELECTED_MOVE_LINE, payload)
- /* Remover Move Line */
- commit(REMOVE_MOVE_LINE, payload)
- commit(SET_TOTAL_MOVE_PAYMENTS)
- },
- /**
- *
- * @param {*} param0
- * @param {*} payload
- */
- [REMOVE_MOVE_PAYMENTS] ({ commit, dispatch }, payload) {
- dispatch(ADD_MOVE_IN_INVOICE, {
- moveLine: payload,
- mode: 'partial'
- })
- commit(REMOVE_PAYMENTS_MOVE, {
- moveLine: payload,
- mode: 'partial'
- })
- commit(SET_TOTAL_MOVE_PAYMENTS)
- },
- /**
- * [length description]
- * @type {[type]}
- */
- [REMOVE_MOVE_PAYMENTS_ALL] ({commit, dispatch, state}, payload) {
- console.log(payload);
- if (!payload) return
- if (state.movesPayments.length === 0 ) return
- dispatch(ADD_MOVE_IN_INVOICE,{
- moveLine: state.movesPayments.map(item => {
- return item
- }),
- mode: 'full'
- })
- commit(REMOVE_PAYMENTS_MOVE, {
- moveLine: state.movesPayments.map(item => {
- return item
- }),
- mode: 'full'
- })
- commit(SET_TOTAL_MOVE_PAYMENTS)
- }
- }
- export default {
- state,
- getters,
- mutations,
- actions
- }
|