From 464dac56714f4fb187785abda04bf3f2170af2a2 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Thu, 7 Dec 2023 04:22:03 +0530 Subject: showing more useful information in invoice items table --- src/views/EditInvoice.vue | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/views/EditInvoice.vue') diff --git a/src/views/EditInvoice.vue b/src/views/EditInvoice.vue index 958846e..adc172b 100644 --- a/src/views/EditInvoice.vue +++ b/src/views/EditInvoice.vue @@ -3,8 +3,10 @@ import { ref, onMounted, toRaw } from 'vue' import { useRoute } from "vue-router" import { useToast } from 'vue-toast-notification' import axios from 'axios' +import currency from "currency.js" import Invoice from "./../classes/invoice" +import InvoiceItem from "./../classes/invoice_item" import invoiceHeader from './../components/invoice_header.vue' import itemSelector from './../components/item_selector.vue' @@ -18,11 +20,33 @@ const route = useRoute() const invoiceId = route.params.id const invoice = ref(new Invoice()) -const items = ref([]) +const items = ref([]) const invoiceIsLoading = ref(true) const itemsTableIsLoading = ref(true) +const processItems = (items: InvoiceItem[]) => items.map((x: InvoiceItem) => { + const quantity = currency(x.Quantity) + const unitPrice = currency(x.UnitPrice) + const gstPercentage = currency(x.GSTPercentage) + const gstValue = unitPrice.multiply(gstPercentage).divide(100) + const totalGSTValue = gstValue.multiply(quantity) + const amountWithoutGST = unitPrice.multiply(quantity) + + return({ + ...x + , Quantity: quantity + , UnitPrice: unitPrice + , GSTValue: gstValue + , TotalGSTValue: totalGSTValue + , AmountWithoutGST: amountWithoutGST + , TotalAmount: amountWithoutGST.add(totalGSTValue) + }) +}) + //{{ currency(item.UnitPrice).add(currency(item.UnitPrice).multiply(currency(item.GSTPercentage)).divide(100)).multiply(currency(item.Quantity)) }} + // {{ currency(item.UnitPrice).multiply(currency(item.Quantity)) }} + // {{ currency(item.UnitPrice).multiply(currency(item.GSTPercentage)).divide(100).multiply(item.Quantity) }} + const getInvoice = async () => { invoiceIsLoading.value = true itemsTableIsLoading.value = true @@ -30,7 +54,7 @@ const getInvoice = async () => { try { const r = await axios.get(`/invoice/${invoiceId}`) invoice.value = r.data.data - items.value = r.data.data.Items + items.value = processItems(r.data.data.Items) } catch (err) { toast.error('An unhandled exception occoured. Please check logs') console.error(err) @@ -41,13 +65,13 @@ const getInvoice = async () => { } const refreshItems = async () => { - items.value = [] + //items.value = [] itemsTableIsLoading.value = true try { const res = await axios.get(`/invoice/${invoiceId}/item`) if (res.status === 200) { - items.value = res.data.data + items.value = processItems(res.data.data) } } catch (err) { toast.error('An unhandled exception occoured. Please check logs') -- cgit v1.2.3