0
0
Fork 0

fix: refs #7353 salesClientTable

This commit is contained in:
Jorge Penadés 2024-08-16 13:54:37 +02:00
parent 4b2f4ffac1
commit a13ea900ce
3 changed files with 88 additions and 84 deletions

View File

@ -1,44 +1,33 @@
<script setup> <script setup>
import { ref, computed, reactive, watch } from 'vue'; import { ref, computed } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import FetchData from 'components/FetchData.vue';
import WorkerDescriptorProxy from 'src/pages/Worker/Card/WorkerDescriptorProxy.vue'; import WorkerDescriptorProxy from 'src/pages/Worker/Card/WorkerDescriptorProxy.vue';
import CustomerDescriptorProxy from 'src/pages/Customer/Card/CustomerDescriptorProxy.vue'; import CustomerDescriptorProxy from 'src/pages/Customer/Card/CustomerDescriptorProxy.vue';
import { toDateFormat } from 'src/filters/date.js'; import { toDateFormat } from 'src/filters/date.js';
import VnTable from 'src/components/VnTable/VnTable.vue'; import VnTable from 'src/components/VnTable/VnTable.vue';
import VnInputDate from 'src/components/common/VnInputDate.vue';
import VnRow from 'src/components/ui/VnRow.vue';
const { t } = useI18n(); const { t } = useI18n();
const paginateRef = ref(null);
const workersActiveOptions = ref([]);
const clientsOptions = ref([]);
const from = ref(Date.vnNew()); const from = ref(Date.vnNew());
const to = ref(Date.vnNew()); const to = ref(Date.vnNew());
const dateRange = computed(() => { const filter = computed(() => {
const minHour = new Date(from.value); const obj = {};
minHour.setHours(0, 0, 0, 0); const formatFrom = setHours(from.value, 'from');
const maxHour = new Date(to.value); const formatTo = setHours(to.value, 'to');
maxHour.setHours(23, 59, 59, 59);
return [minHour, maxHour]; if (!formatFrom && formatTo)
Object.assign(obj, { where: { 'v.stamp': { lte: formatTo } } });
else if (formatFrom && !formatTo)
Object.assign(obj, { where: { 'v.stamp': { gte: formatFrom } } });
else if (formatFrom && formatTo)
Object.assign(obj, {
where: { 'v.stamp': { between: [formatFrom, formatTo] } },
}); });
const filter = reactive({ return obj;
where: {
'v.stamp': {
between: dateRange.value,
},
},
});
const refetch = async () => await paginateRef.value.fetch();
watch(dateRange, (val) => {
filter.where['v.stamp'].between = val;
refetch();
}); });
function exprBuilder(param, value) { function exprBuilder(param, value) {
@ -50,7 +39,14 @@ function exprBuilder(param, value) {
} }
} }
const params = reactive({}); function setHours(date, type) {
if (!date) return null;
const d = new Date(date);
if (type == 'from') d.setHours(0, 0, 0, 0);
else d.setHours(23, 59, 59, 59);
return d;
}
const columns = computed(() => [ const columns = computed(() => [
{ {
@ -58,8 +54,7 @@ const columns = computed(() => [
name: 'dated', name: 'dated',
field: 'dated', field: 'dated',
align: 'left', align: 'left',
columnFilter: null, columnFilter: false,
sortable: true,
format: (row) => toDateFormat(row.dated), format: (row) => toDateFormat(row.dated),
}, },
{ {
@ -67,60 +62,66 @@ const columns = computed(() => [
name: 'hour', name: 'hour',
field: 'hour', field: 'hour',
align: 'left', align: 'left',
sortable: true, columnFilter: false,
}, },
{ {
label: t('salesClientsTable.salesPerson'), label: t('salesClientsTable.salesPerson'),
name: 'salesPerson', name: 'salesPersonFk',
field: 'salesPerson', field: 'salesPerson',
align: 'left', align: 'left',
sortable: true,
columnField: { columnField: {
component: null, component: null,
}, },
optionFilter: 'firstName',
columnFilter: {
component: 'select',
attrs: {
url: 'Workers/activeWithInheritedRole',
fields: ['id', 'name'],
sortBy: 'nickname ASC',
where: { role: 'salesPerson' },
useLike: false,
},
},
}, },
{ {
label: t('salesClientsTable.client'), label: t('salesClientsTable.client'),
field: 'clientName', field: 'clientName',
name: 'client', name: 'clientFk',
align: 'left', align: 'left',
sortable: true,
columnField: { columnField: {
component: null, component: null,
}, },
orderBy: 'c.name',
columnFilter: {
component: 'select',
attrs: {
url: 'Clients',
fields: ['id', 'name'],
sortBy: 'name ASC',
},
},
}, },
]); ]);
</script> </script>
<template> <template>
<FetchData
url="Workers/activeWithInheritedRole"
:filter="{
fields: ['id', 'nickname'],
order: 'nickname ASC',
where: { role: 'salesPerson' },
}"
auto-load
@on-fetch="(data) => (workersActiveOptions = data)"
/>
<FetchData
url="Clients"
:filter="{
fields: ['id', 'name'],
order: 'name ASC',
}"
auto-load
@on-fetch="(data) => (clientsOptions = data)"
/>
<QCard style="max-height: 380px; overflow-y: scroll"> <QCard style="max-height: 380px; overflow-y: scroll">
<QCardSection>
<VnRow>
<VnInputDate v-model="from" label="From" dense style="flex: 0.25" />
<VnInputDate v-model="to" label="To" dense style="flex: 0.25" />
</VnRow>
</QCardSection>
<QCardSection>
<VnTable <VnTable
ref="paginateRef" ref="table"
data-key="SalesMonitorClients" data-key="SalesMonitorClients"
url="SalesMonitors/clientsFilter" url="SalesMonitors/clientsFilter"
search-url="SalesMonitorClients"
:order="['dated DESC', 'hour DESC']" :order="['dated DESC', 'hour DESC']"
:limit="6" :limit="6"
:expr-builder="exprBuilder" :expr-builder="exprBuilder"
:user-params="params"
:filter="filter" :filter="filter"
:offset="50" :offset="50"
auto-load auto-load
@ -130,18 +131,19 @@ const columns = computed(() => [
dense dense
:without-header="true" :without-header="true"
> >
<template #column-salesPerson="{ row }"> <template #column-salesPersonFk="{ row }">
<QTd> <QTd>
<span class="link">{{ row.salesPerson }}</span> <span class="link">{{ row.salesPerson }}</span>
<WorkerDescriptorProxy :id="row.salesPersonFk" dense /> <WorkerDescriptorProxy :id="row.salesPersonFk" dense />
</QTd> </QTd>
</template> </template>
<template #column-client="{ row }"> <template #column-clientFk="{ row }">
<QTd> <QTd>
<span class="link">{{ row.clientName }}</span> <span class="link">{{ row.clientName }}</span>
<CustomerDescriptorProxy :id="row.clientFk" /> <CustomerDescriptorProxy :id="row.clientFk" />
</QTd> </QTd>
</template> </template>
</VnTable> </VnTable>
</QCardSection>
</QCard> </QCard>
</template> </template>

View File

@ -129,6 +129,7 @@ const redirectToOrderSummary = (orderId) => {
ref="paginateRef" ref="paginateRef"
data-key="SalesMonitorOrders" data-key="SalesMonitorOrders"
url="SalesMonitors/ordersFilter" url="SalesMonitors/ordersFilter"
search-url="SalesMonitorOrders"
order="date_make DESC" order="date_make DESC"
:limit="6" :limit="6"
:right-search="false" :right-search="false"

View File

@ -430,6 +430,7 @@ const redirectToSales = (id) => {
ref="paginateRef" ref="paginateRef"
data-key="SalesMonitorTickets" data-key="SalesMonitorTickets"
url="SalesMonitors/salesFilter" url="SalesMonitors/salesFilter"
search-url="SalesMonitorTickets"
:filter="filter" :filter="filter"
:limit="20" :limit="20"
:expr-builder="exprBuilder" :expr-builder="exprBuilder"