fix(CustomerBalance): getClientRisk
gitea/salix-front/pipeline/pr-master This commit looks good
Details
gitea/salix-front/pipeline/pr-master This commit looks good
Details
This commit is contained in:
parent
8c78991163
commit
700fb7481b
|
@ -5,7 +5,7 @@ import { useRoute } from 'vue-router';
|
|||
import { useAcl } from 'src/composables/useAcl';
|
||||
import axios from 'axios';
|
||||
import { useQuasar } from 'quasar';
|
||||
import FetchData from 'components/FetchData.vue';
|
||||
import { getClientRisk } from '../composables/getClientRisk';
|
||||
|
||||
import { toCurrency, toDate, toDateHourMin } from 'src/filters';
|
||||
import { useState } from 'composables/useState';
|
||||
|
@ -16,7 +16,7 @@ import { useVnConfirm } from 'composables/useVnConfirm';
|
|||
import VnTable from 'components/VnTable/VnTable.vue';
|
||||
import VnInput from 'components/common/VnInput.vue';
|
||||
import VnSubToolbar from 'components/ui/VnSubToolbar.vue';
|
||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||
import VnFilter from 'components/VnTable/VnFilter.vue';
|
||||
|
||||
import CustomerNewPayment from 'src/pages/Customer/components/CustomerNewPayment.vue';
|
||||
import InvoiceOutDescriptorProxy from 'src/pages/InvoiceOut/Card/InvoiceOutDescriptorProxy.vue';
|
||||
|
@ -25,7 +25,7 @@ const { openConfirmationModal } = useVnConfirm();
|
|||
const { sendEmail, openReport } = usePrintService();
|
||||
const { t } = useI18n();
|
||||
const { hasAny } = useAcl();
|
||||
const currentBalance = ref({});
|
||||
|
||||
const quasar = useQuasar();
|
||||
const route = useRoute();
|
||||
const state = useState();
|
||||
|
@ -33,28 +33,53 @@ const stateStore = useStateStore();
|
|||
const user = state.getUser();
|
||||
|
||||
const clientRisk = ref([]);
|
||||
const companies = ref([]);
|
||||
const tableRef = ref();
|
||||
const companyId = ref(user.value.companyFk);
|
||||
const companyId = ref();
|
||||
const companyUser = ref(user.value.companyFk);
|
||||
const balances = ref([]);
|
||||
const vnFilterRef = ref({});
|
||||
const filter = computed(() => {
|
||||
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,
|
||||
};
|
||||
|
||||
for (const balance of data) {
|
||||
currentBalance.value[balance.companyFk] = {
|
||||
code: balance.company.code,
|
||||
amount: balance.amount,
|
||||
async function getClientRisks() {
|
||||
const filter = {
|
||||
where: { clientFk: route.params.id, companyFk: companyUser.value },
|
||||
};
|
||||
const { data } = await getClientRisk(filter);
|
||||
clientRisk.value = data;
|
||||
return clientRisk.value;
|
||||
}
|
||||
|
||||
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 }) => {
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<FetchData
|
||||
url="Companies"
|
||||
auto-load
|
||||
@on-fetch="(data) => (companies = data)"
|
||||
></FetchData>
|
||||
<FetchData
|
||||
v-if="companies.length > 0"
|
||||
url="clientRisks"
|
||||
:filter="{
|
||||
include: { relation: 'company', scope: { fields: ['code'] } },
|
||||
where: { clientFk: route.params.id },
|
||||
}"
|
||||
auto-load
|
||||
@on-fetch="getCurrentBalance"
|
||||
></FetchData>
|
||||
|
||||
<VnSubToolbar class="q-mb-md">
|
||||
<template #st-data>
|
||||
<div class="column justify-center q-px-md q-py-sm">
|
||||
<span class="text-bold">{{ t('Total by company') }}</span>
|
||||
<div class="row justify-center">
|
||||
{{ currentBalance[companyId]?.code }}:
|
||||
{{ toCurrency(currentBalance[companyId]?.amount) }}
|
||||
<div class="row justify-center" v-if="clientRisk?.length">
|
||||
{{ clientRisk[0].company.code }}:
|
||||
{{ toCurrency(clientRisk[0].amount) }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #st-actions>
|
||||
<div>
|
||||
<VnSelect
|
||||
:label="t('Company')"
|
||||
<VnFilter
|
||||
ref="vnFilterRef"
|
||||
v-model="companyId"
|
||||
data-key="CustomerBalance"
|
||||
:options="companies"
|
||||
option-label="code"
|
||||
option-value="id"
|
||||
></VnSelect>
|
||||
:column="companyFilterColumn"
|
||||
search-url="balance"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</VnSubToolbar>
|
||||
|
@ -219,6 +248,7 @@ const showBalancePdf = ({ id }) => {
|
|||
:right-search="false"
|
||||
:is-editable="false"
|
||||
:column-search="false"
|
||||
@on-fetch="onFetch"
|
||||
:disable-option="{ card: true }"
|
||||
auto-load
|
||||
>
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import axios from 'axios';
|
||||
|
||||
export async function getClientRisk(_filter) {
|
||||
const filter = {
|
||||
..._filter,
|
||||
include: { relation: 'company', scope: { fields: ['code'] } },
|
||||
};
|
||||
|
||||
return await axios(`ClientRisks`, {
|
||||
params: { filter: JSON.stringify(filter) },
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue