|
|
|
@ -4,14 +4,14 @@ import { useI18n } from 'vue-i18n';
|
|
|
|
|
import { useRoute } from 'vue-router';
|
|
|
|
|
import { useQuasar } from 'quasar';
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
|
|
import useNotify from 'src/composables/useNotify.js';
|
|
|
|
|
import FetchData from 'components/FetchData.vue';
|
|
|
|
|
import FormModel from 'components/FormModel.vue';
|
|
|
|
|
import VnRow from 'components/ui/VnRow.vue';
|
|
|
|
|
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 { useVnConfirm } from 'composables/useVnConfirm';
|
|
|
|
|
import VnCheckbox from 'src/components/common/VnCheckbox.vue';
|
|
|
|
|
import { getDifferences, getUpdatedValues } from 'src/filters';
|
|
|
|
|
import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
|
|
|
@ -19,6 +19,7 @@ import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
|
|
|
|
const quasar = useQuasar();
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
const { openConfirmationModal } = useVnConfirm();
|
|
|
|
|
const { notify } = useNotify();
|
|
|
|
|
|
|
|
|
|
const typesTaxes = ref([]);
|
|
|
|
@ -31,6 +32,44 @@ function handleLocation(data, location) {
|
|
|
|
|
data.provinceFk = provinceFk;
|
|
|
|
|
data.countryFk = countryFk;
|
|
|
|
|
}
|
|
|
|
|
const formModelRef = ref({});
|
|
|
|
|
const hasChangedTaxData = ref(false);
|
|
|
|
|
|
|
|
|
|
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(body, data);
|
|
|
|
|
else await confirm(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function checkExistingClient(body, { email, phone, mobile, id }) {
|
|
|
|
|
const findParams = Object.entries({ email, phone, mobile })
|
|
|
|
|
.filter(([, value]) => value)
|
|
|
|
|
.map(([key, value]) => ({ [key]: value }));
|
|
|
|
|
|
|
|
|
|
const filter = JSON.stringify({
|
|
|
|
|
where: {
|
|
|
|
|
and: [{ or: findParams }, { id: { neq: id } }],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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(body),
|
|
|
|
|
null,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
async function confirm(data) {
|
|
|
|
|
await axios.patch(`Clients/${route.params.id}/updateFiscalData`, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onBeforeSave(formData, originalData) {
|
|
|
|
|
return getUpdatedValues(
|
|
|
|
|
Object.keys(getDifferences(formData, originalData)),
|
|
|
|
@ -72,9 +111,12 @@ async function acceptPropagate({ isEqualizated }) {
|
|
|
|
|
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
|
|
|
|
|
:mapper="onBeforeSave"
|
|
|
|
|
observe-form-changes
|
|
|
|
|
@on-data-saved="checkEtChanges"
|
|
|
|
@ -101,7 +143,6 @@ async function acceptPropagate({ isEqualizated }) {
|
|
|
|
|
<VnRow>
|
|
|
|
|
<VnInput :label="t('Street')" clearable v-model="data.street" required />
|
|
|
|
|
</VnRow>
|
|
|
|
|
|
|
|
|
|
<VnRow>
|
|
|
|
|
<VnSelect
|
|
|
|
|
:label="t('Sage tax type')"
|
|
|
|
@ -112,6 +153,7 @@ async function acceptPropagate({ isEqualizated }) {
|
|
|
|
|
v-model="data.sageTaxTypeFk"
|
|
|
|
|
data-cy="sageTaxTypeFk"
|
|
|
|
|
:required="data.isTaxDataChecked"
|
|
|
|
|
@update:model-value="hasChangedTaxData = true"
|
|
|
|
|
/>
|
|
|
|
|
<VnSelect
|
|
|
|
|
:label="t('Sage transaction type')"
|
|
|
|
@ -122,6 +164,7 @@ async function acceptPropagate({ isEqualizated }) {
|
|
|
|
|
data-cy="sageTransactionTypeFk"
|
|
|
|
|
v-model="data.sageTransactionTypeFk"
|
|
|
|
|
:required="data.isTaxDataChecked"
|
|
|
|
|
@update:model-value="hasChangedTaxData = true"
|
|
|
|
|
>
|
|
|
|
|
<template #option="scope">
|
|
|
|
|
<QItem v-bind="scope.itemProps">
|
|
|
|
@ -183,6 +226,7 @@ async function acceptPropagate({ isEqualizated }) {
|
|
|
|
|
/><QCheckbox
|
|
|
|
|
:label="t('Verified data')"
|
|
|
|
|
v-model="data.isTaxDataChecked"
|
|
|
|
|
@update:model-value="hasChangedTaxData = true"
|
|
|
|
|
/>
|
|
|
|
|
</VnRow>
|
|
|
|
|
</template>
|
|
|
|
@ -191,6 +235,9 @@ async function acceptPropagate({ isEqualizated }) {
|
|
|
|
|
|
|
|
|
|
<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
|
|
|
|
@ -217,6 +264,9 @@ es:
|
|
|
|
|
You changed the equalization tax: Has cambiado el recargo de equivalencia
|
|
|
|
|
Do you want to spread the change?: ¿Deseas propagar el cambio a sus consignatarios?
|
|
|
|
|
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
|
|
|
|
|