From 448d9156f9ffb72a093c6ab1882b93c1e4f37aa4 Mon Sep 17 00:00:00 2001 From: Thanaphon Frappet Date: Wed, 19 Feb 2025 17:03:15 +0700 Subject: [PATCH] refactor: stats missing and new tab --- src/i18n/eng.ts | 10 +++---- src/i18n/tha.ts | 10 +++---- src/pages/12_debit-note/MainPage.vue | 41 ++++++++++++++++------------ src/pages/12_debit-note/constants.ts | 25 +++++++---------- src/stores/debit-note/index.ts | 13 ++++----- src/stores/debit-note/types.ts | 10 +++---- 6 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/i18n/eng.ts b/src/i18n/eng.ts index 3f0f0110..34c63072 100644 --- a/src/i18n/eng.ts +++ b/src/i18n/eng.ts @@ -1306,11 +1306,11 @@ export default { }, stats: { - Pending: 'Debit Note', - Expire: 'Expired', - Payment: 'Payment', - Receipt: 'Receipt', - Succeed: 'Completed', + Issued: 'Debit Note', + Expired: 'Expired', + PaymentPending: 'Payment', + PaymentSuccess: 'Receipt', + ProcessComplete: 'Completed', }, viewMode: { diff --git a/src/i18n/tha.ts b/src/i18n/tha.ts index 1883b158..4f481146 100644 --- a/src/i18n/tha.ts +++ b/src/i18n/tha.ts @@ -1288,11 +1288,11 @@ export default { }, stats: { - Pending: 'ใบเพิ่มหนี้', - Expire: 'พ้นกำหนด', - Payment: 'ชำระเงิน', - Receipt: 'ใบเสร็จรับเงิน', - Succeed: 'เสร็จสิ้น', + Issued: 'ใบเพิ่มหนี้', + Expired: 'พ้นกำหนด', + PaymentPending: 'ชำระเงิน', + PaymentSuccess: 'ใบเสร็จรับเงิน', + ProcessComplete: 'เสร็จสิ้น', }, viewMode: { diff --git a/src/pages/12_debit-note/MainPage.vue b/src/pages/12_debit-note/MainPage.vue index e695ae78..fd3780a9 100644 --- a/src/pages/12_debit-note/MainPage.vue +++ b/src/pages/12_debit-note/MainPage.vue @@ -35,7 +35,7 @@ const { stats, pageMax, page, data, pageSize } = storeToRefs(debitNote); // NOTE: Variable const pageState = reactive({ quotationId: '', - currentTab: DebitNoteStatus.Pending, + currentTab: DebitNoteStatus.Issued, hideStat: false, statusFilter: 'None', inputSearch: '', @@ -64,7 +64,9 @@ async function getList(opts?: { page?: number; pageSize?: number }) { page: opts?.page || page.value, pageSize: opts?.pageSize || pageSize.value, query: pageState.inputSearch === '' ? undefined : pageState.inputSearch, - deebitNoteStatus: pageState.currentTab as DebitNoteStatus | undefined, + status: (pageState.currentTab === DebitNoteStatus.Issued + ? undefined + : pageState.currentTab) as DebitNoteStatus, includeRegisteredBranch: true, }); @@ -126,7 +128,17 @@ onMounted(async () => { navigator.current.title = 'debitNote.title'; navigator.current.path = [{ text: 'debitNote.caption', i18n: true }]; - debitNote.getDebitNoteStats().then((res) => res && (stats.value = res)); + await debitNote.getDebitNoteStats().then((res) => { + if (res) { + stats.value = res; + + stats.value['issued'] = Object.values(res).reduce( + (sum, value) => sum + value, + 0, + ); + } + }); + getList(); }); @@ -184,33 +196,28 @@ watch( :branch="[ { icon: 'material-symbols-light:receipt-long', - count: stats[DebitNoteStatus.Pending] || 0, - label: `debitNote.stats.${DebitNoteStatus.Pending}`, + count: stats['issued'] || 0, + label: `debitNote.stats.${DebitNoteStatus.Issued}`, color: 'orange', }, - { - icon: 'mdi-clock-alert-outline', - count: stats[DebitNoteStatus.Expire] || 0, - label: `debitNote.stats.${DebitNoteStatus.Expire}`, - color: 'cyan', - }, + { icon: 'tabler:cash-register', - count: stats[DebitNoteStatus.Payment] || 0, - label: `debitNote.stats.${DebitNoteStatus.Payment}`, + count: stats['paymentPending'] || 0, + label: `debitNote.stats.${DebitNoteStatus.PaymentPending}`, color: 'dark-orange', }, { icon: 'fluent:receipt-money-16-regular', - count: stats[DebitNoteStatus.Receipt] || 0, - label: `debitNote.stats.${DebitNoteStatus.Receipt}`, + count: stats['paymentSuccess'] || 0, + label: `debitNote.stats.${DebitNoteStatus.PaymentSuccess}`, color: 'green', }, { icon: 'mdi-check-decagram-outline', - count: stats[DebitNoteStatus.Succeed] || 0, - label: `debitNote.stats.${DebitNoteStatus.Succeed}`, + count: stats['processComplete'] || 0, + label: `debitNote.stats.${DebitNoteStatus.ProcessComplete}`, color: 'blue', }, ]" diff --git a/src/pages/12_debit-note/constants.ts b/src/pages/12_debit-note/constants.ts index af2560cd..2434ea69 100644 --- a/src/pages/12_debit-note/constants.ts +++ b/src/pages/12_debit-note/constants.ts @@ -4,29 +4,24 @@ import { formatNumberDecimal } from 'src/stores/utils'; export const taskStatusOpts = [ { - status: DebitNoteStatus.Expire, - name: `debitNote.status.${DebitNoteStatus.Expire}`, + status: DebitNoteStatus.PaymentPending, + name: `debitNote.status.${DebitNoteStatus.PaymentPending}`, }, { - status: DebitNoteStatus.Payment, - name: `debitNote.status.${DebitNoteStatus.Payment}`, + status: DebitNoteStatus.PaymentSuccess, + name: `debitNote.status.${DebitNoteStatus.PaymentSuccess}`, }, { - status: DebitNoteStatus.Receipt, - name: `debitNote.status.${DebitNoteStatus.Receipt}`, - }, - { - status: DebitNoteStatus.Succeed, - name: `debitNote.status.${DebitNoteStatus.Succeed}`, + status: DebitNoteStatus.PaymentSuccess, + name: `debitNote.status.${DebitNoteStatus.ProcessComplete}`, }, ]; export const pageTabs = [ - { label: 'Pending', value: DebitNoteStatus.Pending }, - { label: 'Expire', value: DebitNoteStatus.Expire }, - { label: 'Payment', value: DebitNoteStatus.Payment }, - { label: 'Receipt', value: DebitNoteStatus.Receipt }, - { label: 'Succeed', value: DebitNoteStatus.Succeed }, + { label: 'Pending', value: DebitNoteStatus.Issued }, + { label: 'Payment', value: DebitNoteStatus.PaymentPending }, + { label: 'Receipt', value: DebitNoteStatus.PaymentSuccess }, + { label: 'Succeed', value: DebitNoteStatus.ProcessComplete }, ]; export enum Status { diff --git a/src/stores/debit-note/index.ts b/src/stores/debit-note/index.ts index 7ef3b8b3..40b2c7a4 100644 --- a/src/stores/debit-note/index.ts +++ b/src/stores/debit-note/index.ts @@ -26,7 +26,7 @@ export async function getDebitNoteList(params?: { page?: number; pageSize?: number; query?: string; - deebitNoteStatus?: Status; + status?: Status; includeRegisteredBranch?: boolean; }) { const res = await api.get>(`/${ENDPOINT}`, { @@ -66,12 +66,11 @@ export const useDebitNote = defineStore('debit-note-store', () => { const page = ref(1); const pageMax = ref(1); const pageSize = ref(30); - const stats = ref>({ - [Status.Pending]: 0, - [Status.Expire]: 0, - [Status.Payment]: 0, - [Status.Receipt]: 0, - [Status.Succeed]: 0, + const stats = ref>({ + ['issued']: 0, + ['paymentPending']: 0, + ['paymentSuccess']: 0, + ['processComplete']: 0, }); return { diff --git a/src/stores/debit-note/types.ts b/src/stores/debit-note/types.ts index 00f6b468..2eb901db 100644 --- a/src/stores/debit-note/types.ts +++ b/src/stores/debit-note/types.ts @@ -86,9 +86,9 @@ export type DebitNote = { }; export enum DebitNoteStatus { - Pending = 'Pending', - Expire = 'Expire', - Payment = 'Payment', - Receipt = 'Receipt', - Succeed = 'Succeed', + Issued = 'Issued', + Expired = 'Expired', + PaymentPending = 'PaymentPending', + PaymentSuccess = 'PaymentSuccess', + ProcessComplete = 'ProcessComplete', }