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 (
| + | Metric | @@ -1227,18 +1292,18 @@ setAdditionalForecastMonths([ <> {/* 12 columns when showPreviousNext is true */} {!shouldHidePreviousQuarter && ( -+ | {previousLabel || 'Q1 2024'} (PREVIOUS QUARTER) | )} -+ | {currentLabel || 'Q2 2024'} (CURRENT QUARTER) | -+ | {additionalForecastLabel || ''} (PREVIOUS FORECAST) | {!shouldHideForecast && ( -+ | {forecastLabel || 'Q3 2024'} (NEXT QUARTER FORECAST) | )} @@ -1247,15 +1312,15 @@ setAdditionalForecastMonths([ <> {/* 9 columns when showPreviousNext is false */} {!shouldHidePreviousQuarter && ( -+ | {previousLabel || 'Q1 2024'} (PREVIOUS QUARTER) | )} -+ | {currentLabel || 'Q2 2024'} (CURRENT QUARTER) | {!shouldHideForecast && ( -+ | {forecastLabel || 'Q3 2024'} (NEXT QUARTER FORECAST) | )} @@ -1278,6 +1343,9 @@ setAdditionalForecastMonths([{previousMonths?.previous_period_three || 'Mar'} | ++ {previousLabel || 'Q1 2024'} + | > )} @@ -1291,6 +1359,9 @@ setAdditionalForecastMonths([{currentMonths?.current_period_three || 'Jun'} | ++ {currentLabel || 'Q2 2024'} + | {/* Previous Forecast Months */}@@ -1302,6 +1373,9 @@ setAdditionalForecastMonths([ | {additionalForecastMonths?.[2] || 'Sep'} | ++ {additionalForecastLabel || ''} + | {/* Next Year Forecast Months */} {!shouldHideForecast && ( @@ -1315,6 +1389,9 @@ setAdditionalForecastMonths([{forecastMonths?.forecast_period_three || 'Dec'} | ++ {forecastLabel || 'Q3 2024'} + | > )} > @@ -1332,6 +1409,9 @@ setAdditionalForecastMonths([{previousMonths?.previous_period_three || 'Mar'} | ++ {previousLabel || 'Q1 2024'} + | > )} @@ -1345,6 +1425,9 @@ setAdditionalForecastMonths([{currentMonths?.current_period_three || 'Jun'} | ++ {currentLabel || 'Q2 2024'} + | {/* Next Year Forecast Months */} {!shouldHideForecast && ( @@ -1358,6 +1441,9 @@ setAdditionalForecastMonths([{forecastMonths?.forecast_period_three || 'Sep'} | ++ {forecastLabel || 'Q3 2024'} + | > )} > @@ -1411,6 +1497,11 @@ setAdditionalForecastMonths([ )} +
+
+ {formatQuarterValue(previousQuantityTotal)}
+
+ |
>
)}
@@ -1455,33 +1546,42 @@ setAdditionalForecastMonths([
)}
+
+
+ {formatQuarterValue(currentQuantityTotal)}
+ {!shouldHidePreviousQuarter && getVarianceDisplay(previousQuantityTotal, currentQuantityTotal)}
+
+ |
{/* HISTORICAL Data (from API) */}
- {showPreviousNext && (() => {
- const historicalData = getCurrentYearForecastData(product?.product?.id);
- return (
- <>
-
-
- {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)}
-
- |
- >
- );
- })()}
+ {showPreviousNext && (
+ <>
+
+
+ {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)}
+
+ |
+ >
+ )}
{/* NEXT YEAR FORECAST Data (original from submission) */}
{!shouldHideForecast && (
@@ -1504,6 +1604,12 @@ setAdditionalForecastMonths([
{getVarianceDisplay(product.forecast_quantity_period_two, product.forecast_quantity_period_three)}
+
+
+ {formatQuarterValue(forecastQuantityTotal)}
+ {getVarianceDisplay(showPreviousNext ? historicalQuantityTotal : currentQuantityTotal, forecastQuantityTotal)}
+
+ |
>
)}
>
@@ -1543,6 +1649,13 @@ setAdditionalForecastMonths([
)}
+ {!shouldHidePreviousQuarter && (
+
+
+ {formatQuarterValue(previousQuantityTotal)}
+
+ |
+ )}
{/* Current Quarter – Month 1 */}
@@ -1576,6 +1689,12 @@ setAdditionalForecastMonths([ )} | +
+
+ {formatQuarterValue(currentQuantityTotal)}
+ {!shouldHidePreviousQuarter && getVarianceDisplay(previousQuantityTotal, currentQuantityTotal)}
+
+ |
{/* Next Year Forecast – Month 1 */}
{!shouldHideForecast && (
@@ -1615,6 +1734,14 @@ setAdditionalForecastMonths([
)}
+ {!shouldHideForecast && (
+
+
+ {formatQuarterValue(forecastQuantityTotal)}
+ {getVarianceDisplay(currentQuantityTotal, forecastQuantityTotal)}
+
+ |
+ )}
>
)}
+
+ {formatQuarterValue(previousCostTotal)}
+
+ |
>
)}
@@ -1684,33 +1816,42 @@ setAdditionalForecastMonths([
{getVarianceDisplay(product.current_cost_period_two, product.current_cost_period_three)}
+
+
+ {formatQuarterValue(currentCostTotal)}
+ {!shouldHidePreviousQuarter && getVarianceDisplay(previousCostTotal, currentCostTotal)}
+
+ |
{/* HISTORICAL Cost (from API) */}
- {showPreviousNext && (() => {
- const historicalData = getCurrentYearForecastData(product?.product?.id);
- return (
- <>
-
-
- {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)}
-
- |
- >
- );
- })()}
+ {showPreviousNext && (
+ <>
+
+
+ {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)}
+
+ |
+ >
+ )}
{/* NEXT YEAR FORECAST Cost (original from submission) */}
{!shouldHideForecast && (
@@ -1733,6 +1874,12 @@ setAdditionalForecastMonths([
{getVarianceDisplay(product.forecast_cost_period_two, product.forecast_cost_period_three)}
+
+
+ {formatQuarterValue(forecastCostTotal)}
+ {getVarianceDisplay(showPreviousNext ? historicalCostTotal : currentCostTotal, forecastCostTotal)}
+
+ |
>
)}
>
@@ -1772,6 +1919,13 @@ setAdditionalForecastMonths([
)}
+ {!shouldHidePreviousQuarter && (
+
+
+ {formatQuarterValue(previousCostTotal)}
+
+ |
+ )}
{/* Current Cost – Month 1 */}
@@ -1805,6 +1959,12 @@ setAdditionalForecastMonths([ )} | +
+
+ {formatQuarterValue(currentCostTotal)}
+ {!shouldHidePreviousQuarter && getVarianceDisplay(previousCostTotal, currentCostTotal)}
+
+ |
{/* Forecast Cost – Month 1 */}
{!shouldHideForecast && (
@@ -1844,6 +2004,14 @@ setAdditionalForecastMonths([
)}
+ {!shouldHideForecast && (
+
+
+ {formatQuarterValue(forecastCostTotal)}
+ {getVarianceDisplay(currentCostTotal, forecastCostTotal)}
+
+ |
+ )}
>
)}
@@ -1855,11 +2023,11 @@ setAdditionalForecastMonths([
{showPreviousNext ? (
<>
{!shouldHidePreviousQuarter && (
- + | – | )} -+ | {product.other_variation_reason || (product?.variation_reason?.reason ? (product.variation_reason.reason.startsWith('Other (specify)') ? '' : product.variation_reason.reason) @@ -1867,11 +2035,11 @@ setAdditionalForecastMonths([ } | {/* Previous Forecast (colSpan 3) */} -+ | – | {!shouldHideForecast && ( -+ | – | )} @@ -1879,11 +2047,11 @@ setAdditionalForecastMonths([ ) : ( <> {!shouldHidePreviousQuarter && ( -+ | – | )} -+ | {product.other_variation_reason || (product?.variation_reason?.reason ? (product.variation_reason.reason.startsWith('Other (specify)') ? '' : product.variation_reason.reason) @@ -1891,7 +2059,7 @@ setAdditionalForecastMonths([ } | {!shouldHideForecast && ( -+ | – | )} @@ -1906,18 +2074,18 @@ setAdditionalForecastMonths([ {showPreviousNext ? ( <> {!shouldHidePreviousQuarter && ( -+ | – | )} -+ | – | -+ | – | {!shouldHideForecast && ( -+ | {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 && ( - | + | – | )} -+ | – | {!shouldHideForecast && ( -+ | {product.other_zero_target_reason || (product?.zero_target_reason?.reason ? (product.zero_target_reason.reason.startsWith('Other (specify)') ? '' : product.zero_target_reason.reason) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|