feat: refs #8388 enhance invoice booking validation and user confirmation messages
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2025-01-31 18:07:20 +01:00
parent c2042276ae
commit f18da15262
1 changed files with 29 additions and 14 deletions

View File

@ -4,6 +4,7 @@ import { useQuasar } from 'quasar';
import { useI18n } from 'vue-i18n';
import VnConfirm from 'src/components/ui/VnConfirm.vue';
import { useArrayData } from 'src/composables/useArrayData';
import qs from 'qs';
const { notify, dialog } = useQuasar();
const { t } = useI18n();
@ -12,29 +13,41 @@ defineExpose({ checkToBook });
const { store } = useArrayData();
async function checkToBook(id) {
let directBooking = true;
let messages = [];
const { data: totals } = await axios.get(`InvoiceIns/${id}/getTotals`);
const taxableBaseNotEqualDueDay = totals.totalDueDay != totals.totalTaxableBase;
const vatNotEqualDueDay = totals.totalDueDay != totals.totalVat;
if (taxableBaseNotEqualDueDay && vatNotEqualDueDay) directBooking = false;
if (taxableBaseNotEqualDueDay && vatNotEqualDueDay)
messages.push(t('The sum of the taxable bases does not match the due dates'));
const { data: dueDaysCount } = await axios.get('InvoiceInDueDays/count', {
where: {
invoiceInFk: id,
dueDated: { gte: Date.vnNew() },
},
});
const dueDaysCount = (
await axios.get('InvoiceInDueDays/count', {
params: {
where: JSON.stringify({
invoiceInFk: id,
dueDated: { gte: Date.vnNew() },
}),
},
})
).data?.count;
if (dueDaysCount) directBooking = false;
if (dueDaysCount) messages.push(t('Some due dates are less than or equal to today'));
if (directBooking) return toBook(id);
if (!messages.length) toBook(id);
else
dialog({
component: VnConfirm,
componentProps: {
title: t('Are you sure you want to book this invoice?'),
message: messages.reduce((acc, msg) => `${acc}<p>${msg}</p>`, ''),
},
}).onOk(async () => {
await toBook(id);
dialog({
component: VnConfirm,
componentProps: { title: t('Are you sure you want to book this invoice?') },
}).onOk(async () => await toBook(id));
axios.get();
});
}
async function toBook(id) {
@ -59,4 +72,6 @@ async function toBook(id) {
es:
Are you sure you want to book this invoice?: ¿Estás seguro de querer asentar esta factura?
It was not able to book the invoice: No se pudo contabilizar la factura
Some due dates are less than or equal to today: Algún vencimiento tiene una fecha menor o igual que hoy
The sum of the taxable bases does not match the due dates: La suma de las bases imponibles no coincide con la de los vencimientos
</i18n>