public void MustCalculateTotalWorkedHoursByResourceWhenMissesEndDateWithEmergencyResponse()
        {
            //Arrange
            DateTime currentDate = DateTime.Now.Date.AddHours(3);
            CS_DPIResource dpiResources = new CS_DPIResource() { ID = 1 };
            List<DPICallLogVO> startCallLog = new List<DPICallLogVO>();
            List<DPICallLogVO> endCallLog = new List<DPICallLogVO>();
            startCallLog.Add(
                new DPICallLogVO()
                {
                    ID = 1,
                    ActionTime = currentDate.AddHours(-10)
                });
            endCallLog.Add(new DPICallLogVO()
            {
                ID = 2,
                ActionTime = currentDate.AddHours(-8)
            });
            endCallLog.Add(new DPICallLogVO()
            {
                ID = 3,
                ActionTime = currentDate.AddHours(-6)
            });
            startCallLog.Add(new DPICallLogVO()
            {
                ID = 4,
                ActionTime = currentDate.AddHours(-4)
            });

            DPIModel model = new DPIModel();

            //Act
            model.CalculateHoursForResouce(
                dpiResources, true,
                currentDate.AddHours(-10),
                startCallLog,
                endCallLog,
                currentDate.Date.AddDays(-1));

            //Assert
            Assert.AreEqual(5, Math.Round(dpiResources.Hours, 2)
            );
        }
 public void MustCalculateTotalWorkedHoursByResourceWhenMissesEndDatesWithoutEmergencyResponseWithMultipleValues()
 {
     //Arrange
     CS_DPIResource dpiResources = new CS_DPIResource() { ID = 1 };
     List<DPICallLogVO> startCallLog = new List<DPICallLogVO>();
     List<DPICallLogVO> endCallLog = new List<DPICallLogVO>();
     startCallLog.Add(
         new DPICallLogVO()
         {
             ID = 1,
             ActionTime = DateTime.Now.AddHours(-10)
         });
     startCallLog.Add(
         new DPICallLogVO()
         {
             ID = 2,
             ActionTime = DateTime.Now.AddHours(-8)
         });
     endCallLog.Add(new DPICallLogVO()
     {
         ID = 3,
         ActionTime = DateTime.Now.AddHours(-6)
     });
     endCallLog.Add(new DPICallLogVO()
     {
         ID = 4,
         ActionTime = DateTime.Now.AddHours(-4)
     });
     startCallLog.Add(new DPICallLogVO()
     {
         ID = 4,
         ActionTime = DateTime.Now.AddHours(-2)
     });
     DPIModel model = new DPIModel();
     //Act
     model.CalculateHoursForResouce(dpiResources, false, new DateTime(), startCallLog, endCallLog, DateTime.Now.Date);
     //Assert
     Assert.AreEqual(Convert.ToInt32(6 + DateTime.Now.Subtract(startCallLog[2].ActionTime).TotalHours), Convert.ToInt32(dpiResources.Hours));
 }
 public void MustCalculateTotalWorkedHoursByResourceWhenStartAndEndDatesMatchWithoutEmergencyResponseWithMultipleValues()
 {
     //Arrange
     CS_DPIResource dpiResources = new CS_DPIResource() { ID = 1 };
     List<DPICallLogVO> startCallLog = new List<DPICallLogVO>();
     List<DPICallLogVO> endCallLog = new List<DPICallLogVO>();
     startCallLog.Add(new DPICallLogVO() { ID = 1, ActionTime = new DateTime(2011, 8, 9, 8, 0, 0) });
     startCallLog.Add(new DPICallLogVO() { ID = 3, ActionTime = new DateTime(2011, 8, 9, 9, 0, 0) });
     endCallLog.Add(new DPICallLogVO() { ID = 2, ActionTime = new DateTime(2011, 8, 9, 12, 0, 0) });
     startCallLog.Add(new DPICallLogVO() { ID = 1, ActionTime = new DateTime(2011, 8, 9, 14, 0, 0) });
     endCallLog.Add(new DPICallLogVO() { ID = 4, ActionTime = new DateTime(2011, 8, 9, 18, 0, 0) });
     DPIModel model = new DPIModel();
     //Act
     model.CalculateHoursForResouce(dpiResources, false, new DateTime(), startCallLog, endCallLog, new DateTime(2011, 8, 9, 0, 0, 0));
     //Assert
     Assert.AreEqual(8, dpiResources.Hours);
 }
 public void MustCalculateTotalWorkedHoursByResourceWhenStartAndEndDatesMatchWithEmergencyResponse()
 {
     //Arrange
     CS_DPIResource dpiResources = new CS_DPIResource() { ID = 1 };
     List<DPICallLogVO> startCallLog = new List<DPICallLogVO>();
     List<DPICallLogVO> endCallLog = new List<DPICallLogVO>();
     startCallLog.Add(new DPICallLogVO() { ID = 1, ActionTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 9, 0, 0) });
     endCallLog.Add(new DPICallLogVO() { ID = 2, ActionTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 13, 0, 0) });
     endCallLog.Add(new DPICallLogVO() { ID = 3, ActionTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 15, 0, 0) });
     DPIModel model = new DPIModel();
     //Act
     model.CalculateHoursForResouce(dpiResources, true, new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 11, 0, 0), startCallLog, endCallLog, new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0));
     //Assert
     Assert.AreEqual(4, dpiResources.Hours);
 }
 public void MustCalculateTotalWorkedHoursByResourceWhenMissesEndDateWithoutEmergencyResponse()
 {
     //Arrange
     CS_DPIResource dpiResources = new CS_DPIResource() { ID = 1 };
     List<DPICallLogVO> startCallLog = new List<DPICallLogVO>();
     List<DPICallLogVO> endCallLog = new List<DPICallLogVO>();
     startCallLog.Add(
         new DPICallLogVO()
         {
             ID = 1,
             ActionTime = DateTime.Now.AddHours(-6)
         });
     endCallLog.Add(new DPICallLogVO()
     {
         ID = 2,
         ActionTime = DateTime.Now.AddHours(-4)
     });
     startCallLog.Add(new DPICallLogVO()
     {
         ID = 3,
         ActionTime = DateTime.Now.AddHours(-2)
     });
     DPIModel model = new DPIModel();
     //Act
     model.CalculateHoursForResouce(dpiResources, false, new DateTime(), startCallLog, endCallLog, DateTime.Now.Date);
     //Assert
     Assert.AreEqual(Math.Round(Convert.ToDecimal(2 + DateTime.Now.Subtract(startCallLog[1].ActionTime).TotalHours), 2), Math.Round(dpiResources.Hours, 2));
 }
