From a6197f67b23880df5078fb88aeb61604a637d05b Mon Sep 17 00:00:00 2001 From: Elsio Sanchez <45974454+elsiosanchez@users.noreply.github.com> Date: Mon, 16 Aug 2021 17:45:57 -0400 Subject: [PATCH] Amount converted to payment (#1066) * Correcting total amount converted in the payment * minimal changes * delete console Co-authored-by: elsiosanchez --- .../ADempiere/Form/VPOS/Collection/index.vue | 43 +++++++++++++++++-- .../Form/VPOS/Collection/typeCollection.vue | 34 ++++++++++++--- .../ADempiere/Form/VPOS/Options/index.vue | 1 + .../pointOfSales/payments/actions.js | 4 ++ 4 files changed, 72 insertions(+), 10 deletions(-) diff --git a/src/components/ADempiere/Form/VPOS/Collection/index.vue b/src/components/ADempiere/Form/VPOS/Collection/index.vue index 2129db55..58242141 100644 --- a/src/components/ADempiere/Form/VPOS/Collection/index.vue +++ b/src/components/ADempiere/Form/VPOS/Collection/index.vue @@ -633,6 +633,19 @@ export default { query: value.reference.query }) } + }, + listPayments(payment) { + if (!this.isEmptyValue(this.convertionsList)) { + let rate + payment.forEach((pay) => { + rate = this.convertionsList.find(currency => currency.currencyTo.uuid === pay.currencyUuid) + if (!rate) { + if (this.currentPointOfSales.priceList.currency.uuid !== pay.currencyUuid) { + this.searchConversion(pay.currencyUuid) + } + } + }) + } } }, created() { @@ -662,8 +675,9 @@ export default { let sum = 0 if (cash) { cash.forEach((pay) => { + const amount = this.convertAmount(pay.currencyUuid) if (!this.isEmptyValue(pay.divideRate)) { - sum += pay.amountConvertion / pay.divideRate + sum += amount * pay.amount } else { sum += pay.amount } @@ -671,6 +685,18 @@ export default { } return sum }, + convertAmount(currencyUuid) { + const currencyPay = this.convertionsList.find(currency => { + if (!this.isEmptyValue(currency.currencyTo) && currency.currencyTo.uuid === currencyUuid) { + return currency + } + }) + if (!currencyPay) { + return 0 + } + const rate = (currencyPay.divideRate > currencyPay.multiplyRate) ? currencyPay.divideRate : currencyPay.multiplyRate + return rate + }, notSubmitForm(event) { event.preventDefault() return false @@ -699,14 +725,14 @@ export default { containerUuid, columnName: 'ReferenceNo' }) - this.amontSend = this.dayRate.divideRate * this.amontSend if (this.sendToServer) { this.$store.dispatch('setPaymentBox', { posUuid, orderUuid, bankUuid, referenceNo, - amount: this.amontSend * this.convertion, + amount: this.amontSend, + convertedAmount: this.amontSend * this.dayRate.divideRate, paymentDate, tenderTypeCode, currencyUuid: this.dayRate.currencyTo.uuid @@ -717,7 +743,8 @@ export default { orderUuid, bankUuid, referenceNo, - amount: this.amontSend * this.convertion, + amount: this.amontSend, + convertedAmount: this.amontSend * this.dayRate.divideRate, paymentDate, tenderTypeCode, currencyUuid: this.dayRate.currencyTo.uuid @@ -795,6 +822,7 @@ export default { this.currentFieldCurrency = this.pointOfSalesCurrency.iSOCode }, exit() { + this.cancel() this.$store.commit('setShowPOSCollection', false) }, getPriceApplyingDiscount(price, discount) { @@ -948,6 +976,13 @@ export default { if (!this.isEmptyValue(currency) && this.isEmptyValue(convert) && currency.uuid !== this.currentPointOfSales.currentPriceList.currency.uuid) { this.amountConvert(currency) } + }, + searchConversion(value) { + this.$store.dispatch('searchConversion', { + conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, + currencyFromUuid: this.currentPointOfSales.priceList.currency.uuid, + currencyToUuid: value + }) } } } diff --git a/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue b/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue index 4ddbd04f..fcb0a1f7 100644 --- a/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue +++ b/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue @@ -62,20 +62,19 @@ {{ formatDate(value.paymentDate) }}
-

+

- {{ formatPrice(value.amount, currency.iSOCode) }} + {{ amountConvertion(value) }}


-

+

- {{ formatPrice(value.amountConvertion, value.currencyConvertion.iSOCode) }} + {{ formatPrice(value.amount, iSOCode(value)) }}

@@ -155,6 +154,9 @@ export default { // Validate if there is a payment in a different type of currency to the point paymentCurrency() { return this.currentPointOfSales.currentOrder.listPayments.payments.find(pay => pay.currencyUuid !== this.currency.uuid) + }, + convertionsList() { + return this.$store.state['pointOfSales/point/index'].conversionsList } }, watch: { @@ -181,6 +183,26 @@ export default { methods: { formatDate, formatPrice, + iSOCode(value) { + const currencyPay = this.convertionsList.find(currency => currency.currencyTo.uuid === value.currencyUuid) + if (!currencyPay) { + return '' + } + return currencyPay.currencyTo.iSOCode + }, + amountConvertion(value) { + const currencyPay = this.convertionsList.find(currency => currency.currencyTo.uuid === value.currencyUuid) + if (!currencyPay) { + this.$store.dispatch('searchConversion', { + conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, + currencyFromUuid: this.currency.uuid, + currencyToUuid: value.currencyUuid + }) + return this.formatPrice(0) + } + const rate = (currencyPay.divideRate > currencyPay.multiplyRate) ? currencyPay.divideRate : currencyPay.multiplyRate + return this.formatPrice(value.amount * rate, this.currency.iSOCode) + }, // If there are payments in another currency, search for conversion convertingPaymentMethods() { if (!this.isEmptyValue(this.paymentCurrency)) { @@ -193,7 +215,7 @@ export default { this.$store.getters.posAttributes.currentPointOfSales.currentOrder.listPayments.payments.forEach(element => { if (element.currencyUuid !== this.pointOfSalesCurrency.uuid) { element.multiplyRate = element.amount / response.multiplyRate - element.amountConvertion = element.amount / response.divideRate + element.amountConvertion = element.amount * response.divideRate element.divideRate = response.multiplyRate element.currencyConvertion = response.currencyTo } diff --git a/src/components/ADempiere/Form/VPOS/Options/index.vue b/src/components/ADempiere/Form/VPOS/Options/index.vue index 404d8e8f..267bbb54 100644 --- a/src/components/ADempiere/Form/VPOS/Options/index.vue +++ b/src/components/ADempiere/Form/VPOS/Options/index.vue @@ -559,6 +559,7 @@ export default { columnName: 'C_Order_ID', value: this.currentOrder.id }] + this.$store.commit('setShowPOSCollection', false) this.$store.dispatch('addParametersProcessPos', parametersList) createOrder({ posUuid, diff --git a/src/store/modules/ADempiere/pointOfSales/payments/actions.js b/src/store/modules/ADempiere/pointOfSales/payments/actions.js index ad1eea7d..5502f98f 100644 --- a/src/store/modules/ADempiere/pointOfSales/payments/actions.js +++ b/src/store/modules/ADempiere/pointOfSales/payments/actions.js @@ -37,6 +37,7 @@ export default { referenceNo, description, amount, + convertedAmount, paymentDate, tenderTypeCode, currencyUuid @@ -53,6 +54,7 @@ export default { referenceNo, description, amount, + convertedAmount, paymentDate, tenderTypeCode, currencyUuid @@ -185,6 +187,7 @@ export default { referenceNo, description, amount, + convertedAmount, paymentDate, tenderTypeCode, currencyUuid @@ -204,6 +207,7 @@ export default { referenceNo, description, amount, + convertedAmount, paymentDate, tenderTypeCode, currencyUuid