diff --git a/src/components/ADempiere/Form/VPOS/Collection/index.vue b/src/components/ADempiere/Form/VPOS/Collection/index.vue index 42d12e02..d6a402cd 100644 --- a/src/components/ADempiere/Form/VPOS/Collection/index.vue +++ b/src/components/ADempiere/Form/VPOS/Collection/index.vue @@ -14,11 +14,11 @@ > - {{ formatPrice(order.grandTotal, currencyPoint.iSOCode) }} + {{ formatPrice(currentOrder.grandTotal, currencyPoint.iSOCode) }} @@ -71,18 +71,9 @@ -
@@ -101,11 +92,11 @@ > - {{ formatPrice(order.grandTotal, currencyPoint.iSOCode) }} + {{ formatPrice(currentOrder.grandTotal, currencyPoint.iSOCode) }} @@ -227,19 +218,20 @@ export default { computed: { validateCompleteCollection() { let collection - if (this.pay === this.order.grandTotal) { + if (this.pay === this.currentOrder.grandTotal) { collection = false } else { - if (this.pay >= this.order.grandTotal && (this.isCashAmt >= this.change) || this.checked) { + if (this.pay >= this.currentOrder.grandTotal && (this.isCashAmt >= this.change) || this.checked) { collection = false } else { collection = true } } return collection + // return false }, fullCopper() { - if ((this.change > this.isCashAmt) && this.pay > this.order.grandTotal) { + if ((this.change > this.isCashAmt) && this.pay > this.currentOrder.grandTotal) { return true } return false @@ -312,7 +304,7 @@ export default { }) const allPay = this.cashPayment + amount if (typePay !== 'X') { - if (allPay <= this.order.grandTotal) { + if (allPay <= this.currentOrder.grandTotal) { return false } return true @@ -347,11 +339,11 @@ export default { return this.sumCash(this.listPayments) }, pending() { - const missing = this.order.grandTotal - this.pay - if (this.pay > 0 && this.pay < this.order.grandTotal) { + const missing = this.currentOrder.grandTotal - this.pay + if (this.pay > 0 && this.pay < this.currentOrder.grandTotal) { return missing } - const pending = this.order.grandTotal <= this.pay ? 0 : this.order.grandTotal + const pending = this.currentOrder.grandTotal <= this.pay ? 0 : this.currentOrder.grandTotal return pending }, isMandatory() { @@ -378,15 +370,12 @@ export default { return !this.isEmptyValue(fieldsEmpty) }, change() { - const missing = this.pay - this.order.grandTotal - if (this.pay > 0 && this.pay > this.order.grandTotal) { + const missing = this.pay - this.currentOrder.grandTotal + if (this.pay > 0 && this.pay > this.currentOrder.grandTotal) { return missing } return 0 }, - order() { - return this.$store.getters.getFindOrder - }, currencyPoint() { const currency = this.$store.getters.getCurrentPOS if (!this.isEmptyValue(currency)) { @@ -400,7 +389,7 @@ export default { } }, currentOrder() { - return this.$store.getters.getFindOrder + return this.$store.getters.getOrder }, typeCurrency() { return this.$store.getters.getValueOfField({ diff --git a/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue b/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue index d2d3b6ad..2a28e436 100644 --- a/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue +++ b/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue @@ -110,6 +110,10 @@ export default { currency: { type: Object, default: undefined + }, + listTypesPayment: { + type: Object, + default: undefined } }, data() { @@ -119,6 +123,7 @@ export default { }, computed: { typesPayment() { + console.log(this.$store.getters.getListsPaymentTypes) return this.$store.getters.getListsPaymentTypes }, listCurrency() { @@ -128,6 +133,13 @@ export default { return this.$store.getters.getConvertionPayment } }, + watch: { + listTypesPayment(value) { + if (!this.isEmptyValue(value) && this.typesPayment.length <= 1) { + this.tenderTypeDisplaye(value) + } + } + }, methods: { formatDate, formatPrice, @@ -183,6 +195,21 @@ export default { }, amountConvertion(payment) { return payment.amount * this.conevertionAmount.multiplyRate + }, + tenderTypeDisplaye(value) { + if (!this.isEmptyValue(value.reference)) { + const tenderType = value.reference + if (!this.isEmptyValue(tenderType)) { + this.$store.dispatch('getLookupListFromServer', { + tableName: tenderType.tableName, + query: tenderType.query, + filters: [] + }) + .then(response => { + this.$store.dispatch('tenderTypeDisplaye', response) + }) + } + } } } } diff --git a/src/components/ADempiere/Form/VPOS/Options/index.vue b/src/components/ADempiere/Form/VPOS/Options/index.vue index 3fa7d7a4..e3d8f7b9 100644 --- a/src/components/ADempiere/Form/VPOS/Options/index.vue +++ b/src/components/ADempiere/Form/VPOS/Options/index.vue @@ -354,8 +354,6 @@ export default { this.newOrder() }, newOrder() { - this.$store.dispatch('findOrderServer', {}) - const pos = this.pointOfSalesId || this.$route.query.pos this.$router.push({ params: { @@ -367,7 +365,24 @@ export default { }).catch(error => { console.info(`VPOS/Options component (New Order): ${error.message}`) }).finally(() => { - // const { templateBusinessPartner } = this.currentPOS + const { templateBusinessPartner } = this.$store.getters.getCurrentPOS + // TODO: Set order with POS Terminal default values + this.$store.commit('setListPayments', []) + this.$store.dispatch('setOrder', { + documentType: {}, + documentStatus: { + value: '' + }, + totalLines: 0, + grandTotal: 0, + salesRepresentative: {}, + businessPartner: { + value: '', + uuid: '' + } + }) + this.$store.dispatch('listOrderLine', []) + this.$store.commit('setShowPOSCollection', false) this.$store.commit('updateValuesOfContainer', { containerUuid: this.metadata.containerUuid, attributes: [{ @@ -380,27 +395,17 @@ export default { }, { columnName: 'C_BPartner_ID', - value: 1000006 + value: templateBusinessPartner.id }, { columnName: 'DisplayColumn_C_BPartner_ID', - value: 'Cliente Unico' + value: templateBusinessPartner.name }, { columnName: ' C_BPartner_ID_UUID', - value: '9f6cf428-9209-11e9-8046-0242ac140002' + value: this.$store.getters['user/getUserUuid'] }] }) - - // TODO: Set order with POS Terminal default values - // this.order = { - // documentType: {}, - // documentStatus: {}, - // salesRepresentative: this.currentPOS.salesRepresentative - // - this.$store.commit('setListPayments', []) - this.$store.dispatch('listOrderLine', []) - this.$store.commit('setShowPOSCollection', false) }) }, printOrder() { diff --git a/src/components/ADempiere/Form/VPOS/Order/index.vue b/src/components/ADempiere/Form/VPOS/Order/index.vue index 5093ac56..70f97b00 100644 --- a/src/components/ADempiere/Form/VPOS/Order/index.vue +++ b/src/components/ADempiere/Form/VPOS/Order/index.vue @@ -34,12 +34,12 @@ - + Borrador - {{ order.documentStatus.name }} + {{ getOrder.documentStatus.name }} @@ -232,9 +232,9 @@

{{ $t('form.pos.order.seller') }}: - {{ order.salesRepresentative.name }} + {{ getOrder.salesRepresentative.name }}

-

{{ $t('form.pos.order.subTotal') }}:{{ formatPrice(order.totalLines, currencyPoint.iSOCode) }}

+

{{ $t('form.pos.order.subTotal') }}:{{ formatPrice(getOrder.totalLines, currencyPoint.iSOCode) }}

{{ $t('form.pos.order.discount') }}:{{ formatPrice(0, currencyPoint.iSOCode) }}

{{ $t('form.pos.order.tax') }}:{{ getOrderTax(currencyPoint.iSOCode) }}

@@ -249,25 +249,25 @@ - {{ formatPrice(order.grandTotal, currencyPoint.iSOCode) }} + {{ formatPrice(getOrder.grandTotal, currencyPoint.iSOCode) }}

-

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

+

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

{{ $t('form.pos.order.date') }}: {{ orderDate }}

-

{{ $t('form.pos.order.type') }}:{{ order.documentType.name }}

+

{{ $t('form.pos.order.type') }}:{{ getOrder.documentType.name }}

{{ $t('form.pos.order.itemQuantity') }} @@ -357,19 +357,22 @@ export default { if (currentPOS && !this.isEmptyValue(currentPOS.name)) { return currentPOS } - return undefined + return { + name: '', + uuid: '' + } }, sellingPointsList() { return this.$store.getters.getSellingPointsList }, orderDate() { - if (this.isEmptyValue(this.order) || this.isEmptyValue(this.order.dateOrdered)) { + if (this.isEmptyValue(this.getOrder) || this.isEmptyValue(this.getOrder.dateOrdered)) { return this.formatDate(new Date()) } - return this.formatDate(this.order.dateOrdered) + return this.formatDate(this.getOrder.dateOrdered) }, getItemQuantity() { - if (this.isEmptyValue(this.currentOrder)) { + if (this.isEmptyValue(this.getOrder)) { return 0 } const result = this.allOrderLines.map(order => { @@ -384,7 +387,7 @@ export default { return 0 }, numberOfLines() { - if (this.isEmptyValue(this.currentOrder)) { + if (this.isEmptyValue(this.getOrder)) { return } return this.allOrderLines.length @@ -456,7 +459,6 @@ export default { }, mounted() { setTimeout(() => { - this.tenderTypeDisplaye() this.currencyDisplaye() }, 1500) }, @@ -468,14 +470,12 @@ export default { openCollectionPanel() { this.isShowedPOSKeyLayout = !this.isShowedPOSKeyLayout this.$store.commit('setShowPOSCollection', true) - // this.isShowedPOSKeyLayout = true const orderUuid = this.$route.query.action this.$store.dispatch('listPayments', { orderUuid }) this.isShowedPOSKeyLaout = !this.isShowedPOSKeyLaout this.$store.commit('setShowPOSOptions', false) }, newOrder() { - this.$store.dispatch('findOrderServer', {}) this.$router.push({ params: { ...this.$route.params @@ -486,7 +486,6 @@ export default { }).catch(() => { }).finally(() => { const { templateBusinessPartner } = this.currentPoint - this.$store.commit('updateValuesOfContainer', { containerUuid: this.metadata.containerUuid, attributes: [{ @@ -510,7 +509,19 @@ export default { value: templateBusinessPartner.uuid }] }) - + this.$store.dispatch('setOrder', { + documentType: {}, + documentStatus: { + value: '' + }, + totalLines: 0, + grandTotal: 0, + salesRepresentative: {}, + businessPartner: { + value: '', + uuid: '' + } + }) this.$store.dispatch('listOrderLine', []) }) }, @@ -522,25 +533,29 @@ export default { 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) + if (!this.isEmptyValue(tenderType)) { + 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) + if (!this.isEmptyValue(currency)) { + 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/index.vue b/src/components/ADempiere/Form/VPOS/OrderList/index.vue index eb71a620..e0aa7fa4 100644 --- a/src/components/ADempiere/Form/VPOS/OrderList/index.vue +++ b/src/components/ADempiere/Form/VPOS/OrderList/index.vue @@ -174,7 +174,6 @@ export default { if (!this.isEmptyValue(order)) { return order } - this.$store.dispatch('listOrderLine', []) return null }, isReadyFromGetData() { @@ -201,14 +200,6 @@ export default { this.loadOrdersList() } }, - mounted() { - const listOrder = this.$store.getters.getListOrderLine - if (this.isEmptyValue(listOrder) && !this.isEmptyValue(this.$store.getters.getCurrentPOS.uuid)) { - this.$store.dispatch('listOrdersFromServer', { - posUuid: this.$store.getters.getCurrentPOS.uuid - }) - } - }, beforeDestroy() { this.unsubscribe() }, diff --git a/src/components/ADempiere/Form/VPOS/index.vue b/src/components/ADempiere/Form/VPOS/index.vue index 652097aa..d5f3bee4 100644 --- a/src/components/ADempiere/Form/VPOS/index.vue +++ b/src/components/ADempiere/Form/VPOS/index.vue @@ -123,9 +123,6 @@ export default { } this.unsubscribePOSList = this.posListWithOrganization() - if (!this.isEmptyValue(this.$route.query.action)) { - this.$store.dispatch('findOrderServer', this.$route.query.action) - } }, mounted() { if (this.isEmptyValue(this.$route.query) || this.isEmptyValue(this.$route.query.pos)) { diff --git a/src/components/ADempiere/Form/VPOS/posMixin.js b/src/components/ADempiere/Form/VPOS/posMixin.js index 95aa8e63..f716a553 100644 --- a/src/components/ADempiere/Form/VPOS/posMixin.js +++ b/src/components/ADempiere/Form/VPOS/posMixin.js @@ -1,8 +1,5 @@ import { findProduct, - requestCreateOrder, - requestGetOrder, - requestUpdateOrder, requestUpdateOrderLine } from '@/api/ADempiere/form/point-of-sales.js' import { @@ -10,7 +7,6 @@ import { formatPrice, formatQuantity } from '@/utils/ADempiere/valueFormat.js' -// import posProcess from '@/utils/ADempiere/constants/posProcess' export default { name: 'POSMixin', @@ -23,18 +19,6 @@ export default { data() { return { product: {}, - order: { - documentType: {}, - documentStatus: { - value: '' - }, - totalLines: 0, - grandTotal: 0, - salesRepresentative: {}, - businessPartner: { - value: '' - } - }, currentTable: 0, currentOrderLine: { product: { @@ -57,9 +41,6 @@ export default { }, computed: { allOrderLines() { - if (this.isEmptyValue(this.listOrderLine)) { - return [] - } return this.listOrderLine }, listOrderLine() { @@ -75,10 +56,7 @@ export default { currentOrder() { const action = this.$route.query.action if (!this.isEmptyValue(action)) { - const order = this.ordersList.find(item => item.uuid === action) - if (!this.isEmptyValue(order)) { - return order - } + return this.$store.getters.getOrder } return { @@ -90,7 +68,8 @@ export default { grandTotal: 0, salesRepresentative: {}, businessPartner: { - value: '' + value: '', + uuid: '' } } }, @@ -118,21 +97,39 @@ export default { }, updateOrderProcessPos() { return this.$store.getters.getUpdateOrderPos + }, + getOrder() { + return this.$store.getters.getOrder } }, watch: { + getOrder(value) { + if (!this.isEmptyValue(value)) { + // this.order = value + this.$store.commit('updateValuesOfContainer', { + parentUuid: this.parentUuid, + containerUuid: this.containerUuid, + attributes: [{ + columnName: 'C_BPartner_ID', + value: value.businessPartner.id + }, + { + columnName: 'DisplayColumn_C_BPartner_ID', + value: value.businessPartner.name + }, + { + columnName: ' C_BPartner_ID_UUID', + value: value.businessPartner.uuid + }] + }) + } + }, currentOrder(value) { if (this.isEmptyValue(value)) { this.orderLines = [] - this.order = { - documentType: {}, - documentStatus: {}, - salesRepresentative: {} - } this.$store.dispatch('listOrderLine', []) this.listOrderLines({}) } else { - this.fillOrder(value) this.listOrderLines(value) } }, @@ -157,7 +154,6 @@ export default { beforeMount() { if (!this.isEmptyValue(this.currentPoint)) { if (!this.isEmptyValue(this.currentOrder)) { - this.fillOrder(this.currentOrder) this.listOrderLines(this.currentOrder) } } @@ -167,7 +163,6 @@ export default { this.unsubscribe() }, mounted() { - // this.findProcess() if (!this.isEmptyValue(this.$route.query)) { this.reloadOrder(true, this.$route.query.action) } @@ -203,41 +198,14 @@ export default { } }, updateOrder(update) { - if (this.withoutPOSTerminal()) { - return - } - if (!this.$route.query || this.isEmptyValue(this.$route.query.action)) { - return - } - - const { uuid: posUuid } = this.currentPoint - - let customerUuid - if (update.columnName === 'C_BPartner_ID_UUID') { - customerUuid = update.value - if (this.isEmptyValue(customerUuid) && !this.isEmptyValue(this.currentPoint)) { - customerUuid = this.currentPoint.templateBusinessPartner.uuid - } - } - - requestUpdateOrder({ - orderUuid: this.$route.query.action, - posUuid, - customerUuid - // documentTypeUuid: value.value, - // description - }) - .then(response => { - // this.reloadOrder(true) - }) - .catch(error => { - console.error(error.message) - this.$message({ - type: 'error', - message: error.message, - showClose: true - }) + // user session + if (update.value !== this.getOrder.businessPartner.uuid) { + this.$store.dispatch('updateOrder', { + orderUuid: this.$route.query.action, + posUuid: this.currentPoint.uuid, + customerUuid: update.value }) + } }, setBusinessPartner({ name, id, uuid }) { // Use update values of container (without subscription) @@ -309,50 +277,43 @@ export default { const orderUuid = this.$route.query.action if (this.isEmptyValue(orderUuid)) { const posUuid = this.currentPoint.uuid - let customerUuid = this.$store.getters.getValueOfField({ containerUuid: this.containerUuid, columnName: 'C_BPartner_ID_UUID' }) - if (this.isEmptyValue(customerUuid)) { + const id = this.$store.getters.getValueOfField({ + containerUuid: this.containerUuid, + columnName: 'C_BPartner_ID' + }) + if (this.isEmptyValue(customerUuid) || id === 1000006) { customerUuid = this.currentPoint.templateBusinessPartner.uuid } - // user session - const salesRepresentativeUuid = this.$store.getters['user/getUserUuid'] - requestCreateOrder({ + // alert(name) + this.$store.dispatch('createOrder', { posUuid, customerUuid, - salesRepresentativeUuid + salesRepresentativeUuid: this.currentPoint.templateBusinessPartner.uuid }) - .then(order => { - this.$store.dispatch('currentOrder', order) - this.fillOrder(order) - + .then(response => { + // this.order = response + this.reloadOrder(true, response.uuid) this.$router.push({ params: { ...this.$route.params }, query: { ...this.$route.query, - action: order.uuid + action: response.uuid } }).then(() => { if (withLine) { - this.createOrderLine(order.uuid) + this.createOrderLine(response.uuid) } + this.$store.dispatch('listOrdersFromServer', { + posUuid: this.$store.getters.getCurrentPOS.uuid + }) }).catch(() => {}) - - // update orders list - this.$store.commit('setIsReloadListOrders') - }) - .catch(error => { - console.error(error.message) - this.$message({ - type: 'error', - message: error.message, - showClose: true - }) }) } else { this.createOrderLine(orderUuid) @@ -367,22 +328,8 @@ export default { } } if (!this.isEmptyValue(orderUuid)) { - requestGetOrder(orderUuid) - .then(orderResponse => { - this.$store.dispatch('currentOrder', orderResponse) - this.fillOrder(orderResponse) - this.listOrderLines(orderResponse) - }) - .catch(error => { - this.$message({ - type: 'error', - message: error.message, - showClose: true - }) - }) + this.$store.dispatch('reloadOrder', { orderUuid }) } - } else { - this.fillOrder(this.currentOrder, false) } }, fillOrder(order, setToStore = true) { @@ -407,7 +354,7 @@ export default { const { businessPartner } = order this.setBusinessPartner(businessPartner) } - this.order = orderToPush + // this.order = orderToPush }, getOrderTax(currency) { if (this.isEmptyValue(this.order)) { @@ -433,16 +380,8 @@ export default { this.updateOrderLine(mutation.payload) } break - // - case 'C_DocType_ID': - this.updateOrder(mutation.payload) - break } } else if (mutation.type === 'updateValueOfField') { - // if (this.metadata.containerUuid === mutation.payload.containerUuid && - // mutation.payload.columnName === 'ProductValue') { - // this.findProduct(mutation.payload.value) - // } switch (mutation.payload.columnName) { case 'DisplayColumn_TenderType': this.displayType = mutation.payload.value diff --git a/src/store/modules/ADempiere/pointOfSales/order.js b/src/store/modules/ADempiere/pointOfSales/order.js deleted file mode 100644 index 5d06b7d8..00000000 --- a/src/store/modules/ADempiere/pointOfSales/order.js +++ /dev/null @@ -1,169 +0,0 @@ -import { - requestGetOrder, - requestListOrders -} from '@/api/ADempiere/form/point-of-sales.js' -import { isEmptyValue, extractPagingToken } from '@/utils/ADempiere/valueUtils.js' -import { showMessage } from '@/utils/ADempiere/notification.js' - -const withoutResponse = { - isLoaded: false, - isReload: true, - recordCount: 0, - nextPageToken: undefined -} - -const ordes = { - state: { - order: {}, - findOrder: {}, - listOrder: { - ...withoutResponse, - isShowPopover: false - } - }, - mutations: { - setOrder(state, order) { - state.order = order - }, - setListOrder(state, listOrder) { - state.listOrder = { - ...state.listOrder, - ...listOrder - } - }, - setOrdersListPageNumber(state, pageNumber) { - state.listOrder.pageNumber = pageNumber - }, - showListOrders(state, isShow) { - state.listOrder.isShowPopover = isShow - }, - setIsReloadListOrders(state) { - state.listOrder.isReload = true - }, - currentOrder(state, currentOrder) { - state.currentOrder = currentOrder - }, - findOrder(state, findOrder) { - state.findOrder = findOrder - } - }, - actions: { - /** - * Set page number of pagination list - * @param {number} pageNumber - */ - setOrdersListPageNumber({ commit, dispatch }, pageNumber) { - commit('setOrdersListPageNumber', pageNumber) - dispatch('listOrdersFromServer', {}) - }, - listOrdersFromServer({ state, commit, getters }, { - posUuid, - documentNo, - businessPartnerUuid, - grandTotal, - openAmount, - isPaid, - isProcessed, - isAisleSeller, - isInvoiced, - dateOrderedFrom, - dateOrderedTo, - salesRepresentativeUuid - }) { - if (isEmptyValue(posUuid)) { - posUuid = getters.getPointOfSalesUuid - } - - let { pageNumber, token } = state.listOrder - if (isEmptyValue(pageNumber)) { - pageNumber = 1 - } - let pageToken - if (!isEmptyValue(token)) { - pageToken = token + '-' + pageNumber - } - requestListOrders({ - posUuid, - documentNo, - businessPartnerUuid, - grandTotal, - openAmount, - isPaid, - isProcessed, - isAisleSeller, - isInvoiced, - dateOrderedFrom, - dateOrderedTo, - salesRepresentativeUuid, - pageToken - }) - .then(responseOrdersList => { - if (isEmptyValue(token) || isEmptyValue(pageToken)) { - token = extractPagingToken(responseOrdersList.nextPageToken) - } - - commit('setListOrder', { - ...responseOrdersList, - isLoaded: true, - isReload: false, - posUuid, - token, - pageNumber - }) - }) - .catch(error => { - console.warn(`listOrdersFromServer: ${error.message}. Code: ${error.code}.`) - // showMessage({ - // type: 'info', - // message: error.message, - // showClose: true - // }) - }) - }, - setOrder({ commit }, order) { - commit('setOrder', order) - }, - currentOrder({ commit }, findOrder) { - commit('findOrder', findOrder) - }, - findOrderServer({ commit }, orderUuid) { - if (typeof orderUuid === 'string' && !isEmptyValue(orderUuid)) { - requestGetOrder(orderUuid) - .then(responseOrder => { - commit('findOrder', responseOrder) - }) - .catch(error => { - console.warn(`findOrderServer: ${error.message}. Code: ${error.code}.`) - showMessage({ - type: 'info', - message: error.message, - showClose: true - }) - }) - } - commit('findOrder', {}) - } - }, - getters: { - getOrder: (state) => { - return state.order - }, - getListOrder: (state) => { - if (isEmptyValue(state.listOrder)) { - return { - ...withoutResponse, - ordersList: [] - } - } - return state.listOrder - }, - getCurrentOrder: (state) => { - return state.currentOrder - }, - getFindOrder: (state) => { - return state.findOrder - } - } -} - -export default ordes diff --git a/src/store/modules/ADempiere/pointOfSales/order/actions.js b/src/store/modules/ADempiere/pointOfSales/order/actions.js new file mode 100644 index 00000000..7cbbb2cf --- /dev/null +++ b/src/store/modules/ADempiere/pointOfSales/order/actions.js @@ -0,0 +1,263 @@ +import { + requestCreateOrder, + requestGetOrder, + requestUpdateOrder, + requestCreateOrderLine, + requestListOrders +} from '@/api/ADempiere/form/point-of-sales.js' +import { isEmptyValue, extractPagingToken } from '@/utils/ADempiere/valueUtils.js' +import { showMessage } from '@/utils/ADempiere/notification.js' + +/** + * Order Actions + * @author Elsio Sanchez + */ +export default { + /** + * Create Sales Order + * @param {string} posUuid Current POS Uuid + * @param {string} customerUuid Customer Uuid + * @param {string} salesRepresentativeUuid Sales Representative Uuid + */ + createOrder({ commit, dispatch }, { + posUuid, + customerUuid, + salesRepresentativeUuid + }) { + return requestCreateOrder({ + posUuid, + customerUuid, + salesRepresentativeUuid + }) + .then(order => { + commit('setOrder', order) + dispatch('fillOrde', { attribute: order }) + + commit('setIsReloadListOrders') + return order + }) + .catch(error => { + console.error(error.message) + showMessage({ + type: 'error', + message: error.message, + showClose: true + }) + }) + }, + /** + * Update Sales Order + * @param {string} posUuid Current POS Uuid + * @param {string} posUuid Order Uuid + * @param {string} customerUuid Customer Uuid + */ + updateOrder({ commit, dispatch }, { + orderUuid, + posUuid, + customerUuid + }) { + requestUpdateOrder({ + orderUuid, + posUuid, + customerUuid + }) + .then(response => { + dispatch('reloadOrder', { orderUuid: response.uuid }) + }) + .catch(error => { + console.error(error.message) + this.$message({ + type: 'error', + message: error.message, + showClose: true + }) + }) + }, + + /** + * Create order line from order uuid and product + * @param {string} orderUuid Order Uuid + * @param {string} productUuid Product Uuid + * @param {string} description Product description + * @param {number} quantity Quantity Producto + * @param {number} price Price Producto + * @param {number} discountRate DiscountRate Producto + */ + createOrderLine({ commit, dispatch }, { + orderUuid, + warehouseUuid, + productUuid, + chargeUuid, + description, + quantity, + price, + discountRate + }) { + requestCreateOrderLine({ + orderUuid, + productUuid + }) + .then(orderLine => { + dispatch('updateOrderLines', orderLine) + // this.fillOrderLine(orderLine) + this.reloadOrder(true, orderUuid) + }) + .catch(error => { + console.warn(error.message) + showMessage({ + type: 'error', + message: error.message, + showClose: true + }) + }) + }, + /** + * Reload Order + * @param {string} orderUuid Order Uuid + */ + reloadOrder({ commit, dispatch, rootGetters }, { orderUuid }) { + if (isEmptyValue(orderUuid)) { + orderUuid = rootGetters.getOrder.uuid // this.currentOrder.uuid + } + if (!isEmptyValue(orderUuid)) { + requestGetOrder(orderUuid) + .then(orderResponse => { + dispatch('fillOrde', { + attribute: orderResponse, + setToStore: false + }) + dispatch('currentOrder', orderResponse) + // dispatch('listOrderLinesFromServer', orderResponse.uuid) + }) + .catch(error => { + showMessage({ + type: 'error', + message: error.message, + showClose: true + }) + }) + } + }, + /** + * Fill Order + * @param {object} attribute Attributes of the Order + * @param {boolean} setToStore set To Store + */ + fillOrde({ commit, dispatch }, { + attribute, + setToStore = true + }) { + const orderToPush = { + uuid: attribute.uuid, + id: attribute.id, + businessPartner: attribute.businessPartner, // description, duns, id, lastName, naics, name, taxId, uuid, value + documentNo: attribute.documentNo, + dateOrdered: attribute.dateOrdered, + documentStatus: attribute.documentStatus, // value, name, description + documentType: attribute.documentType, // name, printName + salesRepresentative: attribute.salesRepresentative, // id, uuid, name, description, + totalLines: attribute.totalLines, + grandTotal: attribute.grandTotal + } + // if (setToStore) { + dispatch('setOrder', { + ...orderToPush + }) + // } + }, + /** + * Set page number of pagination list + * @param {number} pageNumber + */ + setOrdersListPageNumber({ commit, dispatch }, pageNumber) { + commit('setOrdersListPageNumber', pageNumber) + dispatch('listOrdersFromServer', {}) + }, + listOrdersFromServer({ state, commit, getters }, { + posUuid, + documentNo, + businessPartnerUuid, + grandTotal, + openAmount, + isPaid, + isProcessed, + isAisleSeller, + isInvoiced, + dateOrderedFrom, + dateOrderedTo, + salesRepresentativeUuid + }) { + if (isEmptyValue(posUuid)) { + posUuid = getters.getPointOfSalesUuid + } + + let { pageNumber, token } = state.listOrder + if (isEmptyValue(pageNumber)) { + pageNumber = 1 + } + let pageToken + if (!isEmptyValue(token)) { + pageToken = token + '-' + pageNumber + } + requestListOrders({ + posUuid, + documentNo, + businessPartnerUuid, + grandTotal, + openAmount, + isPaid, + isProcessed, + isAisleSeller, + isInvoiced, + dateOrderedFrom, + dateOrderedTo, + salesRepresentativeUuid, + pageToken + }) + .then(responseOrdersList => { + if (isEmptyValue(token) || isEmptyValue(pageToken)) { + token = extractPagingToken(responseOrdersList.nextPageToken) + } + + commit('setListOrder', { + ...responseOrdersList, + isLoaded: true, + isReload: false, + posUuid, + token, + pageNumber + }) + }) + .catch(error => { + console.warn(`listOrdersFromServer: ${error.message}. Code: ${error.code}.`) + // showMessage({ + // type: 'info', + // message: error.message, + // showClose: true + // }) + }) + }, + setOrder({ commit }, order) { + commit('setOrder', order) + }, + currentOrder({ commit }, findOrder) { + commit('findOrder', findOrder) + }, + findOrderServer({ commit }, orderUuid) { + if (typeof orderUuid === 'string' && !isEmptyValue(orderUuid)) { + requestGetOrder(orderUuid) + .then(responseOrder => { + commit('findOrder', responseOrder) + }) + .catch(error => { + console.warn(`findOrderServer: ${error.message}. Code: ${error.code}.`) + showMessage({ + type: 'info', + message: error.message, + showClose: true + }) + }) + } + commit('findOrder', {}) + } +} diff --git a/src/store/modules/ADempiere/pointOfSales/order/getters.js b/src/store/modules/ADempiere/pointOfSales/order/getters.js new file mode 100644 index 00000000..8b45bc27 --- /dev/null +++ b/src/store/modules/ADempiere/pointOfSales/order/getters.js @@ -0,0 +1,33 @@ +/** + * Order Getters + * @author Elsio Sanchez + */ +import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js' + +const withoutResponse = { + isLoaded: false, + isReload: true, + recordCount: 0, + nextPageToken: undefined +} + +export default { + getOrder: (state) => { + return state.order + }, + getListOrder: (state) => { + if (isEmptyValue(state.listOrder)) { + return { + ...withoutResponse, + ordersList: [] + } + } + return state.listOrder + }, + getCurrentOrder: (state) => { + return state.currentOrder + }, + getFindOrder: (state) => { + return state.findOrder + } +} diff --git a/src/store/modules/ADempiere/pointOfSales/order/index.js b/src/store/modules/ADempiere/pointOfSales/order/index.js new file mode 100644 index 00000000..fdec594f --- /dev/null +++ b/src/store/modules/ADempiere/pointOfSales/order/index.js @@ -0,0 +1,23 @@ + +import state from './state.js' +import mutations from './mutations.js' +import actions from './actions.js' +import getters from './getters.js' + +/** + * Order Vuex Module + * Create Order + * Update Order + * List Order + * Delete Order + * Reload Order + * @author Elsio Sanchez + */ +const ordes = { + state, + mutations, + actions, + getters +} + +export default ordes diff --git a/src/store/modules/ADempiere/pointOfSales/order/mutations.js b/src/store/modules/ADempiere/pointOfSales/order/mutations.js new file mode 100644 index 00000000..4bd1d154 --- /dev/null +++ b/src/store/modules/ADempiere/pointOfSales/order/mutations.js @@ -0,0 +1,31 @@ + +/** + * Order Mutations + * @author Elsio Sanchez + */ +export default { + setOrder(state, order) { + state.order = order + }, + setListOrder(state, listOrder) { + state.listOrder = { + ...state.listOrder, + ...listOrder + } + }, + setOrdersListPageNumber(state, pageNumber) { + state.listOrder.pageNumber = pageNumber + }, + showListOrders(state, isShow) { + state.listOrder.isShowPopover = isShow + }, + setIsReloadListOrders(state) { + state.listOrder.isReload = true + }, + currentOrder(state, currentOrder) { + state.currentOrder = currentOrder + }, + findOrder(state, findOrder) { + state.findOrder = findOrder + } +} diff --git a/src/store/modules/ADempiere/pointOfSales/order/state.js b/src/store/modules/ADempiere/pointOfSales/order/state.js new file mode 100644 index 00000000..5972d483 --- /dev/null +++ b/src/store/modules/ADempiere/pointOfSales/order/state.js @@ -0,0 +1,30 @@ +/** + * Order State + * @author Elsio Sanchez + */ +const withoutResponse = { + isLoaded: false, + isReload: true, + recordCount: 0, + nextPageToken: undefined +} +export default { + order: { + documentType: {}, + documentStatus: { + value: '' + }, + totalLines: 0, + grandTotal: 0, + salesRepresentative: {}, + businessPartner: { + value: '', + uuid: '' + } + }, + findOrder: {}, + listOrder: { + ...withoutResponse, + isShowPopover: false + } +} diff --git a/src/store/modules/ADempiere/pointOfSales/payments/getters.js b/src/store/modules/ADempiere/pointOfSales/payments/getters.js index 0acc707a..45e7d036 100644 --- a/src/store/modules/ADempiere/pointOfSales/payments/getters.js +++ b/src/store/modules/ADempiere/pointOfSales/payments/getters.js @@ -5,7 +5,6 @@ export default { getPaymentBox: (state) => { - console.log({ state }) return state }, getMultiplyRate: (state) => { @@ -21,7 +20,6 @@ export default { return state.divideRateCollection }, getListPayments: (state) => { - console.log({ state }, 1) return state.listPayments }, getListsPaymentTypes: (state) => {