Skip to content

Commit

Permalink
include year in excel filename
Browse files Browse the repository at this point in the history
  • Loading branch information
eperedo committed Nov 19, 2024
1 parent 47e0009 commit 5139248
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ export const CountryIndicatorReport = React.memo(() => {
: undefined;

const downloadReport = () => {
if (indicatorReport && orgUnit && selectedPeriod) {
if (indicatorReport && orgUnit && selectedPeriod && year) {
buildSpreadSheet({
indicatorReport,
countryName: orgUnit.displayName,
period: selectedPeriod,
settings,
year,
}).then(downloadFile);
}
};
Expand Down
10 changes: 6 additions & 4 deletions src/pages/country-indicator-report/excel-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@ type SpreadSheetOptions = {
countryName: string;
settings: UniqueBeneficiariesSettings[];
period: UniqueBeneficiariesPeriod;
year: number;
};

export async function buildSpreadSheet(options: SpreadSheetOptions) {
const { indicatorReport, countryName } = options;
const { indicatorReport, countryName, year } = options;
const workbook = new ExcelJS.Workbook();
const sheet = workbook.addWorksheet(i18n.t("Country Projects & Indicators"));
sheet.columns = generateColumns();
generateRows(options, sheet);
return generateFileInBuffer(workbook, countryName, indicatorReport);
return generateFileInBuffer(workbook, countryName, indicatorReport, year);
}

async function generateFileInBuffer(
workbook: ExcelJS.Workbook,
countryName: string,
indicatorReport: IndicatorReport
indicatorReport: IndicatorReport,
year: number
) {
const buffer = await workbook.xlsx.writeBuffer();
const filename = `${countryName.toLowerCase()}_${indicatorReport.period.name.toLowerCase()}_report.xlsx`;
const filename = `${countryName.toLowerCase()}_${indicatorReport.period.name.toLowerCase()}_${year}_report.xlsx`;
return { buffer, filename };
}

Expand Down

0 comments on commit 5139248

Please sign in to comment.