aboutsummaryrefslogtreecommitdiff
path: root/src/views/EditInvoice.vue
diff options
context:
space:
mode:
Diffstat (limited to 'src/views/EditInvoice.vue')
-rw-r--r--src/views/EditInvoice.vue31
1 files changed, 4 insertions, 27 deletions
diff --git a/src/views/EditInvoice.vue b/src/views/EditInvoice.vue
index adc172b..69afc7e 100644
--- a/src/views/EditInvoice.vue
+++ b/src/views/EditInvoice.vue
@@ -1,12 +1,11 @@
<script setup lang="ts">
-import { ref, onMounted, toRaw } from 'vue'
+import { ref, onMounted } 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 { calculate } from "./../classes/invoice_item"
import invoiceHeader from './../components/invoice_header.vue'
import itemSelector from './../components/item_selector.vue'
@@ -25,28 +24,6 @@ const items = ref<any[]>([])
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
@@ -54,7 +31,7 @@ const getInvoice = async () => {
try {
const r = await axios.get(`/invoice/${invoiceId}`)
invoice.value = r.data.data
- items.value = processItems(r.data.data.Items)
+ items.value = calculate(r.data.data.Items)
} catch (err) {
toast.error('An unhandled exception occoured. Please check logs')
console.error(err)
@@ -71,7 +48,7 @@ const refreshItems = async () => {
try {
const res = await axios.get(`/invoice/${invoiceId}/item`)
if (res.status === 200) {
- items.value = processItems(res.data.data)
+ items.value = calculate(res.data.data)
}
} catch (err) {
toast.error('An unhandled exception occoured. Please check logs')