Esempio n. 6
0
        public CS_DPIResource CalculateHoursForResouce(CS_DPIResource currentDPIResource, bool IsEmergencyResponse, DateTime jobStartDate, List<DPICallLogVO> startCallLogs, List<DPICallLogVO> endCallLogs, DateTime calculationDate)
        {
            //VARIABLES NEEDED FOR CALCULATION PURPOSES
            DateTime lastStartTime = new DateTime(), currentStartTime = new DateTime(), currentEndTime = new DateTime(), endOfDay = calculationDate.Date + TimeSpan.Parse("23:59:59");
            double lastTotalHours = 0, totalHours = 0, rate = 0;
            bool lookingForStart = true, insf = false;

            //IF JOB HAS EMERGENCY RESPONSE FLAGGED FOR THE CURRENT DAY, USE IT AS FIRST START DATE
            if (IsEmergencyResponse && (jobStartDate.Date == calculationDate.Date))
            {
                currentStartTime = jobStartDate;
                lookingForStart = false;
            }

            do
            {
                if (lookingForStart)
                {
                    if (startCallLogs.Count > 0)
                    {
                        DPICallLogVO startItem = startCallLogs.FirstOrDefault(e => e.ActionTime > currentEndTime);

                        if (null != startItem) //START DATE FOUND, USE IT FOR CALCULATION AND SEARCH FOR NEXT END DATE
                        {
                            currentStartTime = startItem.ActionTime;
                            lookingForStart = false;
                        }
                        else //NO START DATE THAT MATTERS TO THE LOGIC, END LOOP
                        {
                            break;
                        }
                    }
                    else //NO START DATE, END LOOP
                    {
                        break;
                    }
                }

                if (!lookingForStart)
                {
                    //SEEK HIGHEST END DATE BEFORE THE NEXT START CALL LOG
                    DPICallLogVO endItem = endCallLogs.FirstOrDefault(e => e.ActionTime >= currentStartTime);

                    if (null != endItem) //END DATE FOUND, USE IT FOR CALCULATION AND LOOK FOR NEXT START DATE
                    {
                        DPICallLogVO nextSupposedStartItem = startCallLogs.FirstOrDefault(e => e.ActionTime > endItem.ActionTime);

                        //SEE IF THERE'S ANOTHER END DATE, GREATER THAN THE FIRST
                        if (null != nextSupposedStartItem)
                        {
                            endItem = endCallLogs.LastOrDefault(e => e.ActionTime >= endItem.ActionTime && e.ActionTime < nextSupposedStartItem.ActionTime);
                        }
                        else //IF THERE IS ANY OTHER END DATE AND THERE ARE NO MORE START DATE
                        {
                            endItem = endCallLogs.LastOrDefault(e => e.ActionTime >= endItem.ActionTime);
                        }

                        currentEndTime = endItem.ActionTime;
                        lookingForStart = true;
                    }
                    else //NO END DATE CALL LOG FOUND, CALCULATE USING CURRENT TIME AND END LOOP
                    {
                        if (calculationDate.Date == DateTime.Now.Date && currentStartTime <= DateTime.Now)
                        {
                            currentEndTime = DateTime.Now;
                        }
                        else
                        {
                            currentEndTime = endOfDay;
                        }

                        insf = true;
                    }

                    //SAVE START DATE FOR CALCULATING CONTINUING HOURS
                    lastStartTime = currentStartTime;
                    lastTotalHours = totalHours;
                }

                totalHours += currentEndTime.Subtract(currentStartTime).TotalHours;

            } while (lookingForStart);

            currentDPIResource.Hours = Math.Round(Convert.ToDecimal(totalHours), 2);

            if (!lastStartTime.Equals(new DateTime()))
                currentDPIResource.ContinuingHours = Math.Round(Convert.ToDecimal(lastTotalHours + (endOfDay.Subtract(lastStartTime).TotalHours)), 2);

            if (insf)
                currentDPIResource.CalculationStatus = (int)Globals.DPI.CalculationStatus.INSF;
            else
                currentDPIResource.CalculationStatus = (int)Globals.DPI.CalculationStatus.Done;

            //SIMULATE RATE
            Random rnd = new Random();
            rate = rnd.Next(1, 3) * 100;

            currentDPIResource.Rate = Convert.ToDecimal(rate);

            return currentDPIResource;
        }
