bugfixing: show last X years correctly for quarter results

This commit is contained in:
MuslemRahimi 2024-08-13 14:54:08 +02:00
parent 1de76c212b
commit 465e7385de
4 changed files with 62 additions and 29 deletions

View File

@ -379,11 +379,23 @@ const exportData = (format = 'csv') => {
fullStatement = data?.getBalanceSheetStatement; fullStatement = data?.getBalanceSheetStatement;
timeFrame = '10Y'; timeFrame = '10Y';
balanceSheet = fullStatement?.slice(0,10);
displayStatement = 'cashAndCashEquivalents'; displayStatement = 'cashAndCashEquivalents';
const getCurrentYear = () => new Date()?.getFullYear();
const filterStatement = (fullStatement, timeFrame) => {
const currentYear = getCurrentYear();
switch(timeFrame) {
case '5Y':
return fullStatement?.filter(item => currentYear - parseInt(item?.calendarYear) < 5);
case '10Y':
return fullStatement?.filter(item => currentYear - parseInt(item?.calendarYear) < 10);
default:
return fullStatement;
}
};
$: { $: {
if (timeFrame || displayStatement || filterRule) if (timeFrame || displayStatement || filterRule)
{ {
@ -395,11 +407,7 @@ $: {
fullStatement = data?.getBalanceSheetStatement; fullStatement = data?.getBalanceSheetStatement;
} }
balanceSheet = timeFrame === '5Y' balanceSheet = filterStatement(fullStatement, timeFrame);
? (fullStatement?.slice(0, 5))
: timeFrame === '10Y'
? (fullStatement?.slice(0, 10))
: fullStatement;
if (mode === true) if (mode === true)
{ {

View File

@ -344,11 +344,24 @@ const exportData = (format = 'csv') => {
fullStatement = data?.getCashFlowStatement; fullStatement = data?.getCashFlowStatement;
timeFrame = '10Y'; timeFrame = '10Y';
cashFlow = fullStatement?.slice(0,10);
displayStatement = 'netIncome'; displayStatement = 'netIncome';
const getCurrentYear = () => new Date()?.getFullYear();
const filterStatement = (fullStatement, timeFrame) => {
const currentYear = getCurrentYear();
switch(timeFrame) {
case '5Y':
return fullStatement?.filter(item => currentYear - parseInt(item?.calendarYear) < 5);
case '10Y':
return fullStatement?.filter(item => currentYear - parseInt(item?.calendarYear) < 10);
default:
return fullStatement;
}
};
$: { $: {
if (timeFrame || displayStatement || filterRule) if (timeFrame || displayStatement || filterRule)
{ {
@ -359,11 +372,7 @@ $: {
fullStatement = data?.getCashFlowStatement; fullStatement = data?.getCashFlowStatement;
} }
cashFlow = timeFrame === '5Y' cashFlow = filterStatement(fullStatement, timeFrame);
? (fullStatement?.slice(0, 5))
: timeFrame === '10Y'
? (fullStatement?.slice(0, 10))
: fullStatement;
if (mode === true) if (mode === true)
{ {

View File

@ -315,10 +315,23 @@ const exportData = (format = 'csv') => {
}; };
*/ */
const getCurrentYear = () => new Date()?.getFullYear();
const filterStatement = (fullStatement, timeFrame) => {
const currentYear = getCurrentYear();
switch(timeFrame) {
case '5Y':
return fullStatement?.filter(item => currentYear - parseInt(item?.calendarYear) < 5);
case '10Y':
return fullStatement?.filter(item => currentYear - parseInt(item?.calendarYear) < 10);
default:
return fullStatement;
}
};
fullStatement = data?.getIncomeStatement; fullStatement = data?.getIncomeStatement;
timeFrame = '10Y'; timeFrame = '10Y';
income = fullStatement?.slice(0,10);
displayStatement = 'revenue'; displayStatement = 'revenue';
@ -331,12 +344,7 @@ const exportData = (format = 'csv') => {
else { else {
fullStatement = data?.getIncomeStatement; fullStatement = data?.getIncomeStatement;
} }
income = filterStatement(fullStatement, timeFrame);
income = timeFrame === '5Y'
? (fullStatement?.slice(0, 5))
: timeFrame === '10Y'
? (fullStatement?.slice(0, 10))
: fullStatement;
if (mode === true) if (mode === true)
{ {

View File

@ -288,10 +288,22 @@ const exportData = (format = 'csv') => {
fullStatement = data?.getRatiosStatement; fullStatement = data?.getRatiosStatement;
timeFrame = '10Y'; timeFrame = '10Y';
ratios = fullStatement?.slice(0,10);
displayStatement = 'priceEarningsRatio'; displayStatement = 'priceEarningsRatio';
const getCurrentYear = () => new Date()?.getFullYear();
const filterStatement = (fullStatement, timeFrame) => {
const currentYear = getCurrentYear();
switch(timeFrame) {
case '5Y':
return fullStatement?.filter(item => currentYear - parseInt(item?.calendarYear) < 5);
case '10Y':
return fullStatement?.filter(item => currentYear - parseInt(item?.calendarYear) < 10);
default:
return fullStatement;
}
};
$: { $: {
@ -304,11 +316,7 @@ $: {
fullStatement = data?.getRatiosStatement; fullStatement = data?.getRatiosStatement;
} }
ratios = timeFrame === '5Y' ratios = filterStatement(fullStatement, timeFrame);
? (fullStatement?.slice(0, 5))
: timeFrame === '10Y'
? (fullStatement?.slice(0, 10))
: fullStatement;
if (mode === true) if (mode === true)
{ {