예제 #1
0
 private void userListView_ItemClick(object sender, ItemClickEventArgs e)
 {
     PayrollCore.Entities.User user = e.ClickedItem as PayrollCore.Entities.User;
     this.Frame.Navigate(typeof(UserDetailsPage), user, new SlideNavigationTransitionInfo()
     {
         Effect = SlideNavigationTransitionEffect.FromRight
     });
 }
예제 #2
0
        public Activity GenerateSignOutInfo(Activity activity, PayrollCore.Entities.User user)
        {
            DateTime signInTime  = activity.inTime;
            DateTime signOutTime = DateTime.Now;

            if (signInTime.DayOfYear < signOutTime.DayOfYear)
            {
                activity.RequireNotification = true;
                activity.NotificationReason  = 2;
                string s = activity.inTime.ToShortDateString() + " " + activity.EndShift.startTime.ToString();
                DateTime.TryParse(s, out signOutTime);
            }
            else
            {
                activity.RequireNotification = false;
            }

            activity.outTime = signOutTime;

            TimeSpan activityOffset = signOutTime.Subtract(signInTime);

            if (user.userGroup.DefaultRate.rate > activity.StartShift.DefaultRate.rate)
            {
                // Use user's default rate
                activity.ApplicableRate = user.userGroup.DefaultRate;
            }
            else
            {
                // Use shift's default rate
                activity.ApplicableRate = activity.StartShift.DefaultRate;
            }

            activity.ClaimableAmount = CalcPay(activityOffset.TotalHours, activity.ApplicableRate.rate);
            activity.ApprovedHours   = activityOffset.TotalHours;
            activity.ClaimDate       = DateTime.Today;

            return(activity);
        }
예제 #3
0
        private async void LoadTimer_Tick(object sender, object e)
        {
            loadTimer.Stop();
            string emailContent;

            if (SettingsHelper.Instance.userState != null)
            {
                Activity activity = await SettingsHelper.Instance.op2.CompleteWorkActivity(SettingsHelper.Instance.userState.LatestActivity,
                                                                                           SettingsHelper.Instance.userState.user, false);

                bool IsSuccess = await SettingsHelper.Instance.op2.UpdateActivity(activity);

                if (IsSuccess)
                {
                    if (activity.RequireNotification == true)
                    {
                        emailContent  = "Dear all, \n " + SettingsHelper.Instance.userState.user.fullName + " has signed out late. Below are the details of the shift.";
                        emailContent += "\n Shift: " + activity.EndShift.shiftName + "\n Location: " + SettingsHelper.Instance.appLocation.locationName + "\n Shift ends: ";
                        emailContent += activity.EndShift.endTime.ToString() + "\n Actual sign out: " + activity.actualOutTime;
                        emailContent += "\n Thank You. \n This is an auto-generated email. Please do not reply to this email.";

                        var message = new Message
                        {
                            Subject = "[Payroll] Sign Out Late " + activity.EndShift.shiftName + DateTime.Today.ToShortDateString(),
                            Body    = new ItemBody
                            {
                                ContentType = BodyType.Text,
                                Content     = emailContent
                            },
                            ToRecipients = new List <Recipient>()
                            {
                                new Recipient
                                {
                                    EmailAddress = new EmailAddress
                                    {
                                        Address = "*****@*****.**"
                                    }
                                }
                            },
                            CcRecipients = new List <Recipient>()
                            {
                                new Recipient
                                {
                                    EmailAddress = new EmailAddress
                                    {
                                        Address = SettingsHelper.Instance.userState.user.userID
                                    }
                                }
                            }
                        };

                        var saveToItems = false;

                        try
                        {
                            var provider = ProviderManager.Instance.GlobalProvider;

                            if (provider != null && provider.State == ProviderState.SignedIn)
                            {
                                await provider.Graph.Me.SendMail(message, saveToItems).Request().PostAsync();
                            }
                        }
                        catch (Microsoft.Graph.ServiceException graphEx)
                        {
                            ContentDialog contentDialog = new ContentDialog
                            {
                                Title               = "Signed out with errors",
                                Content             = "Please send the Sign Out Late email to HR. Tap on the More info button to see what failed.",
                                PrimaryButtonText   = "Ok",
                                SecondaryButtonText = "More info"
                            };

                            ContentDialogResult result = await contentDialog.ShowAsync();

                            if (result == ContentDialogResult.Secondary)
                            {
                                ContentDialog contentDialog2 = new ContentDialog
                                {
                                    Title             = "Graph API error",
                                    Content           = graphEx.Error,
                                    PrimaryButtonText = "Close"
                                };

                                await contentDialog2.ShowAsync();
                            }
                        }
                        finally
                        {
                            PayrollCore.Entities.User user = SettingsHelper.Instance.userState.user;
                            await SettingsHelper.Instance.UpdateUserState(user);

                            this.Frame.Navigate(typeof(UserProfilePage), null, new SlideNavigationTransitionInfo()
                            {
                                Effect = SlideNavigationTransitionEffect.FromLeft
                            });
                        }
                    }
                }
                else
                {
                    ContentDialog contentDialog = new ContentDialog
                    {
                        Title               = "Unable to sign out",
                        Content             = "There's a problem signing you out. Please try again later. If the problem persists, please contact Chiefs or HR Functional Unit to sign you out.",
                        PrimaryButtonText   = "Ok",
                        SecondaryButtonText = "More info"
                    };

                    await contentDialog.ShowAsync();

                    this.Frame.Navigate(typeof(LoginPagev2), null, new SlideNavigationTransitionInfo()
                    {
                        Effect = SlideNavigationTransitionEffect.FromLeft
                    });
                }
            }
            else
            {
                this.Frame.Navigate(typeof(LoginPagev2), null, new SlideNavigationTransitionInfo()
                {
                    Effect = SlideNavigationTransitionEffect.FromLeft
                });
            }

            await SettingsHelper.Instance.UpdateUserState(SettingsHelper.Instance.userState.user);

            loadTimer.Stop();
            pageContent.Visibility = Visibility.Visible;
            loadGrid.Visibility    = Visibility.Collapsed;
        }
