197 lines
8.3 KiB
C#
197 lines
8.3 KiB
C#
using EnVisage.Code;
|
|
using EnVisage.Models;
|
|
using Prevu.Core.Main;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using static EnVisage.Models.ScenarioDetailsCalendarModel;
|
|
|
|
namespace EnVisage
|
|
{
|
|
public class ScenarioUIManager
|
|
{
|
|
#region Private Members
|
|
|
|
private IUserManager _userManager = null;
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public ScenarioUIManager(IUserManager userManager)
|
|
{
|
|
_userManager = userManager;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public ScenarioDetailsCalendarModel CreateScenarioDetailsCalendarModel(Guid userId, ScenarioCalendarOpener opener)
|
|
{
|
|
var model = new ScenarioDetailsCalendarModel
|
|
{
|
|
Opener = opener,
|
|
};
|
|
var user = _userManager.GetUser(userId);
|
|
if (user != null)
|
|
{
|
|
model.ShowAvgTotals = user.PreferredTotalsDisplaying;
|
|
model.IsUOMHours = !user.PreferredResourceAllocation;
|
|
model.PagePreferences = _userManager.GetPagePreferences("/Scenarios/Details", "scenarioCalendar", userId);
|
|
}
|
|
|
|
return model;
|
|
}
|
|
|
|
public ScenarioDetailsCalendarModel CreateScenarioDetailsCalendarModel(Guid userId, ScenarioDetailModel detailModel, ScenarioCalendarOpener opener)
|
|
{
|
|
var model = CreateScenarioDetailsCalendarModel(userId, opener);
|
|
if (detailModel == null)
|
|
return model;
|
|
|
|
model.Id = detailModel.Id;
|
|
model.Name = detailModel.Name;
|
|
model.ParentId = detailModel.ParentId;
|
|
model.TemplateId = detailModel.TemplateId;
|
|
model.StartDate = detailModel.StartDate.HasValue ? Utils.ConvertToUnixDate(detailModel.StartDate.Value) : 0;
|
|
model.EndDate = detailModel.EndDate.HasValue ? Utils.ConvertToUnixDate(detailModel.EndDate.Value) : 0;
|
|
model.ProjectedRevenue = detailModel.FinInfo.ProjectedRevenue ?? 0;
|
|
model.GrowthScenario = detailModel.GrowthScenario;
|
|
model.Type = detailModel.Type ?? ScenarioType.Portfolio;
|
|
model.UseLMMargin = detailModel.FinInfo.UseLMMargin;
|
|
model.GrossMargin = detailModel.FinInfo.GrossMargin;
|
|
model.LMMargin = detailModel.FinInfo.LMMargin;
|
|
model.Duration = detailModel.Duration ?? 0;
|
|
model.TDDirectCosts = detailModel.FinInfo.TDDirectCosts;
|
|
model.CGSplit = detailModel.FinInfo.LaborSplitPercentage / (decimal)100.0;
|
|
model.EFXSplit = detailModel.FinInfo.EFXSplit;
|
|
model.Shots = detailModel.TotalMilestones;
|
|
model.IsActiveScenario = detailModel.IsActiveScenario;
|
|
model.ShowActuals = false;
|
|
model.IsTableModeQuantity = true;
|
|
model.IsViewModeMonth = true;
|
|
model.ShowFilters = false;
|
|
model.TeamsInScenario = null;
|
|
model.NeedToRecalculateScenarioDetails = Guid.Empty.Equals(detailModel.Id);
|
|
model.NeedToAdjustMargin = Guid.Empty.Equals(detailModel.Id);
|
|
model.IsBottomUp = detailModel.IsBottomUp;
|
|
model.ProjectDeadline = detailModel.ProjectDeadline;
|
|
|
|
if (detailModel.ScenarioExpenditures != null)
|
|
{
|
|
model.AvailableExpenditures = detailModel.ScenarioExpenditures.Select(t => new ExpenditureModel
|
|
{
|
|
Id = t.Id,
|
|
Name = t.Name
|
|
}).ToList();
|
|
}
|
|
|
|
return model;
|
|
}
|
|
|
|
public ScenarioDetailsCalendarModel CreateScenarioDetailsCalendarModel(Guid userId, CreateScenarioModel.GeneralInfoModel detailModel, ScenarioCalendarOpener opener)
|
|
{
|
|
var model = CreateScenarioDetailsCalendarModel(userId, opener);
|
|
if (detailModel == null)
|
|
return model;
|
|
|
|
model.Id = detailModel.ScenarioId;
|
|
model.Name = detailModel.ScenarioName;
|
|
model.ParentId = detailModel.PartId ?? detailModel.ProjectId;
|
|
model.TemplateId = detailModel.TemplateId;
|
|
model.StartDate = detailModel.StartDate.HasValue ? Utils.ConvertToUnixDate(detailModel.StartDate.Value) : 0;
|
|
model.EndDate = detailModel.EndDate.HasValue ? Utils.ConvertToUnixDate(detailModel.EndDate.Value) : 0;
|
|
model.ProjectedRevenue = 0;
|
|
model.GrowthScenario = detailModel.GrowthScenario;
|
|
model.Type = ScenarioType.Portfolio;
|
|
model.UseLMMargin = false;
|
|
model.GrossMargin = 0;
|
|
model.LMMargin = null;
|
|
model.Duration = 0;
|
|
model.TDDirectCosts = 0;
|
|
model.CGSplit = detailModel.LaborSplitPercentage / (decimal)100.0;
|
|
model.EFXSplit = detailModel.EFXSplit;
|
|
model.Shots = 0;
|
|
model.IsActiveScenario = detailModel.CreateAsActive;
|
|
model.ShowActuals = false;
|
|
model.IsTableModeQuantity = true;
|
|
model.IsViewModeMonth = true;
|
|
model.ShowFilters = false;
|
|
model.NeedToRecalculateScenarioDetails = Guid.Empty.Equals(detailModel.ScenarioId);
|
|
model.NeedToAdjustMargin = Guid.Empty.Equals(detailModel.ScenarioId);
|
|
model.IsBottomUp = detailModel.IsBottomUp;
|
|
model.ProjectDeadline = detailModel.ProjectDeadline;
|
|
|
|
if (detailModel.ScenarioExpenditures != null)
|
|
{
|
|
model.AvailableExpenditures = detailModel.ScenarioExpenditures.Where(t => t.Checked).Select(t => new ExpenditureModel
|
|
{
|
|
Id = t.Id,
|
|
Name = t.Name
|
|
}).ToList();
|
|
}
|
|
|
|
if (detailModel.Teams?.Sliders != null && detailModel.Teams.Sliders.Count > 0)
|
|
{
|
|
model.TeamsInScenario = detailModel.Teams.Sliders.Select(x => new TeamInScenarioModel
|
|
{
|
|
TeamId = x.EntityId,
|
|
Allocation = (short)Math.Round(x.AllocatePercentage, 0),
|
|
IsNew = x.IsExcludable
|
|
}).ToList();
|
|
}
|
|
|
|
return model;
|
|
}
|
|
|
|
public ScenarioDetailsCalendarModel CreateScenarioDetailsCalendarModel(Guid userId, ScenarioCalendarMixModel mixModel, List<Guid> teamsInScenario, DateTime? deadline)
|
|
{
|
|
var model = CreateScenarioDetailsCalendarModel(userId, ScenarioCalendarOpener.RMO);
|
|
if (mixModel == null)
|
|
return model;
|
|
|
|
model.Id = mixModel.Id;
|
|
model.ParentId = mixModel.ParentId ?? mixModel.TemplateId;
|
|
model.TemplateId = mixModel.TemplateId;
|
|
model.StartDate = mixModel.StartDate;
|
|
model.EndDate = mixModel.EndDate;
|
|
model.GrowthScenario = mixModel.GrowthScenario;
|
|
model.Type = mixModel.Type;
|
|
model.Duration = mixModel.Duration;
|
|
model.Pinned = mixModel.Pinned;
|
|
model.IsBottomUp = mixModel.IsBottomUp;
|
|
model.Shots = 0;
|
|
model.IsActiveScenario = true;
|
|
model.ShowActuals = false;
|
|
model.IsTableModeQuantity = true;
|
|
model.IsViewModeMonth = true;
|
|
model.ShowFilters = false;
|
|
model.NeedToRecalculateScenarioDetails = false;
|
|
model.NeedToAdjustMargin = false;
|
|
model.InitOnDemand = true; // calendar will be populated with data by client-side request
|
|
model.ProjectDeadline = deadline;
|
|
if (mixModel.FinInfo != null)
|
|
{
|
|
model.ProjectedRevenue = mixModel.FinInfo.ProjectedRevenue;
|
|
model.UseLMMargin = mixModel.FinInfo.UseLMMargin;
|
|
model.GrossMargin = mixModel.FinInfo.GrossMargin;
|
|
model.LMMargin = mixModel.FinInfo.LMMargin;
|
|
model.TDDirectCosts = mixModel.FinInfo.TDDirectCosts;
|
|
model.CGSplit = mixModel.FinInfo.LaborSplitPercentage / (decimal)100.0;
|
|
model.EFXSplit = mixModel.FinInfo.EFXSplit;
|
|
}
|
|
|
|
if (teamsInScenario != null)
|
|
{
|
|
model.TeamsInScenario = teamsInScenario.Select(x => new TeamInScenarioModel() { TeamId = x, IsAccessible = true, CanBeDeleted = false })
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
model.TeamsInScenario = null;
|
|
}
|
|
|
|
return model;
|
|
}
|
|
}
|
|
} |