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

This commit is contained in:
Thanaphon Frappet 2025-03-12 15:36:02 +07:00
parent 3dbbc4f98c
commit 47395b0847
2 changed files with 91 additions and 13 deletions

View file

@ -305,7 +305,12 @@ watch([() => pastYears.value], async () => {
style="margin-left: auto"
:icon="'material-symbols:download'"
:label="$t('general.download')"
@click.stop="reportStore.downloadReportQuotation()"
@click.stop="
reportStore.downloadReportQuotation({
startDate: state.date[0],
endDate: state.date[1],
})
"
/>
</div>
</template>
@ -346,7 +351,12 @@ watch([() => pastYears.value], async () => {
style="margin-left: auto"
:icon="'material-symbols:download'"
:label="$t('general.download')"
@click.stop="reportStore.downloadReportInvoice()"
@click.stop="
reportStore.downloadReportInvoice({
startDate: state.date[0],
endDate: state.date[1],
})
"
/>
</div>
</template>
@ -386,7 +396,12 @@ watch([() => pastYears.value], async () => {
style="margin-left: auto"
:icon="'material-symbols:download'"
:label="$t('general.download')"
@click.stop="reportStore.downloadReportReceipt()"
@click.stop="
reportStore.downloadReportReceipt({
startDate: state.date[0],
endDate: state.date[1],
})
"
/>
</div>
</template>
@ -428,7 +443,12 @@ watch([() => pastYears.value], async () => {
style="margin-left: auto"
:icon="'material-symbols:download'"
:label="$t('general.download')"
@click.stop="reportStore.downloadReportInvoice()"
@click.stop="
reportStore.downloadReportInvoice({
startDate: state.date[0],
endDate: state.date[1],
})
"
/>
</div>
</template>
@ -469,7 +489,12 @@ watch([() => pastYears.value], async () => {
style="margin-left: auto"
:icon="'material-symbols:download'"
:label="$t('general.download')"
@click.stop="reportStore.downloadReportInvoice()"
@click.stop="
reportStore.downloadReportInvoice({
startDate: state.date[0],
endDate: state.date[1],
})
"
/>
</div>
</template>
@ -492,7 +517,10 @@ watch([() => pastYears.value], async () => {
:icon="'material-symbols:download'"
:label="$t('general.download')"
@click.stop="
reportStore.downloadReportSale('by-customer')
reportStore.downloadReportSale('by-customer', {
startDate: state.date[0],
endDate: state.date[1],
})
"
/>
</div>
@ -533,7 +561,10 @@ watch([() => pastYears.value], async () => {
:icon="'material-symbols:download'"
:label="$t('general.download')"
@click.stop="
reportStore.downloadReportSale('by-product-group')
reportStore.downloadReportSale('by-product-group', {
startDate: state.date[0],
endDate: state.date[1],
})
"
/>
</div>
@ -565,7 +596,12 @@ watch([() => pastYears.value], async () => {
style="margin-left: auto"
:icon="'material-symbols:download'"
:label="$t('general.download')"
@click.stop="reportStore.downloadReportSale('by-sale')"
@click.stop="
reportStore.downloadReportSale('by-sale', {
startDate: state.date[0],
endDate: state.date[1],
})
"
/>
</div>
</template>

View file

@ -15,7 +15,28 @@ import { getToken } from 'src/services/keycloak';
const ENDPOINT = 'report';
async function _download(url: string, filename?: string) {
async function _download(
url: string,
filename?: string,
params?: {
startDate: string | Date;
endDate: string | Date;
},
) {
if (params) {
const queryParams = new URLSearchParams({
startDate:
params.startDate instanceof Date
? params.startDate.toISOString()
: params.startDate,
endDate:
params.endDate instanceof Date
? params.endDate.toISOString()
: params.endDate,
}).toString();
url += '?' + queryParams;
}
const res = await fetch(url, {
headers: { ['Authorization']: 'Bearer ' + (await getToken()) },
});
@ -30,10 +51,14 @@ async function _download(url: string, filename?: string) {
}
}
export async function downloadReportQuotation() {
export async function downloadReportQuotation(params?: {
startDate: string | Date;
endDate: string | Date;
}) {
await _download(
baseUrl + '/' + ENDPOINT + '/quotation/download',
'quotation-report',
params,
);
}
@ -51,10 +76,14 @@ export async function getReportQuotation(params?: {
return null;
}
export async function downloadReportInvoice() {
export async function downloadReportInvoice(params?: {
startDate: string | Date;
endDate: string | Date;
}) {
await _download(
baseUrl + '/' + ENDPOINT + '/invoice/download',
'invoice-report',
params,
);
}
@ -69,10 +98,14 @@ export async function getReportInvoice(params?: {
return null;
}
export async function downloadReportReceipt() {
export async function downloadReportReceipt(params?: {
startDate: string | Date;
endDate: string | Date;
}) {
await _download(
baseUrl + '/' + ENDPOINT + '/receipt/download',
'receipt-report',
params,
);
}
@ -89,10 +122,15 @@ export async function getReportReceipt(params?: {
export async function downloadReportSale(
category: 'by-product-group' | 'by-sale' | 'by-customer',
params?: {
startDate: string | Date;
endDate: string | Date;
},
) {
await _download(
baseUrl + '/' + ENDPOINT + '/sale/' + category + '/download',
'sale-' + category + '-report',
params,
);
}
@ -108,10 +146,14 @@ export async function getReportSale(params?: {
return null;
}
export async function downloadReportProduct() {
export async function downloadReportProduct(params?: {
startDate: string | Date;
endDate: string | Date;
}) {
await _download(
baseUrl + '/' + ENDPOINT + '/receipt/download',
'product-report',
params,
);
}