actions.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import axios from 'axios'
  2. const actions = {
  3. notify(_, message) {
  4. openerp.web.notification.do_warn('Atencion', message)
  5. return false
  6. },
  7. initProcessBank({ getters, commit, dispatch}, mode) {
  8. commit('setMode', mode || getters.mode)
  9. return axios.get('/eiru_bank_statement/init', {
  10. params: {
  11. mode: getters.mode
  12. }
  13. }).then(({data}) => {
  14. dispatch('explodeData', data)
  15. }).catch(error => {
  16. console.error(error);
  17. })
  18. },
  19. explodeData({ dispatch }, data) {
  20. for (let value in data) {
  21. dispatch(`init${value[0].toUpperCase()}${value.slice(1)}`, data[value]);
  22. }
  23. },
  24. /* Check Statement */
  25. checkStatement({ getters, dispatch }) {
  26. return !!getters.selectedStatement || dispatch('notify', 'Necesitas seleccionar una caja para continuar');
  27. },
  28. /* Check Statement Dest */
  29. checkStatementDest({ getters, dispatch }) {
  30. return !!getters.selectedStatementDest || dispatch('notify', 'Necesitas seleccionar una caja para la transferencia')
  31. },
  32. /*
  33. checkAmount({ getters, dispatch}) {
  34. return getters.amountOperation > 0 || dispatch('notify', 'El valor de la operación debe ser mayor que “0”.')
  35. },*/
  36. //
  37. // description
  38. /* Fin del processo */
  39. endProcess({getters, commit, dispatch}) {
  40. let data = {}
  41. if (getters.isTransfer || getters.isInputCashbox || getters.isOutputCashbox) {
  42. console.log("Transferencia, entrada o Salida")
  43. /* Verift Amount Operation */
  44. if (getters.amountOperation <= 0) {
  45. dispatch('notify', 'El valor de la operación debe ser mayor que “0”.')
  46. return false
  47. }
  48. /* Verify Description */
  49. if (!getters.description.trim()) {
  50. dispatch('notify', 'Necesitas ingresar una observación para la operación.')
  51. return false
  52. }
  53. /* Generate Data */
  54. data = {
  55. transfer: getters.isTransfer,
  56. input: getters.isInputCashbox,
  57. output: getters.isOutputCashbox,
  58. amount: getters.amountOperation,
  59. description: getters.description,
  60. casboxOriginId: getters.selectedStatement.id,
  61. casboxDestID: !!getters.selectedStatementDest ? getters.selectedStatementDest.id: '',
  62. }
  63. commit('setDataEndProcess', data)
  64. dispatch('createCasboxMove')
  65. }
  66. if (getters.isStatmentConfirm) {
  67. console.log("CIERRE ")
  68. let data = {}
  69. if (!getters.description.trim()) {
  70. dispatch('notify', 'Necesitas ingresar una observación para el cierre de caja.')
  71. return false
  72. }
  73. data = {
  74. statementId: getters.selectedStatement.id,
  75. amount: getters.amountOperation,
  76. description: getters.description,
  77. }
  78. commit('setDataEndProcess', data)
  79. dispatch('processClosingStatement')
  80. }
  81. },
  82. /**
  83. * [createCasboxMove ]
  84. * # Transferencia
  85. * # input
  86. * # Output
  87. */
  88. createCasboxMove({ getters, dispatch, commit }) {
  89. return axios.post('/eiru_bank_statement/create_cashbox_move', {
  90. jsonrpc: '2.0',
  91. method: 'call',
  92. params: {
  93. data: getters.data
  94. }
  95. }).then(({data}) => {
  96. // dispatch('notify', data.result.message)
  97. }).catch(error => {
  98. console.error(error)
  99. })
  100. },
  101. processClosingStatement({ getters, dispatch, commit }) {
  102. return axios.post('/eiru_bank_statement/process_closing_statement', {
  103. jsonrpc: '2.0',
  104. method: 'call',
  105. params: {
  106. data: getters.data
  107. }
  108. }).then(({data}) => {
  109. dispatch('notify', data.result.message)
  110. }).catch(error => {
  111. console.error(error)
  112. })
  113. },
  114. /*
  115. ____ ____ _____ _ _____ _____ ____ _____ _ _____ _____ __ __ _____ _ _ _____
  116. / ___| _ \| ____| / \|_ _| ____| / ___|_ _|/ \|_ _| ____| \/ | ____| \ | |_ _|
  117. | | | |_) | _| / _ \ | | | _| \___ \ | | / _ \ | | | _| | |\/| | _| | \| | | |
  118. | |___| _ <| |___ / ___ \| | | |___ ___) || |/ ___ \| | | |___| | | | |___| |\ | | |
  119. \____|_| \_\_____/_/ \_\_| |_____| |____/ |_/_/ \_\_| |_____|_| |_|_____|_| \_| |_|
  120. */
  121. endProcessNewStatement({getters, commit, dispatch}){
  122. let data = {}
  123. data = {
  124. journal_id: getters.selectedJournal,
  125. type_statement: getters.selectedStatementType,
  126. user_id: getters.selectedUserStatement,
  127. date: getters.dateStatement,
  128. }
  129. commit('setDataEndProcess', data)
  130. dispatch('createAccountBankStatement')
  131. },
  132. /*[CreateAccountBankStatement "Crear Caja"]*/
  133. createAccountBankStatement({ getters, dispatch, commit}) {
  134. return axios.post('/eiru_bank_statement/create_account_bank_statement', {
  135. jsonrpc: '2.0',
  136. method: 'call',
  137. params: {
  138. data: getters.data
  139. }
  140. }).then(({data}) => {
  141. dispatch('notify', data.result.message)
  142. if (data.result.state){
  143. dispatch('receiveStatment',data.result.data)
  144. dispatch('showStatementAdd',false)
  145. }
  146. }).catch(error => {
  147. console.error(error)
  148. })
  149. },
  150. resetStoreModules({ dispatch }, payload) {
  151. // console.log(payload)
  152. // console.log(
  153. // !!getters.isInputCashbox
  154. // !!getters.isOutputCashbox
  155. // )
  156. // if (!!getters.isInputCashbox || !!getters.isOutputCashbox && payload === 1) {
  157. //
  158. // }
  159. // if (payload > 1 ){
  160. // return
  161. // }
  162. // dispatch('resetStatementAction')
  163. // dispatch('resetStatement')
  164. // isTransfer
  165. // isInputCashbox
  166. // isOutputCashbox
  167. // resetStatement
  168. // resetStatementAction
  169. return
  170. }
  171. }
  172. export default actions