0
0
Fork 0

feat: refs #7010 added packing type field in customer summary and ticket list

This commit is contained in:
Jon Elias 2024-09-25 14:18:34 +02:00
parent 4ff068aa8a
commit 56af4d3736
2 changed files with 74 additions and 14 deletions

View File

@ -32,6 +32,16 @@ const filter = {
},
{ relation: 'invoiceOut', scope: { fields: ['id'] } },
{ relation: 'agencyMode', scope: { fields: ['name'] } },
{
relation: 'ticketSales',
scope: {
fields: ['id', 'concept', 'itemFk'],
include: { relation: 'item' },
scope: {
fields: ['id', 'name', 'itemPackingTypeFk'],
},
},
},
],
where: { clientFk: route.params.id },
order: ['shipped DESC', 'id'],
@ -87,7 +97,13 @@ const columns = computed(() => [
label: t('Total'),
name: 'total',
},
{
align: 'left',
name: 'itemPackingTypeFk',
label: t('ticketSale.packaging'),
format: (row, dashIfEmpty) =>
dashIfEmpty(row?.ticketSales[0]?.item.itemPackingTypeFk),
},
{
align: 'right',
label: '',

View File

@ -1,6 +1,6 @@
<script setup>
import axios from 'axios';
import { computed, ref, onMounted } from 'vue';
import { computed, ref, onMounted, reactive } from 'vue';
import { useRoute } from 'vue-router';
import { useStateStore } from 'stores/useStateStore';
import { useI18n } from 'vue-i18n';
@ -62,6 +62,7 @@ const dialogData = ref();
const companiesOptions = ref([]);
const accountingOptions = ref([]);
const amountToReturn = ref();
const salesData = reactive({});
const columns = computed(() => [
{
@ -95,6 +96,7 @@ const columns = computed(() => [
columnField: {
component: null,
},
columnClass: 'expand',
format: (row, dashIfEmpty) => dashIfEmpty(row.salesPerson),
},
{
@ -153,11 +155,6 @@ const columns = computed(() => [
},
columnClass: 'expand',
},
{
align: 'left',
name: 'refFk',
label: t('ticketList.ref'),
},
{
align: 'left',
name: 'zoneFk',
@ -191,6 +188,12 @@ const columns = computed(() => [
},
format: (row) => toCurrency(row.totalWithVat),
},
{
align: 'left',
name: 'itemPackageFk',
label: t('ticketSale.packaging'),
format: (row, dashIfEmpty) => dashIfEmpty(row.itemPackageFk),
},
{
align: 'right',
name: 'tableActions',
@ -439,6 +442,41 @@ function setReference(data) {
dialogData.value.value.description = newDescription;
}
async function fetchSalesData(row) {
if (salesData[row.id]) {
return salesData[row.id]; // Retorna de caché si ya existen datos
}
try {
const sales = await getSales(row.id);
const packingTypes = getPackingTypes(sales);
const result = packingTypes.length > 0 ? packingTypes.join(', ') : '-';
salesData[row.id] = result; // Cachea el resultado
return result;
} catch (err) {
console.error('Error fetching sales', err);
salesData[row.id] = 'Error'; // Cachea el error
return 'Error';
}
}
async function getSales(rowId) {
const { data } = await axios.get(`Tickets/${rowId}/getSales`);
return data;
}
function getPackingTypes(sales) {
const itemPackingTypes = [];
sales.forEach((sale) => {
const packingType = sale?.item?.itemPackingTypeFk;
if (packingType && !itemPackingTypes.includes(packingType)) {
itemPackingTypes.push(packingType);
}
});
return itemPackingTypes;
}
</script>
<template>
@ -548,7 +586,7 @@ function setReference(data) {
</template>
<template #column-salesPersonFk="{ row }">
<span class="link" @click.stop>
{{ row.salesPerson }}
{{ dashIfEmpty(row.salesPerson) }}
<CustomerDescriptorProxy :id="row.salesPersonFk" />
</span>
</template>
@ -577,16 +615,16 @@ function setReference(data) {
{{ row.state }}
</QChip>
</span>
<span v-else-if="row.state === 'Entregado'">
<span class="link" @click.stop>
{{ row.refFk }}
<InvoiceOutDescriptorProxy :id="row.invoiceOutId" />
</span>
</span>
<span v-else>
{{ row.state }}
</span>
</template>
<template #column-refFk="{ row }">
<span class="link" @click.stop>
{{ dashIfEmpty(row.refFk) }}
<InvoiceOutDescriptorProxy :id="row.invoiceOutId" />
</span>
</template>
<template #column-zoneFk="{ row }">
<span class="link" @click.stop>
{{ dashIfEmpty(row.zoneName) }}
@ -603,6 +641,12 @@ function setReference(data) {
{{ row.totalWithVat }}
</QChip>
</template>
<template #column-itemPackageFk="{ row }">
<div v-if="salesData[row.id]">{{ dashIfEmpty(salesData[row.id]) }}</div>
<div v-else>
{{ fetchSalesData(row) }}
</div>
</template>
<template #more-create-dialog="{ data }">
<VnRow>
<VnSelect