GWM : cost sum added and filter added in view submission

This commit is contained in:
Gowtham M 2025-10-31 16:10:34 +05:30
parent 0e1fc24d59
commit 0bde898342
3 changed files with 64 additions and 25 deletions

View File

@ -152,14 +152,11 @@ exports.getEstablishmentDashboard = async (req, res) => {
}
};
exports.adminDashboard = async (req, res) => {
try {
const { quarter, year } = req.query; // e.g., Q1, 2025
// --- 1Summary Counts ---
// --- Summary Counts ---
const [
totalEstablishments,
submittedCount,
@ -184,7 +181,7 @@ exports.adminDashboard = async (req, res) => {
where: { id: { [Op.notIn]: startedIds } },
});
// --- 2 Recent 10 submissions for given quarter & year ---
// --- Recent 10 submissions for given quarter & year ---
const whereCond = {};
if (quarter) whereCond.quarter = quarter;
if (year) whereCond.year = year;
@ -222,7 +219,7 @@ exports.adminDashboard = async (req, res) => {
limit: 10,
});
// --- 3 Send Response ---
// --- Send Response ---
return res.status(200).json({
status: "success",
summary: {

View File

@ -92,8 +92,6 @@ exports.createSubmission = async (req, res) => {
res.status(500).json({ status: "failed", message: err.message });
}
};
exports.updateSubmission = async (req, res) => {
try {
@ -188,16 +186,28 @@ exports.updateSubmission = async (req, res) => {
}
};
exports.submissionHistory = async (req, res) => {
try {
const { establishment_id } = req.params;
const data = await Submission.findAll({
attributes: {
include: [
[
Sequelize.literal(`(SELECT COUNT(*) FROM submission_products AS sp1 WHERE sp1.submission_id = submission.id)`),
"product_count"
],
[
Sequelize.literal(`(SELECT SUM(sp2.current_cost) FROM submission_products AS sp2 WHERE sp2.submission_id = submission.id)`),
"total_cost"
]
]
},
where: { establishment_id },
order: [["id", "DESC"]],
});
res.status(200).json({ status: "success", data });
@ -206,7 +216,6 @@ exports.submissionHistory = async (req, res) => {
}
};
// exports.submissionList = async (req, res) => {
// try {
@ -244,7 +253,6 @@ exports.submissionHistory = async (req, res) => {
// }
// };
exports.submissionList = async (req, res) => {
try {
const {
@ -352,8 +360,26 @@ exports.viewSubmissionDetails = async (req, res) => {
try {
const { id } = req.params;
const { establishment_id, year, quarter } = req.query; // optional search params
const data = await Submission.findByPk(id, {
let whereCondition = {};
// Primary search by ID (default)
if (id) {
whereCondition.id = id;
}
// Secondary combination search if establishment_id, year, quarter given
if (establishment_id && year && quarter) {
whereCondition = {
establishment_id,
year,
quarter,
};
}
const data = await Submission.findOne( {
where: whereCondition,
include: [
{
model: Establishment,
@ -388,11 +414,10 @@ exports.viewSubmissionDetails = async (req, res) => {
],
});
const quarter_periods = getQuarterPeriods(Number(data.year), data.quarter);
if (!data) return res.status(404).json({ status: "failed", message: "Not found" });
const quarter_periods = getQuarterPeriods(Number(data.year), data.quarter);
res.status(200).json({ status: "success", data , quarter_periods });
} catch (err) {
@ -400,8 +425,6 @@ exports.viewSubmissionDetails = async (req, res) => {
}
};
exports.submissionEditRequest = async (req, res) => {
try {
@ -454,7 +477,6 @@ exports.enableOrDisableSubmissionEditAccess = async (req, res) => {
}
};
exports.approveOrRejectSubmission = async (req, res) => {
try {
@ -487,8 +509,6 @@ exports.approveOrRejectSubmission = async (req, res) => {
}
};
exports.getQuarterPeriods = async (req, res) => {
try {
const { current_year, current_quarter } = req.body;

View File

@ -1811,9 +1811,9 @@ router.get("/submissions",[verifySignature, verifyToken], submissionController.s
/**
* @swagger
* /api/submissions/{id}:
* /api/submissions/view/{id}:
* get:
* summary: Get submission with product details
* summary: Get submission details by ID or by (establishment_id, year, quarter)
* tags: [Submissions]
* security:
* - appSignature: []
@ -1821,12 +1821,34 @@ router.get("/submissions",[verifySignature, verifyToken], submissionController.s
* parameters:
* - name: id
* in: path
* required: true
* required: false
* description: Submission ID (optional if using query combination)
* schema:
* type: integer
* - name: establishment_id
* in: query
* required: false
* schema:
* type: integer
* - name: year
* in: query
* required: false
* schema:
* type: integer
* - name: quarter
* in: query
* required: false
* schema:
* type: string
* responses:
* 200:
* description: Submission details
* description: Submission details retrieved successfully
* 404:
* description: Submission not found
* 500:
* description: Server error
*/
router.get("/submissions/:id",[verifySignature, verifyToken], submissionController.viewSubmissionDetails);
router.get("/submissions/view/:id",[verifySignature, verifyToken], submissionController.viewSubmissionDetails);