/// <summary>
        /// Verifies if the specified recurrence dates match the Route's definition.
        /// </summary>
        /// <param name="cache">PXCache instance.</param>
        /// <param name="fsRouteContractScheduleRow">FSRouteContractSchedule object row.</param>
        private void ValidateDays(PXCache cache, FSRouteContractSchedule fsRouteContractScheduleRow)
        {
            FSScheduleRoute fsScheduleRouteRow = ScheduleRoutes.Current;

            if (fsScheduleRouteRow == null || fsScheduleRouteRow.DfltRouteID == null)
            {
                return;
            }

            FSRoute fsRouteRow = PXSelect <FSRoute,
                                           Where <
                                               FSRoute.routeID, Equal <Required <FSRoute.routeID> > > >
                                 .Select(this, fsScheduleRouteRow.DfltRouteID);

            if (fsRouteRow != null && fsRouteContractScheduleRow.FrequencyType == ID.Schedule_FrequencyType.WEEKLY &&
                ((fsRouteContractScheduleRow.WeeklyOnMon == true && fsRouteRow.ActiveOnMonday == false) ||
                 (fsRouteContractScheduleRow.WeeklyOnThu == true && fsRouteRow.ActiveOnThursday == false) ||
                 (fsRouteContractScheduleRow.WeeklyOnWed == true && fsRouteRow.ActiveOnWednesday == false) ||
                 (fsRouteContractScheduleRow.WeeklyOnTue == true && fsRouteRow.ActiveOnTuesday == false) ||
                 (fsRouteContractScheduleRow.WeeklyOnFri == true && fsRouteRow.ActiveOnFriday == false) ||
                 (fsRouteContractScheduleRow.WeeklyOnSat == true && fsRouteRow.ActiveOnSaturday == false) ||
                 (fsRouteContractScheduleRow.WeeklyOnSun == true && fsRouteRow.ActiveOnSunday == false)))
            {
                throw new PXException(TX.Error.RECURRENCE_DAYS_ROUTE_DAYS_MISMATCH);
            }
        }
        /// <summary>
        /// Returns the priority of the Schedule depending on its Time Restrictions or Route information.
        /// </summary>
        public static Schedule.ScheduleGenerationPriority SetSchedulePriority(Schedule schedule, PXGraph graph)
        {
            var fsContractScheduleSet = PXSelectJoin <FSContractSchedule,
                                                      LeftJoin <
                                                          FSScheduleRoute,
                                                          On <FSScheduleRoute.scheduleID, Equal <FSContractSchedule.scheduleID> > >,
                                                      Where <
                                                          FSContractSchedule.entityID, Equal <Required <FSContractSchedule.entityID> > > >
                                        .Select(graph, schedule.EntityID);

            foreach (PXResult <FSContractSchedule, FSScheduleRoute> bqlResult in fsContractScheduleSet)
            {
                FSContractSchedule fsContractScheduleRow = (FSContractSchedule)bqlResult;
                FSScheduleRoute    fsScheduleRouteRow    = (FSScheduleRoute)bqlResult;

                if (fsContractScheduleRow.RestrictionMax == true || fsContractScheduleRow.RestrictionMin == true)
                {
                    return(Schedule.ScheduleGenerationPriority.TimeRestriction);
                }
                else if (fsScheduleRouteRow.DfltRouteID != null)
                {
                    return(Schedule.ScheduleGenerationPriority.Sequence);
                }
            }

            return(Schedule.ScheduleGenerationPriority.Nothing);
        }
        /// <summary>
        /// Prepares a new List[RouteInfo] with the information of the routes defined in a particular FSScheduleRoute.
        /// </summary>
        public static List <RouteInfo> getRouteListFromSchedule(Schedule schedule, PXGraph graph)
        {
            List <RouteInfo> returnList = new List <RouteInfo>();

            var fsContractScheduleSet = PXSelectJoin <FSContractSchedule,
                                                      LeftJoin <
                                                          FSScheduleRoute,
                                                          On <FSScheduleRoute.scheduleID, Equal <FSContractSchedule.scheduleID> > >,
                                                      Where <
                                                          FSContractSchedule.entityID, Equal <Required <FSContractSchedule.entityID> > > >
                                        .Select(graph, schedule.EntityID);

            foreach (PXResult <FSContractSchedule, FSScheduleRoute> bqlResult in fsContractScheduleSet)
            {
                FSScheduleRoute fsScheduleRouteRow = (FSScheduleRoute)bqlResult;

                returnList.Add(new RouteInfo(fsScheduleRouteRow.RouteIDSunday, int.Parse(fsScheduleRouteRow.SequenceSunday)));
                returnList.Add(new RouteInfo(fsScheduleRouteRow.RouteIDMonday, int.Parse(fsScheduleRouteRow.SequenceMonday)));
                returnList.Add(new RouteInfo(fsScheduleRouteRow.RouteIDTuesday, int.Parse(fsScheduleRouteRow.SequenceTuesday)));
                returnList.Add(new RouteInfo(fsScheduleRouteRow.RouteIDWednesday, int.Parse(fsScheduleRouteRow.SequenceWednesday)));
                returnList.Add(new RouteInfo(fsScheduleRouteRow.RouteIDThursday, int.Parse(fsScheduleRouteRow.SequenceThursday)));
                returnList.Add(new RouteInfo(fsScheduleRouteRow.RouteIDFriday, int.Parse(fsScheduleRouteRow.SequenceFriday)));
                returnList.Add(new RouteInfo(fsScheduleRouteRow.RouteIDSaturday, int.Parse(fsScheduleRouteRow.SequenceSaturday)));
            }

            return(returnList);
        }
        protected virtual void _(Events.RowPersisting <FSScheduleRoute> e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSScheduleRoute fsScheduleRouteRow = (FSScheduleRoute)e.Row;

            fsScheduleRouteRow.GlobalSequence = fsScheduleRouteRow.GlobalSequence.PadLeft(5, '0');
        }
        protected virtual void FSScheduleRoute_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSScheduleRoute fsScheduleRouteRow = (FSScheduleRoute)e.Row;

            fsScheduleRouteRow.GlobalSequence = fsScheduleRouteRow.GlobalSequence.PadLeft(5, '0');
        }
        protected virtual void _(Events.FieldUpdated <FSScheduleRoute, FSScheduleRoute.globalSequence> e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSScheduleRoute fsScheduleRouteRow = (FSScheduleRoute)e.Row;

            fsScheduleRouteRow.GlobalSequence = fsScheduleRouteRow.GlobalSequence.PadLeft(5, '0');
            ServiceContracts.View.RequestRefresh();
        }
        protected virtual void FSScheduleRoute_GlobalSequence_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSScheduleRoute fsScheduleRouteRow = (FSScheduleRoute)e.Row;

            fsScheduleRouteRow.GlobalSequence = fsScheduleRouteRow.GlobalSequence.PadLeft(5, '0');
            ServiceContracts.View.RequestRefresh();
        }
        /// <summary>
        /// Force 'required fields' in Route tab to be filled when a new record is inserted.
        /// </summary>
        private void ForceFilling_RequiredFields_RouteTab(PXCache cache, FSRouteContractSchedule fsRouteContractScheduleRow)
        {
            if (cache.GetStatus(fsRouteContractScheduleRow) == PXEntryStatus.Inserted)
            {
                //Making sure that required field (DfltRouteID) in Route tab is going to be filled
                FSScheduleRoute fsScheduleRouteRow = ScheduleRoutes.Current;

                if (fsScheduleRouteRow == null)
                {
                    fsScheduleRouteRow = new FSScheduleRoute();
                    ScheduleRoutes.Insert(fsScheduleRouteRow);
                }
            }
        }
        protected virtual void _(Events.RowPersisting <FSScheduleRoute> e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSScheduleRoute fsScheduleRouteRow = (FSScheduleRoute)e.Row;

            if (e.Operation == PXDBOperation.Insert && fsScheduleRouteRow.DfltRouteID.HasValue == true)
            {
                if (string.IsNullOrEmpty(fsScheduleRouteRow.GlobalSequence))
                {
                    FSScheduleRoute fsScheduleRouteRow_Local = PXSelectGroupBy <FSScheduleRoute,
                                                                                Aggregate <
                                                                                    Max <FSScheduleRoute.globalSequence> > >
                                                               .Select(this);

                    if (fsScheduleRouteRow_Local == null || string.IsNullOrEmpty(fsScheduleRouteRow_Local.GlobalSequence))
                    {
                        fsScheduleRouteRow.GlobalSequence = "00010";
                    }
                    else
                    {
                        fsScheduleRouteRow.GlobalSequence = (int.Parse(fsScheduleRouteRow_Local.GlobalSequence) + 10).ToString("00000");
                    }
                }
                else
                {
                    fsScheduleRouteRow.GlobalSequence = int.Parse(fsScheduleRouteRow.GlobalSequence).ToString("00000");
                }

                fsScheduleRouteRow.SequenceSunday    = fsScheduleRouteRow.GlobalSequence;
                fsScheduleRouteRow.SequenceMonday    = fsScheduleRouteRow.GlobalSequence;
                fsScheduleRouteRow.SequenceTuesday   = fsScheduleRouteRow.GlobalSequence;
                fsScheduleRouteRow.SequenceWednesday = fsScheduleRouteRow.GlobalSequence;
                fsScheduleRouteRow.SequenceThursday  = fsScheduleRouteRow.GlobalSequence;
                fsScheduleRouteRow.SequenceFriday    = fsScheduleRouteRow.GlobalSequence;
                fsScheduleRouteRow.SequenceSaturday  = fsScheduleRouteRow.GlobalSequence;
            }
        }
        public virtual IEnumerable GenerateProjection(PXAdapter adapter)
        {
            if (RouteAppointmentForecastingFilter.Current != null &&
                RouteAppointmentForecastingFilter.Current.DateBegin != null &&
                RouteAppointmentForecastingFilter.Current.DateEnd != null &&
                RouteAppointmentForecastingFilter.Current.DateBegin < RouteAppointmentForecastingFilter.Current.DateEnd)
            {
                DateTime beginFromFilter = RouteAppointmentForecastingFilter.Current.DateBegin.Value;
                DateTime endToFilter     = RouteAppointmentForecastingFilter.Current.DateEnd.Value;
                string   recordType      = ID.RecordType_ServiceContract.ROUTE_SERVICE_CONTRACT;

                int?serviceID          = RouteAppointmentForecastingFilter.Current.ServiceID;
                int?customerID         = RouteAppointmentForecastingFilter.Current.CustomerID;
                int?customerLocationID = RouteAppointmentForecastingFilter.Current.CustomerLocationID;
                int?routeID            = RouteAppointmentForecastingFilter.Current.RouteID;

                PXLongOperation.StartOperation(
                    this,
                    delegate
                {
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        if (beginFromFilter != null && endToFilter != null)
                        {
                            DateHandler requestDate = new DateHandler(endToFilter);

                            var period = new Period((DateTime)beginFromFilter, (DateTime)endToFilter);

                            List <Scheduler.Schedule> scheduleListToProcess = new List <Scheduler.Schedule>();
                            var generator = new TimeSlotGenerator();

                            var fsRouteContractScheduleRecords =
                                PXSelectJoinGroupBy <FSRouteContractSchedule,
                                                     InnerJoin <FSServiceContract,
                                                                On <FSServiceContract.serviceContractID, Equal <FSRouteContractSchedule.entityID> >,
                                                                InnerJoin <FSScheduleRoute,
                                                                           On <FSScheduleRoute.scheduleID, Equal <FSRouteContractSchedule.scheduleID> >,
                                                                           InnerJoin <FSScheduleDet,
                                                                                      On <FSScheduleDet.scheduleID, Equal <FSRouteContractSchedule.scheduleID> > > > >,
                                                     Where <
                                                         FSRouteContractSchedule.entityType, Equal <FSSchedule.entityType.Contract>,
                                                         And <FSServiceContract.recordType, Equal <FSServiceContract.recordType.RouteServiceContract>,
                                                              And <FSRouteContractSchedule.active, Equal <True>,
                                                                   And <FSServiceContract.status, Equal <FSServiceContract.status.Active>,
                                                                        And <FSRouteContractSchedule.startDate, LessEqual <Required <FSRouteContractSchedule.startDate> >,
                                                                             And2 <
                                                                                 Where <
                                                                                     Required <FSScheduleDet.inventoryID>, IsNull,
                                                                                     Or <FSScheduleDet.inventoryID, Equal <Required <FSScheduleDet.inventoryID> > > >,
                                                                                 And2 <
                                                                                     Where <
                                                                                         Required <FSRouteContractSchedule.customerID>, IsNull,
                                                                                         Or <FSRouteContractSchedule.customerID, Equal <Required <FSRouteContractSchedule.customerID> > > >,
                                                                                     And2 <
                                                                                         Where <
                                                                                             Required <FSRouteContractSchedule.customerLocationID>, IsNull,
                                                                                             Or <FSRouteContractSchedule.customerLocationID, Equal <Required <FSRouteContractSchedule.customerLocationID> > > >,
                                                                                         And2 <
                                                                                             Where <
                                                                                                 Required <FSScheduleRoute.dfltRouteID>, IsNull,
                                                                                                 Or <FSScheduleRoute.dfltRouteID, Equal <Required <FSScheduleRoute.dfltRouteID> > > >,
                                                                                             And <
                                                                                                 Where <FSRouteContractSchedule.endDate, IsNull,
                                                                                                        Or <FSRouteContractSchedule.endDate, GreaterEqual <Required <FSRouteContractSchedule.startDate> > > > > > > > > > > > > >,
                                                     Aggregate <
                                                         GroupBy <FSRouteContractSchedule.scheduleID> > >
                                .Select(this, beginFromFilter, serviceID, serviceID, customerID, customerID, customerLocationID, customerLocationID, routeID, routeID, endToFilter);

                            foreach (FSRouteContractSchedule fsRouteContractScheduleRecord in fsRouteContractScheduleRecords)
                            {
                                List <Scheduler.Schedule> mapScheduleResults = MapFSScheduleToSchedule.convertFSScheduleToSchedule(RouteAppointmentForecastingFilter.Cache, fsRouteContractScheduleRecord, endToFilter, recordType);

                                foreach (Scheduler.Schedule mapSchedule in mapScheduleResults)
                                {
                                    scheduleListToProcess.Add(mapSchedule);
                                }
                            }

                            if (recordType == ID.RecordType_ServiceContract.ROUTE_SERVICE_CONTRACT)
                            {
                                foreach (Scheduler.Schedule schedule in scheduleListToProcess)
                                {
                                    schedule.Priority      = (int?)RouteScheduleProcess.SetSchedulePriority(schedule, this);
                                    schedule.RouteInfoList = RouteScheduleProcess.getRouteListFromSchedule(schedule, this);
                                }
                            }

                            List <TimeSlot> timeSlots = generator.GenerateCalendar(period, scheduleListToProcess);

                            var fsRouteAppointmentForecastingRecords =
                                PXSelect <FSRouteAppointmentForecasting,
                                          Where <
                                              FSRouteAppointmentForecasting.startDate, GreaterEqual <Required <FSRouteAppointmentForecasting.startDate> >,
                                              And <
                                                  FSRouteAppointmentForecasting.startDate, LessEqual <Required <FSRouteAppointmentForecasting.startDate> > > > >
                                .Select(this, beginFromFilter, endToFilter);

                            PXCache <FSRouteAppointmentForecasting> cacheRouteForecasting = new PXCache <FSRouteAppointmentForecasting>(this);

                            foreach (FSRouteAppointmentForecasting fsRouteAppointmentDetailProjectionRecord in fsRouteAppointmentForecastingRecords)
                            {
                                cacheRouteForecasting.PersistDeleted(fsRouteAppointmentDetailProjectionRecord);
                            }

                            foreach (TimeSlot timeSlot in timeSlots)
                            {
                                requestDate.setDate(timeSlot.DateTimeBegin);

                                FSSchedule fsScheduleRow = ScheduleSelected.Select(timeSlot.ScheduleID);

                                FSScheduleRoute fsScheduleRouteRow = ScheduleRouteSelected.Select(fsScheduleRow.ScheduleID);

                                FSServiceContract fsServiceContractRow = ServiceContractSelected.Select(fsScheduleRow.EntityID);

                                FSRouteAppointmentForecasting fsRouteAppointmentForecastingRow = new FSRouteAppointmentForecasting();

                                fsRouteAppointmentForecastingRow.RouteID            = fsScheduleRouteRow.DfltRouteID;
                                fsRouteAppointmentForecastingRow.StartDate          = requestDate.StartOfDay();
                                fsRouteAppointmentForecastingRow.ScheduleID         = fsScheduleRow.ScheduleID;
                                fsRouteAppointmentForecastingRow.ServiceContractID  = fsServiceContractRow.ServiceContractID;
                                fsRouteAppointmentForecastingRow.CustomerLocationID = fsServiceContractRow.CustomerLocationID;
                                fsRouteAppointmentForecastingRow.CustomerID         = fsServiceContractRow.CustomerID;
                                fsRouteAppointmentForecastingRow.SequenceOrder      = int.Parse(fsScheduleRouteRow.GlobalSequence);

                                cacheRouteForecasting.PersistInserted(fsRouteAppointmentForecastingRow);
                            }
                        }

                        ts.Complete();
                    }
                });
            }

            return(adapter.Get());
        }
        /// <summary>
        /// Create an Appointment from a TimeSlot.
        /// </summary>
        protected void CreateAppointment(FSServiceOrder fsServiceOrderRow,
                                         TimeSlot timeSlotAppointment,
                                         FSSchedule fsScheduleRow,
                                         bool insertingFromServiceOrder,
                                         bool isARouteAppointment,
                                         bool isPrepaidContract)
        {
            if (graphAppointmentEntry != null)
            {
                graphAppointmentEntry.Clear(PXClearOption.ClearAll);
            }
            else
            {
                graphAppointmentEntry = PXGraph.CreateInstance <AppointmentEntry>();
                graphAppointmentEntry.CalculateGoogleStats                = false;
                graphAppointmentEntry.AvoidCalculateRouteStats            = true;
                graphAppointmentEntry.IsGeneratingAppointment             = true;
                graphAppointmentEntry.DisableServiceOrderUnboundFieldCalc = true;
            }

            graphAppointmentEntry.SkipManualTimeFlagUpdate = true;

            FSScheduleRoute fsScheduleRouteRow = null;

            if (isARouteAppointment == true)
            {
                fsScheduleRouteRow = PXSelect <FSScheduleRoute,
                                               Where <
                                                   FSScheduleRoute.scheduleID, Equal <Required <FSScheduleRoute.scheduleID> > > >
                                     .Select(this, fsServiceOrderRow.ScheduleID);
            }

            FSAppointment fsAppointmentRow = new FSAppointment();

            fsAppointmentRow.SrvOrdType = fsServiceOrderRow.SrvOrdType;

            #region Setting flags for recurring appointments
            fsAppointmentRow.ValidatedByDispatcher = false;
            fsAppointmentRow.GeneratedBySystem     = true;
            fsAppointmentRow.Status = ID.Status_Appointment.AUTOMATIC_SCHEDULED;

            fsAppointmentRow = graphAppointmentEntry.AppointmentRecords.Insert(fsAppointmentRow);

            graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.soRefNbr>(graphAppointmentEntry.AppointmentRecords.Current, fsServiceOrderRow.RefNbr);
            graphAppointmentEntry.AppointmentRecords.Cache.SetValueExt <FSAppointment.docDesc>(fsAppointmentRow, fsServiceOrderRow.DocDesc);

            if (isARouteAppointment)
            {
                graphAppointmentEntry.AppointmentRecords.Cache.SetValueExt <FSAppointment.scheduledDateTimeBegin>(fsAppointmentRow, timeSlotAppointment.DateTimeBegin);
                graphAppointmentEntry.AppointmentRecords.Cache.SetValueExt <FSAppointment.scheduledDateTimeEnd>(fsAppointmentRow, timeSlotAppointment.DateTimeEnd);
            }
            else
            {
                DateTime?scheduledDateTimeBegin = PXDBDateAndTimeAttribute.CombineDateTime(timeSlotAppointment.DateTimeBegin, fsScheduleRow.ScheduleStartTime);
                graphAppointmentEntry.AppointmentRecords.Cache.SetValueExt <FSAppointment.scheduledDateTimeBegin>(fsAppointmentRow, scheduledDateTimeBegin);
            }

            graphAppointmentEntry.AppointmentRecords.Cache.SetValueExt <FSAppointment.serviceContractID>(fsAppointmentRow, fsServiceOrderRow.ServiceContractID);

            if (isPrepaidContract == true &&
                graphAppointmentEntry.BillingCycleRelated.Current != null &&
                graphAppointmentEntry.BillingCycleRelated.Current.BillingBy == ID.Billing_By.APPOINTMENT)
            {
                graphAppointmentEntry.AppointmentRecords.Cache.SetValueExt <FSAppointment.billServiceContractID>(fsAppointmentRow, fsServiceOrderRow.ServiceContractID);
            }

            fsAppointmentRow = graphAppointmentEntry.AppointmentRecords.Current;

            //Total times get initialized
            fsAppointmentRow.EstimatedDurationTotal = 0;
            fsAppointmentRow.ActualDurationTotal    = 0;

            fsAppointmentRow.ScheduleID        = fsServiceOrderRow.ScheduleID;
            fsAppointmentRow.ServiceContractID = fsServiceOrderRow.ServiceContractID;
            fsAppointmentRow.GenerationID      = fsServiceOrderRow.GenerationID;

            fsAppointmentRow.SalesPersonID  = fsServiceOrderRow.SalesPersonID;
            fsAppointmentRow.Commissionable = fsServiceOrderRow.Commissionable;
            #endregion

            #region Setting route
            if (fsScheduleRouteRow != null)
            {
                switch (timeSlotAppointment.DateTimeBegin.DayOfWeek)
                {
                case DayOfWeek.Sunday:
                    if (fsScheduleRouteRow.RouteIDSunday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDSunday;
                    }

                    break;

                case DayOfWeek.Monday:
                    if (fsScheduleRouteRow.RouteIDMonday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDMonday;
                    }

                    break;

                case DayOfWeek.Tuesday:
                    if (fsScheduleRouteRow.RouteIDTuesday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDTuesday;
                    }

                    break;

                case DayOfWeek.Wednesday:
                    if (fsScheduleRouteRow.RouteIDWednesday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDWednesday;
                    }

                    break;

                case DayOfWeek.Thursday:
                    if (fsScheduleRouteRow.RouteIDThursday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDThursday;
                    }

                    break;

                case DayOfWeek.Friday:
                    if (fsScheduleRouteRow.RouteIDFriday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDFriday;
                    }

                    break;

                case DayOfWeek.Saturday:
                    if (fsScheduleRouteRow.RouteIDSaturday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDSaturday;
                    }

                    break;
                }

                if (fsAppointmentRow.RouteID == null)
                {
                    fsAppointmentRow.RouteID = fsScheduleRouteRow.DfltRouteID;
                }

                fsAppointmentRow.RoutePosition = int.Parse(fsScheduleRouteRow.GlobalSequence);

                if (fsAppointmentRow.DeliveryNotes == null)
                {
                    fsAppointmentRow.DeliveryNotes = fsScheduleRouteRow.DeliveryNotes;
                }
            }
            #endregion

            #region Setting Appointment Details
            foreach (FSSODet fsSODetRow in graphServiceOrderEntry.ServiceOrderDetails.Select())
            {
                var fsAppointmentDetRow = new FSAppointmentDet();

                fsAppointmentDetRow.ScheduleID    = fsSODetRow.ScheduleID;
                fsAppointmentDetRow.ScheduleDetID = fsSODetRow.ScheduleDetID;

                AppointmentEntry.InsertDetailLine <FSAppointmentDet, FSSODet>(graphAppointmentEntry.AppointmentDetails.Cache,
                                                                              fsAppointmentDetRow,
                                                                              graphServiceOrderEntry.ServiceOrderDetails.Cache,
                                                                              fsSODetRow,
                                                                              fsSODetRow.NoteID,
                                                                              fsSODetRow.SODetID,
                                                                              copyTranDate: false,
                                                                              tranDate: fsSODetRow.TranDate,
                                                                              SetValuesAfterAssigningSODetID: false,
                                                                              copyingFromQuote: false);
            }

            foreach (FSSOEmployee fsSOEmployeeRow in graphServiceOrderEntry.ServiceOrderEmployees.Select())
            {
                FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee();
                fsAppointmentEmployeeRow.EmployeeID = fsSOEmployeeRow.EmployeeID;
                graphAppointmentEntry.AppointmentServiceEmployees.Insert(fsAppointmentEmployeeRow);
            }
            #endregion

            if (fsScheduleRow.VendorID != null)
            {
                FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee();
                fsAppointmentEmployeeRow.EmployeeID = fsScheduleRow.VendorID;
                graphAppointmentEntry.AppointmentServiceEmployees.Insert(fsAppointmentEmployeeRow);
            }

            graphAppointmentEntry.Save.Press();
        }