示例#1
0
        public virtual string GetItemStatusFromLog(FSAppointmentDet appointmentDet)
        {
            if (appointmentDet != null &&
                (appointmentDet.LineType == ID.LineType_ALL.SERVICE ||
                 appointmentDet.LineType == ID.LineType_ALL.NONSTOCKITEM))
            {
                IEnumerable <FSAppointmentLog> itemLogRecords = LogRecords.Select().RowCast <FSAppointmentLog>().Where(_ => _.DetLineRef == appointmentDet.LineRef);
                bool anyInProcess = itemLogRecords.Where(_ => _.Status == ID.Status_Log.IN_PROCESS).Any();

                if (anyInProcess == false)
                {
                    if (itemLogRecords.Count() > 0)
                    {
                        if (appointmentDet.Status == ID.Status_AppointmentDet.COMPLETED ||
                            appointmentDet.Status == ID.Status_AppointmentDet.NOT_FINISHED)
                        {
                            return(appointmentDet.Status);
                        }
                        else
                        {
                            return(ID.Status_AppointmentDet.COMPLETED);
                        }
                    }
                }
                else
                {
                    return(ID.Status_AppointmentDet.IN_PROCESS);
                }
            }

            return(ID.Status_AppointmentDet.NOT_STARTED);
        }
示例#2
0
        public virtual void ClearSourceLineBeforeCopy(FSAppointmentDet apptDet)
        {
            //TODO - This sould be delete in 2020R2
            if (apptDet.Status == ID.Status_AppointmentDet.NOT_PERFORMED &&
                apptDet.ManualPrice == true)
            {
                apptDet.ManualPrice = false;
            }

            apptDet.Status = ID.Status_AppointmentDet.NOT_STARTED;

            apptDet.ActualDuration = 0;
            apptDet.Qty            = 0;

            apptDet.CuryTranAmt = 0;

            apptDet.CuryBillableExtPrice = 0;

            apptDet.CuryBillableTranAmt = 0;

            apptDet.PostID = null;
            apptDet.NoteID = null;

            apptDet.LogActualDuration = 0;
        }
示例#3
0
        public virtual void StartNonStockAction(FSAppointmentDet fsAppointmentDet)
        {
            if (fsAppointmentDet == null)
            {
                return;
            }

            FSAppointmentLog fsAppointmentLogRow = new FSAppointmentLog()
            {
                Type           = ID.Type_Log.NON_STOCK,
                BAccountID     = null,
                DetLineRef     = fsAppointmentDet.LineRef,
                DateTimeBegin  = PXDBDateAndTimeAttribute.CombineDateTime(AppointmentRecords.Current.ExecutionDate, PXTimeZoneInfo.Now),
                TimeDuration   = fsAppointmentDet.EstimatedDuration ?? 0,
                Status         = ID.Status_Log.IN_PROCESS,
                TrackTime      = false,
                Descr          = fsAppointmentDet.TranDesc,
                TrackOnService = true,
                ProjectID      = fsAppointmentDet.ProjectID,
                ProjectTaskID  = fsAppointmentDet.ProjectTaskID,
                CostCodeID     = fsAppointmentDet.CostCodeID
            };

            LogRecords.Cache.Insert(fsAppointmentLogRow);

            this.Actions.PressSave();
        }
        /// <summary>
        /// Gets the information of the Appointment and AppointmentInventoryItem using as reference the [appointmentID] and [appointmentInventoryItemID].
        /// </summary>
        private SharedClasses.AppointmentInventoryItemInfo GetAppointmentInventoryItemInfo(int?appointmentID, int?appDetID, int index)
        {
            PXResult <FSAppointment, FSServiceOrder, FSSrvOrdType, FSAppointmentInventoryItem, FSAppointmentDet> bqlResult =
                (PXResult <FSAppointment, FSServiceOrder, FSSrvOrdType, FSAppointmentInventoryItem, FSAppointmentDet>)
                PXSelectReadonly2 <FSAppointment,
                                   InnerJoin <FSServiceOrder,
                                              On <FSServiceOrder.sOID, Equal <FSAppointment.sOID>,
                                                  And <FSAppointment.appointmentID, Equal <Required <FSAppointment.appointmentID> > > >,
                                              InnerJoin <FSSrvOrdType,
                                                         On <FSSrvOrdType.srvOrdType, Equal <FSAppointment.srvOrdType> >,
                                                         InnerJoin <FSAppointmentInventoryItem,
                                                                    On <FSAppointmentInventoryItem.appointmentID, Equal <FSAppointment.appointmentID>,
                                                                        And <FSAppointmentInventoryItem.appDetID, Equal <Required <FSAppointmentInventoryItem.appDetID> > > >,
                                                                    InnerJoin <FSAppointmentDet,
                                                                               On <FSAppointmentDet.sODetID, Equal <FSAppointmentInventoryItem.sODetID> > > > > > >
                .Select(this, appointmentID, appDetID);

            SharedClasses.AppointmentInventoryItemInfo appointmentInfoToReturn = new SharedClasses.AppointmentInventoryItemInfo();

            if (bqlResult != null)
            {
                FSAppointment              fsAppointmentRow              = (FSAppointment)bqlResult;
                FSServiceOrder             fsServiceOrderRow             = (FSServiceOrder)bqlResult;
                FSSrvOrdType               fsSrvOrdTypeRow               = (FSSrvOrdType)bqlResult;
                FSAppointmentInventoryItem fsAppointmentInventoryItemRow = (FSAppointmentInventoryItem)bqlResult;
                FSAppointmentDet           fsAppointmentDetRow           = (FSAppointmentDet)bqlResult;

                appointmentInfoToReturn = new SharedClasses.AppointmentInventoryItemInfo(fsAppointmentRow, fsServiceOrderRow, fsSrvOrdTypeRow, fsAppointmentDetRow, fsAppointmentInventoryItemRow, index);
            }

            return(appointmentInfoToReturn);
        }
示例#5
0
            private int?GetAcct(PXGraph graph,
                                IFSSODetBase fsSODetBase,
                                FSAppointmentDet fsAppointmentInventoryItem,
                                FSServiceOrder fsServiceOrderRow,
                                FSSrvOrdType fsSrvOrdTypeRow)
            {
                int?acctID = null;

                if (fsSODetBase != null)
                {
                    if (fsSODetBase.AcctID != null)
                    {
                        acctID = fsSODetBase.AcctID;
                    }
                    else
                    {
                        acctID = ServiceOrderCore.Get_TranAcctID_DefaultValue(graph,
                                                                              fsSrvOrdTypeRow.SalesAcctSource,
                                                                              fsSODetBase.InventoryID,
                                                                              fsSODetBase.SiteID,
                                                                              fsServiceOrderRow);
                    }
                }
                else if (fsAppointmentInventoryItem != null)
                {
                    acctID = ServiceOrderCore.Get_TranAcctID_DefaultValue(graph,
                                                                          fsSrvOrdTypeRow.SalesAcctSource,
                                                                          fsAppointmentInventoryItem.InventoryID,
                                                                          fsAppointmentInventoryItem.SiteID,
                                                                          fsServiceOrderRow);
                }

                return(acctID);
            }
 protected virtual IAddressBase GetToAddress(FSServiceOrder order, FSAppointmentDet line)
 {
     /*if (order.WillCall == true && line.SiteID != null && !(line.POCreate == true && line.POSource == INReplenishmentSource.DropShipToOrder))
      *  return GetFromAddress(order, line); // will call
      * else*/
     return(GetToAddress(order));
 }
示例#7
0
        public virtual FSAppointmentLog ProcessCompleteLog(DateTime dateTimeEnd, string newApptDetStatus, FSAppointmentLog logRow, List <FSAppointmentDet> apptDetRows)
        {
            if (logRow == null)
            {
                return(null);
            }

            logRow = PXCache <FSAppointmentLog> .CreateCopy(logRow);

            logRow.Status = ID.Status_Log.COMPLETED;
            if (logRow.KeepDateTimes == false)
            {
                logRow.DateTimeEnd = dateTimeEnd;
            }

            if (apptDetRows != null && string.IsNullOrWhiteSpace(logRow.DetLineRef) == false)
            {
                FSAppointmentDet apptDet = apptDetRows.Where(r => r.LineRef == logRow.DetLineRef).FirstOrDefault();
                if (apptDet != null)
                {
                    ProcessStopItemLine(apptDet, newApptDetStatus);
                }
            }

            return((FSAppointmentLog)LogRecords.Cache.Update(logRow));
        }