Esempio n. 7
0
        private CS_DPIResource CreateAutomaticDPIObject(CS_DPI dpi, CS_Resource resource, DateTime calculationDate)
        {
            CS_DPIResource dpiResource = new CS_DPIResource();
            dpiResource.DPIID = dpi.ID;

            if (resource.EquipmentID.HasValue)
            {
                dpiResource.EquipmentID = resource.EquipmentID;

                if (resource.CS_Equipment.Seasonal && resource.CS_Equipment.ComboID.HasValue && resource.CS_Equipment.ID != resource.CS_Equipment.CS_EquipmentCombo.PrimaryEquipmentID && resource.CS_Equipment.DivisionID != resource.CS_Equipment.CS_EquipmentCombo.CS_Equipment_PrimaryEquipment.DivisionID)
                    dpiResource.DivisionID = resource.CS_Equipment.CS_EquipmentCombo.CS_Equipment_PrimaryEquipment.DivisionID;
                else
                    dpiResource.DivisionID = resource.CS_Equipment.DivisionID;
            }

            if (resource.EmployeeID.HasValue)
            {
                dpiResource.EmployeeID = resource.EmployeeID;
                dpiResource.DivisionID = resource.CS_Employee.DivisionID;
            }

            dpiResource.CalculationStatus = dpi.CalculationStatus;
            dpiResource.Hours = 0;
            dpiResource.IsContinuing = false;
            dpiResource.Rate = 0;
            dpiResource.HasHotel = false;
            dpiResource.Total = 0;
            dpiResource.CreatedBy = "System";
            dpiResource.CreationDate = calculationDate;
            dpiResource.ModifiedBy = "System";
            dpiResource.ModificationDate = calculationDate;
            dpiResource.Active = true;
            return dpiResource;
        }