From 6f4fc11780f2cf01a8135606d77b400dec861a42 Mon Sep 17 00:00:00 2001 From: Elsio Sanchez <45974454+elsiosanchez@users.noreply.github.com> Date: Fri, 5 Feb 2021 17:15:22 -0400 Subject: [PATCH] upload orders to the server (#579) * upload orders to the server * support convert currency * support for currency search, payment types and undoing payment * change icon --- .../Form/VPOS/BusinessPartner/index.vue | 54 ++++---- .../VPOS/Collection/fieldsListCollection.js | 28 ++--- .../ADempiere/Form/VPOS/Collection/index.vue | 117 ++++++++++++------ .../Form/VPOS/Collection/typeCollection.vue | 74 ++++++++--- .../Form/VPOS/Order/fieldsListOrder.js | 34 +++++ .../ADempiere/Form/VPOS/Order/index.vue | 40 +++++- .../Form/VPOS/OrderList/fieldsListOrders.js | 13 +- .../ADempiere/pointOfSales/collection.js | 93 ++++++++++++-- src/utils/ADempiere/globalMethods.js | 2 + src/utils/ADempiere/valueUtils.js | 49 +++++++- 10 files changed, 391 insertions(+), 113 deletions(-) diff --git a/src/components/ADempiere/Form/VPOS/BusinessPartner/index.vue b/src/components/ADempiere/Form/VPOS/BusinessPartner/index.vue index 04192607..9c98e444 100644 --- a/src/components/ADempiere/Form/VPOS/BusinessPartner/index.vue +++ b/src/components/ADempiere/Form/VPOS/BusinessPartner/index.vue @@ -1,33 +1,5 @@ diff --git a/src/components/ADempiere/Form/VPOS/Collection/fieldsListCollection.js b/src/components/ADempiere/Form/VPOS/Collection/fieldsListCollection.js index b2cbe7ef..f34ea1a5 100644 --- a/src/components/ADempiere/Form/VPOS/Collection/fieldsListCollection.js +++ b/src/components/ADempiere/Form/VPOS/Collection/fieldsListCollection.js @@ -15,6 +15,20 @@ export default [ isMandatory: true } }, + // Currency + { + tableName: 'C_Order', + columnName: 'C_Currency_ID', + isFromDictionary: true, + overwriteDefinition: { + size: 24, + handleActionKeyPerformed: true, + handleActionPerformed: true, + validationCode: 'C_Currency.C_Currency_ID = 100', + isActiveLogics: true, + isMandatory: true + } + }, // TenderType { tableName, @@ -64,20 +78,6 @@ export default [ isMandatory: true } }, - // Currency - { - tableName: 'C_Order', - columnName: 'C_Currency_ID', - isFromDictionary: true, - overwriteDefinition: { - size: 24, - handleActionKeyPerformed: true, - handleActionPerformed: true, - validationCode: 'C_Currency.C_Currency_ID = 100', - isActiveLogics: true, - isMandatory: true - } - }, // ReferenceNo { tableName: 'HR_Attribute', diff --git a/src/components/ADempiere/Form/VPOS/Collection/index.vue b/src/components/ADempiere/Form/VPOS/Collection/index.vue index 2c741ca7..b35b70ee 100644 --- a/src/components/ADempiere/Form/VPOS/Collection/index.vue +++ b/src/components/ADempiere/Form/VPOS/Collection/index.vue @@ -63,17 +63,8 @@ - - - - {{ $t('form.pos.collect.fullPayment') }} - - - + @@ -228,7 +219,9 @@ export default { allPayCurrency: 0, labelTenderType: '', defaultLabel: '', - fieldsList: fieldsListCollection + fieldsList: fieldsListCollection, + sendToServer: false, + amontSend: 0 } }, computed: { @@ -265,7 +258,12 @@ export default { return false }, listPayments() { - return this.$store.getters.getListPayments + const listLocal = this.$store.getters.getPaymentBox + const listServer = this.$store.getters.getListPayments + if (!this.sendToServer) { + return listServer.reverse() + } + return listLocal }, paymentBox() { const payment = this.isPaymentBox.filter(pay => { @@ -451,7 +449,13 @@ export default { return true }, fieldpending() { - return this.pending * this.multiplyRateCollection + return this.pending + }, + displayCurrency() { + return this.$store.getters.getListCurrency + }, + convert() { + return this.$store.getters.getConvertionPayment } }, watch: { @@ -522,7 +526,7 @@ export default { }, mounted() { setTimeout(() => { - this.tenderTypeDisplaye() + this.convertCurrency() }, 1000) }, methods: { @@ -547,7 +551,7 @@ export default { containerUuid, columnName: 'C_Bank_ID_UUID' }) - const amount = this.$store.getters.getValueOfField({ + this.amontSend = this.$store.getters.getValueOfField({ containerUuid, columnName: 'PayAmt' }) @@ -567,19 +571,46 @@ export default { containerUuid, columnName: 'C_Currency_ID_UUID' }) - - this.$store.dispatch('createPayments', { - posUuid, - orderUuid, - bankUuid, - referenceNo, - amount, - paymentDate, - tenderTypeCode, - currencyUuid + const currencyId = this.$store.getters.getValueOfField({ + containerUuid, + columnName: 'C_Currency_ID' }) + const currencyToPay = this.isEmptyValue(currencyUuid) ? currencyId : currencyUuid + if (this.currencyDisplay(currencyToPay).currencyUuid !== this.currencyPoint.uuid) { + this.amontSend = this.convert.divideRate * this.amontSend + } + if (this.sendToServer) { + this.$store.dispatch('setPaymentBox', { + posUuid, + orderUuid, + bankUuid, + referenceNo, + amount: this.amontSend, + paymentDate, + tenderTypeCode, + currencyUuid + }) + } else { + this.$store.dispatch('createPayments', { + posUuid, + orderUuid, + bankUuid, + referenceNo, + amount: this.amontSend, + paymentDate, + tenderTypeCode, + currencyUuid: this.currencyDisplay(currencyToPay).currencyUuid + }) + } + this.amontSend = 0 this.addCollect() }, + updateServer(listPaymentsLocal) { + // const listLocal = this.$store.getters.getPaymentBox + const posUuid = this.$store.getters.getCurrentPOS.uuid + const orderUuid = this.$route.query.action + this.$store.dispatch('uploadOrdersToServer', { listPaymentsLocal, posUuid, orderUuid }) + }, addCollect() { this.fieldsList.forEach(element => { if (element.columnName !== 'PayAmt') { @@ -693,17 +724,33 @@ export default { value: this.$t('form.pos.collect.TenderType.cash') }) }, - tenderTypeDisplaye() { - if (!this.isEmptyValue(this.fieldsList)) { - const tenderType = this.fieldsList[1].reference - this.$store.dispatch('getLookupListFromServer', { - tableName: tenderType.tableName, - query: tenderType.query - }) - .then(response => { - this.$store.dispatch('tenderTypeDisplaye', response) - }) + currencyDisplay(currency) { + const display = this.displayCurrency.find(item => { + if (item.currencyUuid === currency || (item.currencyId === currency)) { + return item + } + }) + if (display) { + return display } + return currency + }, + convertCurrency() { + const convertCurrency = this.currencyDisplay(100) + this.$store.dispatch('convertionPayment', { + conversionTypeUuid: this.$store.getters.getCurrentPOS.conversionTypeUuid, + currencyFromUuid: this.currencyPoint.uuid, + currencyToUuid: convertCurrency.currencyUuid + }) + }, + undoPatment() { + const list = this.listPayments[this.listPayments.length - 1] + const orderUuid = list.orderUuid + const paymentUuid = list.uuid + this.$store.dispatch('deletetPayments', { + orderUuid, + paymentUuid + }) }, subscribeChanges() { return this.$store.subscribe((mutation, state) => { diff --git a/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue b/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue index f613a2b1..d2d3b6ad 100644 --- a/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue +++ b/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue @@ -18,7 +18,14 @@ />
- {{ tenderTypeDisplay(value.tenderTypeCode) }} + + {{ + tenderTypeFind({ + currentPayment: value.tenderTypeCode, + listTypePayment: typesPayment + }) + }} +
{{ formatDate(value.paymentDate) }} - -
-

- +

+

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


-

- - {{ formatPrice(value.quantityCahs) }} +

+ + {{ + formatPrice( + (amountConvertion(value)), + currencyFind({ + currencyCurrent: value.currencyUuid, + listCurrency: listCurrency, + defaultCurrency: currency + }).currencyDisplay + ) + }} + +

+
+
+

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

@@ -81,9 +112,20 @@ export default { default: undefined } }, + data() { + return { + conevertion: 0 + } + }, computed: { - label() { - return this.$store.getters.getTenderTypeDisplaye + typesPayment() { + return this.$store.getters.getListsPaymentTypes + }, + listCurrency() { + return this.$store.getters.getListCurrency + }, + conevertionAmount() { + return this.$store.getters.getConvertionPayment } }, methods: { @@ -139,16 +181,8 @@ export default { paymentUuid }) }, - tenderTypeDisplay(payments) { - const display = this.label.find(item => { - if (item.tenderTypeCode === payments) { - return item.tenderTypeDisplay - } - }) - if (display) { - return display.tenderTypeDisplay - } - return payments + amountConvertion(payment) { + return payment.amount * this.conevertionAmount.multiplyRate } } } diff --git a/src/components/ADempiere/Form/VPOS/Order/fieldsListOrder.js b/src/components/ADempiere/Form/VPOS/Order/fieldsListOrder.js index e30b95a1..25d0e354 100644 --- a/src/components/ADempiere/Form/VPOS/Order/fieldsListOrder.js +++ b/src/components/ADempiere/Form/VPOS/Order/fieldsListOrder.js @@ -3,10 +3,12 @@ export default [ { elementColumnName: 'ProductValue', columnName: 'ProductValue', + tabindex: '1', isFromDictionary: true, overwriteDefinition: { size: 24, sequence: 10, + handleFocusGained: true, handleActionPerformed: true, handleActionKeyPerformed: true } @@ -14,6 +16,7 @@ export default [ { elementColumnName: 'QtyEntered', columnName: 'QtyEntered', + tabindex: '2', isFromDictionary: true, overwriteDefinition: { size: 24, @@ -26,6 +29,7 @@ export default [ { elementColumnName: 'PriceEntered', columnName: 'PriceEntered', + tabindex: '3', isFromDictionary: true, overwriteDefinition: { size: 24, @@ -39,6 +43,7 @@ export default [ { elementColumnName: 'Discount', columnName: 'Discount', + tabindex: '4', isFromDictionary: true, overwriteDefinition: { size: 24, @@ -48,5 +53,34 @@ export default [ handleContentSelection: true, handleActionKeyPerformed: true } + }, + { + tableName: 'C_Order', + columnName: 'C_Currency_ID', + isFromDictionary: true, + overwriteDefinition: { + size: 24, + handleActionKeyPerformed: true, + handleActionPerformed: true, + validationCode: 'C_Currency.C_Currency_ID = 100', + isActiveLogics: false, + isMandatory: true + } + }, + // TenderType + { + tableName: 'C_Payment', + elementColumnName: 'TenderType', + columnName: 'TenderType', + isFromDictionary: true, + overwriteDefinition: { + defaultValue: 'X', + handleActionKeyPerformed: true, + handleContentSelection: true, + handleActionPerformed: true, + size: 24, + isActiveLogics: false, + isMandatory: true + } } ] diff --git a/src/components/ADempiere/Form/VPOS/Order/index.vue b/src/components/ADempiere/Form/VPOS/Order/index.vue index 128ef4c4..972cdee9 100644 --- a/src/components/ADempiere/Form/VPOS/Order/index.vue +++ b/src/components/ADempiere/Form/VPOS/Order/index.vue @@ -84,7 +84,7 @@ - + - - {{ $t('form.productInfo.productInformation') }} + + {{ $t('form.productInfo.productInformation') }} - + - {{ $t('form.pos.tableProduct.editQuantities') }} + {{ $t('form.pos.tableProduct.editQuantities') }} @@ -444,6 +444,12 @@ export default { } } }, + mounted() { + setTimeout(() => { + this.tenderTypeDisplaye() + this.currencyDisplaye() + }, 1500) + }, methods: { changePos(posElement) { this.$store.dispatch('setCurrentPOS', posElement) @@ -503,6 +509,30 @@ export default { if (!this.seeConversion) { this.seeConversion = true } + }, + tenderTypeDisplaye() { + if (!this.isEmptyValue(this.fieldsList)) { + const tenderType = this.fieldsList[5].reference + this.$store.dispatch('getLookupListFromServer', { + tableName: tenderType.tableName, + query: tenderType.query + }) + .then(response => { + this.$store.dispatch('tenderTypeDisplaye', response) + }) + } + }, + currencyDisplaye() { + if (!this.isEmptyValue(this.fieldsList)) { + const currency = this.fieldsList[4].reference + this.$store.dispatch('getLookupListFromServer', { + tableName: currency.tableName, + query: currency.query + }) + .then(response => { + this.$store.dispatch('currencyDisplaye', response) + }) + } } } } diff --git a/src/components/ADempiere/Form/VPOS/OrderList/fieldsListOrders.js b/src/components/ADempiere/Form/VPOS/OrderList/fieldsListOrders.js index d79bd21b..7e9e1d9f 100644 --- a/src/components/ADempiere/Form/VPOS/OrderList/fieldsListOrders.js +++ b/src/components/ADempiere/Form/VPOS/OrderList/fieldsListOrders.js @@ -3,6 +3,7 @@ const tableName = 'C_Order' export default [ { tableName, + elementColumnName: 'DocumentNo', columnName: 'DocumentNo', isFromDictionary: true, overwriteDefinition: { @@ -12,6 +13,7 @@ export default [ }, { tableName, + elementColumnName: 'C_BPartner_ID', columnName: 'C_BPartner_ID', isFromDictionary: true, overwriteDefinition: { @@ -22,6 +24,7 @@ export default [ { tableName, columnName: 'GrandTotal', + elementColumnName: 'GrandTotal', isFromDictionary: true, overwriteDefinition: { size: 8, @@ -48,7 +51,7 @@ export default [ }, { tableName, - columnName: 'Processed', + elementColumnName: 'Processed', isFromDictionary: true, overwriteDefinition: { size: 8, @@ -66,7 +69,8 @@ export default [ }, { tableName, - columnName: 'IsInvoiced', + elementColumnName: 'IsInvoiced', + columnName: 'IsInvoiced ', isFromDictionary: true, overwriteDefinition: { size: 8, @@ -75,6 +79,7 @@ export default [ }, { tableName, + elementColumnName: 'DateOrdered', columnName: 'DateOrdered', isFromDictionary: true, overwriteDefinition: { @@ -85,7 +90,8 @@ export default [ }, { tableName, - columnName: 'DateOrdered', + elementColumnName: 'DateOrdered', + columnName: 'DateOrderedTo', isFromDictionary: true, overwriteDefinition: { columnName: 'DateOrderedTo', @@ -95,6 +101,7 @@ export default [ }, { tableName, + elementColumnName: 'SalesRep_ID', columnName: 'SalesRep_ID', isFromDictionary: true, overwriteDefinition: { diff --git a/src/store/modules/ADempiere/pointOfSales/collection.js b/src/store/modules/ADempiere/pointOfSales/collection.js index 4de91a49..f5ac4cea 100644 --- a/src/store/modules/ADempiere/pointOfSales/collection.js +++ b/src/store/modules/ADempiere/pointOfSales/collection.js @@ -17,7 +17,14 @@ const collection = { multiplyRateCollection: 1, divideRateCollection: 1, listPayments: [], - tenderTypeDisplaye: [] + tenderTypeDisplaye: [ + { + tenderTypeCode: 0, + tenderTypeDisplay: '' + } + ], + currency: [], + convertion: {} }, mutations: { addPaymentBox(state, paymentBox) { @@ -40,6 +47,12 @@ const collection = { }, setTenderTypeDisplaye(state, tenderTypeDisplaye) { state.tenderTypeDisplaye = tenderTypeDisplaye + }, + setCurrencyDisplaye(state, currency) { + state.currency = currency + }, + setConvertionPayment(state, convertion) { + state.convertion = convertion } }, actions: { @@ -86,6 +99,38 @@ const collection = { 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) @@ -224,12 +269,10 @@ const collection = { orderUuid, paymentUuid }) { - console.log(paymentUuid, orderUuid) requestDeletePayment({ paymentUuid }) .then(response => { - console.log(response.listPayments) dispatch('listPayments', { orderUuid }) }) .catch(error => { @@ -241,13 +284,12 @@ const collection = { }) }) }, - listPayments({ commit }, { posUuid, orderUuid }) { + listPayments({ commit, rootGetters }, { posUuid, orderUuid }) { requestListPayments({ posUuid, orderUuid }) .then(response => { - console.log(response.listPayments) commit('setListPayments', response.listPayments) }) .catch(error => { @@ -267,6 +309,38 @@ const collection = { } }) 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: { @@ -286,11 +360,16 @@ const collection = { return state.divideRateCollection }, getListPayments: (state) => { - console.log(state.listPayments) return state.listPayments }, - getTenderTypeDisplaye: (state) => { + getListsPaymentTypes: (state) => { return state.tenderTypeDisplaye + }, + getListCurrency: (state) => { + return state.currency + }, + getConvertionPayment: (state) => { + return state.convertion } } } diff --git a/src/utils/ADempiere/globalMethods.js b/src/utils/ADempiere/globalMethods.js index 9a2bd74c..f8ccaa28 100644 --- a/src/utils/ADempiere/globalMethods.js +++ b/src/utils/ADempiere/globalMethods.js @@ -6,5 +6,7 @@ export { isEmptyValue, calculationValue, clearVariables, + currencyFind, + tenderTypeFind, typeValue } from '@/utils/ADempiere/valueUtils.js' diff --git a/src/utils/ADempiere/valueUtils.js b/src/utils/ADempiere/valueUtils.js index c6c3ba95..8cc8a8c7 100644 --- a/src/utils/ADempiere/valueUtils.js +++ b/src/utils/ADempiere/valueUtils.js @@ -251,6 +251,7 @@ export const recursiveTreeSearch = ({ /** * Parsed value to component type + * @author Elsio Sanchez * @param {mixed} value, value to parsed * @param {string} componentPath * @param {number} displayType, reference in ADempiere @@ -358,6 +359,7 @@ export function parsedValueComponent({ /** * add a tab depending on the status of the document + * @author Elsio Sanchez * @param {string} tag, document status key */ export function tagStatus(tag) { @@ -405,7 +407,8 @@ export function tagStatus(tag) { /** * add a tab depending on the status of the document - * @param {string} tag, document status key + * @author Elsio Sanchez + * @param {string} iconElment, icon the Elment */ export function iconStatus(iconElment) { let icon @@ -479,7 +482,51 @@ export function calculationValue(value, event) { } } } +/** + * Search in the currency lists for the current currency + * @author Elsio Sanchez + * @param {string} currencyCurrent current currency to search + * @param {array} listCurrency Currency Listing + * @param {object} currencyCurrent Default Currency + */ +export function currencyFind({ + currencyCurrent, + listCurrency, + defaultCurrency +}) { + if (!isEmptyValue(listCurrency)) { + const currency = listCurrency.find(item => { + if (item.currencyUuid === currencyCurrent) { + return item + } + }) + if (currency) { + return currency + } + } + return defaultCurrency.iSOCode +} +/** + * Search the Payment List for the Current Payment + * @author Elsio Sanchez + * @param {string} currentPayment Current Payment + * @param {array} listTypePayment Payment Type Listings + */ +export function tenderTypeFind({ + currentPayment, + listTypePayment +}) { + const payment = listTypePayment.find(item => { + if (item.tenderTypeCode === currentPayment) { + return item.tenderTypeDisplay + } + }) + if (payment) { + return payment.tenderTypeDisplay + } + return currentPayment +} export function clearVariables() { partialValue = '' }