示例#8
0
 private static object GetProjectTaskIDToUseInEPActivityApprove(FSAppointment fsAppointmentRow,
                                                                FSAppointmentLog fsAppointmentLogRow,
                                                                FSAppointmentDet fsAppointmentDetRow)
 {
     if (fsAppointmentLogRow != null && fsAppointmentLogRow.DetLineRef != null && fsAppointmentDetRow != null)
     {
         return(fsAppointmentDetRow.ProjectTaskID);
     }
     else
     {
         return(fsAppointmentRow.DfltProjectTaskID);
     }
 }
示例#9
0
        public virtual void CompleteAction(FSAppointmentDet apptDet, IEnumerable <ILogDetail> completeLogItems, DateTime?dateTimeEnd, PXSelectBase <FSAppointmentLog> logSelect, params object[] logSelectArgs)
        {
            int rowsAffected = CompleteMultipleLogs(dateTimeEnd, ID.Status_AppointmentDet.COMPLETED, apptDet != null ? false : true, completeLogItems, logSelect, logSelectArgs);

            if (apptDet != null)
            {
                rowsAffected += ProcessStopItemLine(apptDet, ID.Status_AppointmentDet.COMPLETED);
            }

            if (rowsAffected > 0)
            {
                this.Actions.PressSave();
            }
        }
示例#10
0
        public ContractInvoiceLine(PXResult <FSAppointmentDet, FSSODet, FSAppointment> row) : this((IDocLine)(FSAppointmentDet)row)
        {
            FSAppointmentDet fsAppointmentDetRow = (FSAppointmentDet)row;
            FSAppointment    fsAppointmentRow    = (FSAppointment)row;
            FSSODet          fsSODetRow          = (FSSODet)row;

            AppointmentID = fsAppointmentDetRow.AppointmentID;
            AppDetID      = fsAppointmentDetRow.AppDetID;

            BillingRule      = fsSODetRow.BillingRule;
            ContractRelated  = fsAppointmentDetRow.ContractRelated;
            Qty              = fsAppointmentDetRow.ContractRelated == true ? fsAppointmentDetRow.Qty : fsAppointmentDetRow.BillableQty;
            OverageItemPrice = fsAppointmentDetRow.OverageItemPrice;
            SalesPersonID    = fsAppointmentRow.SalesPersonID;
            Commissionable   = fsAppointmentRow.Commissionable;
        }
