0
0
Fork 0

Merge pull request 'fix: refs #7323 auto fill bic' (!642) from 7323-hotfix-workerCreate into master

Reviewed-on: verdnatura/salix-front#642
Reviewed-by: Javier Segarra <jsegarra@verdnatura.es>
This commit is contained in:
Jorge Penadés 2024-08-26 11:57:10 +00:00
commit 8277b30033
3 changed files with 45 additions and 17 deletions

View File

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

View File

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

View File

@ -23,7 +23,6 @@ const { t } = useI18n();
const tableRef = ref(); const tableRef = ref();
const { viewSummary } = useSummaryDialog(); const { viewSummary } = useSummaryDialog();
const companiesOptions = ref([]); const companiesOptions = ref([]);
const workersOptions = ref([]);
const payMethodsOptions = ref([]); const payMethodsOptions = ref([]);
const bankEntitiesOptions = ref([]); const bankEntitiesOptions = ref([]);
const postcodesOptions = ref([]); const postcodesOptions = ref([]);
@ -125,6 +124,16 @@ function generateCodeUser(worker) {
if (!worker.companyFk) worker.companyFk = user.companyFk; 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 } });
worker.bankEntityFk = data?.[0]?.id ?? undefined;
}
</script> </script>
<template> <template>
<VnSearchbar <VnSearchbar
@ -137,11 +146,6 @@ function generateCodeUser(worker) {
@on-fetch="(data) => (companiesOptions = data)" @on-fetch="(data) => (companiesOptions = data)"
auto-load auto-load
/> />
<FetchData
url="Workers/search"
@on-fetch="(data) => (workersOptions = data)"
auto-load
/>
<FetchData <FetchData
url="Paymethods" url="Paymethods"
@on-fetch="(data) => (payMethodsOptions = data)" @on-fetch="(data) => (payMethodsOptions = data)"
@ -225,7 +229,7 @@ function generateCodeUser(worker) {
<VnSelect <VnSelect
:label="t('worker.create.boss')" :label="t('worker.create.boss')"
v-model="data.bossFk" v-model="data.bossFk"
:options="workersOptions" url="Workers/search"
option-value="id" option-value="id"
option-label="name" option-label="name"
hide-selected hide-selected
@ -290,6 +294,7 @@ function generateCodeUser(worker) {
v-model="data.iban" v-model="data.iban"
:label="t('worker.create.iban')" :label="t('worker.create.iban')"
:disable="data.isFreelance" :disable="data.isFreelance"
@update:model-value="autofillBic(data)"
> >
<template #append> <template #append>
<QIcon name="info" class="cursor-info"> <QIcon name="info" class="cursor-info">
@ -308,6 +313,8 @@ function generateCodeUser(worker) {
hide-selected hide-selected
:roles-allowed-to-create="['salesAssistant', 'hr']" :roles-allowed-to-create="['salesAssistant', 'hr']"
:disable="data.isFreelance" :disable="data.isFreelance"
@update:model-value="autofillBic(data)"
:filter-options="['bic', 'name']"
> >
<template #form> <template #form>
<CreateBankEntityForm <CreateBankEntityForm