aboutsummaryrefslogtreecommitdiff
path: root/src/views/ViewInvoice.vue
blob: 68857b4658a6ee81d8b68c70c372b2db07f4de72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<script setup lang="ts">
import { ref, onMounted } from 'vue'
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 invoiceHeader from './../components/invoice_header.vue'
import invoiceItemsTable from './../components/invoice_items_table.vue'
import invoiceSummary from './../components/invoice_summary.vue'

const toast = useToast({
  position: 'top-right'
})

const route = useRoute()

const invoiceId = route.params.id
const invoice = ref(new Invoice())
const items = ref<any[]>([])

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)
  } catch (err) {
    toast.error('An unhandled exception occoured. Please check logs')
    console.error(err)
  }

  invoiceIsLoading.value = false
  itemsTableIsLoading.value = false
}

const handlePrint = () => {
  print()
}

onMounted(() => {
  getInvoice()
})
</script>

<template>
  <div id="print-preview" class="bg-white text-black">
    <invoiceHeader
      :invoice="invoice" />
    <invoiceItemsTable
      preview=true
      :items="items"
      :isLoading="itemsTableIsLoading" />
    <invoiceSummary
      :items="items"
      :isLoading="itemsTableIsLoading"
    />
  </div>
  <button id="print-button" class="btn btn-primary" @click="handlePrint">Print</button>
</template>

<style>
#print-preview {
  width: 670px;
}
#print-preview * {
  font-size: 12pt !important;
}
#print-preview .sup {
  display: none;
}
#print-preview table {
  width: 100%;
}
#print-preview table * {
  font-size: 10pt !important;
}
#print-preview .invoice-items-table {
  margin-bottom: auto !important;
}
#print-preview .invoice-summary {
  margin-top: auto !important;
}
@media print {
  #print-preview {
    width: auto !important;
  }
  #sidebar, #navbar, #print-button, .btn {
    display: none !important;
  }
  ::-webkit-scrollbar {
    display: none;
  }
  main {
    width: 100% !important;
    overflow-x: visible !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  #app {
    display: block;
    max-height: auto !important;
    overflow-y: visible !important;
  }
}
</style>