Exemplo n.º 1
0
        private static bool IsNecessaryToUpdateTimeCards(PXCache appointmentCache,
                                                         AppointmentCore.AppointmentLog_View appointmentEmployeeLogs,
                                                         FSAppointment fsAppointmentRow)
        {
            DateTime?oldActualDateTimeBegin = (DateTime?)appointmentCache.GetValueOriginal <FSAppointment.actualDateTimeBegin>(fsAppointmentRow);
            DateTime?oldActualDateTimeEnd   = (DateTime?)appointmentCache.GetValueOriginal <FSAppointment.actualDateTimeEnd>(fsAppointmentRow);
            DateTime?oldExecutionDate       = (DateTime?)appointmentCache.GetValueOriginal <FSAppointment.executionDate>(fsAppointmentRow);
            string   oldDocDesc             = (string)appointmentCache.GetValueOriginal <FSAppointment.docDesc>(fsAppointmentRow);
            bool     appointmentModified    = false;

            if (fsAppointmentRow.ActualDateTimeBegin != oldActualDateTimeBegin ||
                fsAppointmentRow.ActualDateTimeEnd != oldActualDateTimeEnd ||
                fsAppointmentRow.ExecutionDate != oldExecutionDate ||
                fsAppointmentRow.DocDesc != oldDocDesc)
            {
                appointmentModified = true;
            }

            if (fsAppointmentRow.Status == ID.Status_Appointment.COMPLETED &&
                (
                    ((string)appointmentCache.GetValueOriginal <FSAppointment.status>(fsAppointmentRow) != ID.Status_Appointment.COMPLETED &&
                     (string)appointmentCache.GetValueOriginal <FSAppointment.status>(fsAppointmentRow) != ID.Status_Appointment.CLOSED) ||
                    appointmentEmployeeLogs.Cache.IsInsertedUpdatedDeleted ||
                    appointmentModified))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
 public virtual void OnApptEndTimeChangeUpdateLogEndTime(FSAppointment fsAppointmentRow, FSSrvOrdType fsSrvOrdTypeRow,
                                                         AppointmentCore.AppointmentLog_View logRecords)
 {
     if (fsAppointmentRow != null && fsSrvOrdTypeRow?.OnEndTimeChangeUpdateLogEndTime == true)
     {
         foreach (FSAppointmentLog fsAppointmentLogRow in logRecords.Select().RowCast <FSAppointmentLog>()
                  .Where(_ => _.KeepDateTimes == false && _.Type != ID.Type_Log.TRAVEL))
         {
             FSAppointmentLog copy = (FSAppointmentLog)logRecords.Cache.CreateCopy(fsAppointmentLogRow);
             copy.DateTimeEnd = fsAppointmentRow.ActualDateTimeEnd;
             logRecords.Cache.Update(copy);
         }
     }
 }
Exemplo n.º 3
0
        public static void InsertUpdateDeleteTimeActivities(AppointmentEntry graphAppointmentEntry,
                                                            PXCache appointmentCache,
                                                            FSAppointment fsAppointmentRow,
                                                            FSServiceOrder fsServiceOrderRow,
                                                            AppointmentCore.AppointmentLog_View appointmentEmployeeLogs,
                                                            List <FSAppointmentLog> deleteReleatedTimeActivity,
                                                            List <FSAppointmentLog> createReleatedTimeActivity)
        {
            if (!TimeCardHelper.IsTheTimeCardIntegrationEnabled(graphAppointmentEntry) ||
                (fsAppointmentRow.Status != ID.Status_Appointment.COMPLETED &&
                 fsAppointmentRow.Status != ID.Status_Appointment.MANUAL_SCHEDULED))
            {
                return;
            }

            if (PXAccess.FeatureInstalled <FeaturesSet.timeReportingModule>() == false)
            {
                return;
            }

            EmployeeActivitiesEntry graphEmployeeActivitiesEntry = PXGraph.CreateInstance <EmployeeActivitiesEntry>();

            if (IsNecessaryToUpdateTimeCards(appointmentCache, appointmentEmployeeLogs, fsAppointmentRow))
            {
                foreach (FSAppointmentLog fsAppointmentLogRow in appointmentEmployeeLogs.Select().RowCast <FSAppointmentLog>().Where(row => row.BAccountType == BAccountType.EmployeeType))
                {
                    EPActivityApprove epActivityApproveRow    = null;
                    EPActivityApprove oldEPActivityApproveRow = null;
                    TMEPEmployee      epEmployeeRow           = null;

                    FindTMEmployee(graphAppointmentEntry, fsAppointmentLogRow.BAccountID, ref epEmployeeRow);
                    FindEPActivityApprove(graphAppointmentEntry, fsAppointmentLogRow, epEmployeeRow, ref epActivityApproveRow);

                    if (fsAppointmentLogRow.TrackTime == true)
                    {
                        if (fsAppointmentLogRow.BAccountID != null)
                        {
                            TMEPEmployee oldEPEmployeeRow = null;
                            FindTMEmployee(graphAppointmentEntry, fsAppointmentLogRow.BAccountID, ref oldEPEmployeeRow);
                            FindEPActivityApprove(graphAppointmentEntry, fsAppointmentLogRow, oldEPEmployeeRow, ref oldEPActivityApproveRow);
                            DeleteEPActivityApprove(graphEmployeeActivitiesEntry, oldEPActivityApproveRow);
                        }

                        InsertUpdateEPActivityApprove(graphAppointmentEntry, graphEmployeeActivitiesEntry, fsAppointmentLogRow, fsAppointmentRow, fsServiceOrderRow, epActivityApproveRow, epEmployeeRow);
                    }
                    else
                    {
                        if (epActivityApproveRow != null)
                        {
                            DeleteEPActivityApprove(graphEmployeeActivitiesEntry, epActivityApproveRow);
                        }
                    }
                }

                foreach (FSAppointmentLog fsAppointmentLogRow in appointmentEmployeeLogs.Cache.Deleted.RowCast <FSAppointmentLog>().Where(row => row.BAccountType == BAccountType.EmployeeType))
                {
                    SearchAndDeleteEPActivity(graphAppointmentEntry, fsAppointmentLogRow, graphEmployeeActivitiesEntry);
                }
            }
            else if ((string)appointmentCache.GetValueOriginal <FSAppointment.status>(fsAppointmentRow) == ID.Status_Appointment.COMPLETED &&
                     fsAppointmentRow.Status == ID.Status_Appointment.MANUAL_SCHEDULED)
            {
                foreach (FSAppointmentLog fsAppointmentLogRow in appointmentEmployeeLogs.Select().RowCast <FSAppointmentLog>().Where(row => row.BAccountType == BAccountType.EmployeeType))
                {
                    SearchAndDeleteEPActivity(graphAppointmentEntry, fsAppointmentLogRow, graphEmployeeActivitiesEntry);
                }

                foreach (FSAppointmentLog fsAppointmentLogRow in appointmentEmployeeLogs.Cache.Deleted.RowCast <FSAppointmentLog>().Where(row => row.BAccountType == BAccountType.EmployeeType))
                {
                    SearchAndDeleteEPActivity(graphAppointmentEntry, fsAppointmentLogRow, graphEmployeeActivitiesEntry);
                }
            }

            if (deleteReleatedTimeActivity != null)
            {
                //Deleting time activities related with canceled service lines
                foreach (FSAppointmentLog fsAppointmentLogRow in deleteReleatedTimeActivity)
                {
                    if (fsAppointmentLogRow.BAccountType == BAccountType.EmployeeType)
                    {
                        SearchAndDeleteEPActivity(graphAppointmentEntry, fsAppointmentLogRow, graphEmployeeActivitiesEntry);
                    }
                }
            }

            if (createReleatedTimeActivity != null)
            {
                //Creating time activities related with re-opened service lines
                foreach (FSAppointmentLog fsAppointmentLogRow in createReleatedTimeActivity)
                {
                    if (fsAppointmentLogRow.BAccountType == BAccountType.EmployeeType)
                    {
                        TMEPEmployee epEmployeeRow = null;
                        FindTMEmployee(graphAppointmentEntry, fsAppointmentLogRow.BAccountID, ref epEmployeeRow);
                        InsertUpdateEPActivityApprove(graphAppointmentEntry, graphEmployeeActivitiesEntry, fsAppointmentLogRow, fsAppointmentRow, fsServiceOrderRow, null, epEmployeeRow);
                    }
                }
            }

            if (graphEmployeeActivitiesEntry.IsDirty == true)
            {
                graphEmployeeActivitiesEntry.Save.Press();
            }
        }