示例#11
0
 public AppointmentInventoryItemInfo(FSAppointment fsAppointmentRow,
                                     FSServiceOrder fsServiceOrderRow,
                                     FSSrvOrdType fsSrvOrdTypeRow,
                                     FSAppointmentDet fsAppointmentDet,
                                     FSAppointmentDet fsAppointmentInventoryItemRow,
                                     int index)
 {
     this.FSAppointmentRow           = fsAppointmentRow;
     this.FSServiceOrderRow          = fsServiceOrderRow;
     this.FSSrvOrdTypeRow            = fsSrvOrdTypeRow;
     this.FSAppointmentDet           = fsAppointmentDet;
     this.FSAppointmentInventoryItem = fsAppointmentInventoryItemRow;
     this.AppointmentID = fsAppointmentRow.AppointmentID;
     this.ServiceType   = fsAppointmentDet.ServiceType;
     this.Index         = index;
 }
        public virtual IEnumerable ViewPostBatch(PXAdapter adapter)
        {
            if (Appointments.Current != null)
            {
                FSAppointmentDet fsAppointmentInventoryItemRow = Appointments.Current;

                if (!string.IsNullOrEmpty(fsAppointmentInventoryItemRow.Mem_BatchNbr))
                {
                    graphUpdatePostBatchMaint.BatchRecords.Current = graphUpdatePostBatchMaint.BatchRecords.Search <FSPostBatch.batchNbr>(fsAppointmentInventoryItemRow.Mem_BatchNbr);
                    throw new PXRedirectRequiredException(graphUpdatePostBatchMaint, null)
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
            }

            return(adapter.Get());
        }
示例#13
0
        private static string GetDescriptionToUseInEPActivityApprove(FSAppointment fsAppointmentRow,
                                                                     FSAppointmentLog fsAppointmentLogRow,
                                                                     FSAppointmentDet fsAppointmentDetRow)
        {
            if (fsAppointmentLogRow != null)
            {
                if (fsAppointmentLogRow.Type == ID.Type_Log.TRAVEL)
                {
                    return(fsAppointmentLogRow.Descr);
                }
                else if (fsAppointmentLogRow.DetLineRef != null &&
                         fsAppointmentDetRow != null)
                {
                    return(fsAppointmentDetRow.TranDesc);
                }
            }

            return(fsAppointmentRow.DocDesc);
        }
示例#14
0
 public FSProfitability(FSAppointmentDet fsAppointmentDetRow)
 {
     this.LineRef         = fsAppointmentDetRow.LineRef;
     this.LineType        = fsAppointmentDetRow.LineType;
     this.ItemID          = fsAppointmentDetRow.InventoryID;
     this.Descr           = fsAppointmentDetRow.TranDesc;
     this.UnitPrice       = fsAppointmentDetRow.CuryUnitPrice;
     this.EstimatedQty    = fsAppointmentDetRow.EstimatedQty;
     this.EstimatedAmount = fsAppointmentDetRow.CuryEstimatedTranAmt;
     this.ActualDuration  = fsAppointmentDetRow.IsService ? fsAppointmentDetRow.ActualDuration : 0;
     this.ActualQty       = fsAppointmentDetRow.Qty;
     this.ActualAmount    = fsAppointmentDetRow.CuryTranAmt;
     this.BillableQty     = fsAppointmentDetRow.BillableQty;
     this.BillableAmount  = fsAppointmentDetRow.CuryBillableTranAmt;
     this.UnitCost        = fsAppointmentDetRow.CuryUnitCost;
     this.CostTotal       = this.BillableQty * this.UnitCost;
     this.Profit          = Math.Round((decimal)this.BillableAmount, 2) - Math.Round((decimal)this.CostTotal, 2);
     this.ProfitPercent   = this.CostTotal == 0.0m ? 0.0m : (this.Profit / this.CostTotal) * 100;
 }
示例#15
0
        public virtual void RunLogAction(string action, string type, FSAppointmentDet apptDet, PXSelectBase <FSAppointmentLog> logSelect, params object[] logSelectArgs)
        {
            if (type != ID.Type_Log.NON_STOCK)
            {
                VerifyBeforeTransaction(action, type);
            }

            if (this.SkipLongOperation == false)
            {
                PXLongOperation.StartOperation(this,
                                               delegate()
                {
                    RunLogActionBase(action, type, apptDet, logSelect, logSelectArgs);
                });
            }
            else
            {
                RunLogActionBase(action, type, apptDet, logSelect, logSelectArgs);
            }
        }
示例#16
0
        public virtual void CloneServices(AppointmentEntry gOriginalAppt, AppointmentEntry gNewAppt, FSAppointment newAppointmentRow, FSAppointmentDet sourceRow, Dictionary <string, string> itemLineRef)
        {
            if (sourceRow == null || sourceRow.Status == ID.Status_AppointmentDet.CANCELED)
            {
                return;
            }

            // Creates a copy to not edit the original row.
            FSAppointmentDet sourceRowCopy = PXCache <FSAppointmentDet> .CreateCopy(sourceRow);

            ClearSourceLineBeforeCopy(sourceRowCopy);

            FSAppointmentDet newRow = new FSAppointmentDet();

            newRow = AppointmentEntry.InsertDetailLine <FSAppointmentDet, FSAppointmentDet>(
                gNewAppt.AppointmentDetails.Cache,
                newRow,
                gOriginalAppt.AppointmentDetails.Cache,
                sourceRowCopy,
                null,
                sourceRowCopy.SODetID,
                copyTranDate: false,
                tranDate: sourceRowCopy.TranDate,
                SetValuesAfterAssigningSODetID: true,
                copyingFromQuote: false);

            PXNoteAttribute.CopyNoteAndFiles(
                gOriginalAppt.AppointmentDetails.Cache,
                sourceRow,
                gNewAppt.AppointmentDetails.Cache,
                newRow,
                copyNotes: true,
                copyFiles: false);


            gNewAppt.AppointmentDetails.SetValueExt <FSAppointmentDet.acctID>(newRow, sourceRowCopy.AcctID);
            gNewAppt.AppointmentDetails.SetValueExt <FSAppointmentDet.subID>(newRow, sourceRowCopy.SubID);

            itemLineRef.Add(sourceRow.LineRef, newRow.LineRef);
        }
示例#17
0
        public virtual void SetLogInfoFromDetails(PXCache cache, FSAppointmentLog fsLogRow)
        {
            string logType = fsLogRow.Travel == true ? ID.Type_Log.TRAVEL : ID.Type_Log.SERVICE;

            if (fsLogRow.DetLineRef != null)
            {
                FSAppointmentDet fsAppointmentDetRow = AppointmentDetails.Select().RowCast <FSAppointmentDet>().Where(_ => _.LineRef == fsLogRow.DetLineRef).FirstOrDefault();

                if (fsAppointmentDetRow != null)
                {
                    fsLogRow.Descr = fsAppointmentDetRow.TranDesc;
                    if (fsAppointmentDetRow.IsTravelItem == true)
                    {
                        logType = ID.Type_Log.TRAVEL;
                    }
                    else if (fsAppointmentDetRow.LineType == ID.LineType_ALL.NONSTOCKITEM)
                    {
                        logType = ID.Type_Log.NON_STOCK;
                    }
                    else
                    {
                        logType = ID.Type_Log.SERVICE;
                    }
                }
            }
            else if (fsLogRow.BAccountID != null)
            {
                if (fsLogRow.Travel == true)
                {
                    logType = ID.Type_Log.TRAVEL;
                }
                else
                {
                    logType = ID.Type_Log.STAFF_ASSIGMENT;
                }
            }

            cache.SetValueExt <FSAppointmentLog.type>(fsLogRow, logType);
        }
        protected virtual IAddressBase GetFromAddress(FSServiceOrder order, FSAppointmentDet line)
        {
            IAddressBase returnAddress = null;

            if (line.SiteID != null)
            {
                returnAddress = PXSelectJoin <Address,
                                              InnerJoin <INSite, On <Address.addressID, Equal <INSite.addressID> > >,
                                              Where <
                                                  INSite.siteID, Equal <Required <INSite.siteID> > > >
                                .Select(Base, line.SiteID)
                                .RowCast <Address>()
                                .FirstOrDefault();
            }

            if (returnAddress == null)
            {
                returnAddress = GetFromAddress(order);
            }

            return(returnAddress);
        }
        protected virtual void VerifyIsAlreadyPosted <Field>(PXCache cache, FSAppointmentDet fsAppointmentDetRow, FSAppointmentInventoryItem fsAppointmentInventoryItemRow, FSBillingCycle billingCycleRow)
            where Field : class, IBqlField
        {
            if ((fsAppointmentDetRow == null && fsAppointmentInventoryItemRow == null) || ServiceOrderRelated.Current == null || billingCycleRow == null)
            {
                return;
            }

            IFSSODetBase row   = null;
            int?         pivot = -1;

            if (fsAppointmentDetRow != null)
            {
                row   = fsAppointmentDetRow;
                pivot = fsAppointmentDetRow.SODetID;
            }
            else if (fsAppointmentInventoryItemRow != null)
            {
                row   = fsAppointmentInventoryItemRow;
                pivot = fsAppointmentInventoryItemRow.AppDetID > 0 ? fsAppointmentInventoryItemRow.AppDetID : null;
            }

            PXEntryStatus status            = ServiceOrderRelated.Cache.GetStatus(ServiceOrderRelated.Current);
            bool          needsVerify       = status == PXEntryStatus.Updated || status == PXEntryStatus.Notchanged;
            bool          isSOAlreadyPosted = ServiceOrderPostedIn.Select().Count > 0;

            if (needsVerify == true &&
                pivot == null &&
                IsInstructionOrComment(row) == false &&
                billingCycleRow.BillingBy == ID.Billing_By.SERVICE_ORDER &&
                isSOAlreadyPosted == true)
            {
                cache.RaiseExceptionHandling <Field>(row,
                                                     row.InventoryID,
                                                     new PXSetPropertyException(
                                                         PXMessages.LocalizeFormat(TX.Error.CANNOT_ADD_INVENTORY_TYPE_LINES_BECAUSE_SO_POSTED, GetLineType(row.LineType)),
                                                         PXErrorLevel.RowError));
            }
        }
        private FSAppointmentDetUNION CreateTaxRow(FSAppointmentDet baseRow)
        {
            var taxRow = new FSAppointmentDetUNION()
            {
                SrvOrdType    = baseRow.SrvOrdType,
                RefNbr        = baseRow.RefNbr,
                AppointmentID = baseRow.AppointmentID,
                ApptLineNbr   = baseRow.ApptLineNbr,
                SODetID       = baseRow.SODetID,
                LineRef       = baseRow.LineRef,
                AppDetID      = baseRow.AppDetID,

                CuryInfoID           = baseRow.CuryInfoID,
                TaxCategoryID        = baseRow.TaxCategoryID,
                GroupDiscountRate    = baseRow.GroupDiscountRate,
                SiteID               = baseRow.SiteID,
                SiteLocationID       = baseRow.SiteLocationID,
                DocumentDiscountRate = baseRow.DocumentDiscountRate,
                CuryEstimatedTranAmt = baseRow.CuryEstimatedTranAmt,
                CuryBillableTranAmt  = baseRow.CuryBillableTranAmt,
            };

            return(taxRow);
        }
示例#21
0
        /// <summary>
        /// Resets certain Log fields when there's no employee selected.
        /// </summary>
        /// <param name="fsLogRow"></param>
        public virtual void ResetLogFieldsNoEmployee(FSAppointmentLog fsLogRow)
        {
            if (fsLogRow.BAccountID == null)
            {
                fsLogRow.EarningType = null;
                fsLogRow.LaborItemID = null;

                FSAppointmentDet fsAppointmentDetRow = null;

                if (string.IsNullOrWhiteSpace(fsLogRow.DetLineRef) == false)
                {
                    fsAppointmentDetRow = AppointmentDetails.Select().RowCast <FSAppointmentDet>().Where(_ => _.LineRef == fsLogRow.DetLineRef).FirstOrDefault();
                }

                if (fsAppointmentDetRow != null &&
                    (fsAppointmentDetRow.LineType == ID.LineType_ALL.SERVICE ||
                     fsAppointmentDetRow.LineType == ID.LineType_ALL.NONSTOCKITEM))
                {
                    fsLogRow.ProjectID     = fsAppointmentDetRow.ProjectID;
                    fsLogRow.ProjectTaskID = fsAppointmentDetRow.ProjectTaskID;
                    fsLogRow.CostCodeID    = fsAppointmentDetRow.CostCodeID;
                }
            }
        }
        /// <summary>
        /// Launches the AppointmentEntry screen with some preloaded values.
        /// </summary>
        /// <param name="fsWrkProcessRow"><c>FSWrkProcess</c> row.</param>
        private void LaunchAppointmentEntryScreen(FSWrkProcess fsWrkProcessRow)
        {
            AppointmentEntry graphAppointmentEntry = PXGraph.CreateInstance <AppointmentEntry>();

            FSAppointment  fsAppointmentRow  = new FSAppointment();
            FSServiceOrder fsServiceOrderRow = GetServiceOrder(fsWrkProcessRow);

            fsAppointmentRow.SrvOrdType = GetSrvOrdType(fsWrkProcessRow, fsServiceOrderRow);

            if (fsAppointmentRow.SrvOrdType == null)
            {
                throw new PXException(TX.Error.DEFAULT_SERVICE_ORDER_TYPE_NOT_PROVIDED);
            }

            if (fsAppointmentRow.SOID == null)
            {
                SharedFunctions.ValidateSrvOrdTypeNumberingSequence(this, fsAppointmentRow.SrvOrdType);
            }

            graphAppointmentEntry.AppointmentRecords.Current = graphAppointmentEntry.AppointmentRecords.Insert(fsAppointmentRow);

            #region ScheduleDateTime Fields
            // to know if we want to set false to the flag KeepTotalServicesDuration
            bool scheduleTimeFlag = true;

            if (fsWrkProcessRow.ScheduledDateTimeBegin.HasValue == true)
            {
                graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.scheduledDateTimeBegin>
                    (graphAppointmentEntry.AppointmentRecords.Current, fsWrkProcessRow.ScheduledDateTimeBegin);
            }
            else
            {
                scheduleTimeFlag = false;
            }

            if (fsWrkProcessRow.ScheduledDateTimeEnd.HasValue && scheduleTimeFlag)
            {
                graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.handleManuallyScheduleTime>
                    (graphAppointmentEntry.AppointmentRecords.Current, true);

                if (fsWrkProcessRow.ScheduledDateTimeBegin != fsWrkProcessRow.ScheduledDateTimeEnd)
                {
                    graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.scheduledDateTimeEnd>
                        (graphAppointmentEntry.AppointmentRecords.Current, fsWrkProcessRow.ScheduledDateTimeEnd);
                }
                else
                {
                    graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.scheduledDateTimeEnd>
                        (graphAppointmentEntry.AppointmentRecords.Current, fsWrkProcessRow.ScheduledDateTimeBegin.Value.AddHours(1));
                }
            }

            #endregion

            #region ServiceOrder Fields

            if (fsServiceOrderRow == null)
            {
                if (fsWrkProcessRow.BranchID.HasValue == true)
                {
                    graphAppointmentEntry.ServiceOrderRelated.SetValueExt <FSServiceOrder.branchID>
                        (graphAppointmentEntry.ServiceOrderRelated.Current, fsWrkProcessRow.BranchID);
                }

                if (fsWrkProcessRow.BranchLocationID.HasValue == true && fsWrkProcessRow.BranchLocationID > 0)
                {
                    graphAppointmentEntry.ServiceOrderRelated.SetValueExt <FSServiceOrder.branchLocationID>
                        (graphAppointmentEntry.ServiceOrderRelated.Current, fsWrkProcessRow.BranchLocationID);
                }

                if (fsWrkProcessRow.CustomerID.HasValue == true && fsWrkProcessRow.CustomerID > 0)
                {
                    graphAppointmentEntry.ServiceOrderRelated.SetValueExt <FSServiceOrder.customerID>
                        (graphAppointmentEntry.ServiceOrderRelated.Current, fsWrkProcessRow.CustomerID);
                }
            }
            else
            {
                graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.soRefNbr>
                    (graphAppointmentEntry.AppointmentRecords.Current, fsServiceOrderRow.RefNbr);
            }

            if (string.IsNullOrEmpty(fsWrkProcessRow.RoomID) == false &&
                string.IsNullOrWhiteSpace(fsWrkProcessRow.RoomID) == false)
            {
                graphAppointmentEntry.ServiceOrderRelated.SetValueExt <FSServiceOrder.roomID>
                    (graphAppointmentEntry.ServiceOrderRelated.Current, fsWrkProcessRow.RoomID);

                if (fsServiceOrderRow != null)
                {
                    graphAppointmentEntry.ServiceOrderRelated.Cache.SetStatus(graphAppointmentEntry.ServiceOrderRelated.Current, PXEntryStatus.Updated);
                }
            }

            #endregion

            #region Get Appointment Values
            List <string> soDetIDList  = GetParameterList(fsWrkProcessRow.LineRefList, SEPARATOR);
            List <string> employeeList = GetParameterList(fsWrkProcessRow.EmployeeIDList, SEPARATOR);

            #region Services
            soDetIDList.Reverse();

            if (soDetIDList.Count > 0)
            {
                foreach (FSAppointmentDetService fsAppointmentDetServiceRow in graphAppointmentEntry.AppointmentDetServices.Select())
                {
                    if (soDetIDList.Contains(fsAppointmentDetServiceRow.SODetID.ToString()) == false)
                    {
                        graphAppointmentEntry.AppointmentDetServices.Delete(fsAppointmentDetServiceRow);
                    }
                    else
                    {
                        InsertEmployeeLinkedToService(graphAppointmentEntry, employeeList, fsAppointmentDetServiceRow.LineRef);
                    }
                }

                foreach (FSAppointmentEmployee fsAppointmentEmployeeRow in graphAppointmentEntry.AppointmentEmployees.Select()
                         .RowCast <FSAppointmentEmployee>()
                         .Where(_ => _.ServiceLineRef != null))
                {
                    FSAppointmentDet fsAppointmentDetRow = (FSAppointmentDet)PXSelectorAttribute.Select <FSAppointmentEmployee.serviceLineRef>
                                                               (graphAppointmentEntry.AppointmentEmployees.Cache, fsAppointmentEmployeeRow);

                    if (fsAppointmentDetRow != null && soDetIDList.Contains(fsAppointmentDetRow.SODetID.ToString()) == false)
                    {
                        graphAppointmentEntry.AppointmentEmployees.Delete(fsAppointmentEmployeeRow);
                    }
                }
            }
            #endregion
            #region Employees

            employeeList.Reverse();

            if (employeeList.Count > 0 && soDetIDList.Count <= 0)
            {
                for (int i = 0; i < employeeList.Count; i++)
                {
                    FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee();

                    fsAppointmentEmployeeRow.EmployeeID = (int?)Convert.ToInt32(employeeList[i]);
                    graphAppointmentEntry.AppointmentEmployees.Insert(fsAppointmentEmployeeRow);
                }
            }
            #endregion
            #region Equipment
            List <string> equipmentList = GetParameterList(fsWrkProcessRow.EquipmentIDList, SEPARATOR);
            equipmentList.Reverse();
            if (equipmentList.Count > 0)
            {
                for (int i = 0; i < equipmentList.Count; i++)
                {
                    FSAppointmentResource fsAppointmentResourceRow = new FSAppointmentResource();

                    fsAppointmentResourceRow.SMEquipmentID = (int?)Convert.ToInt32(equipmentList[i]);
                    graphAppointmentEntry.AppointmentResources.Insert(fsAppointmentResourceRow);
                }
            }
            #endregion
            #endregion

            if (fsWrkProcessRow.SMEquipmentID.HasValue == true)
            {
                graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.mem_SMequipmentID>
                    (graphAppointmentEntry.AppointmentRecords.Current, fsWrkProcessRow.SMEquipmentID);
            }

            throw new PXRedirectRequiredException(graphAppointmentEntry, null)
                  {
                      Mode = PXBaseRedirectException.WindowMode.Same
                  };
        }
        public override List <DocLineExt> GetInvoiceLines(Guid currentProcessID, int billingCycleID, string groupKey, bool getOnlyTotal, out decimal?invoiceTotal, string postTo)
        {
            PXGraph tempGraph = new PXGraph();

            if (getOnlyTotal == true)
            {
                /* Always keep both BQLs with the same Joins and Where conditions */
                FSAppointmentDet fsAppointmentDetRow =
                    PXSelectJoinGroupBy <FSAppointmentDet,
                                         InnerJoin <FSAppointment,
                                                    On <FSAppointment.appointmentID, Equal <FSAppointmentDet.appointmentID> >,
                                                    InnerJoin <FSServiceOrder,
                                                               On <FSServiceOrder.sOID, Equal <FSAppointment.sOID> >,
                                                               InnerJoin <FSSrvOrdType,
                                                                          On <FSSrvOrdType.srvOrdType, Equal <FSServiceOrder.srvOrdType> >,
                                                                          InnerJoin <FSPostDoc,
                                                                                     On <
                                                                                         FSPostDoc.appointmentID, Equal <FSAppointment.appointmentID>,
                                                                                         And <FSPostDoc.entityType, Equal <ListField_PostDoc_EntityType.Appointment> > >,
                                                                                     LeftJoin <FSPostInfo,
                                                                                               On <
                                                                                                   FSPostInfo.postID, Equal <FSAppointmentDet.postID> > > > > > >,
                                         Where <
                                             FSPostDoc.processID, Equal <Required <FSPostDoc.processID> >,
                                             And <FSPostDoc.billingCycleID, Equal <Required <FSPostDoc.billingCycleID> >,
                                                  And <FSPostDoc.groupKey, Equal <Required <FSPostDoc.groupKey> >,
                                                       And <FSAppointmentDet.lineType, NotEqual <FSLineType.Comment>,
                                                            And <FSAppointmentDet.lineType, NotEqual <FSLineType.Instruction>,
                                                                 And <FSAppointmentDet.isCanceledNotPerformed, NotEqual <True>,
                                                                      And <FSAppointmentDet.lineType, NotEqual <ListField_LineType_Pickup_Delivery.Pickup_Delivery>,
                                                                           And <FSAppointmentDet.isPrepaid, Equal <False>,
                                                                                And <FSAppointmentDet.isBillable, Equal <True>,
                                                                                     And <
                                                                                         Where2 <
                                                                                             Where <
                                                                                                 FSAppointmentDet.postID, IsNull>,
                                                                                             Or <
                                                                                                 Where <
                                                                                                     FSPostInfo.aRPosted, Equal <False>,
                                                                                                     And <FSPostInfo.aPPosted, Equal <False>,
                                                                                                          And <FSPostInfo.sOPosted, Equal <False>,
                                                                                                               And <FSPostInfo.sOInvPosted, Equal <False>,
                                                                                                                    And <
                                                                                                                        Where2 <
                                                                                                                            Where <
                                                                                                                                Required <FSPostBatch.postTo>, NotEqual <FSPostBatch.postTo.SO> >,
                                                                                                                            Or <
                                                                                                                                Where <
                                                                                                                                    Required <FSPostBatch.postTo>, Equal <FSPostBatch.postTo.SO>,
                                                                                                                                    And <FSPostInfo.iNPosted, Equal <False> > > > > > > > > > > > > > > > > > > > > >,
                                         Aggregate <
                                             Sum <FSAppointmentDet.billableTranAmt> > >
                    .Select(tempGraph, currentProcessID, billingCycleID, groupKey, postTo, postTo);

                invoiceTotal = fsAppointmentDetRow.BillableTranAmt;

                FSAppointmentDet fsAppointmentInventoryItem =
                    PXSelectJoinGroupBy <FSAppointmentDet,
                                         InnerJoin <FSAppointment,
                                                    On <FSAppointment.appointmentID, Equal <FSAppointmentDet.appointmentID> >,
                                                    InnerJoin <FSServiceOrder,
                                                               On <FSServiceOrder.sOID, Equal <FSAppointment.sOID> >,
                                                               InnerJoin <FSSrvOrdType,
                                                                          On <FSSrvOrdType.srvOrdType, Equal <FSServiceOrder.srvOrdType> >,
                                                                          InnerJoin <FSPostDoc,
                                                                                     On <
                                                                                         FSPostDoc.appointmentID, Equal <FSAppointment.appointmentID>,
                                                                                         And <FSPostDoc.entityType, Equal <ListField_PostDoc_EntityType.Appointment> > >,
                                                                                     LeftJoin <FSPostInfo,
                                                                                               On <
                                                                                                   FSPostInfo.postID, Equal <FSAppointmentDet.postID> > > > > > >,
                                         Where <
                                             FSAppointmentDet.lineType, Equal <ListField_LineType_Pickup_Delivery.Pickup_Delivery>,
                                             And <FSPostDoc.processID, Equal <Required <FSPostDoc.processID> >,
                                                  And <FSPostDoc.billingCycleID, Equal <Required <FSPostDoc.billingCycleID> >,
                                                       And <FSPostDoc.groupKey, Equal <Required <FSPostDoc.groupKey> >,
                                                            And <
                                                                Where2 <
                                                                    Where <
                                                                        FSAppointmentDet.postID, IsNull>,
                                                                    Or <
                                                                        Where <
                                                                            FSPostInfo.aRPosted, Equal <False>,
                                                                            And <FSPostInfo.aPPosted, Equal <False>,
                                                                                 And <FSPostInfo.sOPosted, Equal <False>,
                                                                                      And <FSPostInfo.sOInvPosted, Equal <False>,
                                                                                           And <
                                                                                               Where2 <
                                                                                                   Where <
                                                                                                       Required <FSPostBatch.postTo>, NotEqual <FSPostBatch.postTo.SO> >,
                                                                                                   Or <
                                                                                                       Where <
                                                                                                           Required <FSPostBatch.postTo>, Equal <FSPostBatch.postTo.SO>,
                                                                                                           And <FSPostInfo.iNPosted, Equal <False> > > > > > > > > > > > > > > > >,
                                         Aggregate <
                                             Sum <FSAppointmentDet.billableTranAmt> > >
                    .Select(tempGraph, currentProcessID, billingCycleID, groupKey, postTo, postTo);

                invoiceTotal += fsAppointmentInventoryItem.BillableTranAmt ?? 0;

                return(null);
            }
            else
            {
                invoiceTotal = null;

                /* Always keep both BQLs with the same Joins and Where conditions */
                var resultSet1 = PXSelectJoin <FSAppointmentDet,
                                               InnerJoin <FSAppointment,
                                                          On <FSAppointment.appointmentID, Equal <FSAppointmentDet.appointmentID> >,
                                                          InnerJoin <FSServiceOrder,
                                                                     On <FSServiceOrder.sOID, Equal <FSAppointment.sOID> >,
                                                                     InnerJoin <FSSrvOrdType,
                                                                                On <FSSrvOrdType.srvOrdType, Equal <FSServiceOrder.srvOrdType> >,
                                                                                InnerJoin <FSPostDoc,
                                                                                           On <
                                                                                               FSPostDoc.appointmentID, Equal <FSAppointment.appointmentID>,
                                                                                               And <FSPostDoc.entityType, Equal <ListField_PostDoc_EntityType.Appointment> > >,
                                                                                           LeftJoin <FSPostInfo,
                                                                                                     On <
                                                                                                         FSPostInfo.postID, Equal <FSAppointmentDet.postID> >,
                                                                                                     LeftJoin <FSSODet,
                                                                                                               On <FSSODet.srvOrdType, Equal <FSServiceOrder.srvOrdType>,
                                                                                                                   And <FSSODet.refNbr, Equal <FSServiceOrder.refNbr>,
                                                                                                                        And <FSSODet.sODetID, Equal <FSAppointmentDet.sODetID> > > >,
                                                                                                               LeftJoin <FSSODetSplit,
                                                                                                                         On <FSSODetSplit.srvOrdType, Equal <FSSODet.srvOrdType>,
                                                                                                                             And <FSSODetSplit.refNbr, Equal <FSSODet.refNbr>,
                                                                                                                                  And <FSSODetSplit.lineNbr, Equal <FSSODet.lineNbr>,
                                                                                                                                       And <FSSODetSplit.completed, Equal <False> > > > >,
                                                                                                                         LeftJoin <INItemPlan,
                                                                                                                                   On <INItemPlan.planID, Equal <FSSODetSplit.planID> >,
                                                                                                                                   LeftJoin <PMTask,
                                                                                                                                             On <PMTask.taskID, Equal <FSAppointmentDet.projectTaskID> > > > > > > > > > >,
                                               Where <
                                                   FSPostDoc.processID, Equal <Required <FSPostDoc.processID> >,
                                                   And <FSPostDoc.billingCycleID, Equal <Required <FSPostDoc.billingCycleID> >,
                                                        And <FSPostDoc.groupKey, Equal <Required <FSPostDoc.groupKey> >,
                                                             And <FSAppointmentDet.lineType, NotEqual <FSLineType.Comment>,
                                                                  And <FSAppointmentDet.lineType, NotEqual <FSLineType.Instruction>,
                                                                       And <FSAppointmentDet.isCanceledNotPerformed, NotEqual <True>,
                                                                            And <FSAppointmentDet.lineType, NotEqual <ListField_LineType_Pickup_Delivery.Pickup_Delivery>,
                                                                                 And <FSAppointmentDet.isPrepaid, Equal <False>,
                                                                                      And <
                                                                                          Where2 <
                                                                                              Where <
                                                                                                  FSAppointmentDet.postID, IsNull>,
                                                                                              Or <
                                                                                                  Where <
                                                                                                      FSPostInfo.aRPosted, Equal <False>,
                                                                                                      And <FSPostInfo.aPPosted, Equal <False>,
                                                                                                           And <FSPostInfo.sOPosted, Equal <False>,
                                                                                                                And <FSPostInfo.sOInvPosted, Equal <False>,
                                                                                                                     And <
                                                                                                                         Where2 <
                                                                                                                             Where <
                                                                                                                                 Required <FSPostBatch.postTo>, NotEqual <FSPostBatch.postTo.SO> >,
                                                                                                                             Or <
                                                                                                                                 Where <
                                                                                                                                     Required <FSPostBatch.postTo>, Equal <FSPostBatch.postTo.SO>,
                                                                                                                                     And <FSPostInfo.iNPosted, Equal <False> > > > > > > > > > > > > > > > > > > > >,
                                               OrderBy <
                                                   Asc <FSAppointment.executionDate,
                                                        Asc <FSAppointmentDet.appointmentID,
                                                             Asc <FSAppointmentDet.appDetID> > > > >
                                 .Select(tempGraph, currentProcessID, billingCycleID, groupKey, postTo, postTo);

                var docLines = new List <DocLineExt>();

                foreach (PXResult <FSAppointmentDet, FSAppointment, FSServiceOrder, FSSrvOrdType, FSPostDoc, FSPostInfo, FSSODet, FSSODetSplit, INItemPlan, PMTask> row in resultSet1)
                {
                    docLines.Add(new DocLineExt(row));
                }

                var resultSet2 = PXSelectJoin <FSAppointmentDet,
                                               InnerJoin <FSAppointment,
                                                          On <FSAppointment.appointmentID, Equal <FSAppointmentDet.appointmentID> >,
                                                          InnerJoin <FSServiceOrder,
                                                                     On <FSServiceOrder.sOID, Equal <FSAppointment.sOID> >,
                                                                     InnerJoin <FSSrvOrdType,
                                                                                On <FSSrvOrdType.srvOrdType, Equal <FSServiceOrder.srvOrdType> >,
                                                                                InnerJoin <FSPostDoc,
                                                                                           On <
                                                                                               FSPostDoc.appointmentID, Equal <FSAppointment.appointmentID>,
                                                                                               And <FSPostDoc.entityType, Equal <ListField_PostDoc_EntityType.Appointment> > >,
                                                                                           LeftJoin <FSPostInfo,
                                                                                                     On <
                                                                                                         FSPostInfo.postID, Equal <FSAppointmentDet.postID> >,
                                                                                                     LeftJoin <PMTask,
                                                                                                               On <PMTask.taskID, Equal <FSAppointmentDet.projectTaskID> > > > > > > >,
                                               Where <
                                                   FSAppointmentDet.lineType, Equal <ListField_LineType_Pickup_Delivery.Pickup_Delivery>,
                                                   And <FSPostDoc.processID, Equal <Required <FSPostDoc.processID> >,
                                                        And <FSPostDoc.billingCycleID, Equal <Required <FSPostDoc.billingCycleID> >,
                                                             And <FSPostDoc.groupKey, Equal <Required <FSPostDoc.groupKey> >,
                                                                  And <
                                                                      Where2 <
                                                                          Where <
                                                                              FSAppointmentDet.postID, IsNull>,
                                                                          Or <
                                                                              Where <
                                                                                  FSPostInfo.aRPosted, Equal <False>,
                                                                                  And <FSPostInfo.aPPosted, Equal <False>,
                                                                                       And <FSPostInfo.sOPosted, Equal <False>,
                                                                                            And <FSPostInfo.sOInvPosted, Equal <False>,
                                                                                                 And <
                                                                                                     Where2 <
                                                                                                         Where <
                                                                                                             Required <FSPostBatch.postTo>, NotEqual <FSPostBatch.postTo.SO> >,
                                                                                                         Or <
                                                                                                             Where <
                                                                                                                 Required <FSPostBatch.postTo>, Equal <FSPostBatch.postTo.SO>,
                                                                                                                 And <FSPostInfo.iNPosted, Equal <False> > > > > > > > > > > > > > > > >,
                                               OrderBy <
                                                   Asc <FSAppointment.executionDate,
                                                        Asc <FSAppointmentDet.appointmentID,
                                                             Asc <FSAppointmentDet.appDetID> > > > >
                                 .Select(tempGraph, currentProcessID, billingCycleID, groupKey, postTo, postTo);

                DocLineExt docLineExtRow;

                foreach (PXResult <FSAppointmentDet, FSAppointment, FSServiceOrder, FSSrvOrdType, FSPostDoc, FSPostInfo, PMTask> row in resultSet2)
                {
                    docLineExtRow = new DocLineExt(row);

                    docLineExtRow.docLine.AcctID = ServiceOrderCore.Get_TranAcctID_DefaultValue(this,
                                                                                                docLineExtRow.fsSrvOrdType.SalesAcctSource,
                                                                                                docLineExtRow.docLine.InventoryID,
                                                                                                docLineExtRow.docLine.SiteID,
                                                                                                docLineExtRow.fsServiceOrder);

                    docLines.Add(docLineExtRow);
                }

                return(docLines);
            }
        }
        /// <summary>
        /// Update the references in <c>FSPostInfo</c> and <c>FSPostDet</c> when the posting process of every AppointmentInventoryItem is complete in IN.
        /// </summary>
        public virtual void UpdateIssuePostInfo(INIssueEntry graphINIssueEntry, InventoryPostBatchMaint graphInventoryPostBatchMaint, PostInfoEntry graphPostInfoEntry, FSAppointmentDet fsAppointmentInventoryItemRow, SharedClasses.AppointmentInventoryItemInfo appointmentInventoryItemInfoRow, FSPostBatch fsPostBatchRow)
        {
            //Create | Update Post info
            FSPostInfo fsPostInfoRow;
            FSPostDet  fsPostDet;

            fsPostBatchRow = graphInventoryPostBatchMaint.BatchRecords.Current = graphInventoryPostBatchMaint.BatchRecords.Search <FSPostBatch.batchID>(fsPostBatchRow.BatchID);

            fsPostInfoRow = PXSelect <FSPostInfo,
                                      Where <
                                          FSPostInfo.postID, Equal <Required <FSPostInfo.postID> > > >
                            .Select(this, appointmentInventoryItemInfoRow.FSAppointmentInventoryItem.PostID);

            if (fsPostInfoRow == null || fsPostInfoRow.PostID == null)
            {
                fsPostInfoRow = new FSPostInfo();
                fsPostInfoRow = graphPostInfoEntry.PostInfoRecords.Current = graphPostInfoEntry.PostInfoRecords.Insert(fsPostInfoRow);
            }
            else
            {
                fsPostInfoRow = graphPostInfoEntry.PostInfoRecords.Current = graphPostInfoEntry.PostInfoRecords.Search <FSPostInfo.postID>(fsPostInfoRow.PostID);
            }

            fsPostInfoRow.INPosted  = true;
            fsPostInfoRow.INDocType = graphINIssueEntry.issue.Current.DocType;
            fsPostInfoRow.INRefNbr  = graphINIssueEntry.issue.Current.RefNbr;

            foreach (INTran inTranRowLocal in graphINIssueEntry.transactions.Select())
            {
                FSxINTran fsxINTranRow = graphINIssueEntry.transactions.Cache.GetExtension <FSxINTran>(inTranRowLocal);

                if (fsxINTranRow != null && appointmentInventoryItemInfoRow.FSAppointmentInventoryItem.AppDetID == fsxINTranRow.AppDetID)
                {
                    fsPostInfoRow.INLineNbr = inTranRowLocal.LineNbr;
                    break;
                }
            }

            fsPostInfoRow.AppointmentID = appointmentInventoryItemInfoRow.FSAppointmentRow.AppointmentID;
            fsPostInfoRow.SOID          = appointmentInventoryItemInfoRow.FSAppointmentRow.SOID;

            fsPostInfoRow = graphPostInfoEntry.PostInfoRecords.Update(fsPostInfoRow);

            graphPostInfoEntry.Save.Press();
            fsPostInfoRow = graphPostInfoEntry.PostInfoRecords.Current;

            fsPostDet = new FSPostDet();

            fsPostDet.PostID    = fsPostInfoRow.PostID;
            fsPostDet.INPosted  = fsPostInfoRow.INPosted;
            fsPostDet.INDocType = fsPostInfoRow.INDocType;
            fsPostDet.INRefNbr  = fsPostInfoRow.INRefNbr;
            fsPostDet.INLineNbr = fsPostInfoRow.INLineNbr;

            graphInventoryPostBatchMaint.BatchDetails.Insert(fsPostDet);
            graphInventoryPostBatchMaint.Save.Press();

            fsAppointmentInventoryItemRow.Mem_BatchNbr = fsPostBatchRow.BatchNbr;

            fsPostInfoRow = graphPostInfoEntry.PostInfoRecords.Current;

            PXUpdate <
                Set <FSAppointmentDet.postID, Required <FSAppointmentDet.postID> >,
                FSAppointmentDet,
                Where <
                    FSAppointmentDet.appDetID, Equal <Required <FSAppointmentDet.appDetID> > > >
            .Update(this, fsPostInfoRow.PostID, appointmentInventoryItemInfoRow.FSAppointmentInventoryItem.AppDetID);
        }
        /// <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();
        }
