/// <summary> /// Copies holidays to a new Holiday Pattern /// </summary> /// <param name="holidayPatternId"></param> /// <param name="userName"></param> private void CopyHolidayPatternInformation(int holidayPatternId, string userName) { var loggedInUserId = userRepository.GetAll().FirstOrDefault(x => x.AccountName == userName).Id; var existingPattern = holidayPatternRepository.Get(holidayPatternId); var newPattern = new HolidayPattern { Name = "Copy Of " + existingPattern.Name, IsActive = existingPattern.IsActive, CreatedBy = loggedInUserId, CreatedOn = TimeZoneUtility.GetCurrentTimestamp(), LastModifiedBy = loggedInUserId, LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(), Holidays = existingPattern.Holidays.Where(x => x.IsActive).Select(y => new HolidayPatternInfo { Date = y.Date, IsActive = true, CreatedBy = loggedInUserId, CreatedOn = TimeZoneUtility.GetCurrentTimestamp(), LastModifiedBy = loggedInUserId, LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(), }).ToList() }; ValidateHolidayPatternCopyRequest(newPattern); holidayPatternRepository.AddOrUpdate(newPattern); holidayPatternRepository.Save(); }
/// <summary> /// Adds the or update monthly targets. /// </summary> /// <param name="targetId">The target identifier.</param> /// <param name="monthlyTargets">The monthly targets.</param> /// <param name="userName">Name of the user.</param> public void AddOrUpdateMonthlyTargets(int targetId, IList <RollupTargetItem> monthlyTargets, string userName) { int loggedInUserId = userRepository.GetAll().FirstOrDefault( x => x.AccountName == userName)?.Id ?? 0; DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp(); foreach (RollupTargetItem target in monthlyTargets) { if (target.TargetId.HasValue) { var existingMonthlyTarget = monthlyTargetRepository.Get(target.TargetId.Value); existingMonthlyTarget.RolledUpGoalValue = target.RollUpValue; existingMonthlyTarget.LastModifiedBy = loggedInUserId; existingMonthlyTarget.LastModifiedOn = curTimestamp; var monthlyTargetHistory = TargetConverters.ConvertMonthlyTargetToMonthlyTargetHistory(existingMonthlyTarget); monthlyTargetHistory.TargetId = existingMonthlyTarget.TargetId; existingMonthlyTarget.MonthlyTargetHistory.Add(monthlyTargetHistory); } else { if (target.RollUpValue.HasValue) { var monthlyTarget = CreateMonthlyRollupTarget(targetId, target.TargetEntryDate.Month, loggedInUserId); monthlyTarget.RolledUpGoalValue = target.RollUpValue; monthlyTargetRepository.AddOrUpdate(monthlyTarget); } } } monthlyTargetRepository.Save(); }
/// <summary> /// Gets the last day with target for current month. /// </summary> /// <param name="target">The target.</param> /// <param name="monthlyTarget">The monthly target.</param> private int GetLastDayWithTargetForCurrentMonth(Target target, MonthlyTarget monthlyTarget) { bool isRolledUpTarget = false; var currentDate = TimeZoneUtility.GetCurrentTimestamp(); var day = currentDate.Day; DailyTarget dailyTarget = new DailyTarget(); if (target.CascadedMetricsTrackingMethodId.HasValue) { // check whether cascaded metrics tracking method is rolled up targets isRolledUpTarget = (target.CascadedMetricsTrackingMethodId.Value == (int)CascadedMetricsTrackingMethod.RolledUpTargets && target.IsCascaded); } if (isRolledUpTarget) { dailyTarget = monthlyTarget.DailyTargets .Where(x => x.Day <= currentDate.Day && (x.RolledUpGoalValue != null)) .OrderByDescending(x => x.Day) .FirstOrDefault(); } else { dailyTarget = monthlyTarget.DailyTargets .Where(x => x.Day <= currentDate.Day && (x.MaxGoalValue != null)) .OrderByDescending(x => x.Day) .FirstOrDefault(); } if (dailyTarget != null) { day = dailyTarget.Day; } return(day); }
/// <summary> /// Method to Add or Update Daily Target /// </summary> /// <param name="monthlyTarget">The monthly target.</param> /// <param name="date">The date.</param> /// <param name="loggedInUserId">The logged in user identifier.</param> public virtual void AddOrUpdateDailyTarget(MonthlyTarget monthlyTarget, DateTime date, int loggedInUserId) { var currentDate = TimeZoneUtility.GetCurrentTimestamp(); var dailyTarget = dailyTargetRepository.GetAll().FirstOrDefault(x => x.MonthlyTargetId == monthlyTarget.Id && x.Day == date.Day); // add update delete if (dailyTarget == null) { var dailyTargetDate = new DailyTarget() { MonthlyTargetId = monthlyTarget.Id, Day = date.Day, MaxGoalValue = monthlyTarget.DailyRate, CreatedOn = currentDate, CreatedBy = loggedInUserId, LastModifiedOn = currentDate, LastModifiedBy = loggedInUserId }; dailyTargetRepository.AddOrUpdate(dailyTargetDate); } else { dailyTarget.MaxGoalValue = monthlyTarget.DailyRate; dailyTarget.LastModifiedBy = loggedInUserId; dailyTarget.LastModifiedOn = currentDate; dailyTargetRepository.AddOrUpdate(dailyTarget); } dailyTargetRepository.Save(); }
/// <summary> /// Method to update status and goal for monthly entry /// </summary> /// <param name="targetId">The target identifier.</param> /// <param name="selectedDate">The selected date.</param> /// <param name="userName">logged in user name</param> public virtual void UpdateMonthlyActualStatusAndGoalForMonth(int targetId, DateTime selectedDate, string userName) { //get logged in user id int loggedInUserId = userRepository.GetAll().FirstOrDefault( x => x.AccountName == userName)?.Id ?? 0; var target = targetRepository.Get(targetId); //Update corresponding monthly actual var existingMonthlyActual = monthlyActualRepository.GetAll().FirstOrDefault(x => x.TargetId == targetId && x.Month == selectedDate.Month); if (existingMonthlyActual != null) { existingMonthlyActual.LastModifiedBy = loggedInUserId; existingMonthlyActual.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(); decimal?monthlyTarget = goalCalculator.GetMonthlyGoal(targetId, selectedDate.Month); existingMonthlyActual.Status = TargetActualComparer.GetActualStatus(monthlyTarget, existingMonthlyActual.ActualValue, target.Metric.GoalTypeId); // Add the history as well existingMonthlyActual.MonthlyActualHistory.Add( ActualConverters.ConvertMonthlyActualToMonthlyActualHistory(existingMonthlyActual)); } monthlyActualRepository.Save(); }
/// <summary> /// Method to update daily rate /// </summary> /// <param name="targetId">The target identifier.</param> /// <param name="IsMarkWorkday">if set to <c>true</c> [is mark workday].</param> /// <param name="date">The date.</param> /// <param name="loggedInUserId">The logged in user identifier.</param> public virtual void UpdateDailyRateValue(int targetId, bool IsMarkWorkday, DateTime date, int loggedInUserId) { var currentDate = TimeZoneUtility.GetCurrentTimestamp(); var monthlyTarget = monthlyTargetRepository.GetAll().FirstOrDefault(x => x.TargetId == targetId && x.Month == date.Month); if (monthlyTarget != null) { if (IsMarkWorkday) { //Mark a workday //Add or update dailyTarget with Daily Rate AddOrUpdateDailyTarget(monthlyTarget, date, loggedInUserId); } else {//Mark a holiday var dailyTarget = dailyTargetRepository.GetAll().FirstOrDefault((x => x.MonthlyTargetId == monthlyTarget.Id && x.Day == date.Day)); if (dailyTarget != null) { dailyTarget.MaxGoalValue = null; dailyTarget.LastModifiedBy = loggedInUserId; dailyTarget.LastModifiedOn = currentDate; dailyTargetRepository.AddOrUpdate(dailyTarget); } } dailyTargetRepository.Save(); } }
/// <summary> /// method to validate the update of Monthly Targets for past months /// </summary> /// <param name="updatedMonthlyTargets">monthly targets that needs to be updated</param> /// <param name="existingMonthlyTargets">existing monthly targets</param> private void ValidateMonthlyTargetUpdate(List <MonthlyTargetItem> updatedMonthlyTargets, ICollection <MonthlyTarget> existingMonthlyTargets) { DateTime currentDate = TimeZoneUtility.GetCurrentTimestamp().Date; //check to restrict the update of Monthly Targets for past months foreach (var monthlyTarget in updatedMonthlyTargets) { //Condition to check whether update is for past months, If the years (current year //and selected month's year) are the same, compare the months, if the years are //not the same, selected month's year must be smaller than current year if ((monthlyTarget.Month.Year == currentDate.Year && monthlyTarget.Month.Id < currentDate.Month - 1) || monthlyTarget.Month.Year < currentDate.Year) { var existingMonthlyTarget = existingMonthlyTargets .Where(x => x.Id == monthlyTarget.Id).FirstOrDefault(); if (existingMonthlyTarget != null) { if ((existingMonthlyTarget.MaxGoalValue != monthlyTarget.GoalValue) || (existingMonthlyTarget.StretchGoalValue != monthlyTarget.StretchGoalValue)) { throw new NDMSBusinessException( Constants.MonthlyTargetUpdatePastMonthErrorMessage); } } else if (monthlyTarget.GoalValue.HasValue) { throw new NDMSBusinessException( Constants.MonthlyTargetUpdatePastMonthErrorMessage); } } } }
/// <summary> /// Tracks the recordable date. /// </summary> /// <param name="target">The target.</param> /// <param name="actualRequestDate">The actual request date.</param> public void TrackRecordables(int targetId, ActualItem actualRequest, string userName) { Target target = targetRepository.Get(targetId); DateTime recordableDate = actualRequest.Date; DateTime currentDate = TimeZoneUtility.GetCurrentTimestamp().Date; int loggedInUserId = userRepository.GetAll().FirstOrDefault( x => x.AccountName == userName).Id; // if tracking method is monthly and actual entry month and current month is same // set recordable date as current date if (target.TrackingMethodId == Constants.TrackingMethodMonthly && actualRequest.Date.Month == currentDate.Month) { recordableDate = currentDate; } if (actualRequest.ActualValue > 0) { AddOrUpdateRecordable(target, recordableDate, loggedInUserId); } else { if (target.TrackingMethodId == Constants.TrackingMethodMonthly) { DeleteRecordablesOfMonth(target, recordableDate, loggedInUserId); } else { DeleteRecordablesOfDay(target, recordableDate, loggedInUserId); } } recordableRepository.Save(); }
/// <summary> /// Method to add a metric mapping to database /// </summary> /// <param name="metricMappingItem">metric mapping to be added</param> /// <param name="userName">logged in user name</param> private void AddMetricMapping(MetricMappingItem metricMappingItem, string userName) { int loggedInUserId = userRepository.GetAll().FirstOrDefault( x => x.AccountName == userName).Id; var metricMapping = new MetricMapping() { BusinessSegmentId = metricMappingItem.BusinessSegmentId.Value, DivisionId = metricMappingItem.DivisionId.Value, FacilityId = metricMappingItem.FacilityId.Value, ProductLineId = metricMappingItem.ProductLineId.Value, DepartmentId = metricMappingItem.DepartmentId.Value, ProcessId = metricMappingItem.ProcessId.Value, KPIId = metricMappingItem.KPIId.Value, MetricId = metricMappingItem.MetricId.Value, CreatedBy = loggedInUserId, LastModifiedBy = loggedInUserId, LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(), CreatedOn = TimeZoneUtility.GetCurrentTimestamp(), IsActive = true }; metricMappingRepository.AddOrUpdate(metricMapping); metricMappingRepository.Save(); }
/// <summary> /// Adds the or update recordable date. /// </summary> /// <param name="target">The target.</param> /// <param name="recordableDate">The recordable date.</param> /// <param name="loggedInUserId">The logged in user identifier.</param> private void AddOrUpdateRecordable(Target target, DateTime recordableDate, int loggedInUserId) { var scorecardRecordable = recordableRepository.GetAll() .Where(x => x.ScorecardId == target.ScorecardId && x.RecordableDate == recordableDate && !x.IsManual).FirstOrDefault(); if (scorecardRecordable == null) { scorecardRecordable = new Recordable { ScorecardId = target.ScorecardId, RecordableDate = recordableDate, IsManual = false, IsActive = true, CreatedBy = loggedInUserId, LastModifiedBy = loggedInUserId, CreatedOn = TimeZoneUtility.GetCurrentTimestamp(), LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp() }; } else { // update recordable date scorecardRecordable.IsManual = false; scorecardRecordable.IsActive = true; scorecardRecordable.RecordableDate = recordableDate; scorecardRecordable.LastModifiedBy = loggedInUserId; scorecardRecordable.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(); } recordableRepository.AddOrUpdate(scorecardRecordable); }
/// <summary> /// Method to convert copied Target item DTO to Target entity /// </summary> /// <param name="targetItem">Target item DTO to be converted</param> /// <param name="loggedInUserId">Logged In UserId</param> /// <param name="parentTarget">parent target info for cascaded metrics, else null</param> /// <returns> /// Target entity /// </returns> public static Target ConvertCurrentYearTargetToNextYearTarget(Target targetItem, int loggedInUserId, Target parentTarget) { DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp(); var target = new Target() { ScorecardId = targetItem.ScorecardId, KPIId = targetItem.KPIId, MetricId = targetItem.MetricId, MetricType = targetItem.MetricType, //if cascaded from parent CascadeFromParent = parentTarget != null ? true : false, ParentTargetId = parentTarget?.ParentTargetId, IsStretchGoalEnabled = parentTarget?.IsStretchGoalEnabled ?? targetItem.IsStretchGoalEnabled, TrackingMethodId = parentTarget?.TrackingMethodId ?? targetItem.TrackingMethodId, TargetEntryMethodId = parentTarget?.TargetEntryMethodId ?? targetItem.TargetEntryMethodId, GraphPlottingMethodId = parentTarget?.GraphPlottingMethodId ?? targetItem.GraphPlottingMethodId, MTDPerformanceTrackingMethodId = parentTarget?.MTDPerformanceTrackingMethodId ?? targetItem.MTDPerformanceTrackingMethodId, CascadedMetricsTrackingMethodId = parentTarget?.CascadedMetricsTrackingMethodId ?? targetItem.CascadedMetricsTrackingMethodId, IsCascaded = false, IsCopiedMetric = true, IsActive = true, CreatedOn = curTimestamp, LastModifiedOn = curTimestamp, CreatedBy = loggedInUserId, LastModifiedBy = loggedInUserId, }; target.TargetHistory = new List <TargetHistory>() { ConvertTargetToTargetHistory(target) }; return(target); }
/// <summary> /// Method to get scorecard id and target availability status /// </summary> /// <param name="username">Logged in user name</param> /// <returns>ScorecardTargetStatusData DS</returns> public ScorecardTargetStatusData GetScorecardIdAndTargetStatus(string userName) { int? scorecardId = null; bool isTargetAvailable = false; var user = userRepository.GetAll().Where(x => x.AccountName == userName && x.IsActive) .FirstOrDefault(); scorecardId = GetDefaultScorecardId(user); if (scorecardId.HasValue) { DateTime curDate = TimeZoneUtility.GetCurrentTimestamp().Date; var currentYear = yearRepository.GetAll().Where(x => x.StartDate <= curDate && x.EndDate >= curDate).FirstOrDefault(); if (currentYear != null) { isTargetAvailable = targetRepository.GetAll().Any( x => x.ScorecardId == scorecardId && x.CalendarYearId == currentYear.Id && x.IsActive); } } return(new ScorecardTargetStatusData() { Id = scorecardId, IsTargetAvailable = isTargetAvailable, }); }
/// <summary> /// Adjusts(add or update)monthly actual when adding a new daily actual /// </summary> /// <param name="actualRequest">actual request</param> /// <param name="goalTypeId">goal type id</param> /// <param name="dataTypeId">data type id</param> /// <param name="loggedInUserId">logged in user id</param> /// <returns>Adjusted monthly Actual Entity after including daily target</returns> private MonthlyActual AdjustMonthlyActual(ActualItem actualRequest, int goalTypeId, int dataTypeId, int loggedInUserId) { // Get existing monthly actual entry if exists var existingMonthlyActual = monthlyActualRepository.GetAll().FirstOrDefault(x => x.TargetId == actualRequest.TargetId && x.Month == actualRequest.Date.Month); if (existingMonthlyActual != null) { // updating existing monthly actual return(UpdateExistingMonthlyActualOfDailyActual(existingMonthlyActual, actualRequest, goalTypeId, dataTypeId, loggedInUserId)); } else { DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp(); // get monthly target decimal?monthlyTarget = goalCalculator.GetMonthlyGoal(actualRequest.TargetId, actualRequest.Date.Month); // Assign the monthly target instead of daily target, because we // need to create monthly actual here actualRequest.GoalValue = monthlyTarget; return(CreateMonthlyActual(actualRequest, goalTypeId, loggedInUserId)); } }
/// <summary> /// Determines the Cascaded Metrics Tracking Method for the month for the given target. /// </summary> /// <param name="target">The target.</param> /// <param name="month">The month.</param> /// <returns> /// <c>true</c> if [is rolled up targets for month] [the specified target]; otherwise, <c>false</c>. /// </returns> private bool IsRolledUpTargetsForMonth(Target target, int month) { bool isLegendaryData = false; // non-cascaded targets always go with entered targets if (!target.IsCascaded) { return(false); } // logic to find out legend data DateTime currentDate = TimeZoneUtility.GetCurrentTimestamp(); int targetYear = target.CalendarYear.StartDate.Year; isLegendaryData = ((month < (currentDate.Month - 1) && targetYear == currentDate.Year) || (targetYear < currentDate.Year)); if (isLegendaryData) { var monthlyTarget = target.MonthlyTargets?.FirstOrDefault(x => x.Month == month); return(monthlyTarget?.IsRolledUpGoal ?? false); } else { return(target.CascadedMetricsTrackingMethodId == (int)CascadedMetricsTrackingMethod.RolledUpTargets); } }
/// <summary> /// Method to add new actual entry /// </summary> /// <param name="actualRequest">Daily actual request</param> /// <param name="goalTypeId">Metric goal type id</param> /// <param name="dataTypeId">Data type id</param> /// <param name="userName">Logged in user name</param> /// <returns>Newly created Entity Id</returns> public virtual int AddDailyActual(ActualItem actualRequest, int goalTypeId, int dataTypeId, string userName) { // Get logged in user id int loggedInUserId = userRepository.GetAll().FirstOrDefault( x => x.AccountName == userName).Id; var target = targetRepository.Get(actualRequest.TargetId); decimal?actualValueToBeCompared = actualRequest.ActualValue; decimal?goalValueToBeCompared = actualRequest.GoalValue; decimal?goalValueToBeSaved = actualRequest.GoalValue; //get cumulative actual & goal value that needs to be compared in case of cumulative plotting if (target.GraphPlottingMethodId == Constants.GraphPlottingMethodCumulative) { actualValueToBeCompared = actualCalculator.CalculateCumulativeActual( actualRequest.TargetId, actualRequest.Date, actualRequest.ActualValue); goalValueToBeCompared = goalCalculator.CalculateCumulativeGoal( target, actualRequest.Date); goalValueToBeSaved = goalCalculator.GetDailyGoal(actualRequest.TargetId, actualRequest.Date.Month, actualRequest.Date.Day); } DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp(); // Creating daily actual entity var dailyActual = new DailyActual() { Date = actualRequest.Date, GoalValue = goalValueToBeSaved, ActualValue = actualRequest.ActualValue, Status = (actualValueToBeCompared.HasValue) ? TargetActualComparer.GetActualStatus( goalValueToBeCompared, actualValueToBeCompared, goalTypeId) : ActualStatus.NotEntered, TargetId = actualRequest.TargetId, CreatedOn = curTimestamp, LastModifiedOn = curTimestamp, CreatedBy = loggedInUserId, LastModifiedBy = loggedInUserId }; dailyActual.DailyActualHistory = new List <DailyActualHistory>() { ActualConverters.ConvertDailyActualToDailyActualHistory(dailyActual) }; // Add/Update corresponding monthly actual var monthlyActual = AdjustMonthlyActual(actualRequest, goalTypeId, dataTypeId, loggedInUserId); // If it is a new monthly actual entry, add explicitly if (monthlyActual.Id == 0) { monthlyActualRepository.AddOrUpdate(monthlyActual); } dailyActualRepository.AddOrUpdate(dailyActual); dailyActualRepository.Save(); return(dailyActual.Id); }
/// <summary> /// Method to validate due date of counter measure /// </summary> /// <param name="date">counter measure due date</param> private void ValidateCounterMeasureDueDate(DateTime date) { //check whether the due date is a past date if (date < TimeZoneUtility.GetCurrentTimestamp().Date) { throw new NDMSBusinessException(Constants.CounterMeasureDueDateErrorMessage); } }
/// <summary> /// Method to validate whether Stretch Goal Targets must be on par or beat the /// monthly target based on the Goal type of the Metric /// </summary> /// <param name="metricId">Identifier of Metric</param> /// <param name="monthlyTargets">list of monthly targets</param> private void ValidateStrechGoalTarget(int metricId, List <MonthlyTargetItem> monthlyTargets) { var metric = metricRepository.Get(metricId); DateTime currentDate = TimeZoneUtility.GetCurrentTimestamp().Date; //check whether stretch goal is not entered for any current or future months bool isStretchGoalNotEntered = monthlyTargets.Any(x => (x.GoalValue.HasValue || x.DailyRateValue.HasValue) && !x.StretchGoalValue.HasValue && ((x.Month.Year == currentDate.Year && x.Month.Id >= currentDate.Month) || x.Month.Year > currentDate.Year)); if (isStretchGoalNotEntered) { throw new NDMSBusinessException(Constants.StretchGoalEmptyErrorMessage); } foreach (var monthlyTarget in monthlyTargets) { if (monthlyTarget.StretchGoalValue != null) { if (metric.GoalTypeId == Constants.GoalTypeEqualTo) { if (monthlyTarget.GoalValue != null && monthlyTarget.StretchGoalValue != monthlyTarget.GoalValue) { throw new NDMSBusinessException(Constants.TargetStretchGoalEqualToErrorMessage); } if (monthlyTarget.DailyRateValue != null && monthlyTarget.StretchGoalValue != monthlyTarget.DailyRateValue) { throw new NDMSBusinessException(Constants.DailyRateStretchGoalEqualToErrorMessage); } } else if (metric.GoalTypeId == Constants.GoalTypeGreaterThanOrEqualTo) { if (monthlyTarget.GoalValue != null && (monthlyTarget.StretchGoalValue < monthlyTarget.GoalValue)) { throw new NDMSBusinessException(Constants.TargetStretchGoalGreaterThanErrorMessage); } if (monthlyTarget.DailyRateValue != null && (monthlyTarget.StretchGoalValue < monthlyTarget.DailyRateValue)) { throw new NDMSBusinessException(Constants.DailyRateStretchGoalGreaterThanErrorMessage); } } else if (metric.GoalTypeId == Constants.GoalTypeLessThanOrEqualTo) { if (monthlyTarget.GoalValue != null && (monthlyTarget.StretchGoalValue > monthlyTarget.GoalValue)) { throw new NDMSBusinessException(Constants.TargetStretchGoalLessThanErrorMessage); } if (monthlyTarget.DailyRateValue != null && (monthlyTarget.StretchGoalValue > monthlyTarget.DailyRateValue)) { throw new NDMSBusinessException(Constants.DailyRatetStretchGoalLessThanErrorMessage); } } } } }
/// <summary> /// Updates existing Holiday Pattern /// </summary> /// <param name="requestItem"></param> /// <param name="userName"></param> private void UpdateHolidayPattern(HolidayPatternItem requestItem, string userName) { var loggedInUserId = userRepository.GetAll().FirstOrDefault(x => x.AccountName == userName).Id; var existingPattern = holidayPatternRepository.Get(requestItem.Id.Value); existingPattern.Name = requestItem.Name; existingPattern.IsActive = requestItem.IsActive; existingPattern.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(); existingPattern.LastModifiedBy = loggedInUserId; holidayPatternRepository.Save(); }
/// <summary> /// Updates the existing monthly target. /// </summary> /// <param name="existingMonthlyTarget">The existing monthly target.</param> /// <param name="targetValue">The target value.</param> /// <param name="targetEntryDate">The target entry date.</param> /// <param name="loggedInUserId">The logged in user identifier.</param> /// <returns></returns> private MonthlyTarget UpdateExistingMonthlyRollupTarget(MonthlyTarget existingMonthlyTarget, int loggedInUserId) { DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp(); existingMonthlyTarget.LastModifiedBy = loggedInUserId; existingMonthlyTarget.LastModifiedOn = curTimestamp; var monthlyTargetHistory = TargetConverters.ConvertMonthlyTargetToMonthlyTargetHistory(existingMonthlyTarget); monthlyTargetHistory.TargetId = existingMonthlyTarget.TargetId; existingMonthlyTarget.MonthlyTargetHistory.Add(monthlyTargetHistory); return(existingMonthlyTarget); }
/// <summary> /// Method to get active counter measure count for a KPI which belongs to scorecard /// </summary> /// <param name="scorecardId">Scorecard Id</param> /// <param name="kpiId">KPI Id</param> /// <returns>counter measure count</returns> public int GetCounterMeasureCount(int scorecardId, int kpiId) { DateTime currentDate = TimeZoneUtility.GetCurrentTimestamp().Date; //get count of all counter measure which are not confirmed int counterMeasureCount = counterMeasureRepository.GetAll() .Count(x => x.ScorecardId == scorecardId && x.KPIId == kpiId && x.CounterMeasureStatusId != Constants.CounterMeasureStatusConfirmed); return(counterMeasureCount); }
/// <summary> /// Validates the list of updated holidays /// </summary> /// <param name="holidays"></param> private void ValidateHolidaysListUpdateRequest(HolidayPatternInfoRequest request) { var existingHolidays = holidayPatternRepository.Get(request.HolidayPatternId) .Holidays.Where(x => x.IsActive).Select(y => y.Date).ToList(); if (request.Holidays.Where(x => x.Date <= TimeZoneUtility.GetCurrentTimestamp().Date).Any(y => !existingHolidays.Contains(y))) { throw new NDMSBusinessException(ValidationMessages.PastDateError); } }
/// <summary> /// Method to convert Counter Measure Comment to Counter Measure Comment Entity /// </summary> /// <param name="comment">comment</param> /// <param name="loggedInUserId">Logged In UserId</param> /// <returns></returns> public static CounterMeasureComment ConvertCommentToCounterMeasureComment(string comment, int loggedInUserId) { var counterMeasureComment = new CounterMeasureComment() { Comment = comment, CreatedBy = loggedInUserId, LastModifiedBy = loggedInUserId, CreatedOn = TimeZoneUtility.GetCurrentTimestamp(), LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp() }; return(counterMeasureComment); }
/// <summary> /// Gets the required Holiday pattern and holidays associated /// </summary> /// <param name="id"></param> /// <returns></returns> private HolidayPatternItem GetHolidayPatternHolidays(int id) { var holidayPatternItem = holidayPatternRepository.GetAll().Where(x => x.Id == id).Select(m => new HolidayPatternItem { Id = m.Id, Name = m.Name, IsActive = m.IsActive, Holidays = m.Holidays.Where(n => n.IsActive).Select(y => y.Date).ToList() }).FirstOrDefault(); holidayPatternItem.CurrentDate = TimeZoneUtility.GetCurrentTimestamp(); return(holidayPatternItem); }
/// <summary> /// Get Month To date performance to determine Goal Value /// </summary> /// <param name="target"></param> /// <param name="year"></param> /// <param name="month"></param> /// <returns></returns> public decimal?GetMonthToDateGoalValue(Target target, int year, int monthId) { decimal?goal = null; var currentDate = TimeZoneUtility.GetCurrentTimestamp(); var day = currentDate.Day; var monthlyTarget = target.MonthlyTargets.FirstOrDefault(x => x.TargetId == target.Id && x.Month == monthId); if (monthlyTarget != null) { if (!target.MTDPerformanceTrackingMethodId.HasValue) { return(monthlyTarget.MaxGoalValue); } switch ((MTDPerformanceTrackingMethod)target.MTDPerformanceTrackingMethodId) { case MTDPerformanceTrackingMethod.Cumulative: { goal = goalCalculator.CalculateCumulativeMTDGoal(target, monthId); } break; case MTDPerformanceTrackingMethod.Average: { goal = goalCalculator.CalculateAverageMTDGoal(target, monthId); } break; case MTDPerformanceTrackingMethod.Latest: { goal = goalCalculator.GetDailyMTDGoal(target, monthId); } break; default: break; } if (goal.HasValue) { if (target.Metric.DataTypeId == Constants.DataTypeWholeNumber) { goal = Math.Round(goal.Value, 0, MidpointRounding.AwayFromZero); } else { goal = Math.Round(goal.Value, 2, MidpointRounding.AwayFromZero); } } } return(goal); }
/// <summary> /// Deletes the recordable details for the given date. /// </summary> /// <param name="target">The target.</param> /// <param name="recordableDate">The recordable date.</param> /// <param name="loggedInUserId">The logged in user identifier.</param> private void DeleteRecordablesOfDay(Target target, DateTime recordableDate, int loggedInUserId) { var scorecardRecordable = recordableRepository.GetAll() .Where(x => x.ScorecardId == target.ScorecardId && x.RecordableDate == recordableDate && !x.IsManual && x.IsActive).FirstOrDefault(); if (scorecardRecordable != null) { scorecardRecordable.IsActive = false; scorecardRecordable.LastModifiedBy = loggedInUserId; scorecardRecordable.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(); recordableRepository.AddOrUpdate(scorecardRecordable); } }
/// <summary> /// Method to update daily actual and monthly entry /// </summary> /// <param name="actualRequest">daily actual request</param> /// <param name="goalTypeId">metric goal type id</param> /// <param name="dataTypeId">metric data type id</param> /// <param name="userName">logged in user name</param> public virtual void UpdateDailyActual(ActualItem actualRequest, int goalTypeId, int dataTypeId, string userName) { //get logged in user id int loggedInUserId = userRepository.GetAll().FirstOrDefault( x => x.AccountName == userName).Id; //get existing daily actual var existingDailyActual = dailyActualRepository.Get(actualRequest.Id.Value); var target = targetRepository.Get(actualRequest.TargetId); decimal?actualValueToBeCompared = actualRequest.ActualValue; decimal?goalValueToBeCompared = actualRequest.GoalValue; decimal?goalValueToBeSaved = actualRequest.GoalValue; //get cumulative actual & goal value that needs to be compared in case of cumulative plotting if (target.GraphPlottingMethodId == Constants.GraphPlottingMethodCumulative) { actualValueToBeCompared = actualCalculator.CalculateCumulativeActual( actualRequest.TargetId, actualRequest.Date, actualRequest.ActualValue); goalValueToBeCompared = goalCalculator.CalculateCumulativeGoal( target, actualRequest.Date); goalValueToBeSaved = goalCalculator.GetDailyGoal(actualRequest.TargetId, actualRequest.Date.Month, actualRequest.Date.Day); } //update daily actual with new changes existingDailyActual.ActualValue = actualRequest.ActualValue; existingDailyActual.GoalValue = goalValueToBeSaved; existingDailyActual.Status = (actualValueToBeCompared.HasValue) ? TargetActualComparer.GetActualStatus(goalValueToBeCompared, actualValueToBeCompared, goalTypeId) : ActualStatus.NotEntered; existingDailyActual.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(); existingDailyActual.LastModifiedBy = loggedInUserId; //add history of daily actual existingDailyActual.DailyActualHistory.Add( ActualConverters.ConvertDailyActualToDailyActualHistory(existingDailyActual)); // Add/Update corresponding monthly actual var monthlyActual = AdjustMonthlyActual(actualRequest, goalTypeId, dataTypeId, loggedInUserId); // If it is a new monthly actual entry, add explicitly if (monthlyActual.Id == 0) { monthlyActualRepository.AddOrUpdate(monthlyActual); } dailyActualRepository.Save(); }
/// <summary> /// Method to return current date and year Id /// </summary> /// <returns>Current date details</returns> public CurrentDateDetails GetCurrentDateAndYearId() { CurrentDateDetails curDateDetails = null; DateTime curDate = TimeZoneUtility.GetCurrentTimestamp().Date; var curYear = yearRepository.GetAll().Where(x => x.StartDate <= curDate && x.EndDate >= curDate).FirstOrDefault(); if (curYear != null) { curDateDetails = new CurrentDateDetails(); curDateDetails.CurrentDate = curDate; curDateDetails.YearId = curYear.Id; } return(curDateDetails); }
/// <summary> /// Method to update a metric item /// </summary> /// <param name="metricItem">Metric item to update</param> /// <param name="userName">logged in user name</param> private void UpdateMetric(MetricItem metricItem, string userName) { int loggedInUserId = userRepository.GetAll().FirstOrDefault( x => x.AccountName == userName).Id; //get existing metric details var existingMetric = metricRepository.Get(metricItem.Id.Value); existingMetric.Name = metricItem.Name; existingMetric.DataTypeId = metricItem.DataType.Id.Value; existingMetric.GoalTypeId = metricItem.GoalType.Id.Value; existingMetric.IsActive = metricItem.IsActive; existingMetric.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(); existingMetric.LastModifiedBy = loggedInUserId; metricRepository.Save(); }
/// <summary> /// Method to convert Target entity to target item DTO /// </summary> /// <param name="target">target entity to be converted</param> /// <param name="monthsList">List of months in the calendar year</param> /// <returns>target item DTO</returns> public static TargetItem ConvertTargetToTargetItemDTO(Target target, List <MonthItem> monthsList) { var currentDate = TimeZoneUtility.GetCurrentTimestamp(); var targetItem = new TargetItem() { Id = target.Id, KPIId = target.KPIId, ScorecardId = target.ScorecardId, CalendarYearId = target.CalendarYearId, MetricId = target.Metric.Id, MetricName = target.Metric.Name, MetricType = target.MetricType, MetricDataTypeId = target.Metric.DataTypeId, EffectiveStartDate = target.EffectiveStartDate, EffectiveEndDate = target.EffectiveEndDate, CascadeFromParent = target.CascadeFromParent, IsCascaded = target.IsCascaded, TargetEntryMethodId = target.TargetEntryMethodId, IsStretchGoalEnabled = target.IsStretchGoalEnabled, GraphPlottingMethodId = target.GraphPlottingMethodId, MTDPerformanceTrackingMethodId = target.MTDPerformanceTrackingMethodId, CascadedMetricsTrackingMethodId = target.CascadedMetricsTrackingMethodId, TrackingMethodId = target.TrackingMethodId, AnnualTarget = target.AnnualTarget, MonthlyTargets = target.MonthlyTargets .Select(m => ConvertMonthlyTargetToMonthlyTargetItemDTO(m, monthsList.FirstOrDefault(x => x.Id == m.Month))).ToList() }; // Fill the remaining months with empty goal values foreach (var monthItem in monthsList) { if (!targetItem.MonthlyTargets.Any(x => x.Month.Id == monthItem.Id)) { targetItem.MonthlyTargets.Add(new MonthlyTargetItem() { Month = monthItem, IsPastMonth = (monthItem.Id < (currentDate.Month - 1) && monthItem.Year == currentDate.Year) || monthItem.Year < currentDate.Year }); } } // Sort the monthly targets by year and month. targetItem.MonthlyTargets = targetItem.MonthlyTargets.OrderBy(x => x.Month.Year). ThenBy(x => x.Month.Id).ToList(); return(targetItem); }
/// <summary> /// Method to update monthly actual entry /// </summary> /// <param name="actualRequest">daily actual request</param> /// <param name="goalTypeId">metric goal type id</param> /// <param name="userName">logged in user name</param> public virtual void UpdateMonthlyActual(ActualItem actualRequest, int goalTypeId, string userName) { //get logged in user id int loggedInUserId = userRepository.GetAll().FirstOrDefault( x => x.AccountName == userName)?.Id ?? 0; var monthlyActual = monthlyActualRepository.Get(actualRequest.Id.Value); monthlyActual.ActualValue = actualRequest.ActualValue; monthlyActual.Status = TargetActualComparer.GetActualStatus(actualRequest.GoalValue, actualRequest.ActualValue, goalTypeId); monthlyActual.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(); monthlyActual.LastModifiedBy = loggedInUserId; monthlyActual.MonthlyActualHistory.Add( ActualConverters.ConvertMonthlyActualToMonthlyActualHistory(monthlyActual)); monthlyActualRepository.Save(); }