public void ShouldAddPrefixToJobNumberWhenVisualizing()
        {
            //Arrange
            CS_Job newJob = new CS_Job()
            {
                ID = 1,
                Number = "000014",
                CS_JobInfo = new CS_JobInfo()
                {
                    //The JobStatusId=1 determine this is a job number case (not Internal tracking)
                    CS_Job_JobStatus = new System.Data.Objects.DataClasses.EntityCollection<CS_Job_JobStatus>() { new CS_Job_JobStatus() { ID = 1, JobID =1, JobStatusId = 1, Active = true } },
                    CS_PriceType = new CS_PriceType() { ID = 2, Acronym = "A" },
                    CS_JobType = new CS_JobType() { ID = 3, Description = "Z" }
                }
            };

            //Act
            string numberPrefixed = newJob.PrefixedNumber;

            //Assert
            Assert.AreEqual("AZ000014", numberPrefixed);
        }
        public void ShouldReturnEmptyPrefixWhenInternalTrackingIsNotProvided()
        {
            //Arrange
            CS_Job newJob = new CS_Job()
            {
                ID = 1,
                Internal_Tracking = "",
                CS_JobInfo = new CS_JobInfo()
                {
                    //The JobStatusID=2 determine this is a Internal tracking case (not job number)
                    CS_Job_JobStatus = new System.Data.Objects.DataClasses.EntityCollection<CS_Job_JobStatus>() { new CS_Job_JobStatus(){ ID = 1, JobID = 1, JobStatusId = 2, Active = true} },
                    CS_PriceType = new CS_PriceType() { ID = 2, Acronym = "B" },
                    CS_JobType = new CS_JobType() { ID = 3, Description = "Y" }
                }
            };

            //Act
            string numberPrefixed = newJob.PrefixedNumber;

            //Assert
            Assert.AreEqual(string.Empty, numberPrefixed);
        }
        public void ShouldAddPrefixToInternalTrackingWhenVisualizing()
        {
            //Arrange
            CS_Job newJob = new CS_Job()
            {
                ID = 1,
                Internal_Tracking = "000000001INT",
                CS_JobInfo = new CS_JobInfo()
                {
                    //The JobStatusID=2 determine this is a Internal tracking case (not job number)
                    CS_Job_JobStatus = new System.Data.Objects.DataClasses.EntityCollection<CS_Job_JobStatus>() { new CS_Job_JobStatus() { ID = 1, JobID = 1, JobStatusId = 2, Active = true } },
                    CS_PriceType = new CS_PriceType() { ID = 2, Acronym = "B" },
                    CS_JobType = new CS_JobType() { ID = 3, Description = "Y" }
                }
            };

            //Act
            string numberPrefixed = newJob.PrefixedNumber;

            //Assert
            Assert.AreEqual("BY000000001INT", numberPrefixed);
        }
        /// <summary>
        /// Generates the Subject for the email that needs to be sent by the Call Criteria Process
        /// </summary>
        /// <param name="job">Job Details</param>
        /// <param name="jobInfo">Job Info Details</param>
        /// <param name="customerInfo">Customer Info Details</param>
        /// <param name="locationInfo">Location Info Details</param>
        /// <param name="callType">Call Type</param>
        /// <returns>Email Subject</returns>
        public string GenerateSubjectForCallCriteria(CS_Job job, CS_JobInfo jobInfo, CS_CustomerInfo customerInfo, CS_LocationInfo locationInfo, string callType)
        {
            string subject = string.Empty;

            if (job.ID == Globals.GeneralLog.ID)
                subject = string.Format("{0} - General Log - {1}", job.Number, callType);
            else
            {
                if (null != job)
                    subject = string.Format("{0}, {1}, {2}, {3} {4}, {5}",
                        job.PrefixedNumber,
                        customerInfo.CS_Customer.Name.Trim(),
                        jobInfo.CS_JobAction.Description,
                        locationInfo.CS_City.Name,
                        locationInfo.CS_State.Acronym,
                        callType);
            }

            return subject;
        }
        public void SetCallLogViewCallEntryRowData()
        {
            //Arrange
            FakeObjectSet<CS_FirstAlert> fakeFirstAlert = new FakeObjectSet<CS_FirstAlert>();

            CS_FirstAlertType csFirstAlertType = new CS_FirstAlertType()
            {
                Active = true,
                Description = "injury",
                CreatedBy = "dcecilia",
                CreationDate = new DateTime(10, 10, 10, 5, 0, 1),
                ModifiedBy = "dcecilia",
                ModificationDate = new DateTime(10, 10, 10, 5, 0, 1),

            };

            CS_FirstAlertFirstAlertType csFirstAlertFirstAlertType = new CS_FirstAlertFirstAlertType()
            {
                Active = true,
                FirstAlertID = 1,
                FirstAlertTypeID = 1,
                CreatedBy = "dcecilia",
                CreationDate =
                    new DateTime(10, 10, 10, 5, 0, 1),
                ModifiedBy = "dcecilia",
                ModificationDate =
                    new DateTime(10, 10, 10, 5, 0, 1),
                CS_FirstAlertType = csFirstAlertType
            };

            EntityCollection<CS_FirstAlertFirstAlertType> entityCollectionFirstAlertFirstAlertType = new EntityCollection<CS_FirstAlertFirstAlertType>();
            entityCollectionFirstAlertFirstAlertType.Add(csFirstAlertFirstAlertType);

            DateTime currentDate = DateTime.Now;

            CS_Customer csCustomer = new CS_Customer()
                                         {
                                             ID = 1,
                                             Active = true,
                                             Name = "Abcd",
                                             Country = "USA",
                                             CustomerNumber = "1000"
                                         };

            CS_Job csJob = new CS_Job()
                               {
                                   ID = 1,
                                   Active = true,
                                   CreatedBy = "dcecilia",
                                   CreationDate = currentDate,
                                   ModifiedBy = "dcecilia",
                                   ModificationDate = currentDate,
                                   Number = "123"
                               };

            CS_FirstAlert csFirstAlert = new CS_FirstAlert()
                                             {
                                                 ID = 1,
                                                 Active = true,
                                                 Number = "123",
                                                 JobID = 1,
                                                 CS_Job = csJob,
                                                 CustomerID = 1,
                                                 CS_Customer = csCustomer,

                                                 Details = "aaAaA",
                                                 Date = currentDate,
                                                 HasPoliceReport = true,
                                                 CreatedBy = "dcecilia",
                                                 CreationDate = currentDate,
                                                 ModifiedBy = "dcecilia",
                                                 ModificationDate = new DateTime(2011, 7, 12, 5, 0, 0),
                                                 CS_FirstAlertFirstAlertType = entityCollectionFirstAlertFirstAlertType,
                                             };

            CS_Division csDivision = new CS_Division()
            {
                Active = true,
                ID = 1,
                Name = "001"
            };

            CS_FirstAlertDivision csFirstAlertDivision = new CS_FirstAlertDivision()
            {
                Active = true,
                ID = 1,
                FirstAlertID = 1,
                DivisionID = 1,
                CS_Division = csDivision,
                CS_FirstAlert = csFirstAlert
            };

            Mock<IFirstAlertView> mock = new Mock<IFirstAlertView>();
            mock.SetupProperty(c => c.FirstAlertRowDataItem, csFirstAlert);
            mock.SetupProperty(c => c.FirstAlertRowAlertDateAndTime, "");
            mock.SetupProperty(c => c.FirstAlertRowAlertId, "");
            mock.SetupProperty(c => c.FirstAlertRowAlertNumber, "");
            mock.SetupProperty(c => c.FirstAlertRowCustomer, "");
            mock.SetupProperty(c => c.FirstAlertRowDivision, "");
            mock.SetupProperty(c => c.FirstAlertRowFirstAlertType, "");
            mock.SetupProperty(c => c.FirstAlertRowJobNumber, "");

               //Act
            FirstAlertViewModel viewModel = new FirstAlertViewModel(mock.Object);

            viewModel.SetDetailedFirstAlertRowData();

            // Assert
            Assert.AreEqual(currentDate.ToString("MM/dd/yyyy") + " " + currentDate.ToShortTimeString(), mock.Object.FirstAlertRowAlertDateAndTime, "Failed in FirstAlertRowAlertDateAndTime");
            Assert.AreEqual("1", mock.Object.FirstAlertRowAlertId, "Failed in FirstAlertRowAlertId");
            Assert.AreEqual("123", mock.Object.FirstAlertRowAlertNumber, "Failed in FirstAlertRowAlertNumber");
            Assert.AreEqual("Abcd - USA - 1000", mock.Object.FirstAlertRowCustomer, "Failed in FirstAlertRowCustomer");
            Assert.AreEqual("001", mock.Object.FirstAlertRowDivision, "Failed in FirstAlertRowDivision");
            Assert.AreEqual("injury", mock.Object.FirstAlertRowFirstAlertType, "Failed in FirstAlertRowFirstAlertType");
            Assert.AreEqual("123", mock.Object.FirstAlertRowJobNumber, "Failed in FirstAlertRowJobNumber");
        }
        /// <summary>
        /// Create the Lapsed Preset Call Entry
        /// </summary>
        /// <param name="job"></param>
        public void SavelapsedPreset(CS_Job job)
        {
            try
            {
                CS_CallLog newCallEntry = new CS_CallLog();
                newCallEntry.JobID = job.ID;
                newCallEntry.CallTypeID = (int)Globals.CallEntry.CallType.LapsedPreset;
                newCallEntry.PrimaryCallTypeId = (int)Globals.CallEntry.PrimaryCallType.JobUpdateNotification;
                newCallEntry.CallDate = DateTime.Now;
                DateTimeOffset dateTimeOffset = DateTimeOffset.Now;
                newCallEntry.Xml = null;
                newCallEntry.Note = BuildlapsedPresetNote(job);
                newCallEntry.CreatedBy = "System";
                newCallEntry.CreationDate = DateTime.Now;
                newCallEntry.ModifiedBy = "System";
                newCallEntry.ModificationDate = DateTime.Now;
                newCallEntry.Active = true;
                newCallEntry.UserCall = true;

                _callLogRepository.Add(newCallEntry);
            }
            catch (Exception ex)
            {
                throw new Exception("There was an error while trying to save a new call entry of type Lapsed Preset.", ex);
            }
        }
        public void TestFilterContactByCriteriaValuePriceTypeNoCriteria()
        {
            FakeObjectSet<CS_CallCriteriaValue> fakecallcriteriavalues = new FakeObjectSet<CS_CallCriteriaValue>();

            fakecallcriteriavalues.AddObject
                    (
                        new CS_CallCriteriaValue()
                        {
                            Active = true,
                            CallCriteriaID = 1,
                            CallCriteriaTypeID = (int)Globals.CallCriteria.CallCriteriaType.PriceType,
                            Value = ((int)Globals.JobRecord.PriceType.PublishedRates).ToString(),
                            CS_CallCriteria = new CS_CallCriteria()
                            {
                                ContactID = 2,
                                ID = 1,
                                Active = true
                            }
                        }
                    );

            IList<CS_Contact> lstContactBase = new List<CS_Contact>
            {
                new CS_Contact()
                {
                    ID = 1,
                    CS_CallCriteria = new EntityCollection<CS_CallCriteria>()
                    {
                        new CS_CallCriteria()
                        {
                            ContactID = 1,
                            ID = 1,
                            Active = true,
                            CS_CallCriteriaValue = new EntityCollection<CS_CallCriteriaValue>()
                            {
                                new CS_CallCriteriaValue()
                                {
                                    Active = true,
                                    CallCriteriaID = 1,
                                    CallCriteriaTypeID = (int)Globals.CallCriteria.CallCriteriaType.Customer,
                                    Value = "1090"
                                },
                                new CS_CallCriteriaValue()
                                {
                                    Active = true,
                                    CallCriteriaID = 1,
                                    CallCriteriaTypeID = (int)Globals.CallCriteria.CallCriteriaType.Division,
                                    Value = "1"
                                }
                            }
                        }
                    }
                }
            };

            IList<CS_Contact> lstContact = lstContactBase;

            CS_Job job = new CS_Job()
            {
                ID = 1,
                CS_JobInfo = new CS_JobInfo() { JobID = 1, PriceTypeID = (int)Globals.JobRecord.PriceType.PublishedRates },
                CS_JobDivision = new EntityCollection<CS_JobDivision>() { new CS_JobDivision() { JobID = 1, DivisionID = 1 } },
                CS_CustomerInfo = new CS_CustomerInfo() { JobId = 1, CustomerId = 1090 },
                CS_LocationInfo = new CS_LocationInfo(),
                CS_JobDescription = new CS_JobDescription()
            };

            Mock<IUnitOfWork> mockUnitOfWork = new Mock<IUnitOfWork>();
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_CallCriteriaValue>()).Returns(fakecallcriteriavalues);
            CallCriteriaModel model = new CallCriteriaModel(mockUnitOfWork.Object);

            lstContact = model.FilterContactsByCriteriaValue(lstContactBase, job);

            Assert.AreEqual(1, lstContact.Count);
        }
        public void Initialize()
        {
            // Step 1 - Clear Tables
            JobInfoDao.Singleton.ClearAll();
            ResourceDao.Singleton.ClearAll();
            EmployeeDao.Singleton.ClearAll();

            // Step 2 - Adding controlled data
            country = CountryDao.Singleton.Add(
                new CS_Country()
                {
                    Active = true,
                    Name = "USA",
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });

            state = StateDao.Singleton.Add(
                new CS_State()
                {
                    Active = true,
                    Acronym = "TX",
                    Name = "Texas",
                    CountryID = country.ID,
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });

            division = DivisionDao.Singleton.Add(
                new CS_Division()
                {
                    Active = true,
                    CountryID = country.ID,
                    Description = "DIV1",
                    StateID = state.ID,
                    Name = "001",
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });

            employee1 = EmployeeDao.Singleton.Add(
                new CS_Employee()
                {
                    Active = true,
                    FirstName = "a",
                    Name = "b",
                    DivisionID = division.ID,
                    BusinessCardTitle = "Laborer",
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });
            employee2 = EmployeeDao.Singleton.Add(
                new CS_Employee()
                {
                    Active = true,
                    FirstName = "c",
                    Name = "d",
                    DivisionID = division.ID,
                    BusinessCardTitle = "Regional Vice President",
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });

            jobStatus = JobStatusDao.Singleton.Add(
                new CS_JobStatus()
                {
                    Active = true,
                    Description = "Active",
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });
            priceType = PriceTypeDao.Singleton.Add(
                new CS_PriceType()
                {
                    Active = true,
                    Acronym = "X",
                    Description = "X",
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });
            jobCategory = JobCategoryDao.Singleton.Add(
                new CS_JobCategory()
                {
                    Active = true,
                    Description = "X",
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });
            jobType = JobTypeDao.Singleton.Add(
                new CS_JobType()
                {
                    Active = true,
                    Description = "X",
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });
            jobAction = JobActionDao.Singleton.Add(
                new CS_JobAction()
                {
                    Active = true,
                    Description = "X",
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });

            job = JobDao.Singleton.Add(
                new CS_Job()
                {
                    Active = true,
                    Number = "000001",
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });
            jobInfo = JobInfoDao.Singleton.Add(
                new CS_JobInfo()
                {
                    Active = true,
                    JobID = job.ID,
                    JobStatusID = jobStatus.ID,
                    PriceTypeID = priceType.ID,
                    JobCategoryID = jobCategory.ID,
                    JobTypeID = jobType.ID,
                    JobActionID = jobAction.ID,
                    InitialCallDate = DateTime.Now,
                    InitialCallTime = new TimeSpan(0, 1, 10, 0, 0),
                    InterimBill = false,
                    ProjectManager = employee2.ID,
                    EmployeeID = employee2.ID,
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });

            resource = ResourceDao.Singleton.Add(
                new CS_Resource()
                {
                    Active = true,
                    EmployeeID = employee1.ID,
                    JobID = job.ID,
                    CreatedBy = "Load",
                    CreationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    ModificationDate = DateTime.Now
                });
        }
        public void TestIfSubjectIsCorrectForGeneralLog()
        {
            // Arrange
            CS_Job job = new CS_Job()
            {
                ID = 1,
                Number = "99999",
                Active = true
            };
            string callType = "Call Type Description";

            // Act
            CallCriteriaModel model = new CallCriteriaModel();
            string result = model.GenerateSubjectForCallCriteria(job, null, null, null, callType);

            // Assert
            string expectedResult = "99999 - General Log - Call Type Description";
            Assert.AreEqual(expectedResult, result);
        }
        public void TestListEmployeeCriteriaByDivisionAndCustomer()
        {
            FakeObjectSet<CS_Employee> fakeemployee = new FakeObjectSet<CS_Employee>();
            fakeemployee.AddObject(
                new CS_Employee()
                {
                    ID = 1,
                    CS_CallCriteria = new EntityCollection<CS_CallCriteria>()
                    {
                        new CS_CallCriteria()
                        {
                            EmployeeID = 1,
                            ID = 1,
                            Active = true,
                            CS_CallCriteriaValue = new EntityCollection<CS_CallCriteriaValue>()
                            {
                                new CS_CallCriteriaValue()
                                {
                                    Active = true,
                                    CallCriteriaID = 1,
                                    CallCriteriaTypeID = 1,
                                    Value = "1090"
                                },
                                new CS_CallCriteriaValue()
                                {
                                    Active = true,
                                    CallCriteriaID = 1,
                                    CallCriteriaTypeID = 2,
                                    Value = "1"
                                }
                            }
                        }
                    }
                });

            CS_Job job = new CS_Job()
            {
                ID = 3,
                CS_JobDivision = new EntityCollection<CS_JobDivision>() { new CS_JobDivision() { JobID = 3, DivisionID = 1 } },
                CS_CustomerInfo = new CS_CustomerInfo() { JobId = 3, CustomerId = 1090 }
            };

            Mock<IUnitOfWork> mockUnitOfWork = new Mock<IUnitOfWork>();
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_Employee>()).Returns(fakeemployee);
            CallCriteriaModel model = new CallCriteriaModel(mockUnitOfWork.Object);

            IList<CS_Employee> lstEmployee = model.ListEmployeeCriteriaByDivisionAndCustomer(job);

            Assert.AreEqual(1, lstEmployee.Count);
        }
        public void TestIfSubjectIsCorrect()
        {
            // Arrange
            CS_JobInfo jobInfo = new CS_JobInfo()
            {
                JobID = 2,
                CS_Job_JobStatus = new EntityCollection<CS_Job_JobStatus>() { new CS_Job_JobStatus() { ID = 1, JobID = 2, JobStatusId = 1, Active = true } },
                CS_PriceType = new CS_PriceType() { ID = 1, Acronym = "P", Active = true },
                CS_JobType = new CS_JobType() { ID = 1, Description = "C", Active = true },
                CS_JobAction = new CS_JobAction() { ID = 1, Description = "Action", Active = true }
            };
            CS_Job job = new CS_Job()
            {
                ID = 2, Number = "000001", Active = true,
                CS_JobInfo = jobInfo
            };
            CS_CustomerInfo customerInfo = new CS_CustomerInfo()
            {
                JobId = 2,
                CS_Customer = new CS_Customer() { ID = 1, Name = "Customer Name", Active = true }
            };
            CS_LocationInfo locationInfo = new CS_LocationInfo()
            {
                JobID = 2,
                CS_City = new CS_City() { ID = 1, Name = "City", Active = true },
                CS_State = new CS_State() { ID = 1, Acronym = "ST", Active = true }
            };
            string callType = "Call Type Description";

            // Act
            CallCriteriaModel model = new CallCriteriaModel();
            string result = model.GenerateSubjectForCallCriteria(job, jobInfo, customerInfo, locationInfo, callType);

            // Assert
            string expectedResult = "PC000001, Customer Name, Action, City ST, Call Type Description";
            Assert.AreEqual(expectedResult, result);
        }
        public IList<EmailVO> ListReceiptsByCallLog(string callLogTypeId, int jobId, CS_CallLog callLog, out List<int> callCriteriaIDs)
        {
            CS_Job job = new CS_Job();
            IList<CS_Employee> lstEmployee = new List<CS_Employee>();
            List<CS_Employee> lstEmployeeAux = new List<CS_Employee>();
            IList<CS_Contact> lstContacts = new List<CS_Contact>();
            IList<EmailVO> lstEmail = new List<EmailVO>();

            string emailDomain = string.Empty;

            SettingsModel model = new SettingsModel(_unitOfWork);
            emailDomain = model.GetDomain();

            CS_CallCriteriaRepository _rep = new CS_CallCriteriaRepository(_callCriteriaRepository, _callCriteriaRepository.UnitOfWork);

            int callLogID = 0;

            if (callLog != null)
                callLogID = callLog.ID;

            IList<CS_SP_CheckCallCriteria_Result> callCriteriaResult = _rep.CheckCallCriteria(callLogID, int.Parse(callLogTypeId), jobId);

            IList<int> result = new List<int>();

            for (int i = 0; i < callCriteriaResult.Count; i++)
            {
                result.Add(callCriteriaResult[i].CallCriteriaID.Value);
            }

            callCriteriaIDs = result.ToList();

            lstEmployee = _employeeRepository.ListAll(e => e.CS_CallCriteria.Any(f => result.Contains(f.ID) && f.Active)).ToList();

            lstContacts = _contactRepository.ListAll(e => e.CS_CallCriteria.Any(f => result.Contains(f.ID) && f.Active)).ToList();

            //OLD METHOD
            //job = _jobRepository.Get(e => e.ID == jobId, new string[] { "CS_JobDivision", "CS_CustomerInfo", "CS_JobInfo", "CS_LocationInfo", "CS_JobDescription" });

            //lstEmployee = ListEmployeeCriteriaByDivisionAndCustomer(job);

            //if (!job.ID.Equals(Globals.GeneralLog.ID))
            //    lstEmployeeAux = FilterEmployeeByCriteriaValue(lstEmployee, job).ToList();

            //if (null != callLog)
            //    lstEmployeeAux.AddRange(VerifyHeavyEquipmentCallCriteria(lstEmployee.ToList(), callLog));

            //lstEmployee = lstEmployeeAux.Distinct().ToList();

            //lstEmployee = ListEmployeeByCallLogCriteria(callLogTypeId, lstEmployee.ToList());

            //for (int i = 0; i < lstEmployee.Count; i++)
            //{

            //    CS_EmployeeOffCallHistory offCall = GetActiveOffCallByEmployeeID(lstEmployee[i].ID);

            //    if (null != offCall)
            //        lstEmployee[i] = offCall.CS_Employee_Proxy;
            //}

            //lstContacts = ListContactsCriteriaByDivisionAndCustomer(job);

            //if (!job.ID.Equals(Globals.GeneralLog.ID))
            //    lstContacts = FilterContactsByCriteriaValue(lstContacts, job);

            //lstContacts = ListCustomerContactByCallLogCriteria(callLogTypeId, lstContacts.ToList());

            //if (null != callLog)
            //    lstContacts = VerifyHeavyEquipmentCallCriteria(lstContacts.ToList(), callLog);

            for (int i = 0; i < lstEmployee.Count; i++)
            {
                if (!string.IsNullOrEmpty(lstEmployee[i].GetEmployeeEmail(emailDomain)))
                {
                    EmailVO email = new EmailVO();
                    email.PersonID = lstEmployee[i].ID;
                    email.Name = lstEmployee[i].FullName;
                    email.Email = lstEmployee[i].GetEmployeeEmail(emailDomain);
                    email.Type = (int)Globals.CallCriteria.EmailVOType.Employee;

                    if (!lstEmail.Contains(email, new Globals.EmailService.EmailVO_Comparer()))
                        lstEmail.Add(email);
                }
            }

            for (int i = 0; i < lstContacts.Count; i++)
            {
                if (!string.IsNullOrEmpty(lstContacts[i].Email))
                {
                    EmailVO email = new EmailVO();
                    email.PersonID = lstContacts[i].ID;
                    email.Name = lstContacts[i].FullName;
                    email.Email = lstContacts[i].Email;
                    email.Type = (int)Globals.CallCriteria.EmailVOType.Contact;

                    if (!lstEmail.Contains(email, new Globals.EmailService.EmailVO_Comparer()))
                        lstEmail.Add(email);
                }
            }

            return lstEmail;
        }
        /// <summary>
        /// Returns a list of employees that matches division and customer criterias
        /// </summary>
        /// <param name="job">Criteria Job</param>
        /// <returns>List of CS_Employee entities</returns>
        public IList<CS_Employee> ListEmployeeCriteriaByDivisionAndCustomer(CS_Job job)
        {
            if (job.ID.Equals(Globals.GeneralLog.ID))
            {
                return _employeeRepository.ListAll(
                    e => e.Active &&
                         e.CS_CallCriteria.Any(
                            f => f.Active &&
                                 f.EmployeeID.HasValue &&
                                 f.EmployeeID == e.ID &&
                                 f.CS_CallCriteriaValue.Any(
                                    z => z.Active &&
                                         z.CallCriteriaID == f.ID &&
                                         z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.GeneralLog
                                    )
                            )
                    , new string[] { "CS_CallCriteria.CS_CallCriteriaValue" });
            }
            else
            {
                List<string> divisionIdList = new List<string>();
                foreach (CS_JobDivision jobDivision in job.CS_JobDivision)
                    divisionIdList.Add(jobDivision.DivisionID.ToString());
                string customerId = job.CS_CustomerInfo.CustomerId.ToString();

                return _employeeRepository.ListAll
                    (
                    e =>
                        (
                            e.CS_CallCriteria.Any
                            (
                            f =>
                                f.Active
                                && f.EmployeeID.HasValue
                                && f.EmployeeID == e.ID
                                &&
                                (
                                    (

                                        f.CS_CallCriteriaValue.Any
                                        (
                                        z =>
                                            z.Active
                                            && z.CallCriteriaID == f.ID
                                            && z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.Division
                                            && divisionIdList.Contains(z.Value)
                                        )
                                        &&
                                        f.CS_CallCriteriaValue.Any
                                        (
                                        z =>
                                            z.Active
                                            && z.CallCriteriaID == f.ID
                                            && z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.Customer
                                            && z.Value == customerId
                                        )
                                    )
                                    ||
                                    (
                                        f.CS_CallCriteriaValue.Any
                                        (
                                        z =>
                                            z.Active
                                            && z.CallCriteriaID == f.ID
                                            && z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.Division
                                            && divisionIdList.Contains(z.Value)
                                        )
                                        &&
                                        !f.CS_CallCriteriaValue.Any
                                        (
                                        z =>
                                            z.Active
                                            && z.CallCriteriaID == f.ID
                                            && z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.Customer
                                        )
                                    )
                                    ||
                                    (
                                        !f.CS_CallCriteriaValue.Any
                                        (
                                        z =>
                                            z.Active
                                            && z.CallCriteriaID == f.ID
                                            && z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.Division
                                        )
                                        &&
                                        f.CS_CallCriteriaValue.Any
                                        (
                                        z =>
                                            z.Active
                                            && z.CallCriteriaID == f.ID
                                            && z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.Customer
                                            && z.Value == customerId
                                        )
                                    )
                                )
                            )
                        )
                    , new string[] { "CS_CallCriteria.CS_CallCriteriaValue" });
            }
        }
        public void ShouldReturnEmptyPrefixWhenJobInfoAndNumberAreNotProvided()
        {
            //Arrange
            CS_Job newJob = new CS_Job()
            {
                ID = 1,
            };

            //Act
            string numberPrefixed = newJob.PrefixedNumber;

            //Assert
            Assert.AreEqual(string.Empty, numberPrefixed);
        }
        public void TestFilterEmployeeByCriteriaValueJobCategory()
        {
            FakeObjectSet<CS_CallCriteriaValue> fakecallcriteriavalues = new FakeObjectSet<CS_CallCriteriaValue>();

            fakecallcriteriavalues.AddObject
                    (
                        new CS_CallCriteriaValue()
                        {
                            Active = true,
                            CallCriteriaID = 1,
                            CallCriteriaTypeID = (int)Globals.CallCriteria.CallCriteriaType.JobCategory,
                            Value = (4).ToString(),
                            CS_CallCriteria = new CS_CallCriteria()
                            {
                                EmployeeID = 1,
                                ID = 1,
                                Active = true
                            }
                        }
                    );

            IList<CS_Employee> lstEmployeeBase = new List<CS_Employee>
            {
                new CS_Employee()
                {
                    ID = 1,
                    CS_CallCriteria = new EntityCollection<CS_CallCriteria>()
                    {
                        new CS_CallCriteria()
                        {
                            EmployeeID = 1,
                            ID = 1,
                            Active = true,
                            CS_CallCriteriaValue = new EntityCollection<CS_CallCriteriaValue>()
                            {
                                new CS_CallCriteriaValue()
                                {
                                    Active = true,
                                    CallCriteriaID = 1,
                                    CallCriteriaTypeID = (int)Globals.CallCriteria.CallCriteriaType.Customer,
                                    Value = "1090"
                                },
                                new CS_CallCriteriaValue()
                                {
                                    Active = true,
                                    CallCriteriaID = 1,
                                    CallCriteriaTypeID = (int)Globals.CallCriteria.CallCriteriaType.Division,
                                    Value = "1"
                                }
                            }
                        }
                    }
                }
            };

            IList<CS_Employee> lstEmployee = lstEmployeeBase;

            CS_Job job = new CS_Job()
            {
                ID = 1,
                CS_JobInfo = new CS_JobInfo() { JobID = 1, JobCategoryID = 4 },
                CS_JobDivision = new EntityCollection<CS_JobDivision>() { new CS_JobDivision() { JobID = 1, DivisionID = 1 } },
                CS_CustomerInfo = new CS_CustomerInfo() { JobId = 1, CustomerId = 1090 },
                CS_LocationInfo = new CS_LocationInfo(),
                CS_JobDescription = new CS_JobDescription()
            };

            Mock<IUnitOfWork> mockUnitOfWork = new Mock<IUnitOfWork>();
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_CallCriteriaValue>()).Returns(fakecallcriteriavalues);
            CallCriteriaModel model = new CallCriteriaModel(mockUnitOfWork.Object);

            lstEmployee = model.FilterEmployeeByCriteriaValue(lstEmployeeBase, job);

            Assert.AreEqual(1, lstEmployee.Count);
        }
        public void SaveJobData()
        {
            if ((_view.InitialCallDate.Date + _view.InitialCallTime) > DateTime.Now)
            {
                _view.DisplayMessage("Initial Call Date can not be greater than today.", false);
                _view.SavedSuccessfuly = false;
                return;
            }

            // CS_Job
            CS_Job csJob = new CS_Job();

            csJob.CreatedBy = _view.Username;
            csJob.CreationDate = DateTime.Now;
            csJob.ModifiedBy = _view.Username;
            csJob.ModificationDate = DateTime.Now;
            csJob.Active = true;
            csJob.EmergencyResponse = _view.IsEmergencyResponse;

            _jobModel.NewJob = csJob;

            // Validations for Hulcher Contact and Division
            //int? calledInByContactId = null;
            //if (_view.PrimaryContactId != null && _view.HulcherContactId != null)
            //{
            //    //calledInByContactId = _view.PrimaryContactId;
            //    _view.PrimaryContactId = null;
            //}
            int? hulcherDivision = null;
            if (_view.HulcherContactId.HasValue)
                hulcherDivision = _view.PrimaryDivisionId;

            // CS_CustomerInfo
            CS_CustomerInfo customerInfo = new CS_CustomerInfo()
            {
                Active = true,
                InitialCustomerContactId = _view.PrimaryContactId,
                CustomerId = _view.CustomerId,
                PocEmployeeId = _view.HulcherContactId,
                DivisionId = hulcherDivision,
                CreatedBy = _view.Username,
                CreationDate = DateTime.Now,
                ModifiedBy = _view.Username,
                ModificationDate = DateTime.Now
            };
            _jobModel.NewCustomer = customerInfo;

            // CS_JobDivision
            IList<CS_JobDivision> jobDivisionList = new List<CS_JobDivision>();
            jobDivisionList.Add(new CS_JobDivision()
            {
                Active = true,
                CreatedBy = _view.Username,
                CreationDate = DateTime.Now,
                DivisionID = _view.PrimaryDivisionId,
                IsFromCustomerInfo = hulcherDivision.HasValue,
                ModificationDate = DateTime.Now,
                ModifiedBy = _view.Username,
                PrimaryDivision = true
            });
            _jobModel.NewJobDivision = jobDivisionList;

            // CS_JobInfo
            CS_JobCategory jobCategory = _jobModel.GetJobCategoryByJobAction(_view.JobActionId);
            CS_JobType jobType = _jobModel.GetJobTypeByJobAction(_view.JobActionId);
            DateTime? startDate = null;
            DateTime? closedDate = null;
            if (_view.JobStatusId.Equals((int)Globals.JobRecord.JobStatus.Active))
                startDate = DateTime.Now;
            else if (_view.JobStatusId.Equals((int)Globals.JobRecord.JobStatus.Closed))
                closedDate = DateTime.Now;

            CS_JobInfo jobInfo = new CS_JobInfo()
            {
                Active = true,
                InitialCallDate = _view.InitialCallDate,
                InitialCallTime = _view.InitialCallTime,
                //JobStatusID = _view.JobStatusId,
                PriceTypeID = _view.PriceTypeId,
                JobActionID = _view.JobActionId,
                CreatedBy = _view.Username,
                CreationDate = DateTime.Now,
                ModifiedBy = _view.Username,
                ModificationDate = DateTime.Now,
                JobCategoryID = jobCategory.ID,
                JobTypeID = jobType.ID,
            };
            _jobModel.NewJobInfo = jobInfo;

            CS_Job_JobStatus jobStatus = new CS_Job_JobStatus()
            {
                Active = true,
                CreatedBy = _view.Username,
                CreationDate = DateTime.Now,
                ModifiedBy = _view.Username,
                ModificationDate = DateTime.Now,
                JobStatusId = _view.JobStatusId,
                JobStartDate = startDate,
                JobCloseDate = closedDate
            };

            _jobModel.NewJobStatusHistory = jobStatus;
            _jobModel.JobStatusID = _view.JobStatusId;

            if (_view.JobStatusId == (int)Globals.JobRecord.JobStatus.Active)
                _jobModel.NewJob.BillingStatus = (int)Globals.JobRecord.BillingStatus.Working;
            else if (_view.JobStatusId == (int)Globals.JobRecord.JobStatus.Closed || _view.JobStatusId == (int)Globals.JobRecord.JobStatus.Cancelled || _view.JobStatusId == (int)Globals.JobRecord.JobStatus.Lost)
                _jobModel.NewJob.BillingStatus = (int)Globals.JobRecord.BillingStatus.Done;
            else if (_view.JobStatusId == (int)Globals.JobRecord.JobStatus.Potential || _view.JobStatusId == (int)Globals.JobRecord.JobStatus.Preset || _view.JobStatusId == (int)Globals.JobRecord.JobStatus.PresetPurchase)
                _jobModel.NewJob.BillingStatus = (int)Globals.JobRecord.BillingStatus.Created;

            // CS_LocationInfo
            int countryId = _locationModel.GetCountryByStateId(_view.StateId);
            CS_LocationInfo locationInfo = new CS_LocationInfo()
            {
                Active = true,
                CountryID = countryId,
                StateID = _view.StateId,
                CityID = _view.CityId,
                ZipCodeId = _view.ZipCode,
                CreatedBy = _view.Username,
                CreationDate = DateTime.Now,
                ModifiedBy = _view.Username,
                ModificationDate = DateTime.Now
            };
            _jobModel.NewLocationInfo = locationInfo;

            // CS_ScopeOfWork
            IList<CS_ScopeOfWork> lstScopeOfWork = new List<CS_ScopeOfWork>();
            lstScopeOfWork.Add(new CS_ScopeOfWork()
            {
                Active = true,
                ScopeOfWork = _view.ScopeOfWork,
                CreatedBy = _view.Username,
                CreationDate = DateTime.Now,
                ModifiedBy = _view.Username,
                ModificationDate = DateTime.Now
            });
            _jobModel.NewScopeOfWork = lstScopeOfWork;

            // CS_JobDescription
            CS_JobDescription jobDescription = new CS_JobDescription()
            {
                Active = true,
                CreatedBy = _view.Username,
                CreationDate = DateTime.Now,
                ModifiedBy = _view.Username,
                ModificationDate = DateTime.Now
            };
            _jobModel.NewJobDescription = jobDescription;
            _jobModel.SaveJobData(false, null, true);
            _view.JobId = _jobModel.NewJob.ID;

            _view.SavedSuccessfuly = true;
        }
        public void ShouldReturnOnlyNumberWhenJobInfoIsNotProvided()
        {
            //Arrange
            CS_Job newJob = new CS_Job()
            {
                ID = 1,
                Number = "000014"
            };

            //Act
            string numberPrefixed = newJob.PrefixedNumber;

            //Assert
            Assert.AreEqual("000014", numberPrefixed);
        }
        public IList<CS_DPIResource> ProcessDPIResources(CS_DPI dpiEntity, CS_Job jobEntity, DateTime calculationDate)
        {
            List<CS_DPIResource> returnList = _dpiResourceRepository.ListAll(e => e.DPIID == dpiEntity.ID && e.Active).ToList();

            DateTime jobCallDate = jobEntity.CS_JobInfo.InitialCallDate + jobEntity.CS_JobInfo.InitialCallTime;

            for (int i = 0; i < returnList.Count; i++)
            {
                List<CS_CallLogResource> callLogs = new List<CS_CallLogResource>();
                int equipId = 0, emplId = 0;

                if (returnList[i].EquipmentID.HasValue)
                {
                    equipId = returnList[i].EquipmentID.Value;
                    callLogs = _callLogResourceRepository.ListAll(e => e.EquipmentID == equipId && e.JobID == jobEntity.ID && e.ModificationDate >= calculationDate.Date, "CS_CallLog", "CS_CallLog.CS_CallType").ToList();
                }
                else
                {
                    emplId = returnList[i].EmployeeID.Value;
                    callLogs = _callLogResourceRepository.ListAll(e => e.EmployeeID == emplId && e.JobID == jobEntity.ID && e.ModificationDate >= calculationDate.Date, "CS_CallLog", "CS_CallLog.CS_CallType").ToList();
                }

                //RETRIEVES LIST OF CALL LOGS THAT HAVE A 'START STATUS', TRANSFORM AND ORDER THEM BY DATE
                List<DPICallLogVO> startCallLogs = GetDPICallLogTimesFromList(callLogs.Where(e => e.CS_CallLog.CS_CallType.DpiStatus == (int)Globals.DPI.CallTypeDpiStatus.Start).ToList(), calculationDate);

                //RETRIEVES LIST OF CALL LOGS THAT HAVE A 'END STATUS', TRANSFORM AND ORDER THEM BY DATE
                List<DPICallLogVO> endCallLogs = GetDPICallLogTimesFromList(callLogs.Where(e => e.CS_CallLog.CS_CallType.DpiStatus == (int)Globals.DPI.CallTypeDpiStatus.End).ToList(), calculationDate);

                callLogs = null;

                returnList[i] = CalculateHoursForResouce(returnList[i], jobEntity.EmergencyResponse, jobCallDate, startCallLogs, endCallLogs, calculationDate);

                if (dpiEntity.ProcessStatus == (int)Globals.DPI.DpiStatus.Pending)
                {
                    returnList[i].Total = Convert.ToDecimal(returnList[i].Rate * returnList[i].Hours);
                }
            }

            return returnList;
        }
        public void ShouldReturnOnlyNumberWhenJobTypeIsNotProvided()
        {
            //Arrange
            CS_Job newJob = new CS_Job()
            {
                ID = 1,
                Number = "000014",
                CS_JobInfo = new CS_JobInfo()
                {
                    //The JobStatusID=1 determine this is a job number case (not Internal tracking)
                    CS_Job_JobStatus = new System.Data.Objects.DataClasses.EntityCollection<CS_Job_JobStatus>() {  new CS_Job_JobStatus() { ID=1, JobID=1,JobStatusId =1}},
                    CS_PriceType = new CS_PriceType() { ID = 2, Acronym = "A" }
                }
            };

            //Act
            string numberPrefixed = newJob.PrefixedNumber;

            //Assert
            Assert.AreEqual("000014", numberPrefixed);
        }
        public void TestIfTotalIsBeingCalculated()
        {
            // Arrange
            DateTime calculationDate = DateTime.Today;
            CS_DPI dpiEntry = new CS_DPI() { ID = 1, Active = true, ProcessStatus = (short)Globals.DPI.DpiStatus.Pending };
            CS_Job jobEntry = new CS_Job()
            {
                ID = 1,
                Active = true,
                EmergencyResponse = false,
                CS_JobInfo = new CS_JobInfo() { InitialCallDate = calculationDate, InitialCallTime = new TimeSpan(10, 0, 0), Active = true }
            };

            FakeObjectSet<CS_DPIResource> fakeDPIResource = new FakeObjectSet<CS_DPIResource>();
            fakeDPIResource.AddObject(new CS_DPIResource()
            {
                DPIID = dpiEntry.ID,
                CS_DPI = dpiEntry,
                EquipmentID = 1
            });
            fakeDPIResource.AddObject(new CS_DPIResource()
            {
                DPIID = dpiEntry.ID,
                CS_DPI = dpiEntry,
                EmployeeID = 1
            });

            FakeObjectSet<CS_CallLogResource> fakeCallLogResource = new FakeObjectSet<CS_CallLogResource>();
            fakeCallLogResource.AddObject(new CS_CallLogResource()
            {
                CS_CallLog = new CS_CallLog
                {
                    CS_CallType = new CS_CallType()
                    {
                        ID = 13,
                        IsAutomaticProcess = false,
                        DpiStatus = (int)Globals.DPI.CallTypeDpiStatus.Start,
                        Active = true
                    },
                    Xml = string.Format("<?xml version=\"1.0\" encoding=\"utf-8\"?><DynamicFieldsAggregator xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Controls><DynamicControls xsi:type=\"DynamicDatePickerXml\"><Name>dtpDate</Name><Label><Text>Work Date Continuing:</Text><Css>dynamicLabel</Css><Style /></Label><Css /><Style /><Visible>true</Visible><Text>{0}</Text><IsValidEmpty>false</IsValidEmpty><EmptyValueMessage>The Work Date Continuing field is required</EmptyValueMessage><InvalidValueMessage>Invalid Work Date Continuing format</InvalidValueMessage><DateTimeFormat>Default</DateTimeFormat><ShowOn>Both</ShowOn><ValidationGroup>CallEntry</ValidationGroup></DynamicControls><DynamicControls xsi:type=\"DynamicTimeXml\"><Name>txtTime</Name><Label><Text>Work Time Continuing:</Text><Css>dynamicLabel</Css><Style /></Label><Css>input</Css><Style /><Visible>true</Visible><Text>{1}</Text><Mask>99:99</Mask><MaskedType>Time</MaskedType><InputDirection>LeftToRight</InputDirection><IsValidEmpty>false</IsValidEmpty><ValidationGroup>CallEntry</ValidationGroup><InvalidValueMessage>The Work Time Continuing field is invalid</InvalidValueMessage><EmptyValueMessage>The Work Time Continuing field is required.</EmptyValueMessage></DynamicControls><DynamicControls xsi:type=\"DynamicCountableTextBoxXml\"><Name>txtNote</Name><Label><Text>Note:</Text><Css>dynamicLabel</Css><Style /></Label><Css>input</Css><Style /><Visible>true</Visible><MaxChars>255</MaxChars><MaxCharsWarning>250</MaxCharsWarning><Text>They're BACK!</Text><IsRequired>false</IsRequired><ErrorMessage /><ValidationGroup /><TextMode>MultiLine</TextMode><Width>300</Width><Height>150</Height></DynamicControls></Controls><Extenders /></DynamicFieldsAggregator>",
                        calculationDate.ToString("yyyy-MM-dd"), "10:00"),
                    CreationDate = new DateTime(calculationDate.Year, calculationDate.Month, calculationDate.Day, 10, 0, 0)
                },
                JobID = 1,
                CallLogID = 1,
                EquipmentID = 1,
                CreationDate = new DateTime(calculationDate.Year, calculationDate.Month, calculationDate.Day, 10, 0, 0)
            });
            fakeCallLogResource.AddObject(new CS_CallLogResource()
            {
                CS_CallLog = new CS_CallLog
                {
                    CS_CallType = new CS_CallType()
                    {
                        ID = 18,
                        IsAutomaticProcess = true,
                        DpiStatus = (int)Globals.DPI.CallTypeDpiStatus.End,
                        Active = true
                    },
                    Xml = string.Format("<?xml version=\"1.0\" encoding=\"utf-8\"?><DynamicFieldsAggregator xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Controls><DynamicControls xsi:type=\"DynamicDatePickerXml\"><Name>dtpDate</Name><Label><Text>Work Date Released:</Text><Css>dynamicLabel</Css><Style /></Label><Css /><Style /><Visible>true</Visible><Text>{0}</Text><IsValidEmpty>false</IsValidEmpty><EmptyValueMessage>The Work Date Released field is required</EmptyValueMessage><InvalidValueMessage>Invalid Work Date format</InvalidValueMessage><DateTimeFormat>Default</DateTimeFormat><ShowOn>Both</ShowOn><ValidationGroup>CallEntry</ValidationGroup></DynamicControls><DynamicControls xsi:type=\"DynamicTimeXml\"><Name>txtTime</Name><Label><Text>Work Time Released:</Text><Css>dynamicLabel</Css><Style /></Label><Css /><Style /><Visible>true</Visible><Text>{1}</Text><Mask>99:99</Mask><MaskedType>Time</MaskedType><InputDirection>LeftToRight</InputDirection><IsValidEmpty>false</IsValidEmpty><ValidationGroup>CallEntry</ValidationGroup><InvalidValueMessage>The Work Time Released Time field is invalid</InvalidValueMessage><EmptyValueMessage>The Work Time Released field is required.</EmptyValueMessage></DynamicControls><DynamicControls xsi:type=\"DynamicCountableTextBoxXml\"><Name>txtNote</Name><Label><Text>Note:</Text><Css>dynamicLabel</Css><Style /></Label><Css /><Style /><Visible>true</Visible><MaxChars>255</MaxChars><MaxCharsWarning>250</MaxCharsWarning><Text>They stopped working!</Text><IsRequired>false</IsRequired><ErrorMessage /><ValidationGroup /><TextMode>MultiLine</TextMode><Width>300</Width><Height>150</Height></DynamicControls></Controls><Extenders /></DynamicFieldsAggregator>",
                        calculationDate.ToString("yyyy-MM-dd"), "15:00"),
                    CreationDate = new DateTime(calculationDate.Year, calculationDate.Month, calculationDate.Day, 15, 0, 0)
                },
                JobID = 1,
                CallLogID = 2,
                EquipmentID = 1,
                CreationDate = new DateTime(calculationDate.Year, calculationDate.Month, calculationDate.Day, 15, 0, 0)
            });

            fakeCallLogResource.AddObject(new CS_CallLogResource()
            {
                CS_CallLog = new CS_CallLog
                {
                    CS_CallType = new CS_CallType()
                    {
                        ID = 13,
                        IsAutomaticProcess = false,
                        DpiStatus = (int)Globals.DPI.CallTypeDpiStatus.Start,
                        Active = true
                    },
                    Xml = string.Format("<?xml version=\"1.0\" encoding=\"utf-8\"?><DynamicFieldsAggregator xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Controls><DynamicControls xsi:type=\"DynamicDatePickerXml\"><Name>dtpDate</Name><Label><Text>Work Date Continuing:</Text><Css>dynamicLabel</Css><Style /></Label><Css /><Style /><Visible>true</Visible><Text>{0}</Text><IsValidEmpty>false</IsValidEmpty><EmptyValueMessage>The Work Date Continuing field is required</EmptyValueMessage><InvalidValueMessage>Invalid Work Date Continuing format</InvalidValueMessage><DateTimeFormat>Default</DateTimeFormat><ShowOn>Both</ShowOn><ValidationGroup>CallEntry</ValidationGroup></DynamicControls><DynamicControls xsi:type=\"DynamicTimeXml\"><Name>txtTime</Name><Label><Text>Work Time Continuing:</Text><Css>dynamicLabel</Css><Style /></Label><Css>input</Css><Style /><Visible>true</Visible><Text>{1}</Text><Mask>99:99</Mask><MaskedType>Time</MaskedType><InputDirection>LeftToRight</InputDirection><IsValidEmpty>false</IsValidEmpty><ValidationGroup>CallEntry</ValidationGroup><InvalidValueMessage>The Work Time Continuing field is invalid</InvalidValueMessage><EmptyValueMessage>The Work Time Continuing field is required.</EmptyValueMessage></DynamicControls><DynamicControls xsi:type=\"DynamicCountableTextBoxXml\"><Name>txtNote</Name><Label><Text>Note:</Text><Css>dynamicLabel</Css><Style /></Label><Css>input</Css><Style /><Visible>true</Visible><MaxChars>255</MaxChars><MaxCharsWarning>250</MaxCharsWarning><Text>They're BACK!</Text><IsRequired>false</IsRequired><ErrorMessage /><ValidationGroup /><TextMode>MultiLine</TextMode><Width>300</Width><Height>150</Height></DynamicControls></Controls><Extenders /></DynamicFieldsAggregator>",
                        calculationDate.ToString("yyyy-MM-dd"), "10:00"),
                    CreationDate = new DateTime(calculationDate.Year, calculationDate.Month, calculationDate.Day, 10, 0, 0)
                },
                JobID = 1,
                CallLogID = 3,
                EmployeeID = 1,
                CreationDate = new DateTime(calculationDate.Year, calculationDate.Month, calculationDate.Day, 10, 0, 0)
            });
            fakeCallLogResource.AddObject(new CS_CallLogResource()
            {
                CS_CallLog = new CS_CallLog
                {
                    CS_CallType = new CS_CallType()
                    {
                        ID = 18,
                        IsAutomaticProcess = true,
                        DpiStatus = (int)Globals.DPI.CallTypeDpiStatus.End,
                        Active = true
                    },
                    Xml = string.Format("<?xml version=\"1.0\" encoding=\"utf-8\"?><DynamicFieldsAggregator xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Controls><DynamicControls xsi:type=\"DynamicDatePickerXml\"><Name>dtpDate</Name><Label><Text>Work Date Released:</Text><Css>dynamicLabel</Css><Style /></Label><Css /><Style /><Visible>true</Visible><Text>{0}</Text><IsValidEmpty>false</IsValidEmpty><EmptyValueMessage>The Work Date Released field is required</EmptyValueMessage><InvalidValueMessage>Invalid Work Date format</InvalidValueMessage><DateTimeFormat>Default</DateTimeFormat><ShowOn>Both</ShowOn><ValidationGroup>CallEntry</ValidationGroup></DynamicControls><DynamicControls xsi:type=\"DynamicTimeXml\"><Name>txtTime</Name><Label><Text>Work Time Released:</Text><Css>dynamicLabel</Css><Style /></Label><Css /><Style /><Visible>true</Visible><Text>{1}</Text><Mask>99:99</Mask><MaskedType>Time</MaskedType><InputDirection>LeftToRight</InputDirection><IsValidEmpty>false</IsValidEmpty><ValidationGroup>CallEntry</ValidationGroup><InvalidValueMessage>The Work Time Released Time field is invalid</InvalidValueMessage><EmptyValueMessage>The Work Time Released field is required.</EmptyValueMessage></DynamicControls><DynamicControls xsi:type=\"DynamicCountableTextBoxXml\"><Name>txtNote</Name><Label><Text>Note:</Text><Css>dynamicLabel</Css><Style /></Label><Css /><Style /><Visible>true</Visible><MaxChars>255</MaxChars><MaxCharsWarning>250</MaxCharsWarning><Text>They stopped working!</Text><IsRequired>false</IsRequired><ErrorMessage /><ValidationGroup /><TextMode>MultiLine</TextMode><Width>300</Width><Height>150</Height></DynamicControls></Controls><Extenders /></DynamicFieldsAggregator>",
                        calculationDate.ToString("yyyy-MM-dd"), "16:00"),
                    CreationDate = new DateTime(calculationDate.Year, calculationDate.Month, calculationDate.Day, 16, 0, 0)
                },
                JobID = 1,
                CallLogID = 4,
                EmployeeID = 1,
                CreationDate = new DateTime(calculationDate.Year, calculationDate.Month, calculationDate.Day, 16, 0, 0)
            });

            Mock<IUnitOfWork> mockUnitOfWork = new Mock<IUnitOfWork>();
            mockUnitOfWork.Setup(e => e.CreateObjectSet<CS_DPIResource>()).Returns(fakeDPIResource);
            mockUnitOfWork.Setup(e => e.CreateObjectSet<CS_CallLogResource>()).Returns(fakeCallLogResource);

            // Act
            DPIModel model = new DPIModel(mockUnitOfWork.Object);
            IList<CS_DPIResource> returnList = model.ProcessDPIResources(dpiEntry, jobEntry, calculationDate);

            // Assert
            CS_DPIResource equipment = returnList.FirstOrDefault(e => e.EquipmentID == 1);
            CS_DPIResource employee = returnList.FirstOrDefault(e => e.EmployeeID == 1);
            Assert.AreEqual(equipment.Hours * equipment.Rate, equipment.Total);
            Assert.AreEqual(employee.Hours * employee.Rate, employee.Total);
        }
        public void ShouldReturnOnlyNumberWhenPriceTypeIsNotProvided()
        {
            //Arrange
            CS_Job newJob = new CS_Job()
            {
                ID = 1,
                Internal_Tracking = "000000001INT",
                CS_JobInfo = new CS_JobInfo()
                {
                    //The JobStatusID=2 determine this is a Internal tracking case (not job number)
                    CS_Job_JobStatus = new System.Data.Objects.DataClasses.EntityCollection<CS_Job_JobStatus>() {  new CS_Job_JobStatus() { ID =1, JobID=1,JobStatusId = 2}},
                    CS_JobType = new CS_JobType() { ID = 3, Description = "Y" }
                }
            };

            //Act
            string numberPrefixed = newJob.PrefixedNumber;

            //Assert
            Assert.AreEqual("000000001INT", numberPrefixed);
        }
        /// <summary>
        /// Build the Note for the Lapsed Preset based on Job
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public string BuildlapsedPresetNote(CS_Job job)
        {
            StringBuilder lapsedPreset = new StringBuilder();

            lapsedPreset.Append("Scope of Work: ");
            foreach (CS_ScopeOfWork scopeOfWork in job.CS_ScopeOfWork)
                lapsedPreset.AppendLine(" <Text>" + scopeOfWork.ScopeOfWork + "<BL>");

            if (!string.IsNullOrEmpty(job.NumberOrInternalTracking))
                lapsedPreset.Append("Non-Job #:<Text>" + job.PrefixedNumber + "<BL>");

            lapsedPreset.Append("Company:<Text>" + job.CS_CustomerInfo.CS_Customer.FullCustomerInformation + "<BL>");
            lapsedPreset.Append("Job type:<Text> " + job.CS_JobInfo.CS_JobType.Description + "<BL>");
            lapsedPreset.Append("Job Action:<Text> " + job.CS_JobInfo.CS_JobAction.Description + "<BL>");
            lapsedPreset.Append("Price type:<Text> " + job.CS_JobInfo.CS_PriceType.Description + "<BL>");
            if (null != job.CS_PresetInfo)
            {
                lapsedPreset.Append("Preset Instructions:<Text> " + job.CS_PresetInfo.Instructions + "<BL>");
                if (job.CS_PresetInfo.Date.HasValue)
                    lapsedPreset.Append("Preset Date:<Text> " + job.CS_PresetInfo.Date.Value.ToString("MM/dd/yyyy") + "<BL>");
                if (job.CS_PresetInfo.Time.HasValue)
                    lapsedPreset.Append("Preset Time:<Text> " + job.CS_PresetInfo.Time.Value.ToString() + "<BL>");
            }
            lapsedPreset.Append("Location:<Text> " + job.CS_LocationInfo.CS_Country.Name + ", " + job.CS_LocationInfo.CS_State.Name + ", " + job.CS_LocationInfo.CS_City.Name + ", " + job.CS_LocationInfo.CS_ZipCode.ZipCodeNameEdited + "<BL>");

            return lapsedPreset.ToString();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="lstEmployee"></param>
        /// <param name="job"></param>
        /// <returns></returns>
        public IList<CS_Employee> FilterEmployeeByCriteriaValue(IList<CS_Employee> lstEmployee, CS_Job job)
        {
            List<int> employeeIdList = new List<int>();

            foreach (CS_Employee employee in lstEmployee)
                employeeIdList.Add(employee.ID);

            string JobStatusID = job.CS_JobInfo.LastJobStatusID.ToString();
            string PriceTypeID = job.CS_JobInfo.PriceTypeID.ToString();
            string JobCategoryID = job.CS_JobInfo.JobCategoryID.ToString();
            string JobTypeID = job.CS_JobInfo.JobTypeID.ToString();
            string JobActionID = job.CS_JobInfo.JobActionID.ToString();
            string FrequencyID = (job.CS_JobInfo.FrequencyID.HasValue) ? job.CS_JobInfo.FrequencyID.ToString() : "";

            string CountryID = null;
            string StateID = null;
            string CityID = null;
            if (null != job.CS_LocationInfo)
            {
                CountryID = job.CS_LocationInfo.CountryID.ToString();
                StateID = job.CS_LocationInfo.StateID.ToString();
                CityID = job.CS_LocationInfo.CityID.ToString();
            }
            int CarCount = 0;
            if (null != job.CS_JobDescription)
                CarCount = (((job.CS_JobDescription.NumberEngines.HasValue) ? job.CS_JobDescription.NumberEngines : 0) + ((job.CS_JobDescription.NumberLoads.HasValue) ? job.CS_JobDescription.NumberLoads : 0) + ((job.CS_JobDescription.NumberEmpties.HasValue) ? job.CS_JobDescription.NumberEmpties : 0)).Value;

            IList<CS_CallCriteriaValue> lstCriterias = _callCriteriaValueRepository.ListAll(
                z =>
                (
                    z.CallCriteriaTypeID != (int)Globals.CallCriteria.CallCriteriaType.Division
                    && z.CallCriteriaTypeID != (int)Globals.CallCriteria.CallCriteriaType.Customer
                    && z.CallCriteriaTypeID != (int)Globals.CallCriteria.CallCriteriaType.CallType
                )
                && z.Active
                &&
                (
                    z.CS_CallCriteria.ID == z.CallCriteriaID
                    && z.CS_CallCriteria.Active
                    && z.CS_CallCriteria.EmployeeID.HasValue
                    && employeeIdList.Contains(z.CS_CallCriteria.EmployeeID.Value)
                )
            , new string[] { "CS_CallCriteria" });

            if (lstCriterias.Count == 0)
                return lstEmployee;
            else
                return lstEmployee.Where
                (
                e =>
                    (
                        lstCriterias.Any
                        (
                        z =>
                            z.CS_CallCriteria.EmployeeID == e.ID
                            &&
                            (
                                z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.JobStatus
                                && z.Value == JobStatusID
                                && z.Active
                            )
                            ||
                            (
                                z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.PriceType
                                && z.Value == PriceTypeID
                                && z.Active
                            )
                            ||
                            (
                                z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.JobCategory
                                && z.Value == JobCategoryID
                                && z.Active
                            )
                            ||
                            (
                                z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.JobType
                                && z.Value == JobTypeID
                                && z.Active
                            )
                            ||
                            (
                                z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.JobAction
                                && z.Value == JobActionID
                                && z.Active
                            )
                            ||
                            (
                                z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.Interimbilling
                                && z.Value == FrequencyID
                                && z.Active
                            )
                            ||
                            (
                                z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.Country
                                && z.Value == CountryID
                                && z.Active
                            )
                            ||
                            (
                                z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.State
                                && z.Value == StateID
                                && z.Active
                            )
                            ||
                            (
                                z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.City
                                && z.Value == CityID
                                && z.Active
                            )
                            ||
                            (
                                z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.CarCount
                                &&
                                (
                                    (
                                        (z.Value.Substring(0, 1) == ">") ?
                                            int.Parse(z.Value.Substring(1)) > CarCount
                                        :
                                        (
                                            (z.Value.Substring(0, 1) == "<") ?
                                                int.Parse(z.Value.Substring(1)) < CarCount
                                            :
                                                int.Parse(z.Value) == CarCount
                                        )
                                    )
                                )
                                && z.Active
                            )
                            ||
                            (
                                z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.Commodities
                                && ((z.Value == "1") && (!string.IsNullOrEmpty(job.CS_JobDescription.Lading)))
                                && z.Active
                            )
                            ||
                            (
                                z.CallCriteriaTypeID == (int)Globals.CallCriteria.CallCriteriaType.Chemicals
                                &&
                                (
                                    ((z.Value == "1") && (!string.IsNullOrEmpty(job.CS_JobDescription.UnNumber)))
                                    || ((z.Value == "2") && (!string.IsNullOrEmpty(job.CS_JobDescription.STCCInfo)))
                                    || ((z.Value == "3") && (!string.IsNullOrEmpty(job.CS_JobDescription.Hazmat)))
                                )
                                && z.Active
                            )
                        )
                    )
                ).ToList();
        }