Skip to content

Commit

Permalink
Merge pull request #94 from shikshalokam/master
Browse files Browse the repository at this point in the history
overdue_issue and taskReport fix
  • Loading branch information
aks30 authored Jun 1, 2022
2 parents 6f70551 + 43f69a8 commit 0dd56af
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 55 deletions.
105 changes: 62 additions & 43 deletions module/reports/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ module.exports = class ReportsHelper {
static entity(entityId = "", userId, userToken, userName, reportType, programId = "", getPdf,appVersion) {
return new Promise(async (resolve, reject) => {
try {

let query = { };
if (entityId) {
query["entityId"] = ObjectId(entityId);
Expand All @@ -64,10 +63,10 @@ module.exports = class ReportsHelper {
{ "syncedAt": { $gte: new Date(startFrom), $lte: new Date(endOf) } },
{ "tasks": { $elemMatch: { isDeleted: { $ne: true },syncedAt: { $gte: new Date(startFrom), $lte: new Date(endOf) } } } },
]

const projectDetails = await projectQueries.projectDocument(
query,
["programId","programInformation.name", "entityInformation.name", "taskReport", "status", "tasks", "categories"],
["programId","programInformation.name", "entityInformation.name", "taskReport", "status", "tasks", "categories", "endDate"],
[]
);

Expand Down Expand Up @@ -101,9 +100,7 @@ module.exports = class ReportsHelper {
});




if (!projectDetails.length > 0) {
if ( !projectDetails.length > 0 ) {


if (getPdf == true) {
Expand Down Expand Up @@ -167,8 +164,8 @@ module.exports = class ReportsHelper {
}

await Promise.all(projectDetails.map(async function (project) {

if (project.categories) {
if ( project.categories ) {
project.categories.map(category => {

if(
Expand All @@ -189,69 +186,72 @@ module.exports = class ReportsHelper {
categories['total'] = categories['total'] + project.categories.length;
}

let todayDate = moment(project.endDate, "DD.MM.YYYY");
let endDate = moment().format();

if (project.status == CONSTANTS.common.SUBMITTED_STATUS) {
//Add data into projectReport and check project overdue.
if ( project.status == CONSTANTS.common.SUBMITTED_STATUS ) {

projectReport[CONSTANTS.common.SUBMITTED_STATUS] = projectReport[CONSTANTS.common.SUBMITTED_STATUS] + 1;

} else if (project.status == CONSTANTS.common.INPROGRESS_STATUS) {

if (todayDate.diff(endDate, 'days') < 1) {
} else if ( project.status == CONSTANTS.common.INPROGRESS_STATUS || project.status == CONSTANTS.common.STARTED ) {
//Returns project overdue status true/false.
let overdue = _getOverdueStatus( project.endDate );

if ( overdue ) {
projectReport['overdue'] = projectReport['overdue'] + 1;
} else {
projectReport[CONSTANTS.common.INPROGRESS_STATUS] = projectReport[CONSTANTS.common.INPROGRESS_STATUS] + 1;
}

} else if (project.status == CONSTANTS.common.STARTED) {

if (todayDate.diff(endDate, 'days') < 1) {
projectReport['overdue'] = projectReport['overdue'] + 1;
} else {
projectReport[CONSTANTS.common.STARTED] = projectReport[CONSTANTS.common.STARTED] + 1;
projectReport[project.status] = projectReport[project.status] + 1;
}
}
//get total project count
projectReport["total"] = projectReport[CONSTANTS.common.STARTED] +
projectReport['overdue'] + projectReport[CONSTANTS.common.INPROGRESS_STATUS] +
projectReport[CONSTANTS.common.SUBMITTED_STATUS];

if (project.taskReport) {
let keys = Object.keys(project.taskReport);
keys.map(key => {
if (tasksReport[key]) {
//Get tasks summary deatail of project.
if ( project.taskReport ) {
let keys = Object.keys( project.taskReport );
keys.map( key => {
if ( tasksReport[key] ) {
tasksReport[key] = tasksReport[key] + project.taskReport[key];
} else {
tasksReport[key] = project.taskReport[key];
tasksReport[key] = project.taskReport[key];
}
});
}

//Get number of tasks overdued.
await Promise.all(project.tasks.map(task => {
let taskCurrentDate = moment(task.endDate, "DD.MM.YYYY");
if (taskCurrentDate.diff(endDate, 'days') < 1) {
if (tasksReport['overdue']) {
tasksReport['overdue'] = tasksReport['overdue'] + 1;
} else {
tasksReport['overdue'] = 1;
}
if(tasksReport[task.status]){
tasksReport[task.status] = tasksReport[task.status] - 1;
}
//consider task only if not deleted
if ( task.isDeleted == false && task.status != CONSTANTS.common.COMPLETED_STATUS ){

//Returns true or false
let overdue = _getOverdueStatus( task.endDate );

if ( overdue ) {

if ( tasksReport['overdue'] ) {
tasksReport['overdue'] = tasksReport['overdue'] + 1;
} else {
tasksReport['overdue'] = 1;
}
if ( tasksReport[task.status] ) {
tasksReport[task.status] = tasksReport[task.status] - 1;
}

}
}

}));

}));

if (UTILS.revertStatusorNot(appVersion)) {
if ( UTILS.revertStatusorNot(appVersion) ) {

projectReport[CONSTANTS.common.COMPLETED_STATUS] = projectReport[CONSTANTS.common.SUBMITTED_STATUS];
projectReport[CONSTANTS.common.NOT_STARTED_STATUS] = projectReport[CONSTANTS.common.STARTED];
delete projectReport[CONSTANTS.common.SUBMITTED_STATUS];
delete projectReport[CONSTANTS.common.STARTED];
}

if (getPdf == true) {
if ( getPdf == true ) {

let reportTaskData = {};
Object.keys(tasksReport).map(taskData => {
Expand Down Expand Up @@ -285,7 +285,7 @@ module.exports = class ReportsHelper {
pdfRequest['entityName'] = projectDetails[0].entityInformation.name;
}


//send data to report service to generate PDF.
let response = await reportService.entityReport(userToken, pdfRequest);
if (response && response.success == true) {
return resolve({
Expand Down Expand Up @@ -683,5 +683,24 @@ function _getDateRangeofReport(reportType) {

}

/**
* Get overdue status
* @method
* @name _getOverdueStatus
* @param {String} endDate - date that task or project suppose to be finished.
* @returns {Boolean} - returns overdue status
*/

function _getOverdueStatus( endDate ) {
let overdue = false;
let today = moment().format();
let endDateObject = moment( endDate, 'YYYY-MM-DD' );

//Find difference between present date and end date
if ( endDateObject.diff( today, 'days' ) < 1 ) {
overdue = true;
}

return overdue;
}

49 changes: 37 additions & 12 deletions module/userProjects/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,17 @@ module.exports = class UserProjectsHelper {
taskReport.total = updateProject.tasks.length;

updateProject.tasks.forEach(task => {
if (!taskReport[task.status]) {
taskReport[task.status] = 1;
//consider tasks where isDeleted is false.
if ( task.isDeleted == false ) {
if (!taskReport[task.status]) {
taskReport[task.status] = 1;
} else {
taskReport[task.status] += 1;
}
} else {
taskReport[task.status] += 1;
taskReport.total = taskReport.total - 1;
}

});

updateProject["taskReport"] = taskReport;
Expand Down Expand Up @@ -1364,11 +1370,18 @@ module.exports = class UserProjectsHelper {
};

result.tasks.forEach(task => {
if (!taskReport[task.status]) {
taskReport[task.status] = 1;
if ( task.isDeleted == false ) {

if (!taskReport[task.status]) {
taskReport[task.status] = 1;
} else {
taskReport[task.status] += 1;
}

} else {
taskReport[task.status] += 1;
taskReport.total = taskReport.total - 1;
}

});

result["taskReport"] = taskReport;
Expand Down Expand Up @@ -1508,11 +1521,17 @@ module.exports = class UserProjectsHelper {
taskReport.total = createProject.tasks.length;

createProject.tasks.forEach(task => {
if (!taskReport[task.status]) {
taskReport[task.status] = 1;
if ( task.isDeleted == false ) {
if (!taskReport[task.status]) {
taskReport[task.status] = 1;
} else {
taskReport[task.status] += 1;
}
} else {
taskReport[task.status] += 1;
//if task is deleted it is not counted in total.
taskReport.total = taskReport.total - 1;
}

});

createProject["taskReport"] = taskReport;
Expand Down Expand Up @@ -2060,11 +2079,17 @@ module.exports = class UserProjectsHelper {
taskReport.total = libraryProjects.data.tasks.length;

libraryProjects.data.tasks.forEach(task => {
if (!taskReport[task.status]) {
taskReport[task.status] = 1;
if ( task.isDeleted == false ) {
if (!taskReport[task.status]) {
taskReport[task.status] = 1;
} else {
taskReport[task.status] += 1;
}
} else {
taskReport[task.status] += 1;
//reduce total count if task is deleted.
taskReport.total = taskReport.total - 1;
}

});

libraryProjects.data["taskReport"] = taskReport;
Expand Down

0 comments on commit 0dd56af

Please sign in to comment.