bug fixed
This commit is contained in:
parent
3bd9a55ea6
commit
0c49b1ed51
@ -6,6 +6,7 @@ import apiClient from '@/services/api/apiClient';
|
||||
import { getBeforePreviousData, getQuarterPeriods } from '@/services/submissions/submissionService';
|
||||
import { getProductSubmissionHistory } from '@/services/submissions/submissionService';
|
||||
import { Line } from 'react-chartjs-2';
|
||||
import { putRequest } from '@/services/api/CommonService';
|
||||
|
||||
|
||||
// Helper function to get months for quarter
|
||||
@ -590,7 +591,7 @@ const ValidationReview = () => {
|
||||
const checked = e.target.checked;
|
||||
setShowPreviousNext(checked);
|
||||
|
||||
// Uncheck → reset
|
||||
// ❌ Uncheck → reset
|
||||
if (!checked) {
|
||||
setNextQuarterData({});
|
||||
setAdditionalForecastQuarter("");
|
||||
@ -610,7 +611,7 @@ const ValidationReview = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// API Call
|
||||
// ✅ API Call
|
||||
const response = await getBeforePreviousData(
|
||||
establishmentId,
|
||||
quarterPeriods?.current_quarter,
|
||||
@ -618,6 +619,7 @@ const ValidationReview = () => {
|
||||
productId
|
||||
);
|
||||
|
||||
console.log("API Response:", response);
|
||||
|
||||
let mappedDataMap = {};
|
||||
|
||||
@ -644,16 +646,24 @@ const ValidationReview = () => {
|
||||
|
||||
setNextQuarterData(mappedDataMap);
|
||||
|
||||
// DIRECTLY FROM API – NO CALCULATION
|
||||
const qp = response?.data?.quarter_periods;
|
||||
// 🟢 DIRECTLY FROM API – NO CALCULATION
|
||||
const qp = response?.data?.quarter_periods;
|
||||
|
||||
setAdditionalForecastQuarter(qp?.forecast_quarter);
|
||||
setAdditionalForecastYear(qp?.forecast_year);
|
||||
setAdditionalForecastMonths([
|
||||
qp?.forecast_month?.forecast_period_one,
|
||||
qp?.forecast_month?.forecast_period_two,
|
||||
qp?.forecast_month?.forecast_period_three,
|
||||
]);
|
||||
// Quarter & Year
|
||||
if (!qp?.forecast_quarter && !qp?.forecast_year) {
|
||||
setAdditionalForecastQuarter("No");
|
||||
setAdditionalForecastYear("");
|
||||
} else {
|
||||
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) {
|
||||
console.error("Error fetching forecast data:", error);
|
||||
@ -817,27 +827,37 @@ const ValidationReview = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const getCellClass = (previousValue, currentValue, isFirstMonth = false) => {
|
||||
if (isFirstMonth || !varianceHighlighting) return '';
|
||||
|
||||
const variance = calculateVariance(previousValue, currentValue);
|
||||
const absVariance = Math.abs(variance);
|
||||
|
||||
if (absVariance > threshold) return '';
|
||||
|
||||
return variance > 0 ? 'bg-[#F0FDF4]' : 'bg-[#FEF2F2]';
|
||||
};
|
||||
const getCellClass = (previousValue, currentValue, isFirstMonth = false) => {
|
||||
if (isFirstMonth || !varianceHighlighting) return '';
|
||||
|
||||
// 🔴 Above 100 selected → disable ALL highlighting
|
||||
if (threshold > 100) return '';
|
||||
|
||||
const variance = calculateVariance(previousValue, currentValue);
|
||||
const absVariance = Math.abs(variance);
|
||||
|
||||
if (absVariance > threshold) return '';
|
||||
|
||||
return variance > 0 ? 'bg-[#F0FDF4]' : 'bg-[#FEF2F2]';
|
||||
};
|
||||
|
||||
|
||||
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]';
|
||||
};
|
||||
|
||||
const getBorderClass = (previousValue, currentValue, isFirstMonth = false) => {
|
||||
if (isFirstMonth || !varianceHighlighting) 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]';
|
||||
};
|
||||
|
||||
const getQuarterYearLabel = (quarter, year) => {
|
||||
return `${quarter} ${year}`;
|
||||
@ -895,6 +915,7 @@ const getQuarterYearLabel = (quarter, year) => {
|
||||
const currentYear = quarterPeriods?.current_year || 2025;
|
||||
const forecastQuarter = quarterPeriods?.forecast_quarter || '-';
|
||||
const forecastYear = quarterPeriods?.forecast_year || 2026;
|
||||
console.log("year",forecastQuarter);
|
||||
|
||||
// Get dynamic month information from API response
|
||||
const previousMonths = {
|
||||
@ -930,10 +951,16 @@ const forecastLabel = getQuarterYearLabel(forecastQuarter, forecastYear );
|
||||
// const forecastLabel = yearLabels?.forecast || `${forecastQuarter} ${forecastYear}`;
|
||||
|
||||
// Calculate additional forecast label dynamically
|
||||
const additionalForecastLabel =
|
||||
showPreviousNext && additionalForecastQuarter && additionalForecastYear
|
||||
? `${additionalForecastQuarter} ${additionalForecastYear}`
|
||||
: '';
|
||||
const additionalForecastLabel = showPreviousNext
|
||||
? additionalForecastQuarter === "No"
|
||||
? "No"
|
||||
: [additionalForecastQuarter, additionalForecastYear]
|
||||
.filter(Boolean)
|
||||
.join(" ")
|
||||
: "";
|
||||
|
||||
|
||||
console.log("label",additionalForecastLabel)
|
||||
|
||||
const establishmentDetails = [
|
||||
{
|
||||
@ -1147,14 +1174,16 @@ const additionalForecastLabel =
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{varianceHighlighting && (
|
||||
{varianceHighlighting && (
|
||||
<div className="text-xs text-[#6B7280]">
|
||||
Cells with variance{" "}
|
||||
{threshold <= 100 ? `≤ ${threshold}%` : "> 100%"} will be highlighted
|
||||
{threshold > 100
|
||||
? "Cells with variance > 100% are not highlighted"
|
||||
: `Cells with variance ≤ ${threshold}% will be highlighted`}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<table className="min-w-full text-sm text-left border-collapse">
|
||||
<thead>
|
||||
|
||||
@ -9,6 +9,7 @@ import Footer from '@/components/common/Footer';
|
||||
const searchIconSrc = '/assets/images/material-symbols_search-rounded.svg';
|
||||
const caretUpSrc = '/assets/images/caret-up.svg';
|
||||
import apiClient from '@/services/api/apiClient';
|
||||
import { putRequest } from '@/services/api/CommonService';
|
||||
|
||||
const STATUS_VARIANTS = {
|
||||
Approved: { background: '#F3FAF4', text: '#2F663C', border: '#F3FAF4' },
|
||||
|
||||
Loading…
Reference in New Issue
Block a user