123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- import axios from 'axios'
- import {
- INIT_PAYMENTS_URL,
- PAYMENTS_PROCESS_URL
- } from '@/constants/resourcePaths'
- /*Action */
- import {
- PAYMENTS_NOTIFY,
- INIT_PAYMENTS,
- EXPLODE_DATA,
- INIT_PAYMENTS_DATE,
- INIT_PAYMENTS_USER,
- INIT_PAYMENTS_CUSTOMERS,
- INIT_PAYMENTS_JOURNALS,
- INIT_PAYMENTS_CURRENCIES,
- PAYMENTS_PROCESS,
- CHECK_CUSTOMER,
- CHECK_INVOICE,
- CHECK_MOVE,
- CHECK_PAYMENTS,
- COMPLETED_PAYMENTS,
- RESET_PAYMENT_CUSTOMER,
- RESET_DATE,
- RESET_USER,
- RESET_COMPANY,
- RESET_CUSTOMERS,
- RESET_INVOICES,
- RESET_MOVE_LINES,
- RESET_JOURNALS,
- RESET_CURRENCY,
- RESET_PAYMENTS,
- RESET_BANK_TYPE,
- RESET_BANK,
- SET_CHANGE_TAB_STEPS_SALES,
- REMOVE_MOVE_PAYMENTS_ALL
- } from '@/constants/actionTypes'
- // Mutations
- import {
- SET_PROCESSING_PAYMENTS,
- SET_COMPLETED_PAYMENTS
- } from '@/constants/mutationTypes'
- const actions = {
- /**
- * [PAYMENTS_NOTIFY]
- * @type {[type]}
- */
- [PAYMENTS_NOTIFY] ({ commit },payload) {
- openerp.web.notification.do_warn('Atencion', payload)
- return false
- },
- /**
- * [INIT_PAYMENTS]
- * @param {*} param0
- */
- [INIT_PAYMENTS] ({ dispatch }) {
- return axios.get(INIT_PAYMENTS_URL).then(response => {
- dispatch(COMPLETED_PAYMENTS, false)
- dispatch('explodeData', response.data)
- }).catch(error => {
- console.log(error);
- })
- },
- /**
- * [EXPLODE_DATA]
- * @param {*} param0
- * @param {*} payload
- */
- [EXPLODE_DATA] ({ dispatch }, payload) {
- for (let value in payload) {
- dispatch(`initPayments${value[0].toUpperCase()}${value.slice(1)}`,payload[value])
- }
- },
- /**
- * [CHECK_CUSTOMER]
- */
- [CHECK_CUSTOMER] ({ getters, dispatch }) {
- return !!getters.selectedCustomer ||dispatch(PAYMENTS_NOTIFY,'Necesitas seleccionar un cliente para continuar.')
- },
- /**
- * [CHECK_INVOICE]
- */
- [CHECK_INVOICE] ({ getters, dispatch }) {
- return !!getters.selectedInvoice ||dispatch(PAYMENTS_NOTIFY, 'Necesitas seleccionar una factura para continuar.')
- },
- /**
- * [data description]
- * @type {Object}
- */
- [CHECK_MOVE]({ getters, dispatch }) {
- return !!getters.movesPayments.length || dispatch(PAYMENTS_NOTIFY,'Necesitas seleccionar al menos una cuota para continuar.')
- },
- /**
- * [data description]
- * @type {Object}
- */
- [CHECK_PAYMENTS]({ getters, dispatch }) {
- if (!getters.selectedJournal || getters.selectedJournal.length <= 0) {
- return dispatch(PAYMENTS_NOTIFY, 'Necesitas seleccionar un método de pago')
- }
- if (getters.paidTotal <= 0){
- return dispatch(PAYMENTS_NOTIFY, 'Necesitas ingresar un monto a pagar')
- }
- if (getters.selectedJournal && getters.selectedJournal.type ==='bank') {
- if (!getters.selectedPaymentsBank || getters.selectedPaymentsBank.length <= 0) {
- return dispatch(PAYMENTS_NOTIFY, 'Necesitas seleccionar un banco')
- }
- if (!getters.selectedPaymentsBankType || getters.selectedPaymentsBankType.length <= 0) {
- return dispatch(PAYMENTS_NOTIFY, 'Necesitas seleccionar el tipo de transacción bancaria')
- }
- if (!getters.paymentsBankRef){
- return dispatch(PAYMENTS_NOTIFY, 'Necesitas ingresar el Nº cheque / boleta')
- }
- if (!getters.paymentsBankDateMaturity){
- return dispatch(PAYMENTS_NOTIFY, 'Necesitas ingresar una fecha de vencimiento')
- }
- }
- return true
- },
- /**
- * [PAYMENTS_PROCESS]
- * @param {*} param0
- * @param {*} payload
- */
- [PAYMENTS_PROCESS] ({ getters, commit, dispatch }, payload ) {
- commit(SET_PROCESSING_PAYMENTS, true)
- const data = {
- jsonrpc: '2.0',
- method: 'call',
- params: {
- invoiceId: getters.selectedInvoice.id,
- journalId: getters.selectedJournal.id,
- customerId: getters.selectedCustomer.id,
- amountPayments: getters.paidTotal <= getters.paymentCurrencyTotal ? getters.paidTotal : getters.paymentCurrencyTotal,
- journalType: getters.selectedJournal.type,
- bankId: getters.selectedJournal.type ==='bank' ? getters.selectedPaymentsBank.id : '',
- bankTypeId: getters.selectedJournal.type ==='bank' ? getters.selectedPaymentsBankType.id : '',
- bankRef: getters.selectedJournal.type ==='bank' ? getters.paymentsBankRef : '',
- bankDateMaturity: getters.selectedJournal.type ==='bank' ? getters.paymentsBankDateMaturity : '',
- paymentsBankNumber_cta: getters.selectedJournal.type ==='bank' ? getters.paymentsBankNumberCta : '',
- paymentsBankName_holder: getters.selectedJournal.type ==='bank' ? getters.paymentsBankNameHolder : '',
- moveLines: getters.movesPayments.map(item => {
- return item.id
- })
- }
- }
- return axios.post(PAYMENTS_PROCESS_URL, data).then(response => {
- commit(SET_PROCESSING_PAYMENTS, !response.data.result)
- dispatch(COMPLETED_PAYMENTS, response.data.result)
- }).catch(error => {
- console.log(error);
- commit(SET_PROCESSING_PAYMENTS, false)
- })
- },
- /**
- * [COMPLETED_PAYMENTS]
- *
- */
- [COMPLETED_PAYMENTS] ({ commit }, payload) {
- commit(SET_COMPLETED_PAYMENTS, !!payload)
- },
- /**
- * [RESET_PAYMENT_CUSTOMER]
- */
- [RESET_PAYMENT_CUSTOMER] ({ rootState, commit, dispatch }){
- for (let key in rootState) {
- if (!(rootState[key] instanceof Object)){
- continue
- }
- dispatch(`reset${key[0].toUpperCase()}${key.slice(1)}`)
- }
- dispatch(INIT_PAYMENTS)
- },
- /**
- * [prev description]
- * @type {[type]}
- */
- [SET_CHANGE_TAB_STEPS_SALES] ({ commit, dispatch, getters }, payload) {
- // Resetaer all
- if (payload.prev === 0 && payload.next === -1) {
- dispatch(RESET_PAYMENT_CUSTOMER)
- }
- // Reset STEPS 3-4
- if (payload.prev >= 2 && payload.next <= 1){
- dispatch(REMOVE_MOVE_PAYMENTS_ALL)
- }
- }
- }
- export default actions
|