From 4c49b201441790aebcb345dac5c2c86fdf98b989 Mon Sep 17 00:00:00 2001 From: Elsio Sanchez <45974454+elsiosanchez@users.noreply.github.com> Date: Fri, 23 Apr 2021 18:04:26 -0400 Subject: [PATCH] Converting for payment methods (#749) * Fixes: #736 * minimal changes * minimal changes Co-authored-by: Elsio Sanchez --- .../VPOS/Collection/fieldsListCollection.js | 2 +- .../ADempiere/Form/VPOS/Collection/index.vue | 83 ++++++++++++------- .../Form/VPOS/Collection/typeCollection.vue | 2 +- .../ADempiere/Form/VPOS/Order/index.vue | 48 +++++------ .../ADempiere/Form/VPOS/posMixin.js | 8 +- .../pointOfSales/payments/actions.js | 21 ++++- .../pointOfSales/payments/getters.js | 3 + .../pointOfSales/payments/mutations.js | 13 +++ .../ADempiere/pointOfSales/payments/state.js | 3 +- .../ADempiere/pointOfSales/point/actions.js | 1 + src/utils/ADempiere/apiConverts/core.js | 2 +- src/utils/ADempiere/globalMethods.js | 1 + src/utils/ADempiere/valueUtils.js | 12 +++ 13 files changed, 134 insertions(+), 65 deletions(-) diff --git a/src/components/ADempiere/Form/VPOS/Collection/fieldsListCollection.js b/src/components/ADempiere/Form/VPOS/Collection/fieldsListCollection.js index 54f20dad..7a6c6bfa 100644 --- a/src/components/ADempiere/Form/VPOS/Collection/fieldsListCollection.js +++ b/src/components/ADempiere/Form/VPOS/Collection/fieldsListCollection.js @@ -41,7 +41,7 @@ export default [ size: 24, handleActionKeyPerformed: 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, isMandatory: true } diff --git a/src/components/ADempiere/Form/VPOS/Collection/index.vue b/src/components/ADempiere/Form/VPOS/Collection/index.vue index 1b756054..504fb1ac 100644 --- a/src/components/ADempiere/Form/VPOS/Collection/index.vue +++ b/src/components/ADempiere/Form/VPOS/Collection/index.vue @@ -58,6 +58,17 @@

+

+ Tasa del Día: + + {{ + dateRate.iSOCode + }} + {{ + formatConversionCurrenty(dateRate.amountConvertion) + }} + +

import formMixin from '@/components/ADempiere/Form/formMixin' +import posMixin from '@/components/ADempiere/Form/VPOS/posMixin.js' import fieldsListCollection from './fieldsListCollection.js' import typeCollection from '@/components/ADempiere/Form/VPOS/Collection/typeCollection' import convertAmount from '@/components/ADempiere/Form/VPOS/Collection/convertAmount/index' import { formatDate, formatPrice } from '@/utils/ADempiere/valueFormat.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 { name: 'Collection', @@ -381,7 +393,7 @@ export default { return missing } const pending = this.currentOrder.grandTotal <= this.pay ? 0 : this.currentOrder.grandTotal - return pending / this.convertion + return pending }, convertion() { return this.$store.getters.getDivideRateCollection @@ -437,12 +449,6 @@ export default { multiplyRateCollection() { return this.$store.getters.getMultiplyRateCollection }, - converCurrency() { - return this.$store.getters.getValueOfField({ - containerUuid: 'Collection', - columnName: 'C_Currency_ID_UUID' - }) - }, divideRate() { return this.$store.getters.getDivideRate }, @@ -468,8 +474,12 @@ export default { updateOrderPaymentPos() { return this.$store.getters.getUpdatePaymentPos }, - currentPointOfSales() { - return this.$store.getters.posAttributes.currentPointOfSales + dateRate() { + return this.$store.getters.getConvertionRate.find(currency => { + if (currency.id === this.typeCurrency) { + return currency + } + }) } }, watch: { @@ -481,22 +491,18 @@ export default { }) }, 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', { conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, currencyFromUuid: this.pointOfSalesCurrency.uuid, 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) { if (!this.isEmptyValue(value)) { @@ -504,18 +510,6 @@ export default { } 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) { if (value) { this.$store.commit('updateValueOfField', { @@ -524,14 +518,39 @@ export default { 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() { + console.log(this.$store.getters.getConvertionRate) + this.$store.dispatch('addRateConvertion', this.pointOfSalesCurrency) this.unsubscribe = this.subscribeChanges() this.defaultValueCurrency() }, methods: { 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, sumCash(cash) { let sum = 0 diff --git a/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue b/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue index 6d76fa85..a5baa5f8 100644 --- a/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue +++ b/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue @@ -161,7 +161,7 @@ export default { }) .then(response => { 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.currencyConvertion = response.currencyTo } else { diff --git a/src/components/ADempiere/Form/VPOS/Order/index.vue b/src/components/ADempiere/Form/VPOS/Order/index.vue index 2ef6b65c..2f33894b 100644 --- a/src/components/ADempiere/Form/VPOS/Order/index.vue +++ b/src/components/ADempiere/Form/VPOS/Order/index.vue @@ -253,7 +253,7 @@

- +

{{ $t('form.pos.order.order') }}: {{ currentOrder.documentNo }}

{{ $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') } }, - watch: { - currencyUuid(value) { - if (!this.isEmptyValue(value) && !this.isEmptyValue(this.currentPointOfSales)) { - this.$store.dispatch('conversionDivideRate', { - conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, - currencyFromUuid: this.pointOfSalesCurrency.uuid, - currencyToUuid: value - }) - } - }, - converCurrency(value) { - if (!this.isEmptyValue(value) && !this.isEmptyValue(this.currentPointOfSales)) { - this.$store.dispatch('conversionMultiplyRate', { - containerUuid: 'Order', - conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, - currencyFromUuid: this.pointOfSalesCurrency.uuid, - currencyToUuid: value - }) - } else { - this.$store.commit('currencyMultiplyRate', 1) - } - } - }, + // watch: { + // currencyUuid(value) { + // if (!this.isEmptyValue(value) && !this.isEmptyValue(this.currentPointOfSales)) { + // this.$store.dispatch('conversionDivideRate', { + // conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, + // currencyFromUuid: this.pointOfSalesCurrency.uuid, + // currencyToUuid: value + // }) + // } + // }, + // converCurrency(value) { + // if (!this.isEmptyValue(value) && !this.isEmptyValue(this.currentPointOfSales)) { + // this.$store.dispatch('conversionMultiplyRate', { + // containerUuid: 'Order', + // conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, + // currencyFromUuid: this.pointOfSalesCurrency.uuid, + // currencyToUuid: value + // }) + // } else { + // this.$store.commit('currencyMultiplyRate', 1) + // } + // } + // }, mounted() { if (!this.isEmptyValue(this.$route.query.action)) { this.$store.dispatch('reloadOrder', { orderUuid: this.$route.query.action }) diff --git a/src/components/ADempiere/Form/VPOS/posMixin.js b/src/components/ADempiere/Form/VPOS/posMixin.js index 4d1ceed6..dc7691fe 100644 --- a/src/components/ADempiere/Form/VPOS/posMixin.js +++ b/src/components/ADempiere/Form/VPOS/posMixin.js @@ -82,12 +82,16 @@ export default { pointOfSalesCurrency() { // const currency = this.currentPointOfSales if (!this.isEmptyValue(this.currentPointOfSales.priceList)) { - return this.currentPointOfSales.priceList.currency + return { + ...this.currentPointOfSales.priceList.currency, + amountConvertion: 1 + } } return { uuid: '', iSOCode: '', - curSymbol: '' + curSymbol: '', + amountConvertion: 1 } }, listPointOfSales() { diff --git a/src/store/modules/ADempiere/pointOfSales/payments/actions.js b/src/store/modules/ADempiere/pointOfSales/payments/actions.js index d4f5a175..0191b2fb 100644 --- a/src/store/modules/ADempiere/pointOfSales/payments/actions.js +++ b/src/store/modules/ADempiere/pointOfSales/payments/actions.js @@ -111,18 +111,30 @@ export default { const payment = state.paymentBox payment.splice(0) }, - conversionDivideRate({ commit }, params) { + conversionDivideRate({ commit, dispatch }, params) { + console.log('conversionDivideRate') requestGetConversionRate({ conversionTypeUuid: params.conversionTypeUuid, currencyFromUuid: params.currencyFromUuid, - currencyToUuid: params.currencyToUuid + currencyToUuid: params.currencyToUuid, + conversionDate: params.conversionDate }) .then(response => { 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 multiplyRate = isEmptyValue(response.multiplyRate) ? 1 : response.multiplyRate if (params.containerUuid === 'Collection') { + commit('currencyMultiplyRateCollection', multiplyRate) commit('currencyDivideRateCollection', divideRate) } else { + commit('currencyMultiplyRate', multiplyRate) commit('currencyDivideRateCollection', divideRate) } }) @@ -135,6 +147,9 @@ export default { }) }) }, + addRateConvertion({ commit, state, getters }, currency) { + commit('conversionRate', currency) + }, conversionMultiplyRate({ commit }, { containerUuid, conversionTypeUuid, @@ -149,7 +164,7 @@ export default { // conversionDate }) .then(response => { - const multiplyRate = isEmptyValue(response.multiplyRate) ? 0 : response.multiplyRate + const multiplyRate = isEmptyValue(response.multiplyRate) ? 1 : response.multiplyRate if (containerUuid === 'Collection') { commit('currencyMultiplyRateCollection', multiplyRate) } else { diff --git a/src/store/modules/ADempiere/pointOfSales/payments/getters.js b/src/store/modules/ADempiere/pointOfSales/payments/getters.js index 7c513693..31c5e7d1 100644 --- a/src/store/modules/ADempiere/pointOfSales/payments/getters.js +++ b/src/store/modules/ADempiere/pointOfSales/payments/getters.js @@ -45,5 +45,8 @@ export default { }, getFieldCuerrency: (state) => { return state.fieldCurrency + }, + getConvertionRate: (state) => { + return state.convertionRate } } diff --git a/src/store/modules/ADempiere/pointOfSales/payments/mutations.js b/src/store/modules/ADempiere/pointOfSales/payments/mutations.js index 1b77ce17..d92ce0ed 100644 --- a/src/store/modules/ADempiere/pointOfSales/payments/mutations.js +++ b/src/store/modules/ADempiere/pointOfSales/payments/mutations.js @@ -42,6 +42,19 @@ export default { setConvertionPayment(state, 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) { state.fieldCurrency = currency } diff --git a/src/store/modules/ADempiere/pointOfSales/payments/state.js b/src/store/modules/ADempiere/pointOfSales/payments/state.js index c320d3df..70f935ea 100644 --- a/src/store/modules/ADempiere/pointOfSales/payments/state.js +++ b/src/store/modules/ADempiere/pointOfSales/payments/state.js @@ -29,5 +29,6 @@ export default { }, currency: [], convertion: {}, - fieldCurrency: {} + fieldCurrency: {}, + convertionRate: [] } diff --git a/src/store/modules/ADempiere/pointOfSales/point/actions.js b/src/store/modules/ADempiere/pointOfSales/point/actions.js index 72b5fd78..c31a6ec7 100644 --- a/src/store/modules/ADempiere/pointOfSales/point/actions.js +++ b/src/store/modules/ADempiere/pointOfSales/point/actions.js @@ -73,6 +73,7 @@ export default { } }, () => {}) + commit('resetConversionRate', []) commit('setIsReloadKeyLayout') commit('setIsReloadProductPrice') commit('setIsReloadListOrders') diff --git a/src/utils/ADempiere/apiConverts/core.js b/src/utils/ADempiere/apiConverts/core.js index 84bf8cda..767811ce 100644 --- a/src/utils/ADempiere/apiConverts/core.js +++ b/src/utils/ADempiere/apiConverts/core.js @@ -157,7 +157,7 @@ export function convertCurrency(currencyToConvert) { id: currencyToConvert.id, uuid: currencyToConvert.uuid, iSOCode: currencyToConvert.iso_code, - curSymbol: currencyToConvert.cur_symbol, + curSymbol: currencyToConvert.currency_symbol, description: currencyToConvert.description, standardPrecision: currencyToConvert.standard_precision, costingPrecision: currencyToConvert.costing_precision diff --git a/src/utils/ADempiere/globalMethods.js b/src/utils/ADempiere/globalMethods.js index a2bd7bdc..df423dc7 100644 --- a/src/utils/ADempiere/globalMethods.js +++ b/src/utils/ADempiere/globalMethods.js @@ -23,5 +23,6 @@ export { clearVariables, currencyFind, tenderTypeFind, + formatConversionCurrenty, typeValue } from '@/utils/ADempiere/valueUtils.js' diff --git a/src/utils/ADempiere/valueUtils.js b/src/utils/ADempiere/valueUtils.js index 373e2007..7ed18b4e 100644 --- a/src/utils/ADempiere/valueUtils.js +++ b/src/utils/ADempiere/valueUtils.js @@ -546,3 +546,15 @@ export function tenderTypeFind({ export function clearVariables() { 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 +}