Exemplo n.º 1
0
        internal InventorySettings GetInventorySettings()
        {
            var settings = new InventorySettings();

            settings.upload_type = ToaStringsUtil.GetString(_uploadType);
            settings.keys        = _keyFields;
            return(settings);
        }
Exemplo n.º 2
0
        internal AppointmentSettings GetActivitySettings()
        {
            var settings = new AppointmentSettings();

            settings.action_if_completed = ToaStringsUtil.GetString(_actionIfCompleted);
            settings.keys = _keyFields;
            return(settings);
        }
Exemplo n.º 3
0
        private void UpdateWorkOrderRecord(ToaRequestResult inboundResult, WorkOrderModel workOrderModel)
        {
            IList <IGenericField> fields = _workOrderRecord.GenericFields;

            if (null != fields)
            {
                foreach (IGenericField field in fields)
                {
                    switch (field.Name)
                    {
                    case "External_ID":
                        if (null != workOrderModel.TOA_AID)
                        {
                            field.DataValue.Value = workOrderModel.TOA_AID;
                        }
                        break;

                    case "WO_Status":

                        if (null != workOrderModel.TOA_AID && workOrderModel.TOA_AID != 0)
                        {
                            // Change work order status if activity is cancelled in TOA
                            if (workOrderModel.CancelReason != null && !workOrderModel.CancelReason.Trim().Equals(""))
                            {
                                workOrderModel.Status = Client.Common.ActivityStatus.Cancelled;
                            }
                            else     // Set Update Activity
                            {
                                workOrderModel.Status = Client.Common.ActivityStatus.Pending;
                            }
                        }
                        else
                        {
                            workOrderModel.Status = Client.Common.ActivityStatus.NotCreated;
                        }
                        field.DataValue.Value = ToaStringsUtil.GetString(workOrderModel.Status);
                        break;

                    case "Duration":
                        if (null != workOrderModel.Duration)
                        {
                            field.DataValue.Value = Int32.Parse(workOrderModel.Duration);
                        }
                        break;

                    default:
                        break;
                    }
                }
                _recordContext.RefreshWorkspace();
                _log.Notice("WorkOrder saved");
            }
        }
Exemplo n.º 4
0
        internal InboundInterfaceElement GetInboundRequestElement()
        {
            var inboundRequest = new InboundInterfaceElement();

            // Initialize User
            inboundRequest.user = ToaUserUtil.GetInboundUser();

            //Initialize Head
            var head = new HeadElement();

            head.allow_change_date = ToaStringsUtil.GetString(_allowChangeDate);
            head.date = _uploadDate;
            head.default_appointment_pool = _defaultAppointmentPool;
            head.id = _transactionId;
            head.processing_mode = ToaStringsUtil.GetString(_processingMode);
            head.properties_mode = ToaStringsUtil.GetString(_propertiesMode);
            head.upload_type     = ToaStringsUtil.GetString(_uploadType);
            head.provider_group  = _providerGroup;
            if (null != _activitySettings)
            {
                head.appointment = _activitySettings.GetActivitySettings();
            }
            if (null != _inventorySettings)
            {
                head.inventory = _inventorySettings.GetInventorySettings();
            }
            inboundRequest.head = head;

            //initialize Data
            var data       = new DataElement();
            var noOfModels = _dataModels.Count;

            CommandElement []  commands  = null;
            ProviderElement [] providers = null;
            if (UploadType == UploadType.Full) // Full Upload
            {
                providers = new ProviderElement[noOfModels];
                foreach (var model in _dataModels)
                {
                    if (model is WorkOrderModel)
                    {
                        var activityModel   = ((WorkOrderModel)model);
                        var providerElement = new ProviderElement();
                        providerElement.appointment = activityModel.GetActivityElement();
                        providers[--noOfModels]     = providerElement;
                    }
                    else if (model is InventoryModel)
                    {
                        //TODO: Need to initialize inventory object
                    }
                }
                data.providers = providers;
            }
            else // Incremental Upload
            {
                commands = new CommandElement[noOfModels];
                foreach (var model in _dataModels)
                {
                    if (model is WorkOrderModel)
                    {
                        var workOrderModel = ((WorkOrderModel)model);
                        var command        = new CommandElement();
                        command.appointment    = workOrderModel.GetActivityElement();
                        command.date           = workOrderModel.AssignedDate;
                        command.external_id    = workOrderModel.ExternalId;
                        command.type           = ToaStringsUtil.GetString(workOrderModel.CommandType);
                        commands[--noOfModels] = command;
                    }
                    else if (model is InventoryModel)
                    {
                        //TODO: Need to initialize inventory object
                    }
                }
                data.commands = commands;
            }



            inboundRequest.data = data;

            return(inboundRequest);
        }