예제 #4
0
        private async void signInButton_Click(object sender, RoutedEventArgs e)
        {
            loadGrid.Visibility = Visibility.Visible;

            var selectedItem = shiftSelectionView.SelectedItem as PayrollCore.Entities.Meeting;

            if (selectedItem == null)
            {
                ContentDialog contentDialog = new ContentDialog()
                {
                    Title           = "Please select a meeting",
                    Content         = "You haven't selected any meeting. Please select one and try again.",
                    CloseButtonText = "Ok"
                };

                await contentDialog.ShowAsync();

                return;
            }

            var activity = SettingsHelper.Instance.op2.GenerateMeetingActivity(SettingsHelper.Instance.userState.user.userID, selectedItem);

            bool IsSuccess = await SettingsHelper.Instance.op2.AddNewActivity(activity);

            if (IsSuccess == true)
            {
                if (activity.RequireNotification && SettingsHelper.Instance.userState.user.fromAD)
                {
                    string emailContent;
                    emailContent  = "Dear all, \n " + SettingsHelper.Instance.userState.user.fullName + " has signed in late for a meeting. Below are the details of the meeting.";
                    emailContent += "\n Shift: " + activity.meeting.meetingName + "\n Location: " + SettingsHelper.Instance.appLocation.locationName + "\n Meeting start: ";
                    emailContent += activity.inTime.ToShortDateString() + " " + activity.meeting.StartTime.ToString() + "\n Actual sign in: " + activity.inTime;
                    emailContent += "\n Thank You. \n This is an auto-generated email. Please do not reply to this email.";

                    var message = new Message
                    {
                        Subject = "[Payroll] Meeting Late Attendance " + activity.meeting.meetingName + DateTime.Today.ToShortDateString(),
                        Body    = new ItemBody
                        {
                            ContentType = BodyType.Text,
                            Content     = emailContent
                        },
                        ToRecipients = new List <Recipient>()
                        {
                            new Recipient
                            {
                                EmailAddress = new EmailAddress
                                {
                                    Address = "*****@*****.**"
                                }
                            }
                        },
                        CcRecipients = new List <Recipient>()
                        {
                            new Recipient
                            {
                                EmailAddress = new EmailAddress
                                {
                                    Address = SettingsHelper.Instance.userState.user.userID
                                }
                            }
                        }
                    };

                    var saveToItems = false;

                    try
                    {
                        var provider = ProviderManager.Instance.GlobalProvider;

                        if (provider != null && provider.State == ProviderState.SignedIn)
                        {
                            await provider.Graph.Me.SendMail(message, saveToItems).Request().PostAsync();
                        }
                    }
                    catch (Microsoft.Graph.ServiceException graphEx)
                    {
                        ContentDialog contentDialog = new ContentDialog
                        {
                            Title               = "Unable to send late sign in notification",
                            Content             = "Please notify HR Functional Unit members that you have joined the meeting late. Tap on the More info button to see what failed.",
                            PrimaryButtonText   = "Ok",
                            SecondaryButtonText = "More info"
                        };

                        ContentDialogResult result = await contentDialog.ShowAsync();

                        if (result == ContentDialogResult.Secondary)
                        {
                            ContentDialog contentDialog2 = new ContentDialog
                            {
                                Title             = "Graph API error",
                                Content           = graphEx.Error,
                                PrimaryButtonText = "Close"
                            };

                            await contentDialog2.ShowAsync();
                        }
                    }
                }

                PayrollCore.Entities.User user = SettingsHelper.Instance.userState.user;
                await SettingsHelper.Instance.UpdateUserState(user);

                this.Frame.Navigate(typeof(AttendanceRecodedPage), null, new SlideNavigationTransitionInfo()
                {
                    Effect = SlideNavigationTransitionEffect.FromRight
                });
            }
            else
            {
                ContentDialog warningDialog = new ContentDialog
                {
                    Title             = "Unable to record your attendance.",
                    Content           = "There is a problem recording your attendance for the meeting. Please try again later. If the problem persits, please contact Chiefs or HR Functional Unit to help you sign in.",
                    PrimaryButtonText = "Ok"
                };

                await warningDialog.ShowAsync();

                this.Frame.Navigate(typeof(UserProfilePage), null, new SlideNavigationTransitionInfo()
                {
                    Effect = SlideNavigationTransitionEffect.FromLeft
                });
            }
        }
