Skip to content

Commit

Permalink
fix: export csv/xlsx reports
Browse files Browse the repository at this point in the history
  • Loading branch information
abouolia committed Nov 27, 2023
1 parent 59b9eeb commit 0450f9a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export default class BalanceSheetStatementController extends BaseFinancialReport
...filter,
accountsIds: castArray(filter.accountsIds),
};

try {
const accept = this.accepts(req);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default class CashFlowController extends BaseFinancialReportController {
ACCEPT_TYPE.APPLICATION_JSON,
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
ACCEPT_TYPE.APPLICATION_CSV,
ACCEPT_TYPE.APPLICATION_PDF,
ACCEPT_TYPE.APPLICATION_XLSX,
]);
// Retrieves the json table format.
if (ACCEPT_TYPE.APPLICATION_JSON_TABLE === acceptType) {
Expand All @@ -105,7 +105,7 @@ export default class CashFlowController extends BaseFinancialReportController {
'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
);
return res.status(200).send(buffer);
return res.send(buffer);
// Retrieves the json format.
} else {
const cashflow = await this.cashflowSheetApp.sheet(tenantId, filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export class CashflowExportInjectable {
* @param {ICashFlowStatementQuery} query
* @returns {Promise<Buffer>}
*/
public async xlsx(tenantId: number, query: ICashFlowStatementQuery) {
public async xlsx(
tenantId: number,
query: ICashFlowStatementQuery
): Promise<Buffer> {
const table = await this.cashflowSheetTable.table(tenantId, query);

const tableSheet = new TableSheet(table.table);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
useBalanceSheetCsvExport,
useBalanceSheetXlsxExport,
} from '@/hooks/query';
import { useBalanceSheetQuery } from './utils';

/**
* Balance sheet alerts.
Expand Down Expand Up @@ -97,7 +96,7 @@ export const BalanceSheetExportMenu = () => {
isCloseButtonShown: true,
timeout: 2000,
};
const { query } = useBalanceSheetQuery();
const { query } = useBalanceSheetContext();

const openProgressToast = (amount: number) => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
useTrialBalanceSheetCsvExport,
useTrialBalanceSheetXlsxExport,
} from '@/hooks/query';
import { useTrialBalanceSheetQuery } from './utils';
import { useTrialBalanceSheetHttpQuery } from './utils';

/**
* Trial balance sheet progress loading bar.
Expand Down Expand Up @@ -80,7 +80,7 @@ export const TrialBalanceSheetExportMenu = () => {
isCloseButtonShown: true,
timeout: 2000,
};
const { query } = useTrialBalanceSheetQuery();
const httpQuery = useTrialBalanceSheetHttpQuery();

const openProgressToast = (amount: number) => {
return (
Expand All @@ -97,26 +97,29 @@ export const TrialBalanceSheetExportMenu = () => {
);
};
// Export the report to xlsx.
const { mutateAsync: xlsxExport } = useTrialBalanceSheetXlsxExport(query, {
onDownloadProgress: (xlsxExportProgress: number) => {
if (!toastKey.current) {
toastKey.current = AppToaster.show({
message: openProgressToast(xlsxExportProgress),
...commonToastConfig,
});
} else {
AppToaster.show(
{
const { mutateAsync: xlsxExport } = useTrialBalanceSheetXlsxExport(
httpQuery,
{
onDownloadProgress: (xlsxExportProgress: number) => {
if (!toastKey.current) {
toastKey.current = AppToaster.show({
message: openProgressToast(xlsxExportProgress),
...commonToastConfig,
},
toastKey.current,
);
}
});
} else {
AppToaster.show(
{
message: openProgressToast(xlsxExportProgress),
...commonToastConfig,
},
toastKey.current,
);
}
},
},
});
);
// Export the report to csv.
const { mutateAsync: csvExport } = useTrialBalanceSheetCsvExport(query, {
const { mutateAsync: csvExport } = useTrialBalanceSheetCsvExport(httpQuery, {
onDownloadProgress: (xlsxExportProgress: number) => {
if (!toastKey.current) {
toastKey.current = AppToaster.show({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { castArray } from 'lodash';

import { useAppQueryString } from '@/hooks';
import { transformToForm } from '@/utils';
import { transformFilterFormToQuery } from '../common';

/**
* Retrieves the default trial balance query.
Expand Down Expand Up @@ -56,3 +57,13 @@ export const useTrialBalanceSheetQuery = () => {
setLocationQuery,
};
};

/**
* Retrieves the trial balance sheet http query.
* @returns {object}
*/
export const useTrialBalanceSheetHttpQuery = () => {
const { query } = useTrialBalanceSheetQuery();

return React.useMemo(() => transformFilterFormToQuery(query), [query]);
};

0 comments on commit 0450f9a

Please sign in to comment.