示例#26
0
        private void UpdateCosts()
        {
            if (IsSMRelated() == true)
            {
                Dictionary <int?, decimal?> appointmentIDs = new Dictionary <int?, decimal?>();

                var appointmentSet = PXSelectJoin <FSAppointmentDet,
                                                   InnerJoin <FSAppointment,
                                                              On <FSAppointment.appointmentID, Equal <FSAppointmentDet.appointmentID> >,
                                                              InnerJoin <FSPostDet,
                                                                         On <FSPostDet.postDetID, Equal <FSAppointmentDet.postID> >,
                                                                         LeftJoin <INTran,
                                                                                   On <INTran.sOOrderType, Equal <FSPostDet.sOOrderType>,
                                                                                       And <INTran.sOOrderNbr, Equal <FSPostDet.sOOrderNbr>,
                                                                                            And <INTran.sOOrderLineNbr, Equal <FSPostDet.sOLineNbr> > > > > > >,
                                                   Where <
                                                       FSPostDet.sOOrderType, Equal <Required <FSPostDet.sOOrderType> >,
                                                       And <
                                                           FSPostDet.sOOrderNbr, Equal <Required <FSPostDet.sOOrderNbr> > > > >
                                     .Select(Base, Base.inregister.Current.SOOrderType, Base.inregister.Current.SOOrderNbr);

                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (PXResult <FSAppointmentDet, FSAppointment, FSPostDet, INTran> bqlResult in appointmentSet)
                    {
                        FSAppointmentDet fsAppointmentDetRow = (FSAppointmentDet)bqlResult;
                        FSAppointment    fsAppointmentRow    = (FSAppointment)bqlResult;
                        INTran           inTranRow           = (INTran)bqlResult;

                        if (inTranRow.RefNbr != null)
                        {
                            PXUpdate <
                                Set <FSAppointmentDet.unitCost, Required <FSAppointmentDet.unitCost>,
                                     Set <FSAppointmentDet.curyUnitCost, Required <FSAppointmentDet.curyUnitCost>,
                                          Set <FSAppointmentDet.extCost, Required <FSAppointmentDet.extCost>,
                                               Set <FSAppointmentDet.curyExtCost, Required <FSAppointmentDet.curyExtCost> > > > >,
                                FSAppointmentDet,
                                Where <
                                    FSAppointmentDet.appDetID, Equal <Required <FSAppointmentDet.appDetID> > > >
                            .Update(
                                Base,
                                inTranRow.UnitCost,
                                inTranRow.UnitCost,
                                inTranRow.TranCost,
                                inTranRow.TranCost,
                                fsAppointmentDetRow.AppDetID);
                        }

                        decimal?costTotal = 0.0m;

                        if (appointmentIDs.ContainsKey(fsAppointmentDetRow.AppointmentID) == false)
                        {
                            appointmentIDs.Add(fsAppointmentDetRow.AppointmentID, inTranRow.TranCost ?? fsAppointmentDetRow.ExtCost);
                        }
                        else if (appointmentIDs.TryGetValue(fsAppointmentDetRow.AppointmentID, out costTotal))
                        {
                            costTotal += inTranRow.TranCost ?? fsAppointmentDetRow.ExtCost;
                            appointmentIDs.Remove(fsAppointmentDetRow.AppointmentID);
                            appointmentIDs.Add(fsAppointmentDetRow.AppointmentID, costTotal);
                        }
                    }

                    foreach (KeyValuePair <int?, decimal?> pair in appointmentIDs.ToList())
                    {
                        PXUpdate <
                            Set <FSAppointment.costTotal, Required <FSAppointment.costTotal>,
                                 Set <FSAppointment.curyCostTotal, Required <FSAppointment.curyCostTotal> > >,
                            FSAppointment,
                            Where <
                                FSAppointment.appointmentID, Equal <Required <FSAppointment.appointmentID> >
                                >
                            >
                        .Update(
                            new PXGraph(),
                            pair.Value,
                            pair.Value,
                            pair.Key);
                    }

                    ts.Complete();
                }
            }
        }
        private void CloneParts(AppointmentEntry sourceAppointmentGraph, AppointmentEntry newAppointmentGraph, FSAppointment newAppointmentRow)
        {
            foreach (FSAppointmentDetPart sourceRow in sourceAppointmentGraph.AppointmentDetParts.Select())
            {
                FSSODet fsSODetRow = ServiceOrderCore.GetSODetFromAppointmentDet(sourceAppointmentGraph, sourceRow);

                if (fsSODetRow != null &&
                    (fsSODetRow.Status == ID.Status_AppointmentDet.CANCELED ||
                     fsSODetRow.Status == ID.Status_AppointmentDet.COMPLETED))
                {
                    continue;
                }

                FSAppointmentDet sumFSAppointmentDetPartBillable =
                    PXSelectJoinGroupBy <FSAppointmentDet,
                                         InnerJoin <FSAppointment, On <FSAppointment.srvOrdType, Equal <FSAppointmentDet.srvOrdType>,
                                                                       And <FSAppointment.refNbr, Equal <FSAppointmentDetPart.refNbr> > > >,
                                         Where <FSAppointmentDet.sODetID, Equal <Required <FSAppointmentDet.sODetID> >,
                                                And <FSAppointment.status, NotEqual <FSAppointment.status.Canceled>,
                                                     And <FSAppointmentDet.status, NotEqual <FSAppointmentDet.status.Canceled> > > >,
                                         Aggregate <GroupBy <FSAppointmentDet.sODetID, Sum <FSAppointmentDet.billableQty> > > >
                    .Select(dummyGraph, sourceRow.SODetID);

                decimal?openQty    = fsSODetRow.BillableQty - sumFSAppointmentDetPartBillable.BillableQty;
                bool?   lineCloned = false;

                FSAppointmentDetPart newRow = PXCache <FSAppointmentDetPart> .CreateCopy(sourceRow);

                if (openQty >= sourceRow.BillableQty)
                {
                    newRow = AppointmentEntry.InsertServicePartLine <FSAppointmentDetPart, FSAppointmentDetPart>(
                        newAppointmentGraph.AppointmentDetParts.Cache,
                        newRow,
                        sourceAppointmentGraph.AppointmentDetParts.Cache,
                        sourceRow,
                        null,
                        sourceRow.SODetID,
                        copyTranDate: false,
                        tranDate: sourceRow.TranDate,
                        SetValuesAfterAssigningSODetID: true,
                        copyingFromQuote: false);
                    lineCloned = true;
                }
                else
                {
                    if (openQty > 0)
                    {
                        decimal?remainingQty = sourceRow.BillableQty - openQty;

                        newRow.Qty             = 0;
                        sourceRow.EstimatedQty = openQty;
                        sourceRow.BillableQty  = openQty;
                        newRow = AppointmentEntry.InsertServicePartLine <FSAppointmentDetPart, FSAppointmentDetPart>(
                            newAppointmentGraph.AppointmentDetParts.Cache,
                            newRow,
                            sourceAppointmentGraph.AppointmentDetParts.Cache,
                            sourceRow,
                            null,
                            sourceRow.SODetID,
                            copyTranDate: false,
                            tranDate: sourceRow.TranDate,
                            SetValuesAfterAssigningSODetID: true,
                            copyingFromQuote: false);
                        lineCloned = true;

                        FSAppointmentDetPart secondNewRow = PXCache <FSAppointmentDetPart> .CreateCopy(sourceRow);

                        secondNewRow.Qty       = 0;
                        sourceRow.EstimatedQty = remainingQty;
                        sourceRow.BillableQty  = remainingQty;
                        secondNewRow.SODetID   = null;
                        secondNewRow           = AppointmentEntry.InsertServicePartLine <FSAppointmentDetPart, FSAppointmentDetPart>(
                            newAppointmentGraph.AppointmentDetParts.Cache,
                            secondNewRow,
                            sourceAppointmentGraph.AppointmentDetParts.Cache,
                            sourceRow,
                            null,
                            null,
                            copyTranDate: false,
                            tranDate: sourceRow.TranDate,
                            SetValuesAfterAssigningSODetID: false,
                            copyingFromQuote: false);
                    }
                    else
                    {
                        newRow.SODetID = null;
                        newRow.Qty     = 0;
                        newRow         = AppointmentEntry.InsertServicePartLine <FSAppointmentDetPart, FSAppointmentDetPart>(
                            newAppointmentGraph.AppointmentDetParts.Cache,
                            newRow,
                            sourceAppointmentGraph.AppointmentDetParts.Cache,
                            sourceRow,
                            null,
                            null,
                            copyTranDate: false,
                            tranDate: sourceRow.TranDate,
                            SetValuesAfterAssigningSODetID: false,
                            copyingFromQuote: false);
                    }
                }


                if (lineCloned == true)
                {
                    PXNoteAttribute.CopyNoteAndFiles(
                        sourceAppointmentGraph.AppointmentDetParts.Cache,
                        sourceRow,
                        newAppointmentGraph.AppointmentDetParts.Cache,
                        newRow,
                        copyNotes: true,
                        copyFiles: false);

                    AppointmentCore.UpdateAppointmentsInfoInServiceOrder(newAppointmentGraph.AppointmentDetParts.Cache, newRow, ServiceOrderRelated);
                }
            }
        }
