feat: refs #8277 add invoice confirmation dialog and total amount calculation in EntryControl
This commit is contained in:
parent
232cb7b4f4
commit
1117d3d07a
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, markRaw, useTemplateRef, onBeforeMount } from 'vue';
|
import { ref, computed, markRaw, useTemplateRef, onBeforeMount, watch } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { toDate, toCurrency } from 'src/filters';
|
import { toDate, toCurrency } from 'src/filters';
|
||||||
import { useArrayData } from 'src/composables/useArrayData';
|
import { useArrayData } from 'src/composables/useArrayData';
|
||||||
|
@ -15,8 +15,10 @@ import useNotify from 'src/composables/useNotify';
|
||||||
import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
||||||
import VnDms from 'src/components/common/VnDms.vue';
|
import VnDms from 'src/components/common/VnDms.vue';
|
||||||
import { useState } from 'src/composables/useState';
|
import { useState } from 'src/composables/useState';
|
||||||
|
import { useQuasar } from 'quasar';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const quasar = useQuasar();
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
const user = useState().getUser();
|
const user = useState().getUser();
|
||||||
const dialog = ref();
|
const dialog = ref();
|
||||||
|
@ -36,6 +38,11 @@ const entryTypes = ref([]);
|
||||||
const entryAccounts = ref([]);
|
const entryAccounts = ref([]);
|
||||||
const warehouses = ref([]);
|
const warehouses = ref([]);
|
||||||
const selectedRows = 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 selectedGestDoc;
|
||||||
let supplierRef;
|
let supplierRef;
|
||||||
const columns = computed(() => [
|
const columns = computed(() => [
|
||||||
|
@ -209,6 +216,14 @@ onBeforeMount(() => {
|
||||||
isBooked.value = arrayData.store.userParams.isBooked || false;
|
isBooked.value = arrayData.store.userParams.isBooked || false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(selectedRows, (nVal, oVal) => {
|
||||||
|
if (nVal.length > oVal.length && nVal.at(-1).invoiceInFk)
|
||||||
|
quasar.dialog({
|
||||||
|
component: VnConfirm,
|
||||||
|
componentProps: { title: t('entry.control.hasInvoice') },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function filterByDaysAgo(val) {
|
function filterByDaysAgo(val) {
|
||||||
if (!val) val = DEFAULTDAYS;
|
if (!val) val = DEFAULTDAYS;
|
||||||
else if (val > MAXDAYS) val = MAXDAYS;
|
else if (val > MAXDAYS) val = MAXDAYS;
|
||||||
|
@ -233,27 +248,37 @@ async function preAccount() {
|
||||||
// Is It agricultural?
|
// Is It agricultural?
|
||||||
const selectedAgri = entries.at(0);
|
const selectedAgri = entries.at(0);
|
||||||
// If It's agricultural, get the supplierRef
|
// If It's agricultural, get the supplierRef
|
||||||
if (selectedAgri.isAgricultural) {
|
try {
|
||||||
const year = new Date(selectedAgri.landed).getFullYear();
|
if (selectedAgri.isAgricultural) {
|
||||||
supplierRef = (
|
const year = new Date(selectedAgri.landed).getFullYear();
|
||||||
await axios.get('InvoiceIns/getMaxRef', {
|
supplierRef = (
|
||||||
params: { companyFk: selectedAgri.companyFk, year },
|
await axios.get('InvoiceIns/getMaxRef', {
|
||||||
})
|
params: { companyFk: selectedAgri.companyFk, year },
|
||||||
).data;
|
})
|
||||||
|
).data;
|
||||||
|
if (!supplierRef) supplierRef = year + '001';
|
||||||
|
|
||||||
return createInvoice(true);
|
return createInvoice(true);
|
||||||
} else if (selectedGestDoc) {
|
} else if (selectedGestDoc) {
|
||||||
// If There's a allocated file for an entry? Ask to (update/updlod) the file
|
// If There's an allocated file for an entry? Ask to (update/updload) the file
|
||||||
dialog.value.show();
|
supplierRef = +(
|
||||||
} else {
|
await axios.get(`Dms/${selectedGestDoc.gestDocFk}`, {
|
||||||
// If There's no gestDoc, upload the file
|
params: { filter: JSON.stringify({ fields: { reference: true } }) },
|
||||||
uploadFile();
|
})
|
||||||
|
).data?.reference;
|
||||||
|
dialog.value.show();
|
||||||
|
} else {
|
||||||
|
// If There's no gestDoc, upload the file
|
||||||
|
uploadFile();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateFile() {
|
async function updateFile() {
|
||||||
await axios.post(`Dms/${selectedGestDoc.gestDocFk}/updateFile`, { dmsTypeId: 1 });
|
await axios.post(`Dms/${selectedGestDoc.gestDocFk}/updateFile`, { dmsTypeId: 1 });
|
||||||
table.value.reload();
|
await createInvoice(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadFile() {
|
async function uploadFile() {
|
||||||
|
@ -272,17 +297,19 @@ async function uploadFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createInvoice(isAgricultural) {
|
async function createInvoice(isAgricultural) {
|
||||||
let err;
|
|
||||||
try {
|
try {
|
||||||
await axios.post(`Entries/preAccount`, {
|
await axios.post(`Entries/preAccount`, {
|
||||||
ids: selectedRows.value.map((entry) => entry.id),
|
ids: selectedRows.value.map((entry) => entry.id),
|
||||||
supplierRef,
|
supplierRef,
|
||||||
isAgricultural,
|
isAgricultural,
|
||||||
});
|
});
|
||||||
|
// Una vez marcada las entradas como contabilizadas, no permitir contabilizarla otra vez?? Carlos
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
table.value.reload();
|
table.value.reload();
|
||||||
|
supplierRef = null;
|
||||||
|
selectedGestDoc = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -328,9 +355,9 @@ async function createInvoice(isAgricultural) {
|
||||||
v-model:selected="selectedRows"
|
v-model:selected="selectedRows"
|
||||||
:data-key
|
:data-key
|
||||||
:columns
|
:columns
|
||||||
|
:url
|
||||||
:search-url="dataKey"
|
:search-url="dataKey"
|
||||||
ref="table"
|
ref="table"
|
||||||
:url
|
|
||||||
:disable-option="{ card: true }"
|
:disable-option="{ card: true }"
|
||||||
redirect="Entry"
|
redirect="Entry"
|
||||||
:order="['landed DESC']"
|
:order="['landed DESC']"
|
||||||
|
@ -338,6 +365,11 @@ async function createInvoice(isAgricultural) {
|
||||||
:user-params="{ daysAgo, isBooked }"
|
:user-params="{ daysAgo, isBooked }"
|
||||||
:row-click="false"
|
:row-click="false"
|
||||||
:table="{ selection: 'multiple' }"
|
:table="{ selection: 'multiple' }"
|
||||||
|
:limit="0"
|
||||||
|
:footer="true"
|
||||||
|
@on-fetch="
|
||||||
|
(data) => (totalAmount = data.reduce((acc, entry) => acc + entry.amount, 0))
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<template #top-left>
|
<template #top-left>
|
||||||
<QBtn
|
<QBtn
|
||||||
|
@ -373,6 +405,10 @@ async function createInvoice(isAgricultural) {
|
||||||
<SupplierDescriptorProxy :id="row.supplierFk" />
|
<SupplierDescriptorProxy :id="row.supplierFk" />
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
<template #column-footer-amount>
|
||||||
|
<div v-text="toCurrency(totalSelectedAmount)" />
|
||||||
|
<div v-text="toCurrency(totalAmount)" />
|
||||||
|
</template>
|
||||||
</VnTable>
|
</VnTable>
|
||||||
<VnConfirm
|
<VnConfirm
|
||||||
ref="dialog"
|
ref="dialog"
|
||||||
|
@ -385,8 +421,15 @@ async function createInvoice(isAgricultural) {
|
||||||
color="primary"
|
color="primary"
|
||||||
@click="updateFile"
|
@click="updateFile"
|
||||||
autofocus
|
autofocus
|
||||||
|
v-close-popup
|
||||||
|
/>
|
||||||
|
<QBtn
|
||||||
|
:label="t('globals.no')"
|
||||||
|
color="primary"
|
||||||
|
flat
|
||||||
|
@click="uploadFile"
|
||||||
|
v-close-popup
|
||||||
/>
|
/>
|
||||||
<QBtn :label="t('globals.no')" color="primary" flat @click="uploadFile" />
|
|
||||||
<QBtn :label="t('globals.cancel')" color="primary" flat v-close-popup />
|
<QBtn :label="t('globals.cancel')" color="primary" flat v-close-popup />
|
||||||
</template>
|
</template>
|
||||||
</VnConfirm>
|
</VnConfirm>
|
||||||
|
|
|
@ -140,6 +140,7 @@ entry:
|
||||||
search: Search
|
search: Search
|
||||||
searchInfo: You can search by supplier name or nickname
|
searchInfo: You can search by supplier name or nickname
|
||||||
preAccount: Pre-account
|
preAccount: Pre-account
|
||||||
|
hasInvoice: This entry has already an invoice in
|
||||||
dialog:
|
dialog:
|
||||||
title: Pre-account entries
|
title: Pre-account entries
|
||||||
message: Do you want the invoice to inherit the entry document?
|
message: Do you want the invoice to inherit the entry document?
|
||||||
|
|
|
@ -91,6 +91,7 @@ entry:
|
||||||
search: Buscar
|
search: Buscar
|
||||||
searchInfo: Puedes buscar por nombre o alias de proveedor
|
searchInfo: Puedes buscar por nombre o alias de proveedor
|
||||||
preAccount: Precontabilizar
|
preAccount: Precontabilizar
|
||||||
|
hasInvoice: Esta entrada ya tiene una f. recibida
|
||||||
dialog:
|
dialog:
|
||||||
title: Precontabilizar entradas
|
title: Precontabilizar entradas
|
||||||
message: ¿Desea que la factura herede el documento de la entrada?
|
message: ¿Desea que la factura herede el documento de la entrada?
|
||||||
|
|
Loading…
Reference in New Issue