diff --git a/src/pages/InvoiceIn/Card/InvoiceInSummary.vue b/src/pages/InvoiceIn/Card/InvoiceInSummary.vue index 9976cc03e..8ceab8b51 100644 --- a/src/pages/InvoiceIn/Card/InvoiceInSummary.vue +++ b/src/pages/InvoiceIn/Card/InvoiceInSummary.vue @@ -11,29 +11,15 @@ import SupplierDescriptorProxy from 'src/pages/Supplier/Card/SupplierDescriptorP import InvoiceIntoBook from '../InvoiceInToBook.vue'; import VnTitle from 'src/components/common/VnTitle.vue'; -onMounted(async () => { - salixUrl.value = await getUrl(''); - invoiceInUrl.value = salixUrl.value + `invoiceIn/${entityId.value}/`; -}); - -const { params } = useRoute(); +const props = defineProps({ id: { type: Number, default: 0 } }); const { t } = useI18n(); -const $props = defineProps({ - id: { - type: Number, - default: 0, - }, -}); +const entityId = computed(() => props.id || useRoute().params.id); +const invoiceIn = computed(() => useArrayData('InvoiceIn').store.data); -const entityId = computed(() => $props.id || params.id); -const arrayData = useArrayData('InvoiceIn'); -const invoiceIn = computed(() => arrayData.store.data); - -const salixUrl = ref(); const invoiceInUrl = ref(); const amountsNotMatch = ref(null); -const intrastatTotals = ref({}); +const intrastatTotals = ref({ amount: 0, net: 0, stems: 0 }); const isBooked = ref(); const vatColumns = ref([ @@ -166,6 +152,10 @@ const intrastatColumns = ref([ }, ]); +onMounted(async () => { + invoiceInUrl.value = `${await getUrl('')}invoiceIn/${entityId.value}/`; +}); + function getAmountNotMatch(totals) { return ( 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) { return tax.reduce( (acc, cur) => acc + taxRate(cur.taxableBase, cur.taxTypeSage?.rate), @@ -190,35 +170,36 @@ function getTaxTotal(tax) { ); } -function setData(entity) { - if (!entity) return false; +const init = (data) => { + if (!data) return; - isBooked.value = entity.isBooked; - amountsNotMatch.value = getAmountNotMatch(entity.totals); + isBooked.value = data.isBooked; + amountsNotMatch.value = getAmountNotMatch(data.totals); - if (entity.invoiceInIntrastat.length) - intrastatTotals.value = { ...getIntrastatTotals(entity.invoiceInIntrastat) }; -} + if (data.invoiceInIntrastat.length) { + 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) { - return (rate / 100) * taxableBase; -} +const taxRate = (taxableBase = 0, rate = 0) => (rate / 100) * taxableBase; -function getLink(param) { - return `#/invoice-in/${entityId.value}/${param}`; -} +const getLink = (param) => `#/invoice-in/${entityId.value}/${param}`;