Example #1
0
        public static void Process(List <FSAppointment> list, bool isMassProcess)
        {
            AppointmentEntry appointmentEntryGraph = PXGraph.CreateInstance <AppointmentEntry>();

            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    appointmentEntryGraph.Clear();
                    appointmentEntryGraph.AppointmentRecords.Current = PXSelect <FSAppointment, Where <FSAppointment.srvOrdType, Equal <Required <FSAppointment.srvOrdType> >, And <FSAppointment.refNbr, Equal <Required <FSAppointment.refNbr> > > > > .Select(appointmentEntryGraph, list[i].SrvOrdType, list[i].RefNbr);

                    appointmentEntryGraph.CalculateExternalTax(appointmentEntryGraph.AppointmentRecords.Current);
                    PXProcessing <FSAppointment> .SetInfo(i, ActionsMessages.RecordProcessed);
                }
                catch (Exception e)
                {
                    if (isMassProcess)
                    {
                        PXProcessing <FSAppointment> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message);
                    }
                    else
                    {
                        throw new PXMassProcessException(i, e);
                    }
                }
            }
        }
        /// <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();
        }
        protected virtual void CloneAppointment(AppointmentEntry graphOriginalAppointment, AppointmentEntry graphNewAppointment)
        {
            if (AppointmentSelected.Current == null)
            {
                return;
            }

            graphNewAppointment.Clear(PXClearOption.ClearAll);
            graphNewAppointment.clearLocalServiceOrder();

            FSAppointment fsAppointmentRow = PXCache <FSAppointment> .CreateCopy(AppointmentSelected.Current);

            //Clear key and special fields
            fsAppointmentRow.RefNbr                     = null;
            fsAppointmentRow.AppointmentID              = null;
            fsAppointmentRow.NoteID                     = null;
            fsAppointmentRow.CuryInfoID                 = null;
            fsAppointmentRow.AgreementSignature         = false;
            fsAppointmentRow.FullNameSignature          = null;
            fsAppointmentRow.customerSignaturePath      = null;
            fsAppointmentRow.BillServiceContractID      = null;
            fsAppointmentRow.HandleManuallyActualTime   = null;
            fsAppointmentRow.HandleManuallyScheduleTime = null;

            fsAppointmentRow.OriginalAppointmentID = AppointmentSelected.Current.AppointmentID;

            fsAppointmentRow.ScheduledDateTimeBegin = AppointmentCore.GetDateTimeEnd(
                Filter.Current.ScheduledDate, Filter.Current.ScheduledStartTime);

            fsAppointmentRow.ScheduledDateTimeEnd =
                AppointmentCore.GetDateTimeEnd(
                    Filter.Current.ScheduledDate, Filter.Current.ScheduledEndTime);

            fsAppointmentRow.ExecutionDate = fsAppointmentRow.ScheduledDateTimeBegin.Value.Date;

            fsAppointmentRow.CutOffDate
                = ServiceOrderCore.GetCutOffDate(graphNewAppointment, graphOriginalAppointment.ServiceOrderRelated.Current.CBID, fsAppointmentRow.ExecutionDate);

            fsAppointmentRow.Status = ID.Status_Appointment.MANUAL_SCHEDULED;
            fsAppointmentRow.Hold   = false;

            fsAppointmentRow.AdditionalCommentsCustomer = null;
            fsAppointmentRow.AdditionalCommentsStaff    = null;

            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            //Clean total fields
            fsAppointmentRow.EstimatedDurationTotal = 0;
            fsAppointmentRow.ActualDurationTotal    = 0;

            fsAppointmentRow.CuryEstimatedLineTotal = 0;
            fsAppointmentRow.CuryLineTotal          = 0;
            fsAppointmentRow.CuryBillableLineTotal  = 0;
            fsAppointmentRow.CuryCostTotal          = 0;

            fsAppointmentRow.EstimatedLineTotal = 0;
            fsAppointmentRow.LineTotal          = 0;
            fsAppointmentRow.BillableLineTotal  = 0;
            fsAppointmentRow.CostTotal          = 0;
            //----------------------------------------------------------------------

            graphNewAppointment.IsCloningAppointment = true;
            fsAppointmentRow = graphNewAppointment.AppointmentRecords.Insert(fsAppointmentRow);

            graphNewAppointment.AttributeListRecords.Current = graphNewAppointment.AttributeListRecords.Select();
            graphNewAppointment.Answers.Current = graphNewAppointment.Answers.Select();
            graphNewAppointment.Answers.CopyAllAttributes(graphNewAppointment.AppointmentRecords.Current, AppointmentSelected.Current);

            PXNoteAttribute.CopyNoteAndFiles(
                AppointmentSelected.Cache,
                AppointmentSelected.Current,
                graphNewAppointment.AppointmentSelected.Cache,
                fsAppointmentRow,
                copyNotes: true,
                copyFiles: false);


            this.CloneParts(graphOriginalAppointment, graphNewAppointment, fsAppointmentRow);
            this.CloneServices(graphOriginalAppointment, graphNewAppointment, fsAppointmentRow);
            this.CloneEmployees(graphOriginalAppointment, graphNewAppointment, fsAppointmentRow);
            this.CloneAttendees(graphOriginalAppointment, graphNewAppointment, fsAppointmentRow);
            this.CloneResources(graphOriginalAppointment, graphNewAppointment, fsAppointmentRow);

            if (graphNewAppointment.AppointmentRecords.Current.ScheduledDateTimeEnd != Filter.Current.ScheduledEndTime)
            {
                graphNewAppointment.AppointmentRecords.Cache.SetValueExt <FSAppointment.handleManuallyScheduleTime>(fsAppointmentRow, true);
                graphNewAppointment.AppointmentRecords.Cache.SetValueExt <FSAppointment.scheduledDateTimeEnd>(fsAppointmentRow, Filter.Current.ScheduledEndTime);
            }

            graphNewAppointment.AppointmentRecords.Cache.SetDefaultExt <FSAppointment.billContractPeriodID>(fsAppointmentRow);
            graphNewAppointment.Save.Press();
        }
