Update Value Report.

This commit is contained in:
Athif
2025-12-18 13:37:47 +07:00
parent c112ff165a
commit 1496b80fdf
3 changed files with 52 additions and 55 deletions

View File

@@ -64,41 +64,41 @@ class HistoryValue {
}
static async getHistoryValueReportPivot(param) {
try {
if (!param.plant_sub_section_id) {
throw new ErrorHandler(400, 'plant_sub_section_id is required');
try {
if (!param.plant_sub_section_id) {
throw new ErrorHandler(400, 'plant_sub_section_id is required');
}
if (!param.from || !param.to) {
throw new ErrorHandler(400, 'from and to date parameters are required');
}
const plantSubSection = await getSubSectionByIdDb(param.plant_sub_section_id);
if (!plantSubSection || plantSubSection.length < 1) {
throw new ErrorHandler(404, 'Plant sub section not found');
}
const tableNameValue = plantSubSection[0]?.table_name_value;
if (!tableNameValue) {
throw new ErrorHandler(404, 'Table name not configured for this sub section');
}
const tableExist = await checkTableNamedDb(tableNameValue);
if (!tableExist || tableExist.length < 1) {
throw new ErrorHandler(404, `Value table '${tableNameValue}' not found`);
}
const results = await getHistoryValueReportPivotDb(tableExist[0].TABLE_NAME, param);
return results;
} catch (error) {
throw new ErrorHandler(
error.statusCode || 500,
error.message || 'Error fetching history value report pivot'
);
}
if (!param.from || !param.to) {
throw new ErrorHandler(400, 'from and to date parameters are required');
}
const plantSubSection = await getSubSectionByIdDb(param.plant_sub_section_id);
if (!plantSubSection || plantSubSection.length < 1) {
throw new ErrorHandler(404, 'Plant sub section not found');
}
const tableNameValue = plantSubSection[0]?.table_name_value;
if (!tableNameValue) {
throw new ErrorHandler(404, 'Table name not configured for this sub section');
}
const tableExist = await checkTableNamedDb(tableNameValue);
if (!tableExist || tableExist.length < 1) {
throw new ErrorHandler(404, `Value table '${tableNameValue}' not found`);
}
const results = await getHistoryValueReportPivotDb(tableExist[0].TABLE_NAME, param);
return results;
} catch (error) {
throw new ErrorHandler(
error.statusCode || 500,
error.message || 'Error fetching history value report pivot'
);
}
}
static async getHistoryValueTrendingPivot(param) {
try {