예제 #1
0
        /// <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>
        /// 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);
        }