mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
[AC-2804] Add client ID to provider client invoice report (#4458)
* Add client ID to provider client invoice report * Run dotnet format
This commit is contained in:
parent
8b5f65fc00
commit
9c8a9f41fb
@ -7,6 +7,7 @@ namespace Bit.Commercial.Core.Billing.Models;
|
|||||||
public class ProviderClientInvoiceReportRow
|
public class ProviderClientInvoiceReportRow
|
||||||
{
|
{
|
||||||
public string Client { get; set; }
|
public string Client { get; set; }
|
||||||
|
public string Id { get; set; }
|
||||||
public int Assigned { get; set; }
|
public int Assigned { get; set; }
|
||||||
public int Used { get; set; }
|
public int Used { get; set; }
|
||||||
public int Remaining { get; set; }
|
public int Remaining { get; set; }
|
||||||
@ -18,6 +19,7 @@ public class ProviderClientInvoiceReportRow
|
|||||||
=> new()
|
=> new()
|
||||||
{
|
{
|
||||||
Client = providerInvoiceItem.ClientName,
|
Client = providerInvoiceItem.ClientName,
|
||||||
|
Id = providerInvoiceItem.ClientId?.ToString(),
|
||||||
Assigned = providerInvoiceItem.AssignedSeats,
|
Assigned = providerInvoiceItem.AssignedSeats,
|
||||||
Used = providerInvoiceItem.UsedSeats,
|
Used = providerInvoiceItem.UsedSeats,
|
||||||
Remaining = providerInvoiceItem.AssignedSeats - providerInvoiceItem.UsedSeats,
|
Remaining = providerInvoiceItem.AssignedSeats - providerInvoiceItem.UsedSeats,
|
||||||
|
@ -729,10 +729,13 @@ public class ProviderBillingServiceTests
|
|||||||
string invoiceId,
|
string invoiceId,
|
||||||
SutProvider<ProviderBillingService> sutProvider)
|
SutProvider<ProviderBillingService> sutProvider)
|
||||||
{
|
{
|
||||||
|
var clientId = Guid.NewGuid();
|
||||||
|
|
||||||
var invoiceItems = new List<ProviderInvoiceItem>
|
var invoiceItems = new List<ProviderInvoiceItem>
|
||||||
{
|
{
|
||||||
new ()
|
new ()
|
||||||
{
|
{
|
||||||
|
ClientId = clientId,
|
||||||
ClientName = "Client 1",
|
ClientName = "Client 1",
|
||||||
AssignedSeats = 50,
|
AssignedSeats = 50,
|
||||||
UsedSeats = 30,
|
UsedSeats = 30,
|
||||||
@ -757,6 +760,7 @@ public class ProviderBillingServiceTests
|
|||||||
|
|
||||||
var record = records.First();
|
var record = records.First();
|
||||||
|
|
||||||
|
Assert.Equal(clientId.ToString(), record.Id);
|
||||||
Assert.Equal("Client 1", record.Client);
|
Assert.Equal("Client 1", record.Client);
|
||||||
Assert.Equal(50, record.Assigned);
|
Assert.Equal(50, record.Assigned);
|
||||||
Assert.Equal(30, record.Used);
|
Assert.Equal(30, record.Used);
|
||||||
|
@ -76,6 +76,7 @@ public class ProviderEventService(
|
|||||||
ProviderId = parsedProviderId,
|
ProviderId = parsedProviderId,
|
||||||
InvoiceId = invoice.Id,
|
InvoiceId = invoice.Id,
|
||||||
InvoiceNumber = invoice.Number,
|
InvoiceNumber = invoice.Number,
|
||||||
|
ClientId = client.Id,
|
||||||
ClientName = client.OrganizationName,
|
ClientName = client.OrganizationName,
|
||||||
PlanName = client.Plan,
|
PlanName = client.Plan,
|
||||||
AssignedSeats = client.Seats ?? 0,
|
AssignedSeats = client.Seats ?? 0,
|
||||||
|
@ -14,6 +14,7 @@ public class ProviderInvoiceItem : ITableObject<Guid>
|
|||||||
public string InvoiceId { get; set; } = null!;
|
public string InvoiceId { get; set; } = null!;
|
||||||
[MaxLength(50)]
|
[MaxLength(50)]
|
||||||
public string? InvoiceNumber { get; set; }
|
public string? InvoiceNumber { get; set; }
|
||||||
|
public Guid? ClientId { get; set; }
|
||||||
[MaxLength(50)]
|
[MaxLength(50)]
|
||||||
public string ClientName { get; set; } = null!;
|
public string ClientName { get; set; } = null!;
|
||||||
[MaxLength(50)]
|
[MaxLength(50)]
|
||||||
|
@ -8,7 +8,8 @@ CREATE PROCEDURE [dbo].[ProviderInvoiceItem_Create]
|
|||||||
@AssignedSeats INT,
|
@AssignedSeats INT,
|
||||||
@UsedSeats INT,
|
@UsedSeats INT,
|
||||||
@Total MONEY,
|
@Total MONEY,
|
||||||
@Created DATETIME2 (7) = NULL
|
@Created DATETIME2 (7) = NULL,
|
||||||
|
@ClientId UNIQUEIDENTIFIER = NULL
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
@ -26,7 +27,8 @@ BEGIN
|
|||||||
[AssignedSeats],
|
[AssignedSeats],
|
||||||
[UsedSeats],
|
[UsedSeats],
|
||||||
[Total],
|
[Total],
|
||||||
[Created]
|
[Created],
|
||||||
|
[ClientId]
|
||||||
)
|
)
|
||||||
VALUES
|
VALUES
|
||||||
(
|
(
|
||||||
@ -39,6 +41,7 @@ BEGIN
|
|||||||
@AssignedSeats,
|
@AssignedSeats,
|
||||||
@UsedSeats,
|
@UsedSeats,
|
||||||
@Total,
|
@Total,
|
||||||
@Created
|
@Created,
|
||||||
|
@ClientId
|
||||||
)
|
)
|
||||||
END
|
END
|
||||||
|
@ -8,7 +8,8 @@ CREATE PROCEDURE [dbo].[ProviderInvoiceItem_Update]
|
|||||||
@AssignedSeats INT,
|
@AssignedSeats INT,
|
||||||
@UsedSeats INT,
|
@UsedSeats INT,
|
||||||
@Total MONEY,
|
@Total MONEY,
|
||||||
@Created DATETIME2 (7) = NULL
|
@Created DATETIME2 (7) = NULL,
|
||||||
|
@ClientId UNIQUEIDENTIFIER = NULL
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
@ -26,7 +27,8 @@ BEGIN
|
|||||||
[AssignedSeats] = @AssignedSeats,
|
[AssignedSeats] = @AssignedSeats,
|
||||||
[UsedSeats] = @UsedSeats,
|
[UsedSeats] = @UsedSeats,
|
||||||
[Total] = @Total,
|
[Total] = @Total,
|
||||||
[Created] = @Created
|
[Created] = @Created,
|
||||||
|
[ClientId] = @ClientId
|
||||||
WHERE
|
WHERE
|
||||||
[Id] = @Id
|
[Id] = @Id
|
||||||
END
|
END
|
||||||
|
@ -9,6 +9,7 @@ CREATE TABLE [dbo].[ProviderInvoiceItem] (
|
|||||||
[UsedSeats] INT NOT NULL,
|
[UsedSeats] INT NOT NULL,
|
||||||
[Total] MONEY NOT NULL,
|
[Total] MONEY NOT NULL,
|
||||||
[Created] DATETIME2 (7) NOT NULL,
|
[Created] DATETIME2 (7) NOT NULL,
|
||||||
|
[ClientId] UNIQUEIDENTIFIER NULL,
|
||||||
CONSTRAINT [PK_ProviderInvoiceItem] PRIMARY KEY CLUSTERED ([Id] ASC),
|
CONSTRAINT [PK_ProviderInvoiceItem] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||||
CONSTRAINT [FK_ProviderInvoiceItem_Provider] FOREIGN KEY ([ProviderId]) REFERENCES [dbo].[Provider] ([Id]) ON DELETE CASCADE
|
CONSTRAINT [FK_ProviderInvoiceItem_Provider] FOREIGN KEY ([ProviderId]) REFERENCES [dbo].[Provider] ([Id]) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,124 @@
|
|||||||
|
-- Add 'ClientId' column to 'ProviderInvoiceItem' table.
|
||||||
|
IF COL_LENGTH('[dbo].[ProviderInvoiceItem]', 'ClientId') IS NULL
|
||||||
|
BEGIN
|
||||||
|
ALTER TABLE
|
||||||
|
[dbo].[ProviderInvoiceItem]
|
||||||
|
ADD
|
||||||
|
[ClientId] UNIQUEIDENTIFIER NULL;
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- Recreate 'ProviderInvoiceItemView' so that it includes the 'ClientId' column.
|
||||||
|
CREATE OR ALTER VIEW [dbo].[ProviderInvoiceItemView]
|
||||||
|
AS
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
[dbo].[ProviderInvoiceItem]
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- Alter 'ProviderInvoiceItem_Create' SPROC to add 'ClientId' column.
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[ProviderInvoiceItem_Create]
|
||||||
|
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||||
|
@ProviderId UNIQUEIDENTIFIER,
|
||||||
|
@InvoiceId VARCHAR (50),
|
||||||
|
@InvoiceNumber VARCHAR (50),
|
||||||
|
@ClientName NVARCHAR (50),
|
||||||
|
@PlanName NVARCHAR (50),
|
||||||
|
@AssignedSeats INT,
|
||||||
|
@UsedSeats INT,
|
||||||
|
@Total MONEY,
|
||||||
|
@Created DATETIME2 (7) = NULL,
|
||||||
|
@ClientId UNIQUEIDENTIFIER = NULL
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
SET @Created = COALESCE(@Created, GETUTCDATE())
|
||||||
|
|
||||||
|
INSERT INTO [dbo].[ProviderInvoiceItem]
|
||||||
|
(
|
||||||
|
[Id],
|
||||||
|
[ProviderId],
|
||||||
|
[InvoiceId],
|
||||||
|
[InvoiceNumber],
|
||||||
|
[ClientName],
|
||||||
|
[PlanName],
|
||||||
|
[AssignedSeats],
|
||||||
|
[UsedSeats],
|
||||||
|
[Total],
|
||||||
|
[Created],
|
||||||
|
[ClientId]
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
@Id,
|
||||||
|
@ProviderId,
|
||||||
|
@InvoiceId,
|
||||||
|
@InvoiceNumber,
|
||||||
|
@ClientName,
|
||||||
|
@PlanName,
|
||||||
|
@AssignedSeats,
|
||||||
|
@UsedSeats,
|
||||||
|
@Total,
|
||||||
|
@Created,
|
||||||
|
@ClientId
|
||||||
|
)
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- Alter 'ProviderInvoiceItem_Update' SPROC to add 'ClientId' column.
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[ProviderInvoiceItem_Update]
|
||||||
|
@Id UNIQUEIDENTIFIER,
|
||||||
|
@ProviderId UNIQUEIDENTIFIER,
|
||||||
|
@InvoiceId VARCHAR (50),
|
||||||
|
@InvoiceNumber VARCHAR (50),
|
||||||
|
@ClientName NVARCHAR (50),
|
||||||
|
@PlanName NVARCHAR (50),
|
||||||
|
@AssignedSeats INT,
|
||||||
|
@UsedSeats INT,
|
||||||
|
@Total MONEY,
|
||||||
|
@Created DATETIME2 (7) = NULL,
|
||||||
|
@ClientId UNIQUEIDENTIFIER = NULL
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
SET @Created = COALESCE(@Created, GETUTCDATE())
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
[dbo].[ProviderInvoiceItem]
|
||||||
|
SET
|
||||||
|
[ProviderId] = @ProviderId,
|
||||||
|
[InvoiceId] = @InvoiceId,
|
||||||
|
[InvoiceNumber] = @InvoiceNumber,
|
||||||
|
[ClientName] = @ClientName,
|
||||||
|
[PlanName] = @PlanName,
|
||||||
|
[AssignedSeats] = @AssignedSeats,
|
||||||
|
[UsedSeats] = @UsedSeats,
|
||||||
|
[Total] = @Total,
|
||||||
|
[Created] = @Created,
|
||||||
|
[ClientId] = @ClientId
|
||||||
|
WHERE
|
||||||
|
[Id] = @Id
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- Refresh modules for SPROCs reliant on 'ProviderInvoiceItem' table/view.
|
||||||
|
IF OBJECT_ID('[dbo].[ProviderInvoiceItem_ReadById]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXECUTE sp_refreshsqlmodule N'[dbo].[ProviderInvoiceItem_ReadById]';
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[ProviderInvoiceItem_ReadByInvoiceId]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXECUTE sp_refreshsqlmodule N'[dbo].[ProviderInvoiceItem_ReadByInvoiceId]';
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[ProviderInvoiceItem_ReadByProviderId]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXECUTE sp_refreshsqlmodule N'[dbo].[ProviderInvoiceItem_ReadByProviderId]';
|
||||||
|
END
|
||||||
|
GO
|
2674
util/MySqlMigrations/Migrations/20240703182722_AddClientIdToProviderInvoiceItem.Designer.cs
generated
Normal file
2674
util/MySqlMigrations/Migrations/20240703182722_AddClientIdToProviderInvoiceItem.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Bit.MySqlMigrations.Migrations;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddClientIdToProviderInvoiceItem : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<Guid>(
|
||||||
|
name: "ClientId",
|
||||||
|
table: "ProviderInvoiceItem",
|
||||||
|
type: "char(36)",
|
||||||
|
nullable: true,
|
||||||
|
collation: "ascii_general_ci");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ClientId",
|
||||||
|
table: "ProviderInvoiceItem");
|
||||||
|
}
|
||||||
|
}
|
@ -693,6 +693,9 @@ namespace Bit.MySqlMigrations.Migrations
|
|||||||
b.Property<int>("AssignedSeats")
|
b.Property<int>("AssignedSeats")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<Guid?>("ClientId")
|
||||||
|
.HasColumnType("char(36)");
|
||||||
|
|
||||||
b.Property<string>("ClientName")
|
b.Property<string>("ClientName")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(50)
|
.HasMaxLength(50)
|
||||||
|
2681
util/PostgresMigrations/Migrations/20240703182718_AddClientIdToProviderInvoiceItem.Designer.cs
generated
Normal file
2681
util/PostgresMigrations/Migrations/20240703182718_AddClientIdToProviderInvoiceItem.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Bit.PostgresMigrations.Migrations;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddClientIdToProviderInvoiceItem : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<Guid>(
|
||||||
|
name: "ClientId",
|
||||||
|
table: "ProviderInvoiceItem",
|
||||||
|
type: "uuid",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ClientId",
|
||||||
|
table: "ProviderInvoiceItem");
|
||||||
|
}
|
||||||
|
}
|
@ -698,6 +698,9 @@ namespace Bit.PostgresMigrations.Migrations
|
|||||||
b.Property<int>("AssignedSeats")
|
b.Property<int>("AssignedSeats")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<Guid?>("ClientId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
b.Property<string>("ClientName")
|
b.Property<string>("ClientName")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(50)
|
.HasMaxLength(50)
|
||||||
|
2663
util/SqliteMigrations/Migrations/20240703182714_AddClientIdToProviderInvoiceItem.Designer.cs
generated
Normal file
2663
util/SqliteMigrations/Migrations/20240703182714_AddClientIdToProviderInvoiceItem.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Bit.SqliteMigrations.Migrations;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddClientIdToProviderInvoiceItem : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<Guid>(
|
||||||
|
name: "ClientId",
|
||||||
|
table: "ProviderInvoiceItem",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ClientId",
|
||||||
|
table: "ProviderInvoiceItem");
|
||||||
|
}
|
||||||
|
}
|
@ -682,6 +682,9 @@ namespace Bit.SqliteMigrations.Migrations
|
|||||||
b.Property<int>("AssignedSeats")
|
b.Property<int>("AssignedSeats")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<Guid?>("ClientId")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("ClientName")
|
b.Property<string>("ClientName")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(50)
|
.HasMaxLength(50)
|
||||||
|
Loading…
Reference in New Issue
Block a user