From f821949740489101e3a5e19f44016134fd692069 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 13 Feb 2025 13:25:24 +0100 Subject: [PATCH 01/11] feat: refs #6943 addressPropagate --- src/components/FormModel.vue | 16 ++++----- .../Customer/Card/CustomerFiscalData.vue | 35 +++++++++++++++++++ .../components/CustomerAddressEdit.vue | 17 +++------ 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index 2e580257c..61315e55a 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -97,7 +97,7 @@ const $props = defineProps({ }); const emit = defineEmits(['onFetch', 'onDataSaved']); const modelValue = computed( - () => $props.model ?? `formModel_${route?.meta?.title ?? route.name}` + () => $props.model ?? `formModel_${route?.meta?.title ?? route.name}`, ).value; const componentIsRendered = ref(false); const arrayData = useArrayData(modelValue); @@ -148,7 +148,7 @@ onMounted(async () => { JSON.stringify(newVal) !== JSON.stringify(originalData.value); isResetting.value = false; }, - { deep: true } + { deep: true }, ); } }); @@ -156,7 +156,7 @@ onMounted(async () => { if (!$props.url) watch( () => arrayData.store.data, - (val) => updateAndEmit('onFetch', val) + (val) => updateAndEmit('onFetch', val), ); watch( @@ -165,7 +165,7 @@ watch( originalData.value = null; reset(); await fetch(); - } + }, ); onBeforeRouteLeave((to, from, next) => { @@ -222,7 +222,7 @@ async function save() { if ($props.urlCreate) notify('globals.dataCreated', 'positive'); - updateAndEmit('onDataSaved', formData.value, response?.data); + updateAndEmit('onDataSaved', formData.value, response?.data, originalData.value); if ($props.reload) await arrayData.fetch({}); hasChanges.value = false; } finally { @@ -254,16 +254,16 @@ function filter(value, update, filterOptions) { (ref) => { ref.setOptionIndex(-1); ref.moveOptionSelection(1, true); - } + }, ); } -function updateAndEmit(evt, val, res) { +function updateAndEmit(evt, val, res, old) { state.set(modelValue, val); originalData.value = val && JSON.parse(JSON.stringify(val)); if (!$props.url) arrayData.store.data = val; - emit(evt, state.get(modelValue), res); + emit(evt, state.get(modelValue), res, old); } function trimData(data) { diff --git a/src/pages/Customer/Card/CustomerFiscalData.vue b/src/pages/Customer/Card/CustomerFiscalData.vue index 8f2c4efb0..7e02f7b1f 100644 --- a/src/pages/Customer/Card/CustomerFiscalData.vue +++ b/src/pages/Customer/Card/CustomerFiscalData.vue @@ -2,6 +2,7 @@ import { ref } from 'vue'; import { useI18n } from 'vue-i18n'; import { useRoute } from 'vue-router'; +import useNotify from 'src/composables/useNotify.js'; import FetchData from 'components/FetchData.vue'; import FormModel from 'components/FormModel.vue'; @@ -9,9 +10,13 @@ import VnRow from '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'; +const quasar = useQuasar(); const { t } = useI18n(); const route = useRoute(); +const { notify } = useNotify(); const typesTaxes = ref([]); const typesTransactions = ref([]); @@ -23,6 +28,31 @@ function handleLocation(data, location) { data.provinceFk = provinceFk; data.countryFk = countryFk; } + +async function checkEtChanges(data, _, originalData) { + const equalizatedHasChanged = originalData.isEqualizated != data.isEqualizated; + const hasToInvoiceByAddress = + originalData.hasToInvoiceByAddress || data.hasToInvoiceByAddress; + if (equalizatedHasChanged && hasToInvoiceByAddress) { + quasar.dialog({ + component: VnConfirm, + componentProps: { + title: t('You changed the equalization tax'), + message: t('Do you want to spread the change?'), + promise: () => acceptPropagate(data), + }, + }); + } else if (equalizatedHasChanged) { + await acceptPropagate(data); + } +} + +async function acceptPropagate({ isEqualizated }) { + await $axios.patch(`Clients/${route.params.id}/addressesPropagateRe`, { + isEqualizated, + }); + notify(t('Equivalent tax spreaded'), 'warning'); +}