Example #1
0
        /// <summary>
        /// Fetches the Work Order Areas for a particular zipcode
        /// </summary>
        /// <param name="zipCode">Zipcode</param>
        public void getWorkOrderArea(String zipCode)
        {
            _log.Notice("Inside getWorkOrderArea. ZipCode: " + zipCode);
            CapacityModel capacityModel = new CapacityModel();

            capacityModel.DetermineLocationByWorkZone          = true;
            capacityModel.DetermineLocationByWorkZoneSpecified = true;

            ActivityField zipField = new ActivityField();

            zipField.Name  = "czip";
            zipField.Value = zipCode;

            DateTime[] dateTimes = new DateTime[] {
                DateTime.Today,
            };
            capacityModel.QuotaDates = dateTimes;

            List <ActivityField> activityFields = new List <ActivityField>();

            activityFields.Add(zipField);

            capacityModel.ActivityField = activityFields.ToArray();

            ICapacityService service = CapacityService.GetService();

            if (service != null)
            {
                _log.Notice("Got CapacityService Object");
                service.GetWorkOrderArea(capacityModel, WorkOrderAreaCallback);
            }
        }
        /// <summary>
        /// Get the quota for a given month
        /// </summary>
        public ToaRequestResultCode getQuotaForMonth()
        {
            _log.Notice("Inside getQuotaForMonth");
            CapacityModel request = new CapacityModel();

            request.QuotaDates                   = getQuotaDates();
            request.CalculateDuration            = true;
            request.CalculateDurationSpecified   = true;
            request.CalculateTravelTime          = true;
            request.CalculateTravelTimeSpecified = true;
            request.CalculateWorkSkill           = true;
            request.CalculateWorkSkillSpecified  = true;
            request.ReturnTimeSlotInfo           = true;
            request.ReturnTimeSlotInfoSpecified  = true;
            request.Location = new string[] { Bucket };

            ActivityField zipField = new ActivityField();

            zipField.Name  = "czip";
            zipField.Value = PostalCode;

            ActivityField workType = new ActivityField();

            workType.Name  = "aworktype";
            workType.Value = WorkOrderType;

            List <ActivityField> activityFields = new List <ActivityField>();

            activityFields.Add(zipField);
            activityFields.Add(workType);

            request.ActivityField = activityFields.ToArray();

            ICapacityService service  = CapacityService.GetService();
            ToaRequestResult response = service.GetQuotaForMonth(request);

            if (response.ResultCode == ToaRequestResultCode.Failure)
            {
                return(response.ResultCode);
            }

            CapacityModel model = (CapacityModel)response.DataModels[0];

            monthlyQuota = null;
            monthlyQuota = model.DayQuota;

            List <string> timeSlots = new List <string>();

            timeSlots.Add("All Slots");
            timeSlots.AddRange(model.Timeslots);

            TimeSlotItems = new ObservableCollection <string>(timeSlots);

            CurrentTimeSlot = "All Slots";
            //CurrentDateSelected = DisplayDate;
            this.showQuotaForTimeSlots();
            //this.RequestRefresh();
            return(response.ResultCode);
        }
Example #3
0
        /// <summary>
        /// Callback method that will be invoked after the work order area request is successful.
        /// </summary>
        /// <param name="result">TOARequestResult object</param>
        public void WorkOrderAreaCallback(ToaRequestResult result)
        {
            _log.Notice("Inside Callback Method WorkOrderAreaCallback");
            CapacityModel model = (CapacityModel)result.DataModels[0];

            WorkOrderAreaItems = new ObservableCollection <string>(model.Location);
            ToaExceptionManager manager = new ToaExceptionManager();

            manager.ProcessCapacityServiceResult(result);
        }
