|
@@ -1,13 +1,20 @@
|
|
|
/* Actions */
|
|
|
import {
|
|
|
INIT_SUPPLIER_MOVE_LINES,
|
|
|
- SELECT_SUPPLIER_MOVE_LINES
|
|
|
+ SELECT_SUPPLIER_MOVE_LINES,
|
|
|
+ ACTION_REMOVE_SUPPLIER_LINES_PAYMENTS,
|
|
|
+ ADD_MOVE_IN_INVOICE
|
|
|
} from '@/constants/actionTypes'
|
|
|
/* Mutations */
|
|
|
import {
|
|
|
SET_SUPPLIER_MOVE_LINES,
|
|
|
SET_SELECTED_SUPPLIER_MOVE_LINES,
|
|
|
- SET_SUPPLIER_LINES_PAYMENTS
|
|
|
+ SET_SUPPLIER_LINES_PAYMENTS,
|
|
|
+ REMOVE_SUPPLIER_MOVE_LINES,
|
|
|
+ SET_ORDER_SUPPLIER_MOVE_LINES,
|
|
|
+ SET_ORDER_SUPPLIER_LINES_PAYMENTS,
|
|
|
+ SET_CALCULATE_TOTAL,
|
|
|
+ REMOVE_SUPPLIER_LINES_PAYMENTS
|
|
|
} from '@/constants/mutationTypes'
|
|
|
|
|
|
const intialState = {
|
|
@@ -69,8 +76,71 @@ const mutations = {
|
|
|
|
|
|
[SET_SUPPLIER_LINES_PAYMENTS] (state, payload) {
|
|
|
state.supplierLinesPayments = [payload, ...state.supplierLinesPayments]
|
|
|
- }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [amountTot description]
|
|
|
+ * @type {[type]}
|
|
|
+ */
|
|
|
+ [REMOVE_SUPPLIER_MOVE_LINES] ( state, payload ) {
|
|
|
+ let moveFoundIndex = state.supplierMoveLines.findIndex(item => item.id === payload.id)
|
|
|
+ state.supplierMoveLines.splice(moveFoundIndex, 1)
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [mode description]
|
|
|
+ * @type {[type]}
|
|
|
+ */
|
|
|
+ [REMOVE_SUPPLIER_LINES_PAYMENTS] (state, payload ) {
|
|
|
+ if (payload.mode === 'full') {
|
|
|
+ payload.moveLines.forEach(moves => {
|
|
|
+ //ADD supplierMoveLines
|
|
|
+ let movesFound = state.supplierMoveLines.find(item => item.id === moves.id)
|
|
|
+ if (movesFound) return
|
|
|
+ state.supplierMoveLines = [move, ...state.supplierMoveLines]
|
|
|
+ // Remove Payments
|
|
|
+ let movesPaymentsIndex = state.supplierLinesPayments.findIndex(item => item.id === moves.id)
|
|
|
+ state.supplierLinesPayments.splice(movesPaymentsIndex)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ //ADD supplierMoveLines
|
|
|
+ let movesFound = state.supplierMoveLines.find(item => item.id === payload.moveLines.id)
|
|
|
+ if (movesFound) return
|
|
|
+ state.supplierMoveLines = [payload.moveLines, ...state.supplierMoveLines]
|
|
|
+ // Remove Payments
|
|
|
+ let movesPaymentsIndex = state.supplierLinesPayments.findIndex(item => item.id === payload.moveLines.id)
|
|
|
+ state.supplierLinesPayments.splice(movesPaymentsIndex, 1)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [amountTot description]
|
|
|
+ * @type {[type]}
|
|
|
+ */
|
|
|
+ [SET_CALCULATE_TOTAL] ( state ) {
|
|
|
+ let amountTot = 0
|
|
|
+ if (state.supplierLinesPayments.length > 0)
|
|
|
+ state.supplierLinesPayments.forEach( item => {
|
|
|
+ amountTot = amountTot + item.amountResidualCurrency
|
|
|
+ })
|
|
|
|
|
|
+ state.supplierPaymentsTotal = amountTot
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [supplierMoveLines description]
|
|
|
+ * @type {[type]}
|
|
|
+ */
|
|
|
+ [SET_ORDER_SUPPLIER_MOVE_LINES] ( state ) {
|
|
|
+ state.supplierMoveLines = state.supplierMoveLines.sort((a, b) => {
|
|
|
+ return a.dateMaturity > b.dateMaturity
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [supplierLinesPayments description]
|
|
|
+ * @type {[type]}
|
|
|
+ */
|
|
|
+ [SET_ORDER_SUPPLIER_LINES_PAYMENTS]( state ) {
|
|
|
+ state.supplierLinesPayments = state.supplierLinesPayments.sort((a, b) => {
|
|
|
+ return a.dateMaturity > b.dateMaturity
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
const actions = {
|
|
|
/**
|
|
@@ -78,13 +148,36 @@ const actions = {
|
|
|
*/
|
|
|
[INIT_SUPPLIER_MOVE_LINES] ({ commit }, payload) {
|
|
|
commit(SET_SUPPLIER_MOVE_LINES, payload)
|
|
|
+ commit(SET_ORDER_SUPPLIER_MOVE_LINES)
|
|
|
},
|
|
|
/**
|
|
|
* [SELECT_SUPPLIER_MOVE_LINES]
|
|
|
*/
|
|
|
[SELECT_SUPPLIER_MOVE_LINES] ({ commit }, payload) {
|
|
|
- commit(SET_SELECTED_SUPPLIER_MOVE_LINES, payload)
|
|
|
+ // payments
|
|
|
commit(SET_SUPPLIER_LINES_PAYMENTS, payload)
|
|
|
+ commit(SET_ORDER_SUPPLIER_LINES_PAYMENTS)
|
|
|
+ // Move Lines
|
|
|
+ commit(SET_SELECTED_SUPPLIER_MOVE_LINES, payload)
|
|
|
+ commit(REMOVE_SUPPLIER_MOVE_LINES, payload)
|
|
|
+ // Total
|
|
|
+ commit(SET_CALCULATE_TOTAL)
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * [mode description]
|
|
|
+ * @type {String}
|
|
|
+ */
|
|
|
+ [ACTION_REMOVE_SUPPLIER_LINES_PAYMENTS] ( {commit, dispatch}, payload ) {
|
|
|
+ dispatch(ADD_MOVE_IN_INVOICE, {
|
|
|
+ mode: 'partial',
|
|
|
+ moveLines: payload
|
|
|
+ })
|
|
|
+ commit(REMOVE_SUPPLIER_LINES_PAYMENTS, {
|
|
|
+ mode: 'partial',
|
|
|
+ moveLines: payload
|
|
|
+ })
|
|
|
+
|
|
|
+ commit(SET_ORDER_SUPPLIER_MOVE_LINES)
|
|
|
}
|
|
|
}
|
|
|
|