示例#28
0
        protected GetTaxRequest BuildGetTaxRequest(FSAppointment order, FSServiceOrder serviceOrder)
        {
            if (order == null)
            {
                throw new PXArgumentException(ErrorMessages.ArgumentNullException);
            }

            BAccount cust = (BAccount)PXSelect <BAccount,
                                                Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > .
                            Select(Base, serviceOrder.BillCustomerID);

            Location loc = (Location)PXSelect <Location,
                                               Where <Location.bAccountID, Equal <Required <Location.bAccountID> >, And <Location.locationID, Equal <Required <Location.locationID> > > > > .
                           Select(Base, serviceOrder.BillCustomerID, serviceOrder.BillLocationID);

            IAddressBase addressFrom = GetFromAddress();
            IAddressBase addressTo   = GetToAddress(order, serviceOrder);

            if (addressFrom == null)
            {
                throw new PXException(PX.Objects.CR.Messages.FailedGetFromAddressSO);
            }

            if (addressTo == null)
            {
                throw new PXException(PX.Objects.CR.Messages.FailedGetToAddressSO);
            }

            GetTaxRequest request = new GetTaxRequest();

            request.CompanyCode        = CompanyCodeFromBranch(order.TaxZoneID, Base.Accessinfo.BranchID);
            request.CurrencyCode       = order.CuryID;
            request.CustomerCode       = cust.AcctCD;
            request.OriginAddress      = AddressConverter.ConvertTaxAddress(addressFrom);
            request.DestinationAddress = AddressConverter.ConvertTaxAddress(addressTo);
            request.DocCode            = $"CR.{order.AppointmentID}";
            request.DocDate            = order.ExecutionDate.GetValueOrDefault();

            int mult = 1;

            if (!string.IsNullOrEmpty(loc.CAvalaraCustomerUsageType))
            {
                request.CustomerUsageType = loc.CAvalaraCustomerUsageType;
            }
            if (!string.IsNullOrEmpty(loc.CAvalaraExemptionNumber))
            {
                request.ExemptionNo = loc.CAvalaraExemptionNumber;
            }

            request.DocType = TaxDocumentType.SalesOrder;

            PXSelectBase <FSAppointmentDet> select = new PXSelectJoin <FSAppointmentDet,
                                                                       LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <FSAppointmentDet.inventoryID> >,
                                                                                 LeftJoin <Account, On <Account.accountID, Equal <InventoryItem.salesAcctID> > > >,
                                                                       Where <FSAppointmentDet.appointmentID, Equal <Current <FSAppointment.appointmentID> > >,
                                                                       OrderBy <Asc <FSAppointmentDet.apptLineNbr> > >(Base);

            foreach (PXResult <FSAppointmentDet, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { order }))
            {
                FSAppointmentDet tran         = (FSAppointmentDet)res;
                InventoryItem    item         = (InventoryItem)res;
                Account          salesAccount = (Account)res;

                var line = new TaxCartItem();
                line.Index              = tran.ApptLineNbr ?? 0;
                line.Amount             = mult * tran.CuryBillableTranAmt.GetValueOrDefault();
                line.Description        = tran.TranDesc;
                line.DestinationAddress = request.DestinationAddress;
                line.OriginAddress      = request.OriginAddress;
                line.ItemCode           = item.InventoryCD;
                line.Quantity           = Math.Abs(tran.BillableQty.GetValueOrDefault());
                line.Discounted         = request.Discount > 0;
                line.RevAcct            = salesAccount.AccountCD;
                line.TaxCode            = tran.TaxCategoryID;

                request.CartItems.Add(line);
            }

            return(request);
        }
