Esempio n. 1
0
        public static void CalculateTurnSchStartandEndDate(ITracingService tracer, IOrganizationService service, Entity projectEntity, Entity jobEntity, Mapping mapping, int timeZoneCode)
        {
            if (jobEntity.Attributes.Contains(Constants.Jobs.JobAmount))
            {
                //EntityCollection jobVendorsEntityCollection = RetrieveJobVenodrsByJob(tracer, service, jobEntity.ToEntityReference());
                //if (jobVendorsEntityCollection.Entities.Count > 0)
                //{
                //Entity startDateEntity = jobVendorsEntityCollection.Entities.Where(e => e.Attributes.Contains(Constants.JobVendors.StartDate)).OrderBy(e => e.Attributes[Constants.JobVendors.StartDate]).FirstOrDefault();
                DateTime schJobStartDate = CommonMethods.RetrieveLocalTimeFromUTCTime(service, timeZoneCode, DateTime.Now).ChangeTime(6, 0, 0, 0);
                tracer.Trace($"Project Template is : {mapping.Name}");

                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    tracer.Trace("Processing Turn Project...");
                    if (projectEntity.Attributes.Contains(Constants.Projects.Unit))
                    {
                        Entity unitEntity = service.Retrieve(Constants.Units.LogicalName, projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.Unit).Id, new ColumnSet(Constants.Units.MoveOutDate));
                        if (unitEntity is Entity && unitEntity.Attributes.Contains(Constants.Units.MoveOutDate))
                        {
                            DateTime moveOutDate = CommonMethods.RetrieveLocalTimeFromUTCTime(service, timeZoneCode, unitEntity.GetAttributeValue <DateTime>(Constants.Units.MoveOutDate));
                            tracer.Trace($"Property Move Out Date  : {moveOutDate}");
                            schJobStartDate = moveOutDate;
                            tracer.Trace($"Sched. Start Date from Property Move Out Date : {schJobStartDate.AddDays(1)}.");
                            DateTime schJobCompletionDate = moveOutDate.AddDays((double)Math.Ceiling(jobEntity.GetAttributeValue <Money>(Constants.Jobs.JobAmount).Value / 700) + 1);
                            tracer.Trace($"Final Sched. Job Completion Date  : {schJobCompletionDate}.");

                            PerformScheduledDateMoveOut(tracer, service, projectEntity, schJobCompletionDate, timeZoneCode, true);
                            //CreateVendorProjectTask(tracer, service, projectEntity, jobVendorsEntityCollection, mapping, schJobCompletionDate, timeZoneCode);

                            Entity tmpPrj = new Entity(projectEntity.LogicalName);
                            tmpPrj.Id = projectEntity.Id;
                            tmpPrj[Constants.Projects.ScheduledJobStartDate]      = schJobStartDate.AddDays(1);
                            tmpPrj[Constants.Projects.ScheduledJobCompletionDate] = schJobCompletionDate;
                            service.Update(tmpPrj);
                        }
                        else
                        {
                            tracer.Trace("Unit Entity does not contain Move Out Date.");
                        }
                    }
                    else
                    {
                        tracer.Trace("Project Entity does not contain Unit");
                    }
                }
                else
                {
                    tracer.Trace("Processing Reno Project...");
                    //DateTime schJobStartDate = DateTime.Now.ChangeTime(6, 0, 0, 0);
                    bool schJobCompFound = false;
                    //First use ESCRO
                    EntityCollection prop_acquired_EntityCollection = CommonMethods.RetrieveAllProjectTaskByProjectAndTaskIdentifier(tracer, service, projectEntity.ToEntityReference(), projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate), (int)Events.CLOSE_ESCROW);
                    if (prop_acquired_EntityCollection.Entities.Count > 0)
                    {
                        Entity propAcquiredProjectTaskEntity = prop_acquired_EntityCollection.Entities[0];
                        if (propAcquiredProjectTaskEntity is Entity && propAcquiredProjectTaskEntity.Attributes.Contains(Constants.ProjectTasks.ActualEnd))
                        {
                            schJobStartDate = CommonMethods.RetrieveLocalTimeFromUTCTime(service, timeZoneCode, propAcquiredProjectTaskEntity.GetAttributeValue <DateTime>(Constants.ProjectTasks.ActualEnd)).AddDays(1);
                            tracer.Trace($"Sched. Start Date from Property Acquired Task End Date : {schJobStartDate}.");

                            schJobCompFound = true;
                        }
                    }
                    if (!schJobCompFound)
                    {
                        if (projectEntity.Attributes.Contains(Constants.Projects.Unit))
                        {
                            Entity unitEntity = service.Retrieve(Constants.Units.LogicalName, projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.Unit).Id, new ColumnSet(Constants.Units.ScheduledAcquisitionDate));
                            if (unitEntity is Entity && unitEntity.Attributes.Contains(Constants.Units.ScheduledAcquisitionDate))
                            {
                                schJobStartDate = CommonMethods.RetrieveLocalTimeFromUTCTime(service, timeZoneCode, unitEntity.GetAttributeValue <DateTime>(Constants.Units.ScheduledAcquisitionDate)).AddDays(1);
                                tracer.Trace($"Sched. Start Date from Unit Acquisition Date : {schJobStartDate}.");
                                schJobCompFound = true;
                            }
                        }
                    }
                    if (!schJobCompFound)
                    {
                        EntityCollection jobVendorsEntityCollection = RetrieveJobVenodrsByJob(tracer, service, jobEntity.ToEntityReference());
                        if (jobVendorsEntityCollection.Entities.Count > 0)
                        {
                            Entity endDateEntity = jobVendorsEntityCollection.Entities.Where(e => e.Attributes.Contains(Constants.JobVendors.EndDate)).OrderByDescending(e => e.Attributes[Constants.JobVendors.EndDate]).FirstOrDefault();
                            schJobStartDate = CommonMethods.RetrieveLocalTimeFromUTCTime(service, timeZoneCode, endDateEntity.GetAttributeValue <DateTime>(Constants.JobVendors.EndDate)).AddDays(1);
                            tracer.Trace($"Sched. Start Date from Last Job End Date : {schJobStartDate}.");
                            schJobCompFound = true;
                        }
                    }


                    tracer.Trace($"Sched. Start Date before Job Amount Cal Date : {schJobStartDate}. Job Amount : {jobEntity.GetAttributeValue<Money>(Constants.Jobs.JobAmount).Value}");
                    DateTime schJobCompletionDate = schJobStartDate.AddDays((double)Math.Ceiling(jobEntity.GetAttributeValue <Money>(Constants.Jobs.JobAmount).Value / 700));
                    tracer.Trace($"Final Sched. Job Completion Date  : {schJobCompletionDate}.");


                    Entity tmpPrj = new Entity(projectEntity.LogicalName);
                    tmpPrj.Id = projectEntity.Id;
                    tmpPrj[Constants.Projects.ScheduledJobStartDate]      = schJobStartDate;
                    tmpPrj[Constants.Projects.ScheduledJobCompletionDate] = schJobCompletionDate;
                    service.Update(tmpPrj);

                    PerformScheduledDateMoveOut(tracer, service, projectEntity, schJobCompletionDate, timeZoneCode, false);
                    //CreateVendorProjectTask(tracer, service, projectEntity, jobVendorsEntityCollection, mapping, schJobCompletionDate, timeZoneCode);
                }
                // }
            }
            else
            {
                tracer.Trace("Job Entity does not contain either Job Amount or Unit");
            }
        }
