added service file
This commit is contained in:
parent
fad60efb61
commit
db816b4879
@ -84,69 +84,70 @@ export const getQuarterPeriods = async (currentYear, currentQuarter) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getPreviousForecastData = async (establishmentId, quarter, year, productId) => {
|
||||
export const getPreviousForecastData = async (
|
||||
establishmentId,
|
||||
quarter,
|
||||
year,
|
||||
productId
|
||||
) => {
|
||||
try {
|
||||
const response = await getRequest(
|
||||
'/submissions/getPreviousForecastData',
|
||||
"/submissions/getPreviousForecastData",
|
||||
{
|
||||
params: {
|
||||
establishment_id: establishmentId,
|
||||
quarter: quarter,
|
||||
year: year,
|
||||
product_id: productId
|
||||
}
|
||||
quarter,
|
||||
year,
|
||||
product_id: productId,
|
||||
},
|
||||
}
|
||||
);
|
||||
// Check if response has data property and return it, otherwise return the response as is
|
||||
return response.data || response;
|
||||
|
||||
// Always return only backend data
|
||||
return response?.data || null;
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching previous forecast data:', error);
|
||||
// Instead of throwing, return null to handle the error gracefully
|
||||
console.error("Error fetching previous forecast data:", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const getBeforePreviousData = async (
|
||||
establishmentId,
|
||||
currentQuarter,
|
||||
currentYear,
|
||||
quarter,
|
||||
year,
|
||||
productId
|
||||
) => {
|
||||
try {
|
||||
if (!establishmentId || !currentQuarter || !currentYear || !productId) {
|
||||
if (!establishmentId || !quarter || !year || !productId) {
|
||||
throw new Error("Missing required parameters");
|
||||
}
|
||||
|
||||
const q = Number(currentQuarter.replace("Q", ""));
|
||||
let beforePrevQuarter = `Q${q - 2}`;
|
||||
let beforePrevYear = currentYear;
|
||||
|
||||
if (q - 2 <= 0) {
|
||||
beforePrevQuarter = `Q${4 + (q - 2)}`;
|
||||
beforePrevYear = currentYear - 1;
|
||||
}
|
||||
|
||||
const response = await getRequest(
|
||||
"/submissions/getBeforePreviousData",
|
||||
{
|
||||
params: {
|
||||
establishment_id: establishmentId,
|
||||
current_quarter: beforePrevQuarter,
|
||||
current_year: beforePrevYear,
|
||||
product_id: productId
|
||||
}
|
||||
current_quarter: quarter,
|
||||
current_year: year,
|
||||
product_id: productId,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return response?.data ?? response;
|
||||
return response?.data ?? null;
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error fetching before-previous data:", error);
|
||||
console.error("Error fetching data:", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const getSubmissionHistoryByEstablishment = async (establishmentId, config = {}) => {
|
||||
try {
|
||||
if (!establishmentId) {
|
||||
@ -236,4 +237,5 @@ export default {
|
||||
getProductSubmissionHistory,
|
||||
getBeforePreviousData
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user