diff --git a/components/DataGrid.tsx b/components/DataGrid.tsx index 8ce821c..ff111d3 100644 --- a/components/DataGrid.tsx +++ b/components/DataGrid.tsx @@ -463,9 +463,14 @@ const DataGrid: React.FC = ({ data, hasCustomerFilter, adsData = acc.sellOut += data.sellOut; acc.units += data.units; } + const ads = row.adsByYear?.[year]; + if (ads) { + acc.adSpend += ads.adSpend; + acc.attributedSales += ads.attributedSales; + } return acc; }, - { sellOut: 0, units: 0 } + { sellOut: 0, units: 0, adSpend: 0, attributedSales: 0 } ); result[year] = totals; @@ -480,9 +485,13 @@ const DataGrid: React.FC = ({ data, hasCustomerFilter, adsData = acc.sellOut += data.sellOut; acc.units += data.units; } + const ads = row.adsByYear?.[prevYear]; + if (ads) { + acc.adSpend += ads.adSpend; + } return acc; }, - { sellOut: 0, units: 0 } + { sellOut: 0, units: 0, adSpend: 0 } ); if (prevYearTotals.sellOut > 0) { @@ -496,6 +505,12 @@ const DataGrid: React.FC = ({ data, hasCustomerFilter, adsData = } else if (totals.units > 0) { result[year].unitsGrowth = 100; } + + if (prevYearTotals.adSpend > 0) { + (result[year] as any).adSpendGrowth = ((totals.adSpend - prevYearTotals.adSpend) / prevYearTotals.adSpend) * 100; + } else if (totals.adSpend > 0) { + (result[year] as any).adSpendGrowth = 100; + } } }); @@ -898,7 +913,30 @@ const DataGrid: React.FC = ({ data, hasCustomerFilter, adsData = {prevYear && } - {showAdsMetrics && adsSummary && } + {showAdsMetrics && adsSummary && ( + <> + +
+ + €{totals.adSpend.toLocaleString('de-DE', { maximumFractionDigits: 0 })} + + {(totals as any).adSpendGrowth !== undefined && ( + + {(totals as any).adSpendGrowth >= 0 ? '↑' : '↓'} {Math.abs((totals as any).adSpendGrowth).toFixed(1)}% + + )} +
+ + +
+ + {totals.sellOut > 0 ? ((totals.adSpend / totals.sellOut) * 100).toFixed(2) : '0.00'}% + + TACOS +
+ + + )} ); })}