Esempio n. 2
0
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService             tracer  = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext     context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service = factory.CreateOrganizationService(context.UserId);
            ProjectTemplateSettings     projectTemplateSettings = null;

            if (!string.IsNullOrEmpty(_unsecureConfig))
            {
                StringReader  stringReader = new StringReader(_unsecureConfig);
                XmlSerializer serializer   = new XmlSerializer(typeof(ProjectTemplateSettings));

                projectTemplateSettings = (ProjectTemplateSettings)serializer.Deserialize(stringReader);
            }

            if (projectTemplateSettings == null)
            {
                tracer.Trace($"Project Template Setting not available in Plugin UnSecure Configuration.");
                return;
            }

            Entity jobEntity = null;

            if (!context.InputParameters.Contains(Constants.TARGET))
            {
                return;
            }
            if (((Entity)context.InputParameters[Constants.TARGET]).LogicalName != Constants.Jobs.LogicalName)
            {
                return;
            }


            try
            {
                switch (context.MessageName)
                {
                //case Constants.Messages.Create:
                //    if (context.InputParameters.Contains(Constants.TARGET) && context.InputParameters[Constants.TARGET] is Entity)
                //        jobEntity = context.InputParameters[Constants.TARGET] as Entity;
                //    else
                //        return;
                //    break;
                case Constants.Messages.Update:
                    if (context.InputParameters.Contains(Constants.TARGET) && context.InputParameters[Constants.TARGET] is Entity && context.PostEntityImages.Contains(Constants.POST_IMAGE))
                    {
                        jobEntity = context.PostEntityImages[Constants.POST_IMAGE] as Entity;
                    }
                    else
                    {
                        return;
                    }
                    break;
                }
                //TODO: Do stuff

                if (jobEntity == null || context.Depth > 2)
                {
                    tracer.Trace($"Job entity is Null OR Context Depth is higher than 2. Actual Depth is : {context.Depth}");
                    return;
                }

                if (!jobEntity.Attributes.Contains(Constants.Jobs.JobStatus) || (!jobEntity.Attributes.Contains(Constants.Jobs.Unit) && !jobEntity.Attributes.Contains(Constants.Jobs.RenowalkID)))
                {
                    tracer.Trace($"Job Enity missing either Job Status or Unit or Renowalk ID field. Exiting PlugIn Pipeline");
                    return;
                }

                tracer.Trace($"Job Enity Job Status : {jobEntity.GetAttributeValue<OptionSetValue>(Constants.Jobs.JobStatus).Value}");
                if (jobEntity.GetAttributeValue <OptionSetValue>(Constants.Jobs.JobStatus).Value != 963850004)
                {
                    tracer.Trace($"Job Enity Job Status is NOT Contract Created (963850004). Existing PlugIn Pipeline.");
                    return;
                }

                if (jobEntity is Entity && projectTemplateSettings is ProjectTemplateSettings)
                {
                    tracer.Trace($"Finding Active Project using Unit or Renowalk ID.");
                    EntityCollection projectEntityCollection = new EntityCollection();
                    if (jobEntity.Attributes.Contains(Constants.Jobs.RenowalkID))
                    {
                        projectEntityCollection = CommonMethods.RetrieveActivtProjectByRenowalkId(tracer, service, jobEntity.GetAttributeValue <string>(Constants.Jobs.RenowalkID));
                    }
                    if (projectEntityCollection.Entities.Count == 0 && jobEntity.Attributes.Contains(Constants.Jobs.Unit))
                    {
                        projectEntityCollection = CommonMethods.RetrieveActivtProjectByUnitId(tracer, service, jobEntity.GetAttributeValue <EntityReference>(Constants.Jobs.Unit));
                    }
                    foreach (Entity projectEntity in projectEntityCollection.Entities)
                    {
                        if (projectEntity.Attributes.Contains(Constants.Projects.ProjectTemplate))
                        {
                            Mapping mapping = (
                                from m in projectTemplateSettings.Mappings
                                where m.Key.Equals(projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate).Id.ToString(), StringComparison.OrdinalIgnoreCase)
                                select m).FirstOrDefault <Mapping>();


                            if (mapping is Mapping)
                            {
                                tracer.Trace($"Project Template is : {mapping.Name}");
                                int      timeZoneCode    = CommonMethods.RetrieveCurrentUsersSettings(service);
                                DateTime currentDateTime = CommonMethods.RetrieveLocalTimeFromUTCTime(service, timeZoneCode, DateTime.Now);
                                tracer.Trace($"Current Date Time : {currentDateTime}");
                                CalculateTurnSchStartandEndDate(tracer, service, projectEntity, jobEntity, mapping, timeZoneCode);
                                //EntityCollection job_and_contracts_sub_to_yardi_EntityCollection = CommonMethods.RetrieveOpenProjectTaskByProjectAndTaskIdentifier(tracer, service, projectEntity.ToEntityReference(), projectEntity.GetAttributeValue<EntityReference>(Constants.Projects.ProjectTemplate),
                                //    mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE) ? 10 : 209, mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE) ? "10" : "9");
                                //foreach (Entity e in job_and_contracts_sub_to_yardi_EntityCollection.Entities)
                                //{
                                //    Entity num = new Entity(e.LogicalName)
                                //    {
                                //        Id = e.Id
                                //    };
                                //    num[Constants.ProjectTasks.ActualStart] = currentDateTime;
                                //    num[Constants.ProjectTasks.ActualEnd] = currentDateTime;
                                //    num[Constants.ProjectTasks.ActualDurationInMinutes] = (!e.Attributes.Contains(Constants.ProjectTasks.ActualStart)) ? 0 : (((currentDateTime - e.GetAttributeValue<DateTime>(Constants.ProjectTasks.ActualStart)).TotalMinutes > 0) ? (int)Math.Floor((currentDateTime - e.GetAttributeValue<DateTime>(Constants.ProjectTasks.ActualStart)).TotalMinutes) : 0);
                                //    //(!e.Attributes.Contains(Constants.ProjectTasks.ActualStart)) ? (int) 0 : (currentDateTime - e.GetAttributeValue<DateTime>(Constants.ProjectTasks.ActualStart)).TotalMinutes;
                                //    num[Constants.ProjectTasks.Progress] = new decimal(100);
                                //    num[Constants.Status.StatusCode] = new OptionSetValue(963850001);
                                //    service.Update(num);
                                //    tracer.Trace("Task for Event : JOB_AND_CONTRACTS_SUBMITTED_TO_YARDI Successfully Updated.");
                                //}

                                EntityCollection job_assign_to_vendor_in_cc_EntityCollection = CommonMethods.RetrieveOpenProjectTaskByProjectAndTaskIdentifier(tracer, service, projectEntity.ToEntityReference(), projectEntity.GetAttributeValue <EntityReference>(Constants.Projects.ProjectTemplate),
                                                                                                                                                               mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE) ? 9 : 207, mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE) ? "9" : "7");
                                foreach (Entity e in job_assign_to_vendor_in_cc_EntityCollection.Entities)
                                {
                                    Entity num = new Entity(e.LogicalName)
                                    {
                                        Id = e.Id
                                    };
                                    if (!e.Attributes.Contains(Constants.ProjectTasks.ActualStart))
                                    {
                                        num[Constants.ProjectTasks.ActualStart] = currentDateTime;
                                    }
                                    num[Constants.ProjectTasks.ActualEnd] = currentDateTime;
                                    num[Constants.ProjectTasks.ActualDurationInMinutes] = (!e.Attributes.Contains(Constants.ProjectTasks.ActualStart)) ? 0 : (((currentDateTime - e.GetAttributeValue <DateTime>(Constants.ProjectTasks.ActualStart)).TotalMinutes > 0) ? (int)Math.Floor((currentDateTime - e.GetAttributeValue <DateTime>(Constants.ProjectTasks.ActualStart)).TotalMinutes) : 0);
                                    num[Constants.ProjectTasks.Progress] = new decimal(100);
                                    num[Constants.Status.StatusCode]     = new OptionSetValue(963850001);
                                    service.Update(num);
                                    tracer.Trace("Task for Event : JOB_ASSIGNMENT_TO_VENDORS_IN_CONTRACT_CREATOR Successfully Updated.");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                tracer.Trace(e.Message + e.StackTrace);
            }
        }
Esempio n. 3
0
        private void CreateOutGoingAzureIntegrationCallRecord(IOrganizationService _service, ITracingService tracer, Entity projectEntity, EntityReference projectTemplateEntityReference, ProjectTemplateSettings projectTemplateSettings, string propertyID)
        {
            Mapping mapping = (
                from m in projectTemplateSettings.Mappings
                where m.Key.Equals(projectTemplateEntityReference.Id.ToString(), StringComparison.OrdinalIgnoreCase)
                select m).FirstOrDefault <Mapping>();

            if (mapping is Mapping)
            {
                tracer.Trace($"Project Template is : {mapping.Name}");

                List <GridEvent <DataPayLoad> > gridEventDataPayloadList = new List <GridEvent <DataPayLoad> >();
                GridEvent <DataPayLoad>         gridEventDataPayload     = new GridEvent <DataPayLoad>();
                gridEventDataPayload.EventTime = DateTime.Now.ToString();
                gridEventDataPayload.EventType = "allEvents";
                gridEventDataPayload.Id        = Guid.NewGuid().ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.Subject = $"Turn Process : {Events.REVISED_START_DATE.ToString()}";
                }
                else
                {
                    gridEventDataPayload.Subject = $"Initial Renovation : {Events.IR_REVISED_START_DATE.ToString()}";
                }
                gridEventDataPayload.data       = new DataPayLoad();
                gridEventDataPayload.data.Date1 = projectEntity.GetAttributeValue <DateTime>(Constants.Projects.RevisedStartDate).ToString();
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    gridEventDataPayload.data.Event = Events.REVISED_START_DATE;
                }
                else
                {
                    gridEventDataPayload.data.Event = Events.IR_REVISED_START_DATE;
                }
                gridEventDataPayload.data.IsForce     = false;
                gridEventDataPayload.data.PropertyID  = propertyID;
                gridEventDataPayload.data.EmailID     = string.Empty;
                gridEventDataPayload.data.FotoNotesID = string.Empty;
                gridEventDataPayload.data.JobID       = projectEntity.GetAttributeValue <string>(Constants.Projects.RenowalkID);
                gridEventDataPayload.data.RenowalkID  = projectEntity.GetAttributeValue <string>(Constants.Projects.RenowalkID);

                gridEventDataPayloadList.Add(gridEventDataPayload);

                Entity azIntCallEntity = new Entity(Constants.AzureIntegrationCalls.LogicalName);
                azIntCallEntity[Constants.AzureIntegrationCalls.EventData] = CommonMethods.Serialize(gridEventDataPayloadList);
                azIntCallEntity[Constants.AzureIntegrationCalls.Direction] = true;
                if (mapping.Name.Equals(TURNPROCESS_PROJECT_TEMPLATE))
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.REVISED_START_DATE.ToString();
                }
                else
                {
                    azIntCallEntity[Constants.AzureIntegrationCalls.EventName] = Events.IR_REVISED_START_DATE.ToString();
                }
                _service.Create(azIntCallEntity);
            }
            else
            {
                tracer.Trace($"Project Template Mapping Not found in PlugIn Setting for Project Template : {projectTemplateEntityReference.Id.ToString()}");
            }
        }