Example #4
0
        public virtual void CloneAppointment(AppointmentEntry graphOriginalAppointment, AppointmentEntry graphNewAppointment)
        {
            if (AppointmentSelected.Current == null)
            {
                return;
            }

            graphNewAppointment.Clear(PXClearOption.ClearAll);
            graphNewAppointment.clearLocalServiceOrder();

            FSAppointment fsAppointmentRow = PXCache <FSAppointment> .CreateCopy(AppointmentSelected.Current);

            var itemLineRefNbr = new Dictionary <string, string>();

            //Clear key and special fields
            fsAppointmentRow.RefNbr                     = null;
            fsAppointmentRow.AppointmentID              = null;
            fsAppointmentRow.NoteID                     = null;
            fsAppointmentRow.CuryInfoID                 = null;
            fsAppointmentRow.FullNameSignature          = null;
            fsAppointmentRow.customerSignaturePath      = null;
            fsAppointmentRow.BillServiceContractID      = null;
            fsAppointmentRow.HandleManuallyActualTime   = null;
            fsAppointmentRow.HandleManuallyScheduleTime = null;
            fsAppointmentRow.LogLineCntr                = 0;
            fsAppointmentRow.FinPeriodID                = null;
            fsAppointmentRow.PostingStatusAPARSO        = ID.Status_Posting.PENDING_TO_POST;
            fsAppointmentRow.PendingAPARSOPost          = true;

            fsAppointmentRow.OriginalAppointmentID = AppointmentSelected.Current.AppointmentID;

            fsAppointmentRow.ScheduledDateTimeBegin = AppointmentCore.GetDateTimeEnd(
                Filter.Current.ScheduledDate, Filter.Current.ScheduledStartTime);

            DateTime?scheduledDateTimeEnd = null;

            fsAppointmentRow.ScheduledDateTimeEnd =
                scheduledDateTimeEnd =
                    AppointmentCore.GetDateTimeEnd(
                        Filter.Current.ScheduledDate, Filter.Current.ScheduledEndTime);

            fsAppointmentRow.ExecutionDate = fsAppointmentRow.ScheduledDateTimeBegin.Value.Date;

            fsAppointmentRow.CutOffDate
                = ServiceOrderCore.GetCutOffDate(graphNewAppointment, graphOriginalAppointment.ServiceOrderRelated.Current.CBID, fsAppointmentRow.ExecutionDate, fsAppointmentRow.SrvOrdType);

            fsAppointmentRow.Status = ID.Status_Appointment.MANUAL_SCHEDULED;
            fsAppointmentRow.Hold   = false;

            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            //Clean total fields
            fsAppointmentRow.EstimatedDurationTotal = 0;
            fsAppointmentRow.ActualDurationTotal    = 0;

            fsAppointmentRow.CuryEstimatedLineTotal = 0;
            fsAppointmentRow.CuryLineTotal          = 0;
            fsAppointmentRow.CuryBillableLineTotal  = 0;
            fsAppointmentRow.CuryCostTotal          = 0;

            fsAppointmentRow.EstimatedLineTotal = 0;
            fsAppointmentRow.LineTotal          = 0;
            fsAppointmentRow.BillableLineTotal  = 0;
            fsAppointmentRow.CostTotal          = 0;
            fsAppointmentRow.LineCntr           = 0;
            //----------------------------------------------------------------------

            graphNewAppointment.IsCloningAppointment = true;
            fsAppointmentRow = graphNewAppointment.AppointmentRecords.Insert(fsAppointmentRow);

            graphNewAppointment.Answers.Current = graphNewAppointment.Answers.Select();
            graphNewAppointment.Answers.CopyAllAttributes(graphNewAppointment.AppointmentRecords.Current, AppointmentSelected.Current);

            PXNoteAttribute.CopyNoteAndFiles(AppointmentSelected.Cache,
                                             AppointmentSelected.Current,
                                             graphNewAppointment.AppointmentSelected.Cache,
                                             fsAppointmentRow,
                                             copyNotes: true,
                                             copyFiles: false);


            foreach (FSAppointmentDet sourceRow in graphOriginalAppointment.AppointmentDetails.Select())
            {
                if (sourceRow.IsInventoryItem == true)
                {
                    this.CloneParts(graphOriginalAppointment, graphNewAppointment, fsAppointmentRow, sourceRow);
                }
                else if (sourceRow.IsInventoryItem == false && sourceRow.IsPickupDelivery == false)
                {
                    this.CloneServices(graphOriginalAppointment, graphNewAppointment, fsAppointmentRow, sourceRow, itemLineRefNbr);
                }
            }

            this.CloneEmployees(graphOriginalAppointment, graphNewAppointment, fsAppointmentRow, itemLineRefNbr);
            this.CloneResources(graphOriginalAppointment, graphNewAppointment, fsAppointmentRow);

            if (graphNewAppointment.AppointmentRecords.Current.ScheduledDateTimeEnd != scheduledDateTimeEnd)
            {
                graphNewAppointment.AppointmentRecords.Cache.SetValueExt <FSAppointment.handleManuallyScheduleTime>(fsAppointmentRow, true);
                graphNewAppointment.AppointmentRecords.Cache.SetValueExt <FSAppointment.scheduledDateTimeEnd>(fsAppointmentRow, scheduledDateTimeEnd);
            }

            graphNewAppointment.AppointmentRecords.Cache.SetDefaultExt <FSAppointment.billContractPeriodID>(fsAppointmentRow);
            graphNewAppointment.Save.Press();
        }