123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 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 TableHeader from './TableHeader'
  11. const props = defineProps({
  12. mutations: {
  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: ['mutations'],
  58. })
  59. const params = window.location.search
  60. exportExcelLink.value = `/reports/mutations/export/excel${params}`
  61. })
  62. const filterReset = () => {
  63. Inertia.get('/reports/mutations')
  64. }
  65. const linkReference = (data) => {
  66. if (data.transactionId) {
  67. return route('transactions.show', data.transactionId)
  68. } else {
  69. return route('expenses.show', data.expenseId)
  70. }
  71. }
  72. const exportExcelLink = ref('/reports/mutations/export/excel')
  73. const isAdmin = computed(() => usePage().props.value.isAdmin)
  74. </script>
  75. <template>
  76. <AppLayout>
  77. <Head title="Laporan Mutasi" />
  78. <DataTable
  79. responsive-layout="scroll"
  80. column-resize-mode="expand"
  81. :value="mutations.data"
  82. :row-hover="true"
  83. :striped-rows="true"
  84. >
  85. <template #header>
  86. <h1>Laporan Mutasi</h1>
  87. <div class="grid">
  88. <div class="col-12 md:col-8">
  89. <div class="grid">
  90. <div class="col-12 md:col-4">
  91. <Calendar
  92. class="w-full"
  93. v-model="filterForm.dates"
  94. selection-mode="range"
  95. placeholder="filter waktu..."
  96. date-format="dd/mm/yy"
  97. :manual-input="false"
  98. />
  99. </div>
  100. <div class="col-12 md:col-4">
  101. <Dropdown
  102. v-if="isAdmin"
  103. class="w-full"
  104. placeholder="pilih outlet..."
  105. v-model="filterForm.outlet"
  106. option-label="label"
  107. option-value="value"
  108. :options="outlets"
  109. />
  110. </div>
  111. <div class="col-auto mt-2 ml-2">
  112. <Button label="reset" class="p-button-link" @click="filterReset" />
  113. </div>
  114. </div>
  115. </div>
  116. <div class="col-12 md:col-4 flex justify-content-end">
  117. <AppButton
  118. v-if="mutations.total"
  119. label="Export excel"
  120. class-button="p-button-outlined md:w-16rem"
  121. icon="pi pi-file-excel"
  122. :inertia-link="false"
  123. :href="exportExcelLink"
  124. />
  125. </div>
  126. </div>
  127. </template>
  128. <Column
  129. v-for="tableHeader in TableHeader"
  130. :field="tableHeader.field"
  131. :header="tableHeader.header"
  132. :key="tableHeader.field"
  133. />
  134. <Column>
  135. <template #body="{ data }">
  136. <AppButton
  137. icon="pi pi-link"
  138. class="p-button-text p-button-icon-only p-button-rounded p-button-text"
  139. :href="linkReference(data)"
  140. />
  141. </template>
  142. </Column>
  143. </DataTable>
  144. <AppPagination :links="mutations.links" />
  145. </AppLayout>
  146. </template>