/// <summary> /// show employee details card. /// </summary> /// <param name="context">dialog context.</param> /// <param name="shiftData">shifts data.</param> /// <param name="punchData">punch data.</param> /// <param name="employeeName">emp name.</param> /// <param name="jobAssignmentData">job assignment data.</param> /// <returns>emp details card.</returns> public async Task ShowEmployeeDetailCard(IDialogContext context, UpcomingShiftAlias.Response shiftData, ShowPunchesAlias.Response punchData, string employeeName, JobAssignmentAlias.Response jobAssignmentData) { var reply = context.MakeMessage(); var heroCard = new HeroCard(); heroCard.Title = employeeName; var showPunchesDataOrderedList = punchData?.Timesheet?.TotaledSpans?.TotaledSpan?.OrderByDescending(x => x.InPunch.Punch.Date ?? x.OutPunch.Punch.Date).ThenByDescending(x => x.InPunch.Punch.Time ?? x.OutPunch.Punch.Time).FirstOrDefault(); var shiftsToday = shiftData.Schedule?.ScheduleItems?.ScheduleShift?.OrderBy(x => x.StartDate).FirstOrDefault(); int lastIndex = (jobAssignmentData != null) ? (jobAssignmentData?.JobAssign?.PrimaryLaborAccList?.PrimaryLaborAcc?.OrganizationPath).LastIndexOf('/') : 0; StringBuilder str = new StringBuilder(); str.Append("<br/><u><b>" + Resources.KronosResourceText.Location + "</b></u>"); str.Append($"<br/><b>{Resources.KronosResourceText.PrimaryOrg}</b> - {jobAssignmentData?.JobAssign?.PrimaryLaborAccList?.PrimaryLaborAcc?.OrganizationPath?.Substring(0, lastIndex)}"); str.Append($"<br/><b>{Resources.KronosResourceText.PrimaryJob}</b> - {jobAssignmentData?.JobAssign?.PrimaryLaborAccList?.PrimaryLaborAcc?.OrganizationPath?.Substring(lastIndex + 1)}"); str.Append($"<br/><br/><u><b>{Resources.KronosResourceText.Shifts}</b></u>"); if (shiftsToday?.ShiftSegments?.Count > 0) { foreach (UpcomingShiftAlias.ShiftSegment shiftSegment in shiftsToday?.ShiftSegments) { str.Append($"<br/><b>{shiftSegment.StartTime} - {shiftSegment.EndTime}</b> {shiftSegment.SegmentTypeName}"); } } else { str.Append("<br/>" + Resources.KronosResourceText.NoShiftsForToday); } str.Append("<br/><br/><u><b>" + Resources.KronosResourceText.LastPunch + "</b></u><br/>"); if (showPunchesDataOrderedList == null || string.IsNullOrEmpty(showPunchesDataOrderedList.InPunch.Punch?.EnteredOnDate)) { str.Append(Resources.KronosResourceText.NoPunchesForToday); } else { if (showPunchesDataOrderedList?.OutPunch?.Punch?.Time != null) { // if outpunch available then show out punch str.Append($"<b>{Resources.KronosResourceText.PunchTime}</b> - {DateTime.Parse(showPunchesDataOrderedList.OutPunch.Punch?.EnteredOnDate, CultureInfo.InvariantCulture, DateTimeStyles.None).ToString("MMM d, yyyy", CultureInfo.InvariantCulture)} {showPunchesDataOrderedList.OutPunch.Punch.Time}"); str.Append($"<br/><b>{Resources.KronosResourceText.EnteredOn}</b> - {DateTime.Parse(showPunchesDataOrderedList.OutPunch.Punch?.EnteredOnDate, CultureInfo.InvariantCulture, DateTimeStyles.None).ToString("MMM d, yyyy", CultureInfo.InvariantCulture)} {showPunchesDataOrderedList.OutPunch.Punch.EnteredOnTime}"); } else { str.Append($"<b>{Resources.KronosResourceText.PunchTime}</b> - {DateTime.Parse(showPunchesDataOrderedList.InPunch.Punch?.EnteredOnDate, CultureInfo.InvariantCulture , DateTimeStyles.None).ToString("MMM d, yyyy", CultureInfo.InvariantCulture)} {showPunchesDataOrderedList.InPunch.Punch.Time}"); str.Append($"<br/><b>{Resources.KronosResourceText.EnteredOn}</b> - {DateTime.Parse(showPunchesDataOrderedList.InPunch.Punch?.EnteredOnDate, CultureInfo.InvariantCulture, DateTimeStyles.None).ToString("MMM d, yyyy", CultureInfo.InvariantCulture)} {showPunchesDataOrderedList.InPunch.Punch.EnteredOnTime}"); } } heroCard.Text = str.ToString(); str.Clear(); reply.Attachments.Add(heroCard.ToAttachment()); await context.PostAsync(reply); }
/// <summary> /// show employee details. /// </summary> /// <param name="context">dialog context.</param> /// <param name="result">awaitable string.</param> /// <returns>employee details.</returns> private async Task ShowEmployeeDetails(IDialogContext context, IAwaitable <string> result) { string message = await result; string jSession = string.Empty; string personNumber = string.Empty; string startDate = default(string); string endDate = default(string); JObject tenant = context.Activity.ChannelData as JObject; string tenantId = tenant["tenant"].SelectToken("id").ToString(); if (context.UserData.TryGetValue(context.Activity.From.Id, out this.response)) { personNumber = this.response.PersonNumber; jSession = this.response.JsessionID; } AppInsightsLogger.CustomEventTrace("EmployeeLocationDialog", new Dictionary <string, string>() { { "TenantId", tenantId }, { "User", context.Activity.From.Id }, { "methodName", "ShowEmployeeDetails" }, { "Command", message } }); // todays date startDate = context.Activity.LocalTimestamp.Value.DateTime.Date.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture); endDate = context.Activity.LocalTimestamp.Value.DateTime.Date.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture); // get person number from employee name Response hyperFindResponse = await this.hyperFindActivity.GetHyperFindQueryValues(tenantId, jSession, startDate, endDate, ApiConstants.ReportsToHyperFindQuery, ApiConstants.PersonalVisibilityCode); if (hyperFindResponse?.Status == ApiConstants.Failure) { // User is not logged in - Send Sign in card if (hyperFindResponse.Error?.ErrorCode == ApiConstants.UserNotLoggedInError) { await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity); } } else { var employee = hyperFindResponse.HyperFindResult.Where(x => x.FullName.ToLowerInvariant().Contains(message)).FirstOrDefault(); if (employee == null) { await context.PostAsync(Resources.KronosResourceText.NoEmpFoundByName.Replace("{txt}", message)); } else { JobAssignmentAlias.Response jobAssignmentResponse = await this.jobAssignmentActivity.getJobAssignment(employee?.PersonNumber, tenantId, jSession); if (jobAssignmentResponse?.Status == ApiConstants.Failure) { if (jobAssignmentResponse.Error?.ErrorCode == ApiConstants.UserNotLoggedInError) { await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity); } } else { UpcomingShiftAlias.Response scheduleResponse = await this.upcomingShiftsActivity.ShowUpcomingShifts(tenantId, jSession, startDate, endDate, employee?.PersonNumber); ShowPunchesAlias.Response showPunchesResponse = await this.showPunchesActivity.ShowPunches(tenantId, jSession, employee?.PersonNumber, startDate, endDate); if (showPunchesResponse?.Status != ApiConstants.Failure && scheduleResponse?.Status != ApiConstants.Failure) { await this.heroEmployeeLocation.ShowEmployeeDetailCard(context, scheduleResponse, showPunchesResponse, employee.FullName, jobAssignmentResponse); } } } } context.Done(default(string)); }
/// <summary> /// Method is used to show present or absent employees. /// </summary> /// <param name="context">Dialog context.</param> /// <param name="result">Awaitable string.</param> /// <returns>A task.</returns> private async Task ShowPresentEmployees(IDialogContext context, IAwaitable <string> result) { var activity = context.Activity as Activity; JObject tenant = activity.ChannelData as JObject; string tenantId = tenant["tenant"].SelectToken("id").ToString(); var personNumber = string.Empty; var jSession = string.Empty; if (!context.UserData.TryGetValue(context.Activity.From.Id, out LoginResponse response)) { response = this.response; } else { personNumber = response.PersonNumber; jSession = response.JsessionID; } AppInsightsLogger.CustomEventTrace("PresentEmployeesDialog", new Dictionary <string, string>() { { "TenantId", tenantId }, { "User", context.Activity.From.Id }, { "methodName", "ShowPresentEmployees" }, { "Command", activity.Text } }); List <TotaledSpan> totaledSpan = new List <TotaledSpan>(); var presentEmployeeList = new SortedList <string, string>(); var personName = string.Empty; string message = activity.Text.ToLowerInvariant().Trim(); var startDate = activity.LocalTimestamp.Value.DateTime.Date.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture); var endDate = activity.LocalTimestamp.Value.DateTime.Date.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture); var isHere = activity.Text.ToLowerInvariant().Contains(Constants.WhoIsHere); switch (message) { case string command when command.Contains(Constants.presentEmpNextpage) || command.Contains(Constants.presentEmpPrevpage) || command.Contains(Constants.absentEmpPrevpage) || command.Contains(Constants.absentEmpNextpage): var item = command.Split('/'); await this.PrevNext(context, Convert.ToInt32(item[2]), message); break; default: string isManager = await this.authenticateUser.IsUserManager(context); if (isManager.Equals(Constants.Yes)) { Models.ResponseEntities.HyperFind.Response hyperFindResponse = await this.hyperFindActivity.GetHyperFindQueryValues(tenantId, jSession, startDate, endDate, ApiConstants.ReportsToHyperFindQuery, ApiConstants.PersonalVisibilityCode); if (hyperFindResponse?.Status == ApiConstants.Failure) { // User is not logged in - Send Sign in card if (hyperFindResponse.Error?.ErrorCode == ApiConstants.UserNotLoggedInError) { await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity); } else { await context.PostAsync(hyperFindResponse.Error?.Message); } } else { var scheduleResponse = await this.upcomingShiftsActivity.ShowUpcomingShifts(tenantId, jSession, startDate, endDate, personNumber, hyperFindResponse.HyperFindResult); if (scheduleResponse?.Status == ApiConstants.Failure) { if (scheduleResponse.Error?.ErrorCode == ApiConstants.UserNotLoggedInError) { await this.authenticationService.SendAuthCardAsync(context, (Activity)context.Activity); } else { await context.PostAsync(scheduleResponse.Error?.Message); } } else { var scheduleShift = scheduleResponse?.Schedule?.ScheduleItems?.ScheduleShift?.GroupBy(x => x.Employee[0].PersonNumber); // Employee has a shift if (scheduleShift != null && scheduleShift.Any() && scheduleShift?.Count() > 0) { var pNumber = string.Empty; var currentDay = activity.LocalTimestamp.Value.Date; endDate = currentDay.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture); startDate = currentDay.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture); foreach (var items in scheduleShift) { var startDates = items.Select(x => x.ShiftSegments[0].StartDate).FirstOrDefault(); var endDates = items.Select(x => x.ShiftSegments.LastOrDefault().EndDate).FirstOrDefault(); var startTime = items.Select(x => x.ShiftSegments.FirstOrDefault().StartTime).FirstOrDefault(); var endTime = items.Select(x => x.ShiftSegments.LastOrDefault().EndTime).LastOrDefault(); var shiftStartDate = DateTime.Parse($"{startDates} {startTime}", CultureInfo.InvariantCulture, DateTimeStyles.None).ToString("MMM d, yyyy h:mm tt", CultureInfo.InvariantCulture); var shiftEndDate = DateTime.Parse($"{endDates} {endTime}", CultureInfo.InvariantCulture, DateTimeStyles.None).ToString("MMM d, yyyy h:mm tt", CultureInfo.InvariantCulture); pNumber = items.Key; var showPunchesResponse = await this.showPunchesActivity.ShowPunches(tenantId, jSession, pNumber, startDate, endDate); totaledSpan = showPunchesResponse?.Timesheet?.TotaledSpans?.TotaledSpan; personName = hyperFindResponse.HyperFindResult.Find(x => x.PersonNumber == pNumber).FullName; JobAssignmentAlias.Response jobAssignmentResponse = await this.jobAssignmentActivity.getJobAssignment(pNumber, tenantId, jSession); int lastIndex = (jobAssignmentResponse != null) ? (jobAssignmentResponse?.JobAssign?.PrimaryLaborAccList?.PrimaryLaborAcc?.OrganizationPath).LastIndexOf('/') : 0; if (totaledSpan.Count > 0) { if (activity.Text.ToLowerInvariant().Contains(Constants.WhoIsHere) && totaledSpan.Any(x => x.InPunch.Punch.EnteredOnDate != null)) { presentEmployeeList.Add(personName, jobAssignmentResponse?.JobAssign?.PrimaryLaborAccList?.PrimaryLaborAcc?.OrganizationPath?.Substring(lastIndex + 1)); } else if (activity.Text.ToLowerInvariant().Contains(Constants.WhoIsNotHere) && totaledSpan.Any(x => x.InPunch.Punch.EnteredOnDate == null)) { // absent employees presentEmployeeList.Add(personName, jobAssignmentResponse?.JobAssign?.PrimaryLaborAccList?.PrimaryLaborAcc?.OrganizationPath?.Substring(lastIndex + 1)); } } } } var pagewiseAttendance = this.GetPagewiseList(presentEmployeeList); // save data for pagination if (isHere) { context.PrivateConversationData.SetValue("PagewisePresentAttendance", pagewiseAttendance); } else { context.PrivateConversationData.SetValue("PagewiseAbsentAttendance", pagewiseAttendance); } await this.presentEmployeesCard.ShowPresentEmployeesData(context, presentEmployeeList.Take(5), isHere, message, 1, presentEmployeeList.Count); } } } else if (isManager.Equals(Constants.No)) { await context.PostAsync(KronosResourceText.NoPermission); } break; } context.Done(string.Empty); }