From c3206679f476e7fd001756190024e03f05340ea2 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sat, 6 Jul 2024 03:20:30 +0530 Subject: populated items list and total in print preview --- src/views/ViewInvoice.vue | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/views/ViewInvoice.vue') diff --git a/src/views/ViewInvoice.vue b/src/views/ViewInvoice.vue index b8b7f2d..e35f9d5 100644 --- a/src/views/ViewInvoice.vue +++ b/src/views/ViewInvoice.vue @@ -4,8 +4,8 @@ import { useRoute } from "vue-router" import { useToast } from 'vue-toast-notification' import axios from 'axios' -import Invoice from "./../classes/invoice" -import { calculate } from "./../classes/invoice_item" +import Invoice, { InvoiceTotal } from "./../classes/invoice" +import { calculateArr, calculateTotal } from "./../classes/invoice_item" import invoiceHeader from './../components/invoice_header.vue' import invoiceItemsTable from './../components/invoice_items_table.vue' @@ -21,26 +21,29 @@ const route = useRoute() const invoiceId = route.params.id const invoice = ref(new Invoice()) -const items = ref([]) +const total = ref(new InvoiceTotal()) const invoiceIsLoading = ref(true) -const itemsTableIsLoading = ref(true) const getInvoice = async () => { invoiceIsLoading.value = true - itemsTableIsLoading.value = true try { const r = await axios.get(`/invoice/${invoiceId}`) - invoice.value = r.data.data - items.value = calculate(r.data.data.Items) + const items = calculateArr(r.data.data.Items) + + invoice.value = { + ...r.data.data, + Items: items + } + + total.value = calculateTotal(items) } catch (err) { toast.error('An unhandled exception occoured. Please check logs') console.error(err) } invoiceIsLoading.value = false - itemsTableIsLoading.value = false } const handlePrint = () => { @@ -54,7 +57,7 @@ onMounted(() => { @@ -62,10 +65,13 @@ onMounted(() => {