bug fixed

This commit is contained in:
Malini 2025-12-19 14:14:16 +05:30
parent 3bd9a55ea6
commit 0c49b1ed51
2 changed files with 68 additions and 38 deletions

View File

@ -6,6 +6,7 @@ import apiClient from '@/services/api/apiClient';
import { getBeforePreviousData, getQuarterPeriods } from '@/services/submissions/submissionService'; import { getBeforePreviousData, getQuarterPeriods } from '@/services/submissions/submissionService';
import { getProductSubmissionHistory } from '@/services/submissions/submissionService'; import { getProductSubmissionHistory } from '@/services/submissions/submissionService';
import { Line } from 'react-chartjs-2'; import { Line } from 'react-chartjs-2';
import { putRequest } from '@/services/api/CommonService';
// Helper function to get months for quarter // Helper function to get months for quarter
@ -590,7 +591,7 @@ const ValidationReview = () => {
const checked = e.target.checked; const checked = e.target.checked;
setShowPreviousNext(checked); setShowPreviousNext(checked);
// Uncheck reset // Uncheck reset
if (!checked) { if (!checked) {
setNextQuarterData({}); setNextQuarterData({});
setAdditionalForecastQuarter(""); setAdditionalForecastQuarter("");
@ -610,7 +611,7 @@ const ValidationReview = () => {
return; return;
} }
// API Call // API Call
const response = await getBeforePreviousData( const response = await getBeforePreviousData(
establishmentId, establishmentId,
quarterPeriods?.current_quarter, quarterPeriods?.current_quarter,
@ -618,6 +619,7 @@ const ValidationReview = () => {
productId productId
); );
console.log("API Response:", response);
let mappedDataMap = {}; let mappedDataMap = {};
@ -644,16 +646,24 @@ const ValidationReview = () => {
setNextQuarterData(mappedDataMap); setNextQuarterData(mappedDataMap);
// DIRECTLY FROM API NO CALCULATION // 🟢 DIRECTLY FROM API NO CALCULATION
const qp = response?.data?.quarter_periods; const qp = response?.data?.quarter_periods;
setAdditionalForecastQuarter(qp?.forecast_quarter); // Quarter & Year
setAdditionalForecastYear(qp?.forecast_year); if (!qp?.forecast_quarter && !qp?.forecast_year) {
setAdditionalForecastMonths([ setAdditionalForecastQuarter("No");
qp?.forecast_month?.forecast_period_one, setAdditionalForecastYear("");
qp?.forecast_month?.forecast_period_two, } else {
qp?.forecast_month?.forecast_period_three, setAdditionalForecastQuarter(qp?.forecast_quarter || "");
]); setAdditionalForecastYear(qp?.forecast_year || "");
}
// Months (always "-" fallback)
setAdditionalForecastMonths([
qp?.forecast_month?.forecast_period_one || "-",
qp?.forecast_month?.forecast_period_two || "-",
qp?.forecast_month?.forecast_period_three || "-",
]);
} catch (error) { } catch (error) {
console.error("Error fetching forecast data:", error); console.error("Error fetching forecast data:", error);
@ -817,27 +827,37 @@ const ValidationReview = () => {
); );
}; };
const getCellClass = (previousValue, currentValue, isFirstMonth = false) => { const getCellClass = (previousValue, currentValue, isFirstMonth = false) => {
if (isFirstMonth || !varianceHighlighting) return ''; if (isFirstMonth || !varianceHighlighting) return '';
const variance = calculateVariance(previousValue, currentValue); // 🔴 Above 100 selected disable ALL highlighting
const absVariance = Math.abs(variance); if (threshold > 100) return '';
if (absVariance > threshold) return ''; const variance = calculateVariance(previousValue, currentValue);
const absVariance = Math.abs(variance);
return variance > 0 ? 'bg-[#F0FDF4]' : 'bg-[#FEF2F2]'; if (absVariance > threshold) return '';
};
const getBorderClass = (previousValue, currentValue, isFirstMonth = false) => { return variance > 0 ? 'bg-[#F0FDF4]' : 'bg-[#FEF2F2]';
if (isFirstMonth || !varianceHighlighting) return ''; };
const variance = calculateVariance(previousValue, currentValue);
const absVariance = Math.abs(variance);
if (absVariance > threshold) return ''; const getBorderClass = (previousValue, currentValue, isFirstMonth = false) => {
if (isFirstMonth || !varianceHighlighting) return '';
// 🔴 Above 100 selected no border highlight
if (threshold > 100) return '';
const variance = calculateVariance(previousValue, currentValue);
const absVariance = Math.abs(variance);
if (absVariance > threshold) return '';
return variance > 0
? 'border-2 border-[#1E7C34]'
: 'border-2 border-[#B52520]';
};
return variance > 0 ? 'border-2 border-[#1E7C34]' : 'border-2 border-[#B52520]';
};
const getQuarterYearLabel = (quarter, year) => { const getQuarterYearLabel = (quarter, year) => {
return `${quarter} ${year}`; return `${quarter} ${year}`;
@ -895,6 +915,7 @@ const getQuarterYearLabel = (quarter, year) => {
const currentYear = quarterPeriods?.current_year || 2025; const currentYear = quarterPeriods?.current_year || 2025;
const forecastQuarter = quarterPeriods?.forecast_quarter || '-'; const forecastQuarter = quarterPeriods?.forecast_quarter || '-';
const forecastYear = quarterPeriods?.forecast_year || 2026; const forecastYear = quarterPeriods?.forecast_year || 2026;
console.log("year",forecastQuarter);
// Get dynamic month information from API response // Get dynamic month information from API response
const previousMonths = { const previousMonths = {
@ -930,10 +951,16 @@ const forecastLabel = getQuarterYearLabel(forecastQuarter, forecastYear );
// const forecastLabel = yearLabels?.forecast || `${forecastQuarter} ${forecastYear}`; // const forecastLabel = yearLabels?.forecast || `${forecastQuarter} ${forecastYear}`;
// Calculate additional forecast label dynamically // Calculate additional forecast label dynamically
const additionalForecastLabel = const additionalForecastLabel = showPreviousNext
showPreviousNext && additionalForecastQuarter && additionalForecastYear ? additionalForecastQuarter === "No"
? `${additionalForecastQuarter} ${additionalForecastYear}` ? "No"
: ''; : [additionalForecastQuarter, additionalForecastYear]
.filter(Boolean)
.join(" ")
: "";
console.log("label",additionalForecastLabel)
const establishmentDetails = [ const establishmentDetails = [
{ {
@ -1147,14 +1174,16 @@ const additionalForecastLabel =
</label> </label>
</div> </div>
</div> </div>
{varianceHighlighting && ( {varianceHighlighting && (
<div className="text-xs text-[#6B7280]"> <div className="text-xs text-[#6B7280]">
Cells with variance{" "} {threshold > 100
{threshold <= 100 ? `${threshold}%` : "> 100%"} will be highlighted ? "Cells with variance > 100% are not highlighted"
: `Cells with variance ≤ ${threshold}% will be highlighted`}
</div> </div>
)} )}
</div> </div>
<table className="min-w-full text-sm text-left border-collapse"> <table className="min-w-full text-sm text-left border-collapse">
<thead> <thead>

View File

@ -9,6 +9,7 @@ import Footer from '@/components/common/Footer';
const searchIconSrc = '/assets/images/material-symbols_search-rounded.svg'; const searchIconSrc = '/assets/images/material-symbols_search-rounded.svg';
const caretUpSrc = '/assets/images/caret-up.svg'; const caretUpSrc = '/assets/images/caret-up.svg';
import apiClient from '@/services/api/apiClient'; import apiClient from '@/services/api/apiClient';
import { putRequest } from '@/services/api/CommonService';
const STATUS_VARIANTS = { const STATUS_VARIANTS = {
Approved: { background: '#F3FAF4', text: '#2F663C', border: '#F3FAF4' }, Approved: { background: '#F3FAF4', text: '#2F663C', border: '#F3FAF4' },