diff --git a/ipi-survey-platform/src/components/survey/ProductData/ProductData.jsx b/ipi-survey-platform/src/components/survey/ProductData/ProductData.jsx index 6863901..ccdd608 100644 --- a/ipi-survey-platform/src/components/survey/ProductData/ProductData.jsx +++ b/ipi-survey-platform/src/components/survey/ProductData/ProductData.jsx @@ -760,7 +760,6 @@ const location = useLocation(); productId ); - console.log("response",response) if (!response) { console.warn('Empty response from getPreviousForecastData'); return null; @@ -893,7 +892,6 @@ const location = useLocation(); // Handle product selection if (field === 'product') { const selectedProduct = options?.find(opt => opt.value === value); - console.log(selectedProduct,"selectedProduct") const updatedProduct = { ...product, product: selectedProduct?.value || value, @@ -911,7 +909,6 @@ const location = useLocation(); if (establishmentId && quarter && year) { // Use the product_id directly as the value const productId = selectedProduct.value; - console.log("productId",productId) // Call handleProductSelect with the product ID handleProductSelect(productId, establishmentId, id); @@ -1030,7 +1027,6 @@ const location = useLocation(); }); return; } - console.log("handleProductSelect",handleProductSelect) try { const forecastData = await fetchPreviousForecastData(productId, establishmentId); @@ -1038,7 +1034,6 @@ const location = useLocation(); console.warn('No forecast data received for product:', productId); return; } - console.log("forecastData",forecastData) // Check if the response has a data property (nested response) or is the data itself const data = forecastData.data || forecastData; @@ -1057,7 +1052,6 @@ const location = useLocation(); } return product; }); - console.log("updatedProducts",updatedProducts) onProductsChange(updatedProducts); } catch (error) { console.error('Error in handleProductSelect:', { @@ -1285,13 +1279,11 @@ const location = useLocation(); opt.productId?.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) const productId = selectedProduct?.originalData?.product_id || selectedProduct?.productId || selectedProduct?.value; - console.log("productId",productId) // Get unit information from the selected product const unitId = selectedProduct?.originalData?.['product.unit.id'] || selectedProduct?.unitId || @@ -1368,20 +1360,19 @@ const location = useLocation(); if (establishmentId && quarter && year) { 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); if (forecastData) { const data = forecastData.data || forecastData; const updatedWithForecast = { ...updatedProduct, - octQuantity: data.current_quantity_period_one || '', - novQuantity: data.current_quantity_period_two || '', - decQuantity: data.current_quantity_period_three || '', - octCost: data.current_cost_period_one || '', - novCost: data.current_cost_period_two || '', - decCost: data.current_cost_period_three || '', - capacity: data.annual_installed_capacity || '' + octQuantity: data.current_quantity_period_one || '0', + novQuantity: data.current_quantity_period_two || '0', + decQuantity: data.current_quantity_period_three || '0', + octCost: data.current_cost_period_one || '0', + novCost: data.current_cost_period_two || '0', + decCost: data.current_cost_period_three || '0', + capacity: data.annual_installed_capacity || '0' }; const finalUpdatedProducts = updatedProducts.map((prod, i) => @@ -1389,6 +1380,23 @@ const location = useLocation(); ); 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) { diff --git a/ipi-survey-platform/src/components/survey/ReviewSubmit/ReviewSubmit.jsx b/ipi-survey-platform/src/components/survey/ReviewSubmit/ReviewSubmit.jsx index 251340a..db339ad 100644 --- a/ipi-survey-platform/src/components/survey/ReviewSubmit/ReviewSubmit.jsx +++ b/ipi-survey-platform/src/components/survey/ReviewSubmit/ReviewSubmit.jsx @@ -218,7 +218,7 @@ const buildProductRows = (products = [], options = {}) => { q2_jun_cost: formatNumber(product.junCost) || '—', // 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_dec_quantity: formatNumber(product.decQuantity) || '—', q4_oct_cost: formatNumber(product.octCost) || '—', diff --git a/ipi-survey-platform/src/pages/Admin/ValidationReview.jsx b/ipi-survey-platform/src/pages/Admin/ValidationReview.jsx index 4a81288..e8d2712 100644 --- a/ipi-survey-platform/src/pages/Admin/ValidationReview.jsx +++ b/ipi-survey-platform/src/pages/Admin/ValidationReview.jsx @@ -610,7 +610,7 @@ const ValidationReview = () => { return; } - // ✅ API Call + // API Call const response = await getBeforePreviousData( establishmentId, quarterPeriods?.current_quarter, @@ -618,7 +618,6 @@ const ValidationReview = () => { productId ); - console.log("API Response:", response); let mappedDataMap = {}; @@ -919,7 +918,6 @@ 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 = { @@ -964,7 +962,6 @@ const additionalForecastLabel = showPreviousNext : ""; -console.log("label",additionalForecastLabel) const establishmentDetails = [ { diff --git a/ipi-survey-platform/src/pages/Admin/Validations.jsx b/ipi-survey-platform/src/pages/Admin/Validations.jsx index 350fa86..d31cd3b 100644 --- a/ipi-survey-platform/src/pages/Admin/Validations.jsx +++ b/ipi-survey-platform/src/pages/Admin/Validations.jsx @@ -389,7 +389,6 @@ React.useEffect(() => { const matches = matchSearch && matchYear && matchQuarter && matchEmirate && matchStatus; if (matches) { - // console.log('Matching item:', item); } else { ('Filtered out item:', item, { matchSearch, matchYear, matchQuarter, matchEmirate, matchStatus }); } diff --git a/ipi-survey-platform/src/pages/Survey/Survey.jsx b/ipi-survey-platform/src/pages/Survey/Survey.jsx index 6b13344..372f972 100644 --- a/ipi-survey-platform/src/pages/Survey/Survey.jsx +++ b/ipi-survey-platform/src/pages/Survey/Survey.jsx @@ -628,6 +628,13 @@ const Survey = () => { // Add remarks to the product payload 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_quantity_period_one: stringify(product.janQuantity || '0'), current_quantity_period_two: stringify(product.febQuantity || '0'),