This commit is contained in:
Malini 2025-12-23 08:43:56 +05:30
parent 30360fe3f3
commit 43967063a9
5 changed files with 33 additions and 22 deletions

View File

@ -760,7 +760,6 @@ const location = useLocation();
productId productId
); );
console.log("response",response)
if (!response) { if (!response) {
console.warn('Empty response from getPreviousForecastData'); console.warn('Empty response from getPreviousForecastData');
return null; return null;
@ -893,7 +892,6 @@ const location = useLocation();
// Handle product selection // Handle product selection
if (field === 'product') { if (field === 'product') {
const selectedProduct = options?.find(opt => opt.value === value); const selectedProduct = options?.find(opt => opt.value === value);
console.log(selectedProduct,"selectedProduct")
const updatedProduct = { const updatedProduct = {
...product, ...product,
product: selectedProduct?.value || value, product: selectedProduct?.value || value,
@ -911,7 +909,6 @@ const location = useLocation();
if (establishmentId && quarter && year) { if (establishmentId && quarter && year) {
// Use the product_id directly as the value // Use the product_id directly as the value
const productId = selectedProduct.value; const productId = selectedProduct.value;
console.log("productId",productId)
// Call handleProductSelect with the product ID // Call handleProductSelect with the product ID
handleProductSelect(productId, establishmentId, id); handleProductSelect(productId, establishmentId, id);
@ -1030,7 +1027,6 @@ const location = useLocation();
}); });
return; return;
} }
console.log("handleProductSelect",handleProductSelect)
try { try {
const forecastData = await fetchPreviousForecastData(productId, establishmentId); const forecastData = await fetchPreviousForecastData(productId, establishmentId);
@ -1038,7 +1034,6 @@ const location = useLocation();
console.warn('No forecast data received for product:', productId); console.warn('No forecast data received for product:', productId);
return; return;
} }
console.log("forecastData",forecastData)
// Check if the response has a data property (nested response) or is the data itself // Check if the response has a data property (nested response) or is the data itself
const data = forecastData.data || forecastData; const data = forecastData.data || forecastData;
@ -1057,7 +1052,6 @@ const location = useLocation();
} }
return product; return product;
}); });
console.log("updatedProducts",updatedProducts)
onProductsChange(updatedProducts); onProductsChange(updatedProducts);
} catch (error) { } catch (error) {
console.error('Error in handleProductSelect:', { console.error('Error in handleProductSelect:', {
@ -1285,13 +1279,11 @@ const location = useLocation();
opt.productId?.toString() === selectedValue || opt.productId?.toString() === selectedValue ||
opt.originalData?.product_id?.toString() === selectedValue; opt.originalData?.product_id?.toString() === selectedValue;
}); });
console.log("Selected Product:", selectedProduct);
// Get the correct product ID (prefer originalData.product_id, then productId, then value) // Get the correct product ID (prefer originalData.product_id, then productId, then value)
const productId = selectedProduct?.originalData?.product_id || const productId = selectedProduct?.originalData?.product_id ||
selectedProduct?.productId || selectedProduct?.productId ||
selectedProduct?.value; selectedProduct?.value;
console.log("productId",productId)
// Get unit information from the selected product // Get unit information from the selected product
const unitId = selectedProduct?.originalData?.['product.unit.id'] || const unitId = selectedProduct?.originalData?.['product.unit.id'] ||
selectedProduct?.unitId || selectedProduct?.unitId ||
@ -1368,20 +1360,19 @@ const location = useLocation();
if (establishmentId && quarter && year) { if (establishmentId && quarter && year) {
const selectedProductId = selectedProduct.originalData?.product_id || selectedProduct.value; const selectedProductId = selectedProduct.originalData?.product_id || selectedProduct.value;
console.log('Using product ID for API call:', selectedProductId);
const forecastData = await fetchPreviousForecastData(selectedProductId, establishmentId, p.id); const forecastData = await fetchPreviousForecastData(selectedProductId, establishmentId, p.id);
if (forecastData) { if (forecastData) {
const data = forecastData.data || forecastData; const data = forecastData.data || forecastData;
const updatedWithForecast = { const updatedWithForecast = {
...updatedProduct, ...updatedProduct,
octQuantity: data.current_quantity_period_one || '', octQuantity: data.current_quantity_period_one || '0',
novQuantity: data.current_quantity_period_two || '', novQuantity: data.current_quantity_period_two || '0',
decQuantity: data.current_quantity_period_three || '', decQuantity: data.current_quantity_period_three || '0',
octCost: data.current_cost_period_one || '', octCost: data.current_cost_period_one || '0',
novCost: data.current_cost_period_two || '', novCost: data.current_cost_period_two || '0',
decCost: data.current_cost_period_three || '', decCost: data.current_cost_period_three || '0',
capacity: data.annual_installed_capacity || '' capacity: data.annual_installed_capacity || '0'
}; };
const finalUpdatedProducts = updatedProducts.map((prod, i) => const finalUpdatedProducts = updatedProducts.map((prod, i) =>
@ -1389,6 +1380,23 @@ const location = useLocation();
); );
onProductsChange(finalUpdatedProducts); onProductsChange(finalUpdatedProducts);
} else {
// If forecastData is null/undefined, reset all values to '0'
const resetProduct = {
...updatedProduct,
octQuantity: '0',
novQuantity: '0',
decQuantity: '0',
octCost: '0',
novCost: '0',
decCost: '0',
capacity: '0'
};
const resetProducts = updatedProducts.map((prod, i) =>
i === idx ? resetProduct : prod
);
onProductsChange(resetProducts);
} }
} }
} catch (error) { } catch (error) {

View File

@ -218,7 +218,7 @@ const buildProductRows = (products = [], options = {}) => {
q2_jun_cost: formatNumber(product.junCost) || '—', q2_jun_cost: formatNumber(product.junCost) || '—',
// Previous Quarter (Q4) - October to December (if available) // Previous Quarter (Q4) - October to December (if available)
q4_oct_quantity: formatNumber(product.previousQuantity) || '—', q4_oct_quantity: formatNumber(product.octQuantity) || '—',
q4_nov_quantity: formatNumber(product.novQuantity) || '—', q4_nov_quantity: formatNumber(product.novQuantity) || '—',
q4_dec_quantity: formatNumber(product.decQuantity) || '—', q4_dec_quantity: formatNumber(product.decQuantity) || '—',
q4_oct_cost: formatNumber(product.octCost) || '—', q4_oct_cost: formatNumber(product.octCost) || '—',

View File

@ -610,7 +610,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,7 +618,6 @@ const ValidationReview = () => {
productId productId
); );
console.log("API Response:", response);
let mappedDataMap = {}; let mappedDataMap = {};
@ -919,7 +918,6 @@ 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 = {
@ -964,7 +962,6 @@ const additionalForecastLabel = showPreviousNext
: ""; : "";
console.log("label",additionalForecastLabel)
const establishmentDetails = [ const establishmentDetails = [
{ {

View File

@ -389,7 +389,6 @@ React.useEffect(() => {
const matches = matchSearch && matchYear && matchQuarter && matchEmirate && matchStatus; const matches = matchSearch && matchYear && matchQuarter && matchEmirate && matchStatus;
if (matches) { if (matches) {
// console.log('Matching item:', item);
} else { } else {
('Filtered out item:', item, { matchSearch, matchYear, matchQuarter, matchEmirate, matchStatus }); ('Filtered out item:', item, { matchSearch, matchYear, matchQuarter, matchEmirate, matchStatus });
} }

View File

@ -628,6 +628,13 @@ const Survey = () => {
// Add remarks to the product payload // Add remarks to the product payload
remarks: surveyRemarks, remarks: surveyRemarks,
// Previous Quarter - Map month fields to period fields
previous_quantity_period_one: stringify(product.octQuantity || '0'),
previous_quantity_period_two: stringify(product.novQuantity || '0'),
previous_quantity_period_three: stringify(product.decQuantity || '0'),
previous_cost_period_one: stringify(product.octCost || '0'),
previous_cost_period_two: stringify(product.novCost || '0'),
previous_cost_period_three: stringify(product.decCost || '0'),
// Current Quarter (Q1) - January, February, March // Current Quarter (Q1) - January, February, March
current_quantity_period_one: stringify(product.janQuantity || '0'), current_quantity_period_one: stringify(product.janQuantity || '0'),
current_quantity_period_two: stringify(product.febQuantity || '0'), current_quantity_period_two: stringify(product.febQuantity || '0'),