diff --git a/src/api/ADempiere/form/point-of-sales.js b/src/api/ADempiere/form/point-of-sales.js index 5c9b8643..c1502a84 100644 --- a/src/api/ADempiere/form/point-of-sales.js +++ b/src/api/ADempiere/form/point-of-sales.js @@ -3,6 +3,7 @@ import { ApiRest as requestRest, evaluateResponse } from '@/api/ADempiere/instances.js' +import { isEmptyValue } from '@/utils/ADempiere' /** * method in api/price-checking.js as requestGetProductPrice @@ -110,7 +111,7 @@ export function requestUpdateOrder({ // Get order from uuid export function requestGetOrder(orderUuid) { return requestRest({ - url: '/pos/update-order', + url: '/pos/get-order', data: { order_uuid: orderUuid } @@ -545,3 +546,59 @@ export function requestListPayments({ } }) } + +/** + * Process Order + * This request allows process a draft order with payments + * + * req.query.token - user token + * Body: + * req.body.pos_uuid - POS UUID reference + * req.body.order_uuid - Order UUID reference + * req.body.create_payments - Optional create payments (if is true then hope payments array) + * req.body.payments + * [ + * invoice_uuid - Invoice UUID reference + * bank_uuid - Bank UUID reference + * reference_no - Reference no + * description - Description for Payment + * amount - Payment Amount + * tender_type_code - Tender Type + * payment_date - Payment Date (default now) + * currency_uuid - Currency UUID reference + * ] + */ +export function requestProcessOrder({ + posUuid, + orderUuid, + createPayments, + payments +}) { + if (!isEmptyValue(payments)) { + payments = payments.map(parameter => { + return { + invoice_uuid: parameter.invoiceUuid, + bank_uuid: parameter.bankUuid, + reference_no: parameter.referenceNo, + description: parameter.description, + amount: parameter.amount, + tender_type_code: parameter.tenderTypeCode, + payment_ate: parameter.paymentDate, + currency_uid: parameter.currency_uuid + } + }) + } + return requestRest({ + url: '/pos/process-order', + data: { + pos_uuid: posUuid, + order_uuid: orderUuid, + create_payments: createPayments, + payments: payments + } + }) + .then(evaluateResponse) + .then(processOrderResponse => { + return processOrderResponse + }) +} diff --git a/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue b/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue index 2a28e436..77b3b8d6 100644 --- a/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue +++ b/src/components/ADempiere/Form/VPOS/Collection/typeCollection.vue @@ -123,7 +123,6 @@ export default { }, computed: { typesPayment() { - console.log(this.$store.getters.getListsPaymentTypes) return this.$store.getters.getListsPaymentTypes }, listCurrency() { diff --git a/src/components/ADempiere/Form/VPOS/Options/index.vue b/src/components/ADempiere/Form/VPOS/Options/index.vue index e3d8f7b9..6d69c3ad 100644 --- a/src/components/ADempiere/Form/VPOS/Options/index.vue +++ b/src/components/ADempiere/Form/VPOS/Options/index.vue @@ -256,13 +256,12 @@ import ListProductPrice from '@/components/ADempiere/Form/VPOS/ProductInfo/produ import { requestPrintOrder, requestGenerateImmediateInvoice, - requestCompletePreparedOrder, - // requestReverseSalesTransaction, requestCreateWithdrawal, requestCreateNewCustomerReturnOrder, requestCashClosing, requestDeleteOrder, - requestCreateOrder + requestCreateOrder, + requestProcessOrder } from '@/api/ADempiere/form/point-of-sales.js' import ModalDialog from '@/components/ADempiere/Dialog' import posProcess from '@/utils/ADempiere/constants/posProcess' @@ -422,9 +421,36 @@ export default { }) }, completePreparedOrder() { - requestCompletePreparedOrder({ - orderUuid: this.$route.query.action + const posUuid = this.currentPoint.uuid + this.$store.dispatch('updateOrderPos', true) + this.$message({ + type: 'info', + message: this.$t('notifications.processing'), + showClose: true }) + requestProcessOrder({ + posUuid, + orderUuid: this.$route.query.action, + createPayments: !this.isEmptyValue(this.$store.getters.getListPayments), + payments: this.$store.getters.getListPayments + }) + .then(response => { + this.$store.dispatch('reloadOrder', response.uuid) + }) + .catch(error => { + console.log(error) + }) + .finally(() => { + this.$store.dispatch('listOrdersFromServer', { + posUuid: this.$store.getters.getCurrentPOS.uuid + }) + this.$message({ + type: 'success', + message: this.$t('notifications.completed'), + showClose: true + }) + this.$store.dispatch('updateOrderPos', false) + }) }, reverseSalesTransaction() { const process = this.$store.getters.getProcess(posProcess[0].uuid) diff --git a/src/components/ADempiere/Form/VPOS/Order/index.vue b/src/components/ADempiere/Form/VPOS/Order/index.vue index 298d0b4a..14081dfb 100644 --- a/src/components/ADempiere/Form/VPOS/Order/index.vue +++ b/src/components/ADempiere/Form/VPOS/Order/index.vue @@ -34,6 +34,7 @@ @@ -458,6 +459,9 @@ export default { } }, mounted() { + if (!this.isEmptyValue(this.$route.query.action)) { + this.$store.dispatch('reloadOrder', { orderUuid: this.$route.query.action }) + } setTimeout(() => { this.currencyDisplaye() }, 1500) diff --git a/src/components/ADempiere/Form/VPOS/posMixin.js b/src/components/ADempiere/Form/VPOS/posMixin.js index 9d2e417a..35200e35 100644 --- a/src/components/ADempiere/Form/VPOS/posMixin.js +++ b/src/components/ADempiere/Form/VPOS/posMixin.js @@ -323,9 +323,9 @@ export default { if (requery) { if (this.isEmptyValue(orderUuid)) { orderUuid = this.$route.query.action - if (this.isEmptyValue(orderUuid)) { - orderUuid = this.$store.getters.getOrder.uuid // this.currentOrder.uuid - } + // if (this.isEmptyValue(orderUuid)) { + // orderUuid = this.$store.getters.getOrder.uuid // this.currentOrder.uuid + // } } if (!this.isEmptyValue(orderUuid)) { this.$store.dispatch('reloadOrder', { orderUuid }) diff --git a/src/store/modules/ADempiere/pointOfSales/order/state.js b/src/store/modules/ADempiere/pointOfSales/order/state.js index 5972d483..5c851d9b 100644 --- a/src/store/modules/ADempiere/pointOfSales/order/state.js +++ b/src/store/modules/ADempiere/pointOfSales/order/state.js @@ -20,7 +20,8 @@ export default { businessPartner: { value: '', uuid: '' - } + }, + uuid: '' }, findOrder: {}, listOrder: { diff --git a/src/utils/ADempiere/apiConverts/core.js b/src/utils/ADempiere/apiConverts/core.js index 2796ffbc..69fcdd63 100644 --- a/src/utils/ADempiere/apiConverts/core.js +++ b/src/utils/ADempiere/apiConverts/core.js @@ -126,6 +126,17 @@ export function convertCountry(countryToConvert) { } export function convertCurrency(currencyToConvert) { + if (isEmptyValue(currencyToConvert)) { + return { + id: 0, + uuid: '', + iSOCode: '', + curSymbol: '', + description: '', + standardPrecision: 0, + costingPrecision: 0 + } + } return { id: currencyToConvert.id, uuid: currencyToConvert.uuid,