In dashboard project Progress show from first task assigned if give date is older than first assign date

This commit is contained in:
ashutosh.nehete 2025-04-14 15:58:14 +05:30
parent 832555d2b2
commit be0c37588e
4 changed files with 56 additions and 47 deletions

View File

@ -1,11 +1,6 @@
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using System.ComponentModel;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Marco.Pms.Model.Entitlements namespace Marco.Pms.Model.Entitlements
{ {

View File

@ -34,14 +34,20 @@ namespace Marco.Pms.Services.Controllers
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid starting date.", "Invalid starting date.", 400)); return BadRequest(ApiResponse<object>.ErrorResponse("Invalid starting date.", "Invalid starting date.", 400));
} }
if (projectId == null) { projectId = 0; } var firstTask = await _context.TaskAllocations.Select(t => new {t.TenantId,t.AssignmentDate}).FirstOrDefaultAsync(t => t.TenantId == tenantId);
if (FromDate == null) fromDate = DateTime.UtcNow.Date; if (FromDate == null) fromDate = DateTime.UtcNow.Date;
if (days >= 0) if (days >= 0)
{ {
double negativeDays = 0 - days; double negativeDays = 0 - days;
toDate = fromDate.AddDays(negativeDays); toDate = fromDate.AddDays(negativeDays);
if (firstTask.AssignmentDate.Date >= toDate.Date)
{
toDate = firstTask.AssignmentDate;
}
if (projectId == 0) if (projectId == 0)
{ {
List<TaskAllocation> tasks = await _context.TaskAllocations.Where(t => t.AssignmentDate.Date <= fromDate.Date && t.AssignmentDate.Date >= toDate.Date && t.TenantId == tenantId).ToListAsync(); List<TaskAllocation> tasks = await _context.TaskAllocations.Where(t => t.AssignmentDate.Date <= fromDate.Date && t.AssignmentDate.Date >= toDate.Date && t.TenantId == tenantId).ToListAsync();
@ -53,20 +59,23 @@ namespace Marco.Pms.Services.Controllers
ProjectProgressionVM.ProjectId = projectId; ProjectProgressionVM.ProjectId = projectId;
ProjectProgressionVM.ProjectName = ""; ProjectProgressionVM.ProjectName = "";
var date = fromDate.AddDays(flagDays); var date = fromDate.AddDays(flagDays);
var todayTasks = tasks.Where(t => t.AssignmentDate.Date == date.Date).ToList(); if (date >= firstTask.AssignmentDate.Date)
double plannedTaks = 0;
double completedTasks = 0;
ProjectProgressionVM.Date = date;
foreach (var task in todayTasks)
{ {
plannedTaks += task.PlannedTask; var todayTasks = tasks.Where(t => t.AssignmentDate.Date == date.Date).ToList();
completedTasks += task.CompletedTask; double plannedTaks = 0;
} double completedTasks = 0;
ProjectProgressionVM.PlannedTask = plannedTaks; ProjectProgressionVM.Date = date;
ProjectProgressionVM.CompletedTask = completedTasks;
projectProgressionVMs.Add(ProjectProgressionVM); foreach (var task in todayTasks)
{
plannedTaks += task.PlannedTask;
completedTasks += task.CompletedTask;
}
ProjectProgressionVM.PlannedTask = plannedTaks;
ProjectProgressionVM.CompletedTask = completedTasks;
projectProgressionVMs.Add(ProjectProgressionVM);
}
flagDays -= 1; flagDays -= 1;
} }
} }
@ -95,20 +104,24 @@ namespace Marco.Pms.Services.Controllers
projectProgressionVM.ProjectId = projectId; projectProgressionVM.ProjectId = projectId;
projectProgressionVM.ProjectName = project.Name; projectProgressionVM.ProjectName = project.Name;
var date = fromDate.AddDays(flagDays); var date = fromDate.AddDays(flagDays);
var todayTasks = tasks.Where(t => t.AssignmentDate.Date == date.Date).ToList(); if (date >= firstTask.AssignmentDate.Date)
double plannedTaks = 0;
double completedTasks = 0;
projectProgressionVM.Date = date;
foreach (var task in todayTasks)
{ {
plannedTaks += task.PlannedTask; var todayTasks = tasks.Where(t => t.AssignmentDate.Date == date.Date).ToList();
completedTasks += task.CompletedTask; double plannedTaks = 0;
} double completedTasks = 0;
projectProgressionVM.PlannedTask = plannedTaks; projectProgressionVM.Date = date;
projectProgressionVM.CompletedTask = completedTasks;
foreach (var task in todayTasks)
{
plannedTaks += task.PlannedTask;
completedTasks += task.CompletedTask;
}
projectProgressionVM.PlannedTask = plannedTaks;
projectProgressionVM.CompletedTask = completedTasks;
projectProgressionVMs.Add(projectProgressionVM);
}
projectProgressionVMs.Add(projectProgressionVM);
flagDays -= 1; flagDays -= 1;
} }
} }
@ -122,8 +135,8 @@ namespace Marco.Pms.Services.Controllers
{ {
var tenantId = _userHelper.GetTenantId(); var tenantId = _userHelper.GetTenantId();
var projects = await _context.Projects.Where(p => p.TenantId == tenantId && p.ProjectStatusId != 4).ToListAsync(); var projects = await _context.Projects.Where(p => p.TenantId == tenantId).ToListAsync();
var ongoingProjects = projects.Where(p => p.ProjectStatusId == 1).ToList(); var ongoingProjects = projects.Where(p => p.ProjectStatusId == 1 || p.ProjectStatusId == 2).ToList();
ProjectDashboardVM projectDashboardVM = new ProjectDashboardVM ProjectDashboardVM projectDashboardVM = new ProjectDashboardVM
{ {

View File

@ -177,7 +177,7 @@ namespace MarcoBMS.Services.Controllers
List<WorkItem> workItems = await _context.WorkItems.Where(i => idList.Contains(i.WorkAreaId) && i.TenantId == tenantId).Include(i => i.ActivityMaster).ToListAsync(); List<WorkItem> workItems = await _context.WorkItems.Where(i => idList.Contains(i.WorkAreaId) && i.TenantId == tenantId).Include(i => i.ActivityMaster).ToListAsync();
idList = workItems.Select(i => i.Id).ToList(); idList = workItems.Select(i => i.Id).ToList();
List<TaskAllocation> taskAllocations = await _context.TaskAllocations.Where(t => idList.Contains(t.WorkItemId) && t.AssignmentDate >= fromDate && t.AssignmentDate <= toDate && t.TenantId == tenantId).Include(t => t.WorkItem).Include(t=>t.Employee).ToListAsync(); List<TaskAllocation> taskAllocations = await _context.TaskAllocations.Where(t => idList.Contains(t.WorkItemId) && t.AssignmentDate.Date >= fromDate.Date && t.AssignmentDate.Date <= toDate.Date && t.TenantId == tenantId).Include(t => t.WorkItem).Include(t=>t.Employee).ToListAsync();
var taskIdList = taskAllocations.Select(t => t.Id).ToList(); var taskIdList = taskAllocations.Select(t => t.Id).ToList();
List<TaskMembers> teamMembers = await _context.TaskMembers.Where(t => taskIdList.Contains(t.TaskAllocationId)).Include(t => t.Employee).ToListAsync(); List<TaskMembers> teamMembers = await _context.TaskMembers.Where(t => taskIdList.Contains(t.TaskAllocationId)).Include(t => t.Employee).ToListAsync();
@ -193,7 +193,10 @@ namespace MarcoBMS.Services.Controllers
List<EmployeeVM> team = new List<EmployeeVM>(); List<EmployeeVM> team = new List<EmployeeVM>();
foreach (var taskMember in teamMembers) foreach (var taskMember in teamMembers)
{ {
team.Add(taskMember.Employee.ToEmployeeVMFromEmployee()); if(taskMember != null)
{
team.Add(taskMember.Employee.ToEmployeeVMFromEmployee());
}
} }
List<CommentVM> commentVM = new List<CommentVM> { }; List<CommentVM> commentVM = new List<CommentVM> { };
foreach (var comment in comments) foreach (var comment in comments)

View File

@ -24,16 +24,6 @@ builder.Host.UseSerilog((context, config) =>
; ;
// Add services // Add services
//builder.Services.AddCors(options =>
//{
// options.AddPolicy("DevCorsPolicy", policy =>
// {
// policy.AllowAnyOrigin()
// .AllowAnyMethod()
// .AllowAnyHeader();
// });
//});
var corsSettings = builder.Configuration.GetSection("Cors"); var corsSettings = builder.Configuration.GetSection("Cors");
var allowedOrigins = corsSettings.GetValue<string>("AllowedOrigins")?.Split(','); var allowedOrigins = corsSettings.GetValue<string>("AllowedOrigins")?.Split(',');
var allowedMethods = corsSettings.GetValue<string>("AllowedMethods")?.Split(','); var allowedMethods = corsSettings.GetValue<string>("AllowedMethods")?.Split(',');
@ -50,6 +40,14 @@ builder.Services.AddCors(options =>
.WithHeaders(allowedHeaders); .WithHeaders(allowedHeaders);
} }
}); });
}).AddCors(options =>
{
options.AddPolicy("DevCorsPolicy", policy =>
{
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
}); });
// Add services to the container. // Add services to the container.