public virtual void VerifyBeforeTransaction(string action, string type) { int itemsSelectedCount = 0; bool canPerformAction = false; if (action == ID.LogActions.START) { if (type == ID.Type_Log.TRAVEL || type == ID.Type_Log.SERVICE) { itemsSelectedCount = StaffMemberLogStartAction.Select().RowCast <FSAppointmentEmployeeFSLogStart>().Where(x => x.Selected == true).Count(); canPerformAction = LogActionFilter.Current.Me == true || itemsSelectedCount > 0; if (type == ID.Type_Log.SERVICE && LogActionFilter.Current.DetLineRef == null) { LogActionFilter.Cache.RaiseExceptionHandling <FSLogActionFilter.detLineRef>(LogActionFilter.Current, LogActionFilter.Current.DetLineRef, new PXSetPropertyException(PXMessages.LocalizeFormatNoPrefix(TX.Error.FIELD_MAY_NOT_BE_EMPTY, PXUIFieldAttribute.GetDisplayName <FSLogActionFilter.detLineRef>(LogActionFilter.Cache)))); canPerformAction = false; } } else if (type == ID.Type_Log.STAFF_ASSIGMENT) { itemsSelectedCount = LogStaffActionDetails.Select().RowCast <FSStaffLogActionDetail>().Where(x => x.Selected == true).Count(); canPerformAction = itemsSelectedCount > 0; } else if (type == ID.Type_Log.SERV_BASED_ASSIGMENT) { itemsSelectedCount = ServicesLogAction.Select().RowCast <FSDetailFSLogAction>().Where(x => x.Selected == true).Count(); canPerformAction = itemsSelectedCount > 0; } } else if (action == ID.LogActions.COMPLETE) { if (type == ID.Type_Log.TRAVEL) { itemsSelectedCount = LogActionTravelDetails.Select().RowCast <FSLogActionTravelDetail>().Where(x => x.Selected == true).Count(); } else if (type == ID.Type_Log.SERVICE || type == ID.Type_Log.STAFF_ASSIGMENT) { itemsSelectedCount = LogActionServiceDetails.Select().RowCast <NoTravelLogInProcess>().Where(x => x.Selected == true).Count(); } canPerformAction = itemsSelectedCount > 0; } if (canPerformAction == false) { LogActionFilter.Cache.RaiseExceptionHandling <FSLogActionFilter.action>(LogActionFilter.Current, LogActionFilter.Current.Action, new PXSetPropertyException(TX.Error.CANNOT_PERFORM_LOG_ACTION_RECORD_NOT_SELECTED)); throw new PXRowPersistingException(null, null, TX.Error.CANNOT_PERFORM_LOG_ACTION_RECORD_NOT_SELECTED); } }
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); } } }