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