Exemplo n.º 5
0
        ///
        /// This method is only used within toa client to create AppointmentElement object
        ///
        internal AppointmentElement GetActivityElement()
        {
            var activity = new AppointmentElement();

            //key fields
            activity.customer_number = _customerNumber;
            activity.appt_number     = _apptNumber;
            //mandatory fields
            activity.worktype = _workType;
            //Other fields
            if (null != _name)
            {
                activity.name = _name;
            }

            activity.action_if_completed = ToaStringsUtil.GetString(_actionIfCompleted);

            if (null != _address)
            {
                activity.address = _address;
            }

            if (null != _cell)
            {
                activity.cell = _cell;
            }

            if (null != _city)
            {
                activity.city = _city;
            }

            if (null != _coordinateX)
            {
                activity.coordx = _coordinateX;
            }

            if (null != _coordinateY)
            {
                activity.coordy = _coordinateY;
            }

            if (null != _email)
            {
                activity.email = _email;
            }

            if (null != _duration)
            {
                activity.duration = _duration;
            }

            if (null != _language)
            {
                activity.language = _language;
            }

            if (null != _points)
            {
                activity.points = _points.ToString();
            }

            if (null != _phone)
            {
                activity.phone = _phone;
            }

            if (null != _reminderTime)
            {
                activity.reminder_time = _reminderTime.ToString();
            }

            if (null != _serviceWindowStart)
            {
                activity.service_window_start = _serviceWindowStart;
            }

            if (null != _serviceWindowEnd)
            {
                activity.service_window_end = _serviceWindowEnd;
            }

            //if(null != _slaWindowStart)
            //    activity.sla_window_start = _slaWindowStart.ToString("yyyy'-'MM'-'dd HH':'mm");

            if (null != _slaWindowEnd)
            {
                activity.sla_window_end = ((DateTime)_slaWindowEnd).ToString("yyyy'-'MM'-'dd HH':'mm");

                //Below 2 null checks and fix is required as ETA is not behaving correctly.
                //If it has sla_window_end parameter then it should override the date and timeslot as mandatory fields in Inbound Request.
                //But it is not doing so, hence we are explictly required to send TimeSlot and Date.
                //If we do not provide them and if they are empty then activity creation fails in ETA.
                if (null == TimeSlot)
                {
                    TimeSlot = ActivityProperty.ALL_DAY_TIME_SLOT_LABEL;
                }
                if (null == AssignedDate)
                {
                    AssignedDate = "";
                }
            }


            if (null != _state)
            {
                activity.state = _state;
            }

            if (null != _teamId)
            {
                activity.team_id = _teamId;
            }

            if (null != _timeSlot)
            {
                activity.time_slot = _timeSlot;
            }

            if (null != _timeZone)
            {
                activity.time_zone = _timeZone;
            }
            //activity.worktype = _workType;
            //Below code is for using worktype label. We plan to use only WorkType and not the label.
            //if (null != _workTypeLabel)
            //    activity.worktype_label = _workTypeLabel;

            if (null != _zip)
            {
                activity.zip = _zip;
            }


            // Activity Properties
            if (null != Properties)
            {
                var noOfInventories  = Properties.Count;
                var propertyElements = new PropertyElement[noOfInventories];
                foreach (var property in Properties)
                {
                    var propertyElement = new PropertyElement();
                    propertyElement.label = property.Key;
                    propertyElement.value = property.Value;
                    propertyElements[--noOfInventories] = propertyElement;
                }
                activity.properties = propertyElements;
            }


            // Activity Inventories
            if (null != _inventories)
            {
                var noOfInventories   = _inventories.Count;
                var inventoryElements = new InventoryElement[noOfInventories];
                foreach (var inventoryModel in _inventories)
                {
                    var inventoryElement = inventoryModel.GetInventoryElement();
                    inventoryElements[--noOfInventories] = inventoryElement;
                }
                activity.inventories = inventoryElements;
            }

            // Preference Provideres
            if (null != _providerPreferences)
            {
                var noOfProviders = _providerPreferences.Count;
                var providers     = new ProviderPreferenceElement[noOfProviders];
                foreach (var providerModel in _providerPreferences)
                {
                    var ProviderPreferenceElement = providerModel.GetProviderPreferenceElement();
                    providers[--noOfProviders] = ProviderPreferenceElement;
                }
                activity.provider_preferences = providers;
            }

            // Required Inventories
            if (null != _requiredInventories && _requiredInventories.Count > 0)
            {
                var noOfRequiedInventories    = _requiredInventories.Count;
                var requiredInventoryElements = new RequiredInventoryElement[noOfRequiedInventories];
                foreach (var requiredInventoryModel in _requiredInventories)
                {
                    var requiredInventory = requiredInventoryModel.GetRequiredInventoryElement();
                    requiredInventoryElements[--noOfRequiedInventories] = requiredInventory;
                }
                activity.required_inventories = requiredInventoryElements;
            }
            if (null != UserData && UserData.Trim().Length > 0)
            {
                activity.userdata = UserData;
            }

            return(activity);
        }
