diff --git a/src/components/CreateThermographForm.vue b/src/components/CreateThermographForm.vue index 0b7e4c5c6..54844ee8f 100644 --- a/src/components/CreateThermographForm.vue +++ b/src/components/CreateThermographForm.vue @@ -38,7 +38,7 @@ const onDataSaved = (dataSaved) => { @on-fetch="(data) => (warehousesOptions = data)" auto-load url="Warehouses" - :filter="{ fields: ['id', 'name'], order: 'name ASC', limit: 30 }" + :filter="{ fields: ['id', 'name'], order: 'name ASC' }" /> { return { clientId: route.params.id, - companyId: companyId.value ?? user.value.companyFk, + companyId: companyId.value ?? companyUser.value, }; }); +const companyFilterColumn = { + align: 'left', + name: 'companyId', + label: t('Company'), + component: 'select', + attrs: { + url: 'Companies', + optionLabel: 'code', + optionValue: 'id', + sortBy: 'code', + }, + columnFilter: { + event: { + remove: () => (companyId.value = null), + 'update:modelValue': (newCompanyFk) => { + if (!newCompanyFk) return; + vnFilterRef.value.addFilter(newCompanyFk); + companyUser.value = newCompanyFk; + }, + blur: () => !companyId.value && (companyId.value = companyUser.value), + }, + }, + visible: false, +}; + const columns = computed(() => [ { - align: 'right', + align: 'left', name: 'payed', label: t('Date'), format: ({ payed }) => toDate(payed), cardVisible: true, }, { - align: 'right', + align: 'left', name: 'created', label: t('Creation date'), format: ({ created }) => toDateHourMin(created), @@ -65,7 +90,12 @@ const columns = computed(() => [ label: t('Employee'), columnField: { component: 'userLink', - attrs: ({ row }) => ({ workerId: row.workerFk, name: row.userName }), + attrs: ({ row }) => { + return { + workerId: row.workerFk, + name: row.userName, + }; + }, }, cardVisible: true, }, @@ -77,13 +107,13 @@ const columns = computed(() => [ class: 'extend', }, { - align: 'right', + align: 'left', name: 'bankFk', label: t('Bank'), cardVisible: true, }, { - align: 'right', + align: 'left', name: 'debit', label: t('Debit'), format: ({ debit }) => debit && toCurrency(debit), @@ -136,20 +166,37 @@ const columns = computed(() => [ onBeforeMount(() => { stateStore.rightDrawer = true; + companyId.value = companyUser.value; }); -async function getCurrentBalance(data) { - currentBalance.value[companyId.value] = { - amount: 0, - code: companies.value.find((c) => c.id === companyId.value)?.code, +async function getClientRisks() { + const filter = { + where: { clientFk: route.params.id, companyFk: companyUser.value }, }; + const { data } = await getClientRisk(filter); + clientRisk.value = data; + return clientRisk.value; +} - for (const balance of data) { - currentBalance.value[balance.companyFk] = { - code: balance.company.code, - amount: balance.amount, - }; +async function getCurrentBalance() { + const currentBalance = (await getClientRisks()).find((balance) => { + return balance.companyFk === companyId.value; + }); + return currentBalance && currentBalance.amount; +} + +async function onFetch(data) { + balances.value = []; + for (const [index, balance] of data.entries()) { + if (index === 0) { + balance.balance = await getCurrentBalance(); + continue; + } + const previousBalance = data[index - 1]; + balance.balance = + previousBalance?.balance - (previousBalance?.debit - previousBalance?.credit); } + balances.value = data; } const showNewPaymentDialog = () => { @@ -169,43 +216,25 @@ const showBalancePdf = ({ id }) => {