diff options
Diffstat (limited to 'src/views/ViewInvoice.vue')
-rw-r--r-- | src/views/ViewInvoice.vue | 26 |
1 files changed, 16 insertions, 10 deletions
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<any[]>([]) +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(() => { <template> <div id="print-preview" class="bg-white text-black"> - <PrintPreview :invoice="invoice"/> + <PrintPreview :invoice="invoice" :total="total"/> </div> <button id="print-button" class="btn btn-primary" @click="handlePrint">Print</button> </template> @@ -62,10 +65,13 @@ onMounted(() => { <style> #print-preview { max-height: 90vh; - /*display: none;*/ + display: none; aspect-ratio: 1 / 1.414; } @media print { + @page { + size: A4 portrait; + } body { background-color: white; } |