/// <summary> /// Check if the given service License are contained by each given employee. /// </summary> /// <param name="serviceLicenses">Service with its licenses.</param> /// <param name="employeeLicenseList">List of employees and their licenses.</param> private static bool CanThisServiceBeCompleteByTheseEmployeesLicenses(SharedClasses.ItemList serviceLicenses, List <SharedClasses.ItemList> employeeLicenseList) { if (employeeLicenseList.Count > 0) { foreach (SharedClasses.ItemList employeeLicenses in employeeLicenseList.Where(x => x.list.Count > 0)) { if (serviceLicenses.list.Except(employeeLicenses.list).Any()) { return(false); } } return(true); } return(false); }
/// <summary> /// Evaluates if the employeeItemList (belonging to an Employee) provided has the items (skills or licenseTypes) selected in filter. /// </summary> /// <param name="employeeItemList">Employee item list instance.</param> /// <param name="itemsSelection">Items list selected in filter.</param> /// <returns>True if Employee has items Selected, otherwise False.</returns> private static bool HasEmployeeItemsSelected(SharedClasses.ItemList employeeItemList, List <int?> itemsSelection) { if (employeeItemList != null) { List <int?> list = employeeItemList.list.Cast <int?>().ToList(); if (itemsSelection.Except(list).Any()) { return(false); } } else { if (itemsSelection.Count > 0) { return(false); } } return(true); }
public static IEnumerable StaffRecordsDelegate( object staffView, PXSelectBase <SkillGridFilter> skillView, PXSelectBase <LicenseTypeGridFilter> licenseTypeView, PXFilter <StaffSelectionFilter> filter) { if (filter.Current == null) { yield break; } PXGraph graphFilter = filter.Cache.Graph; IEnumerable <BAccountStaffMember> staffSet = GetStaffAvailableForSelect(filter, staffView); List <int?> skillsSelection = skillView.Select() .Where(y => ((SkillGridFilter)y).Mem_Selected == true) .Select(y => ((SkillGridFilter)y).SkillID) .ToList(); List <int?> licenseTypesSelection = licenseTypeView.Select() .Where(y => ((LicenseTypeGridFilter)y).Mem_Selected == true) .Select(y => ((LicenseTypeGridFilter)y).LicenseTypeID) .ToList(); if (skillsSelection.Count == 0 && licenseTypesSelection.Count == 0) { foreach (BAccountStaffMember staffRow in staffSet) { yield return(staffRow); } } else { List <int?> employeeIDList = staffSet.Select(y => y.BAccountID).ToList(); //Loading Skill list for each employee in employeeIDList List <SharedClasses.ItemList> allStaffSkillList = SharedFunctions.GetItemWithList <FSEmployeeSkill, FSEmployeeSkill.employeeID, FSEmployeeSkill.skillID>(graphFilter, employeeIDList); //NOTE: TIME info must be removed in order to catch licenses that expire the same day as ScheduledDateTimeBegin filter.Current.ScheduledDateTimeBegin = SharedFunctions.RemoveTimeInfo(filter.Current.ScheduledDateTimeBegin); //Loading LicenseType list for each employee in employeeIDList List <SharedClasses.ItemList> allStaffLicenseTypeList = SharedFunctions.GetItemWithList <FSLicense, FSLicense.employeeID, FSLicense.licenseTypeID, Where2 < Where <Current <StaffSelectionFilter.scheduledDateTimeBegin>, IsNull>, Or <Where <FSLicense.expirationDate, GreaterEqual <Current <StaffSelectionFilter.scheduledDateTimeBegin> >, And <FSLicense.issueDate, LessEqual <Current <StaffSelectionFilter.scheduledDateTimeBegin> > > > > > > (graphFilter, employeeIDList); foreach (BAccountStaffMember staffRow in staffSet) { SharedClasses.ItemList employeeSkillList = allStaffSkillList.FirstOrDefault(y => y.itemID == staffRow.BAccountID); if (HasEmployeeItemsSelected(employeeSkillList, skillsSelection) == false && staffRow.Selected == false) { continue; } SharedClasses.ItemList employeeLicenseTypeList = allStaffLicenseTypeList.FirstOrDefault(y => y.itemID == staffRow.BAccountID); if (HasEmployeeItemsSelected(employeeLicenseTypeList, licenseTypesSelection) == false && staffRow.Selected == false) { continue; } yield return(staffRow); } } }
public static IEnumerable ServiceRecordsDelegate <ServiceDetType>( PXSelectBase <ServiceDetType> servicesView, PXSelectBase <EmployeeGridFilter> employeesView, PXFilter <ServiceSelectionFilter> filter) where ServiceDetType : class, IBqlTable, IFSSODetBase, new() { if (filter.Current == null) { yield break; } PXGraph graph = filter.Cache.Graph; PXSelectBase <InventoryItem> cmd = new ServiceRecords_View(graph); List <int?> serviceList = GetServicesInServiceTab <ServiceDetType>(servicesView, null); List <int?> employeeSelection = employeesView.Select() .Where(y => y.GetItem <EmployeeGridFilter>().Mem_Selected == true) .Select(y => y.GetItem <EmployeeGridFilter>().EmployeeID) .ToList(); IEnumerable <InventoryItem> inventoryRecords = GetListWithServicesOnly(cmd, serviceList); if (employeeSelection.Count == 0) { foreach (InventoryItem inventoryRow in inventoryRecords) { yield return(inventoryRow); } } else { List <int?> serviceIDList = inventoryRecords.Select(y => y.InventoryID).ToList(); //Loading Skill list for each service in inventoryIDList List <SharedClasses.ItemList> serviceSkillList = SharedFunctions.GetItemWithList <FSServiceSkill, FSServiceSkill.serviceID, FSServiceSkill.skillID>(graph, serviceIDList); //Loading Skill list for each employee in employeeSelection List <SharedClasses.ItemList> employeeSkillList = SharedFunctions.GetItemWithList <FSEmployeeSkill, FSEmployeeSkill.employeeID, FSEmployeeSkill.skillID>(graph, employeeSelection); //Loading License list for each service in inventoryIDList List <SharedClasses.ItemList> serviceLicenseList = SharedFunctions.GetItemWithList <FSServiceLicenseType, FSServiceLicenseType.serviceID, FSServiceLicenseType.licenseTypeID>(graph, serviceIDList); //NOTE: TIME info must be removed in order to catch licenses that expire the same day as ScheduledDateTimeBegin filter.Current.ScheduledDateTimeBegin = SharedFunctions.RemoveTimeInfo(filter.Current.ScheduledDateTimeBegin); //Loading License list for each employee in employeeSelection List <SharedClasses.ItemList> employeeLicenseList = SharedFunctions.GetItemWithList <FSLicense, FSLicense.employeeID, FSLicense.licenseTypeID, Where2 < Where <Current <ServiceSelectionFilter.scheduledDateTimeBegin>, IsNull>, Or <Where <FSLicense.expirationDate, GreaterEqual <Current <ServiceSelectionFilter.scheduledDateTimeBegin> >, And <FSLicense.issueDate, LessEqual <Current <ServiceSelectionFilter.scheduledDateTimeBegin> > > > > > >(graph, employeeSelection); foreach (InventoryItem inventoryRow in inventoryRecords) { SharedClasses.ItemList inventoryItemSkillList = null; SharedClasses.ItemList inventoryItemLicenseList = null; if (serviceSkillList.Count != 0) { inventoryItemSkillList = serviceSkillList.FirstOrDefault(y => y.itemID == inventoryRow.InventoryID); } if (serviceLicenseList.Count != 0) { inventoryItemLicenseList = serviceLicenseList.FirstOrDefault(y => y.itemID == inventoryRow.InventoryID); } if ((inventoryItemSkillList == null || CanThisServiceBeCompleteByTheseEmployeesSkills(inventoryItemSkillList, employeeSkillList)) && (inventoryItemLicenseList == null || CanThisServiceBeCompleteByTheseEmployeesLicenses(inventoryItemLicenseList, employeeLicenseList))) { yield return(inventoryRow); } continue; } } }