refactor: add start date and end date
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 9s

This commit is contained in:
Thanaphon Frappet 2025-03-12 15:16:27 +07:00
parent db9a1d7056
commit 3dbbc4f98c
2 changed files with 109 additions and 17 deletions

View file

@ -30,6 +30,7 @@ import BadgeComponent from 'src/components/BadgeComponent.vue';
import Expansion from 'src/components/14_report/Expansion.vue'; import Expansion from 'src/components/14_report/Expansion.vue';
import { SaveButton } from 'src/components/button'; import { SaveButton } from 'src/components/button';
import { ReportProfit } from 'src/stores/report/types'; import { ReportProfit } from 'src/stores/report/types';
import { dateFormatJS } from 'src/utils/datetime';
// NOTE: Variable // NOTE: Variable
const navigatorStore = useNavigator(); const navigatorStore = useNavigator();
@ -50,6 +51,13 @@ const {
detaReportDept, detaReportDept,
} = storeToRefs(reportStore); } = storeToRefs(reportStore);
const endDate = new Date();
const startDate = new Date(new Date().setFullYear(endDate.getFullYear() - 1));
const state = reactive({
date: [startDate, endDate],
});
const userRoles = computed(() => getRole() || []); const userRoles = computed(() => getRole() || []);
const combinedProfitYear = computed(() => { const combinedProfitYear = computed(() => {
@ -74,24 +82,48 @@ const combinedProfitYear = computed(() => {
}); });
async function fetchReportQuotation() { async function fetchReportQuotation() {
dataReportQuotation.value = (await reportStore.getReportQuotation()) || []; dataReportQuotation.value =
(await reportStore.getReportQuotation({
startDate: state.date[0],
endDate: state.date[1],
})) || [];
} }
async function fetchReportInvoice() { async function fetchReportInvoice() {
dataReportInvoice.value = (await reportStore.getReportInvoice()) || []; dataReportInvoice.value =
(await reportStore.getReportInvoice({
startDate: state.date[0],
endDate: state.date[1],
})) || [];
} }
async function fetchReportReceipt() { async function fetchReportReceipt() {
dataReportReceipt.value = (await reportStore.getReportReceipt()) || []; dataReportReceipt.value =
(await reportStore.getReportReceipt({
startDate: state.date[0],
endDate: state.date[1],
})) || [];
} }
async function fetchReportSale() { async function fetchReportSale() {
dataReportSale.value = (await reportStore.getReportSale()) || undefined; dataReportSale.value =
(await reportStore.getReportSale({
startDate: state.date[0],
endDate: state.date[1],
})) || undefined;
} }
async function fetchReportProduct() { async function fetchReportProduct() {
dataReportProduct.value = (await reportStore.getReportProduct()) || []; dataReportProduct.value =
(await reportStore.getReportProduct({
startDate: state.date[0],
endDate: state.date[1],
})) || [];
} }
async function fetchReportProfit() { async function fetchReportProfit() {
dataReportProfit.value = (await reportStore.getReportProfit()) || undefined; dataReportProfit.value =
(await reportStore.getReportProfit({
startDate: state.date[0],
endDate: state.date[1],
})) || undefined;
dataReportProfitByYears.value = dataReportProfit.value?.dataset || []; dataReportProfitByYears.value = dataReportProfit.value?.dataset || [];
} }
@ -163,7 +195,7 @@ onMounted(async () => {
await fetchReportTab(); await fetchReportTab();
}); });
watch([() => pageState.currentTab], async () => { watch([() => pageState.currentTab, () => state.date], async () => {
await fetchReportTab(); await fetchReportTab();
}); });
@ -174,9 +206,50 @@ watch([() => pastYears.value], async () => {
<template> <template>
<div class="column full-height no-wrap"> <div class="column full-height no-wrap">
<div class="row q-mb-sm">
<VueDatePicker
utc
range
teleport
auto-apply
for="select-date-range"
class="col-md-3 col"
v-model="state.date"
:dark="$q.dark.isActive"
:locale="$i18n.locale === 'tha' ? 'th' : 'en'"
>
<template #trigger>
<q-input
placeholder="DD/MM/YYYY"
hide-bottom-space
dense
outlined
for="select-date-range"
:model-value="
dateFormatJS({ date: state.date[0] }) +
' - ' +
dateFormatJS({ date: state.date[1] })
"
>
<template #prepend>
<q-icon name="mdi-calendar-outline" class="app-text-muted" />
</template>
<q-tooltip>
{{
dateFormatJS({ date: state.date[0] }) +
' - ' +
dateFormatJS({ date: state.date[1] })
}}
</q-tooltip>
</q-input>
</template>
</VueDatePicker>
</div>
<section class="col surface-1 rounded bordered overflow-hidden"> <section class="col surface-1 rounded bordered overflow-hidden">
<div class="column full-height"> <div class="column full-height">
<!-- SEC: header content --> <!-- SEC: header content -->
<header <header
class="row surface-3 justify-between full-width items-center" class="row surface-3 justify-between full-width items-center"
style="z-index: 1" style="z-index: 1"

View file

@ -37,8 +37,13 @@ export async function downloadReportQuotation() {
); );
} }
export async function getReportQuotation() { export async function getReportQuotation(params?: {
const res = await api.get<ReportQuotation[]>(`/${ENDPOINT}/quotation`); startDate: string | Date;
endDate: string | Date;
}) {
const res = await api.get<ReportQuotation[]>(`/${ENDPOINT}/quotation`, {
params,
});
if (res.status < 400) { if (res.status < 400) {
res.data; res.data;
return res.data; return res.data;
@ -53,8 +58,11 @@ export async function downloadReportInvoice() {
); );
} }
export async function getReportInvoice() { export async function getReportInvoice(params?: {
const res = await api.get<Report[]>(`/${ENDPOINT}/invoice`); startDate: string | Date;
endDate: string | Date;
}) {
const res = await api.get<Report[]>(`/${ENDPOINT}/invoice`, { params });
if (res.status < 400) { if (res.status < 400) {
return res.data; return res.data;
} }
@ -68,8 +76,11 @@ export async function downloadReportReceipt() {
); );
} }
export async function getReportReceipt() { export async function getReportReceipt(params?: {
const res = await api.get<Report[]>(`/${ENDPOINT}/receipt`); startDate: string | Date;
endDate: string | Date;
}) {
const res = await api.get<Report[]>(`/${ENDPOINT}/receipt`, { params });
if (res.status < 400) { if (res.status < 400) {
return res.data; return res.data;
} }
@ -85,8 +96,11 @@ export async function downloadReportSale(
); );
} }
export async function getReportSale() { export async function getReportSale(params?: {
const res = await api.get<ReportSale>(`/${ENDPOINT}/sale`); startDate: string | Date;
endDate: string | Date;
}) {
const res = await api.get<ReportSale>(`/${ENDPOINT}/sale`, { params });
if (res.status < 400) { if (res.status < 400) {
return res.data; return res.data;
@ -101,8 +115,13 @@ export async function downloadReportProduct() {
); );
} }
export async function getReportProduct() { export async function getReportProduct(params?: {
const res = await api.get<ReportProduct[]>(`/${ENDPOINT}/product`); startDate: string | Date;
endDate: string | Date;
}) {
const res = await api.get<ReportProduct[]>(`/${ENDPOINT}/product`, {
params,
});
if (res.status < 400) { if (res.status < 400) {
return res.data; return res.data;
} }