refactor(EntryControl): refs #8277 update file handling and improve dialog management
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
dd908c49ce
commit
3120ca93e6
|
@ -16,17 +16,17 @@ import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
|||
import VnDms from 'src/components/common/VnDms.vue';
|
||||
import { useState } from 'src/composables/useState';
|
||||
import { useQuasar } from 'quasar';
|
||||
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
|
||||
import InvoiceInDescriptorProxy from '../InvoiceIn/Card/InvoiceInDescriptorProxy.vue';
|
||||
import { useStateStore } from 'src/stores/useStateStore';
|
||||
import { downloadFile } from 'src/composables/downloadFile';
|
||||
|
||||
const { t } = useI18n();
|
||||
const quasar = useQuasar();
|
||||
const { notify } = useNotify();
|
||||
const user = useState().getUser();
|
||||
const stateStore = useStateStore();
|
||||
const dialog = ref();
|
||||
const dmsDialog = ref();
|
||||
const updateDialog = ref();
|
||||
const uploadDialog = ref();
|
||||
const MAXDAYS = 365;
|
||||
const DEFAULTDAYS = 60;
|
||||
const dataKey = 'entryControl';
|
||||
|
@ -41,14 +41,16 @@ const countries = ref([]);
|
|||
const entryTypes = ref([]);
|
||||
const entryAccounts = ref([]);
|
||||
const warehouses = ref([]);
|
||||
const defaultDmsDescription = ref();
|
||||
const dmsTypeId = ref();
|
||||
const selectedRows = ref([]);
|
||||
const totalAmount = ref();
|
||||
const totalSelectedAmount = computed(() => {
|
||||
if (!selectedRows.value.length) return 0;
|
||||
return selectedRows.value.reduce((acc, entry) => acc + entry.amount, 0);
|
||||
});
|
||||
let selectedGestDoc;
|
||||
let supplierRef;
|
||||
let dmsFk;
|
||||
const columns = computed(() => [
|
||||
{
|
||||
name: 'id',
|
||||
|
@ -243,50 +245,42 @@ function filterByDaysAgo(val) {
|
|||
|
||||
async function preAccount() {
|
||||
const entries = selectedRows.value;
|
||||
for (const i in entries) {
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const { supplierFk, companyFk } = entries[i];
|
||||
const nextEntry = entries[+i + 1];
|
||||
|
||||
// Has It gestDoc?
|
||||
if (!selectedGestDoc && entries[i].gestDocFk) selectedGestDoc = entries[i];
|
||||
// Is It same supplier and company?
|
||||
if (!dmsFk && entries[i].gestDocFk) dmsFk = entries[i].gestDocFk;
|
||||
if (!nextEntry) break;
|
||||
else if (nextEntry.supplierFk !== supplierFk || nextEntry.companyFk !== companyFk)
|
||||
return notify('Entries must have the same supplier and company', 'negative');
|
||||
}
|
||||
// Is It agricultural?
|
||||
const selectedAgri = entries.at(0);
|
||||
// If It's agricultural, get the supplierRef
|
||||
const firstRow = entries.at(0);
|
||||
try {
|
||||
if (selectedAgri.isAgricultural) {
|
||||
const year = new Date(selectedAgri.landed).getFullYear();
|
||||
if (firstRow.isAgricultural) {
|
||||
const year = new Date(firstRow.landed).getFullYear();
|
||||
supplierRef = (
|
||||
await axios.get('InvoiceIns/getMaxRef', {
|
||||
params: { companyFk: selectedAgri.companyFk, year },
|
||||
params: { companyFk: firstRow.companyFk, year },
|
||||
})
|
||||
).data;
|
||||
return createInvoice(true);
|
||||
} else if (selectedGestDoc) {
|
||||
// If There's an allocated file for an entry? Ask to (update/updload) the file
|
||||
} else if (dmsFk) {
|
||||
supplierRef = (
|
||||
await axios.get(`Dms/${selectedGestDoc.gestDocFk}`, {
|
||||
await axios.get(`Dms/${dmsFk}`, {
|
||||
params: { filter: JSON.stringify({ fields: { reference: true } }) },
|
||||
})
|
||||
).data?.reference;
|
||||
dialog.value.show();
|
||||
updateDialog.value.show();
|
||||
} else {
|
||||
// If There's no gestDoc, upload the file
|
||||
uploadFile();
|
||||
}
|
||||
|
||||
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async function updateFile() {
|
||||
await axios.post(`Dms/${selectedGestDoc.gestDocFk}/updateFile`, { dmsTypeId: 1 }); // Sacar el id de invIN de dmsTYpe
|
||||
await axios.post(`Dms/${dmsFk}/updateFile`, { dmsTypeId });
|
||||
await createInvoice(false);
|
||||
}
|
||||
|
||||
|
@ -294,14 +288,18 @@ async function uploadFile() {
|
|||
const firstSelectedEntry = selectedRows.value.at(0);
|
||||
const { supplier, companyFk, invoiceNumber } = firstSelectedEntry;
|
||||
dmsData.value = {
|
||||
dmsTypeFk: 1,
|
||||
dmsTypeFk: dmsTypeId.value,
|
||||
warehouseFk: user.value.warehouseFk,
|
||||
companyFk: companyFk,
|
||||
description: supplier + '.Fact: ' + invoiceNumber, // Crear col InvocieInConfig, defaultDmsDescription
|
||||
reference: invoiceNumber,
|
||||
description: supplier + defaultDmsDescription.value + invoiceNumber,
|
||||
};
|
||||
dmsDialog.value.show();
|
||||
await createInvoice(false); // Revisar
|
||||
uploadDialog.value.show();
|
||||
}
|
||||
|
||||
async function afterUploadFile({ reference }, res) {
|
||||
supplierRef = reference;
|
||||
dmsFk = res.data[0].id;
|
||||
await createInvoice(false);
|
||||
}
|
||||
|
||||
async function createInvoice(isAgricultural) {
|
||||
|
@ -309,6 +307,7 @@ async function createInvoice(isAgricultural) {
|
|||
await axios.post(`Entries/preAccount`, {
|
||||
ids: selectedRows.value.map((entry) => entry.id),
|
||||
supplierRef,
|
||||
dmsFk,
|
||||
isAgricultural,
|
||||
});
|
||||
} catch (e) {
|
||||
|
@ -316,7 +315,7 @@ async function createInvoice(isAgricultural) {
|
|||
} finally {
|
||||
table.value.reload();
|
||||
supplierRef = null;
|
||||
selectedGestDoc = null;
|
||||
dmsFk = null;
|
||||
selectedRows.value.length = 0;
|
||||
}
|
||||
}
|
||||
|
@ -352,6 +351,19 @@ async function createInvoice(isAgricultural) {
|
|||
@on-fetch="(data) => (entryAccounts = data)"
|
||||
auto-load
|
||||
/>
|
||||
<FetchData
|
||||
url="InvoiceInConfigs/findOne"
|
||||
:filter="{ fields: ['defaultDmsDescription'] }"
|
||||
@on-fetch="(data) => (defaultDmsDescription = data?.defaultDmsDescription)"
|
||||
auto-load
|
||||
/>
|
||||
<FetchData
|
||||
url="DmsTypes/findOne"
|
||||
:filter="{ fields: ['id'] }"
|
||||
:where="{ code: 'invoiceIn' }"
|
||||
@on-fetch="(data) => (dmsTypeId = data?.id)"
|
||||
auto-load
|
||||
/>
|
||||
<VnSearchbar
|
||||
:data-key
|
||||
:url
|
||||
|
@ -359,7 +371,6 @@ async function createInvoice(isAgricultural) {
|
|||
:info="t('entry.control.searchInfo')"
|
||||
:search-remove-params="false"
|
||||
/>
|
||||
<VnSubToolbar />
|
||||
<VnTable
|
||||
v-model:selected="selectedRows"
|
||||
:data-key
|
||||
|
@ -399,7 +410,6 @@ async function createInvoice(isAgricultural) {
|
|||
:decimal-places="0"
|
||||
@update:model-value="filterByDaysAgo"
|
||||
debounce="500"
|
||||
max="365"
|
||||
:title="t('entry.control.daysAgo')"
|
||||
/>
|
||||
</template>
|
||||
|
@ -409,6 +419,11 @@ async function createInvoice(isAgricultural) {
|
|||
<EntryDescriptorProxy :id="row.id" />
|
||||
</span>
|
||||
</template>
|
||||
<template #column-gestDocFk="{ row }">
|
||||
<span class="link" @click.stop="downloadFile(row.gestDocFk)">
|
||||
{{ row.gestDocFk }}
|
||||
</span>
|
||||
</template>
|
||||
<template #column-supplier="{ row }">
|
||||
<span class="link" @click.stop>
|
||||
{{ row.supplier }}
|
||||
|
@ -427,7 +442,7 @@ async function createInvoice(isAgricultural) {
|
|||
</template>
|
||||
</VnTable>
|
||||
<VnConfirm
|
||||
ref="dialog"
|
||||
ref="updateDialog"
|
||||
:title="t('entry.control.dialog.title')"
|
||||
:message="t('entry.control.dialog.message')"
|
||||
>
|
||||
|
@ -449,12 +464,12 @@ async function createInvoice(isAgricultural) {
|
|||
<QBtn :label="t('globals.cancel')" color="primary" flat v-close-popup />
|
||||
</template>
|
||||
</VnConfirm>
|
||||
<QDialog ref="dmsDialog">
|
||||
<QDialog ref="uploadDialog">
|
||||
<VnDms
|
||||
model="dms"
|
||||
:form-initial-data="dmsData"
|
||||
url="Dms/uploadFile"
|
||||
@data-saved="dmsData = null"
|
||||
@on-data-saved="afterUploadFile"
|
||||
/>
|
||||
</QDialog>
|
||||
</template>
|
||||
|
|
Loading…
Reference in New Issue