예제 #5
0
        private async void signInButton_Click(object sender, RoutedEventArgs e)
        {
            loadGrid.Visibility = Visibility.Visible;
            bool AllowSignin = false;

            PayrollCore.Entities.Shift startShift;
            PayrollCore.Entities.Shift endShift;

            if (shiftSelectionView.SelectedItems.Count > 1)
            {
                List <PayrollCore.Entities.Shift> selectedShiftList = new List <PayrollCore.Entities.Shift>();

                foreach (PayrollCore.Entities.Shift shift in shiftSelectionView.SelectedItems)
                {
                    selectedShiftList.Add(shift);
                }

                selectedShiftList.Sort((s1, s2) => TimeSpan.Compare(s1.startTime, s2.startTime));
                startShift = selectedShiftList.First();
                endShift   = selectedShiftList.Last();

                TimeSpan lastEndTime = new TimeSpan();
                foreach (PayrollCore.Entities.Shift shift in selectedShiftList)
                {
                    Debug.WriteLine("[SHIFT] Checking shift: " + shift.shiftName);
                    if (shift.Equals(startShift))
                    {
                        Debug.WriteLine("[SHIFT] First shift selected: " + shift.shiftName);
                        lastEndTime = shift.endTime;
                    }
                    else
                    {
                        if (lastEndTime != shift.startTime)
                        {
                            break;
                        }
                        else
                        {
                            lastEndTime = shift.endTime;
                        }
                    }

                    if (shift.Equals(endShift))
                    {
                        Debug.WriteLine("[SHIFT] Last shift selected: " + shift.shiftName);
                        AllowSignin = true;
                    }
                }
            }
            else if (shiftSelectionView.SelectedItems.Count == 1)
            {
                AllowSignin = true;
                startShift  = shiftSelectionView.SelectedItem as PayrollCore.Entities.Shift;
                endShift    = startShift;
            }
            else
            {
                ContentDialog contentDialog = new ContentDialog()
                {
                    Title           = "Please select a shift",
                    Content         = "You haven't selected any shift. Please select at least one and try again.",
                    CloseButtonText = "Ok"
                };

                await contentDialog.ShowAsync();

                return;
            }

            if (AllowSignin)
            {
                var activity = SettingsHelper.Instance.op2.GenerateWorkActivity(SettingsHelper.Instance.userState.user.userID, startShift, endShift);

                bool IsSuccess = await SettingsHelper.Instance.op2.AddNewActivity(activity);

                if (IsSuccess)
                {
                    if (activity.RequireNotification && SettingsHelper.Instance.userState.user.fromAD)
                    {
                        string emailContent;
                        emailContent  = "Dear all, \n " + SettingsHelper.Instance.userState.user.fullName + " has signed in late. Below are the details of the shift.";
                        emailContent += "\n Shift: " + activity.StartShift.shiftName + "\n Location: " + SettingsHelper.Instance.appLocation.locationName + "\n Shift start: ";
                        emailContent += activity.StartShift.startTime.ToString() + "\n Actual sign in: " + activity.inTime;
                        emailContent += "\n Thank You. \n This is an auto-generated email. Please do not reply to this email.";

                        var message = new Message
                        {
                            Subject = "[Payroll] Sign In Late " + activity.StartShift.shiftName + " " + DateTime.Today.ToShortDateString(),
                            Body    = new ItemBody
                            {
                                ContentType = BodyType.Text,
                                Content     = emailContent
                            },
                            ToRecipients = new List <Recipient>()
                            {
                                new Recipient
                                {
                                    EmailAddress = new EmailAddress
                                    {
                                        Address = "*****@*****.**"
                                    }
                                }
                            },
                            CcRecipients = new List <Recipient>()
                            {
                                new Recipient
                                {
                                    EmailAddress = new EmailAddress
                                    {
                                        Address = SettingsHelper.Instance.userState.user.userID
                                    }
                                }
                            }
                        };

                        var saveToItems = false;

                        try
                        {
                            var provider = ProviderManager.Instance.GlobalProvider;

                            if (provider != null && provider.State == ProviderState.SignedIn)
                            {
                                await provider.Graph.Me.SendMail(message, saveToItems).Request().PostAsync();
                            }
                        }
                        catch (Microsoft.Graph.ServiceException graphEx)
                        {
                            ContentDialog contentDialog = new ContentDialog
                            {
                                Title               = "Unable to send late sign in notification",
                                Content             = "Please send the Sign In Late email to HR. You are signed in. There is no need to re-sign in. Tap on the More info button to see what failed.",
                                PrimaryButtonText   = "Ok",
                                SecondaryButtonText = "More info"
                            };

                            ContentDialogResult result = await contentDialog.ShowAsync();

                            if (result == ContentDialogResult.Secondary)
                            {
                                ContentDialog contentDialog2 = new ContentDialog
                                {
                                    Title             = "Graph API error",
                                    Content           = graphEx.Error,
                                    PrimaryButtonText = "Close"
                                };

                                await contentDialog2.ShowAsync();
                            }
                        }
                    }
                }
                else
                {
                    ContentDialog warningDialog = new ContentDialog
                    {
                        Title             = "Unable to sign in!",
                        Content           = "There's a problem preventing us to sign you in. Please try again later. If the problem persits, please contact Chiefs or HR Functional Unit to help you sign in.",
                        PrimaryButtonText = "Ok"
                    };

                    await warningDialog.ShowAsync();
                }

                PayrollCore.Entities.User user = SettingsHelper.Instance.userState.user;
                await SettingsHelper.Instance.UpdateUserState(user);

                this.Frame.Navigate(typeof(UserProfilePage), null, new SlideNavigationTransitionInfo()
                {
                    Effect = SlideNavigationTransitionEffect.FromLeft
                });
            }
            else
            {
                ContentDialog contentDialog = new ContentDialog()
                {
                    Title           = "Invalid selection",
                    Content         = "The shifts you selected are invalid. Please make sure that the shifts you selected are back to back.",
                    CloseButtonText = "Ok"
                };

                await contentDialog.ShowAsync();

                loadGrid.Visibility = Visibility.Collapsed;
            }
        }