currency.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const initialState = {
  2. currency: [],
  3. loadingCurrency: false,
  4. currencyAmount: []
  5. }
  6. const state = {
  7. currency: initialState.currency,
  8. loadingCurrency: initialState.loadingCurrency,
  9. currencyAmount: initialState.currencyAmount
  10. }
  11. const getters = {
  12. /**
  13. * [currency]
  14. */
  15. currency(state) {
  16. return state.currency
  17. },
  18. /**
  19. * [loadingCurrency]
  20. */
  21. loadingCurrency(state) {
  22. return state.loadingCurrency
  23. },
  24. /**
  25. * [currencyAmount description]
  26. */
  27. currencyAmount (state) {
  28. return state.currencyAmount
  29. }
  30. }
  31. const mutations = {
  32. /**
  33. * [currency]
  34. */
  35. setCurrencies (state, payload) {
  36. state.currency = payload
  37. },
  38. /**
  39. * [loadingCurrency]
  40. */
  41. setLoadingCurrencies (state, payload) {
  42. state.loadingCurrency = !!payload
  43. },
  44. /**
  45. * [actions description]
  46. */
  47. setCurrenciesAmount (state, payload) {
  48. let currency = payload.currency
  49. let currencyMove = payload.currencyMovePayments
  50. let amountCurrency = []
  51. currency.forEach(item => {
  52. let amount = 0
  53. currencyMove.forEach(currency =>{
  54. let currencyMoveLine = currency.currencyAmount.find(move => move.id === item.id)
  55. amount = amount + currencyMoveLine.amountCurencyResidual
  56. })
  57. amountCurrency.push({
  58. id: item.id,
  59. symbolCurrency: item.symbol,
  60. amount: amount,
  61. symbol: ' ',
  62. position: 'before',
  63. thousandsSeparator: item.thousandsSeparator,
  64. decimalSeparator: item.decimalSeparator,
  65. decimalPlaces: item.decimalPlaces,
  66. rateSilent: item.rateSilent
  67. })
  68. })
  69. state.currencyAmount = amountCurrency
  70. }
  71. }
  72. const actions = {
  73. /**
  74. * [INIT_CURRENCIES]
  75. */
  76. initPaymentsCurrencies ({commit}, payload) {
  77. commit('setCurrencies', payload)
  78. commit('setLoadingCurrencies', payload)
  79. },
  80. /**
  81. * [currencyInvoiceRate description]
  82. */
  83. resetCurrency({ commit }) {
  84. commit('setCurrencies', [] )
  85. },
  86. /**
  87. * [currencyInvoiceRate description]
  88. */
  89. initCurrenciesAmount ({ commit, getters, dispatch}) {
  90. commit('setCurrenciesAmount', {
  91. currencyMovePayments: getters.movesPayments,
  92. currency: getters.currency
  93. })
  94. dispatch('resetPayments')
  95. }
  96. }
  97. export default {
  98. state,
  99. getters,
  100. mutations,
  101. actions
  102. }