Report.vue 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <script setup>
  2. import { Inertia } from '@inertiajs/inertia'
  3. import { watch, computed, onMounted, ref } from 'vue'
  4. import { Head, useForm, usePage } from '@inertiajs/inertia-vue3'
  5. import dayjs from 'dayjs'
  6. import throttle from 'lodash/throttle'
  7. import pickBy from 'lodash/pickBy'
  8. import AppLayout from '@/layouts/AppLayout.vue'
  9. import AppPagination from '@/components/AppPagination.vue'
  10. import AppButton from '@/components/AppButton.vue'
  11. import { TransactionReportTable } from './TableHeader'
  12. const props = defineProps({
  13. transactions: Object,
  14. filters: Object,
  15. outlets: Array,
  16. })
  17. const filterForm = useForm({
  18. dates: null,
  19. startDate: props.filters.startDate,
  20. endDate: props.filters.endDate,
  21. outlet: props.filters.outlet,
  22. })
  23. onMounted(() => {
  24. if (props.filters.startDate || props.filters.endDate) {
  25. if (props.filters.endDate) {
  26. filterForm.dates = [new Date(props.filters.startDate), new Date(props.filters.endDate)]
  27. } else {
  28. filterForm.dates = [new Date(props.filters.startDate), null]
  29. }
  30. }
  31. })
  32. watch(
  33. filterForm,
  34. throttle(() => {
  35. if (filterForm.dates) {
  36. if (filterForm.dates[1]) {
  37. filterForm.startDate = dayjs(filterForm.dates[0]).format('YYYY-MM-DD')
  38. filterForm.endDate = dayjs(filterForm.dates[1]).format('YYYY-MM-DD')
  39. } else {
  40. filterForm.startDate = dayjs(filterForm.dates[0]).format('YYYY-MM-DD')
  41. filterForm.endDate = null
  42. }
  43. } else {
  44. filterForm.endDate = null
  45. filterForm.startDate = null
  46. }
  47. Inertia.get(
  48. '/reports/transactions',
  49. pickBy({
  50. startDate: filterForm.startDate,
  51. endDate: filterForm.endDate,
  52. outlet: filterForm.outlet,
  53. }),
  54. {
  55. preserveState: true,
  56. }
  57. )
  58. const params = window.location.search
  59. exportExcelLink.value = `/reports/transactions/export/excel${params}`
  60. }, 300)
  61. )
  62. const exportExcelLink = ref('/reports/transactions/export/excel')
  63. const isAdmin = computed(() => usePage().props.value.isAdmin)
  64. </script>
  65. <template>
  66. <AppLayout>
  67. <Head title="Laporan Transaksi" />
  68. <DataTable
  69. responsive-layout="scroll"
  70. column-resize-mode="expand"
  71. :value="transactions.data"
  72. :row-hover="true"
  73. :striped-rows="true"
  74. >
  75. <template #header>
  76. <h5>Laporan Transaksi</h5>
  77. <div class="grid">
  78. <div class="col-12 md:col-8">
  79. <div class="grid">
  80. <div class="col-12 md:col-4">
  81. <Calendar
  82. class="w-full"
  83. v-model="filterForm.dates"
  84. selection-mode="range"
  85. placeholder="filter waktu..."
  86. date-format="dd/mm/yy"
  87. :show-button-bar="true"
  88. :manual-input="false"
  89. />
  90. </div>
  91. <div class="col-12 md:col-4">
  92. <Dropdown
  93. v-if="isAdmin"
  94. class="w-full"
  95. placeholder="pilih outlet..."
  96. v-model="filterForm.outlet"
  97. option-label="label"
  98. option-value="value"
  99. :options="outlets"
  100. />
  101. </div>
  102. </div>
  103. </div>
  104. <div class="col-12 md:col-4 flex justify-content-end">
  105. <AppButton
  106. v-if="transactions.data.length"
  107. label="Export excel"
  108. class-button="p-button-text md:w-16rem"
  109. icon="pi pi-file-excel"
  110. :inertia-link="false"
  111. :href="exportExcelLink"
  112. />
  113. </div>
  114. </div>
  115. </template>
  116. <Column
  117. v-for="tableHeader in TransactionReportTable"
  118. :field="tableHeader.field"
  119. :header="tableHeader.header"
  120. :key="tableHeader.field"
  121. />
  122. <Column>
  123. <template #body="{ data }">
  124. <AppButton
  125. icon="pi pi-link"
  126. class="p-button-text p-button-icon-only p-button-rounded p-button-text"
  127. :href="`/transactions?startDate=${data.startDate}&endDate=${data.startDate}`"
  128. />
  129. </template>
  130. </Column>
  131. </DataTable>
  132. <AppPagination :links="transactions.links" />
  133. </AppLayout>
  134. </template>