Closed Quarter restricted

This commit is contained in:
unknown 2025-12-29 11:56:39 +05:30
parent 34a9fbf4fc
commit 856f221399
2 changed files with 13 additions and 28 deletions

View File

@ -143,6 +143,16 @@ exports.getEstablishmentDashboard = async (req, res) => {
if (activeQuarters?.length > 0) {
for (const q of activeQuarters) {
const endDate = new Date(q.end_date);
const graceDays = Number(q.grace_periods_days || 0);
const finalDeadline = new Date(endDate);
finalDeadline.setDate(finalDeadline.getDate() + graceDays);
const now = new Date();
// Skip this quarter if it's closed (deadline has passed)
if (now > finalDeadline) {
continue;
}
const submissionMatch = await Submission.findOne({
where: {

View File

@ -811,7 +811,8 @@ exports.getQuarterPeriods = async (req, res) => {
const config = await QuarterlyWindowsConfiguration.findOne({
where: {
year: current_year,
quarter: current_quarter
quarter: current_quarter,
is_active: true
}
});
@ -820,33 +821,7 @@ exports.getQuarterPeriods = async (req, res) => {
status: "failed",
message: `No configuration found for Quarter ${current_quarter} ${current_year}`
});
}
if (config.is_active === 0) {
return res.status(403).json({
status: "failed",
message: `Quarter ${current_quarter} ${current_year} is not active`
});
}
const endDate = new Date(config.end_date);
const graceDays = Number(config.grace_periods_days || 0);
const finalDeadline = new Date(endDate);
finalDeadline.setDate(finalDeadline.getDate() + graceDays);
const now = new Date();
if (now > finalDeadline) {
return res.status(403).json({
status: "failed",
quarter_closed: true,
message: `Quarter ${current_quarter} ${current_year} is closed. The grace period ended on ${finalDeadline}. Cannot create surveys for this quarter.`,
deadline: finalDeadline.toISOString(),
current_time: now.toISOString()
});
}
}
const quarter_periods = getQuarterPeriods(Number(current_year), current_quarter);
return res.status(200).json({ status: "success", data: quarter_periods });