Exemplo n.º 1
0
        /// <summary>
        /// Gets the week items for user.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public static WeekItemInfo[] GetWeekItemsForUser(DateTime from, DateTime to, int userId)
        {
            List <WeekItemInfo> retVal = new List <WeekItemInfo>();

            // Load User TT blocks
            TimeTrackingBlock[] userBlocks = TimeTrackingBlock.List(FilterElement.EqualElement("OwnerId", userId),
                                                                    new IntervalFilterElement("StartDate", from, to));

            // Sort Block By Start Date
            Array.Sort <TimeTrackingBlock>(userBlocks, CompareTimeTrackingBlockByStartDate);

            // Create Week Item Info list
            DateTime currentWeekStart = GetRealWeekStart(from);

            // TODO: Current
            while (currentWeekStart < to)
            {
                // Calculate aggregated status of all blocks
                WeekItemStatus status = CalculateWeekStatusByBlocks(currentWeekStart, userBlocks);

                WeekItemInfo item = new WeekItemInfo(currentWeekStart,
                                                     Iso8601WeekNumber.GetWeekNumber(currentWeekStart.AddDays(3)),
                                                     status);

                CalculateDayTotal(currentWeekStart, item, userBlocks);

                retVal.Add(item);

                // Go to next week
                currentWeekStart = currentWeekStart.AddDays(7);
            }

            return(retVal.ToArray());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates the week status by blocks.
        /// </summary>
        /// <param name="currentWeekStart">The current week start.</param>
        /// <param name="userBlocks">The user blocks.</param>
        /// <returns></returns>
        private static WeekItemStatus CalculateWeekStatusByBlocks(DateTime currentWeekStart, TimeTrackingBlock[] userBlocks)
        {
            DateTime currentWeekEnd = currentWeekStart.AddDays(7);

            WeekItemStatus status = WeekItemStatus.NotCompleted;

            foreach (TimeTrackingBlock block in userBlocks)
            {
                // Process if block.StartDate IN [currentWeekStart, currentWeekStart)
                if (block.StartDate < currentWeekStart)
                {
                    continue;
                }
                if (block.StartDate >= currentWeekEnd)
                {
                    break;
                }

                if ((bool)block["IsRejected"] && block.mc_State == "Initial")
                {
                    // At least one block rejected
                    status = WeekItemStatus.Rejected;
                    break;
                }

                switch (block.mc_State)
                {
                case "Initial":                         // Initial - At least one block not sent to approve
                    if (status == WeekItemStatus.NotCompleted ||
                        (int)status > (int)WeekItemStatus.InProcess)
                    {
                        status = WeekItemStatus.InProcess;
                    }
                    break;

                case "Final":                         // Final - All blocks approved
                    if (status == WeekItemStatus.NotCompleted)
                    {
                        status = WeekItemStatus.Approved;
                    }
                    break;

                default:
                    if (status == WeekItemStatus.NotCompleted ||
                        (int)status > (int)WeekItemStatus.Submitted)
                    {
                        status = WeekItemStatus.Submitted;
                    }
                    break;
                }
            }

            return(status);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WeekItemInfo"/> class.
 /// </summary>
 /// <param name="startDate">The start date.</param>
 /// <param name="weekNumber">The week number.</param>
 /// <param name="status">The status.</param>
 public WeekItemInfo(DateTime startDate, int weekNumber, WeekItemStatus status)
 {
     this.StartDate  = startDate;
     this.WeekNumber = weekNumber;
     this.Status     = status;
 }