Closed Quarter restricted
This commit is contained in:
parent
34a9fbf4fc
commit
856f221399
@ -143,6 +143,16 @@ exports.getEstablishmentDashboard = async (req, res) => {
|
|||||||
if (activeQuarters?.length > 0) {
|
if (activeQuarters?.length > 0) {
|
||||||
|
|
||||||
for (const q of activeQuarters) {
|
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({
|
const submissionMatch = await Submission.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@ -811,7 +811,8 @@ exports.getQuarterPeriods = async (req, res) => {
|
|||||||
const config = await QuarterlyWindowsConfiguration.findOne({
|
const config = await QuarterlyWindowsConfiguration.findOne({
|
||||||
where: {
|
where: {
|
||||||
year: current_year,
|
year: current_year,
|
||||||
quarter: current_quarter
|
quarter: current_quarter,
|
||||||
|
is_active: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -822,32 +823,6 @@ exports.getQuarterPeriods = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
const quarter_periods = getQuarterPeriods(Number(current_year), current_quarter);
|
||||||
return res.status(200).json({ status: "success", data: quarter_periods });
|
return res.status(200).json({ status: "success", data: quarter_periods });
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user