fixed
This commit is contained in:
parent
d57d37c55a
commit
30360fe3f3
@ -755,12 +755,12 @@ const location = useLocation();
|
|||||||
|
|
||||||
const response = await getPreviousForecastData(
|
const response = await getPreviousForecastData(
|
||||||
establishmentId,
|
establishmentId,
|
||||||
formattedQuarter,
|
quarterPeriods?.previous_quarter || formattedQuarter,
|
||||||
year,
|
quarterPeriods?.previous_year || year,
|
||||||
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,6 +893,7 @@ 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,
|
||||||
@ -910,6 +911,7 @@ 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);
|
||||||
@ -1028,6 +1030,7 @@ const location = useLocation();
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log("handleProductSelect",handleProductSelect)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const forecastData = await fetchPreviousForecastData(productId, establishmentId);
|
const forecastData = await fetchPreviousForecastData(productId, establishmentId);
|
||||||
@ -1035,6 +1038,7 @@ 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;
|
||||||
@ -1042,17 +1046,18 @@ const location = useLocation();
|
|||||||
if (product.id === id) {
|
if (product.id === id) {
|
||||||
return {
|
return {
|
||||||
...product,
|
...product,
|
||||||
octQuantity: data.previous_quantity_period_one || '',
|
octQuantity: data.current_quantity_period_one || '',
|
||||||
novQuantity: data.previous_quantity_period_two || '',
|
novQuantity: data.current_quantity_period_two || '',
|
||||||
decQuantity: data.previous_quantity_period_three || '',
|
decQuantity: data.current_quantity_period_three || '',
|
||||||
octCost: data.previous_cost_period_one || '',
|
octCost: data.current_cost_period_one || '',
|
||||||
novCost: data.previous_cost_period_two || '',
|
novCost: data.current_cost_period_two || '',
|
||||||
decCost: data.previous_cost_period_three || '',
|
decCost: data.current_cost_period_three || '',
|
||||||
capacity: data.annual_installed_capacity || ''
|
capacity: data.annual_installed_capacity || ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
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:', {
|
||||||
@ -1275,8 +1280,18 @@ const location = useLocation();
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the selected product from options
|
// Find the selected product from options
|
||||||
const selectedProduct = productOptions.find(opt => opt.value === selectedValue || opt.productId?.toString() === selectedValue);
|
const selectedProduct = productOptions.find(opt => {
|
||||||
|
return opt.value === selectedValue ||
|
||||||
|
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
|
// 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 ||
|
||||||
@ -1352,19 +1367,20 @@ const location = useLocation();
|
|||||||
localStorage.getItem('establishment_id');
|
localStorage.getItem('establishment_id');
|
||||||
|
|
||||||
if (establishmentId && quarter && year) {
|
if (establishmentId && quarter && year) {
|
||||||
const selectedProductId = selectedProduct.originalData?.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.previous_quantity_period_one || '',
|
octQuantity: data.current_quantity_period_one || '',
|
||||||
novQuantity: data.previous_quantity_period_two || '',
|
novQuantity: data.current_quantity_period_two || '',
|
||||||
decQuantity: data.previous_quantity_period_three || '',
|
decQuantity: data.current_quantity_period_three || '',
|
||||||
octCost: data.previous_cost_period_one || '',
|
octCost: data.current_cost_period_one || '',
|
||||||
novCost: data.previous_cost_period_two || '',
|
novCost: data.current_cost_period_two || '',
|
||||||
decCost: data.previous_cost_period_three || '',
|
decCost: data.current_cost_period_three || '',
|
||||||
capacity: data.annual_installed_capacity || ''
|
capacity: data.annual_installed_capacity || ''
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user