0
0
Fork 0

refactor: refs #6942 summary

This commit is contained in:
Jorge Penadés 2024-05-17 17:26:58 +02:00
parent 7f880b397c
commit 81998a4137
1 changed files with 27 additions and 46 deletions

View File

@ -11,29 +11,15 @@ import SupplierDescriptorProxy from 'src/pages/Supplier/Card/SupplierDescriptorP
import InvoiceIntoBook from '../InvoiceInToBook.vue'; import InvoiceIntoBook from '../InvoiceInToBook.vue';
import VnTitle from 'src/components/common/VnTitle.vue'; import VnTitle from 'src/components/common/VnTitle.vue';
onMounted(async () => { const props = defineProps({ id: { type: Number, default: 0 } });
salixUrl.value = await getUrl('');
invoiceInUrl.value = salixUrl.value + `invoiceIn/${entityId.value}/`;
});
const { params } = useRoute();
const { t } = useI18n(); const { t } = useI18n();
const $props = defineProps({ const entityId = computed(() => props.id || useRoute().params.id);
id: { const invoiceIn = computed(() => useArrayData('InvoiceIn').store.data);
type: Number,
default: 0,
},
});
const entityId = computed(() => $props.id || params.id);
const arrayData = useArrayData('InvoiceIn');
const invoiceIn = computed(() => arrayData.store.data);
const salixUrl = ref();
const invoiceInUrl = ref(); const invoiceInUrl = ref();
const amountsNotMatch = ref(null); const amountsNotMatch = ref(null);
const intrastatTotals = ref({}); const intrastatTotals = ref({ amount: 0, net: 0, stems: 0 });
const isBooked = ref(); const isBooked = ref();
const vatColumns = ref([ const vatColumns = ref([
@ -166,6 +152,10 @@ const intrastatColumns = ref([
}, },
]); ]);
onMounted(async () => {
invoiceInUrl.value = `${await getUrl('')}invoiceIn/${entityId.value}/`;
});
function getAmountNotMatch(totals) { function getAmountNotMatch(totals) {
return ( return (
totals.totalDueDay != totals.totalTaxableBase && totals.totalDueDay != totals.totalTaxableBase &&
@ -173,16 +163,6 @@ function getAmountNotMatch(totals) {
); );
} }
function getIntrastatTotals(intrastat) {
const totals = {
amount: intrastat.reduce((acc, cur) => acc + cur.amount, 0),
net: intrastat.reduce((acc, cur) => acc + cur.net, 0),
stems: intrastat.reduce((acc, cur) => acc + cur.stems, 0),
};
return totals;
}
function getTaxTotal(tax) { function getTaxTotal(tax) {
return tax.reduce( return tax.reduce(
(acc, cur) => acc + taxRate(cur.taxableBase, cur.taxTypeSage?.rate), (acc, cur) => acc + taxRate(cur.taxableBase, cur.taxTypeSage?.rate),
@ -190,35 +170,36 @@ function getTaxTotal(tax) {
); );
} }
function setData(entity) { const init = (data) => {
if (!entity) return false; if (!data) return;
isBooked.value = entity.isBooked; isBooked.value = data.isBooked;
amountsNotMatch.value = getAmountNotMatch(entity.totals); amountsNotMatch.value = getAmountNotMatch(data.totals);
if (entity.invoiceInIntrastat.length) if (data.invoiceInIntrastat.length) {
intrastatTotals.value = { ...getIntrastatTotals(entity.invoiceInIntrastat) }; data.invoiceInIntrastat.forEach((val) => {
} intrastatTotals.value.amount += val.amount;
intrastatTotals.value.net += val.net;
intrastatTotals.value.stems += val.stems;
});
}
};
function taxRate(taxableBase = 0, rate = 0) { const taxRate = (taxableBase = 0, rate = 0) => (rate / 100) * taxableBase;
return (rate / 100) * taxableBase;
}
function getLink(param) { const getLink = (param) => `#/invoice-in/${entityId.value}/${param}`;
return `#/invoice-in/${entityId.value}/${param}`;
}
</script> </script>
<template> <template>
<CardSummary <CardSummary
data-key="InvoiceInSummary" data-key="InvoiceInSummary"
:url="`InvoiceIns/${entityId}/summary`" :url="`InvoiceIns/${entityId}/summary`"
@on-fetch="(data) => setData(data)" @on-fetch="(data) => init(data)"
> >
<template #header="{ entity }"> <template #header="{ entity }">
<div>{{ entity.id }} - {{ entity.supplier?.name }}</div> <div>{{ entity.id }} - {{ entity.supplier?.name }}</div>
</template> </template>
<template #header-right v-if="!invoiceIn?.isBooked"> <template #header-right v-if="!isBooked">
<InvoiceIntoBook> <InvoiceIntoBook>
<template #content="{ book }"> <template #content="{ book }">
<QBtn <QBtn
@ -346,7 +327,7 @@ function getLink(param) {
</QCardSection> </QCardSection>
</QCard> </QCard>
<!--Vat--> <!--Vat-->
<QCard v-if="invoiceIn.invoiceInTax.length"> <QCard v-if="entity.invoiceInTax.length">
<VnTitle :url="getLink('vat')" :text="t('invoiceIn.card.vat')" /> <VnTitle :url="getLink('vat')" :text="t('invoiceIn.card.vat')" />
<QTable <QTable
:columns="vatColumns" :columns="vatColumns"
@ -374,7 +355,7 @@ function getLink(param) {
</QTable> </QTable>
</QCard> </QCard>
<!--Due Day--> <!--Due Day-->
<QCard v-if="invoiceIn.invoiceInDueDay.length"> <QCard v-if="entity.invoiceInDueDay.length">
<VnTitle :url="getLink('due-day')" :text="t('invoiceIn.card.dueDay')" /> <VnTitle :url="getLink('due-day')" :text="t('invoiceIn.card.dueDay')" />
<QTable <QTable
class="full-width" class="full-width"
@ -400,7 +381,7 @@ function getLink(param) {
</QTable> </QTable>
</QCard> </QCard>
<!--Intrastat--> <!--Intrastat-->
<QCard v-if="invoiceIn.invoiceInIntrastat.length"> <QCard v-if="entity.invoiceInIntrastat.length">
<VnTitle <VnTitle
:url="getLink('intrastat')" :url="getLink('intrastat')"
:text="t('invoiceIn.card.intrastat')" :text="t('invoiceIn.card.intrastat')"