fix: refs #7323 auto fill bic
gitea/salix-front/pipeline/pr-master This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-08-26 12:47:05 +02:00
parent 9636d5a3ad
commit 6f9cd7fe15
3 changed files with 46 additions and 17 deletions

View File

@ -73,6 +73,10 @@ const $props = defineProps({
type: Boolean,
default: true,
},
params: {
type: Object,
default: null,
},
});
const { t } = useI18n();
@ -153,9 +157,15 @@ async function fetchFilter(val) {
? optionValue.value
: optionFilter.value ?? optionLabel.value);
const defaultWhere = $props.useLike
? { [key]: { like: `%${val}%` } }
: { [key]: val };
let defaultWhere = {};
if ($props.filterOptions.length) {
defaultWhere = $props.filterOptions.reduce((obj, prop) => {
if (!obj.or) obj.or = [];
obj.or.push({ [prop]: { like: `%${val}%` } });
return obj;
}, {});
} else
defaultWhere = $props.useLike ? { [key]: { like: `%${val}%` } } : { [key]: val };
const where = { ...(val ? defaultWhere : {}), ...$props.where };
const fetchOptions = { where, include, limit };
if (fields) fetchOptions.fields = fields;
@ -205,6 +215,7 @@ function nullishToTrue(value) {
:limit="limit"
:sort-by="sortBy"
:fields="fields"
:params="params"
/>
<QSelect
v-model="value"

View File

@ -19,7 +19,6 @@ const { t } = useI18n();
const user = useState().getUser();
const companiesOptions = ref([]);
const workersOptions = ref([]);
const payMethodsOptions = ref([]);
const bankEntitiesOptions = ref([]);
const formData = ref({ companyFk: user.value.companyFk, isFreelance: false });
@ -56,6 +55,18 @@ function generateCodeUser(worker) {
if (!worker.companyFk) worker.companyFk = user.companyFk;
}
async function autofillBic(worker) {
if (!worker || !worker.iban) return;
let bankEntityId = parseInt(worker.iban.substr(4, 4));
let filter = { where: { id: bankEntityId } };
const { data } = await axios.get(`BankEntities`, { params: { filter } });
const hasData = data && data[0];
if (hasData) worker.bankEntityFk = data[0].id;
else if (!hasData) worker.bankEntityFk = undefined;
}
</script>
<template>
<FetchData
@ -63,11 +74,6 @@ function generateCodeUser(worker) {
@on-fetch="(data) => (companiesOptions = data)"
auto-load
/>
<FetchData
url="Workers/search"
@on-fetch="(data) => (workersOptions = data)"
auto-load
/>
<FetchData
url="Paymethods"
@on-fetch="(data) => (payMethodsOptions = data)"
@ -146,7 +152,7 @@ function generateCodeUser(worker) {
<VnSelect
:label="t('worker.create.boss')"
v-model="data.bossFk"
:options="workersOptions"
url="Workers/search"
option-value="id"
option-label="name"
hide-selected
@ -220,6 +226,7 @@ function generateCodeUser(worker) {
:label="t('worker.create.iban')"
:rules="validate('Worker.iban')"
:disable="formData.isFreelance"
@update:model-value="autofillBic(data)"
>
<template #append>
<QIcon name="info" class="cursor-info">
@ -237,6 +244,8 @@ function generateCodeUser(worker) {
:roles-allowed-to-create="['salesAssistant', 'hr']"
:rules="validate('Worker.bankEntity')"
:disable="formData.isFreelance"
@update:model-value="autofillBic(data)"
:filter-options="['bic', 'name']"
>
<template #form>
<CreateBankEntityForm

View File

@ -23,7 +23,6 @@ const { t } = useI18n();
const tableRef = ref();
const { viewSummary } = useSummaryDialog();
const companiesOptions = ref([]);
const workersOptions = ref([]);
const payMethodsOptions = ref([]);
const bankEntitiesOptions = ref([]);
const postcodesOptions = ref([]);
@ -125,6 +124,18 @@ function generateCodeUser(worker) {
if (!worker.companyFk) worker.companyFk = user.companyFk;
}
async function autofillBic(worker) {
if (!worker || !worker.iban) return;
let bankEntityId = parseInt(worker.iban.substr(4, 4));
let filter = { where: { id: bankEntityId } };
const { data } = await axios.get(`BankEntities`, { params: { filter } });
const hasData = data && data[0];
if (hasData) worker.bankEntityFk = data[0].id;
else if (!hasData) worker.bankEntityFk = undefined;
}
</script>
<template>
<VnSearchbar
@ -137,11 +148,6 @@ function generateCodeUser(worker) {
@on-fetch="(data) => (companiesOptions = data)"
auto-load
/>
<FetchData
url="Workers/search"
@on-fetch="(data) => (workersOptions = data)"
auto-load
/>
<FetchData
url="Paymethods"
@on-fetch="(data) => (payMethodsOptions = data)"
@ -225,7 +231,7 @@ function generateCodeUser(worker) {
<VnSelect
:label="t('worker.create.boss')"
v-model="data.bossFk"
:options="workersOptions"
url="Workers/search"
option-value="id"
option-label="name"
hide-selected
@ -290,6 +296,7 @@ function generateCodeUser(worker) {
v-model="data.iban"
:label="t('worker.create.iban')"
:disable="data.isFreelance"
@update:model-value="autofillBic(data)"
>
<template #append>
<QIcon name="info" class="cursor-info">
@ -308,6 +315,8 @@ function generateCodeUser(worker) {
hide-selected
:roles-allowed-to-create="['salesAssistant', 'hr']"
:disable="data.isFreelance"
@update:model-value="autofillBic(data)"
:filter-options="['bic', 'name']"
>
<template #form>
<CreateBankEntityForm