Skip to content

Commit

Permalink
Merge pull request #3006 from LiteFarmOrg/LF-3866-could-not-download-…
Browse files Browse the repository at this point in the history
…finance-report

LF-3866 Could not download finance report
  • Loading branch information
SayakaOno authored Nov 20, 2023
2 parents 4a0c761 + ddedbf6 commit 609100a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/api/src/util/generateFinanceReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const generateTransactionsList = ({
title,
}) => {
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet(title);
const worksheet = workbook.addWorksheet(getFallbackTitle(title, 'Transactions'));

addHeadersToWorksheet(worksheet, reportHeaders);
setWorksheetColumnWidths(worksheet, [36, 18, 12, 14]);
Expand Down Expand Up @@ -67,7 +67,7 @@ export const addConfigurationWorksheet = ({
language,
title,
}) => {
const worksheet = workbook.addWorksheet(title);
const worksheet = workbook.addWorksheet(getFallbackTitle(title, 'Export Settings'));

const expenseTypes = generateTypeCountAndList(config.typesFilter.EXPENSE_TYPE);
const revenueTypes = generateTypeCountAndList(config.typesFilter.REVENUE_TYPE);
Expand Down Expand Up @@ -224,3 +224,14 @@ function addConfigDataRows({
const formatDate = (date, language = 'en') => {
return new Date(date).toLocaleDateString(language);
};

/**
* Returns the translated worksheet title, or English fallback if necessary
*
* @param {string} title - The translated title string to check.
* @param {string} defaultTitle - The default title to use if the original is missing or marked as 'MISSING'.
* @returns {string} - The original title or the default title if the original is missing or 'MISSING'.
*/
const getFallbackTitle = (title, defaultTitle) => {
return !title || title === 'MISSING' ? defaultTitle : title;
};

0 comments on commit 609100a

Please sign in to comment.