mirror of
https://github.com/PanJiaChen/vue-element-admin.git
synced 2025-08-12 22:29:59 +08:00
feat: Refactor payments vuex module (#586)
* feat: Refactorizar el módulo vuex de pagos * minimal changees * minimal changes
This commit is contained in:
parent
d8ee1b8f7b
commit
b996c4a53c
@ -11,6 +11,10 @@
|
|||||||
{
|
{
|
||||||
"name": "Edwin Betancourt",
|
"name": "Edwin Betancourt",
|
||||||
"url": "https://github.com/EdwinBetanc0urt/"
|
"url": "https://github.com/EdwinBetanc0urt/"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Elsio Sanchez",
|
||||||
|
"url": "https://github.com/elsiosanchez"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -266,7 +266,7 @@ export default {
|
|||||||
return listLocal
|
return listLocal
|
||||||
},
|
},
|
||||||
paymentBox() {
|
paymentBox() {
|
||||||
const payment = this.isPaymentBox.filter(pay => {
|
const payment = this.listPayments.filter(pay => {
|
||||||
return pay.isVisible
|
return pay.isVisible
|
||||||
})
|
})
|
||||||
if (this.isEmptyValue(payment)) {
|
if (this.isEmptyValue(payment)) {
|
||||||
@ -527,7 +527,7 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.convertCurrency()
|
this.convertCurrency()
|
||||||
}, 1000)
|
}, 2000)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
formatDate,
|
formatDate,
|
||||||
@ -602,7 +602,6 @@ export default {
|
|||||||
currencyUuid: this.currencyDisplay(currencyToPay).currencyUuid
|
currencyUuid: this.currencyDisplay(currencyToPay).currencyUuid
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.amontSend = 0
|
|
||||||
this.addCollect()
|
this.addCollect()
|
||||||
},
|
},
|
||||||
updateServer(listPaymentsLocal) {
|
updateServer(listPaymentsLocal) {
|
||||||
|
@ -216,7 +216,7 @@
|
|||||||
>
|
>
|
||||||
<p>
|
<p>
|
||||||
<i class="el-icon-mobile-phone" />
|
<i class="el-icon-mobile-phone" />
|
||||||
{{ $t('form.pos.order.pointSale') }}: <b style="cursor: pointer"> {{ namePointOfSales }} </b>
|
{{ $t('form.pos.order.pointSale') }}: <b style="cursor: pointer"> {{ namePointOfSales.name }} </b>
|
||||||
</p>
|
</p>
|
||||||
<el-dropdown-menu slot="dropdown">
|
<el-dropdown-menu slot="dropdown">
|
||||||
<el-dropdown-item
|
<el-dropdown-item
|
||||||
@ -355,7 +355,7 @@ export default {
|
|||||||
namePointOfSales() {
|
namePointOfSales() {
|
||||||
const currentPOS = this.$store.getters.getCurrentPOS
|
const currentPOS = this.$store.getters.getCurrentPOS
|
||||||
if (currentPOS && !this.isEmptyValue(currentPOS.name)) {
|
if (currentPOS && !this.isEmptyValue(currentPOS.name)) {
|
||||||
return currentPOS.name
|
return currentPOS
|
||||||
}
|
}
|
||||||
return undefined
|
return undefined
|
||||||
},
|
},
|
||||||
@ -443,13 +443,22 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
this.$store.commit('currencyMultiplyRate', 1)
|
this.$store.commit('currencyMultiplyRate', 1)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
namePo1intOfSales(value) {
|
||||||
|
if (!this.isEmptyValue(value)) {
|
||||||
|
this.$router.push({
|
||||||
|
query: {
|
||||||
|
pos: value.id
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
// setTimeout(() => {
|
setTimeout(() => {
|
||||||
// this.tenderTypeDisplaye()
|
this.tenderTypeDisplaye()
|
||||||
// this.currencyDisplaye()
|
this.currencyDisplaye()
|
||||||
// }, 1500)
|
}, 1500)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
changePos(posElement) {
|
changePos(posElement) {
|
||||||
@ -460,9 +469,8 @@ export default {
|
|||||||
this.isShowedPOSKeyLayout = !this.isShowedPOSKeyLayout
|
this.isShowedPOSKeyLayout = !this.isShowedPOSKeyLayout
|
||||||
this.$store.commit('setShowPOSCollection', true)
|
this.$store.commit('setShowPOSCollection', true)
|
||||||
// this.isShowedPOSKeyLayout = true
|
// this.isShowedPOSKeyLayout = true
|
||||||
const posUuid = this.$store.getters.getCurrentPOS.uuid
|
|
||||||
const orderUuid = this.$route.query.action
|
const orderUuid = this.$route.query.action
|
||||||
this.$store.dispatch('listPayments', { posUuid, orderUuid })
|
this.$store.dispatch('listPayments', { orderUuid })
|
||||||
this.isShowedPOSKeyLaout = !this.isShowedPOSKeyLaout
|
this.isShowedPOSKeyLaout = !this.isShowedPOSKeyLaout
|
||||||
this.$store.commit('setShowPOSOptions', false)
|
this.$store.commit('setShowPOSOptions', false)
|
||||||
},
|
},
|
||||||
|
@ -203,7 +203,7 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
const listOrder = this.$store.getters.getListOrderLine
|
const listOrder = this.$store.getters.getListOrderLine
|
||||||
if (this.isEmptyValue(listOrder)) {
|
if (this.isEmptyValue(listOrder) && !this.isEmptyValue(this.$store.getters.getCurrentPOS.uuid)) {
|
||||||
this.$store.dispatch('listOrdersFromServer', {
|
this.$store.dispatch('listOrdersFromServer', {
|
||||||
posUuid: this.$store.getters.getCurrentPOS.uuid
|
posUuid: this.$store.getters.getCurrentPOS.uuid
|
||||||
})
|
})
|
||||||
@ -256,9 +256,8 @@ export default {
|
|||||||
action: row.uuid
|
action: row.uuid
|
||||||
}
|
}
|
||||||
}, () => {})
|
}, () => {})
|
||||||
const posUuid = this.$store.getters.getCurrentPOS.uuid
|
|
||||||
const orderUuid = this.$route.query.action
|
const orderUuid = this.$route.query.action
|
||||||
this.$store.dispatch('listPayments', { posUuid, orderUuid })
|
this.$store.dispatch('listPayments', { orderUuid })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
subscribeChanges() {
|
subscribeChanges() {
|
||||||
|
@ -1,372 +0,0 @@
|
|||||||
|
|
||||||
import {
|
|
||||||
requestGetConversionRate,
|
|
||||||
requestCreatePayment,
|
|
||||||
requestDeletePayment,
|
|
||||||
requestUpdatePayment,
|
|
||||||
requestListPayments
|
|
||||||
} from '@/api/ADempiere/form/point-of-sales.js'
|
|
||||||
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
|
|
||||||
import { showMessage } from '@/utils/ADempiere/notification.js'
|
|
||||||
|
|
||||||
const collection = {
|
|
||||||
state: {
|
|
||||||
paymentBox: [],
|
|
||||||
multiplyRate: 1,
|
|
||||||
divideRate: 1,
|
|
||||||
multiplyRateCollection: 1,
|
|
||||||
divideRateCollection: 1,
|
|
||||||
listPayments: [],
|
|
||||||
tenderTypeDisplaye: [
|
|
||||||
{
|
|
||||||
tenderTypeCode: 0,
|
|
||||||
tenderTypeDisplay: ''
|
|
||||||
}
|
|
||||||
],
|
|
||||||
currency: [],
|
|
||||||
convertion: {}
|
|
||||||
},
|
|
||||||
mutations: {
|
|
||||||
addPaymentBox(state, paymentBox) {
|
|
||||||
state.paymentBox.push(paymentBox)
|
|
||||||
},
|
|
||||||
currencyMultiplyRate(state, multiplyRate) {
|
|
||||||
state.multiplyRate = multiplyRate
|
|
||||||
},
|
|
||||||
currencyDivideRate(state, divideRate) {
|
|
||||||
state.divideRate = divideRate
|
|
||||||
},
|
|
||||||
currencyMultiplyRateCollection(state, multiplyRateCollection) {
|
|
||||||
state.multiplyRateCollection = multiplyRateCollection
|
|
||||||
},
|
|
||||||
currencyDivideRateCollection(state, divideRateCollection) {
|
|
||||||
state.divideRateCollection = divideRateCollection
|
|
||||||
},
|
|
||||||
setListPayments(state, list) {
|
|
||||||
state.listPayments = list
|
|
||||||
},
|
|
||||||
setTenderTypeDisplaye(state, tenderTypeDisplaye) {
|
|
||||||
state.tenderTypeDisplaye = tenderTypeDisplaye
|
|
||||||
},
|
|
||||||
setCurrencyDisplaye(state, currency) {
|
|
||||||
state.currency = currency
|
|
||||||
},
|
|
||||||
setConvertionPayment(state, convertion) {
|
|
||||||
state.convertion = convertion
|
|
||||||
}
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
/**
|
|
||||||
* creating boxes with the payment list
|
|
||||||
*/
|
|
||||||
setPaymentBox({ state, commit, getters }, {
|
|
||||||
quantityCahs,
|
|
||||||
bankUuid,
|
|
||||||
referenceNo,
|
|
||||||
description,
|
|
||||||
amount,
|
|
||||||
paymentDate,
|
|
||||||
tenderTypeCode,
|
|
||||||
currencyUuid
|
|
||||||
}) {
|
|
||||||
const payments = getters.getPaymentBox.find(element => {
|
|
||||||
if (tenderTypeCode === 'X' && element.currencyUuid === currencyUuid) {
|
|
||||||
return element
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if (isEmptyValue(payments)) {
|
|
||||||
commit('addPaymentBox', {
|
|
||||||
quantityCahs,
|
|
||||||
bankUuid,
|
|
||||||
referenceNo,
|
|
||||||
description,
|
|
||||||
amount,
|
|
||||||
paymentDate,
|
|
||||||
tenderTypeCode,
|
|
||||||
currencyUuid
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
const addPayment = getters.getPaymentBox.map(item => {
|
|
||||||
if ((item.tenderTypeCode === tenderTypeCode) && item.currencyUuid === currencyUuid) {
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
payAmt: item.amount + amount,
|
|
||||||
quantityCahs: item.quantityCahs + quantityCahs
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return item
|
|
||||||
})
|
|
||||||
state.paymentBox = addPayment
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// upload orders to theServer
|
|
||||||
uploadOrdersToServer({ dispatch }, {
|
|
||||||
listPaymentsLocal,
|
|
||||||
posUuid,
|
|
||||||
orderUuid
|
|
||||||
}) {
|
|
||||||
listPaymentsLocal.forEach(payment => {
|
|
||||||
requestCreatePayment({
|
|
||||||
posUuid,
|
|
||||||
orderUuid,
|
|
||||||
bankUuid: payment.bankUuid,
|
|
||||||
referenceNo: payment.referenceNo,
|
|
||||||
description: payment.description,
|
|
||||||
amount: payment.amount,
|
|
||||||
paymentDate: payment.paymentDate,
|
|
||||||
tenderTypeCode: payment.tenderTypeCode,
|
|
||||||
currencyUuid: payment.currencyUuid
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
const orderUuid = response.order_uuid
|
|
||||||
dispatch('listPayments', { orderUuid })
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
|
|
||||||
showMessage({
|
|
||||||
type: 'error',
|
|
||||||
message: error.message,
|
|
||||||
showClose: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
},
|
|
||||||
deleteCollectBox({ state }, key) {
|
|
||||||
const payment = state.paymentBox
|
|
||||||
payment.splice(key, 1)
|
|
||||||
},
|
|
||||||
deleteAllCollectBox({ state }) {
|
|
||||||
const payment = state.paymentBox
|
|
||||||
payment.splice(0)
|
|
||||||
},
|
|
||||||
conversionDivideRate({ commit }, params) {
|
|
||||||
requestGetConversionRate({
|
|
||||||
conversionTypeUuid: params.conversionTypeUuid,
|
|
||||||
currencyFromUuid: params.currencyFromUuid,
|
|
||||||
currencyToUuid: params.currencyToUuid
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
const divideRate = isEmptyValue(response.divideRate) ? 1 : response.divideRate
|
|
||||||
if (params.containerUuid === 'Collection') {
|
|
||||||
commit('currencyDivideRateCollection', divideRate)
|
|
||||||
} else {
|
|
||||||
commit('currencyDivideRate', divideRate)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.warn(`conversionDivideRate: ${error.message}. Code: ${error.code}.`)
|
|
||||||
showMessage({
|
|
||||||
type: 'error',
|
|
||||||
message: error.message,
|
|
||||||
showClose: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
},
|
|
||||||
conversionMultiplyRate({ commit }, {
|
|
||||||
containerUuid,
|
|
||||||
conversionTypeUuid,
|
|
||||||
currencyFromUuid,
|
|
||||||
currencyToUuid
|
|
||||||
// conversionDate
|
|
||||||
}) {
|
|
||||||
requestGetConversionRate({
|
|
||||||
conversionTypeUuid,
|
|
||||||
currencyFromUuid,
|
|
||||||
currencyToUuid
|
|
||||||
// conversionDate
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
const multiplyRate = isEmptyValue(response.multiplyRate) ? 0 : response.multiplyRate
|
|
||||||
if (containerUuid === 'Collection') {
|
|
||||||
commit('currencyMultiplyRateCollection', multiplyRate)
|
|
||||||
} else {
|
|
||||||
commit('currencyMultiplyRate', multiplyRate)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.warn(`conversionMultiplyRate: ${error.message}. Code: ${error.code}.`)
|
|
||||||
showMessage({
|
|
||||||
type: 'error',
|
|
||||||
message: error.message,
|
|
||||||
showClose: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
},
|
|
||||||
changeMultiplyRate({ commit }, params) {
|
|
||||||
commit('currencyMultiplyRate', params)
|
|
||||||
},
|
|
||||||
changeDivideRate({ commit }, divideRate) {
|
|
||||||
commit('currencyDivideRate', divideRate)
|
|
||||||
},
|
|
||||||
createPayments({ dispatch, state, getters }, {
|
|
||||||
posUuid,
|
|
||||||
orderUuid,
|
|
||||||
invoiceUuid,
|
|
||||||
bankUuid,
|
|
||||||
referenceNo,
|
|
||||||
description,
|
|
||||||
amount,
|
|
||||||
paymentDate,
|
|
||||||
tenderTypeCode,
|
|
||||||
currencyUuid
|
|
||||||
}) {
|
|
||||||
const listPayments = getters.getListPayments.find(payment => {
|
|
||||||
if ((payment.tenderTypeCode === tenderTypeCode) && (payment.tenderTypeCode === 'X') && (currencyUuid === payment.currencyUuid)) {
|
|
||||||
return payment
|
|
||||||
}
|
|
||||||
return undefined
|
|
||||||
})
|
|
||||||
if (isEmptyValue(listPayments)) {
|
|
||||||
requestCreatePayment({
|
|
||||||
posUuid,
|
|
||||||
orderUuid,
|
|
||||||
invoiceUuid,
|
|
||||||
bankUuid,
|
|
||||||
referenceNo,
|
|
||||||
description,
|
|
||||||
amount,
|
|
||||||
paymentDate,
|
|
||||||
tenderTypeCode,
|
|
||||||
currencyUuid
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
const orderUuid = response.order_uuid
|
|
||||||
dispatch('listPayments', { orderUuid })
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
|
|
||||||
showMessage({
|
|
||||||
type: 'error',
|
|
||||||
message: error.message,
|
|
||||||
showClose: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
requestUpdatePayment({
|
|
||||||
paymentUuid: listPayments.uuid,
|
|
||||||
bankUuid,
|
|
||||||
referenceNo,
|
|
||||||
description,
|
|
||||||
amount: listPayments.amount + amount,
|
|
||||||
paymentDate,
|
|
||||||
tenderTypeCode
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
const orderUuid = response.order_uuid
|
|
||||||
dispatch('listPayments', { orderUuid })
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
|
|
||||||
showMessage({
|
|
||||||
type: 'error',
|
|
||||||
message: error.message,
|
|
||||||
showClose: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
deletetPayments({ dispatch }, {
|
|
||||||
orderUuid,
|
|
||||||
paymentUuid
|
|
||||||
}) {
|
|
||||||
requestDeletePayment({
|
|
||||||
paymentUuid
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
dispatch('listPayments', { orderUuid })
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
|
|
||||||
showMessage({
|
|
||||||
type: 'error',
|
|
||||||
message: error.message,
|
|
||||||
showClose: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
},
|
|
||||||
listPayments({ commit, rootGetters }, { posUuid, orderUuid }) {
|
|
||||||
requestListPayments({
|
|
||||||
posUuid,
|
|
||||||
orderUuid
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
commit('setListPayments', response.listPayments)
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
tenderTypeDisplaye({ commit }, tenderType) {
|
|
||||||
const displayTenderType = tenderType.map(item => {
|
|
||||||
return {
|
|
||||||
tenderTypeCode: item.id,
|
|
||||||
tenderTypeDisplay: item.label
|
|
||||||
}
|
|
||||||
})
|
|
||||||
commit('setTenderTypeDisplaye', displayTenderType)
|
|
||||||
},
|
|
||||||
currencyDisplaye({ commit }, currency) {
|
|
||||||
const displaycurrency = currency.map(item => {
|
|
||||||
return {
|
|
||||||
currencyUuid: item.uuid,
|
|
||||||
currencyId: item.id,
|
|
||||||
currencyDisplay: item.label
|
|
||||||
}
|
|
||||||
})
|
|
||||||
commit('setCurrencyDisplaye', displaycurrency)
|
|
||||||
},
|
|
||||||
convertionPayment({ commit }, {
|
|
||||||
conversionTypeUuid,
|
|
||||||
currencyFromUuid,
|
|
||||||
currencyToUuid
|
|
||||||
}) {
|
|
||||||
requestGetConversionRate({
|
|
||||||
conversionTypeUuid,
|
|
||||||
currencyFromUuid,
|
|
||||||
currencyToUuid
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
commit('setConvertionPayment', response)
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.warn(`ConvertionPayment: ${error.message}. Code: ${error.code}.`)
|
|
||||||
showMessage({
|
|
||||||
type: 'error',
|
|
||||||
message: error.message,
|
|
||||||
showClose: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
getters: {
|
|
||||||
getPaymentBox: (state) => {
|
|
||||||
return state.paymentBox
|
|
||||||
},
|
|
||||||
getMultiplyRate: (state) => {
|
|
||||||
return state.multiplyRate
|
|
||||||
},
|
|
||||||
getDivideRate: (state) => {
|
|
||||||
return state.divideRate
|
|
||||||
},
|
|
||||||
getMultiplyRateCollection: (state) => {
|
|
||||||
return state.multiplyRateCollection
|
|
||||||
},
|
|
||||||
getDivideRateCollection: (state) => {
|
|
||||||
return state.divideRateCollection
|
|
||||||
},
|
|
||||||
getListPayments: (state) => {
|
|
||||||
return state.listPayments
|
|
||||||
},
|
|
||||||
getListsPaymentTypes: (state) => {
|
|
||||||
return state.tenderTypeDisplaye
|
|
||||||
},
|
|
||||||
getListCurrency: (state) => {
|
|
||||||
return state.currency
|
|
||||||
},
|
|
||||||
getConvertionPayment: (state) => {
|
|
||||||
return state.convertion
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default collection
|
|
@ -82,7 +82,6 @@ const ordes = {
|
|||||||
if (!isEmptyValue(token)) {
|
if (!isEmptyValue(token)) {
|
||||||
pageToken = token + '-' + pageNumber
|
pageToken = token + '-' + pageNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
requestListOrders({
|
requestListOrders({
|
||||||
posUuid,
|
posUuid,
|
||||||
documentNo,
|
documentNo,
|
||||||
@ -114,11 +113,11 @@ const ordes = {
|
|||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.warn(`listOrdersFromServer: ${error.message}. Code: ${error.code}.`)
|
console.warn(`listOrdersFromServer: ${error.message}. Code: ${error.code}.`)
|
||||||
showMessage({
|
// showMessage({
|
||||||
type: 'info',
|
// type: 'info',
|
||||||
message: error.message,
|
// message: error.message,
|
||||||
showClose: true
|
// showClose: true
|
||||||
})
|
// })
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
setOrder({ commit }, order) {
|
setOrder({ commit }, order) {
|
||||||
|
297
src/store/modules/ADempiere/pointOfSales/payments/actions.js
Normal file
297
src/store/modules/ADempiere/pointOfSales/payments/actions.js
Normal file
@ -0,0 +1,297 @@
|
|||||||
|
import {
|
||||||
|
requestGetConversionRate,
|
||||||
|
requestCreatePayment,
|
||||||
|
requestDeletePayment,
|
||||||
|
requestUpdatePayment,
|
||||||
|
requestListPayments
|
||||||
|
} from '@/api/ADempiere/form/point-of-sales.js'
|
||||||
|
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
|
||||||
|
import { showMessage } from '@/utils/ADempiere/notification.js'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payments Actions
|
||||||
|
* @author Elsio Sanchez <elsiosanches@gmail.com>
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
/**
|
||||||
|
* creating boxes with the payment list
|
||||||
|
*/
|
||||||
|
setPaymentBox({ state, commit, getters }, {
|
||||||
|
quantityCahs,
|
||||||
|
bankUuid,
|
||||||
|
referenceNo,
|
||||||
|
description,
|
||||||
|
amount,
|
||||||
|
paymentDate,
|
||||||
|
tenderTypeCode,
|
||||||
|
currencyUuid
|
||||||
|
}) {
|
||||||
|
const payments = getters.getPaymentBox.find(element => {
|
||||||
|
if (tenderTypeCode === 'X' && element.currencyUuid === currencyUuid) {
|
||||||
|
return element
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (isEmptyValue(payments)) {
|
||||||
|
commit('addPaymentBox', {
|
||||||
|
quantityCahs,
|
||||||
|
bankUuid,
|
||||||
|
referenceNo,
|
||||||
|
description,
|
||||||
|
amount,
|
||||||
|
paymentDate,
|
||||||
|
tenderTypeCode,
|
||||||
|
currencyUuid
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const addPayment = getters.getPaymentBox.map(item => {
|
||||||
|
if ((item.tenderTypeCode === tenderTypeCode) && item.currencyUuid === currencyUuid) {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
payAmt: item.amount + amount,
|
||||||
|
quantityCahs: item.quantityCahs + quantityCahs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return item
|
||||||
|
})
|
||||||
|
state.paymentBox = addPayment
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// upload orders to theServer
|
||||||
|
uploadOrdersToServer({ dispatch }, {
|
||||||
|
listPaymentsLocal,
|
||||||
|
posUuid,
|
||||||
|
orderUuid
|
||||||
|
}) {
|
||||||
|
listPaymentsLocal.forEach(payment => {
|
||||||
|
requestCreatePayment({
|
||||||
|
posUuid,
|
||||||
|
orderUuid,
|
||||||
|
bankUuid: payment.bankUuid,
|
||||||
|
referenceNo: payment.referenceNo,
|
||||||
|
description: payment.description,
|
||||||
|
amount: payment.amount,
|
||||||
|
paymentDate: payment.paymentDate,
|
||||||
|
tenderTypeCode: payment.tenderTypeCode,
|
||||||
|
currencyUuid: payment.currencyUuid
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
const orderUuid = response.order_uuid
|
||||||
|
dispatch('listPayments', { orderUuid })
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
|
||||||
|
showMessage({
|
||||||
|
type: 'error',
|
||||||
|
message: error.message,
|
||||||
|
showClose: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
deleteCollectBox({ state }, key) {
|
||||||
|
const payment = state.paymentBox
|
||||||
|
payment.splice(key, 1)
|
||||||
|
},
|
||||||
|
deleteAllCollectBox({ state }) {
|
||||||
|
const payment = state.paymentBox
|
||||||
|
payment.splice(0)
|
||||||
|
},
|
||||||
|
conversionDivideRate({ commit }, params) {
|
||||||
|
requestGetConversionRate({
|
||||||
|
conversionTypeUuid: params.conversionTypeUuid,
|
||||||
|
currencyFromUuid: params.currencyFromUuid,
|
||||||
|
currencyToUuid: params.currencyToUuid
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
const divideRate = isEmptyValue(response.divideRate) ? 1 : response.divideRate
|
||||||
|
if (params.containerUuid === 'Collection') {
|
||||||
|
commit('currencyDivideRateCollection', divideRate)
|
||||||
|
} else {
|
||||||
|
commit('currencyDivideRate', divideRate)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.warn(`conversionDivideRate: ${error.message}. Code: ${error.code}.`)
|
||||||
|
showMessage({
|
||||||
|
type: 'error',
|
||||||
|
message: error.message,
|
||||||
|
showClose: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
conversionMultiplyRate({ commit }, {
|
||||||
|
containerUuid,
|
||||||
|
conversionTypeUuid,
|
||||||
|
currencyFromUuid,
|
||||||
|
currencyToUuid
|
||||||
|
// conversionDate
|
||||||
|
}) {
|
||||||
|
requestGetConversionRate({
|
||||||
|
conversionTypeUuid,
|
||||||
|
currencyFromUuid,
|
||||||
|
currencyToUuid
|
||||||
|
// conversionDate
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
const multiplyRate = isEmptyValue(response.multiplyRate) ? 0 : response.multiplyRate
|
||||||
|
if (containerUuid === 'Collection') {
|
||||||
|
commit('currencyMultiplyRateCollection', multiplyRate)
|
||||||
|
} else {
|
||||||
|
commit('currencyMultiplyRate', multiplyRate)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.warn(`conversionMultiplyRate: ${error.message}. Code: ${error.code}.`)
|
||||||
|
showMessage({
|
||||||
|
type: 'error',
|
||||||
|
message: error.message,
|
||||||
|
showClose: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
changeMultiplyRate({ commit }, params) {
|
||||||
|
commit('currencyMultiplyRate', params)
|
||||||
|
},
|
||||||
|
changeDivideRate({ commit }, divideRate) {
|
||||||
|
commit('currencyDivideRate', divideRate)
|
||||||
|
},
|
||||||
|
createPayments({ dispatch, state, getters }, {
|
||||||
|
posUuid,
|
||||||
|
orderUuid,
|
||||||
|
invoiceUuid,
|
||||||
|
bankUuid,
|
||||||
|
referenceNo,
|
||||||
|
description,
|
||||||
|
amount,
|
||||||
|
paymentDate,
|
||||||
|
tenderTypeCode,
|
||||||
|
currencyUuid
|
||||||
|
}) {
|
||||||
|
const listPayments = getters.getListPayments.find(payment => {
|
||||||
|
if ((payment.tenderTypeCode === tenderTypeCode) && (payment.tenderTypeCode === 'X') && (currencyUuid === payment.currencyUuid)) {
|
||||||
|
return payment
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
})
|
||||||
|
if (isEmptyValue(listPayments)) {
|
||||||
|
requestCreatePayment({
|
||||||
|
posUuid,
|
||||||
|
orderUuid,
|
||||||
|
invoiceUuid,
|
||||||
|
bankUuid,
|
||||||
|
referenceNo,
|
||||||
|
description,
|
||||||
|
amount,
|
||||||
|
paymentDate,
|
||||||
|
tenderTypeCode,
|
||||||
|
currencyUuid
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
const orderUuid = response.order_uuid
|
||||||
|
dispatch('listPayments', { orderUuid })
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
|
||||||
|
showMessage({
|
||||||
|
type: 'error',
|
||||||
|
message: error.message,
|
||||||
|
showClose: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
requestUpdatePayment({
|
||||||
|
paymentUuid: listPayments.uuid,
|
||||||
|
bankUuid,
|
||||||
|
referenceNo,
|
||||||
|
description,
|
||||||
|
amount: listPayments.amount + amount,
|
||||||
|
paymentDate,
|
||||||
|
tenderTypeCode
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
const orderUuid = response.order_uuid
|
||||||
|
dispatch('listPayments', { orderUuid })
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
|
||||||
|
showMessage({
|
||||||
|
type: 'error',
|
||||||
|
message: error.message,
|
||||||
|
showClose: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deletetPayments({ dispatch }, {
|
||||||
|
orderUuid,
|
||||||
|
paymentUuid
|
||||||
|
}) {
|
||||||
|
requestDeletePayment({
|
||||||
|
paymentUuid
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
dispatch('listPayments', { orderUuid })
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
|
||||||
|
showMessage({
|
||||||
|
type: 'error',
|
||||||
|
message: error.message,
|
||||||
|
showClose: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
listPayments({ commit, rootGetters }, { posUuid, orderUuid }) {
|
||||||
|
requestListPayments({
|
||||||
|
posUuid,
|
||||||
|
orderUuid
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
commit('setListPayments', response.listPayments)
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.warn(`ListPaymentsFromServer: ${error.message}. Code: ${error.code}.`)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
tenderTypeDisplaye({ commit }, tenderType) {
|
||||||
|
const displayTenderType = tenderType.map(item => {
|
||||||
|
return {
|
||||||
|
tenderTypeCode: item.id,
|
||||||
|
tenderTypeDisplay: item.label
|
||||||
|
}
|
||||||
|
})
|
||||||
|
commit('setTenderTypeDisplaye', displayTenderType)
|
||||||
|
},
|
||||||
|
currencyDisplaye({ commit }, currency) {
|
||||||
|
const displaycurrency = currency.map(item => {
|
||||||
|
return {
|
||||||
|
currencyUuid: item.uuid,
|
||||||
|
currencyId: item.id,
|
||||||
|
currencyDisplay: item.label
|
||||||
|
}
|
||||||
|
})
|
||||||
|
commit('setCurrencyDisplaye', displaycurrency)
|
||||||
|
},
|
||||||
|
convertionPayment({ commit }, {
|
||||||
|
conversionTypeUuid,
|
||||||
|
currencyFromUuid,
|
||||||
|
currencyToUuid
|
||||||
|
}) {
|
||||||
|
requestGetConversionRate({
|
||||||
|
conversionTypeUuid,
|
||||||
|
currencyFromUuid,
|
||||||
|
currencyToUuid
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
commit('setConvertionPayment', response)
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.warn(`ConvertionPayment: ${error.message}. Code: ${error.code}.`)
|
||||||
|
showMessage({
|
||||||
|
type: 'error',
|
||||||
|
message: error.message,
|
||||||
|
showClose: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
36
src/store/modules/ADempiere/pointOfSales/payments/getters.js
Normal file
36
src/store/modules/ADempiere/pointOfSales/payments/getters.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* Payments Getters
|
||||||
|
* @author Elsio Sanchez <elsiosanches@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default {
|
||||||
|
getPaymentBox: (state) => {
|
||||||
|
console.log({ state })
|
||||||
|
return state
|
||||||
|
},
|
||||||
|
getMultiplyRate: (state) => {
|
||||||
|
return state.multiplyRate
|
||||||
|
},
|
||||||
|
getDivideRate: (state) => {
|
||||||
|
return state.divideRate
|
||||||
|
},
|
||||||
|
getMultiplyRateCollection: (state) => {
|
||||||
|
return state.multiplyRateCollection
|
||||||
|
},
|
||||||
|
getDivideRateCollection: (state) => {
|
||||||
|
return state.divideRateCollection
|
||||||
|
},
|
||||||
|
getListPayments: (state) => {
|
||||||
|
console.log({ state }, 1)
|
||||||
|
return state.listPayments
|
||||||
|
},
|
||||||
|
getListsPaymentTypes: (state) => {
|
||||||
|
return state.tenderTypeDisplaye
|
||||||
|
},
|
||||||
|
getListCurrency: (state) => {
|
||||||
|
return state.currency
|
||||||
|
},
|
||||||
|
getConvertionPayment: (state) => {
|
||||||
|
return state.convertion
|
||||||
|
}
|
||||||
|
}
|
18
src/store/modules/ADempiere/pointOfSales/payments/index.js
Normal file
18
src/store/modules/ADempiere/pointOfSales/payments/index.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
import state from './state.js'
|
||||||
|
import mutations from './mutations.js'
|
||||||
|
import actions from './actions.js'
|
||||||
|
import getters from './getters.js'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payments Vuex Module
|
||||||
|
* @author Elsio Sanchez <elsiosanches@gmail.com>
|
||||||
|
*/
|
||||||
|
const collection = {
|
||||||
|
state,
|
||||||
|
mutations,
|
||||||
|
actions,
|
||||||
|
getters
|
||||||
|
}
|
||||||
|
|
||||||
|
export default collection
|
@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Payments Mutations
|
||||||
|
* @author Elsio Sanchez <elsiosanches@gmail.com>
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
addPaymentBox(state, paymentBox) {
|
||||||
|
state.paymentBox.push(paymentBox)
|
||||||
|
},
|
||||||
|
currencyMultiplyRate(state, multiplyRate) {
|
||||||
|
state.multiplyRate = multiplyRate
|
||||||
|
},
|
||||||
|
currencyDivideRate(state, divideRate) {
|
||||||
|
state.divideRate = divideRate
|
||||||
|
},
|
||||||
|
currencyMultiplyRateCollection(state, multiplyRateCollection) {
|
||||||
|
state.multiplyRateCollection = multiplyRateCollection
|
||||||
|
},
|
||||||
|
currencyDivideRateCollection(state, divideRateCollection) {
|
||||||
|
state.divideRateCollection = divideRateCollection
|
||||||
|
},
|
||||||
|
setListPayments(state, list) {
|
||||||
|
state.listPayments = list
|
||||||
|
},
|
||||||
|
setTenderTypeDisplaye(state, tenderTypeDisplaye) {
|
||||||
|
state.tenderTypeDisplaye = tenderTypeDisplaye
|
||||||
|
},
|
||||||
|
setCurrencyDisplaye(state, currency) {
|
||||||
|
state.currency = currency
|
||||||
|
},
|
||||||
|
setConvertionPayment(state, convertion) {
|
||||||
|
state.convertion = convertion
|
||||||
|
}
|
||||||
|
}
|
20
src/store/modules/ADempiere/pointOfSales/payments/state.js
Normal file
20
src/store/modules/ADempiere/pointOfSales/payments/state.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* Payment State
|
||||||
|
* @author Elsio Sanchez <elsiosanches@gmail.com>
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
paymentBox: [],
|
||||||
|
multiplyRate: 1,
|
||||||
|
divideRate: 1,
|
||||||
|
multiplyRateCollection: 1,
|
||||||
|
divideRateCollection: 1,
|
||||||
|
listPayments: [],
|
||||||
|
tenderTypeDisplaye: [
|
||||||
|
{
|
||||||
|
tenderTypeCode: 0,
|
||||||
|
tenderTypeDisplay: ''
|
||||||
|
}
|
||||||
|
],
|
||||||
|
currency: [],
|
||||||
|
convertion: {}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user