private void CloneResources(AppointmentEntry graphOriginalAppointment, AppointmentEntry graphNewAppointment, FSAppointment newFSAppointmentRow)
        {
            foreach (FSAppointmentResource originalAppointmentResource in graphOriginalAppointment.AppointmentResources.Select())
            {
                FSAppointmentResource fsAppointmentResourceRow = PXCache <FSAppointmentResource> .CreateCopy(originalAppointmentResource);

                fsAppointmentResourceRow.AppointmentID = newFSAppointmentRow.AppointmentID;
                fsAppointmentResourceRow.RefNbr        = null;
                graphNewAppointment.AppointmentResources.Insert(fsAppointmentResourceRow);
            }
        }
        /// <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
                  };
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Launches the AppointmentEntry screen with some preloaded values.
        /// </summary>
        /// <param name="fsWrkProcessRow"><c>FSWrkProcess</c> row.</param>
        public static int?LaunchAppointmentEntryScreen(PXGraph graph, FSWrkProcess fsWrkProcessRow, bool redirect = true)
        {
            AppointmentEntry graphAppointmentEntry = PXGraph.CreateInstance <AppointmentEntry>();

            List <string> soDetIDList  = GetParameterList(fsWrkProcessRow.LineRefList, SEPARATOR);
            List <string> employeeList = GetParameterList(fsWrkProcessRow.EmployeeIDList, SEPARATOR);

            if (fsWrkProcessRow.AppointmentID != null)
            {
                graphAppointmentEntry.AppointmentRecords.Current = graphAppointmentEntry.AppointmentRecords.Search <FSAppointment.appointmentID>(fsWrkProcessRow.AppointmentID, fsWrkProcessRow.SrvOrdType);
                AssignAppointmentRoom(graphAppointmentEntry, fsWrkProcessRow);
                AssignAppointmentEmployeeByList(graphAppointmentEntry, employeeList, soDetIDList);
            }
            else
            {
                FSAppointment  fsAppointmentRow  = new FSAppointment();
                FSServiceOrder fsServiceOrderRow = GetServiceOrder(graph, fsWrkProcessRow);
                fsAppointmentRow.SrvOrdType = GetSrvOrdType(graph, fsWrkProcessRow, fsServiceOrderRow);

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

                if (fsAppointmentRow.SOID == null)
                {
                    SharedFunctions.ValidateSrvOrdTypeNumberingSequence(graph, 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);
                }

                AssignAppointmentRoom(graphAppointmentEntry, fsWrkProcessRow, fsServiceOrderRow);

                #endregion

                #region Get Appointment Values

                #region Services
                soDetIDList.Reverse();

                if (soDetIDList.Count > 0)
                {
                    var appointmentDetails = graphAppointmentEntry.AppointmentDetails.Select().RowCast <FSAppointmentDet>()
                                             .Where(x => x.IsInventoryItem == false);

                    foreach (FSAppointmentDet fsAppointmentDetRow in appointmentDetails)
                    {
                        if (soDetIDList.Contains(fsAppointmentDetRow.SODetID.ToString()) == false)
                        {
                            graphAppointmentEntry.AppointmentDetails.Delete(fsAppointmentDetRow);
                        }
                        else
                        {
                            InsertEmployeeLinkedToService(graphAppointmentEntry, employeeList, fsAppointmentDetRow.LineRef);
                        }
                    }

                    var employees = graphAppointmentEntry.AppointmentServiceEmployees.Select()
                                    .RowCast <FSAppointmentEmployee>()
                                    .Where(_ => _.ServiceLineRef != null);

                    foreach (FSAppointmentEmployee fsAppointmentEmployeeRow in employees)
                    {
                        FSAppointmentDet fsAppointmentDetRow = (FSAppointmentDet)PXSelectorAttribute.Select <FSAppointmentEmployee.serviceLineRef>
                                                                   (graphAppointmentEntry.AppointmentServiceEmployees.Cache,
                                                                   fsAppointmentEmployeeRow);

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

                AssignAppointmentEmployeeByList(graphAppointmentEntry, employeeList, soDetIDList);

                #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);

                redirect = true;
            }

            if (redirect == true)
            {
                throw new PXRedirectRequiredException(graphAppointmentEntry, null)
                      {
                          Mode = PXBaseRedirectException.WindowMode.Same
                      };
            }
            else
            {
                try
                {
                    graphAppointmentEntry.RecalculateExternalTaxesSync = true;
                    graphAppointmentEntry.Actions.PressSave();
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    graphAppointmentEntry.RecalculateExternalTaxesSync = false;
                }

                return(graphAppointmentEntry.AppointmentRecords.Current?.AppointmentID);
            }
        }