Exemplo n.º 6
0
        public void Handler()
        {
            InboundRequest   inboundRequest = null;
            ToaRequestResult inboundResult  = null;
            int?           aid            = null;
            WorkOrderModel workOrderModel = null;

            try
            {
                _log.Notice("Starting WorkOrderSave Handler.");
                object wotype          = EventHandlerServices.GetEventHandlerService().getFieldFromWorOrderRecord(_workOrderRecord, "WO_Type");
                object overrideRequest = EventHandlerServices.GetEventHandlerService().getFieldFromWorOrderRecord(_workOrderRecord, "Override_Request");
                object timeSlot        = EventHandlerServices.GetEventHandlerService().getFieldFromWorOrderRecord(_workOrderRecord, "WO_Time_Slot");
                object wodate          = EventHandlerServices.GetEventHandlerService().getFieldFromWorOrderRecord(_workOrderRecord, "WO_Date");
                object resolutionDue   = EventHandlerServices.GetEventHandlerService().getFieldFromWorOrderRecord(_workOrderRecord, "Resolution_Due");

                if (null == wotype)
                {
                    return;
                }

                if (overrideRequest != null)
                {
                    if (timeSlot == null || wodate == null)
                    {
                        return;
                    }
                }
                else
                {
                    if (timeSlot == null || wodate == null)
                    {
                        if (resolutionDue == null)
                        {
                            return;
                        }
                    }
                }

                _log.Notice("Converting from RecordContext to WorkOrder Model started");
                workOrderModel = EventHandlerServices.GetEventHandlerService().GetWorkOrderModel(_recordContext);
                _log.Notice("Convertion from RecordContext to WorkOrder Model completed");

                //Appointments 'key' fields are set in the constuctor of below object
                var activitySettings = new ActivitySettingsModel();
                //Inventory 'key' fields are set in the constuctor of below object
                var inventorySettings = new InventorySettingsModel();

                _log.Notice("Initialize InboundRequest");
                inboundRequest = new InboundRequest(new List <IToaModel>()
                {
                    workOrderModel
                });
                inboundRequest.PropertiesMode    = Client.Common.PropertiesMode.Replace;
                inboundRequest.AllowChangeDate   = Client.Common.AllowChangeDate.Yes;
                inboundRequest.ActivitySettings  = activitySettings;
                inboundRequest.InventorySettings = inventorySettings;
                _log.Notice("Invoking TOA Server using Inbound API Started");
                inboundResult = InboundService.GetService().BeginSyncRequest(inboundRequest);

                if (inboundResult != null)
                {
                    _log.Notice("Invoking TOA Server using Inbound API Completed");
                    ToaExceptionManager manager = new ToaExceptionManager();
                    _log.Notice("Processing Inbound API Response Result");
                    aid = manager.ProcessInboundResult(inboundResult);
                    _log.Notice("Completed Processing Inbound API Response Result");
                    if (aid == null)
                    {
                        _cancelEventArgs.Cancel = true;
                        return;
                    }
                }
                else
                {
                    foreach (IGenericField field in _workOrderRecord.GenericFields)
                    {
                        if (field.Name.Equals("WO_Status"))
                        {
                            TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
                            field.DataValue.Value = textInfo.ToTitleCase(ToaStringsUtil.GetString(Client.Common.ActivityStatus.NotCreated));
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex.StackTrace);
                MessageBox.Show(ToaExceptionMessages.UnexpectedError, ToaExceptionMessages.TitleError,
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }

            try
            {
                _log.Notice("Updating WorkOrder Record.");
                workOrderModel.TOA_AID = (aid != null) ? aid : 0;
                UpdateWorkOrderRecord(inboundResult, workOrderModel);
                _log.Notice("WorkOrder Record Updated.");
                _log.Notice("Exiting WorkOrderSave Handler.");
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex.StackTrace);
                MessageBox.Show(ToaExceptionMessages.UnexpectedError, ToaExceptionMessages.TitleError,
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 7
0
        public WorkOrderModel GetWorkOrderModel(IRecordContext RecordContext)
        {
            ICustomObject workOrder = RecordContext.GetWorkspaceRecord(RecordContext.WorkspaceTypeName) as ICustomObject;
            IContact      contact   = RecordContext.GetWorkspaceRecord(WorkspaceRecordType.Contact) as IContact;

            WorkOrderModel workOrderModel = new WorkOrderModel();

            _log.Notice("Processing WorkOrder:" + workOrder.Id.ToString());
            if (workOrder != null)
            {
                IList <IGenericField> fields = workOrder.GenericFields;
                workOrderModel.AppointmentNumber = workOrder.Id.ToString();
                InventoryModel primaryAssetInventoryModel = null;
                int            workorderTypeId            = (Int32)getFieldFromWorOrderRecord(workOrder, "WO_Type");
                string[]       workordertype = RightNowConnectService.GetService().GetWorkOrderTypeFromID(workorderTypeId);
                _log.Notice("WorkOrder Type ID:" + workordertype[0]);
                foreach (IGenericField field in fields)
                {
                    if (field.DataValue.Value != null)
                    {
                        switch (field.Name)
                        {
                        case "Asset":
                            //cannot use record context here as Asset WorkspaceType is not exposed through RightNow.AddIns.Common.
                            //TODO Un-Comment below lines when RN Connect Services are available
                            if (null != field.DataValue.Value)
                            {
                                primaryAssetInventoryModel = new InventoryModel();
                                int assetid = (int)field.DataValue.Value;
                                _log.Notice("WorkOrder Primary Asset ID:" + assetid);
                                string[] details        = RightNowConnectService.GetService().GetAssetDetailsFromAssetID(assetid.ToString());
                                string[] productDetails = RightNowConnectService.GetService().GetProductDetailsFromProductID(details[0]);    //Type = Product's ID (i.e. SalesProduct.PartNumber)
                                if (null != productDetails && productDetails.Length > 0)
                                {
                                    primaryAssetInventoryModel.Type = productDetails[0];
                                }
                                else
                                {
                                    _log.Warning("invtype_label is not valid for primary asset.");
                                }
                                if (details.Length > 1)
                                {
                                    primaryAssetInventoryModel.SerialNumber = details[1];     //model = Serial Number
                                }
                            }
                            break;

                        case "Case_Note":
                            workOrderModel.SetPropertyValue("XA_CASE_NOTES", field.DataValue.Value.ToString());
                            break;

                        case "Cancel_Reason":
                            workOrderModel.CancelReason = field.DataValue.Value.ToString();
                            break;

                        case "Contact":
                            if (contact != null)
                            {
                                workOrderModel.CustomerNumber = contact.ID.ToString();
                                _log.Notice("WorkOrder Contact ID:" + contact.ID.ToString());
                                workOrderModel.Name = contact.NameFirst + " " + contact.NameLast;
                            }
                            break;

                        case "Contact_City":
                            workOrderModel.City = field.DataValue.Value.ToString();
                            break;

                        case "Contact_Email":
                            workOrderModel.EmailAddress = field.DataValue.Value.ToString();
                            break;

                        case "Contact_Mobile_Phone":
                            workOrderModel.MobileNumber = field.DataValue.Value.ToString();
                            break;

                        case "Contact_Phone":
                            workOrderModel.PhoneNumber = field.DataValue.Value.ToString();
                            break;

                        case "Contact_Postal_Code":
                            workOrderModel.ZipCode = field.DataValue.Value.ToString();
                            break;

                        case "Contact_Province_State":
                            int    province_id = (Int32)field.DataValue.Value;
                            string name        = RightNowConnectService.GetService().GetProvinceName(province_id);
                            if (name != null)
                            {
                                workOrderModel.State = name;
                            }
                            break;

                        case "Contact_Street":
                            workOrderModel.Address = field.DataValue.Value.ToString();
                            break;

                        case "Duration":
                            if (null == field.DataValue.Value)
                            {
                                if (workordertype[1].Equals("1"))
                                {
                                    workOrderModel.Duration = workordertype[2];
                                }
                                _log.Notice("WorkOrder Duration :" + workOrderModel.Duration);
                            }
                            else
                            {
                                workOrderModel.Duration = field.DataValue.Value.ToString();
                                _log.Notice("WorkOrder Duration :" + workOrderModel.Duration);
                            }
                            break;

                        case "Reminder_Time":
                            if (null != field.DataValue.Value)
                            {
                                int      id            = Convert.ToInt32(field.DataValue.Value);
                                string[] remindertime1 = RightNowConnectService.GetService().GetReminder_TimeFromID(id);
                                workOrderModel.ReminderTime = Convert.ToInt32(remindertime1[0]);
                            }

                            break;

                        case "Requested_Service_End":
                            workOrderModel.ServiceWindowEnd = field.DataValue.Value.ToString();
                            break;

                        case "Requested_Service_Start":
                            workOrderModel.ServiceWindowStart = field.DataValue.Value.ToString();
                            break;

                        case "Resolution_Due":
                            workOrderModel.SlaWindowEnd = Convert.ToDateTime(field.DataValue.Value);
                            break;

                        case "WO_Area":
                            workOrderModel.ExternalId = field.DataValue.Value.ToString();
                            break;

                        case "WO_Date":
                            workOrderModel.AssignedDate = ((DateTime)field.DataValue.Value).ToString("yyyy-MM-dd");
                            break;

                        case "WO_Status":
                            //Set it for each handler and not in generic code.
                            break;

                        case "WO_Time_Slot":
                            workOrderModel.TimeSlot = field.DataValue.Value.ToString();
                            break;

                        case "WO_Type":
                            workOrderModel.WorkType = workordertype[0];
                            break;
                        }
                    }
                }

                //Set Duration
                if (workOrderModel.Duration == null)
                {
                    if (workordertype[1].Equals("1"))
                    {
                        workOrderModel.Duration = workordertype[2];
                    }
                    _log.Notice("WorkOrder Duration :" + workOrderModel.Duration);
                }


                // Set Cancel Activity
                if (workOrderModel.CancelReason != null && !workOrderModel.CancelReason.Trim().Equals(""))
                {
                    workOrderModel.CommandType = Client.Common.ActivityCommandType.Cancel;
                }
                else // Set Update Activity
                {
                    workOrderModel.Status      = Client.Common.ActivityStatus.Pending;
                    workOrderModel.CommandType = Client.Common.ActivityCommandType.Update;
                }
                _log.Notice("WorOrder Command Type is set as " + ToaStringsUtil.GetString(workOrderModel.CommandType));

                workOrderModel.SetActionIfCompleted = Client.Common.ActionIfCompleted.CreateIfAssignOrReschedule;

                //TODO UnComment below code
                SetInventoryModel(workOrderModel, workOrder.Id, primaryAssetInventoryModel, workorderTypeId);
            }

            return(workOrderModel);
        }