diff --git a/apps/saip-fe/src/components/reports/IndustryReport.tsx b/apps/saip-fe/src/components/reports/IndustryReport.tsx index 74f3457..032a0c7 100644 --- a/apps/saip-fe/src/components/reports/IndustryReport.tsx +++ b/apps/saip-fe/src/components/reports/IndustryReport.tsx @@ -159,37 +159,46 @@ function IndustryReport() { {index + 1} {industry[0]} - {numberWithSpaces(industry[1].stock_price)} € + {industry[1]?.stock_price && + numberWithSpaces(industry[1]?.stock_price)}{" "} + € - {numberWithSpaces(industry[1].net_profit)} € + {industry[1]?.net_profit && + numberWithSpaces(industry[1]?.net_profit)}{" "} + € - {numberWithSpaces(industry[1].sell_price)} €/ks + {industry[1]?.sell_price && + numberWithSpaces(industry[1]?.sell_price)}{" "} + €/ks - {numberWithSpaces(industry[1].market_share)} % + {industry[1]?.market_share && + numberWithSpaces(industry[1]?.market_share)}{" "} + % ))} {/* Add row for average stock price */} + Priemer - {/* Calculate and display average stock price */} {data && ( - {numberWithSpaces( - ( - Object.values(data.industry).reduce( - (acc, curr) => acc + curr.stock_price, - 0, - ) / Object.keys(data.industry).length - ).toFixed(2), - )}{" "} + {data.industry && + numberWithSpaces( + ( + Object.values(data.industry).reduce( + (acc, curr) => acc + (curr?.stock_price || 0), + 0, + ) / Object.keys(data.industry).length + ).toFixed(2), + )}{" "} € )} @@ -198,14 +207,15 @@ function IndustryReport() { {/* Calculate and display average net profit */} {data && ( - {numberWithSpaces( - ( - Object.values(data.industry).reduce( - (acc, curr) => acc + curr.net_profit, - 0, - ) / Object.keys(data.industry).length - ).toFixed(2), - )}{" "} + {data.industry && + numberWithSpaces( + ( + Object.values(data.industry).reduce( + (acc, curr) => acc + (curr?.net_profit || 0), + 0, + ) / Object.keys(data.industry).length + ).toFixed(2), + )}{" "} € )} @@ -214,17 +224,18 @@ function IndustryReport() { {/* Calculate and display average sell price */} {data && ( - {numberWithSpaces( - Object.values(data.industry).reduce( - (acc, curr) => acc + curr.sell_price, - 0, - ) / Object.keys(data.industry).length, - )}{" "} + {data.industry && + numberWithSpaces( + Object.values(data.industry).reduce( + (acc, curr) => acc + (curr?.sell_price || 0), + 0, + ) / Object.keys(data.industry).length, + )}{" "} €/ks )} - +