fix: customerDefaulter correct functionality
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2024-07-18 08:19:08 +02:00
parent c253959e01
commit 83596daf76
6 changed files with 159 additions and 252 deletions

View File

@ -147,7 +147,7 @@ const col = computed(() => {
}
if (
(newColumn.name.startsWith('is') || newColumn.name.startsWith('has')) &&
!newColumn.component
newColumn.component == null
)
newColumn.component = 'checkbox';
if ($props.default && !newColumn.component) newColumn.component = $props.default;

View File

@ -1,7 +1,7 @@
<script setup>
import { ref } from 'vue';
import { useArrayData } from 'composables/useArrayData';
const model = defineModel({ type: Object, required: true });
const model = defineModel({ type: Object });
const $props = defineProps({
name: {
type: String,
@ -56,7 +56,7 @@ defineExpose({ orderBy });
<span :title="label">{{ label }}</span>
<QChip
v-if="name"
:label="!vertical && model?.index"
:label="!vertical ? model?.index : ''"
:icon="
(model?.index || hover) && !vertical
? model?.direction == 'DESC'

View File

@ -92,9 +92,9 @@ const route = useRoute();
const router = useRouter();
const quasar = useQuasar();
const DEFAULT_MODE = 'card';
const CARD_MODE = 'card';
const TABLE_MODE = 'table';
const mode = ref(DEFAULT_MODE);
const mode = ref(CARD_MODE);
const selected = ref([]);
const routeQuery = JSON.parse(route?.query[$props.searchUrl] ?? '{}');
const params = ref({ ...routeQuery, ...routeQuery.filter?.where });
@ -113,13 +113,16 @@ const tableModes = [
{
icon: 'grid_view',
title: t('grid view'),
value: DEFAULT_MODE,
value: CARD_MODE,
disable: $props.disableOption?.card,
},
];
onMounted(() => {
mode.value = quasar.platform.is.mobile ? DEFAULT_MODE : $props.defaultMode;
mode.value =
quasar.platform.is.mobile && !$props.disableOption?.card
? CARD_MODE
: $props.defaultMode;
stateStore.rightDrawer = true;
setUserParams(route.query[$props.searchUrl]);
columnsVisibilitySkiped.value = [
@ -208,6 +211,7 @@ function stopEventPropagation(event) {
}
function reload(params) {
selected.value = [];
CrudModelRef.value.reload(params);
}

View File

@ -17,15 +17,17 @@ const $props = defineProps({
},
});
let mixed;
const componentArray = computed(() => {
if (typeof $props.prop === 'object') return [$props.prop];
return $props.prop;
});
function mix(toComponent) {
if (mixed) return mixed;
const { component, attrs, event } = toComponent;
const customComponent = $props.components[component];
return {
mixed = {
component: customComponent?.component ?? component,
attrs: {
...toValueAttrs(attrs),
@ -35,6 +37,7 @@ function mix(toComponent) {
},
event: event ?? customComponent?.event,
};
return mixed;
}
function toValueAttrs(attrs) {

View File

@ -1,9 +1,8 @@
<script setup>
import { ref, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { QBtn, QCheckbox, useQuasar } from 'quasar';
import { useQuasar } from 'quasar';
import { toCurrency, toDate, dateRange } from 'filters/index';
import VnPaginate from 'src/components/ui/VnPaginate.vue';
import CustomerNotificationsFilter from './CustomerDefaulterFilter.vue';
import CustomerBalanceDueTotal from './CustomerBalanceDueTotal.vue';
import CustomerDescriptorProxy from 'src/pages/Customer/Card/CustomerDescriptorProxy.vue';
@ -11,8 +10,9 @@ import WorkerDescriptorProxy from 'src/pages/Worker/Card/WorkerDescriptorProxy.v
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
import VnInput from 'src/components/common/VnInput.vue';
import CustomerDefaulterAddObservation from './CustomerDefaulterAddObservation.vue';
import axios from 'axios';
import DepartmentDescriptorProxy from 'src/pages/Department/Card/DepartmentDescriptorProxy.vue';
import RightMenu from 'src/components/common/RightMenu.vue';
import VnTable from 'src/components/VnTable/VnTable.vue';
const { t } = useI18n();
const quasar = useQuasar();
@ -21,175 +21,139 @@ const dataRef = ref(null);
const balanceDueTotal = ref(0);
const selected = ref([]);
const tableColumnComponents = {
clientFk: {
component: QBtn,
props: () => ({ flat: true, class: 'link', noCaps: true }),
event: () => {},
},
isWorker: {
component: QCheckbox,
props: (prop) => ({
disable: true,
'model-value': Boolean(prop.value),
}),
event: () => {},
},
salesPerson: {
component: QBtn,
props: () => ({ flat: true, class: 'link', noCaps: true }),
event: () => {},
},
departmentName: {
component: 'span',
props: () => {},
event: () => {},
},
country: {
component: 'span',
props: () => {},
event: () => {},
},
payMethod: {
component: 'span',
props: () => {},
event: () => {},
},
balance: {
component: 'span',
props: () => {},
event: () => {},
},
author: {
component: QBtn,
props: () => ({ flat: true, class: 'link', noCaps: true }),
event: () => {},
},
lastObservation: {
component: 'span',
props: () => {},
event: () => {},
},
date: {
component: 'span',
props: () => {},
event: () => {},
},
credit: {
component: 'span',
props: () => {},
event: () => {},
},
from: {
component: 'span',
props: () => {},
event: () => {},
},
finished: {
component: QCheckbox,
props: (prop) => ({
disable: true,
'model-value': prop.value,
}),
event: () => {},
},
};
const columns = computed(() => [
{
align: 'left',
field: 'clientName',
label: t('Client'),
name: 'clientFk',
sortable: true,
label: t('Client'),
columnFilter: {
component: 'select',
attrs: {
url: 'Clients',
fields: ['id', 'name'],
},
},
},
{
align: 'left',
field: ({ isWorker }) => Boolean(isWorker),
label: t('Is worker'),
name: 'isWorker',
label: t('Is worker'),
},
{
align: 'left',
field: 'salesPersonName',
name: 'salesPersonFk',
label: t('Salesperson'),
name: 'salesPerson',
sortable: true,
columnFilter: {
component: 'select',
attrs: {
url: 'Workers/activeWithInheritedRole',
fields: ['id', 'name'],
where: { role: 'salesPerson' },
useLike: false,
optionValue: 'id',
optionLabel: 'name',
optionFilter: 'firstName',
},
},
},
{
align: 'left',
field: 'departmentName',
name: 'departmentFk',
label: t('Department'),
name: 'departmentName',
sortable: true,
columnFilter: {
component: 'select',
attrs: {
url: 'Departments',
fields: ['id', 'name'],
},
},
},
{
align: 'left',
field: 'country',
name: 'countryFk',
label: t('Country'),
name: 'country',
sortable: true,
format: ({ country }) => country,
columnFilter: {
component: 'select',
attrs: {
url: 'Countries',
fields: ['id', 'name'],
},
},
},
{
align: 'left',
field: 'payMethod',
label: t('P. Method'),
name: 'payMethod',
sortable: true,
tooltip: t('Pay method'),
label: t('P. Method'),
columnFilter: {
component: 'select',
attrs: {
url: 'Paymethods',
},
},
},
{
align: 'left',
field: ({ amount }) => toCurrency(amount),
name: 'amount',
label: t('Balance D.'),
name: 'balance',
sortable: true,
tooltip: t('Balance due'),
format: ({ amount }) => toCurrency(amount),
},
{
align: 'left',
field: 'workerName',
name: 'workerFk',
label: t('Author'),
name: 'author',
sortable: true,
tooltip: t('Worker who made the last observation'),
columnFilter: {
component: 'select',
attrs: {
url: 'Workers/activeWithInheritedRole',
fields: ['id', 'name'],
useLike: false,
optionValue: 'id',
optionLabel: 'name',
optionFilter: 'firstName',
},
},
},
{
align: 'left',
field: 'observation',
name: 'observation',
label: t('Last observation'),
name: 'lastObservation',
sortable: true,
columnClass: 'expand',
},
{
align: 'left',
field: ({ created }) => toDate(created),
name: 'created',
label: t('L. O. Date'),
name: 'date',
sortable: true,
format: ({ created }) => toDate(created),
tooltip: t('Last observation date'),
columnFilter: {
component: 'date',
},
},
{
align: 'left',
field: ({ creditInsurance }) => toCurrency(creditInsurance),
name: 'creditInsurance',
format: ({ creditInsurance }) => toCurrency(creditInsurance),
label: t('Credit I.'),
name: 'credit',
sortable: true,
tooltip: t('Credit insurance'),
columnFilter: {
component: 'number',
},
},
{
align: 'left',
field: ({ defaulterSinced }) => toDate(defaulterSinced),
name: 'defaulterSinced',
format: ({ defaulterSinced }) => toDate(defaulterSinced),
label: t('From'),
name: 'from',
sortable: true,
columnFilter: {
component: 'date',
},
},
{
align: 'left',
field: 'finished',
label: t('Has recover'),
name: 'finished',
label: t('Has recovery'),
name: 'hasRecovery',
},
]);
@ -198,22 +162,12 @@ const viewAddObservation = (rowsSelected) => {
component: CustomerDefaulterAddObservation,
componentProps: {
clients: rowsSelected,
promise: async () => await dataRef.value.fetch(),
promise: async () => await dataRef.value.reload(),
},
});
};
const onFetch = async (data) => {
const recoveryData = await axios.get('Recoveries');
const recoveries = recoveryData.data.map(({ clientFk, finished }) => ({
clientFk,
finished,
}));
data.forEach((item) => {
const recovery = recoveries.find(({ clientFk }) => clientFk === item.clientFk);
item.finished = recovery?.finished === null;
});
balanceDueTotal.value = data.reduce((acc, { amount = 0 }) => acc + amount, 0);
};
@ -229,7 +183,7 @@ function exprBuilder(param, value) {
case 'payMethod':
case 'salesPersonFk':
return { [`d.${param}`]: value };
case 'date':
case 'created':
return { 'd.created': { between: dateRange(value) } };
case 'defaulterSinced':
return { 'd.defaulterSinced': { between: dateRange(value) } };
@ -246,123 +200,63 @@ function exprBuilder(param, value) {
<VnSubToolbar>
<template #st-data>
<CustomerBalanceDueTotal :amount="balanceDueTotal" />
<div class="flex items-center q-ml-lg">
<QBtn
color="primary"
icon="vn:notes"
:disabled="!selected.length"
@click.stop="viewAddObservation(selected)"
>
<QTooltip>{{ t('Add observation') }}</QTooltip>
</QBtn>
</div>
</template>
<template #st-actions>
<QBtn
color="primary"
icon="vn:notes"
:disabled="!selected.length"
@click.stop="viewAddObservation(selected)"
>
<QTooltip>{{ t('Add observation') }}</QTooltip>
</QBtn>
</template>
</VnSubToolbar>
<QPage class="column items-center q-pa-md">
<VnPaginate
ref="dataRef"
@on-fetch="onFetch"
data-key="CustomerDefaulter"
:filter="filter"
:expr-builder="exprBuilder"
auto-load
url="Defaulters/filter"
>
<template #body="{ rows }">
<div class="q-pa-md">
<QTable
:columns="columns"
:rows="rows"
class="full-width"
row-key="clientFk"
selection="multiple"
v-model:selected="selected"
>
<template #header="props">
<QTr :props="props" class="bg" style="min-height: 200px">
<QTh>
<QCheckbox v-model="props.selected" />
</QTh>
<QTh
v-for="col in props.cols"
:key="col.name"
:props="props"
>
{{ t(col.label) }}
<QTooltip v-if="col.tooltip">{{
col.tooltip
}}</QTooltip>
</QTh>
</QTr>
</template>
<template #body-cell="props">
<QTd :props="props">
<QTr :props="props" class="cursor-pointer">
<component
:is="
tableColumnComponents[props.col.name]
.component
"
class="col-content"
v-bind="
tableColumnComponents[props.col.name].props(
props
)
"
@click="
tableColumnComponents[props.col.name].event(
props
)
"
>
<template v-if="typeof props.value !== 'boolean'">
<div
v-if="
props.col.name === 'lastObservation'
"
>
<VnInput
type="textarea"
v-model="props.value"
readonly
dense
rows="2"
/>
</div>
<div v-else>{{ props.value }}</div>
</template>
<WorkerDescriptorProxy
:id="props.row.salesPersonFk"
v-if="props.col.name === 'salesPerson'"
/>
<WorkerDescriptorProxy
:id="props.row.workerFk"
v-if="props.col.name === 'author'"
/>
<CustomerDescriptorProxy
:id="props.row.clientFk"
v-if="props.col.name === 'client'"
/>
</component>
</QTr>
</QTd>
</template>
</QTable>
</div>
</template>
</VnPaginate>
</QPage>
<VnTable
ref="dataRef"
data-key="CustomerDefaulter"
url="Defaulters/filter"
:expr-builder="exprBuilder"
:columns="columns"
@on-fetch="onFetch"
:use-model="true"
:table="{
'row-key': 'clientFk',
selection: 'multiple',
}"
v-model:selected="selected"
:disable-option="{ card: true }"
auto-load
>
<template #column-clientFk="{ row }">
<span class="link" @click.stop>
{{ row.clientName }}
<CustomerDescriptorProxy :id="row.clientFk" />
</span>
</template>
<template #column-observation="{ row }">
<VnInput type="textarea" v-model="row.observation" readonly dense rows="2" />
</template>
<template #column-salesPersonFk="{ row }">
<span class="link" @click.stop>
{{ row.salesPersonName }}
<WorkerDescriptorProxy :id="row.salesPersonFk" />
</span>
</template>
<template #column-departmentFk="{ row }">
<span class="link" @click.stop>
{{ row.departmentName }}
<DepartmentDescriptorProxy :id="row.departmentFk" />
</span>
</template>
<template #column-workerFk="{ row }">
<span class="link" @click.stop>
{{ row.workerName }}
<WorkerDescriptorProxy :id="row.workerFk" />
</span>
</template>
</VnTable>
</template>
<style lang="scss" scoped>
.col-content {
border-radius: 4px;
padding: 6px;
}
</style>
<i18n>
es:
Add observation: Añadir observación
@ -383,4 +277,5 @@ es:
Credit I.: Crédito A.
Credit insurance: Crédito asegurado
From: Desde
Has recovery: Tiene recobro
</i18n>

View File

@ -33,24 +33,28 @@ const columns = computed(() => [
},
},
columnClass: 'expand',
isTitle: true,
},
{
align: 'left',
field: 'city',
label: t('City'),
name: 'city',
cardVisible: true,
},
{
align: 'left',
field: 'phone',
label: t('Phone'),
name: 'phone',
cardVisible: true,
},
{
align: 'left',
field: 'email',
label: t('Email'),
name: 'email',
cardVisible: true,
},
]);
</script>
@ -78,6 +82,7 @@ const columns = computed(() => [
selection: 'multiple',
}"
v-model:selected="selected"
:right-search="false"
:columns="columns"
:use-model="true"
auto-load