feat: refs #6943 solve conflicts

This commit is contained in:
Javier Segarra 2025-03-01 20:07:39 +01:00
parent 4551691922
commit a92f66fbcb
1 changed files with 18 additions and 22 deletions
src/pages/Customer/Card

View File

@ -32,40 +32,36 @@ function handleLocation(data, location) {
data.provinceFk = provinceFk;
data.countryFk = countryFk;
}
const formModelRef = ref(null);
const formModelRef = ref({});
const hasChangedTaxData = ref(false);
async function formCustomFn(data) {
async function formCustomFn(body) {
const data = formModelRef.value.formData;
const { email, phone, mobile } = data;
const hasContactData = email || phone || mobile;
if (hasChangedTaxData.value && hasContactData) await checkExistingClient(data);
if (hasChangedTaxData.value && hasContactData) await checkExistingClient(body, data);
else await confirm(data);
}
async function checkExistingClient({ email, phone, mobile, id }) {
const findParams = [];
if (email) findParams.push({ email: email });
async function checkExistingClient(body, { email, phone, mobile, id }) {
const findParams = Object.entries({ email, phone, mobile })
.filter(([, value]) => value)
.map(([key, value]) => ({ [key]: value }));
if (phone) findParams.push({ phone: phone });
const filter = JSON.stringify({
where: {
and: [{ or: findParams }, { id: { neq: id } }],
},
});
if (mobile) findParams.push({ mobile: mobile });
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);
const { data: exist } = await axios.get(`Clients/findOne`, { params: { filter } });
if (!exist) confirm(data);
else {
openConfirmationModal(
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),
() => confirm(body),
null,
);
}
@ -147,8 +143,8 @@ async function acceptPropagate({ isEqualizated }) {
<VnRow>
<VnInput :label="t('Street')" clearable v-model="data.street" required />
</VnRow>
{{ hasChangedTaxData }}
<VnRow>
{{ data.isTaxDataChecked }}
<VnSelect
:label="t('Sage tax type')"
:options="typesTaxes"
@ -157,7 +153,7 @@ async function acceptPropagate({ isEqualizated }) {
option-value="id"
v-model="data.sageTaxTypeFk"
data-cy="sageTaxTypeFk"
:required="data.isTaxDataChecked"
:required="true"
@update:model-value="hasChangedTaxData = true"
/>
<VnSelect
@ -168,7 +164,7 @@ async function acceptPropagate({ isEqualizated }) {
option-value="id"
data-cy="sageTransactionTypeFk"
v-model="data.sageTransactionTypeFk"
:required="data.isTaxDataChecked"
:required="true"
@update:model-value="hasChangedTaxData = true"
>
<template #option="scope">