diff --git a/src/api/giftCard.ts b/src/api/giftCard.ts index e9ea93b..886d839 100644 --- a/src/api/giftCard.ts +++ b/src/api/giftCard.ts @@ -7,6 +7,26 @@ import type {Giftcard, GiftcardInput} from "@/model/giftCard"; export const getGiftCardTable = async (params: TableInput) => await useAxios.post>('/admin/giftcard/table', params) +export interface GiftCardCodesUsageSummary { + total_codes: number + used_codes: number + unused_codes: number + active_codes: number + expired_codes: number +} + +export type GiftCardCodesUsageReportResponse = { + rows: Record[] + summary?: GiftCardCodesUsageSummary + query?: Record +} + +export const getGiftCardCodesUsageReport = async (params: TableInput) => + await useAxios.post( + '/admin/giftcard/codes-usage-report', + params, + ) + export const createGiftCard = async (obj: GiftcardInput) => await useAxios.post(`/admin/giftcard/generate`, obj) diff --git a/src/pages/menuPages/giftCards/components/GiftCardCodesUsageReportSheet.vue b/src/pages/menuPages/giftCards/components/GiftCardCodesUsageReportSheet.vue new file mode 100644 index 0000000..5475366 --- /dev/null +++ b/src/pages/menuPages/giftCards/components/GiftCardCodesUsageReportSheet.vue @@ -0,0 +1,104 @@ + + + diff --git a/src/pages/menuPages/giftCards/components/table.vue b/src/pages/menuPages/giftCards/components/table.vue index 7fb589a..f4f666e 100644 --- a/src/pages/menuPages/giftCards/components/table.vue +++ b/src/pages/menuPages/giftCards/components/table.vue @@ -23,6 +23,15 @@ > افزودن کد تخفیف + + گزارش استفاده کدها + @@ -84,6 +95,7 @@ import { isMobile } from '@core/utils/is' import { isStoreApp } from '@/utils/config' import { giftCardsPageIntro } from '@/utils/adminHelpCopy' import { usePageActionAccess } from '@/composables/usePageActionAccess' +import GiftCardCodesUsageReportSheet from './GiftCardCodesUsageReportSheet.vue' interface Prop { customerId?: number @@ -92,6 +104,7 @@ interface Prop { const props = defineProps() const emits = defineEmits(['delete', 'edit', 'add', 'info', 'giftcardcodes']) const { can } = usePageActionAccess() +const usageReportVisible = ref(false) const [submit, reload] = useBaseTable() const mobileListRef = ref Promise }>(null) diff --git a/src/pages/menuPages/giftCards/hooks/usageReportColumns.tsx b/src/pages/menuPages/giftCards/hooks/usageReportColumns.tsx new file mode 100644 index 0000000..2b0245a --- /dev/null +++ b/src/pages/menuPages/giftCards/hooks/usageReportColumns.tsx @@ -0,0 +1,157 @@ +import type { BaseTableColumn } from '@core/type/baseTable' +import { toJalali } from '@core/utils/useDataTime' +import CustomTag from '@/components/CustomTag.vue' +import { metalLabel } from '@/utils/adminMetalLabels' + +export function getGiftCardUsageReportColumns(): BaseTableColumn[] { + return [ + { + title: 'ردیف', + dataIndex: 'id', + key: 'row', + filterable: false, + sortable: false, + customRender: (record: { index: number }) => record.index + 1, + }, + { + title: 'کد', + dataIndex: 'code', + key: 'code', + type: 'text', + }, + { + title: 'نام پویش', + dataIndex: 'campaign_name', + key: 'campaign_name', + type: 'text', + }, + { + title: 'تعداد استفاده', + dataIndex: 'usage_count', + key: 'usage_count', + type: 'Number', + filterable: false, + }, + { + title: 'وضعیت کد', + dataIndex: 'sts', + key: 'sts', + type: 'Number', + customRender: ({ record }) => { + const sts = Number(record.sts) + if (sts === 1) { + return ( +
+ + فعال + +
+ ) + } + if (sts === 2) { + return ( +
+ + استفاده شده + +
+ ) + } + return ( +
+ + منقضی / غیرفعال + +
+ ) + }, + }, + { + title: 'نوع', + dataIndex: 'unit', + key: 'unit', + filterable: false, + customRender: ({ record }) => { + const unit = Number(record.unit) + if (unit === 3) { + return ( +
+ + تخفیف + +
+ ) + } + if (unit === 2) { + return ( +
+ + {metalLabel.goldWalletShort()} + +
+ ) + } + return ( +
+ + ریالی + +
+ ) + }, + }, + { + title: 'مقدار', + dataIndex: 'amount', + key: 'amount', + type: 'Number', + filterable: false, + }, + { + title: 'مصرف‌کننده', + dataIndex: 'assigned_to', + key: 'assigned_to_name', + filterable: false, + customRender: ({ record }) => record.assigned_to?.name ?? '-', + }, + { + title: 'موبایل مصرف‌کننده', + dataIndex: 'assigned_to', + key: 'assigned_to_mobile', + filterable: false, + customRender: ({ record }) => ( + + {record.assigned_to?.mobile ?? '-'} + + ), + }, + { + title: 'تاریخ استفاده', + dataIndex: 'used_at', + key: 'used_at', + filterable: false, + customRender: ({ record }) => (record.used_at ? toJalali(record.used_at) : '-'), + }, + { + title: 'انقضا', + dataIndex: 'expiry_date', + key: 'expiry_date', + filterable: false, + customRender: ({ record }) => (record.expiry_date ? toJalali(record.expiry_date) : '-'), + }, + { + title: 'کل مجاز پویش', + dataIndex: 'campaign_count', + key: 'campaign_count', + type: 'Number', + filterable: false, + }, + { + title: 'مصرف‌شده پویش', + dataIndex: 'campaign_used_count', + key: 'campaign_used_count', + type: 'Number', + filterable: false, + }, + ] +}