示例#29
0
        public virtual void RunLogActionBase(string action, string type, FSAppointmentDet apptDet, PXSelectBase <FSAppointmentLog> logSelect, params object[] logSelectArgs)
        {
            if (action == ID.LogActions.START)
            {
                bool saveDocument = false;

                if (type == ID.Type_Log.TRAVEL)
                {
                    StartTravelAction();
                    saveDocument = LogRecords.Cache.IsDirty == true || AppointmentServiceEmployees.Cache.IsDirty;
                }
                else if (type == ID.Type_Log.SERVICE)
                {
                    StartServiceAction();
                    saveDocument = LogRecords.Cache.IsDirty == true;
                }
                else if (type == ID.Type_Log.NON_STOCK)
                {
                    StartNonStockAction(apptDet);
                    saveDocument = true;
                }
                else if (type == ID.Type_Log.STAFF_ASSIGMENT)
                {
                    StartStaffAction();
                    saveDocument = LogRecords.Cache.IsDirty == true || AppointmentServiceEmployees.Cache.IsDirty == true;
                }
                else if (type == ID.Type_Log.SERV_BASED_ASSIGMENT)
                {
                    StartServiceBasedOnAssignmentAction();
                    saveDocument = LogRecords.Cache.IsDirty == true || AppointmentServiceEmployees.Cache.IsDirty == true;
                }

                if (saveDocument == true)
                {
                    this.Actions.PressSave();
                }
            }
            else if (action == ID.LogActions.COMPLETE)
            {
                /***************************************************************/
                // Change this to use logSelect and logSelectArgs

                IEnumerable <ILogDetail> completeLogItems = null;

                if (type == ID.Type_Log.TRAVEL)
                {
                    completeLogItems = LogActionTravelDetails.Select().RowCast <FSLogActionTravelDetail>().Where(_ => _.Selected == true);
                }
                else if (type == ID.Type_Log.SERVICE || type == ID.Type_Log.STAFF_ASSIGMENT)
                {
                    completeLogItems = LogActionServiceDetails.Select().RowCast <NoTravelLogInProcess>().Where(_ => _.Selected == true);
                }

                /***************************************************************/

                CompleteAction(apptDet, completeLogItems, LogActionFilter.Current.LogTime, logSelect, logSelectArgs);

                if (type == ID.Type_Log.TRAVEL &&
                    ServiceOrderTypeSelected.Current.OnTravelCompleteStartAppt == true &&
                    (AppointmentRecords.Current?.Status == ID.Status_Appointment.AUTOMATIC_SCHEDULED ||
                     AppointmentRecords.Current?.Status == ID.Status_Appointment.MANUAL_SCHEDULED))
                {
                    startAppointment.PressImpl();
                }
            }
        }
