diff --git a/src/composables/confirmOrder.js b/src/composables/confirmOrder.js new file mode 100644 index 000000000..33e05a1d7 --- /dev/null +++ b/src/composables/confirmOrder.js @@ -0,0 +1,22 @@ +import axios from 'axios'; +import { useQuasar } from 'quasar'; +import { useI18n } from 'vue-i18n'; + +export function confirmOrder() { + const quasar = useQuasar(); + const { t } = useI18n(); + + async function confirm(route) { + const { data } = await axios.post(`Orders/${route}/confirm`); + if (data) { + quasar.notify({ + message: t('globals.confirm'), + type: 'positive', + }); + return data; + } + return null; + } + + return { confirm }; +} diff --git a/src/pages/Order/Card/OrderLines.vue b/src/pages/Order/Card/OrderLines.vue index ee883b73a..90586dc15 100644 --- a/src/pages/Order/Card/OrderLines.vue +++ b/src/pages/Order/Card/OrderLines.vue @@ -6,6 +6,7 @@ import { useQuasar } from 'quasar'; import axios from 'axios'; import { useStateStore } from 'stores/useStateStore'; import { useArrayData } from 'composables/useArrayData'; +import { confirmOrder } from 'composables/confirmOrder'; import { toCurrency, toDate } from 'src/filters'; import VnConfirm from 'components/ui/VnConfirm.vue'; @@ -31,7 +32,7 @@ const orderSummary = ref({ }); const getTotalRef = ref(); const getVATRef = ref(); - +const { confirm } = confirmOrder(); const lineFilter = ref({ include: [ { @@ -204,20 +205,17 @@ async function remove(item) { getVATRef.value.fetch(); } -async function confirmOrder() { - await axios.post(`Orders/${route.params.id}/confirm`); - quasar.notify({ - message: t('globals.confirm'), - type: 'positive', - }); - router.push({ - name: 'TicketList', - query: { - table: JSON.stringify({ clientFk: descriptorData.store.data.clientFk }), - }, - }); +async function handleConfirm() { + const result = await confirm(route.params.id); + if (result) { + router.push({ + name: 'TicketList', + query: { + table: JSON.stringify({ clientFk: descriptorData.store.data.clientFk }), + }, + }); + } } - watch( () => router.currentRoute.value.params.id, () => { @@ -314,7 +312,7 @@ watch( - + {{ t('confirm') }} diff --git a/src/pages/Order/Card/OrderSummary.vue b/src/pages/Order/Card/OrderSummary.vue index 9bc89ad28..3669fe8d8 100644 --- a/src/pages/Order/Card/OrderSummary.vue +++ b/src/pages/Order/Card/OrderSummary.vue @@ -2,10 +2,9 @@ import { computed, ref } from 'vue'; import { useRoute } from 'vue-router'; import { useI18n } from 'vue-i18n'; -import { useQuasar } from 'quasar'; -import axios from 'axios'; import { dashIfEmpty, toCurrency, toDateHourMinSec } from 'src/filters'; import { useArrayData } from 'composables/useArrayData'; +import { confirmOrder } from 'composables/confirmOrder'; import VnLv from 'components/ui/VnLv.vue'; import CardSummary from 'components/ui/CardSummary.vue'; import CustomerDescriptorProxy from 'pages/Customer/Card/CustomerDescriptorProxy.vue'; @@ -25,8 +24,8 @@ const $props = defineProps({ const entityId = computed(() => $props.id || route.params.id); const summary = ref(); -const quasar = useQuasar(); const descriptorData = useArrayData('orderData'); +const { confirm } = confirmOrder(); const detailsColumns = ref([ { name: 'item', @@ -56,14 +55,12 @@ const detailsColumns = ref([ }, ]); -async function confirmOrder() { - await axios.post(`Orders/${route.params.id}/confirm`); - quasar.notify({ - message: t('globals.confirm'), - type: 'positive', - }); - summary.value.fetch({}); - descriptorData.fetch({}); +async function handleConfirm() { + const result = await confirm(route.params.id); + if (result) { + summary.value.fetch({}); + descriptorData.fetch({}); + } } @@ -84,7 +81,7 @@ async function confirmOrder() { text-color="white" :disabled="isConfirmed" :label="t('order.summary.confirm')" - @click="confirmOrder()" + @click="handleConfirm()" > {{ t('order.summary.confirmLines') }}