diff --git a/src/Api/AdminConsole/Models/Response/Providers/ProviderOrganizationResponseModel.cs b/src/Api/AdminConsole/Models/Response/Providers/ProviderOrganizationResponseModel.cs index b8704d7bc..963fbaa20 100644 --- a/src/Api/AdminConsole/Models/Response/Providers/ProviderOrganizationResponseModel.cs +++ b/src/Api/AdminConsole/Models/Response/Providers/ProviderOrganizationResponseModel.cs @@ -42,6 +42,8 @@ public class ProviderOrganizationResponseModel : ResponseModel RevisionDate = providerOrganization.RevisionDate; UserCount = providerOrganization.UserCount; Seats = providerOrganization.Seats; + OccupiedSeats = providerOrganization.OccupiedSeats; + RemainingSeats = providerOrganization.Seats - providerOrganization.OccupiedSeats; Plan = providerOrganization.Plan; } @@ -54,6 +56,8 @@ public class ProviderOrganizationResponseModel : ResponseModel public DateTime RevisionDate { get; set; } public int UserCount { get; set; } public int? Seats { get; set; } + public int? OccupiedSeats { get; set; } + public int? RemainingSeats { get; set; } public string Plan { get; set; } } diff --git a/src/Billing/Services/Implementations/ProviderEventService.cs b/src/Billing/Services/Implementations/ProviderEventService.cs index 6a3ffea07..2da071de7 100644 --- a/src/Billing/Services/Implementations/ProviderEventService.cs +++ b/src/Billing/Services/Implementations/ProviderEventService.cs @@ -79,7 +79,7 @@ public class ProviderEventService( ClientName = client.OrganizationName, PlanName = client.Plan, AssignedSeats = client.Seats ?? 0, - UsedSeats = client.UserCount, + UsedSeats = client.OccupiedSeats ?? 0, Total = client.Plan == enterprisePlan.Name ? (client.Seats ?? 0) * discountedEnterpriseSeatPrice : (client.Seats ?? 0) * discountedTeamsSeatPrice diff --git a/src/Core/AdminConsole/Models/Data/Provider/ProviderOrganizationOrganizationDetails.cs b/src/Core/AdminConsole/Models/Data/Provider/ProviderOrganizationOrganizationDetails.cs index d1baac001..1b2112707 100644 --- a/src/Core/AdminConsole/Models/Data/Provider/ProviderOrganizationOrganizationDetails.cs +++ b/src/Core/AdminConsole/Models/Data/Provider/ProviderOrganizationOrganizationDetails.cs @@ -20,6 +20,7 @@ public class ProviderOrganizationOrganizationDetails public DateTime CreationDate { get; set; } public DateTime RevisionDate { get; set; } public int UserCount { get; set; } + public int? OccupiedSeats { get; set; } public int? Seats { get; set; } public string Plan { get; set; } public OrganizationStatusType Status { get; set; } diff --git a/src/Infrastructure.EntityFramework/AdminConsole/Repositories/Queries/ProviderOrganizationOrganizationDetailsReadByProviderIdQuery.cs b/src/Infrastructure.EntityFramework/AdminConsole/Repositories/Queries/ProviderOrganizationOrganizationDetailsReadByProviderIdQuery.cs index af42114ad..62e46566d 100644 --- a/src/Infrastructure.EntityFramework/AdminConsole/Repositories/Queries/ProviderOrganizationOrganizationDetailsReadByProviderIdQuery.cs +++ b/src/Infrastructure.EntityFramework/AdminConsole/Repositories/Queries/ProviderOrganizationOrganizationDetailsReadByProviderIdQuery.cs @@ -32,6 +32,7 @@ public class ProviderOrganizationOrganizationDetailsReadByProviderIdQuery : IQue CreationDate = x.po.CreationDate, RevisionDate = x.po.RevisionDate, UserCount = x.o.OrganizationUsers.Count(ou => ou.Status == Core.Enums.OrganizationUserStatusType.Confirmed), + OccupiedSeats = x.o.OrganizationUsers.Count(ou => ou.Status >= 0), Seats = x.o.Seats, Plan = x.o.Plan, Status = x.o.Status diff --git a/src/Sql/dbo/Views/ProviderOrganizationOrganizationDetailsView.sql b/src/Sql/dbo/Views/ProviderOrganizationOrganizationDetailsView.sql index 5e5bce9eb..0fcff7369 100644 --- a/src/Sql/dbo/Views/ProviderOrganizationOrganizationDetailsView.sql +++ b/src/Sql/dbo/Views/ProviderOrganizationOrganizationDetailsView.sql @@ -10,6 +10,7 @@ SELECT PO.[CreationDate], PO.[RevisionDate], (SELECT COUNT(1) FROM [dbo].[OrganizationUser] OU WHERE OU.OrganizationId = PO.OrganizationId AND OU.Status = 2) UserCount, + (SELECT COUNT(1) FROM [dbo].[OrganizationUser] OU WHERE OU.OrganizationId = PO.OrganizationId AND OU.Status >= 0) OccupiedSeats, O.[Seats], O.[Plan], O.[Status] diff --git a/test/Billing.Test/Services/ProviderEventServiceTests.cs b/test/Billing.Test/Services/ProviderEventServiceTests.cs index 75bd6f9a2..47c2f8450 100644 --- a/test/Billing.Test/Services/ProviderEventServiceTests.cs +++ b/test/Billing.Test/Services/ProviderEventServiceTests.cs @@ -176,7 +176,7 @@ public class ProviderEventServiceTests OrganizationName = "Client 1", Plan = "Teams (Monthly)", Seats = 50, - UserCount = 30, + OccupiedSeats = 30, Status = OrganizationStatusType.Managed }, new () @@ -184,7 +184,7 @@ public class ProviderEventServiceTests OrganizationName = "Client 2", Plan = "Enterprise (Monthly)", Seats = 50, - UserCount = 30, + OccupiedSeats = 30, Status = OrganizationStatusType.Managed } }; diff --git a/util/Migrator/DbScripts/2024-06-27_00_AddOccupiedSeatsToProviderOrganizationOrganizationDetailsView.sql b/util/Migrator/DbScripts/2024-06-27_00_AddOccupiedSeatsToProviderOrganizationOrganizationDetailsView.sql new file mode 100644 index 000000000..fa67fbbd4 --- /dev/null +++ b/util/Migrator/DbScripts/2024-06-27_00_AddOccupiedSeatsToProviderOrganizationOrganizationDetailsView.sql @@ -0,0 +1,22 @@ +-- Add column 'AssignedSeats' +CREATE OR AlTER VIEW [dbo].[ProviderOrganizationOrganizationDetailsView] +AS +SELECT + PO.[Id], + PO.[ProviderId], + PO.[OrganizationId], + O.[Name] OrganizationName, + PO.[Key], + PO.[Settings], + PO.[CreationDate], + PO.[RevisionDate], + (SELECT COUNT(1) FROM [dbo].[OrganizationUser] OU WHERE OU.OrganizationId = PO.OrganizationId AND OU.Status = 2) UserCount, + (SELECT COUNT(1) FROM [dbo].[OrganizationUser] OU WHERE OU.OrganizationId = PO.OrganizationId AND OU.Status >= 0) OccupiedSeats, + O.[Seats], + O.[Plan], + O.[Status] +FROM + [dbo].[ProviderOrganization] PO +LEFT JOIN + [dbo].[Organization] O ON O.[Id] = PO.[OrganizationId] +GO