forked from verdnatura/salix-front
Reviewed-on: verdnatura/salix-front#642 Reviewed-by: Javier Segarra <jsegarra@verdnatura.es>
This commit is contained in:
commit
8277b30033
|
@ -73,6 +73,10 @@ const $props = defineProps({
|
|||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
params: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
});
|
||||
|
||||
const { t } = useI18n();
|
||||
|
@ -153,9 +157,14 @@ 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]: getVal(val) });
|
||||
return obj;
|
||||
}, {});
|
||||
} else defaultWhere = { [key]: getVal(val) };
|
||||
const where = { ...(val ? defaultWhere : {}), ...$props.where };
|
||||
const fetchOptions = { where, include, limit };
|
||||
if (fields) fetchOptions.fields = fields;
|
||||
|
@ -194,6 +203,8 @@ async function filterHandler(val, update) {
|
|||
function nullishToTrue(value) {
|
||||
return value ?? true;
|
||||
}
|
||||
|
||||
const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -205,6 +216,7 @@ function nullishToTrue(value) {
|
|||
:limit="limit"
|
||||
:sort-by="sortBy"
|
||||
:fields="fields"
|
||||
:params="params"
|
||||
/>
|
||||
<QSelect
|
||||
v-model="value"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,16 @@ 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 } });
|
||||
worker.bankEntityFk = data?.[0]?.id ?? undefined;
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<VnSearchbar
|
||||
|
@ -137,11 +146,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 +229,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 +294,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 +313,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
|
||||
|
|
Loading…
Reference in New Issue