Example #4
0
        /// <summary>
        /// Get Work Order Area mapped to zipcode
        /// </summary>
        /// <param name="capacityModel">Capacity Model object</param>
        /// <param name="capacityCallback">Callback method</param>
        public void GetWorkOrderArea(CapacityModel capacityModel, CapacityServiceDelegate capacityCallback)
        {
            _log.Notice("Inside GetWorkOrderArea");
            var backgroundService = new ToaBackgroundServiceUtil();

            backgroundService.RunAsync(() =>
            {
                try
                {
                    capacity_element[] capacityElement           = capacityModel.getCapacityElement();
                    time_slot_info_element[] timeSlotInfoElement = capacityModel.getTimeSlotInfoElement();
                    long activityTravelTime          = capacityModel.ActivityTravelTime;
                    bool activityTravelTimeSpecified = capacityModel.AggregateResultsSpecified;

                    _toaCapacityInterface.get_capacity(ToaUserUtil.GetCapacityUser(), capacityModel.QuotaDates, capacityModel.Location,
                                                       capacityModel.CalculateDuration, capacityModel.CalculateDurationSpecified, capacityModel.CalculateTravelTime, capacityModel.CalculateTravelTimeSpecified,
                                                       capacityModel.CalculateWorkSkill, capacityModel.CalculateWorkSkillSpecified, capacityModel.ReturnTimeSlotInfo, capacityModel.ReturnTimeSlotInfoSpecified,
                                                       capacityModel.DetermineLocationByWorkZone, capacityModel.DetermineLocationByWorkZoneSpecified, capacityModel.DontAggregateResults, capacityModel.DontAggregateResultsSpecified,
                                                       capacityModel.MinTimeEndOfTimeSlot, capacityModel.MinTimeEndOfTimeSlotSpecified,
                                                       capacityModel.DefaultDuration, capacityModel.DefaultDurationSpecified, capacityModel.Timeslots, capacityModel.WorkSkill,
                                                       capacityModel.getActivityFieldElement(),
                                                       out activityTravelTime, out activityTravelTimeSpecified, out activityTravelTime, out activityTravelTimeSpecified, out capacityElement, out timeSlotInfoElement);

                    CapacityModel response = new CapacityModel();

                    HashSet <string> locations = new HashSet <string>();
                    if (capacityElement != null)
                    {
                        foreach (capacity_element ce in capacityElement)
                        {
                            if (!locations.Contains(ce.location))
                            {
                                locations.Add(ce.location);
                            }
                        }
                    }

                    response.Location = new string[locations.Count];
                    locations.CopyTo(response.Location);
                    // initialize  toa result and activity model object
                    var toaRequestResult = new ToaRequestResult();
                    toaRequestResult.DataModels.Add(response);

                    toaRequestResult.ResultCode = ToaRequestResultCode.Success;

                    if (locations.Count == 0)
                    {
                        List <ReportMessageModel> reportMessageModel = new List <ReportMessageModel>();
                        _log.Error("Unable to determine work zone for given fields");
                        reportMessageModel.Add(new ReportMessageModel("No Work Order Areas exist for this Postal Code, please update the Postal Code field or submit with no timeslot and data selected", null, null, "Unable to determine work zone for given fields"));
                        toaRequestResult.ReportMessages = reportMessageModel;
                        toaRequestResult.ResultCode     = ToaRequestResultCode.Failure;
                    }

                    capacityCallback.Invoke(toaRequestResult);
                }
                catch (Exception exception)
                {
                    _log.Error("Unable to fetch Work Order Area");
                    _log.Error(exception.StackTrace);
                    MessageBox.Show("No Work Order Areas exist for this Postal Code, please update the Postal Code field or submit with no timeslot and data selected");
                }
            });
        }
