#6943 Customer FiscalData already exists #1365

Closed
jsegarra wants to merge 7 commits from 6943_customerFD_alreadyExists into dev
2 changed files with 99 additions and 7 deletions
Showing only changes of commit 8dd74501ec - Show all commits

View File

@ -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);

View File

@ -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);
}

que @alexm confirme técnicamente el enfoque i en caso que este correcto, hazle test de front.

que @alexm confirme técnicamente el enfoque i en caso que este correcto, hazle test de front.

Este caso es muy concreto por eso la nueva prop en FormModel
No puede usarse lo que hay porque al darle a guardar tiene que hacer una comprobación previa(beforeSave), y según eso ejecutar una cosa después del guardado onDataSaved.
Me parece complicado y fácil de entender, el separar un flujo en dos funciones

Este caso es muy concreto por eso la nueva prop en FormModel No puede usarse lo que hay porque al darle a guardar tiene que hacer una comprobación previa(beforeSave), y según eso ejecutar una cosa después del guardado onDataSaved. Me parece complicado y fácil de entender, el separar un flujo en dos funciones

Okey, ya lo tengo. Cuando me confirmes hago e2e

Okey, ya lo tengo. Cuando me confirmes hago e2e
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(
Review

aqui llamas con data primero y luego con body, imagino que lo habrás probado, de donde sale body?

aqui llamas con _data_ primero y luego con _body_, imagino que lo habrás probado, de donde sale body?
t('Found a client with this data'),
`${t('foundClient_before')} <a class="link" href="#!/client/${exist.id}/summary" target="_blank">${exist.id}</a> ${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);
</script>
<template>
@ -33,9 +93,12 @@ function handleLocation(data, location) {
url="SageTransactionTypes"
/>
<FormModel
:url-update="`Clients/${route.params.id}/updateFiscalData`"
:has-confirm-modal="true"
ref="formModelRef"
auto-load
model="Customer"
:save-fn="formCustomFn"
prevent-submit
>
<template #form="{ data, validate }">
<VnRow>
@ -59,7 +122,7 @@ function handleLocation(data, location) {
<VnRow>
<VnInput :label="t('Street')" clearable v-model="data.street" required />
</VnRow>
{{ hasChangedTaxData }}
<VnRow>
<VnSelect
:label="t('Sage tax type')"
@ -70,6 +133,7 @@ function handleLocation(data, location) {
v-model="data.sageTaxTypeFk"
data-cy="sageTaxTypeFk"
:required="data.isTaxDataChecked"
@update:model-value="hasChangedTaxData = true"
/>
<VnSelect
:label="t('Sage transaction type')"
@ -80,6 +144,7 @@ function handleLocation(data, location) {
data-cy="sageTransactionTypeFk"
v-model="data.sageTransactionTypeFk"
:required="data.isTaxDataChecked"
@update:model-value="hasChangedTaxData = true"
>
<template #option="scope">
<QItem v-bind="scope.itemProps">
@ -150,14 +215,34 @@ function handleLocation(data, location) {
/><QCheckbox
:label="t('Verified data')"
v-model="data.isTaxDataChecked"
@update:model-value="hasChangedTaxData = true"
/>
</VnRow>
</template>
</FormModel>
<!-- <VnConfirm
v-model="foundClientDialog"
:title="t('Found a client with this data')"
:message="false"
:promise="confirm"
>
<template #customHTML>
<span
>{{ t('foundClient_before') }}
<a class="link" href="#!/client/{clientId}/summary" target="_blank">{{
paramsFoundClient.clientId
}}</a>
{{ t('foundClient_after') }}</span
>
</template>
</VnConfirm> -->
</template>
<i18n>
es:
Found a client with this data: Se ha encontrado un cliente con estos datos
foundClient_before: El cliente con id
foundClient_after: ya tiene este teléfono o email. ¿Quieres continuar?
Social name: Razón social
Tax number: NIF / CIF
Street: Dirección fiscal
@ -181,6 +266,9 @@ es:
inOrderToInvoice: Para facturar no se consulta este campo, sino el RE de consignatario. Al modificar este campo si no esta marcada la casilla Facturar por consignatario, se propagará automaticamente el cambio a todos lo consignatarios, en caso contrario preguntará al usuario si quiere o no propagar
Daily invoice: Facturación diaria
en:
Found a client with this data: A client with this data has been found
foundClient_before: The client with id
foundClient_after: already has this phone or email. ¿Do you want to continue?
onlyLetters: Only letters, numbers and spaces can be used
whenActivatingIt: When activating it, do not enter the country code in the ID field
inOrderToInvoice: In order to invoice, this field is not contulted, but the consignee's ET. When modifiying this field if the invoice by address option is not checked, the change will be automatically propagated to all addresses, otherwise the user will be asked if he wants to propagate it or not