feat: download report
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 8s
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 8s
This commit is contained in:
parent
7522c967d9
commit
e6f2a8df4e
3 changed files with 106 additions and 9 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import { ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { Pagination, Status } from '../types';
|
||||
import { api } from 'src/boot/axios';
|
||||
import {
|
||||
Report,
|
||||
|
|
@ -9,9 +8,33 @@ import {
|
|||
ReportQuotation,
|
||||
ReportSale,
|
||||
} from './types';
|
||||
import { baseUrl } from '../utils';
|
||||
import { getToken } from 'src/services/keycloak';
|
||||
|
||||
const ENDPOINT = 'report';
|
||||
|
||||
async function _download(url: string, filename?: string) {
|
||||
const res = await fetch(url, {
|
||||
headers: { ['Authorization']: 'Bearer ' + (await getToken()) },
|
||||
});
|
||||
const text = await res.json();
|
||||
const blob = new Blob([text], { type: 'text/csv' });
|
||||
if (res.ok && blob) {
|
||||
const a = document.createElement('a');
|
||||
a.download = (filename || 'report') + '.csv';
|
||||
a.href = window.URL.createObjectURL(blob);
|
||||
a.click();
|
||||
a.remove();
|
||||
}
|
||||
}
|
||||
|
||||
export async function downloadReportQuotation() {
|
||||
await _download(
|
||||
baseUrl + '/' + ENDPOINT + '/quotation/download',
|
||||
'quotation-report',
|
||||
);
|
||||
}
|
||||
|
||||
export async function getReportQuotation() {
|
||||
const res = await api.get<ReportQuotation[]>(`/${ENDPOINT}/quotation`);
|
||||
if (res.status < 400) {
|
||||
|
|
@ -21,6 +44,13 @@ export async function getReportQuotation() {
|
|||
return null;
|
||||
}
|
||||
|
||||
export async function downloadReportInvoice() {
|
||||
await _download(
|
||||
baseUrl + '/' + ENDPOINT + '/invoice/download',
|
||||
'invoice-report',
|
||||
);
|
||||
}
|
||||
|
||||
export async function getReportInvoice() {
|
||||
const res = await api.get<Report[]>(`/${ENDPOINT}/invoice`);
|
||||
if (res.status < 400) {
|
||||
|
|
@ -29,6 +59,13 @@ export async function getReportInvoice() {
|
|||
return null;
|
||||
}
|
||||
|
||||
export async function downloadReportReceipt() {
|
||||
await _download(
|
||||
baseUrl + '/' + ENDPOINT + '/receipt/download',
|
||||
'receipt-report',
|
||||
);
|
||||
}
|
||||
|
||||
export async function getReportReceipt() {
|
||||
const res = await api.get<Report[]>(`/${ENDPOINT}/receipt`);
|
||||
if (res.status < 400) {
|
||||
|
|
@ -46,6 +83,13 @@ export async function getReportSale() {
|
|||
return null;
|
||||
}
|
||||
|
||||
export async function downloadReportProduct() {
|
||||
await _download(
|
||||
baseUrl + '/' + ENDPOINT + '/receipt/download',
|
||||
'product-report',
|
||||
);
|
||||
}
|
||||
|
||||
export async function getReportProduct() {
|
||||
const res = await api.get<ReportProduct[]>(`/${ENDPOINT}/product`);
|
||||
if (res.status < 400) {
|
||||
|
|
@ -78,10 +122,14 @@ export const useReportStore = defineStore('report-store', () => {
|
|||
dataReportProduct,
|
||||
dataReportPayment,
|
||||
|
||||
downloadReportQuotation,
|
||||
getReportQuotation,
|
||||
downloadReportInvoice,
|
||||
getReportInvoice,
|
||||
downloadReportReceipt,
|
||||
getReportReceipt,
|
||||
getReportSale,
|
||||
downloadReportProduct,
|
||||
getReportProduct,
|
||||
getReportPayment,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue