From 8dd74501ec0aaabd621acc07a38433ef281fd72b Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 10 Feb 2025 13:42:42 +0100 Subject: [PATCH 1/3] feat: refs #6943 already exists --- src/components/FormModel.vue | 6 +- .../Customer/Card/CustomerFiscalData.vue | 100 ++++++++++++++++-- 2 files changed, 99 insertions(+), 7 deletions(-) diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index 59141d374..5c5e5d857 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -73,6 +73,10 @@ const $props = defineProps({ type: Boolean, default: true, }, + hasConfirmModal: { + type: Boolean, + default: false, + }, saveFn: { type: Function, default: null, @@ -224,7 +228,7 @@ async function save() { if ($props.saveFn) response = await $props.saveFn(body); else response = await axios[method](url, body); - + if ($props.hasConfirmModal) return; if ($props.urlCreate) notify('globals.dataCreated', 'positive'); updateAndEmit('onDataSaved', formData.value, response?.data); diff --git a/src/pages/Customer/Card/CustomerFiscalData.vue b/src/pages/Customer/Card/CustomerFiscalData.vue index b256c001a..76e0016f9 100644 --- a/src/pages/Customer/Card/CustomerFiscalData.vue +++ b/src/pages/Customer/Card/CustomerFiscalData.vue @@ -2,16 +2,21 @@ import { ref } from 'vue'; import { useI18n } from 'vue-i18n'; import { useRoute } from 'vue-router'; - -import FetchData from 'components/FetchData.vue'; -import FormModel from 'components/FormModel.vue'; -import VnRow from 'components/ui/VnRow.vue'; +import axios from 'axios'; +import FetchData from 'src/components/FetchData.vue'; +import FormModel from 'src/components/FormModel.vue'; +import VnRow from 'src/components/ui/VnRow.vue'; import VnInput from 'src/components/common/VnInput.vue'; import VnSelect from 'src/components/common/VnSelect.vue'; import VnLocation from 'src/components/common/VnLocation.vue'; +import { useQuasar } from 'quasar'; +import VnConfirm from 'src/components/ui/VnConfirm.vue'; +import { useVnConfirm } from 'composables/useVnConfirm'; +const { openConfirmationModal } = useVnConfirm(); const { t } = useI18n(); const route = useRoute(); +const quasar = useQuasar(); const typesTaxes = ref([]); const typesTransactions = ref([]); @@ -23,6 +28,61 @@ function handleLocation(data, location) { data.provinceFk = provinceFk; data.countryFk = countryFk; } +const formModelRef = ref(null); +const foundClientDialog = ref(false); + +async function formCustomFn(data) { + const { email, phone, mobile, i } = data; + + const hasContactData = email || phone || mobile; + if (hasChangedTaxData.value && hasContactData) await checkExistingClient(data); + else await confirm(data); +} +async function checkExistingClient(data) { + const { email, phone, mobile, id } = data; + const findParams = []; + if (email) findParams.push({ email: email }); + + if (phone) findParams.push({ phone: phone }); + + if (mobile) findParams.push({ mobile: mobile }); + console.error('Custom function', data); + const filter = encodeURIComponent( + JSON.stringify({ + where: { + and: [{ or: findParams }, { id: { neq: id } }], + }, + }), + ); + const query = `Clients/findOne?filter=${filter}`; + + const { data: exist } = await axios.get(query); + if (!exist) confirm(data); + else { + // paramsFoundClient.value = { clientId: exist.id }; + // foundClientDialog.value = true; + openConfirmationModal( + t('Found a client with this data'), + `${t('foundClient_before')} ${exist.id} ${t('foundClient_after')}`, + () => confirm(data), + null, + ); + // quasar + // .dialog({ + // component: VnConfirm, + // componentProps: { + // title: t('Found a client with this phone or email'), + // data: { params }, + // }, + // }) + // .onOk(() => formModelRef.value.save()); + } +} +const paramsFoundClient = ref(null); +async function confirm(data) { + await axios.patch(`Clients/${route.params.id}/updateFiscalData`, data); +} +const hasChangedTaxData = ref(false);