Example #5
0
        /// <summary>
        /// Get Quota for month
        /// </summary>
        /// <param name="capacityModel"></param>
        /// <returns></returns>
        public ToaRequestResult GetQuotaForMonth(CapacityModel capacityModel)
        {
            _log.Notice("Inside GetQuotaForMonth");
            var toaRequestResult = new ToaRequestResult();

            try
            {
                capacity_element[]       capacityElement     = capacityModel.getCapacityElement();
                time_slot_info_element[] timeSlotInfoElement = capacityModel.getTimeSlotInfoElement();
                long activityTravelTime          = capacityModel.ActivityTravelTime;
                bool activityTravelTimeSpecified = capacityModel.ActivityTravelTimeSpecified;
                long activityDuration            = capacityModel.ActivityDuration;
                bool activityDurationSpecified   = capacityModel.ActivityDurationSpecified;

                _toaCapacityInterface.get_capacity(ToaUserUtil.GetCapacityUser(), capacityModel.QuotaDates, capacityModel.Location,
                                                   capacityModel.CalculateDuration, capacityModel.CalculateDurationSpecified, capacityModel.CalculateTravelTime, capacityModel.CalculateTravelTimeSpecified,
                                                   capacityModel.CalculateWorkSkill, capacityModel.CalculateWorkSkillSpecified, capacityModel.ReturnTimeSlotInfo, capacityModel.ReturnTimeSlotInfoSpecified,
                                                   capacityModel.DetermineLocationByWorkZone, capacityModel.DetermineLocationByWorkZoneSpecified, capacityModel.DontAggregateResults, capacityModel.DontAggregateResultsSpecified,
                                                   capacityModel.MinTimeEndOfTimeSlot, capacityModel.MinTimeEndOfTimeSlotSpecified,
                                                   capacityModel.DefaultDuration, capacityModel.DefaultDurationSpecified, capacityModel.Timeslots, capacityModel.WorkSkill,
                                                   capacityModel.getActivityFieldElement(),
                                                   out activityDuration, out activityDurationSpecified, out activityTravelTime, out activityTravelTimeSpecified, out capacityElement, out timeSlotInfoElement);

                CapacityModel response = new CapacityModel();

                if (activityDuration != null)
                {
                    response.ActivityDuration = activityDuration;
                }

                if (activityTravelTime != null)
                {
                    response.ActivityTravelTime = activityTravelTime;
                }

                Dictionary <DateTime, DayQuota> dayQuota = new Dictionary <DateTime, DayQuota>();
                if (capacityElement != null)
                {
                    foreach (capacity_element ce in capacityElement)
                    {
                        if (dayQuota.ContainsKey(ce.date))
                        {
                            DayQuota quota = dayQuota[ce.date];
                            if (quota.TimeSlotQuota == null)
                            {
                                quota.TimeSlotQuota = new Dictionary <string, float>();
                            }
                            float quotaAvailable = (((ce.available - (activityDuration + activityTravelTime)) * 100) / ce.quota);

                            quota.TimeSlotQuota.Add(ce.time_slot, quotaAvailable);
                        }
                        else
                        {
                            DayQuota quota = new DayQuota();
                            quota.QuotaDate     = ce.date;
                            quota.TimeSlotQuota = new Dictionary <string, float>();
                            float quotaAvailable = (((ce.available - (activityDuration + activityTravelTime)) * 100) / ce.quota);
                            quota.TimeSlotQuota.Add(ce.time_slot, quotaAvailable);
                            dayQuota.Add(ce.date, quota);
                        }
                    }
                }

                _log.Debug("Monthy Quota Response: ", Json.Encode(capacityElement));
                _log.Debug("TimeSlots: ", Json.Encode(timeSlotInfoElement));

                HashSet <string> timeSlotSet = new HashSet <string>();
                if (timeSlotInfoElement != null)
                {
                    foreach (time_slot_info_element ts in timeSlotInfoElement)
                    {
                        timeSlotSet.Add(ts.label);
                    }
                }

                if (timeSlotSet.Count > 0)
                {
                    response.Timeslots = new string[timeSlotSet.Count];
                    timeSlotSet.CopyTo(response.Timeslots);
                    Array.Sort(response.Timeslots);
                }

                DateTime currentDate = DateTime.Today;
                bool     todayExists = Array.IndexOf(capacityModel.QuotaDates, currentDate) >= 0;

                //Fix the closing quota issue
                if (todayExists)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        if (dayQuota.ContainsKey(currentDate))
                        {
                            DayQuota quota = dayQuota[currentDate];
                            foreach (string timeSlot in response.Timeslots)
                            {
                                if (!quota.TimeSlotQuota.ContainsKey(timeSlot))
                                {
                                    quota.TimeSlotQuota.Add(timeSlot, 0);
                                }
                            }
                        }
                        else
                        {
                            DayQuota quota = new DayQuota();
                            quota.QuotaDate     = currentDate;
                            quota.TimeSlotQuota = new Dictionary <string, float>();
                            foreach (string timeSlot in response.Timeslots)
                            {
                                quota.TimeSlotQuota.Add(timeSlot, 0);
                            }
                            dayQuota.Add(currentDate, quota);
                        }

                        currentDate = DateTime.Today.AddDays(1);
                        bool currentDateExists = Array.IndexOf(capacityModel.QuotaDates, currentDate) >= 0;
                        if (!currentDateExists)
                        {
                            break;
                        }
                    }
                }

                response.DayQuota = dayQuota;
                // initialize  toa result and activity model object

                toaRequestResult.DataModels.Add(response);
                if (dayQuota.Count == 0 || timeSlotSet.Count == 0)
                {
                    toaRequestResult.ResultCode = ToaRequestResultCode.Failure;
                }
                else
                {
                    toaRequestResult.ResultCode = ToaRequestResultCode.Success;
                }

                return(toaRequestResult);
            }
            catch (Exception exception)
            {
                _log.Error("Unable to fetch Quota for given dates");
                _log.Error(exception.StackTrace);
                MessageBox.Show("No quota available for the Work Order Type and Work Order Area selected.  Please reselect, if you continue to receive this warning, please contact support for assistance.",
                                "Warning: No Quota Available", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                toaRequestResult.ResultCode = ToaRequestResultCode.Failure;
            }
            return(toaRequestResult);
        }