Example #1
0
        private async Task <TimeAndAttendanceTimeView> GetTimeByMinuteDuration(string punchinString, int minutesDuration)
        {
            DateTime fromTime;
            DateTime toTime;
            string   timeIn  = "";
            string   timeOut = "";

            try
            {
                timeIn   = ReverseDate(punchinString) + " " + ReverseTranslate24hr(punchinString);
                fromTime = DateTime.Parse(timeIn);

                toTime = fromTime.AddMinutes(minutesDuration);

                timeOut = GetPunchDateTime(toTime);

                TimeAndAttendanceTimeView myTime = new TimeAndAttendanceTimeView();

                myTime.PunchDate     = toTime;
                myTime.PunchDateTime = timeOut;

                await Task.Yield();

                return(myTime);
            }
            catch (Exception ex)
            {
                throw new Exception(GetMyMethodName(), ex);
            }
        }
Example #2
0
        public async Task <CreateProcessStatus> UpdatePunchin(TimeAndAttendancePunchIn taPunchin, int mealDeduction, int manualElapsedHours = 0, int manualElapsedMinutes = 0)
        {
            try
            {
                //long timePunchinId = 0;
                long?  employeeId      = taPunchin.EmployeeId;
                string punchinDateTime = taPunchin.PunchinDateTime;
                int    minutesDuration = 0;
                TimeAndAttendanceTimeView currentTime = null;
                //Case 1 : Manual entry of punchout time based on minutes duration
                if (manualElapsedHours != 0 || manualElapsedMinutes != 0)
                {
                    minutesDuration = manualElapsedHours * 60 + manualElapsedMinutes - mealDeduction;
                    currentTime     = await GetTimeByMinuteDuration(punchinDateTime, minutesDuration);
                }
                //Case 2 : User presses punchout
                else
                {
                    currentTime = await GetUTCAdjustedTime();

                    minutesDuration = await GetDuration(punchinDateTime, currentTime.PunchDateTime, mealDeduction);
                }
                taPunchin.PunchoutDate     = currentTime.PunchDate;
                taPunchin.PunchoutDateTime = currentTime.PunchDateTime;

                taPunchin.DurationInMinutes     = minutesDuration;
                taPunchin.MealDurationInMinutes = mealDeduction;

                Udc status = await base.GetUdc2("TA_STATUS", TypeOfTAStatus.Closed.ToString().ToUpper());

                taPunchin.TaskStatusXrefId = status.XrefId;
                taPunchin.TaskStatus       = status.KeyCode;

                UpdateObject(taPunchin);
                return(CreateProcessStatus.Update);
            }
            catch (Exception ex)
            {
                throw new Exception(GetMyMethodName(), ex);
            }
        }
Example #3
0
        public async Task <TimeAndAttendanceTimeView> GetUTCAdjustedTime()
        {
            try
            {
                TimeAndAttendanceTimeView utcTime = new TimeAndAttendanceTimeView();

                DateTime mst = DateTime.Now;

                TimeZoneInfo localTime;

                TimeAndAttendanceSetup setup = await GetTimeAndAttendanceTimeZone();

                localTime = TimeZoneInfo.FindSystemTimeZoneById(setup.TimeZone); //TimeZoneInfo.Local.StandardName

                TimeSpan offset = localTime.GetUtcOffset(mst);

                //bool isDaylightSaving = localTime.IsDaylightSavingTime(mst);

                mst = DateTime.Now.ToUniversalTime().AddHours(offset.Hours).ToUniversalTime();

                utcTime.PunchDate = mst;

                string year    = mst.Year.ToString();
                string month   = Utilities.Right("0" + mst.Month.ToString(), 2);
                string day     = Utilities.Right("0" + mst.Day.ToString(), 2);
                string hours   = Utilities.Right("0" + mst.Hour.ToString(), 2);
                string minutes = Utilities.Right("0" + mst.Minute.ToString(), 2);
                string seconds = Utilities.Right("0" + mst.Second.ToString(), 2);

                utcTime.PunchDateTime = year + month + day + hours + minutes + seconds;
                return(utcTime);
            }
            catch (Exception ex)
            {
                throw new Exception(GetMyMethodName(), ex);
            }
        }