0
0
Fork 0

Implement Route autonomous dms

This commit is contained in:
Kevin Martinez 2024-03-03 23:36:14 -03:00
parent b2be4c1380
commit 1073512aae
2 changed files with 67 additions and 15 deletions

View File

@ -27,6 +27,10 @@ const $props = defineProps({
type: Object, type: Object,
default: null, default: null,
}, },
url: {
type: String,
default: null,
},
}); });
const warehouses = ref(); const warehouses = ref();
@ -65,14 +69,15 @@ function mapperDms(data) {
} }
function getUrl() { function getUrl() {
if ($props.url) return $props.url;
if ($props.formInitialData) return 'dms/' + $props.formInitialData.id + '/updateFile'; if ($props.formInitialData) return 'dms/' + $props.formInitialData.id + '/updateFile';
return `${$props.model}/${route.params.id}/uploadFile`; return `${$props.model}/${route.params.id}/uploadFile`;
} }
async function save() { async function save() {
const body = mapperDms(dms.value); const body = mapperDms(dms.value);
await axios.post(getUrl(), body[0], body[1]); const response = await axios.post(getUrl(), body[0], body[1]);
emit('onDataSaved', body[1].params); emit('onDataSaved', body[1].params, response);
} }
function defaultData() { function defaultData() {

View File

@ -12,8 +12,11 @@ import VnLv from 'components/ui/VnLv.vue';
import useNotify from 'composables/useNotify'; import useNotify from 'composables/useNotify';
import RouteAutonomousFilter from 'pages/Route/Card/RouteAutonomousFilter.vue'; import RouteAutonomousFilter from 'pages/Route/Card/RouteAutonomousFilter.vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import RouteSummary from "pages/Route/Card/RouteSummary.vue"; import RouteSummary from 'pages/Route/Card/RouteSummary.vue';
import {useSummaryDialog} from "composables/useSummaryDialog"; import { useSummaryDialog } from 'composables/useSummaryDialog';
import VnDms from 'components/common/VnDms.vue';
import { useState } from 'composables/useState';
import axios from 'axios';
const stateStore = useStateStore(); const stateStore = useStateStore();
const { t } = useI18n(); const { t } = useI18n();
@ -24,6 +27,13 @@ const { viewSummary } = useSummaryDialog();
onMounted(() => (stateStore.rightDrawer = true)); onMounted(() => (stateStore.rightDrawer = true));
onUnmounted(() => (stateStore.rightDrawer = false)); onUnmounted(() => (stateStore.rightDrawer = false));
const state = useState();
const user = state.getUser();
const dmsDialog = ref({
show: false,
initialForm: {},
rowsToCreateInvoiceIn: [],
});
const selectedRows = ref([]); const selectedRows = ref([]);
const columns = computed(() => [ const columns = computed(() => [
{ {
@ -108,8 +118,8 @@ const refreshKey = ref(0);
const total = computed(() => selectedRows.value.reduce((item) => item?.price || 0, 0)); const total = computed(() => selectedRows.value.reduce((item) => item?.price || 0, 0));
const openCreateInvoiceIn = () => { const openDmsUploadDialog = async () => {
const rowsToCreateInvoiceIn = selectedRows.value dmsDialog.value.rowsToCreateInvoiceIn = selectedRows.value
.filter( .filter(
(agencyTerm) => agencyTerm.supplierFk === selectedRows.value?.[0].supplierFk (agencyTerm) => agencyTerm.supplierFk === selectedRows.value?.[0].supplierFk
) )
@ -120,20 +130,44 @@ const openCreateInvoiceIn = () => {
totalPrice: total.value, totalPrice: total.value,
})); }));
if (rowsToCreateInvoiceIn.length !== selectedRows.value.length) { if (dmsDialog.value.rowsToCreateInvoiceIn.length !== selectedRows.value.length) {
dmsDialog.value.rowsToCreateInvoiceIn = [];
dmsDialog.value.initialForm = null;
return notify(t('Two autonomous cannot be counted at the same time'), 'negative'); return notify(t('Two autonomous cannot be counted at the same time'), 'negative');
} }
const params = encodeURI(JSON.stringify({ const dmsType = await axios
supplierName: selectedRows.value?.[0].supplierName, .get('DmsTypes/findOne', {
rows: rowsToCreateInvoiceIn, filter: {
})); where: { code: 'invoiceIn' },
},
})
.then((res) => res.data);
router.push({ name: 'RouteAutonomousCreateInvoiceIn', query: { q: params } }); dmsDialog.value.initialForm = {
description: selectedRows.value?.[0].supplierName,
companyFk: user.value.companyFk,
warehouseFk: user.value.warehouseFk,
dmsTypeFk: dmsType?.id,
};
dmsDialog.value.show = true;
};
const onDmsSaved = async (dms, response) => {
if (response) {
await axios.post('AgencyTerms/createInvoiceIn', {
rows: dmsDialog.value.rowsToCreateInvoiceIn,
dms: response.data,
});
}
dmsDialog.value.show = false;
dmsDialog.value.initialForm = null;
dmsDialog.value.rowsToCreateInvoiceIn = [];
refreshKey.value++;
}; };
function navigateToRouteSummary(event, row) { function navigateToRouteSummary(event, row) {
router.push({ name: 'RouteSummary', params: { id: row.routeFk } }) router.push({ name: 'RouteSummary', params: { id: row.routeFk } });
} }
</script> </script>
@ -238,7 +272,12 @@ function navigateToRouteSummary(event, row) {
name="preview" name="preview"
size="xs" size="xs"
color="primary" color="primary"
@click.stop="viewSummary(props?.row?.routeFk, RouteSummary)" @click.stop="
viewSummary(
props?.row?.routeFk,
RouteSummary
)
"
> >
<QTooltip>{{ t('Preview') }}</QTooltip> <QTooltip>{{ t('Preview') }}</QTooltip>
</QIcon> </QIcon>
@ -255,7 +294,7 @@ function navigateToRouteSummary(event, row) {
fab fab
icon="vn:invoice-in-create" icon="vn:invoice-in-create"
color="primary" color="primary"
@click="openCreateInvoiceIn" @click="openDmsUploadDialog"
> >
<QTooltip> <QTooltip>
{{ t('Create invoiceIn') }} {{ t('Create invoiceIn') }}
@ -263,6 +302,14 @@ function navigateToRouteSummary(event, row) {
</QBtn> </QBtn>
</QPageSticky> </QPageSticky>
</QPage> </QPage>
<QDialog v-model="dmsDialog.show">
<VnDms
url="dms/uploadFile"
model="AgencyTerms"
:form-initial-data="dmsDialog.initialForm"
@on-data-saved="onDmsSaved"
/>
</QDialog>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>