Ejemplo n.º 1
0
        private static SOFTTEK.SCMS.Business.Entity.SRA.Week <T> GetWeekForDate <T>(DateTime date)
            where T : SOFTTEK.SCMS.Entity.SRA.Activity, new()
        {
            int      weekNumber     = -1;
            DateTime firstdayOfYear = new DateTime(date.Year, 1, 1);
            int      offset         = DayOfWeek.Thursday - firstdayOfYear.DayOfWeek;
            DateTime firstThursday  = firstdayOfYear.AddDays(offset);
            int      firstWeek      = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(firstThursday, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
            //Get Current Week
            DayOfWeek day = CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(date);

            if (day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday)
            {
                date = date.AddDays(3);
            }
            weekNumber = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
            DateTime start = firstThursday.AddDays(weekNumber * DAYS_PER_WEEK).AddDays(-(int)DayOfWeek.Thursday + 1);
            DateTime end   = start.AddDays(DAYS_PER_WEEK - 1);

            SOFTTEK.SCMS.Business.Entity.SRA.Week <T> week = new Entity.SRA.Week <T>
            {
                From   = start,
                To     = end,
                Number = weekNumber
            };
            return(week);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the range/2 previous and the range/2 fallowings weeks, by using the Iso8601 Week Of Year calculation
        /// </summary>
        /// <returns>List of week entities</returns>
        public List <Entity.SRA.Week <T> > GetAvailableWeeksInformationForEmployee <T>(int employeeID)
            where T : SOFTTEK.SCMS.Entity.SRA.Activity, new()
        {
            DateTime firstThursday;
            int      range        = 4;
            int      startingWeek = GetStartingWeekNumberInRangeForCurrentWeek(range, out firstThursday);



            return(context.Execute(() =>
            {
                List <Entity.SRA.Week <T> > weeks = new List <Entity.SRA.Week <T> >();
                for (int i = 0; i < range; i++)
                {
                    Entity.SRA.Week <T> week = new Entity.SRA.Week <T>();
                    week.From = firstThursday.AddDays((startingWeek + i) * DAYS_PER_WEEK).AddDays(-(int)DayOfWeek.Thursday + 1);
                    week.To = week.From.AddDays(DAYS_PER_WEEK - 1);
                    week.Number = startingWeek + i;
                    week.ReportedActivities = GetActivitiesForEmployeeIdInPeriod <T>(employeeID, week.From, week.To);
                    weeks.Add(week);
                }

                return weeks;
            }, "Retrive previous 2 weeks, and next 2 weeks for the week corresponding to the current day, and get the registered activities for the provided employee identifier."));
        }
Ejemplo n.º 3
0
        private void ValidateReportedActivityEffort(SOFTTEK.SCMS.Entity.SRA.Activity activity)
        {
            // Retrieve activities for the corresponding week of the validated activity
            Entity.SRA.Week <SOFTTEK.SCMS.Entity.SRA.Activity> week = GetWeekForDate <SOFTTEK.SCMS.Entity.SRA.Activity>(activity.ExecutedAt);
            week.ReportedActivities = GetActivitiesForEmployeeIdInPeriod <SOFTTEK.SCMS.Entity.SRA.Activity>(activity.Employee.Identifier, week.From, week.To);


            if (activity.Jornade == "IH")
            {
                // Daily Activities Total Effort Maximum Duration Check
                if ((week.ReportedActivities.Where(a => a.ExecutedAt.Date == activity.ExecutedAt.Date && a.Jornade == "IH")
                     .Sum(a => a.Effort) + activity.Effort) > MAX_EFFORT_PER_DAY)
                {
                    throw new Exception("La duración de la actividad supera el máximo de horas permitidas para reportar en día.",
                                        new InvalidOperationException(string.Format("El máximo de horas permitido para reportar por día es de {0}",
                                                                                    MAX_EFFORT_PER_DAY)
                                                                      )
                                        );
                }

                // Weekly Activities Total Effort Maximum Duration Check
                if ((week.ReportedActivities.Where(a => a.Jornade == "IH").Sum(a => a.Effort) + activity.Effort) > (MAX_EFFORT_PER_DAY * LABOR_DAYS_PER_WEEK))
                {
                    throw new Exception("La duración de la actividad supera el máximo de horas permitidas para reportar en una semana.",
                                        new InvalidOperationException(string.Format("El máximo de horas permitido para reportar por semana es de {0}",
                                                                                    (MAX_EFFORT_PER_DAY * LABOR_DAYS_PER_WEEK))
                                                                      )
                                        );
                }
            }
            else if (activity.Jornade == "AH")
            {
                DateTime dateExecuteAt = activity.ExecutedAt.Date;
                var      dateValue     = new DateTime(dateExecuteAt.Year, dateExecuteAt.Month, dateExecuteAt.Day).AddDays(1);

                TimeSpan oSpan         = dateValue.Subtract(dateExecuteAt);
                double   countHoursDay = oSpan.TotalHours;

                if ((week.ReportedActivities.Where(a => a.ExecutedAt.Date == activity.ExecutedAt.Date)
                     .Sum(a => a.Effort) + activity.Effort) > countHoursDay)
                {
                    throw new Exception("La duración de la actividad supera el máximo de horas permitidas para reportar en un día.",
                                        new InvalidOperationException(string.Format("El máximo de horas permitido para reportar por día es de {0} incluyendo las horas adicionales.",
                                                                                    countHoursDay)
                                                                      )
                                        );
                }
            }
        }
Ejemplo n.º 4
0
 private void ValidateUpdatedActivityEffort(SCMS.Entity.SRA.Activity activity)
 {
     Entity.SRA.Week <SOFTTEK.SCMS.Entity.SRA.Activity> week = GetWeekForDate <SOFTTEK.SCMS.Entity.SRA.Activity>(activity.ExecutedAt);
     week.ReportedActivities = GetActivitiesForEmployeeIdInPeriod <SOFTTEK.SCMS.Entity.SRA.Activity>(activity.Employee.Identifier, week.From, week.To);
 }