0
0
Fork 0

Mejoras y cosas faltantes

This commit is contained in:
William Buezas 2024-01-29 16:33:39 -03:00
parent 7eda82bf82
commit 6096123c6e
8 changed files with 339 additions and 130 deletions

View File

@ -1047,7 +1047,9 @@ export default {
entries: 'Entries', entries: 'Entries',
cloneShipping: 'Clone travel', cloneShipping: 'Clone travel',
CloneTravelAndEntries: 'Clone travel and his entries', CloneTravelAndEntries: 'Clone travel and his entries',
deleteTravel: 'Delete travel',
AddEntry: 'Add entry', AddEntry: 'Add entry',
thermographs: 'Thermographs',
}, },
variables: { variables: {
search: 'Id/Reference', search: 'Id/Reference',

View File

@ -1047,7 +1047,9 @@ export default {
entries: 'Entradas', entries: 'Entradas',
cloneShipping: 'Clonar envío', cloneShipping: 'Clonar envío',
CloneTravelAndEntries: 'Clonar travel y sus entradas', CloneTravelAndEntries: 'Clonar travel y sus entradas',
deleteTravel: 'Eliminar envío',
AddEntry: 'Añadir entrada', AddEntry: 'Añadir entrada',
thermographs: 'Termógrafos',
}, },
variables: { variables: {
search: 'Id/Referencia', search: 'Id/Referencia',

View File

@ -1,7 +1,7 @@
<script setup> <script setup>
import { reactive, ref } from 'vue'; import { reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import FormModel from 'components/FormModel.vue'; import FormModel from 'components/FormModel.vue';
import VnRow from 'components/ui/VnRow.vue'; import VnRow from 'components/ui/VnRow.vue';
@ -9,20 +9,27 @@ import VnSelectFilter from 'src/components/common/VnSelectFilter.vue';
import FetchData from 'components/FetchData.vue'; import FetchData from 'components/FetchData.vue';
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue'; import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
import { useState } from 'src/composables/useState';
import { toDate } from 'src/filters'; import { toDate } from 'src/filters';
const state = useState();
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
const router = useRouter();
const user = state.getUser();
const newEntryForm = reactive({ const newEntryForm = reactive({
supplierFk: null, supplierFk: null,
travelFk: route.query?.travelFk || null, travelFk: route.query?.travelFk || null,
companyFk: null, companyFk: user.value.companyFk || null,
}); });
const suppliersOptions = ref([]); const suppliersOptions = ref([]);
const travelsOptionsOptions = ref([]); const travelsOptionsOptions = ref([]);
const companiesOptions = ref([]); const companiesOptions = ref([]);
const redirectToEntryBasicData = (_, { id }) => {
router.push({ name: 'EntryBasicData', params: { id } });
};
</script> </script>
<template> <template>
@ -48,12 +55,14 @@ const companiesOptions = ref([]);
@on-fetch="(data) => (companiesOptions = data)" @on-fetch="(data) => (companiesOptions = data)"
auto-load auto-load
/> />
<!-- Agregar searchbar de entries -->
<QPage> <QPage>
<VnSubToolbar /> <VnSubToolbar />
<FormModel url-create="Entries" model="entry" :form-initial-data="newEntryForm"> <FormModel
url-create="Entries"
model="entry"
:form-initial-data="newEntryForm"
@on-data-saved="redirectToEntryBasicData"
>
<template #form="{ data, validate }"> <template #form="{ data, validate }">
<VnRow class="row q-gutter-md q-mb-md"> <VnRow class="row q-gutter-md q-mb-md">
<VnSelectFilter <VnSelectFilter

View File

@ -2,10 +2,13 @@
import { ref, computed } from 'vue'; import { ref, computed } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { toDate } from 'src/filters';
import CardDescriptor from 'components/ui/CardDescriptor.vue'; import CardDescriptor from 'components/ui/CardDescriptor.vue';
import VnLv from 'src/components/ui/VnLv.vue'; import VnLv from 'src/components/ui/VnLv.vue';
import TravelDescriptorMenuItems from './TravelDescriptorMenuItems.vue';
import useCardDescription from 'src/composables/useCardDescription'; import useCardDescription from 'src/composables/useCardDescription';
import { toDate } from 'src/filters';
const $props = defineProps({ const $props = defineProps({
id: { id: {
@ -28,6 +31,7 @@ const filter = {
'warehouseInFk', 'warehouseInFk',
'warehouseOutFk', 'warehouseOutFk',
'cargoSupplierFk', 'cargoSupplierFk',
'agencyModeFk',
], ],
include: [ include: [
{ {
@ -82,6 +86,9 @@ const setData = (entity) => {
</QTooltip> </QTooltip>
</QBtn> </QBtn>
</template> </template>
<template #menu="{ entity }">
<TravelDescriptorMenuItems :travel="entity" />
</template>
<template #body="{ entity }"> <template #body="{ entity }">
<VnLv :label="t('globals.wareHouseIn')" :value="entity.warehouseIn.name" /> <VnLv :label="t('globals.wareHouseIn')" :value="entity.warehouseIn.name" />
<VnLv :label="t('globals.wareHouseOut')" :value="entity.warehouseOut.name" /> <VnLv :label="t('globals.wareHouseOut')" :value="entity.warehouseOut.name" />
@ -89,10 +96,32 @@ const setData = (entity) => {
<VnLv :label="t('globals.landed')" :value="toDate(entity.landed)" /> <VnLv :label="t('globals.landed')" :value="toDate(entity.landed)" />
<VnLv :label="t('globals.totalEntries')" :value="entity.totalEntries" /> <VnLv :label="t('globals.totalEntries')" :value="entity.totalEntries" />
</template> </template>
<template #actions="{ entity }">
<QCardActions>
<QBtn
:to="{
name: 'TravelList',
query: {
params: JSON.stringify({
agencyModeFk: entity.agencyModeFk,
}),
},
}"
size="md"
icon="local_airport"
color="primary"
>
<QTooltip>{{ t('All travels with current agency') }}</QTooltip>
</QBtn>
</QCardActions>
</template>
</CardDescriptor> </CardDescriptor>
</template> </template>
<i18n> <i18n>
es: es:
Go to module index: Ir al índice del módulo Go to module index: Ir al índice del módulo
The travel will be deleted: El envío será eliminado
Do you want to delete this travel?: ¿Quieres eliminar este envío?
All travels with current agency: Todos los envíos con la agencia actual
</i18n> </i18n>

View File

@ -0,0 +1,108 @@
<script setup>
import { computed } from 'vue';
import { useQuasar } from 'quasar';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import VnConfirm from 'components/ui/VnConfirm.vue';
import axios from 'axios';
import useNotify from 'src/composables/useNotify.js';
import { useRole } from 'src/composables/useRole';
const $props = defineProps({
travel: {
type: Object,
default: () => {},
},
});
const { t } = useI18n();
const router = useRouter();
const quasar = useQuasar();
const { notify } = useNotify();
const role = useRole();
const redirectToCreateView = (queryParams) => {
router.push({ name: 'TravelCreate', query: { travelData: queryParams } });
};
const cloneTravel = () => {
const stringifiedTravelData = JSON.stringify($props.travel);
redirectToCreateView(stringifiedTravelData);
};
const cloneTravelWithEntries = () => {
try {
axios.post(`Travels/${$props.travel.id}/cloneWithEntries`);
notify('globals.dataSaved', 'positive');
} catch (err) {
console.err('Error cloning travel with entries');
}
};
const isBuyer = computed(() => {
return role.hasAny(['buyer']);
});
const openDeleteEntryDialog = (id) => {
quasar
.dialog({
component: VnConfirm,
componentProps: {
title: t('The travel will be deleted'),
message: t('Do you want to delete this travel?'),
},
})
.onOk(async () => {
await deleteTravel(id);
});
};
const deleteTravel = async (id) => {
try {
await axios.delete(`Travels/${id}`);
router.push({ name: 'TravelList' });
notify('globals.dataDeleted', 'positive');
} catch (err) {
console.error('Error deleting travel');
}
};
</script>
<template>
<QItem v-ripple clickable @click="cloneTravel(travel)">
<QItemSection>{{ t('travel.summary.cloneShipping') }}</QItemSection>
</QItem>
<QItem v-ripple clickable @click="cloneTravelWithEntries()">
<QItemSection>
{{ t('travel.summary.CloneTravelAndEntries') }}
</QItemSection>
</QItem>
<QItem
v-if="isBuyer && travel.totalEntries === 0"
v-ripple
clickable
@click="openDeleteEntryDialog(travel.id)"
>
<QItemSection>
{{ t('travel.summary.deleteTravel') }}
</QItemSection>
</QItem>
<QItem v-ripple clickable>
<QItemSection>
<RouterLink
:to="{ name: 'EntryCreate', query: { travelFk: travel.id } }"
class="color-vn-text"
>
{{ t('travel.summary.AddEntry') }}
</RouterLink>
</QItemSection>
</QItem>
</template>
<i18n>
es:
The travel will be deleted: El envío será eliminado
Do you want to delete this travel?: ¿Quieres eliminar este envío?
</i18n>

View File

@ -1,23 +1,20 @@
<script setup> <script setup>
import { onMounted, ref, computed, onUpdated } from 'vue'; import { onMounted, ref, computed, onUpdated } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { QCheckbox, QIcon } from 'quasar';
import CardSummary from 'components/ui/CardSummary.vue'; import CardSummary from 'components/ui/CardSummary.vue';
import VnLv from 'src/components/ui/VnLv.vue'; import VnLv from 'src/components/ui/VnLv.vue';
import EntryDescriptorProxy from 'src/pages/Entry/Card/EntryDescriptorProxy.vue'; import EntryDescriptorProxy from 'src/pages/Entry/Card/EntryDescriptorProxy.vue';
import FetchData from 'src/components/FetchData.vue';
import TravelDescriptorMenuItems from './TravelDescriptorMenuItems.vue';
import travelService from 'src/services/travel.service';
import { toDate, toCurrency } from 'src/filters'; import { toDate, toCurrency } from 'src/filters';
import { getUrl } from 'src/composables/getUrl'; import { getUrl } from 'src/composables/getUrl';
import axios from 'axios'; import axios from 'axios';
onUpdated(() => summaryRef.value.fetch()); onUpdated(() => summaryRef.value.fetch());
const route = useRoute();
const { t } = useI18n();
const $props = defineProps({ const $props = defineProps({
id: { id: {
type: Number, type: Number,
@ -26,36 +23,21 @@ const $props = defineProps({
}, },
}); });
const router = useRouter(); const route = useRoute();
const { t } = useI18n();
const entityId = computed(() => $props.id || route.params.id); const entityId = computed(() => $props.id || route.params.id);
const entries = ref([]);
const summaryRef = ref(); const summaryRef = ref();
const travel = ref();
const travelUrl = ref(); const travelUrl = ref();
const travel = ref();
const entries = ref([]);
const thermographs = ref([]);
const warehouses = ref([]);
onMounted(async () => { onMounted(async () => {
travelUrl.value = (await getUrl('travel/')) + entityId.value; travelUrl.value = (await getUrl('travel/')) + entityId.value;
}); });
const cloneTravel = () => {
const stringifiedTravelData = JSON.stringify(travel.value);
redirectToCreateView(stringifiedTravelData);
};
const cloneTravelWithEntries = () => {
try {
axios.post(`Travels/${$props.id}/cloneWithEntries`);
} catch (err) {
console.err('Error cloning travel with entries');
}
};
const headerMenuOptions = [
{ name: t('travel.summary.cloneShipping'), action: cloneTravel },
{ name: t('travel.summary.CloneTravelAndEntries'), action: cloneTravelWithEntries },
{ name: t('travel.summary.AddEntry'), action: null },
];
const entriesTableColumns = computed(() => { const entriesTableColumns = computed(() => {
return [ return [
{ {
@ -126,25 +108,122 @@ const entriesTableColumns = computed(() => {
]; ];
}); });
const thermographsTableColumns = computed(() => {
return [
{
label: t('travel.thermographs.code'),
field: 'thermographFk',
name: 'thermographFk',
align: 'left',
},
{
label: t('travel.thermographs.temperature'),
field: 'temperatureFk',
name: 'temperatureFk',
align: 'left',
},
{
label: t('travel.thermographs.state'),
field: 'result',
name: 'result',
align: 'left',
},
{
label: t('travel.thermographs.destination'),
field: 'warehouseFk',
name: 'destination',
align: 'left',
format: (val) =>
warehouses.value.find((warehouse) => warehouse.id === val).name,
},
{
label: t('travel.thermographs.created'),
field: 'created',
name: 'created',
align: 'left',
format: (val) => toDate(val),
},
];
});
const entriesTableRows = computed(() => { const entriesTableRows = computed(() => {
if (!entries.value && !entries.value.length > 0) return []; if (!entries.value && !entries.value.length > 0) return [];
return entries.value; return entries.value;
}); });
async function setTravelData(data) { const entriesTotalHb = computed(() => {
if (data) { return entriesTableRows.value.reduce((acc, { hb }) => acc + hb, 0);
travel.value = data; });
const entriesResponse = await travelService.getTravelEntries(travel.value.id);
if (entriesResponse.data) entries.value = entriesResponse.data;
}
}
const redirectToCreateView = (queryParams) => { const entriesTotalFreight = computed(() => {
router.push({ name: 'TravelCreate', query: { travelData: queryParams } }); return toCurrency(
entriesTableRows.value.reduce((acc, { freightValue }) => acc + freightValue, 0)
);
});
const entriesTotalCc = computed(() => {
return entriesTableRows.value.reduce((acc, { cc }) => acc + cc, 0);
});
const entriesTotalPallet = computed(() => {
return entriesTableRows.value.reduce((acc, { pallet }) => acc + pallet, 0);
});
const entriesTotalM3 = computed(() => {
return entriesTableRows.value.reduce((acc, { m3 }) => acc + m3, 0);
});
const getTravelEntries = async (id) => {
try {
const { data } = await axios.get(`Travels/${id}/getEntries`);
entries.value = data;
} catch (err) {
console.error('Error fetching travel entries');
}
}; };
const getTravelThermographs = async (id) => {
try {
const filter = {
include: {
relation: 'warehouse',
scope: {
fields: ['id', 'name'],
},
},
where: { travelFk: id },
};
const { data } = await axios.get('TravelThermographs', {
params: { filter: JSON.parse(JSON.stringify(filter)) },
});
thermographs.value = data;
} catch (err) {
console.error('Error fetching travel thermographs');
}
};
async function setTravelData(travelData) {
try {
if (travelData) {
travel.value = travelData;
await getTravelEntries(travel.value.id);
await getTravelThermographs(travel.value.id);
}
} catch (err) {
console.error(`Error setting travel data`, err);
}
}
</script> </script>
<template> <template>
<FetchData
url="Warehouses"
:filter="{ fields: ['id', 'name'] }"
order="name"
@on-fetch="(data) => (warehouses = data)"
auto-load
/>
<CardSummary <CardSummary
ref="summaryRef" ref="summaryRef"
:url="`Travels/${entityId}/getTravel`" :url="`Travels/${entityId}/getTravel`"
@ -165,10 +244,8 @@ const redirectToCreateView = (queryParams) => {
{{ t('components.cardDescriptor.moreOptions') }} {{ t('components.cardDescriptor.moreOptions') }}
</QTooltip> </QTooltip>
<QMenu> <QMenu>
<QList dense v-for="option in headerMenuOptions" :key="option"> <QList>
<QItem v-ripple clickable @click="option.action"> <TravelDescriptorMenuItems :travel="travel" />
{{ option.name }}
</QItem>
</QList> </QList>
</QMenu> </QMenu>
</QBtn> </QBtn>
@ -214,10 +291,9 @@ const redirectToCreateView = (queryParams) => {
<VnLv :label="t('globals.totalEntries')" :value="travel.m3" /> <VnLv :label="t('globals.totalEntries')" :value="travel.m3" />
</QCard> </QCard>
<QCard class="full-width" v-if="entriesTableRows.length > 0"> <QCard class="full-width" v-if="entriesTableRows.length > 0">
<a class="header" :href="travelUrl + 'entry'"> <span class="header">
{{ t('travel.summary.entries') }} {{ t('travel.summary.entries') }}
<QIcon name="open_in_new" color="primary" /> </span>
</a>
<QTable <QTable
:rows="entriesTableRows" :rows="entriesTableRows"
:columns="entriesTableColumns" :columns="entriesTableColumns"
@ -225,69 +301,71 @@ const redirectToCreateView = (queryParams) => {
row-key="id" row-key="id"
class="full-width q-mt-md" class="full-width q-mt-md"
> >
<!-- <template #body-cell-isConfirmed="{ row }"> <template #header="props">
<QTd auto-width> <QTr :props="props" class="bg">
<QTh v-for="col in props.cols" :key="col.name" :props="props">
{{ t(col.label) }}
</QTh>
</QTr>
</template>
<template #body-cell-isConfirmed="{ col, value }">
<QTd>
<QIcon <QIcon
:name="row.isConfirmed ? 'check' : 'close'" v-if="col.name === 'isConfirmed'"
:color="row.isConfirmed ? 'positive' : 'negative'" :name="value ? 'check' : 'close'"
:color="value ? 'positive' : 'negative'"
size="sm" size="sm"
/> />
</QTd> </QTd>
</template> </template>
<template #body-cell-id="{ row }"> <template #body-cell-id="{ col, value }">
<QTd auto-width> <QTd>
<QBtn flat color="blue"> <QBtn v-if="col.name === 'id'" flat color="blue" dense>
{{ row.id }} {{ value }}
<EntryDescriptorProxy :id="row.id" /> <EntryDescriptorProxy :id="value" />
</QBtn> </QBtn>
</QTd> </QTd>
</template> </template>
<template #body-cell-observation="{ row }"> <template #body-cell-observation="{ value }">
<QTd auto-width> <QTd>
<QIcon <QIcon name="insert_drive_file" color="primary" size="24px">
v-if="row.observation" <QTooltip>{{ value }}</QTooltip>
name="insert_drive_file" </QIcon>
color="primary"
size="sm"
/>
</QTd> </QTd>
</template> -->
<!-- <template #body="props">
<QTr :props="props" :key="`m_${props.row.index}`">
<QTd v-for="col in props.cols" :key="col.name" :props="props">
<template v-if="col.showValue">{{ col.value }}</template>
</QTd>
</QTr>
<QTr
:props="props"
:key="`e_${props.row.index}`"
class="q-virtual-scroll--with-prev"
>
<QTd colspan="100%">
<div class="text-left">
This is the second row generated from the same data:
</div>
</QTd>
</QTr>
</template> -->
<template #body-cell="props">
<QTd :props="props">
<QTr :props="props" :key="`m_${props.row.index}`">
<template v-if="props.col.showValue">
{{ props.value }}
</template> </template>
</QTr> <template #bottom-row>
</QTd> <QTd></QTd>
<QTd :props="props"> <QTd></QTd>
<QTr :props="props" :key="`m_${props.row.index}`"> <QTd></QTd>
<template v-if="props.col.showValue"> <QTd></QTd>
{{ props.value }} <QTd class="text-bold">{{ entriesTotalHb }}</QTd>
</template> <QTd class="text-bold">{{ entriesTotalFreight }}</QTd>
</QTr> <QTd class="text-bold">{{ entriesTotalCc }}</QTd>
</QTd> <QTd class="text-bold">{{ entriesTotalPallet }}</QTd>
<QTd class="text-bold">{{ entriesTotalM3 }}</QTd>
</template> </template>
</QTable> </QTable>
</QCard> </QCard>
<QCard class="full-width" v-if="thermographs.length > 0">
<RouterLink
class="header"
:to="{
name: 'TravelThermographsIndex',
params: { id: travel.id },
}"
>
{{ t('travel.summary.thermographs') }}
<QIcon name="open_in_new" color="primary" />
</RouterLink>
<QTable
:rows="thermographs"
:columns="thermographsTableColumns"
hide-bottom
row-key="id"
class="full-width q-mt-md"
/>
</QCard>
</template> </template>
</CardSummary> </CardSummary>
</template> </template>

View File

@ -16,7 +16,7 @@ import { toCurrency } from 'src/filters';
import { useArrayData } from 'composables/useArrayData'; import { useArrayData } from 'composables/useArrayData';
import { toDate } from 'src/filters'; import { toDate } from 'src/filters';
import { usePrintService } from 'composables/usePrintService'; import { usePrintService } from 'composables/usePrintService';
import travelService from 'src/services/travel.service'; import axios from 'axios';
const router = useRouter(); const router = useRouter();
const stateStore = useStateStore(); const stateStore = useStateStore();
@ -222,9 +222,13 @@ const openReportPdf = () => {
}; };
const saveFieldValue = async (val, field, index) => { const saveFieldValue = async (val, field, index) => {
try {
const id = rows.value[index].id; const id = rows.value[index].id;
const params = { [field]: val }; const params = { [field]: val };
await travelService.updateTravel(id, params); await axios.patch(`Travels/${id}`, params);
} catch (err) {
console.error('Error updating travel');
}
}; };
const navigateToTravelId = (id) => { const navigateToTravelId = (id) => {

View File

@ -1,23 +0,0 @@
import axios from 'axios';
const travelService = {
getTravelEntries: async (param) => {
try {
return await axios.get(`Travels/${param}/getEntries`);
} catch (err) {
console.error(`Error fetching travel entries`, err);
return err.response;
}
},
updateTravel: async (id, params) => {
try {
return await axios.patch(`Travels/${id}`, params);
} catch (err) {
console.error(`Error updating travel`, err);
return err.response;
}
},
};
export default travelService;