diff --git a/ipi-survey-platform/src/pages/Admin/ValidationReview.jsx b/ipi-survey-platform/src/pages/Admin/ValidationReview.jsx index 7004a69..9d7e3d8 100644 --- a/ipi-survey-platform/src/pages/Admin/ValidationReview.jsx +++ b/ipi-survey-platform/src/pages/Admin/ValidationReview.jsx @@ -856,6 +856,19 @@ setAdditionalForecastMonths([ return `${quarter} ${year}`; }; + const sumQuarterValues = (...values) => + values.reduce((total, value) => total + (Number(value) || 0), 0); + + const formatQuarterValue = (value) => { + const numericValue = Number(value) || 0; + + if (Number.isInteger(numericValue)) { + return numericValue.toString(); + } + + return numericValue.toFixed(2).replace(/\.?0+$/, ''); + }; + if (loading) { return (
@@ -1096,6 +1109,52 @@ setAdditionalForecastMonths([ (!product.previous_cost_period_one || Number(product.previous_cost_period_one) === 0) && (!product.previous_cost_period_two || Number(product.previous_cost_period_two) === 0) && (!product.previous_cost_period_three || Number(product.previous_cost_period_three) === 0); + + const historicalData = showPreviousNext + ? getCurrentYearForecastData(product?.product?.id) + : null; + + const previousQuantityTotal = sumQuarterValues( + product.previous_quantity_period_one, + product.previous_quantity_period_two, + product.previous_quantity_period_three + ); + const currentQuantityTotal = sumQuarterValues( + product.current_quantity_period_one, + product.current_quantity_period_two, + product.current_quantity_period_three + ); + const historicalQuantityTotal = sumQuarterValues( + historicalData?.forecast_quantity_period_one, + historicalData?.forecast_quantity_period_two, + historicalData?.forecast_quantity_period_three + ); + const forecastQuantityTotal = sumQuarterValues( + product.forecast_quantity_period_one, + product.forecast_quantity_period_two, + product.forecast_quantity_period_three + ); + + const previousCostTotal = sumQuarterValues( + product.previous_cost_period_one, + product.previous_cost_period_two, + product.previous_cost_period_three + ); + const currentCostTotal = sumQuarterValues( + product.current_cost_period_one, + product.current_cost_period_two, + product.current_cost_period_three + ); + const historicalCostTotal = sumQuarterValues( + historicalData?.forecast_cost_period_one, + historicalData?.forecast_cost_period_two, + historicalData?.forecast_cost_period_three + ); + const forecastCostTotal = sumQuarterValues( + product.forecast_cost_period_one, + product.forecast_cost_period_two, + product.forecast_cost_period_three + ); return (
@@ -1216,10 +1275,16 @@ setAdditionalForecastMonths([
)} - +
- @@ -1227,18 +1292,18 @@ setAdditionalForecastMonths([ <> {/* 12 columns when showPreviousNext is true */} {!shouldHidePreviousQuarter && ( - )} - - {!shouldHideForecast && ( - )} @@ -1247,15 +1312,15 @@ setAdditionalForecastMonths([ <> {/* 9 columns when showPreviousNext is false */} {!shouldHidePreviousQuarter && ( - )} - {!shouldHideForecast && ( - )} @@ -1278,6 +1343,9 @@ setAdditionalForecastMonths([ + )} @@ -1291,6 +1359,9 @@ setAdditionalForecastMonths([ + {/* Previous Forecast Months */} + {/* Next Year Forecast Months */} {!shouldHideForecast && ( @@ -1315,6 +1389,9 @@ setAdditionalForecastMonths([ + )} @@ -1332,6 +1409,9 @@ setAdditionalForecastMonths([ + )} @@ -1345,6 +1425,9 @@ setAdditionalForecastMonths([ + {/* Next Year Forecast Months */} {!shouldHideForecast && ( @@ -1358,6 +1441,9 @@ setAdditionalForecastMonths([ + )} @@ -1411,6 +1497,11 @@ setAdditionalForecastMonths([ )} + )} @@ -1455,33 +1546,42 @@ setAdditionalForecastMonths([ )} + {/* HISTORICAL Data (from API) */} - {showPreviousNext && (() => { - const historicalData = getCurrentYearForecastData(product?.product?.id); - return ( - <> - - - - - ); - })()} + {showPreviousNext && ( + <> + + + + + + )} {/* NEXT YEAR FORECAST Data (original from submission) */} {!shouldHideForecast && ( @@ -1504,6 +1604,12 @@ setAdditionalForecastMonths([ {getVarianceDisplay(product.forecast_quantity_period_two, product.forecast_quantity_period_three)} + )} @@ -1543,6 +1649,13 @@ setAdditionalForecastMonths([ )} + {!shouldHidePreviousQuarter && ( + + )} {/* Current Quarter – Month 1 */} + {/* Next Year Forecast – Month 1 */} {!shouldHideForecast && ( @@ -1615,6 +1734,14 @@ setAdditionalForecastMonths([ )} + {!shouldHideForecast && ( + + )} )} @@ -1662,6 +1789,11 @@ setAdditionalForecastMonths([ )} + )} @@ -1684,33 +1816,42 @@ setAdditionalForecastMonths([ {getVarianceDisplay(product.current_cost_period_two, product.current_cost_period_three)} + {/* HISTORICAL Cost (from API) */} - {showPreviousNext && (() => { - const historicalData = getCurrentYearForecastData(product?.product?.id); - return ( - <> - - - - - ); - })()} + {showPreviousNext && ( + <> + + + + + + )} {/* NEXT YEAR FORECAST Cost (original from submission) */} {!shouldHideForecast && ( @@ -1733,6 +1874,12 @@ setAdditionalForecastMonths([ {getVarianceDisplay(product.forecast_cost_period_two, product.forecast_cost_period_three)} + )} @@ -1772,6 +1919,13 @@ setAdditionalForecastMonths([ )} + {!shouldHidePreviousQuarter && ( + + )} {/* Current Cost – Month 1 */} + {/* Forecast Cost – Month 1 */} {!shouldHideForecast && ( @@ -1844,6 +2004,14 @@ setAdditionalForecastMonths([ )} + {!shouldHideForecast && ( + + )} )} @@ -1855,11 +2023,11 @@ setAdditionalForecastMonths([ {showPreviousNext ? ( <> {!shouldHidePreviousQuarter && ( - )} - {/* Previous Forecast (colSpan 3) */} - {!shouldHideForecast && ( - )} @@ -1879,11 +2047,11 @@ setAdditionalForecastMonths([ ) : ( <> {!shouldHidePreviousQuarter && ( - )} - {!shouldHideForecast && ( - )} @@ -1906,18 +2074,18 @@ setAdditionalForecastMonths([ {showPreviousNext ? ( <> {!shouldHidePreviousQuarter && ( - )} - - {!shouldHideForecast && ( - )} - {!shouldHideForecast && ( -
+ Metric + {previousLabel || 'Q1 2024'} (PREVIOUS QUARTER) + {currentLabel || 'Q2 2024'} (CURRENT QUARTER) + {additionalForecastLabel || ''} (PREVIOUS FORECAST) + {forecastLabel || 'Q3 2024'} (NEXT QUARTER FORECAST) + {previousLabel || 'Q1 2024'} (PREVIOUS QUARTER) + {currentLabel || 'Q2 2024'} (CURRENT QUARTER) + {forecastLabel || 'Q3 2024'} (NEXT QUARTER FORECAST) {previousMonths?.previous_period_three || 'Mar'} + {previousLabel || 'Q1 2024'} + {currentMonths?.current_period_three || 'Jun'} + {currentLabel || 'Q2 2024'} + @@ -1302,6 +1373,9 @@ setAdditionalForecastMonths([ {additionalForecastMonths?.[2] || 'Sep'} + {additionalForecastLabel || ''} + {forecastMonths?.forecast_period_three || 'Dec'} + {forecastLabel || 'Q3 2024'} + {previousMonths?.previous_period_three || 'Mar'} + {previousLabel || 'Q1 2024'} + {currentMonths?.current_period_three || 'Jun'} + {currentLabel || 'Q2 2024'} + {forecastMonths?.forecast_period_three || 'Sep'} + {forecastLabel || 'Q3 2024'} + +
+ {formatQuarterValue(previousQuantityTotal)} +
+
+
+ {formatQuarterValue(currentQuantityTotal)} + {!shouldHidePreviousQuarter && getVarianceDisplay(previousQuantityTotal, currentQuantityTotal)} +
+
-
- {historicalData.forecast_quantity_period_one || '0'} - {getVarianceDisplay(product.current_quantity_period_three, historicalData.forecast_quantity_period_one)} -
-
-
- {historicalData.forecast_quantity_period_two || '0'} - {getVarianceDisplay(historicalData.forecast_quantity_period_one, historicalData.forecast_quantity_period_two)} -
-
-
- {historicalData.forecast_quantity_period_three || '0'} - {getVarianceDisplay(historicalData.forecast_quantity_period_two, historicalData.forecast_quantity_period_three)} -
-
+
+ {historicalData.forecast_quantity_period_one || '0'} + {getVarianceDisplay(product.current_quantity_period_three, historicalData.forecast_quantity_period_one)} +
+
+
+ {historicalData.forecast_quantity_period_two || '0'} + {getVarianceDisplay(historicalData.forecast_quantity_period_one, historicalData.forecast_quantity_period_two)} +
+
+
+ {historicalData.forecast_quantity_period_three || '0'} + {getVarianceDisplay(historicalData.forecast_quantity_period_two, historicalData.forecast_quantity_period_three)} +
+
+
+ {formatQuarterValue(historicalQuantityTotal)} + {getVarianceDisplay(currentQuantityTotal, historicalQuantityTotal)} +
+
+
+ {formatQuarterValue(forecastQuantityTotal)} + {getVarianceDisplay(showPreviousNext ? historicalQuantityTotal : currentQuantityTotal, forecastQuantityTotal)} +
+
+
+ {formatQuarterValue(previousQuantityTotal)} +
+
@@ -1576,6 +1689,12 @@ setAdditionalForecastMonths([ )} +
+ {formatQuarterValue(currentQuantityTotal)} + {!shouldHidePreviousQuarter && getVarianceDisplay(previousQuantityTotal, currentQuantityTotal)} +
+
+
+ {formatQuarterValue(forecastQuantityTotal)} + {getVarianceDisplay(currentQuantityTotal, forecastQuantityTotal)} +
+
+
+ {formatQuarterValue(previousCostTotal)} +
+
+
+ {formatQuarterValue(currentCostTotal)} + {!shouldHidePreviousQuarter && getVarianceDisplay(previousCostTotal, currentCostTotal)} +
+
-
- {historicalData.forecast_cost_period_one || '0'} - {getVarianceDisplay(product.current_cost_period_three, historicalData.forecast_cost_period_one)} -
-
-
- {historicalData.forecast_cost_period_two || '0'} - {getVarianceDisplay(historicalData.forecast_cost_period_one, historicalData.forecast_cost_period_two)} -
-
-
- {historicalData.forecast_cost_period_three || '0'} - {getVarianceDisplay(historicalData.forecast_cost_period_two, historicalData.forecast_cost_period_three)} -
-
+
+ {historicalData.forecast_cost_period_one || '0'} + {getVarianceDisplay(product.current_cost_period_three, historicalData.forecast_cost_period_one)} +
+
+
+ {historicalData.forecast_cost_period_two || '0'} + {getVarianceDisplay(historicalData.forecast_cost_period_one, historicalData.forecast_cost_period_two)} +
+
+
+ {historicalData.forecast_cost_period_three || '0'} + {getVarianceDisplay(historicalData.forecast_cost_period_two, historicalData.forecast_cost_period_three)} +
+
+
+ {formatQuarterValue(historicalCostTotal)} + {getVarianceDisplay(currentCostTotal, historicalCostTotal)} +
+
+
+ {formatQuarterValue(forecastCostTotal)} + {getVarianceDisplay(showPreviousNext ? historicalCostTotal : currentCostTotal, forecastCostTotal)} +
+
+
+ {formatQuarterValue(previousCostTotal)} +
+
@@ -1805,6 +1959,12 @@ setAdditionalForecastMonths([ )} +
+ {formatQuarterValue(currentCostTotal)} + {!shouldHidePreviousQuarter && getVarianceDisplay(previousCostTotal, currentCostTotal)} +
+
+
+ {formatQuarterValue(forecastCostTotal)} + {getVarianceDisplay(currentCostTotal, forecastCostTotal)} +
+
+ + {product.other_variation_reason || (product?.variation_reason?.reason ? (product.variation_reason.reason.startsWith('Other (specify)') ? '' : product.variation_reason.reason) @@ -1867,11 +2035,11 @@ setAdditionalForecastMonths([ } + + + + {product.other_variation_reason || (product?.variation_reason?.reason ? (product.variation_reason.reason.startsWith('Other (specify)') ? '' : product.variation_reason.reason) @@ -1891,7 +2059,7 @@ setAdditionalForecastMonths([ } + + + + + {product.other_zero_target_reason || (product?.zero_target_reason?.reason ? (product.zero_target_reason.reason.startsWith('Other (specify)') ? '' : product.zero_target_reason.reason) @@ -1929,15 +2097,15 @@ setAdditionalForecastMonths([ ) : ( <> {!shouldHidePreviousQuarter && ( - + + + {product.other_zero_target_reason || (product?.zero_target_reason?.reason ? (product.zero_target_reason.reason.startsWith('Other (specify)') ? '' : product.zero_target_reason.reason)