Report.vue 4.2KB

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