1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-10 12:01:57 +08:00

Converting for payment methods (#749)

* Fixes: #736

* minimal changes

* minimal changes

Co-authored-by: Elsio Sanchez <elsiosanche@gmail.com>
This commit is contained in:
Elsio Sanchez 2021-04-23 18:04:26 -04:00 committed by GitHub
parent 1e42f1ede9
commit 4c49b20144
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 134 additions and 65 deletions

View File

@ -41,7 +41,7 @@ export default [
size: 24, size: 24,
handleActionKeyPerformed: true, handleActionKeyPerformed: true,
handleActionPerformed: true, handleActionPerformed: true,
validationCode: 'C_Currency.C_Currency_ID = 100', validationCode: 'C_Currency.C_Currency_ID = 100 OR C_Currency.C_Currency_ID = 50001',
isActiveLogics: true, isActiveLogics: true,
isMandatory: true isMandatory: true
} }

View File

@ -58,6 +58,17 @@
</el-popover> </el-popover>
</b> </b>
</p> </p>
<p class="total">
<b>Tasa del Día: </b>
<b v-if="!isEmptyValue(dateRate)" style="float: right;">
{{
dateRate.iSOCode
}}
{{
formatConversionCurrenty(dateRate.amountConvertion)
}}
</b>
</p>
</div> </div>
<div <div
v-if="isLoaded" v-if="isLoaded"
@ -200,12 +211,13 @@
<script> <script>
import formMixin from '@/components/ADempiere/Form/formMixin' import formMixin from '@/components/ADempiere/Form/formMixin'
import posMixin from '@/components/ADempiere/Form/VPOS/posMixin.js'
import fieldsListCollection from './fieldsListCollection.js' import fieldsListCollection from './fieldsListCollection.js'
import typeCollection from '@/components/ADempiere/Form/VPOS/Collection/typeCollection' import typeCollection from '@/components/ADempiere/Form/VPOS/Collection/typeCollection'
import convertAmount from '@/components/ADempiere/Form/VPOS/Collection/convertAmount/index' import convertAmount from '@/components/ADempiere/Form/VPOS/Collection/convertAmount/index'
import { formatDate, formatPrice } from '@/utils/ADempiere/valueFormat.js' import { formatDate, formatPrice } from '@/utils/ADempiere/valueFormat.js'
import { processOrder } from '@/api/ADempiere/form/point-of-sales.js' import { processOrder } from '@/api/ADempiere/form/point-of-sales.js'
import posMixin from '@/components/ADempiere/Form/VPOS/posMixin.js' import { FIELDS_DECIMALS } from '@/utils/ADempiere/references'
export default { export default {
name: 'Collection', name: 'Collection',
@ -381,7 +393,7 @@ export default {
return missing return missing
} }
const pending = this.currentOrder.grandTotal <= this.pay ? 0 : this.currentOrder.grandTotal const pending = this.currentOrder.grandTotal <= this.pay ? 0 : this.currentOrder.grandTotal
return pending / this.convertion return pending
}, },
convertion() { convertion() {
return this.$store.getters.getDivideRateCollection return this.$store.getters.getDivideRateCollection
@ -437,12 +449,6 @@ export default {
multiplyRateCollection() { multiplyRateCollection() {
return this.$store.getters.getMultiplyRateCollection return this.$store.getters.getMultiplyRateCollection
}, },
converCurrency() {
return this.$store.getters.getValueOfField({
containerUuid: 'Collection',
columnName: 'C_Currency_ID_UUID'
})
},
divideRate() { divideRate() {
return this.$store.getters.getDivideRate return this.$store.getters.getDivideRate
}, },
@ -468,8 +474,12 @@ export default {
updateOrderPaymentPos() { updateOrderPaymentPos() {
return this.$store.getters.getUpdatePaymentPos return this.$store.getters.getUpdatePaymentPos
}, },
currentPointOfSales() { dateRate() {
return this.$store.getters.posAttributes.currentPointOfSales return this.$store.getters.getConvertionRate.find(currency => {
if (currency.id === this.typeCurrency) {
return currency
}
})
} }
}, },
watch: { watch: {
@ -481,22 +491,18 @@ export default {
}) })
}, },
currencyUuid(value) { currencyUuid(value) {
if (!this.isEmptyValue(value)) { const alo = this.$store.getters.getConvertionRate.find(currency => {
if (currency.uuid === value) {
return currency
}
})
if (alo === undefined) {
this.$store.dispatch('conversionDivideRate', { this.$store.dispatch('conversionDivideRate', {
conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid,
currencyFromUuid: this.pointOfSalesCurrency.uuid, currencyFromUuid: this.pointOfSalesCurrency.uuid,
currencyToUuid: value currencyToUuid: value
}) })
} }
if (this.isEmptyValue(value)) {
this.$store.commit('setFieldCurrency', this.pointOfSalesCurrency)
this.$store.dispatch('conversionDivideRate', {
containerUuid: 'Collection',
conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid,
currencyFromUuid: this.pointOfSalesCurrency.uuid,
currencyToUuid: value
})
}
}, },
convertAllPayment(value) { convertAllPayment(value) {
if (!this.isEmptyValue(value)) { if (!this.isEmptyValue(value)) {
@ -504,18 +510,6 @@ export default {
} }
this.allPayCurrency = this.pay this.allPayCurrency = this.pay
}, },
converCurrency(value) {
if (!this.isEmptyValue(value)) {
this.$store.dispatch('conversionMultiplyRate', {
containerUuid: 'Collection',
conversionTypeUuid: this.currentPointOfSales,
currencyFromUuid: this.pointOfSalesCurrency.uuid,
currencyToUuid: value
})
} else {
this.$store.commit('currencyMultiplyRate', 1)
}
},
isLoaded(value) { isLoaded(value) {
if (value) { if (value) {
this.$store.commit('updateValueOfField', { this.$store.commit('updateValueOfField', {
@ -524,14 +518,39 @@ export default {
value: this.pending value: this.pending
}) })
} }
},
dateRate(value) {
if (value && !this.isEmptyValue(value.amountConvertion)) {
this.$store.commit('updateValueOfField', {
containerUuid: this.containerUuid,
columnName: 'PayAmt',
value: this.pending / value.amountConvertion
})
} else {
this.$store.commit('updateValueOfField', {
containerUuid: this.containerUuid,
columnName: 'PayAmt',
value: this.pending
})
}
} }
}, },
created() { created() {
console.log(this.$store.getters.getConvertionRate)
this.$store.dispatch('addRateConvertion', this.pointOfSalesCurrency)
this.unsubscribe = this.subscribeChanges() this.unsubscribe = this.subscribeChanges()
this.defaultValueCurrency() this.defaultValueCurrency()
}, },
methods: { methods: {
formatDate, formatDate,
formatNumber({ displayType, number }) {
let fixed = 0
// Amount, Costs+Prices, Number
if (FIELDS_DECIMALS.includes(displayType)) {
fixed = 2
}
return new Intl.NumberFormat().format(number.toFixed(fixed))
},
formatPrice, formatPrice,
sumCash(cash) { sumCash(cash) {
let sum = 0 let sum = 0

View File

@ -161,7 +161,7 @@ export default {
}) })
.then(response => { .then(response => {
this.isAddTypePay.forEach(element => { this.isAddTypePay.forEach(element => {
if (element.currencyUuid !== this.$store.getters.getCurrentPOS.priceList.currency.uuid) { if (element.currencyUuid !== this.pointOfSalesCurrency.uuid) {
element.amountConvertion = element.amount / response.divideRate element.amountConvertion = element.amount / response.divideRate
element.currencyConvertion = response.currencyTo element.currencyConvertion = response.currencyTo
} else { } else {

View File

@ -253,7 +253,7 @@
</b> </b>
</p> </p>
</span> </span>
<span style="float: right;padding-right: 40px;"> <span style="float: right;padding-right: 3%;">
<p class="total">{{ $t('form.pos.order.order') }}: <b class="order-info">{{ currentOrder.documentNo }}</b></p> <p class="total">{{ $t('form.pos.order.order') }}: <b class="order-info">{{ currentOrder.documentNo }}</b></p>
<p class="total"> <p class="total">
{{ $t('form.pos.order.date') }}: {{ $t('form.pos.order.date') }}:
@ -395,29 +395,29 @@ export default {
return this.isDisabled ? this.$t('form.pos.order.collections') : this.$t('form.pos.order.collect') return this.isDisabled ? this.$t('form.pos.order.collections') : this.$t('form.pos.order.collect')
} }
}, },
watch: { // watch: {
currencyUuid(value) { // currencyUuid(value) {
if (!this.isEmptyValue(value) && !this.isEmptyValue(this.currentPointOfSales)) { // if (!this.isEmptyValue(value) && !this.isEmptyValue(this.currentPointOfSales)) {
this.$store.dispatch('conversionDivideRate', { // this.$store.dispatch('conversionDivideRate', {
conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, // conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid,
currencyFromUuid: this.pointOfSalesCurrency.uuid, // currencyFromUuid: this.pointOfSalesCurrency.uuid,
currencyToUuid: value // currencyToUuid: value
}) // })
} // }
}, // },
converCurrency(value) { // converCurrency(value) {
if (!this.isEmptyValue(value) && !this.isEmptyValue(this.currentPointOfSales)) { // if (!this.isEmptyValue(value) && !this.isEmptyValue(this.currentPointOfSales)) {
this.$store.dispatch('conversionMultiplyRate', { // this.$store.dispatch('conversionMultiplyRate', {
containerUuid: 'Order', // containerUuid: 'Order',
conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, // conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid,
currencyFromUuid: this.pointOfSalesCurrency.uuid, // currencyFromUuid: this.pointOfSalesCurrency.uuid,
currencyToUuid: value // currencyToUuid: value
}) // })
} else { // } else {
this.$store.commit('currencyMultiplyRate', 1) // this.$store.commit('currencyMultiplyRate', 1)
} // }
} // }
}, // },
mounted() { mounted() {
if (!this.isEmptyValue(this.$route.query.action)) { if (!this.isEmptyValue(this.$route.query.action)) {
this.$store.dispatch('reloadOrder', { orderUuid: this.$route.query.action }) this.$store.dispatch('reloadOrder', { orderUuid: this.$route.query.action })

View File

@ -82,12 +82,16 @@ export default {
pointOfSalesCurrency() { pointOfSalesCurrency() {
// const currency = this.currentPointOfSales // const currency = this.currentPointOfSales
if (!this.isEmptyValue(this.currentPointOfSales.priceList)) { if (!this.isEmptyValue(this.currentPointOfSales.priceList)) {
return this.currentPointOfSales.priceList.currency return {
...this.currentPointOfSales.priceList.currency,
amountConvertion: 1
}
} }
return { return {
uuid: '', uuid: '',
iSOCode: '', iSOCode: '',
curSymbol: '' curSymbol: '',
amountConvertion: 1
} }
}, },
listPointOfSales() { listPointOfSales() {

View File

@ -111,18 +111,30 @@ export default {
const payment = state.paymentBox const payment = state.paymentBox
payment.splice(0) payment.splice(0)
}, },
conversionDivideRate({ commit }, params) { conversionDivideRate({ commit, dispatch }, params) {
console.log('conversionDivideRate')
requestGetConversionRate({ requestGetConversionRate({
conversionTypeUuid: params.conversionTypeUuid, conversionTypeUuid: params.conversionTypeUuid,
currencyFromUuid: params.currencyFromUuid, currencyFromUuid: params.currencyFromUuid,
currencyToUuid: params.currencyToUuid currencyToUuid: params.currencyToUuid,
conversionDate: params.conversionDate
}) })
.then(response => { .then(response => {
commit('setFieldCurrency', response.currencyTo) commit('setFieldCurrency', response.currencyTo)
if (!isEmptyValue(response.currencyTo)) {
const currency = {
...response.currencyTo,
amountConvertion: response.divideRate
}
dispatch('addRateConvertion', currency)
}
const divideRate = isEmptyValue(response.divideRate) ? 1 : response.divideRate const divideRate = isEmptyValue(response.divideRate) ? 1 : response.divideRate
const multiplyRate = isEmptyValue(response.multiplyRate) ? 1 : response.multiplyRate
if (params.containerUuid === 'Collection') { if (params.containerUuid === 'Collection') {
commit('currencyMultiplyRateCollection', multiplyRate)
commit('currencyDivideRateCollection', divideRate) commit('currencyDivideRateCollection', divideRate)
} else { } else {
commit('currencyMultiplyRate', multiplyRate)
commit('currencyDivideRateCollection', divideRate) commit('currencyDivideRateCollection', divideRate)
} }
}) })
@ -135,6 +147,9 @@ export default {
}) })
}) })
}, },
addRateConvertion({ commit, state, getters }, currency) {
commit('conversionRate', currency)
},
conversionMultiplyRate({ commit }, { conversionMultiplyRate({ commit }, {
containerUuid, containerUuid,
conversionTypeUuid, conversionTypeUuid,
@ -149,7 +164,7 @@ export default {
// conversionDate // conversionDate
}) })
.then(response => { .then(response => {
const multiplyRate = isEmptyValue(response.multiplyRate) ? 0 : response.multiplyRate const multiplyRate = isEmptyValue(response.multiplyRate) ? 1 : response.multiplyRate
if (containerUuid === 'Collection') { if (containerUuid === 'Collection') {
commit('currencyMultiplyRateCollection', multiplyRate) commit('currencyMultiplyRateCollection', multiplyRate)
} else { } else {

View File

@ -45,5 +45,8 @@ export default {
}, },
getFieldCuerrency: (state) => { getFieldCuerrency: (state) => {
return state.fieldCurrency return state.fieldCurrency
},
getConvertionRate: (state) => {
return state.convertionRate
} }
} }

View File

@ -42,6 +42,19 @@ export default {
setConvertionPayment(state, convertion) { setConvertionPayment(state, convertion) {
state.convertion = convertion state.convertion = convertion
}, },
conversionRate(state, currency) {
const listCurrent = state.convertionRate.find(element => {
if (element.id === currency.id) {
return element
}
})
if (listCurrent === undefined) {
state.convertionRate.push(currency)
}
},
resetConversionRate(state, currency) {
state.convertionRate = currency
},
setFieldCurrency(state, currency) { setFieldCurrency(state, currency) {
state.fieldCurrency = currency state.fieldCurrency = currency
} }

View File

@ -29,5 +29,6 @@ export default {
}, },
currency: [], currency: [],
convertion: {}, convertion: {},
fieldCurrency: {} fieldCurrency: {},
convertionRate: []
} }

View File

@ -73,6 +73,7 @@ export default {
} }
}, () => {}) }, () => {})
commit('resetConversionRate', [])
commit('setIsReloadKeyLayout') commit('setIsReloadKeyLayout')
commit('setIsReloadProductPrice') commit('setIsReloadProductPrice')
commit('setIsReloadListOrders') commit('setIsReloadListOrders')

View File

@ -157,7 +157,7 @@ export function convertCurrency(currencyToConvert) {
id: currencyToConvert.id, id: currencyToConvert.id,
uuid: currencyToConvert.uuid, uuid: currencyToConvert.uuid,
iSOCode: currencyToConvert.iso_code, iSOCode: currencyToConvert.iso_code,
curSymbol: currencyToConvert.cur_symbol, curSymbol: currencyToConvert.currency_symbol,
description: currencyToConvert.description, description: currencyToConvert.description,
standardPrecision: currencyToConvert.standard_precision, standardPrecision: currencyToConvert.standard_precision,
costingPrecision: currencyToConvert.costing_precision costingPrecision: currencyToConvert.costing_precision

View File

@ -23,5 +23,6 @@ export {
clearVariables, clearVariables,
currencyFind, currencyFind,
tenderTypeFind, tenderTypeFind,
formatConversionCurrenty,
typeValue typeValue
} from '@/utils/ADempiere/valueUtils.js' } from '@/utils/ADempiere/valueUtils.js'

View File

@ -546,3 +546,15 @@ export function tenderTypeFind({
export function clearVariables() { export function clearVariables() {
partialValue = '' partialValue = ''
} }
export function formatConversionCurrenty(params) {
let exponential, expre
const number = params.toString()
if (params > 0) {
if (number.includes('e')) {
expre = number.split('-')
exponential = params.toFixed(expre[1])
return exponential
}
}
return params
}