示例#30
0
        public virtual void StartServiceAction(IEnumerable <FSAppointmentEmployeeFSLogStart> createLogItems = null)
        {
            IEnumerable <FSAppointmentEmployeeFSLogStart> createLogItemsLocal = null;
            FSAppointmentLog fsAppointmentLogRow;
            FSAppointmentDet fsAppointmentDetRow = null;
            string           detLineRef          = null;
            DateTime?        dateTimeBegin       = null;
            int timeDuration = 0;

            if (LogActionFilter.Current?.DetLineRef == null)
            {
                return;
            }

            if (createLogItems == null)
            {
                detLineRef    = LogActionFilter.Current?.DetLineRef;
                dateTimeBegin = LogActionFilter.Current?.LogTime;

                if (LogActionFilter.Current.DetLineRef != null)
                {
                    fsAppointmentDetRow = PXSelect <FSAppointmentDet,
                                                    Where <
                                                        FSAppointmentDet.appointmentID, Equal <Required <FSAppointmentDet.appointmentID> >,
                                                        And <FSAppointmentDet.lineRef, Equal <Required <FSAppointmentDet.lineRef> > > > >
                                          .Select(this, AppointmentRecords.Current.AppointmentID, LogActionFilter.Current.DetLineRef);

                    if (fsAppointmentDetRow != null)
                    {
                        timeDuration = fsAppointmentDetRow.EstimatedDuration ?? 0;
                    }
                }

                if (LogActionFilter.Current.Me == true)
                {
                    EPEmployee employeeByUserID = PXSelect <EPEmployee,
                                                            Where <
                                                                EPEmployee.userID, Equal <Current <AccessInfo.userID> > > >
                                                  .Select(this);

                    if (employeeByUserID != null)
                    {
                        bool isEmployeeInGrid = AppointmentServiceEmployees.Select().RowCast <FSAppointmentEmployee>()
                                                .Where(x => x.EmployeeID == employeeByUserID.BAccountID)
                                                .Count() > 0;

                        bool isTherePrimaryDriver = AppointmentServiceEmployees.Select().RowCast <FSAppointmentEmployee>()
                                                    .Where(x => x.PrimaryDriver == true)
                                                    .Count() > 0;

                        if (isEmployeeInGrid == false)
                        {
                            FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee()
                            {
                                EmployeeID = employeeByUserID.BAccountID,
                            };

                            if (isTherePrimaryDriver == false)
                            {
                                fsAppointmentEmployeeRow.PrimaryDriver = true;
                            }

                            AppointmentServiceEmployees.Cache.Insert(fsAppointmentEmployeeRow);
                        }

                        fsAppointmentLogRow = new FSAppointmentLog()
                        {
                            Type          = ID.Type_Log.SERVICE,
                            BAccountID    = employeeByUserID.BAccountID,
                            DetLineRef    = detLineRef,
                            DateTimeBegin = dateTimeBegin,
                            TimeDuration  = timeDuration
                        };

                        LogRecords.Cache.Insert(fsAppointmentLogRow);
                    }
                }
                else
                {
                    createLogItemsLocal = StaffMemberLogStartAction.Select().RowCast <FSAppointmentEmployeeFSLogStart>()
                                          .Where(x => x.Selected == true);
                }
            }
            else
            {
                detLineRef          = null;
                dateTimeBegin       = PXDBDateAndTimeAttribute.CombineDateTime(AppointmentRecords.Current.ExecutionDate, PXTimeZoneInfo.Now);
                createLogItemsLocal = createLogItems;
            }

            if (createLogItemsLocal != null)
            {
                foreach (FSAppointmentEmployeeFSLogStart row in createLogItemsLocal)
                {
                    fsAppointmentLogRow = new FSAppointmentLog()
                    {
                        Type          = ID.Type_Log.SERVICE,
                        BAccountID    = row.BAccountID,
                        DetLineRef    = detLineRef,
                        DateTimeBegin = dateTimeBegin,
                        TimeDuration  = timeDuration
                    };

                    LogRecords.Cache.Insert(fsAppointmentLogRow);
                }
            }
        }